Commit graph

104 commits

Author SHA1 Message Date
Chris Wilson
3fcac1ef21 [slope] Inline _cairo_slope_init()
Move the definition to a separate header file and allow callers to inline
the simple function.
2009-08-29 08:08:33 +01:00
Chris Wilson
3f12d9ec5d [clip] Use geometric clipping for unaligned clips
For the simple cases where the clip is an unaligned box (or boxes), apply
the clip directly to the geometry and avoid having to use an intermediate
clip-mask.
2009-08-29 08:08:33 +01:00
Chris Wilson
4051ed328b [tessellator] Special case rectilinear tessellation
For the frequent cases where we know in advance that we are dealing with a
rectilinear path, but can not use the simple region code, implement a
variant of the Bentley-Ottmann tessellator. The advantages here are that
edge comparison is very simple (we only have vertical edges) and there are
no intersection, though possible overlaps. The idea is the same, maintain
a y-x sorted queue of start/stop events that demarcate traps and sweep
through the active edges at each event, looking for completed traps.

The motivation for this was noticing a performance regression in
box-fill-outline with the self-intersection work:

  1.9.2 to HEAD^: 3.66x slowdown
  HEAD^ to HEAD:  5.38x speedup
  1.9.2 to HEAD:  1.57x speedup

The cause of which was choosing to use spans instead of the region handling
code, as the complex polygon was no longer being tessellated.
2009-08-29 08:08:29 +01:00
Chris Wilson
36480fe531 [traps] Increase exponential expansion factor.
Grow the traps more rapidly, as the allocations are very short-lived so
the over-allocation is less of an issue.
2009-08-29 08:08:28 +01:00
Chris Wilson
9d51c03bad [traps] Compute extents on demand. 2009-08-29 08:08:28 +01:00
Chris Wilson
f8bb3617c3 Eliminate self-intersecting strokes.
We refactor the surface fallbacks to convert full strokes and fills to the
intermediate polygon representation (as opposed to before where we
returned the trapezoidal representation). This allow greater flexibility
to choose how then to rasterize the polygon. Where possible we use the
local spans rasteriser for its increased performance, but still have the
option to use the tessellator instead (for example, with the current
Render protocol which does not yet have a polygon image).

In order to accommodate this, the spans interface is tweaked to accept
whole polygons instead of a path and the tessellator is tweaked for speed.

Performance Impact
==================

...
Still measuring, expecting some severe regressions.
...
2009-08-29 08:08:28 +01:00
Chris Wilson
bed2701e1c Remove clip handling from generic surface layer.
Handling clip as part of the surface state, as opposed to being part of
the operation state, is cumbersome and a hindrance to providing true proxy
surface support. For example, the clip must be copied from the surface
onto the fallback image, but this was forgotten causing undue hassle in
each backend. Another example is the contortion the meta surface
endures to ensure the clip is correctly recorded. By contrast passing the
clip along with the operation is quite simple and enables us to write
generic handlers for providing surface wrappers. (And in the future, we
should be able to write more esoteric wrappers, e.g. automatic 2x FSAA,
trivially.)

In brief, instead of the surface automatically applying the clip before
calling the backend, the backend can call into a generic helper to apply
clipping. For raster surfaces, clip regions are handled automatically as
part of the composite interface. For vector surfaces, a clip helper is
introduced to replay and callback into an intersect_clip_path() function
as necessary.

Whilst this is not primarily a performance related change (the change
should just move the computation of the clip from the moment it is applied
by the user to the moment it is required by the backend), it is important
to track any potential regression:

ppc:
Speedups
========
image-rgba         evolution-20090607-0    1026085.22 0.18% -> 672972.07 0.77%:  1.52x speedup
▌
image-rgba         evolution-20090618-0    680579.98 0.12% -> 573237.66  0.16%:  1.19x speedup
▎
image-rgba      swfdec-fill-rate-4xaa-0    460296.92 0.36% -> 407464.63  0.42%:  1.13x speedup
▏
image-rgba      swfdec-fill-rate-2xaa-0    128431.95 0.47% -> 115051.86  0.42%:  1.12x speedup
▏
Slowdowns
=========
image-rgba     firefox-periodic-table-0    56837.61 0.78% -> 66055.17    3.20%:  1.09x slowdown
▏
2009-07-23 15:32:14 +01:00
Søren Sandmann Pedersen
5d57aeaa23 Reinstate cairo_region_create_rectangles()
cairo_region_union_rectangle() is linear in the number of rectangles
in the region. There is no way to make it significantly faster without
losing the ability to return errors synchronously, so a
cairo_region_create_rectangles() is needed to avoid a large
performance regression.
2009-06-15 05:48:51 -04:00
Chris Wilson
132f44dce1 valgrindify init/fini routines
Annotate object init/fini routines to detect use-after-free for
on-stack/embedded objects.
2009-06-04 14:17:43 +01:00
Chris Wilson
1ae2ddc1dd [memfault] Manually inject faults when using stack allocations
Ensure that no assumptions are made that a small allocation will succeed
by manually injecting faults when we may be simply allocating from an
embedded memory pool.

