Commit graph

512 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
Heiko Lewin
518ba13779 Fix undefined left-shifts 2021-03-31 12:20:34 +02:00
Uli Schlachter
81806c0111 cairo-xlib: Check for maximum surface size
X11 use uint16_t for the width/height of things. Anything too large will
be truncated when sending the request to the X11 server. This commit
adds a size check to a function that did not check things and then later
caused a segmentation fault.

Not adding a test case because the test case from the below bug report
allocates 3,5 GiB of memory, which I find too much for a test.

Fixes: https://gitlab.freedesktop.org/cairo/cairo/-/issues/414
Signed-off-by: Uli Schlachter <psychon@znc.in>
2021-01-13 16:36:33 +01: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
Unknown
12cb59be7d Cairo trivial typos
Found using `codespell -q 3 -I cairo-whitelist.txt`
whereby whitelist contained:
```
amin
iff
lod
writen
```

Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
2018-04-02 17:46:58 -07:00
Uli Schlachter
10e4103a50 xlib: Call XSync() before ignoring errors
The code here wants to ignore errors for a specific request. To do so,
it sets a no-op error handler. However, it could happen that some
previous request caused an error and this error will also be ignored by
the no-op error handler.

To avoid this, call XSync() before setting the error handler. This makes
sure that all pending errors are handled.

Signed-off-by: Uli Schlachter <psychon@znc.in>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
2017-03-07 13:40:21 +01:00
Uli Schlachter
f02ee3d3cf xlib: Remove unused variable
This constant seems to be unused since commit af9fbd176b
from 2011.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2017-03-07 09:57:55 +01:00
Uli Schlachter
d69dd6b341 xlib: Fix double free in _get_image_surface()
If XShmGetImage() fails, the code tries to continue with its normal,
non-shared-memory path. However, the image variable, which was previously set to
NULL, now points to an already-destroyed surface, causing a double-free when the
function cleans up after itself (actually, its an assertion failure because the
reference count of the surface is zero, but technically this is still a double
free).

Fix this by setting image=NULL after destroying the surface that this refers to,
to make sure this surface will not be destroyed again.

