Commit graph

185 commits

Author SHA1 Message Date
Carl Worth
36246c51ba Revert "_cairo_pattern_get_extents: Fix to allow for expansion based on filter"
This reverts commit 731e121c80.

This commit introduced various problems, (some likely noticeable
in the test suite, and others perhaps not). For some details, see
the latest comments in the original bug report leading to the
fix now being reverted:

	http://bugs.freedesktop.org/show_bug.cgi?id=15349
2008-04-07 16:09:06 -07:00
Carl Worth
d1fe008440 Document default extend modes 2008-04-06 02:17:09 -07:00
Carl Worth
731e121c80 _cairo_pattern_get_extents: Fix to allow for expansion based on filter
This fixes the filter-bilinear-extents test case and the
related bug entry:

	bad clipping with EXTEND_NONE
	http://bugs.freedesktop.org/show_bug.cgi?id=15349

Though there are still differences in the PDF and PostScript
backends, (primarily because we can't capture cairo's filter
modes in those file formats).
2008-04-04 19:00:28 -07:00
Carl Worth
04608952e2 Replace open-coded transformation with a call to _cairo_matrix_transform_bounding_box
It's a wonderful feeiling to remove duplicate code.
2008-04-04 18:56:38 -07:00
Carl Worth
75972167a2 Use floating-point offsets for color stops
Previously we were using the cairo_fixed_t type which meant we've
historically only been using 16 bits of precision for these offsets,
and recently only 8 bits. Meanwhile, all manipulatons of offsets
have been in floating-point anyway, so we might as well store them
that way.

This change also prevents a rendering regression introduced with the
24.8->16.16 change betwen snapshots 1.5.10 and 1.5.12 .

This change affected gradient-rendering details for the clip-operator
and operator-source tests, so the corresponding reference images are
updated here.
2008-03-26 14:52:09 -07:00
Chris Wilson
1dd894115e [cairo-pattern] Raise an error for _cairo_pattern_create_solid() failure.
Add a missing _cairo_error() for the malloc failure in
_cairo_pattern_create_solid().
2008-03-04 09:31:21 +00:00
Chris Wilson
914f4a3ec5 [cairo-pattern] Tidy usage of _cairo_error().
Remove the duplicate calls to _cairo_error() along the constructor
error paths and a missing call to _cairo_error().
2008-03-04 09:31:20 +00:00
Behdad Esfahbod
a55f65b5d2 [doc] Fix typo 2008-01-28 22:25:37 -05:00
Behdad Esfahbod
0d898f2bad [doc] Make sure all type names in docs are prefixed by # 2008-01-28 20:49:44 -05:00
Behdad Esfahbod
9ecde82d35 [doc] Make sure all macro names in docs are prefixed by % 2008-01-28 20:48:48 -05:00
Carl Worth
e48d7ca802 Add example to documentation of cairo_pattern_set_filter
It's helpful to let the reade know about cairo_get_source here.
2008-01-28 16:11:39 -08:00
Chris Wilson
481b88dd6b [cairo-pattern] Add an ASSERT_NOT_REACHED
On the default case for an unknown pattern type, add an assert that the
code is never reached, and just in case upgrade the error to a fatal
PATTERN_TYPE_MISMATCH.
2008-01-12 20:44:02 +00:00
Chris Wilson
2e5f278da1 [cairo-pattern] Free the copied pattern on error.
Free the locally allocated pattern if the copy fails.
2008-01-10 22:11:42 +00:00
Chris Wilson
02b0743458 [cairo-pattern] Rearrange CAIRO_MUTEX_INITIALIZE.
test/pattern-get-type exposes a bug whereby we try to acquire the
_cairo_pattern_solid_pattern_cache_lock before initializing the
mutexes. To fix this move the CAIRO_MUTEX_INITIALIZE() from the
depths of _cairo_pattern_init() and perform it at the public entry
points.
2008-01-10 17:10:30 +00:00
Adrian Johnson
6ead8feaf3 Add _cairo_pattern_create_copy() 2008-01-07 20:41:43 +10:30
Adrian Johnson
583059e4a3 Fix bug in _gradient_is_opaque() 2007-10-13 21:16:49 +09:30
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