The main advantage in manual fault injection is improved code coverage -
from within the test suite most allocations are handled by the embedded
memory pools.
2009-04-23 09:22:51 +01:00
Chris Wilson
c35d226f7d [traps] Propagate allocation failure.
Report failure to allocation region.
2009-03-30 10:46:37 +01:00
Søren Sandmann Pedersen
4b3245481c [region] Expand rect to rectangle in a couple of names
Specifically,

	cairo_region_union_rect  ->  cairo_region_union_rectangle
	cairo_region_create_rect ->  cairo_region_create_rectangle

Also delete cairo_region_clear() which is not that useful.
2009-03-28 18:02:57 -04:00
Søren Sandmann Pedersen
bf6d9bc175 [region] Delete cairo_region_create_rectangles()
It was only used in _cairo_traps_extract_region() which could be
simplified significantly by calling cairo_region_union_rect()
repeatedly instead.
2009-03-28 18:02:57 -04:00
Søren Sandmann
1cca5a1348 [region] Remove underscores from _cairo_region_* 2009-03-28 18:02:07 -04:00
Søren Sandmann Pedersen
ebd0e685ae [region] Consistently use rectangles in the API of regions
Usually, rectangles are more useful than boxes, so regions should only
expose rectangles in their public API.

Specifically,
  _cairo_region_num_boxes becomes _cairo_region_num_rectangles
  _cairo_region_get_box becomes _cairo_region_get_rectangle

Remove the cairo_box_int_t type
2009-03-28 18:01:19 -04:00
Søren Sandmann
e3e1b35eb9 [region] Make cairo_region_t a malloced object. 2009-03-28 17:58:48 -04:00
Chris Wilson
e6963a5bfe Mark allocation failures as unlikely.
Use the gcc likelihood annotation to indicate that allocation failures are
extremely unlikely.
2008-11-29 11:20:34 +00:00
Chris Wilson
d1801c23fa Mark if(status) as being unlikely.
The error paths should be hit very rarely during normal operation, so mark
them as being unlikely so gcc may emit better code.
2008-11-29 11:20:33 +00:00
Chris Wilson
64726ccfb9 [traps] Whitespace.
Fixup whitespace in line with CODING_STYLE and rest of file.
2008-10-30 17:52:13 +00:00
Chris Wilson
59e569576d [traps] Discard trivially empty trapezoid.
The convex_quad tessellator (and possibly even the more general polygon
tessellator) will generate empty trapezoids when given a
rectangle which can be trivially discarded before inserting into traps.
2008-10-04 10:12:37 +01:00
Chris Wilson
7a2329e9c8 [traps] Reset extents on clearing.
When clearing the array of current trapezoids, reset the extents to
infinite so that they are properly recomputed.
2008-10-04 10:12:37 +01:00
Chris Wilson
b9c92842d9 [trap] Trivial reject if trapezoid is entirely above or below
Also check whether is vertically within limits.
2008-09-24 11:45:51 +01:00
Chris Wilson
911d5f1a25 [traps] Adjust lines if either point is on the boundary.
If either point lies on the limit and the other outside, adjust the line
to be parallel to the boundary. This adjusts the previous test where both
points needed to be entirely outside.
2008-09-24 11:45:40 +01:00
Chris Wilson
651c6598c9 [traps] Limit extents to imposed constraints.
When reporting the extents of the traps, constrain them to the imposed
limits. This is relied upon in the analysis-surface which sets the
limits on the traps (based on clip/surface extents) and then reports the
extents of the traps as the region of the operation.
2008-09-24 01:02:48 +01:00
Chris Wilson
d5cd7ee74f [stroke] Optimise rectilinear strokes.
Avoid the overhead of sorting the rectangle in
_cairo_traps_tessellate_convex_quad() by constructing the trap directly
from the line segment. This also has secondary effects in only passing
 the non-degenerate trap to _cairo_traps_add_trap().

