Commit graph

50 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
Emmanuele Bassi
5de85afb75 docs: Add docblocks for missing feature defines 2023-09-23 15:18:32 +01:00
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
cae2376dd0 Merge branch 'doc-fixes' into 'master'
More random doc fixes

See merge request cairo/cairo!437
2023-02-08 09:53:29 +00:00
Khaled Hosny
b588a43fcd Fix -Wunused-variable
../src/cairo-quartz-image-surface.c:149:24: warning: unused variable 'size' [-Wunused-variable]
    const unsigned int size = surface->imageSurface->height * surface->imageSurface->stride;
2023-02-06 11:39:08 +02:00
Khaled Hosny
f03c73b270 doc: Fix missing quartz image surface docs 2023-02-02 14:13:56 +02:00
Heiko Lewin
38e486b34d cairo-quartz-image-surface.c: Fix types 2021-02-11 19:12:10 +00:00
Heiko Lewin
ba2afdcacf cairo-quartz-image-surface.c: Add missing call to cairo_surface_reference (Thanks to Fred Bca) 2021-01-19 12:11:33 +00: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
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
Bryce Harrington
d9ba8337ab quartz: Check for quartz surface type before conversion
Fixes the following warning introduced in a recent commit reported by
~suv:

  CC       cairo-quartz-image-surface.lo
cairo-quartz-image-surface.c:382:37: warning: incompatible pointer types
passing 'cairo_quartz_image_surface_t *'
      (aka 'struct cairo_quartz_image_surface *') to parameter of type
       'const cairo_surface_t *' (aka 'const struct _cairo_surface *')
      [-Wincompatible-pointer-types]
    if (! _cairo_surface_is_quartz (surface)) {
                                    ^~~~~~~
./cairo-quartz-private.h:87:50: note: passing argument to parameter 'surface' here
_cairo_surface_is_quartz (const cairo_surface_t *surface);

References:  https://bugs.freedesktop.org/show_bug.cgi?id=84569
Signed-off-by: Bryce Harrington <b.harrington@samsung.com>
2014-10-03 11:55:59 -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
Bryce Harrington
150c1e7044 Don't return NULL to clients when getting image
Return an error surface instead.

Fixes:  https://bugs.freedesktop.org/show_bug.cgi?id=58061
2014-09-22 15:41:24 -07:00
Chris Wilson
0bfd2acd35 xlib: Implement SHM fallbacks and fast upload paths
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2012-08-17 13:58:09 +01:00
Andrea Canciani
13ba74a00d quart-image: Fix compilation
quartz-image uses _cairo_surface_is_image(), which is now declared in
cairo-image-surface-inline.h.

Fixes:
cairo-quartz-image-surface.c: In function 'cairo_quartz_image_surface_create':
cairo-quartz-image-surface.c:312: error: implicit declaration of function '_cairo_surface_is_image'
cairo-quartz-image-surface.c:312: warning: nested extern declaration of '_cairo_surface_is_image'
2012-06-14 08:12:41 +02:00
Chris Wilson
f1b546b1a2 Erradicate internal use of cairo_surface_get_type()
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2012-06-01 18:17:33 +01: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
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
Nis Martensen
6ce412e15a doc: symbol names in header and comment must match
The names of the function arguments in the function prototype and
in the description comment must match, otherwise gtk-doc is confused.
When the argument names differ between function prototype and
definition, use the names from the prototype.

Also add a missing colon.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2012-03-10 10:20:29 +01:00
Chris Wilson
2061cd81f2 Replace the ad-hoc surface unwrappers with a function pointer
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2012-02-09 13:01:17 +00:00
Andrea Canciani
54c8a08f3e quartz-image: Fix build
Add missing headers and fix some minor things (typos, missing
arguments, changed function name).

Map and unmap now rely on the generic path.
2011-11-09 11:27:28 +01:00
Chris Wilson
af9fbd176b Introduce a new compositor architecture
Having spent the last dev cycle looking at how we could specialize the
compositors for various backends, we once again look for the
commonalities in order to reduce the duplication. In part this is
motivated by the idea that spans is a good interface for both the
existent GL backend and pixman, and so they deserve a dedicated
compositor. xcb/xlib target an identical rendering system and so they
should be using the same compositor, and it should be possible to run
that same compositor locally against pixman to generate reference tests.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>

P.S. This brings massive upheaval (read breakage) I've tried delaying in
order to fix as many things as possible but now this one patch does far,
far, far too much. Apologies in advance for breaking your favourite
backend, but trust me in that the end result will be much better. :)
2011-09-12 08:29:48 +01:00
Chris Wilson
a69335a84e API: map-to-image and create-similar-image
A common requirement is the fast upload of pixel data. In order to
allocate the most appropriate image buffer, we need knowledge of the
destination. The most obvious example is that we could use a
shared-memory region for the image to avoid the transfer cost of
uploading the pixels to the X server. Similarly, gl, win32, quartz...

