Commit graph

306 commits

Author SHA1 Message Date
Adrian Johnson
0cae2a4a74 Use _cairo_calloc() to allocate structs
To avoid any possibility of uninitialized memory.

The exceptions are:
 - where the allocation is immediately overwritten by a memcpy or struct copy.
 - arrays of structs to avoid any performance impact (except when the
   array is returned by the public API).
2024-06-21 10:32:23 +09:30
Adrian Johnson
b53b48116e Make cairo_tag_begin/end work correctly in groups
Fixes #508
2023-04-18 18:27:12 +09:30
John Ralls
951a3dd9a7 [quartz]Conditionally Use Main Display ColorSpace instead of kCGColorSpaceDefaultRGB.
The default RGB colorspace must be converted to the GPU's colorspace
    using CGColorTransformConvertUsingCMSConverter. Profiling has shown this
    function to consume as much as 48% of a redraw cycle in gdk-quartz.

    There seems to be no named colorspace that matches the one stored on the
    display, so we use the one associated with the main display. This has
    some risks for users with multiple monitors but in testing with my own
    two-monitor setup, one of which is HDR and the other not, the colorspace
    was the same for both.

    This is applied to quartz surfaces created with
    cairo_quartz_surface_create(); surfaces created with
    cairo_quartz_surface_create_for_cg_context will inherit the colorspace
    from the context.

    In order to generate PNGs that look right I've converted the
    existing debugging functions for writing a quartz surface to png
    into private functions and wired cairo-boilerplate-quartz to use
    them. Using the generic cairo routine produced washed-out PNGs.

    Fixes https://gitlab.freedesktop.org/cairo/cairo/-/issues/330
2023-02-17 10:25:14 -08:00
John Ralls
6b1b14a236 [quartz] Pretty up the surface-type and zero-size tests. 2023-02-14 11:53:02 -08:00
John Ralls
198d1792cf [quartz] Cleanup and make better use of cairo_quartz_image_surface_t.
Use a CGBitmapContext mapping the underlying image surface's data instead
of maintaining a CGImage. Generalize the quartz surface snapshot mechanism
to work with both cairo_quartz_surface_t and cairo_quartz_image_surface_t
and to use the latter to get a CGContext around non-quartz surfaces.
Use this snapshot machanism to get a CGImageRef when needed from a
cairo_quartz_image_surface_t.
2023-02-14 11:52:57 -08:00
Adrian Johnson
7146358250 Fix shared use of recording surface with paginated targets
The problem is _cairo_recording_surface_replay_and_create_regions()
stores the cairo_recording_region_type_t in the same structure as the
recording commands. This does not work well when the recording surface
is used as source by multiple surfaces

Fix this by moving the cairo_recording_region_type_t into a separate
struct cairo_recording_regions_array_t. This struct is stored in a
list that allows multiple create regions results to be store in the
surface.

The new function _cairo_recording_surface_region_array_attach() is
used to create a new cairo_recording_regions_array_t, attach it to the
recording surface and return a unique region id.

The _cairo_recording_surface_replay_and_create_regions() and
_cairo_recording_surface_replay_region() functions use this region id
to identify the cairo_recording_regions_array_t.

To handle nested recording surfaces, when replaying a recording, the
region id is passed to the target as an extra parameter in the surface
pattern. The wrapper surface makes a temporary copy of the pattern to
ensure the snapshot pattern in the recording surface is not modified.

cairo_recording_regions_array_t has a reference count so the target
can hold on to the cairo_recording_regions_array_t after the paginated
surface has called _cairo_recording_surface_region_array_remove().
2023-01-15 19:29:28 +10:30
Adrian Johnson
0b5ec0139c Merge branch 'pbounds-size' into 'master'
Ensure pbounds.size is initialized even in EXTEND_NONE mode.

See merge request cairo/cairo!363
2022-12-28 05:42:51 +00:00
John Ralls
21ab756bd9 Pass the same type when creating the static glyphs and positions arrays.
Fixes https://gitlab.freedesktop.org/cairo/cairo/-/issues/574
2022-11-17 10:49:18 -08:00
Jonathan Kew
77aac45db7 Ensure pbounds.size is initialized even in EXTEND_NONE mode.
Since the if/else was replaced by a switch() here in 2e0075e265,
the size field of pbounds is not being set in the EXTEND_NONE case,
which means we end up passing uninitialized values to CGPatternCreate.
2022-10-19 14:59:45 +01:00
Jeff Muizelaar
cccc81ccba quartz: Avoid reading beyond the end of image surfaces.
The last row of data may have less than stride bytes so make sure we
only copy what we need.
2022-06-29 21:30:08 -04:00
Adrian Johnson
455a4cca54 Merge branch 'quartz-core-text' into 'master'
quartz: support rendering colored bitmap fonts