For rectilinear Hilbert curves this makes the rectilinear stoker over 4x
faster.
2008-09-19 16:59:25 +01:00
Chris Wilson
9930eefbbd Simple perf tweaks for a rectilinear Hilbert curve.
Some tweaks to avoid stack copies and branches that save ~25% in
_cairo_traps_tessellate_convex_quad().
2008-09-19 14:31:33 +01:00
Chris Wilson
27ee8dd9c6 [trap] Fixup a double _cairo_traps_fini().
The rectilinear stroke finalized the cairo_traps_t passed to it - which
was then subsequently used without re-initialized. So instead of
finalizing the structure, just remove any traps that we may have added
(leaving the limits and memory intact).
2008-09-19 14:31:33 +01:00
Behdad Esfahbod
556b16d6a2 [cairo-traps] Fix overflow in traps_path code
This was causing the user-font test failure in type1 subsetting
code as the type1 code creates a font at size 1000.
2008-05-15 20:03:05 -04:00
Behdad Esfahbod
674cba89fe [cairo-traps] Add _cairo_traps_path()
It appends path for each trap to the path.
2008-05-09 15:54:13 +02:00
Behdad Esfahbod
6c9902fd74 Add more consts to function signatures and remove stale prototype 2008-05-09 15:54:11 +02:00
Vladimir Vukicevic
4471e58c12 Optimize dashed strokes, part 2
Pass down the bounding box to the stroker, and avoid doing expensive
calculations for dash segments that are outside the box.
2008-02-05 15:04:28 -08:00
Behdad Esfahbod
f0633f4449 [doc] Make sure all function names in docs are followed by () 2008-01-28 21:49:57 -05:00
Behdad Esfahbod
0d898f2bad [doc] Make sure all type names in docs are prefixed by # 2008-01-28 20:49:44 -05:00
Chris Wilson
db246f2fa2 [cairo-traps] Typo caught by valgrind.
==3429== Conditional jump or move depends on uninitialised value(s)
==3429==    at 0x4E3FB0F: _cairo_box_round_to_rectangle (cairo-fixed-private.h:196)
==3429==    by 0x4E34B29: _cairo_clip_intersect_to_rectangle (cairo-clip.c:162)
==3429==    by 0x4E31943: cairo_push_group_with_content (cairo.c:495)
==3429==    by 0x403044: draw (clip-zero.c:48)
==3429==    by 0x404221: cairo_test_expecting (cairo-test.c:377)
==3429==    by 0x64701C3: (below main) (libc-start.c:222)

Caused by setting extents->p2.y to zero twice.
2008-01-10 21:32:47 +00:00
Chris Wilson
481fd3b4c8 [cairo-traps] Return zero extents if it contains no traps.
Previously, _cairo_traps_extents () returned the extents
p1={INT_MAX, INT_MAX} p2={INT_MIN, INT_MIN} for an empty traps leading
to integer overflow when computing the width using p2-p1 and causing
further overflows within libpixman. [For example this caused the
allocation of massive regions with test/mask and the PS backend.]
2008-01-05 21:23:46 +00:00
Chris Wilson
8343d6cc2a Replace various uses of CAIRO_STACK_BUF_SIZE with a single macro.
In http://bugs.freedesktop.org/show_bug.cgi?id=13699, Pavel Vozenilek
reports a duplicate define for computing the appropriate length for an
on-stack array. The macro in question, and a few other places, was
performing CAIRO_STACK_BUF_SIZE/sizeof(stack[0]) so we can simplify
them slightly by using a common macro.
2007-12-17 13:45:01 +00:00
Chris Wilson
32b78fffc3 [cairo-traps] Simplify the status interaction of traps_grow().
Simply return the error status from the traps_grow() function rather
than having an assignment in the return function and then immediately
another assignment of the error to the status member at its callsite.
2007-10-10 14:21:25 +01:00
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
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
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
9c38aa3b96 [fixpt] Use _cairo_fixed_mul insted of manual multiplication 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
12cc32b674 [pixman] Initial port to standalone pixman library. 2007-06-21 22:21:11 -07:00
Vladimir Vukicevic
2477e57de5 [perf] Add pixman_region_init_rects and use in extract_region
Avoid O(N*N) loop in traps_extract_region by letting us hand pixman
an array of rects all at once.
2007-06-18 14:02:41 -07:00
Chris Wilson
9e99f0611c [cairo-traps] Initialize traps to use embedded buffer.
Set the traps to use the embedded buffer during initialization which will
save one redundant _cairo_traps_grow()
2007-05-16 16:06:12 +01:00
Carl Worth
8286b87416 Clip trapezoids that are partially (or wholly) outside the clip region.
It's quite simple to add a new _cairo_traps_limit call which installs
a box into the cairo_traps_t structure. Then at the time of
_cairo_traps_add we can discard any trapezoid that is wholly outside
the box and also clip any trapezoid that is partially outside the box.

We take advantage of this for both cairo_stroke and cairo_fill, (when
cairo is computing the trapezoids in cairo-surface-fallback.c). Note
that we explicitly do not do any clipping for cairo_stroke_extents,
cairo_fill_extents, cairo_in_stroke, or cairo_in_fill which are
defined to ignore clipping.

As seen by the long-lines perf case, this fix successfully works
around the bug in the X server where it creates overly large masks for
partially-outside-the-destination-surface trapezoids:

 xlib-rgba   long-lines-uncropped-100  545.84 -> 5.83: 93.09x speedup
██████████████████████████████████████████████
 xlib-rgb    long-lines-uncropped-100  554.74 -> 8.10: 69.04x speedup
██████████████████████████████████
2007-04-27 22:44:27 -07:00
Carl Worth
5c95800cde Fix mis-indented _cairo_traps_init_box 2007-04-10 12:13:10 -07:00
Carl Worth
57188b4dcb Fix cairo_traps_t status handling
Add a _cairo_traps_status function and use it instead of adding
error checks to callers of _cairo_traps_add_trap and
_cairo_traps_add_trap_from_points, (both of which are now given
a void return type).
2007-04-10 12:06:09 -07:00