Commit graph

169 commits

Author SHA1 Message Date
Chris Wilson
bed8239f03 [cairo-error] Clean up all the warnings and missing _cairo_error() calls.
Every time we assign or return a hard-coded error status wrap that value
with a call to _cairo_error(). So the idiom becomes:
    status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
or
    return _cairo_error (CAIRO_STATUS_INVALID_DASH);

This ensures that a breakpoint placed on _cairo_error() will trigger
immediately cairo detects the error.
2007-10-04 13:31:44 +01:00
Chris Wilson
71120727e1 [cairo-atomic] Use an atomic operation to set the status on a shared resource.
Since the objects can be shared and may be in use simultaneously across
multiple threads, setting the status needs to be atomic. We use a
locked compare and exchange in order to avoid overwriting an existing
error - that is we use an atomic operation that only sets the new status
value if the current value is CAIRO_STATUS_SUCCESS.
2007-10-04 11:26:44 +01:00
Chris Wilson
8ad56b308a [malloc/error] Add call to _cairo_error() after a failed malloc.
Blitz all allocations to ensure that they raise a
_cairo_error(CAIRO_STATUS_NO_MEMORY) on failure.
2007-10-04 00:42:30 +01:00
Chris Wilson
e49bcde27f [malloc] Check for integer overflow when realloc'ing.
Perform similar sanity checks to Vlad's _cairo_malloc_ab() but on the
arguments to realloc instead.
2007-10-04 00:42:29 +01:00
Chris Wilson
03be41151d [cairo-atomic] Rewrite reference counting using atomic ops.
Introduce an opaque cairo_reference_count_t and define operations on it
in terms of atomic ops. Update all users of reference counters to use
the new opaque type.
2007-09-25 16:29:54 +01:00
Vladimir Vukicevic
93aee43690 Fix previous create_similar fallback patch
We can't use composite, as some backends don't implement it.
Use paint() instead.
2007-08-28 16:47:24 -07:00
Carl Worth
a9662d0aae Eliminate fragile cairo_internal_format_t
Instead we take advantage of the pixman_format_code_t
that now exists in the public interface of the new, external
pixman library.
2007-08-21 17:10:49 -07:00
Chris Wilson
50ebdda3a9 [cairo-pattern] Assert that the pattern->matrix is invertible.
We guarantee when setting the pattern->matrix that it is invertible, so
merely assert that it is so when we attempt to use its inverse.
2007-08-16 15:12:00 +01:00
Carl Worth
13cae8b5e6 Ensure that a copied pattern gets its own user_data array
This fixes the bug reported here:

	Segfault with cairo_pattern_set_user_data
	https://bugs.freedesktop.org/show_bug.cgi?id=11855
2007-08-06 11:06:47 -07:00
Vladimir Vukicevic
c0a7d33ac6 [fixpt] Fixup malloc usage to use _cairo_malloc_*
Fix some introduced mallocs as a result of the fixed point patches.
2007-07-18 22:46:46 +02:00
Vladimir Vukicevic
b719592428 [fixpt] Fix up compilation post pixman merge 2007-07-18 22:46:46 +02:00
Vladimir Vukicevic
0abe5324a5 [fixpt] Create cairo_region wrapper around pixman_region16_t
Insulate region-using code from implementation details;
at some point we'll want to switch to using 32-bit regions.
2007-07-18 22:46:46 +02:00
Vladimir Vukicevic
aaf94ef6c4 [fixpt] remove dependency on some pixman types
Introduce cairo_gradient_stop_t, and remove pixman dependency
for core pattern types.  Perform conversion from cairo types
to pixman types as necessary in fallback code.
2007-07-18 22:45:21 +02:00
Vladimir Vukicevic
be3516335c [fixpt] Replace cairo_rectangle_int16_t with cairo_rectangle_int_t
Mostly s/cairo_rectangle_int16_t/cairo_rectangle_int_t/,
as well as definitions to pick cairo_rectangle_int_t.
2007-07-18 22:45:21 +02:00
Søren Sandmann Pedersen
ef967be630 Merge branch 'master' of git+ssh://sandmann@git.freedesktop.org/git/cairo
Conflicts:

	pixman/src/fbcompose.c
	pixman/src/icimage.c
	pixman/src/pixmanint.h
	pixman/src/pixregionint.h
	src/cairo-clip.c
