diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2009-07-23 15:32:13 +0100 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2009-07-23 15:32:14 +0100 |
commit | bed2701e1c89095878d549cbca8f22d84f3dda3c (patch) | |
tree | 974807761b6d839839ecad9961eae8d567898dcc /src/test-paginated-surface.c | |
parent | f5a1cdf283a6aa1f4409ccbf3c2274fb587724fe (diff) |
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
▏
Diffstat (limited to 'src/test-paginated-surface.c')
-rw-r--r-- | src/test-paginated-surface.c | 100 |
1 files changed, 25 insertions, 75 deletions
diff --git a/src/test-paginated-surface.c b/src/test-paginated-surface.c index d42700c8..164d4a71 100644 --- a/src/test-paginated-surface.c +++ b/src/test-paginated-surface.c @@ -61,37 +61,27 @@ static const cairo_surface_backend_t test_paginated_surface_backend; static const cairo_paginated_surface_backend_t test_paginated_surface_paginated_backend; cairo_surface_t * -_cairo_test_paginated_surface_create_for_data (unsigned char *data, - cairo_content_t content, - int width, - int height, - int stride) +_cairo_test_paginated_surface_create (cairo_surface_t *target) { cairo_status_t status; - cairo_surface_t *target; cairo_surface_t *paginated; test_paginated_surface_t *surface; - target = _cairo_image_surface_create_for_data_with_content (data, content, - width, height, - stride); status = cairo_surface_status (target); - if (status) - return target; + if (unlikely (status)) + return _cairo_surface_create_in_error (status); surface = malloc (sizeof (test_paginated_surface_t)); - if (unlikely (surface == NULL)) { - cairo_surface_destroy (target); + if (unlikely (surface == NULL)) return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - } _cairo_surface_init (&surface->base, &test_paginated_surface_backend, - content); + target->content); - surface->target = target; + surface->target = cairo_surface_reference (target); paginated = _cairo_paginated_surface_create (&surface->base, - content, width, height, + target->content, &test_paginated_surface_paginated_backend); status = paginated->status; if (status == CAIRO_STATUS_SUCCESS) { @@ -115,49 +105,7 @@ _test_paginated_surface_finish (void *abstract_surface) return CAIRO_STATUS_SUCCESS; } -static cairo_int_status_t -_test_paginated_surface_set_clip_region (void *abstract_surface, - cairo_region_t *region) -{ - test_paginated_surface_t *surface = abstract_surface; - - if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) - return CAIRO_STATUS_SUCCESS; - - /* XXX: The whole surface backend clipping interface is a giant - * disaster right now. In particular, its uncleanness shows up - * when trying to implement one surface that wraps another one (as - * we are doing here). - * - * Here are two of the problems that show up: - * - * 1. The most critical piece of information in all this stuff, - * the "clip" isn't getting passed to the backend - * functions. Instead the generic surface layer is caching that as - * surface->clip. This is a problem for surfaces like this one - * that do wrapping. Our base surface will have the clip set, but - * our target's surface will not. - * - * 2. We're here in our backend's set_clip_region function, and we - * want to call into our target surface's set_clip_region. - * Generally, we would do this by calling an equivalent - * _cairo_surface function, but _cairo_surface_set_clip_region - * does not have the same signature/semantics, (it has the - * clip_serial stuff as well). - * - * We kludge around each of these by manually copying the clip - * object from our base surface into the target's base surface - * (yuck!) and by reaching directly into the image surface's - * set_clip_region instead of calling into the generic - * _cairo_surface_set_clip_region (double yuck!). - */ - - surface->target->clip = surface->base.clip; - - return _cairo_image_surface_set_clip_region (surface->target, region); -} - -static cairo_int_status_t +static cairo_bool_t _test_paginated_surface_get_extents (void *abstract_surface, cairo_rectangle_int_t *rectangle) { @@ -170,14 +118,14 @@ static cairo_int_status_t _test_paginated_surface_paint (void *abstract_surface, cairo_operator_t op, const cairo_pattern_t *source, - cairo_rectangle_int_t *extents) + cairo_clip_t *clip) { test_paginated_surface_t *surface = abstract_surface; if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) return CAIRO_STATUS_SUCCESS; - return _cairo_surface_paint (surface->target, op, source, extents); + return _cairo_surface_paint (surface->target, op, source, clip); } static cairo_int_status_t @@ -185,14 +133,15 @@ _test_paginated_surface_mask (void *abstract_surface, cairo_operator_t op, const cairo_pattern_t *source, const cairo_pattern_t *mask, - cairo_rectangle_int_t *extents) + cairo_clip_t *clip) { test_paginated_surface_t *surface = abstract_surface; if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) return CAIRO_STATUS_SUCCESS; - return _cairo_surface_mask (surface->target, op, source, mask, extents); + return _cairo_surface_mask (surface->target, + op, source, mask, clip); } static cairo_int_status_t @@ -205,7 +154,7 @@ _test_paginated_surface_stroke (void *abstract_surface, cairo_matrix_t *ctm_inverse, double tolerance, cairo_antialias_t antialias, - cairo_rectangle_int_t *extents) + cairo_clip_t *clip) { test_paginated_surface_t *surface = abstract_surface; @@ -215,7 +164,8 @@ _test_paginated_surface_stroke (void *abstract_surface, return _cairo_surface_stroke (surface->target, op, source, path, style, ctm, ctm_inverse, - tolerance, antialias, extents); + tolerance, antialias, + clip); } static cairo_int_status_t @@ -226,7 +176,7 @@ _test_paginated_surface_fill (void *abstract_surface, cairo_fill_rule_t fill_rule, double tolerance, cairo_antialias_t antialias, - cairo_rectangle_int_t *extents) + cairo_clip_t *clip) { test_paginated_surface_t *surface = abstract_surface; @@ -235,7 +185,8 @@ _test_paginated_surface_fill (void *abstract_surface, return _cairo_surface_fill (surface->target, op, source, path, fill_rule, - tolerance, antialias, extents); + tolerance, antialias, + clip); } static cairo_bool_t @@ -258,7 +209,7 @@ _test_paginated_surface_show_text_glyphs (void *abstract_surface, int num_clusters, cairo_text_cluster_flags_t cluster_flags, cairo_scaled_font_t *scaled_font, - cairo_rectangle_int_t *extents) + cairo_clip_t *clip) { test_paginated_surface_t *surface = abstract_surface; @@ -268,8 +219,10 @@ _test_paginated_surface_show_text_glyphs (void *abstract_surface, return _cairo_surface_show_text_glyphs (surface->target, op, source, utf8, utf8_len, glyphs, num_glyphs, - clusters, num_clusters, cluster_flags, - scaled_font, extents); + clusters, num_clusters, + cluster_flags, + scaled_font, + clip); } @@ -302,8 +255,6 @@ static const cairo_surface_backend_t test_paginated_surface_backend = { NULL, /* check_span_renderer */ NULL, /* copy_page */ NULL, /* show_page */ - _test_paginated_surface_set_clip_region, - NULL, /* intersect_clip_path */ _test_paginated_surface_get_extents, NULL, /* old_show_glyphs */ NULL, /* get_font_options */ @@ -319,11 +270,10 @@ static const cairo_surface_backend_t test_paginated_surface_backend = { _test_paginated_surface_mask, _test_paginated_surface_stroke, _test_paginated_surface_fill, - NULL, /* show_glyphs */ + NULL, /* replaced by show_text_glyphs */ NULL, /* snapshot */ NULL, /* is_similar */ - NULL, /* reset */ NULL, /* fill_stroke */ NULL, /* create_solid_pattern_surface */ NULL, /* can_repaint_solid_pattern_surface */ |