The other side of the equation is that for manual modification of a
remote surface, it would be more efficient if we can create a similar
image to reduce the transfer costs. This strategy is already followed
for the destination fallbacks and this merely exposes the same
capability for the application fallbacks.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2011-07-26 14:55:58 +01:00
Andrea Canciani
29d19c683b build: Fix compilation
83bfd85a13 and
2458120dee did not update some backends
properly, breaking their compilation.
2011-07-19 08:10:21 +02:00
Chris Wilson
83bfd85a13 Implement cairo_backend_t
Allow a backend to completely reimplement the Cairo API as it wants. The
goal is to pass operations to the native backends such as Quartz,
Direct2D, Qt, Skia, OpenVG with no overhead. And to permit complete
logging contexts, and whatever else the imagination holds. Perhaps to
experiment with double-paths?

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2011-07-15 11:05:19 +01:00
Jeff Muizelaar
9f92901b09 Remove quartz-image extents.
We never used the x,y portion of the extents so we might as well take it out.
2011-04-21 15:23:14 -04:00
Metal Sonic
30d358e098 Update license blocks to use "Mozilla Foundation" instead of "Mozilla Corporation"
From https://bugzilla.mozilla.org/show_bug.cgi?id=507387
2010-05-06 16:07:43 -04:00
Andrea Canciani
b8a7f8621a Update FSF address
I updated the Free Software Foundation address using the following script.

for i in $(git grep Temple | cut -d: -f1 )
do
  sed -e 's/59 Temple Place[, -]* Suite 330, Boston, MA *02111-1307[, ]* USA/51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA/' -i "$i"
done

Fixes http://bugs.freedesktop.org/show_bug.cgi?id=21356
2010-04-27 11:13:38 +02:00
Chris Wilson
f617d5fc98 Add cairo_device_t
The device is a generic method for accessing the underlying interface
with the native graphics subsystem, typically the X connection or
perhaps the GL context. By exposing a cairo_device_t on a surface and
its various methods we enable finer control over interoperability with
external interactions of the device by applications. The use case in
mind is, for example, a multi-threaded gstreamer which needs to serialise
its own direct access to the device along with Cairo's across many
threads.

Secondly, the cairo_device_t is a unifying API for the mismash of
backend specific methods for controlling creation of surfaces with
explicit devices and a convenient hook for debugging and introspection.

The principal components of the API are the memory management of:

  cairo_device_reference(),
  cairo_device_finish() and
  cairo_device_destroy();

along with a pair of routines for serialising interaction:

  cairo_device_acquire() and
  cairo_device_release()

and a method to flush any outstanding accesses:

  cairo_device_flush().

The device for a particular surface may be retrieved using:

  cairo_surface_get_device().

The device returned is owned by the surface.
2010-01-22 23:01:50 +00:00
Chris Wilson
c50c8b90c0 Move _cairo_error() to a standalone header
A pending commit will want to include some utility code from cairo and
so we need to extricate the error handling from the PLT symbol hiding.
2010-01-22 22:30:43 +00:00
Andrea Canciani
7c1424a315 quartz: Fix compilation
The function _cairo_image_surface_create_for_content does not exist.
The correct name of the function is instead _cairo_image_surface_create_with_content.
2009-11-05 10:11:41 +00:00
Chris Wilson
bed2701e1c Remove clip handling from generic surface layer.
Handling clip as part of the surface state, as opposed to being part of
the operation state, is cumbersome and a hindrance to providing true proxy
surface support. For example, the clip must be copied from the surface
onto the fallback image, but this was forgotten causing undue hassle in
each backend. Another example is the contortion the meta surface
endures to ensure the clip is correctly recorded. By contrast passing the
clip along with the operation is quite simple and enables us to write
generic handlers for providing surface wrappers. (And in the future, we
should be able to write more esoteric wrappers, e.g. automatic 2x FSAA,
trivially.)