See merge request cairo/cairo!289
2022-04-27 00:04:43 +00:00
John Ralls
c6dc5df612 [quartz] Convert font handling from CGFont to CTFont. 2022-04-24 13:08:48 -07:00
John Ralls
77a8d0f9e4 [quartz] Require at least Mac OS X 10.7 Lion
Allows removal of most conditional compilation and dlsym lookups.
2022-04-24 13:08:48 -07:00
John Ralls
0048f0f803 [quartz] Fix some compiler warnings. 2022-04-24 13:08:48 -07:00
John Ralls
243938c61a [quartz] Destroy local copy of snapshot after attaching it.
Because cairo_surface_snapshot_attach refs the snapshot.

Fixes https://gitlab.freedesktop.org/cairo/cairo/-/issues/562
2022-04-23 16:38:01 -07:00
Christopher Chavez
5e1dd84796 quartz: Fix spelling in comment 2022-02-26 09:17:28 +00:00
John Ralls
2e0075e265 [quartz] Don't use CGContextDrawTiledImage for tiled patterns.
CGContextDrawTiledImage turned up as a significant time-user while
profiling a benchmark created to evaluate
https://gitlab.gnome.org/GNOME/gtk/-/issues/3714. Without this commit
the benchmark is able to perform a mean frame rate of 2.19 frames per
second with a standard deviation of 0.09; with the commit the mean frame
rate is 2.37 fps, s.d. 0.30, both over 15 10-second samples. Student's
t-test reports a 9.8% likelyhood that the two represent the same
distribution.
2022-02-24 17:00:07 -08:00
John Ralls
a502280fcd [quartz] extract function _cairo_quartz_setup_pattern_source
To simplify _cairo_quartz_setup_state.
2022-02-24 17:00:07 -08:00
John Ralls
b6e0f36ee5 [quartz]Cleanup _cairo_quartz_cairo_repeating_surface_pattern_to_quartz 2022-02-24 17:00:07 -08:00
John Ralls
ae320c4d75 [quartz] Use CoreGraphics instead of Qt to write debug png file. 2022-02-24 17:00:07 -08:00
John Ralls
bacbe9bb2d [quartz] Create similar surfaces using a CGLayer for faster drawing. 2022-02-24 17:00:07 -08:00
John Ralls
76e6a0ddf7 [quartz] Remove cached image_surface on quartz surfaces.
Caching doesn't really do anything and removing it provides a 50%
speedup and gets pdf-operators-text to pass on argb32.
2022-02-24 17:00:07 -08:00
John Ralls
64786613ee [quartz] Snapshot CGBitmapContext-mapped surfaces to cache CGImages.
Motivation: Avoid need to recreate CGImages for unchanged surfaces,
an expensive operation, while ensuring that the CGImages are properly
freed and new ones created when the surface does change.

Thanks to Uli Schlacter for suggestion and coding guidance.
2022-02-24 16:59:56 -08:00
Christopher Chavez
04394d5b15 quartz: Fix spelling in comment 2022-02-23 13:12:35 +00:00
Emmanuele Bassi
bfd1602db9 Remove stray _GNU_SOURCE definitions
We define _GNU_SOURCE globally in both the Autotools build, through the
use of the AC_USE_SYSTEM_EXTENSIONS macro; and in the Meson build, with
add_project_arguments().
2021-05-01 16:58:15 +01:00
John Ralls
dccaa9179b Quartz Better manage acquired/replayed surface. 2020-12-05 11:51:17 -08:00
John Ralls
1ddfccca31 Quartz image drawing: Remove containers for cairo_surface_t.
Since we now copy the data that CGImage needs we don't need to
keep the surface around anymore, nor release it or the image in the
DataProviderReleaseCallback.
2020-12-03 13:56:50 -08:00
John Ralls
b5e84a9783 Quartz: Ensure that image data and surface are available to draw.
Snapshot the cairo_surface_t and copy the image data to provide to
the CGDataProvider so that it is independent of the cairo_surface_t's
lifetime.

Closes https://gitlab.freedesktop.org/cairo/cairo/-/issues/420
2020-12-03 10:59:04 -08:00
John Ralls
32c12c617a Ensure _cairo_quartz_surface_create_internal always nulls imageSurfaceEquiv. 2020-11-30 14:10:18 -08:00
Adrian Johnson
1998239387 Use _cairo_malloc instead of malloc
_cairo_malloc(0) always returns NULL, but has not been used
consistently.  This patch replaces many calls to malloc() with
_cairo_malloc().