2007-07-02 08:33:29 -07:00
Vladimir Vukicevic
5c7d2d14d7 [fix] Avoid int overflow when allocating large buffers
This patch introduces three macros: _cairo_malloc_ab,
_cairo_malloc_abc, _cairo_malloc_ab_plus_c and replaces various calls
to malloc(a*b), malloc(a*b*c), and malloc(a*b+c) with them.  The macros
return NULL if int overflow would occur during the allocation.  See
CODING_STYLE for more information.
2007-06-29 09:46:08 -07:00
Søren Sandmann
0c42dbb192 pixman_image_set_transform() returns FALSE on failure 2007-06-21 22:21:11 -07:00
Søren Sandmann
ca5760a289 Fix initialization of radial patterns 2007-06-21 22:21:11 -07:00
Søren Sandmann
12cc32b674 [pixman] Initial port to standalone pixman library. 2007-06-21 22:21:11 -07:00
Kouhei Sutou
0898411d0a [doc] Minor documentation fixes 2007-05-28 17:05:40 -04:00
Chris Wilson
f382c3e110 [cairo-pattern] Fully initialise the error pattern.
_cairo_pattern_fini depends on the pattern being correctly initialised,
for example when calling _cairo_user_data_array_fini(), so we need to
initialize the whole pattern and not just set the type to SOLID when
creating a pattern for a surface in error.
2007-05-25 12:15:48 +01:00
Carl Worth
2c8598aafb Fix typo in comment. 2007-05-18 13:23:04 -07:00
Carl Worth
3cb67435f8 Document behavior of color stops added with identical offsets. 2007-05-18 13:22:36 -07:00
Chris Wilson
79e6c0207c [cairo-pattern] Check for the nil surface.
cairo_surface_create_similar() does not return NULL as was being checked
for, but the nil surface on error. Also ensure that the returned surface
is destroyed if we encounter an error whilst compositing.
2007-05-16 16:06:26 +01:00
Chris Wilson
ebababc0cf [cairo-pattern] Return the nil cairo_pattern_t for CAIRO_STATUS_NO_MEMORY.
If we asked to create a pattern after encountering an allocation failure,
we can avoid another allocation by returning the nil pattern object.
2007-05-10 21:03:03 +01:00
Chris Wilson
8ddfc1b2e4 [cairo-pattern] Return status from _cairo_pattern_init_copy()
During the copy, allocation of the gradient may fail and so the callers
need to check for a pattern that returned in an error state. No callers
did so and in order to force all callers to check the error status,
the status return was added to _cairo_pattern_init_copy().  The early
error checking may appear redundant for an object with an embedded
structure, however it does fix an error where an uninitialised pattern
was being used:

==1922== Process terminating with default action of signal 11 (SIGSEGV)
==1922==  Access not within mapped region at address 0x55555555
==1922==    at 0x402CF6F: _cairo_array_index (cairo-array.c:208)
==1922==    by 0x402D4F3: _cairo_user_data_array_fini (cairo-array.c:370)
==1922==    by 0x4046464: _cairo_pattern_fini (cairo-pattern.c:188)
==1922==    by 0x404992A: _cairo_meta_surface_paint (cairo-meta-surface.c:266)
==1922==    by 0x403FCE0: _cairo_surface_paint (cairo-surface.c:1331)
==1922==    by 0x405CB5E: _test_meta_surface_paint (test-meta-surface.c:195)
==1922==    by 0x403FCE0: _cairo_surface_paint (cairo-surface.c:1331)
==1922==    by 0x4032A60: _cairo_gstate_paint (cairo-gstate.c:822)
==1922==    by 0x402B2D1: cairo_paint (cairo.c:1879)
==1922==    by 0x804A4F7: draw (radial-gradient.c:73)
==1922==    by 0x804AFA4: cairo_test_expecting (cairo-test.c:326)
==1922==    by 0x804A57C: main (radial-gradient.c:109)
==1922== Injected fault at:
==1922==    at 0x4020EA5: malloc (vg_replace_malloc.c:207)
==1922==    by 0x404475C: _cairo_pattern_init_copy (cairo-pattern.c:136)
==1922==    by 0x403F779: _cairo_surface_copy_pattern_for_destination (cairo-surface.c:2153)
==1922==    by 0x403FCC1: _cairo_surface_paint (cairo-surface.c:1328)
==1922==    by 0x405CB5E: _test_meta_surface_paint (test-meta-surface.c:195)
==1922==    by 0x403FCE0: _cairo_surface_paint (cairo-surface.c:1331)
==1922==    by 0x4032A60: _cairo_gstate_paint (cairo-gstate.c:822)
==1922==    by 0x402B2D1: cairo_paint (cairo.c:1879)
==1922==    by 0x804A4F7: draw (radial-gradient.c:73)
==1922==    by 0x804AFA4: cairo_test_expecting (cairo-test.c:326)
==1922==    by 0x804A57C: main (radial-gradient.c:109)
2007-05-09 10:14:20 +01:00
Chris Wilson
c441938569 [cairo-pattern] Cleanly handle an invalid pattern in cairo_pattern_transform()
Simply return without writing to potentially read-only members of an
invalid pattern rather than assert. This is cleaner than tracking down
all the error paths that may call into cairo_pattern_transform()...
2007-05-08 21:41:09 +01:00
Chris Wilson
056d149212 [cairo-pattern] Don't cache fallback surfaces
_cairo_surface_create_similar_solid() may return an image surface,
should the backend not support the required content or should it
encounter an error whilst creating the surface. In those circumstances
we choose not to cache the fallback surface.
2007-05-04 14:29:48 +01:00
Chris Wilson
a8c8e17d84 [cairo-pattern] Cache surface for solid patterns
Original work by Jorn Baayen <jorn@openedhand.com>,
2715f20981

