Commit graph

223 commits

Author SHA1 Message Date
Uli Schlachter
009d75b8db xcb: remove free pixmap/gc wrappers
With the last commit, these became pointless. Just switch the code to
call the underlying function directly.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2021-05-02 19:30:28 +02: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
Uli Schlachter
bfc243ca52 xcb: Fix error reporting if fallback fails
If we cannot let the X11 server do some operation (for example: the
RENDER extension is not available), then we fall back to an image
surface and do the operation locally instead. This fallback requires the
current content of the surface to be downloaded from the X11 server.
This fallback logic had an error.

The fallback is implemented with _get_image() in the function
_cairo_xcb_surface_fallback(). _get_image() is only called if we do not
yet have a fallback available, so when we call _get_image we have
surface->fallback == NULL. Then, if _get_image() fails, it returns a
surface in an error state.

Before this patch, the code would then just ignore this error surface
and return &surface->fallback->base, a NULL pointer. This would then
quickly cause a crash when e.g. the surface's ->status member is
accessed.

Fix this by returning the error surface instead as the fallback.

The end result of this patch will be that the XCB surface that is
currently drawn to ends up in an error state which is a lot better than
a NULL pointer dereference and actually correct in this case. The error
state is reached because the current drawing operation will fail and
this error is reported up the call stack and eventually "taints" the
surface.

(However, the error code could be better: _get_image() too often fails
with a generic CAIRO_STATUS_NO_MEMORY error, but that's left as future
work)

Signed-off-by: Uli Schlachter <psychon@znc.in>
2017-05-30 18:04:38 +02: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
Uli Schlachter
25a55822b4 xcb: Fix _put_image_boxes() if no SHM is available
This function tries to use _cairo_xcb_connection_put_image() to do the actual
work. However, that function can only be used for images with "native" stride.
If we only want to upload a rectangle from within an image, the function
_cairo_xcb_connection_put_subimage() has to be used. This function makes sure
that the correct information is sent to the X11 server.

No unit test for this, because we currently do not test the !SHM case
automatically. Perhaps we should?

Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-10-14 14:26:47 +02:00
Uli Schlachter
d31dc73f9b xcb: Fix _put_shm_image_boxes if no SHM available
This function always returned CAIRO_INT_STATUS_SUCCESS, even if it didn't do
anything. This commit makes the function return CAIRO_INT_STATUS_UNSUPPORTED
instead.

No unit test for this, because we currently do not test the !SHM case
automatically. Perhaps we should?

Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-10-14 14:26:32 +02:00
Lukáš Lalinský
e691d242d5 xcb: Initialize font options from Xft resources
There is a similar code in the Xlib backend. The logic here is the same, but
XCB doesn't support X resources directly, so there is some custom code
to get and parse the resources from the root window.

Signed-off-by: Lukáš Lalinský <lukas@oxygene.sk>
Reviewed-by: Uli Schlachter <psychon@znc.in>
2014-09-12 18:19:44 +02:00
Ravi Nanjundappa
be62b12211 xcb: make use of _cairo_surface_is_xcb to check for surface type
Introduced a new inline function _cairo_surface_is_xcb() as similar to
_cairo_surface_is_image() and used the same to check for xcb surface
type

Signed-off-by: Ravi Nanjundappa <nravi.n@samsung.com>
2014-07-07 03:53:13 -07:00
Uli Schlachter
9c75065ece xcb: Remove useless error handling
All the *_reply() functions in XCB return a pointer to their result and as last
argument they get a xcb_generic_error_t** where pointers to errors are stored,
if any occurs.

However, a request can either fail or succeed. This means that if the returned
result is a NULL pointer, then an error occurred and the other way around: If
the error pointer is set to non-NULL, then the function must have returned NULL.

Thus, all the code, which just checks if an error occurred and which does not
care about the exact error code, does not need to get the error pointer at all.
In this case, xcb will free() the error internally.

While doing this, I noticed that _cairo_xcb_connection_get_image() always
succeeds and thus its return value can be replaced with the GetImage result.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2013-09-16 12:59:03 +02:00
Uli Schlachter
0251f0951d xcb: Clear the result of create_similar_image
The documentation of cairo_surface_create_similar_image() states that the
image's contents are initially all 0. However, the implementation didn't live up
to the documentation.

This was found via the corresponding assert in
cairo_surface_create_similar_image().

There are some cairo-xcb-internal users of this function which cleared the image
right after creating it. Obviously, this isn't needed anymore.