Fixes:  fdo# 101547
CVE: CVE-2017-9814 Heap buffer overflow at cairo-truetype-subset.c:1299
Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
2018-05-07 16:35:51 -07:00
Adrian Johnson
aa1323f04c Fix some surfaces missed in b1192bea 2015-10-17 22:02:11 +10:30
Andrea Canciani
66bc7b8cb0 quartz: be more strict about the behavior of blend operators
Some blend operators have a (small, but potentially noticeable)
different behaviour in Quartz and pixman. Use the Quartz ones only for
the operators which match pixman except for rounding errors.

Fixes:
 - extended-blend
 - extended-blend-alpha
 - extended-blend-mask
 - extended-blend-alpha-mask
 - extended-blend-solid
 - extended-blend-solid-alpha
2015-07-27 12:46:00 +02:00
Andrea Canciani
6210e34771 quartz: Align filtering quality with image backend
The Quartz framework provides several quality settings, but they were
not used. Now the translation of cairo_filter_t to Quartz filtering
modes tries to match the quality settings from image as much as
possible.

Specifically, CAIRO_FILTER_GOOD and CAIRO_FILTER_BILINEAR are now
converted to kCGInterpolationLow, which seems to be a bilinear filter.

Fixes:
 - pixman-downscale-bilinear-24
 - pixman-downscale-bilinear-95
 - pixman-downscale-good-24
 - pixman-downscale-good-95
 - pthread-same-source
 - recording-surface-extend-none
 - recording-surface-extend-reflect
 - recording-surface-extend-repeat
 - recording-surface-over
 - recording-surface-source
 - surface-pattern-big-scale-down
 - surface-pattern-scale-down
 - surface-pattern-scale-down-extend-none
 - surface-pattern-scale-down-extend-reflect
 - surface-pattern-scale-down-extend-repeat
2015-07-27 12:46:00 +02:00
Andrea Canciani
03756e042a quartz-image: Fix build
The quartz-image backend uses _cairo_surface_is_quartz(), which
therefore needs to be made available to it. Fixed as suggested by
Bryce in the referenced bugreport.

References: https://bugs.freedesktop.org/show_bug.cgi?id=84569
Signed-off-by: Andrea Canciani <ranma42@gmail.com>
2014-10-03 11:38:48 -07:00
Andrea Canciani
531da6fb91 quartz: Fix build
Cairo cannot build with Quartz enabled since
573ddfc3d5, because of a double
definition of _cairo_surface_is_quartz().

References: https://bugs.freedesktop.org/show_bug.cgi?id=84569
Signed-off-by: Andrea Canciani <ranma42@gmail.com>
2014-10-03 11:38:44 -07:00
Ravi Nanjundappa
573ddfc3d5 src: check the surface backend for NULL
This is a follow-up patch on top of 150c1e7044
As discussed in the mailing list, http://lists.cairographics.org/archives/cairo/2014-September/025647.html,
check if the surfaces are of particular backend type or not, before proceeding further.

These changes are based on _cairo_surface_is_xlib() and _cairo_surface_is_image()

Signed-off-by: Ravi Nanjundappa <nravi.n@samsung.com>
2014-09-29 15:59:26 -07:00
Michael Hutchinson
fdec6b3759 quartz: Don't release memory we don't own
This was causing crashes due to double frees.

https://bugs.freedesktop.org/show_bug.cgi?id=62885

Signed-off-by: Benjamin Otte <otte@redhat.com>
2013-03-29 02:40:13 +01:00
Andrea Canciani
d00539ca13 quartz: Use the correct transform when replaying recording surfaces
Recording surfaces should be replayed with the transform matrix used
in the pattern, otherwise the image surface will be transformed,
introducing artifacts.

Fixes record{1414x,2x}-paint-alpha-{,solid-clip,clip},
record2x-{self-intersecting,text-transform} and record90-paint-alpha.
2012-07-24 11:06:30 +02:00
Henry (Yu) Song - SISA
44a07a6613 quartz: Never acquire recording surfaces
We need to replay if the source/mask surface is a recording surface
otherwise, a crash happens if it is unbounded.

Fixes crashes in recordxx-xxx tests
2012-07-24 11:06:30 +02:00
Andrea Canciani
fc33cc3c3a quartz: Provide a valid implementation of map_to_image
and reuse it to implement acquire_source.

Fixes

cairo-quartz-surface.c: In function '_cairo_quartz_surface_map_to_image':
cairo-quartz-surface.c:1568: warning: return from incompatible pointer type
cairo-quartz-surface.c:1576: warning: return from incompatible pointer type
2012-05-26 16:07:47 +02:00
Andrea Canciani
a8a4a8dfd4 quartz: Mark surfaces created clear as is_clear
This might provide a speedup when clearing an already clear surface
and is required by cairo_surface_create_similar().