We use a small cache of size 16 for surfaces created for solid patterns.
This mainly helps with the X backends where we don't have to create a
pattern for every operation, so we save a lot on X traffic.  Xft uses a
similar cache, so cairo's text rendering traffic with the xlib backend
now completely matches that of Xft.

The cache uses an static index variable, which itself acts like a cache of
size 1, remembering the most recently used solid pattern.  So repeated
lookups for the same pattern hit immediately.  If that fails, the cache is
searched linearly, and if that fails too, a new surface is created and a
random member of the cache is evicted.

A cached surface can only be reused if it is similar to the destination.
In order to check for similar surfaces a new test is introduced for the
backends to determine that the cached surface is as would be returned by
a _create_similar() call for the destination and content.

As surfaces are in general complex encapsulation of graphics state we
only return unshared cached surfaces and reset them (to clear any error
conditions and graphics state). In practice this makes little difference
to the efficacy of the cache during various benchmarks. However, in order
to transparently share solid surfaces it would be possible to implement a
COW scheme.

Cache hit rates:    (hit same index + hit in cache) / lookups
cairo-perf:         (42346 + 28480) / 159600 = 44.38%
gtk-theme-torturer: (3023  + 3502)  / 6528   = 99.95%
gtk-perf:           (8270  + 3190)  / 21504  = 53.29%

This translates into a reduction of about 25% of the XRENDER traffic during
cairo-perf.
2007-05-04 14:29:38 +01:00
Carl Worth
29670d3766 Add a content value to solid patterns
This allows for the surface acquired from the pattern to have the
same content. In particular, in a case such as cairo_paint_with_alpha
we can now acquire an A8 mask surface instead of an ARGB32 mask
surface which can be rendered much more efficiently. This results
in a 4x speedup when using the OVER operator with the recently
added paint-with-alpha test:

Speedups
========
image-rgb  paint-with-alpha_image_rgb_over-256 2.25 -> 0.60: 4.45x speedup
███▌

It does slowdown the same test when using the SOURCE operator, but
I don't think we care. Performing SOURCE with a mask is already a very
slow operation, (hitting compositeGeneral), so the slowdown here is
likely from having to convert from A8 back to ARGB32 before the
generalized compositing. So if someone cares about this slowdown,
(though SOURCE with cairo_paint_with_alpha doesn't seem extremely
useful), they will probably be motivated enough to contribute a
customized compositing function to replace compositeGeneral in which
case this slowdown should go away:

image-rgba paint-with-alpha_image_rgb_source-256 3.84 -> 8.86%: 1.94x slowdown
█
2007-04-25 11:09:31 -07:00
Chris Wilson
41c6eebcd1 Optionally provide a pattern to use for creating a similar solid surface.
_cairo_surface_create_similar_solid() creates a fresh pattern to wrap
color, however sometimes the caller already has that pattern available.
In those circumstances we can pass the pattern as well as the color and
avoid the extra allocation.
2007-04-19 11:56:15 +01:00
Chris Wilson
9cf0955633 Create opaque similar solid surfaces when possible.
For opaque surfaces the backends may use simpler code paths - for
example, the xlib backend may be able to use the Core protocol rather
than Render. So we only generate a surface with an alpha component if
the color is not opaque.
2007-04-19 09:30:28 +01:00
Chris Wilson
f7b6fc4746 Define a CAIRO_ALPHA_IS_OPAQUE variant that operates on uint16.
Introducing this variant also fixed a bug in _gradient_is_opaque()
which was using the fractional test on a uint16.
2007-04-19 09:30:15 +01:00
Behdad Esfahbod
84c10a79ff [cairo-pattern] Slightly hackish fix for bug #10508
The so-attributed-to-X-server bug was that cairo maps the drawing
region to the pattern space, rounds the box, and uploads only that
part of the source surface to the X server.  Well, this only works for
NEAREST filter as any more sophisticated filter needs to sneak a peek
at the neighboring pixels around the edges too.

The right fix involves taking into account the filter used, and the
pattern matrix, but for most cases, a single pixel should be enough.
Not sure about scaling down...