Fixes: Nothing. The existing call in the testsuite to
cairo_surface_create_similar_image() doesn't hit this issue, since it creates a
too small image to hit the SHM-case.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2012-10-06 15:00:51 +02:00
Uli Schlachter
de31018bdd xcb: Switch to compositor architecture
This commit removes the hand-written code in cairo-xcb-surface.c and instead
makes use of cairo_compositor_t. Surprisingly, this doesn't break a single test
case. :-)

Signed-off-by: Uli Schlachter <psychon@znc.in>
2012-09-24 09:44:10 +02:00
Uli Schlachter
6300579a8b xcb: Remove unimplemented cairo compositor
Signed-off-by: Uli Schlachter <psychon@znc.in>
2012-09-24 09:44:10 +02:00
Uli Schlachter
8d86ea4dcb xcb: Fix a warn_unused_result warning
cairo-xcb-surface.c: In function '_drawable_changed':
cairo-xcb-surface.c:1434:39: warning: ignoring return value of '_cairo_surface_begin_modification', declared with attribute warn_unused_result [-Wunused-result]

Signed-off-by: Uli Schlachter <psychon@znc.in>
2012-09-24 09:42:43 +02:00
Chris Wilson
77330f6b84 xcb: Always flush the fallback damage to foreign drawables
We need to flush any fallback to a foreign drawable upon finish.
However, we must be careful not to attach the snapshot in that case or
else we end up with an expected reference. This is similar to the
treatment of xlib/shm in commit f864e2d70.

Reported-by: Henry Song <henry.song@samsung.com>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2012-09-11 18:24:33 +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
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
a18506acf0 Update the remaining backends to handle a NULL extents for _cairo_surface_get_source
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2012-04-27 22:13:01 +01:00
Chris Wilson
57cfdfd979 Split cairo-list 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 13:17:29 +01:00
Uli Schlachter
c77112c546 xcb: Fix SHM in _get_image()
Commit 2283ab9 introduced a logic error. Instead of falling back to the non-SHM
path when getting the image via SHM failed, we now did the fallback when getting
the image via SHM worked (which means that the SHM operation was a waste of
time).

Signed-off-by: Uli Schlachter <psychon@znc.in>
2012-04-02 21:02:24 +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
Uli Schlachter
c4d1063e03 xcb/xlib: Add missing "Since: 1.12"
Signed-off-by: Uli Schlachter <psychon@znc.in>
2012-03-26 20:17:10 +02: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
9e4fb906b8 xcb: Add dimension guards to create-similar-image
Just create a image wrapper for a 0x0 surface, and do not try to create
an image surface that is larger than the maximum X coordinate.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2012-01-11 12:43:44 +00:00
Uli Schlachter
9ec5e9fee6 xcb: Fixup some internal state in set_{drawable,size}
Signed-off-by: Uli Schlachter <psychon@znc.in>
2011-12-05 22:48:56 +01:00
Chris Wilson
9156339295 xcb: Silence a compiler warning for mixing status and internal status enums
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2011-12-02 15:31:51 +00:00
Keith Packard
b9d4a5f106 Add cairo_xcb_surface_set_drawable
Mirrors cairo_xlib_surface_set_drawable, allowing the drawable
targeted by a surface to be changed on the fly.

Signed-off-by: Keith Packard <keithp@keithp.com>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2011-12-02 15:31:51 +00:00
Keith Packard
d5c7d2e2f4 cairo-xcb: gtk-doc doesn't like _ in parameter names
Any function documented with gtk-doc must not have _ in any parameter
names, or at least that's what I've found. This patch simply renames
parameters as needed to make things work.

Signed-off-by: Keith Packard <keithp@keithp.com>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2011-12-02 15:31:50 +00:00
Andrea Canciani
adb5eb6f69 xcb: Fix typo 2011-11-18 12:23:02 +01:00
Chris Wilson
2283ab9698 xcb: Handle SHM exhaustion gracefully
Avoid the assertion failure of creating an error surface for an internal
status by handling the expected UNSUPPORTED condition.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2011-11-18 10:01:55 +00:00
Uli Schlachter
f162f7ebb4 xcb: Fix device offsets with unmap_image()
The source and target x/y coordinates were swapped. No idea why this only now
caused a test suite failure, perhaps something recently started using SHM?

Fixes: map-bit-to-image, map-to-image-fill

Signed-off-by: Uli Schlachter <psychon@znc.in>
2011-09-22 22:26:09 +02:00
Uli Schlachter
880321ae9d xcb: Fix a "incompatible pointer" compiler warning
cairo-xcb-surface.c:790:2: warning: return from incompatible pointer type