While we are here (multiple changes in a single commit are bad...), also fix the
cleanup done in bail. In practice, &image->base should be safe when image==NULL,
because this just adds some offset to the pointer (the offset here is actually
zero, so this doesn't do anything at all). However, the C standard does not
require this to be safe, so let's handle this case specially.

Note that anything that is fixed by this change is still buggy, because the only
reason why XShmGetImage() could fail would be BadDrawable, meaning that the
target we draw to does not exist or was already destroyed. This patch will
likely just cause X11 errors elsewhere and drawing to (possible) invalid
drawables is not supported by cairo anyway. This means that if SHM fails, the
following fallback code has a high chance of failing, too.

Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=91967
Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-06-19 11:34:35 +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
Chris Wilson
054f34111d Provide backwards compatibilty with old pixman
The goal is to allow compilation against older pixman to ease regression
testing.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2013-08-23 12:53:27 +01:00
egag
793f8223d4 xlib: Aquire display before using it in DEBUG message. 2013-04-25 09:03:02 +01:00
Chris Wilson
fd59e6d86a xlib/shm: Always request a CompletionEvent from ShmPutImage
...and treat is as an expected event for synchronisation.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2013-01-29 03:00:46 +00:00
Chris Wilson
fa4f48cccb xlib: Do not upload the whole image just because we want an entire row
Fixes regression exposed by

commit a73e7ff018
Author: Chris Wilson <chris@chris-wilson.co.uk>
Date:   Sun Jan 6 11:29:27 2013 +0000

    xlib: Simplify source creation by use of map-to-image

but ultimately from

commit 74941f8220
Author: Chris Wilson <chris@chris-wilson.co.uk>
Date:   Wed Jan 2 22:27:55 2013 +0000

    xlib: Use SHM transport for ordinary image uploads

Reported-by: Gökçen Eraslan <gokcen.eraslan@gmail.com>
Reported-by: Guillaume Ayoub <guillaume.ayoub@kozea.fr>
Reported-by: Emmanuel Benisty <benisty.e@gmail.com>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=59635
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2013-01-23 15:09:35 +00:00
Chris Wilson
74941f8220 xlib: Use SHM transport for ordinary image uploads
In theory this should just save a single copy, however PutImage will
break up requests into a series of scanlines requests which is less
efficient than the single-shot transfer provided by ShmPutImage.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2013-01-03 12:28:33 +00:00
Chris Wilson
71028865fa Revert "xlib/shm: Do not trigger a surplus event from XShmPutImage"
This reverts commit c97f2d4acd.

Testing suggests that keeping that event is a win; so do so.
2012-12-29 15:05:53 +00:00
Chris Wilson
c97f2d4acd xlib/shm: Do not trigger a surplus event from XShmPutImage
As our lazy event mechanism is sufficient for tracking when to reuse shm
memory, and the events are not necessary for ShmPut/ShmGetImage paths.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2012-12-29 14:56:24 +00:00
Weng Xuetian
59248fb262 xlib: Reset fallback counter when discarding the fallback
References: https://bugs.freedesktop.org/show_bug.cgi?id=54657
2012-09-13 22:57:45 +01:00
Chris Wilson
5c59d989f9 xlib: Destroy the fallback damage along with the fallback surface
Whenever we discard the fallback surface, we need to destroy the
associated damage tracking, so move this into the common discard
routine.

This should fix the issue when trying to flush the fallback before
the user modifies any foreign Drawables. The current code issued the
flush and then explicitly discard the fallback, but unless it was idle
at the time of the flush the associated damage would not have also been
destroyed. Asserts followed.

References: https://bugs.freedesktop.org/show_bug.cgi?id=54657
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2012-09-13 22:54:18 +01:00
Chris Wilson
97282ef51a xlib: Do not call _cairo_xlib_surface_flush directly
Use the higher level layer to be sure we detach any snapshots and other
cached data that is invalidated along with the change of Drawable.

Pointed out by the eternally wise Uli Schlachter.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2012-09-13 17:00:24 +01:00
Chris Wilson
69d97d97be xlib: Force the fallback flush before updating the external Drawable
_cairo_surface_begin_modification() performs an internal flush, for
which the xlib backend skips flushing the fallback surface as it will
continue to use it for the subsequent operation. In the case where we
are flushing prior to updating the Drawable, we need to perform an
external flush which will trigger the posting of the damage from the
fallback surface.

Reported-by: Weng Xuetian <wengxt@gmail.com>
References: https://bugs.freedesktop.org/show_bug.cgi?id=54657
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2012-09-13 16:45:46 +01:00
Chris Wilson
6ee216000a xlib: Explicitly discard the fallback shm pixmap upon user modification
If the user changes the size of the underlying drawable, we much make
sure that we discard the current ShmPixmap in order to create a new
fallback pixmap of the correct size next time.

Reported-by: Weng Xuetian <wengxt@gmail.com>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2012-09-13 15:30:27 +01:00
Chris Wilson
e2c4bb9465 xlib: Fix regression in cairo_xlib_surface_set_drawable()
In commit 0bfd2acd35
Author: Chris Wilson <chris@chris-wilson.co.uk>
Date:   Mon Aug 13 01:34:12 2012 +0100

    xlib: Implement SHM fallbacks and fast upload paths

I made the mistake of inverting the logic for
cairo_xlib_surface_set_drawable() causing it then to never update.

Thanks to Uli Schlachter for spotting my error.

References: https://bugs.freedesktop.org/show_bug.cgi?id=54657
Reported-by: Weng Xuetian <wengxt@gmail.com>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2012-09-13 12:40:49 +01:00
Chris Wilson
f864e2d70f xlib/shm: Explicitly release shm surface if we do not own the pixmap
In this case we want to prevent the short-circuiting of the flush of the
ShmPixmap that is ordinarily performed during finish().

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2012-09-08 16:41:23 +01:00
Chris Wilson
fc38d7375d xlib/shm: Add missing release of the display after GetImage
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2012-08-24 17:39:35 +01:00
Chris Wilson
c068691ff5 xlib/shm: Use an impromptu upload ShmSegment
Reduce the number of copies required for uploading large image data.
Ultimately we want the client to allocate the similar-image itself to
acheive zero copy, this is just an intermediate step for legacy clients.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2012-08-17 23:43:26 +01:00
Chris Wilson
bc38108947 xlib/shm: Limit use of the impromptu fallback pixmap for uploads
We want to avoid unnecessary readback and so only want to use the
ShmPixmap when uploading the complete surface.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2012-08-17 23:20:01 +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
fe428fc7f0 xlib: Fix inline conversion for TrueColor PutImage
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2012-04-25 20:56:20 +01:00
Chris Wilson
9e81c5b737 xlib: Allow applications to create 0x0 surfaces
Although 0x0 is not a legimate surface size, we do allow applications
the flexibility to reset the size before drawing. As we previously never
checked the size against minimum legal constraints, applications expect
to be able to create seemingly illegal surfaces, and so we must continue
to provide backwards compatibility.

Many thanks to Pauli Nieminen for trawling through the protocol traces,
diving into the depths of libreoffice and identifying the regression.

Fixes https://bugs.freedesktop.org/show_bug.cgi?id=49118 (presentation
mode in loimpress is blank).