In brief, instead of the surface automatically applying the clip before
calling the backend, the backend can call into a generic helper to apply
clipping. For raster surfaces, clip regions are handled automatically as
part of the composite interface. For vector surfaces, a clip helper is
introduced to replay and callback into an intersect_clip_path() function
as necessary.

Whilst this is not primarily a performance related change (the change
should just move the computation of the clip from the moment it is applied
by the user to the moment it is required by the backend), it is important
to track any potential regression:

ppc:
Speedups
========
image-rgba         evolution-20090607-0    1026085.22 0.18% -> 672972.07 0.77%:  1.52x speedup
▌
image-rgba         evolution-20090618-0    680579.98 0.12% -> 573237.66  0.16%:  1.19x speedup
▎
image-rgba      swfdec-fill-rate-4xaa-0    460296.92 0.36% -> 407464.63  0.42%:  1.13x speedup
▏
image-rgba      swfdec-fill-rate-2xaa-0    128431.95 0.47% -> 115051.86  0.42%:  1.12x speedup
▏
Slowdowns
=========
image-rgba     firefox-periodic-table-0    56837.61 0.78% -> 66055.17    3.20%:  1.09x slowdown
▏
2009-07-23 15:32:14 +01:00
Paolo Bonzini
6394ec3048 [surface] add CAIRO_STATUS_INVALID_SIZE
Adds an error code replacing CAIRO_STATUS_NO_MEMORY in one case where it
is not really appropriate.  CAIRO_STATUS_INVALID_SIZE is used by several
backends that do not support image sizes beyond 2^15 pixels on each side.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2009-01-29 10:10:40 +00:00
M Joonas Pihlaja
4a9b274eeb [cairo-spans] Add a check/create_span_renderer backend methods.
A surface will have the chance to use span rendering at cairo_fill()
time by creating a renderer for a specific combination of
pattern/dst/op before the path is scan converted.  The protocol is to
first call check_span_renderer() to see if the surface wants to render
with spans and then later call create_span_renderer() to create the
renderer for real once the extents of the path are known.

No backends have an implementation yet.
2008-12-06 14:04:36 +02:00
Jeff Muizelaar
b94b600b34 [quartz] Completely remove CAIRO_HAS_QUARTZ_IMAGE_SURFACE check
Instead of fixing the check in d36b02dc66, just
remove it. Conditionally compilation will keep cairo-quartz-image-surface.c
from being compiled in when it is not configured to be. Suggested by Behdad.
2008-10-15 13:41:03 -04:00
Jeff Muizelaar
d36b02dc66 [quartz] Rebalance 'CAIRO_HAS_QUARTZ_IMAGE_SURFACE' #ifdef
Fixes compilation by re-adding '#ifdef CAIRO_HAS_QUARTZ_IMAGE_SURFACE' which
was, I assume, unintentionally removed by
2cf4b3161c.
2008-10-15 12:45:11 -04:00
Vladimir Vukicevic
2cf4b3161c [quartz] move _cairo_quartz_create_cgimage to cairo-quartz-surface.c 2008-09-03 15:34:40 -07:00
Vladimir Vukicevic
96c9e2a1a8 Fix cairo-quartz-image-surface compilation error 2008-07-18 15:55:11 -07:00
Behdad Esfahbod
74eea0f297 [cairo-quartz-image-surface] Remove one abuse of out-of-memory status
Vlad, you need to stop throwing random OOM errors...
2008-05-10 01:21:44 +02:00
Behdad Esfahbod
dca892c83e Fix gtk-doc warnings 2008-05-10 01:21:44 +02:00
Vladimir Vukicevic
a33351f9c6 [quartz] remove some compiler warnings 2008-03-13 15:37:57 -07:00
Vladimir Vukicevic
94e41d5565 [quartz] Don't force interpolation off for images
Creating a CGImage with interpolation set to FALSE means that
it will never be interpolated; otherwise the interoplation
is controlled by the destination context's interpolation
quality setting.
2008-03-08 17:45:47 -08:00
Vladimir Vukicevic
e52bad5e33 [quartz] split out (experimental) quartz-image into separate file 2008-03-07 14:49:15 -08:00
Carl Worth
c8c77f01f7 Fix typo in documentation 2008-02-28 13:02:27 -08:00
Vladimir Vukicevic
63711b1d4a [quartz] Add quartz-image-surface type 2008-02-25 21:06:21 -05:00