Commit graph

59 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
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
b1192beac7 Don't cull very thin lines on vector surfaces
On vector surfaces, use a minimum line width when calculating extents.

Bug 77298
2015-10-17 18:39:18 +10:30
Alexander Larsson
bc792a5e0e surface: Merge scratch construction into _cairo_surface_create_scratch
We merge _cairo_surface_create_similar_scratch and
_cairo_surface_create_similar_solid into a single function named
_cairo_surface_create_scratch, to avoid confusion with
cairo_surface_create_similar which now will have a different
behaviour wrt the sizes and the device-scale.

_create_scratch assumes the width and height are in backend
coordinates, while create_similar does not.
2013-09-05 16:11:09 +01:00
Alexander Larsson
7ab34f302b surface: expose the device scale
This adds the new public functions
cairo_surface_set_device_scale and cairo_surface_get_device_scale and
updates old users of the internal functions.
2013-09-05 16:08:19 +01:00
Alexander Larsson
25eaec0a38 subsurface: Handle device scales 2013-09-05 16:08:19 +01: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
Henry Song
9bc1ea4431 subsurface: Disable subsurface-set-snapshot as it creates a ref cycle
_cairo_surface_subsurface_set_snapshot () sets the subsurface as the
snapshot of its target.  This creates a reference cycle (as the target
is already referenced by the surface) and thus a memory leak (assuming
the likely case that user doesn't call finish).

Test case: subsurface-similar-repeat.

So make this call as a no-op for the time being until the bug is fixed.
2012-06-14 23:07:34 +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
Chris Wilson
7eb33099d3 snapshot: Perform the cow under a mutex
In order to prevent a race between concurrent destroy and use in another
thread, we need to acquire a reference to the snapshot->target under a
mutex. Whilst we hold that reference, it prevents the internal destroy
mechanism from freeing the memory we are using (if we have a pointer to
the original surface) and the client drops their final reference.

Oh boy, talk about opening a can of worms...

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2012-04-27 14:10:50 +01:00
Chris Wilson
0770dda52b Split cairo-clip-privates into struct+inlines
References: https://bugs.freedesktop.org/show_bug.cgi?id=48577
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2012-04-19 12:19:19 +01:00
Chuanbo Weng
91113a9e45 subsurface: Avoid potential crash when subsurface's size is less than 0
When cairo_surface_create_for_rectangle() is given non-integer parameters,
the subsurface's size may be negative(e.g x = 0.2, width = 0.7, the
final width will be -1). This illegal surface may cause crash somewhere
upon later use, and although the fractional subsurface is ill-defined,
we should never crash!
2012-03-13 11:19:23 +00:00
Chris Wilson
c39cb77d64 subsurface: Fix typo in snapshot creation
I need to remember that the translation for the pattern matrix is the
inverse of the translation for drawing.

Fixes: subsurface-modify-parent
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2012-02-24 13:51:25 +00:00
Chris Wilson
8028f04a91 debug: Add some TRACE statements for recording surfaces and snapshots
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2012-02-24 13:51:25 +00: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
Chris Wilson
dc80e8328c subsurface: Add guards for creating similar surface
If the target backend doesn't provide the entry points, just return NULL
(unsupported).

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2012-01-11 12:43:44 +00:00
Chris Wilson
f308ba7a44 subsurface: Replace any existing snapshot
Only allow one owner to keep their snapshot on the subsurface, and
so automatically replace any previous snapshot.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2011-11-25 12:25:38 +00:00
Chris Wilson
2fb4a0e119 subsurface: Support caching for cloned subsurfaces
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2011-11-23 17:35:30 +00:00
Chris Wilson
44a868b552 subsurface: And remove the dead code for releasing complex source
Following the previous commit, we only allocate a simple image when
acquiring the source so we only need to unreference it upon release.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2011-11-23 14:28:27 +00:00
Chris Wilson
c52129feb4 subsurface: Simplify acquire_source_image
Remove all of the special casing and simply extract the source. The time
for special casing is to avoid calling the generic acquire in the first
place, so kiss.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2011-11-23 14:19:22 +00:00
Chris Wilson
ba855a12e8 xlib-xp 2011-10-14 16:01:27 +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
6b3d53646e image: peek through a snapshot to the recording surface behind
Fixes record-* after the recent overhaul.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2011-08-14 12:37:57 +01:00
Chris Wilson
8a90b22897 subsurface+recording: handle recursion
Ouch, a nasty bug surfaces after rearranging code to fix the others.
Another self-copy loop this time through a subsurface of a recording
surface.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2011-08-14 12:37:57 +01:00
Chris Wilson
7971c678f1 subsurface: call the high-level cairo_surface_flush
And not the backend directly as this bypasses the extra steps taken in
the higher level to do common actions such as detach snapshots.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2011-08-14 12:37:57 +01:00
Chris Wilson
9f6428c517 recording: remove the duplicate 'content' field
Just use the member in the base class.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2011-08-14 12:37:56 +01:00
Chris Wilson
e849e7c929 image: move surface definition to new header for subclassing
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2011-08-13 09:54:28 +01:00
Andrea Canciani
3f9717347e win32: Constify
Silences some compiler warnings.
2011-07-27 09:44:25 +02: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
Chris Wilson
69cc802e61 Fix proxying of ->context_create()
Adrian Johnson found that I had broken show_page() and pinpointed the
cause to being that cairo_show_page() was being called on the recording
surface and not the pagination surface after my overhaul for
cairo_backend_t. In fact, the problem was far more severe as the mistake
caused the created context to point to the wrong surface entirely,
bypassing the surface proxy.