Signed-off-by: Uli Schlachter <psychon@znc.in>
2011-09-22 22:24:58 +02:00
Uli Schlachter
87fdc4356f xcb: Don't try to fallback more than once
This fixes the following assert for pretty much every single xcb-fallback test:

cairo-xcb-surface.c:320: _get_image: Assertion `surface->fallback == ((void *)0)' failed.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2011-09-22 20:46:24 +02:00
Chris Wilson
fd613cb9f9 xcb: track fallback damage
And only upload the parts of the image that are modified during the
fallback. I have to keep reminding myself that the goal is always to
reduce the amount of fallbacks required...

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2011-09-19 15:23:57 +01:00
Uli Schlachter
af11d26752 xcb: Remove some dead code
surface->use_pixmap always had the value 0. This code is taken from cairo-xlib.
However, in cairo-xlib use_pixmap is set to 20 if XGetImage() fails.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2011-09-14 15:21:37 +02: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
Uli Schlachter
968eb30bba xcb: Steal from the pending list for GetImage
Before using some piece of SHM again, we must be sure that the X11 server is no
longer working with it. For this, we send a GetInputFocus when we are done with
the SHM locally and will only use the memory again when the reply comes in.

However, if we are allocating the memory for SHM GetImage, then we can re-use
memory earlier, because the server processes requests in order. So it will only
start writing to the memory after it is done with earlier requests for this
memory. So instead of using GetInputFocus for synchronisation, the SHM GetImage
request will automatically do this for us.

Thanks to Chris Wilson for this idea.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2011-09-02 15:21:20 +02:00
Uli Schlachter
73e7391e6e xcb: Handle SHM exhaustion via falling back
When we couldn't get an image from the X11 server via SHM because we ran out
shared memory, we should try again via a normal GetImage request.

Fixes: xcb-huge-image-shm

Signed-off-by: Uli Schlachter <psychon@znc.in>
2011-08-18 16:34:44 +02:00
Uli Schlachter
8951c51d9e xcb: Merge two functions for creating shm images
This merges most of _cairo_xcb_surface_create_similar_image() into
_cairo_xcb_shm_image_create().

These two functions where already doing almost the same thing with only some
differences in error handling.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2011-08-18 16:34:44 +02:00
Uli Schlachter
0da3d3efd2 xcb: Fallback to image if allocating SHM fails
This turns an !!!ERROR!!! for scale-offset-similar with xcb-fallback into a
failed test and might fix other problems. However, since the problem here partly
is a race, those other problems might only be hit sometimes.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2011-08-18 16:34:44 +02: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
ad3ef3a8fb Silence Clang static analyzer reports
Clang static analysis triggers some reports in non-buggy code.

Silence them trying to follow better coding practices.
2011-07-29 11:54:56 +02:00
Uli Schlachter
e06a3b9761 xcb: Handle fallback in map_to_image
Fixes (for xcb-fallback): map-all-to-image map-bit-to-image map-to-image-fill

Signed-off-by: Uli Schlachter <psychon@znc.in>
2011-07-29 10:29:47 +02:00
Uli Schlachter
27702768bf xcb: _get_image only works without fallback
This turns the test suite-failures for map-all-to-image map-bit-to-image
map-to-image-fill with xcb-fallback into failed assertions.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2011-07-29 10:18:55 +02:00
Uli Schlachter
1beab6cca4 xcb: Handle deferred clear in map_to_image
Fixes: map-all-to-image map-bit-to-image map-to-image-fill

Signed-off-by: Uli Schlachter <psychon@znc.in>
2011-07-29 10:10:42 +02:00
Uli Schlachter
8877ca23f5 xcb: Check that the extents are inside our surface
The previous commit fixed a bug in cairo-xlib found by a similar assert, so this
seems to be a good idea to have.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2011-07-27 19:52:58 +02:00
Chris Wilson
91faf9c1cf composite: Pass unbounded extents to initialisation
For an unbounded surface we cannot assume (0, 0, surface_width,
surface_height) as that is wrong and causes the operation to appear
clipped.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2011-07-26 16:00:43 +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
Uli Schlachter
e2150185fc xcb: Unset the deferred_clear flag on fallback
Signed-off-by: Uli Schlachter <psychon@znc.in>
2011-07-21 19:24:38 +02:00
Uli Schlachter
de686f1938 xcb: Handle deferred_clear in _get_image
Fixes: arc-infinite-loop clip-all clip-empty-group clip-fill-no-op
pattern-getters

Signed-off-by: Uli Schlachter <psychon@znc.in>
2011-07-21 19:24:38 +02:00