Fixes zero-mask.
2012-05-26 16:07:33 +02:00
Andrea Canciani
3735881e38 quartz: Silence warning
cairo-quartz-surface.c:177: warning: enumeration value
'CAIRO_FORMAT_RGB30' not handled in switch
2012-05-26 16:07:26 +02:00
Andrea Canciani
d6fb8d2134 surface: Make backend-specific map/unmap functions symmetric
Map allocates a surface. Symmetrically, unmap should destroy it.
2012-05-26 16:06:31 +02:00
Andrea Canciani
df7829e2cc surface: Make map_to_image return cairo_image_surface_t*
This makes it easier to check that the funciton is returning the
correct type of surfaces.
2012-05-26 16:06:26 +02:00
Andrea Canciani
2470065edf doc: Fix some wrong versions
The script from the previous commit reported that some 'Since' fields
indicate incorrect versions.
2012-03-29 11:03:18 +02:00
Andrea Canciani
1d3d64469f doc: Add "since" tag to documentation
The following Python script was used to compute "Since: 1.X" tags,
based on the first version where a symbol became officially supported.

This script requires a concatenation of the the cairo public headers
for the officially supported beckends to be available as
"../../includes/1.X.0.h".

from sys import argv
import re

syms = {}

def stripcomments(text):
    def replacer(match):
        s = match.group(0)
        if s.startswith('/'):
            return ""
        else:
            return s
    pattern = re.compile(
        r'//.*?$|/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\"])*"',
        re.DOTALL | re.MULTILINE
    )
    return re.sub(pattern, replacer, text)

for minor in range(12,-2,-2):
    version = "1.%d" % minor
    names = re.split('([A-Za-z0-9_]+)', stripcomments(open("../../includes/%s.0.h" % version).read()))
    for s in names: syms[s] = version

for filename in argv[1:]:
    is_public = False
    lines = open(filename, "r").read().split("\n")
    newlines = []
    for i in range(len(lines)):
        if lines[i] == "/**":
            last_sym = lines[i+1][2:].strip().replace(":", "")
            is_public = last_sym.lower().startswith("cairo")
        elif is_public and lines[i] == " **/":
            if last_sym in syms:
                v = syms[last_sym]
                if re.search("Since", newlines[-1]): newlines = newlines[:-1]
                if newlines[-1].strip() != "*": newlines.append(" *")
                newlines.append(" * Since: %s" % v)
            else:
                print "%s (%d): Cannot determine the version in which '%s' was introduced" % (filename, i, last_sym)
        newlines.append(lines[i])

    out = open(filename, "w")
    out.write("\n".join(newlines))
    out.close()
2012-03-29 11:03:18 +02:00
Andrea Canciani
7f635e4ead doc: Make doc ids more consistent my always putting ':' after them
This makes the documentations comments more consistent and fixes many
reports of 'invalid doc id'.
2012-03-29 11:03:18 +02:00
Andrea Canciani
f717341ab9 doc: Make documentation comments symmetric
Documentation comments should always start with "/**" and end with
"**/". This is not required by gtk-doc, but it makes the
documentations formatting more consistent and simplifies the checking
of documentation comments.

The following Python script tries to enforce this.

from sys import argv
from sre import search

for filename in argv[1:]:
    in_doc = False
    lines = open(filename, "r").read().split("\n")
    for i in range(len(lines)):
        ls = lines[i].strip()
        if ls == "/**":
            in_doc = True
        elif in_doc and ls == "*/":
            lines[i] = " **/"
        if ls.endswith("*/"):
            in_doc = False

    out = open(filename, "w")
    out.write("\n".join(lines))
    out.close()

This fixes most 'documentation comment not closed with **/' warnings
by check-doc-syntax.awk.
2012-03-29 11:03:18 +02:00
Chris Wilson
154e6b052b quartz: Add missing source hook
Regression from 2061cd81f2.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=45866
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2012-02-10 09:21:32 +00:00
Andrea Canciani
7058e8c181 quartz: Make glyph antialiasing consistent with quartz-font
CAIRO_ANTIALIAS_{FAST,GOOD,BEST} were introduced and used in
cairo-quartz-font.c by commit 70cd3b473d.

Fixes the warnings:

cairo-quartz-surface.c: In function '_cairo_quartz_cg_glyphs':
cairo-quartz-surface.c:1976: warning: enumeration value 'CAIRO_ANTIALIAS_FAST' not handled in switch
cairo-quartz-surface.c:1976: warning: enumeration value 'CAIRO_ANTIALIAS_GOOD' not handled in switch
cairo-quartz-surface.c:1976: warning: enumeration value 'CAIRO_ANTIALIAS_BEST' not handled in switch
2012-01-15 16:23:14 +01:00