Anyway, this is just a workaround to get 1.4.4 out of the door.  I'll
commit a proper fix soon.
2007-04-13 16:33:33 -04:00
Behdad Esfahbod
4e3be54861 [cairo-pattern] Add a TODO item to code 2007-04-12 21:38:25 -04:00
Carl Worth
a6186604f7 cairo_pattern_set_matrix: Validate that matrix is invertible
If not, set an error in the pattern.
2007-04-11 01:21:10 -07:00
Carl Worth
bff45ec9f9 Invert condition to more intuitive form.
The idiom for checking the return value of malloc is:

	if (pointer == NULL) { ... }

rather than:

	if (pointer != NULL) { ... }
2007-04-10 10:14:49 -07:00
Carl Worth
01955a6e82 Rename ARRAY_LEN to ARRAY_LENGTH
Yet another victim in my hunt against abbreviations within cairo's implementation.
2007-04-10 10:14:49 -07:00
Chris Wilson
ac33953a81 Correct handling of a malloc failure during pattern_create_in_error()
Confusion had been introduced as to who provided the fixup after
the malloc failed which resulted in a NULL deference whilst checking for
an erroneous pattern in _cairo_pattern_create_in_error.
2007-04-09 16:47:38 -07:00
Chris Wilson
b32a5b1dc6 cairo-pattern - propagate status
Catch, cleanup and propagate after an error return.
2007-04-09 15:05:35 +01:00
Behdad Esfahbod
88dc0c5f19 Make sure all nil objects start with _cairo_
Previously, the convention was that static ones started with cairo_, but
renamed to start with _cairo_ when they were needed from other files and
became cairo_private instead of static...

This is error prune indeed, and two symbols were already violating.  Now
all nil objects start with _cairo_.
2007-04-03 19:26:18 -04:00
Chris Wilson
256f3e09a8 Destroy the current pattern before replacing with cairo_set_source().
Frequently cairo_set_source_rgb[a]() is used to replace the current
solid-pattern source with a new one of a different colour. The current
pattern is very likely to be unshared and unmodified and so it is likely
just to be immediately freed [or rather simply moved to recently freed
cache]. However as the last active pattern it is likely to cache-warm and
suitable to satisfy the forthcoming allocation. So by setting the current
pattern to 'none' we can move the pattern to the freed list before we
create the new pattern and hopefully immediately reuse it.
2007-03-26 20:58:14 +01:00
Chris Wilson
38442d4948 Back out the solid-pattern-cache from 9b53bc7c65.
Unfortunately one cannot cache live patterns and return a fresh reference
instead of creating new ones as patterns can be modified by the user and
so cannot be transparently shared between different users. However,
solid colour allocation is still a frequent operation, so we maintain a
small cache of recently freed patterns to reduce the malloc pressure.
2007-03-26 20:57:53 +01:00
Behdad Esfahbod
bd275c1978 [cairo-pattern] Make sure cached solid patterns are not put in error status 2007-03-21 12:34:37 -04:00
Behdad Esfahbod
ad51ee5aa0 Define and use ARRAY_LEN 2007-03-20 18:59:19 -04:00
Chris Wilson
9b53bc7c65 Cache solid patterns
We use a small cache of size 16 for patterns created from solid colors,
e.g. cairo_set_source_rgb(). This helps with toolkits that draw many
widgets using the same colour scheme.

The cache uses a static index variable, which itself acts like a cache
of size 1, remembering the most recently used colour. So repeated
lookups for the same colour hit immediately. If that fails, the cache
is searched linearly, and if that fails too, a new pattern is created
and a random member of the cache is evicted.
2007-03-20 18:21:53 -04:00
Mathias Hasselmann
c4bd7cf6f8 Move declaration of cairo_mutex_t to cairo-mutex-private.h 2007-03-20 13:32:33 +01:00
Mathias Hasselmann
be52178443 Initialize mutexes at central location.
All mutex declarations have been moved to cairo-mutex-list.h.
This should avoid breaking of less frequently tested backends,
when mutexes are introduced or when existing mutexes are renamed.

Instead of initializing mutexes on library startup, mutexes are
lazily initialized within the few entry points of now by calling
CAIRO_MUTEX_INITIALIZE(). Currently only the OS/2 backend takes
care about releasing global mutexes. Therefore there is no counter
part of that macro for finalizing all global mutexes yet - but
as cairo-backend-os2.c shows such a function would be quite
easy to implement.
2007-03-20 10:11:14 +01:00
Behdad Esfahbod
e803e2e69b [cairo-pattern] Add a cache of two color stops to cairo_gradient_pattern_t
Most of gradients have only two color stops.  This avoids
calling malloc() for those cases.
2007-03-14 17:24:54 -04:00
Behdad Esfahbod
4514fdca1b [cairo-pattern] Grow color-stops array exponentially 2007-03-14 17:24:54 -04:00