What is desired is for the proxy's target surface to choose what manner
of context is should use, but for all calls into the surface backend to
go through the proxy surface.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2011-07-21 13:45:58 +01:00
Chris Wilson
b132fae5e8 clip: Rudimentary support for clip-polygon extraction
Step 1, fix the failings sighted recently by tracking clip-boxes as an
explicit property of the clipping and of composition.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2011-07-19 21:14:34 +01: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
Benjamin Otte
61a1835e40 subsurface: Fix acquire_source_surface for out-of-bounds surfaces
See subsurface-outside-target test.
2010-09-01 03:17:12 +02:00
M Joonas Pihlaja
b0f65054b8 subsurface: Add a note to the docs about usage restrictions.
Make our assumptions about constructed subsurfaces explicit
while we work out the correct semantics for the edge cases.
2010-08-29 00:03:07 +03:00
M Joonas Pihlaja
df4b23ff74 subsurface: Fix crash when acquiring a source image.
The code is passing in the extra info received from
the target surface's acquire_source() method to
_cairo_surface_get_extents() rather than the acquired
source surface itself.
2010-08-27 20:26:06 +03:00
Andrea Canciani
2d146867dc subsurface: Correct cloning condition
72644c6df2 was using the wrong (inverted)
condition to check if the subsurface extents are contained in the
target extents.
2010-08-26 14:50:34 +02:00
Andrea Canciani
72644c6df2 subsurface: Avoid invalid accesses
Whenever subsurface extents are not contained in the target extents,
using the source image given by the target (with origin corrected by
using an appropriate offset in the data pointer) is not a valid
operation. Fallback to cloning in that case.
2010-08-26 14:38:34 +02:00
Andrea Canciani
df4465bdd1 subsurface: Silence compiler warnings
Commit d1c35f5e65 introduced two
unused variable warnings.
2010-08-26 14:23:04 +02:00
Benjamin Otte
d1c35f5e65 subsurface: Don't clip size to target size
This clipping would modify the origin of the subsurface and then the
creator has no easy way to figure this out.
2010-08-26 13:55:02 +02:00
Benjamin Otte
e79acf47a5 subsurface: Make CAIRO_SURFACE_TYPE_SUBSURFACE public 2010-08-26 12:55:39 +02:00
Benjamin Otte
40459dacb5 subsurface: Don't crash when the device transform isn't integer
Apply the transform before rounding to integer coordinates, so we can
handle doubles easily.
2010-08-26 11:45:28 +02:00
Benjamin Otte
e19b213e84 subsurface: Make subsurfaces their own type
Do not try to hide being a subsurface.
This would cause confusion when users where calling surface-type
specific getters on subsurfaces.

FIXME: We still need public API to access a subsurface's target though.
2010-08-26 11:20:36 +02:00
Benjamin Otte
e65bf64c4a subsurface: Properly account for device offsets in the target 2010-08-26 11:20:36 +02:00
Chris Wilson
eb85ab998b subsurface: Don't assume we ever own the target.
Andrea pointed out that snapshots can be shared, and so the subsurface
should not be calling finish even on a snapshot.
2010-07-10 11:16:19 +01:00
Benjamin Otte
448653e7b9 Call _cairo_error() when setting the FINISHED error on surfaces 2010-07-05 22:42:08 +02:00
Benjamin Otte
6744b78de1 subsurface: Fail if created from a finished surface
Caught by api-special-cases test
2010-07-05 18:38:33 +02:00
Chris Wilson
97a88c5adb xlib: Compile without fontconfig
Create a cairo-fontconfig-private.h where we can add the missing defines
in a common location rather than in the body of the code.
2010-06-28 17:11:54 +01:00
Chris Wilson
ad8abc0110 subsurface: Don't double apply device offset for deep subsurfaces.
If we have a subsurface of a subsurface then the device offset has
already been applied to the extents that we use to offset the new
subsurface.
2010-05-08 18:24:48 +01:00
Chris Wilson
b9e9ff5934 subsurface: Include device offset in extents
Adjust the subsurface extents so that the user specifies the extents in
world space rather than device space.
2010-05-07 11:25:03 +01:00