Reported-by: Eric Valette <eric.valette@free.fr>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2012-04-25 20:51:20 +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
Nis Martensen
80d1e68bb3 doc: do not use / in section title
The Title: field is used to determine the file name of the generated
html. Due to the slash a subdirectory is created and all relative links
in the generated file are broken.

Use a hyphen instead.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2012-04-16 21:55: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
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
16d6b938c8 doc: ensure "compatibility" spelling
This changes not only comments, but also code!

Signed-off-by: Uli Schlachter <psychon@znc.in>
2012-03-10 10:20:29 +01:00
Chris Wilson
cc09b29752 xlib: Tidy conversion of xrender format to cairo_content_t
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2012-02-23 13:44:28 +00:00
Chris Wilson
e5cb567f5d xlib: Trim the ximage to match the trimming of the intermediate
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2012-02-22 15:49:34 +00:00
Chris Wilson
5b107587e7 xlib: Correct the device-offset applied to the map-to-image result
A typo, a typo surely, to use extents->y twice instead of the more
normal x, y.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2012-02-22 15:13:26 +00:00
Chris Wilson
85110d9ce1 xlib: Trim the intermediate upload image to match the upload extents
Rather than transform the whole image, just convert the region of
interest.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2012-02-22 15:06:48 +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
c6c02f5194 xlib: Only reduce a readback of an uninitialised source for pixmaps
For a foreign drawable, we have to assume to that is dirty upon creation
or otherwise we fail to read back the correct pixel data when copying to
an image.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2012-02-02 02:08:19 +00:00
Chris Wilson
24445f9468 xlib: Set IncludeInferiors when acquiring the source image
If we need to fallback and perform a copy first to a pixmap for a
partially unviewable Window, we need to copy its inferiors as well.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2012-02-02 01:46:56 +00:00
Chris Wilson
a7c9c75ffa xlib: Improve choice of bits-per-pixel for depth
The only reliable method would be to query the xserver for the
matching bpp for a particular depth. In the absence of such information,
simply chose the next higher power-of-two(depth).

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2012-01-17 12:40:11 +00:00
Carlos Garcia Campos
8ddecc08a5 xlib: Check pixman format before trying to create an image surface for it 2011-10-27 18:13:29 +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
Chris Wilson
70cd3b473d api: Extend cairo_antialias_t to include performace/quality hints
The existing API only described the method to be used for performing
rasterisation and unlike other API provided no opportunity for the user
to give a hint as to how to trade off performance against speed. So in
order to no be overly prescriptive, we extend the NONE/GRAY/SUBPIXEL
methods with FAST/GOOD/BEST hints and leave the backend to decide how
best to achieve those goals.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2011-08-30 15:17:38 +01:00
Chris Wilson
236cb8aa22 xlib: Fix typo in snapshotting.
We want to only copy up to the maximum height, not width...

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2011-08-20 12:01:09 +01:00