summaryrefslogtreecommitdiff
path: root/boilerplate/cairo-boilerplate-test-surfaces.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2009-07-23 15:32:13 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2009-07-23 15:32:14 +0100
commitbed2701e1c89095878d549cbca8f22d84f3dda3c (patch)
tree974807761b6d839839ecad9961eae8d567898dcc /boilerplate/cairo-boilerplate-test-surfaces.c
parentf5a1cdf283a6aa1f4409ccbf3c2274fb587724fe (diff)
downloadcairo-bed2701e1c89095878d549cbca8f22d84f3dda3c.tar.gz
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 'boilerplate/cairo-boilerplate-test-surfaces.c')
-rw-r--r--boilerplate/cairo-boilerplate-test-surfaces.c113
1 files changed, 53 insertions, 60 deletions
diff --git a/boilerplate/cairo-boilerplate-test-surfaces.c b/boilerplate/cairo-boilerplate-test-surfaces.c
index 849627fd3..501866bad 100644
--- a/boilerplate/cairo-boilerplate-test-surfaces.c
+++ b/boilerplate/cairo-boilerplate-test-surfaces.c
@@ -33,6 +33,7 @@
#include <test-paginated-surface.h>
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1,9,3)
#include <test-null-surface.h>
+#include <test-wrapping-surface.h>
#endif
#include <cairo-types-private.h>
@@ -49,7 +50,8 @@ _cairo_boilerplate_test_fallback_create_surface (const char *name,
void **closure)
{
*closure = NULL;
- return _cairo_test_fallback_surface_create (content, width, height);
+ return _cairo_test_fallback_surface_create (content,
+ ceil (width), ceil (height));
}
static cairo_surface_t *
@@ -64,7 +66,8 @@ _cairo_boilerplate_test_fallback16_create_surface (const char *name,
void **closure)
{
*closure = NULL;
- return _cairo_test_fallback16_surface_create (content, width, height);
+ return _cairo_test_fallback16_surface_create (content,
+ ceil (width), ceil (height));
}
static cairo_surface_t *
@@ -89,11 +92,7 @@ _cairo_boilerplate_test_null_create_surface (const char *name,
static const cairo_user_data_key_t test_paginated_closure_key;
typedef struct {
- unsigned char *data;
- cairo_content_t content;
- int width;
- int height;
- int stride;
+ cairo_surface_t *target;
} test_paginated_closure_t;
static cairo_surface_t *
@@ -115,18 +114,10 @@ _cairo_boilerplate_test_paginated_create_surface (const char *name,
*closure = tpc = xmalloc (sizeof (test_paginated_closure_t));
format = cairo_boilerplate_format_from_content (content);
+ tpc->target = cairo_image_surface_create (format,
+ ceil (width), ceil (height));
- tpc->content = content;
- tpc->width = width;
- tpc->height = height;
- tpc->stride = cairo_format_stride_for_width (format, width);
- tpc->data = xcalloc (tpc->stride, height);
-
- surface = _cairo_test_paginated_surface_create_for_data (tpc->data,
- tpc->content,
- tpc->width,
- tpc->height,
- tpc->stride);
+ surface = _cairo_test_paginated_surface_create (tpc->target);
if (cairo_surface_status (surface))
goto CLEANUP;
@@ -139,8 +130,9 @@ _cairo_boilerplate_test_paginated_create_surface (const char *name,
cairo_surface_destroy (surface);
surface = cairo_boilerplate_surface_create_in_error (status);
+ cairo_surface_destroy (tpc->target);
+
CLEANUP:
- free (tpc->data);
free (tpc);
return surface;
}
@@ -160,8 +152,6 @@ static cairo_status_t
_cairo_boilerplate_test_paginated_surface_write_to_png (cairo_surface_t *surface,
const char *filename)
{
- cairo_surface_t *image;
- cairo_format_t format;
test_paginated_closure_t *tpc;
cairo_status_t status;
@@ -172,19 +162,7 @@ _cairo_boilerplate_test_paginated_surface_write_to_png (cairo_surface_t *surface
return status;
tpc = cairo_surface_get_user_data (surface, &test_paginated_closure_key);
-
- format = cairo_boilerplate_format_from_content (tpc->content);
-
- image = cairo_image_surface_create_for_data (tpc->data,
- format,
- tpc->width,
- tpc->height,
- tpc->stride);
-
- status = cairo_surface_write_to_png (image, filename);
- cairo_surface_destroy (image);
-
- return status;
+ return cairo_surface_write_to_png (tpc->target, filename);
}
static cairo_surface_t *
@@ -193,7 +171,6 @@ _cairo_boilerplate_test_paginated_get_image_surface (cairo_surface_t *surface,
int width,
int height)
{
- cairo_format_t format;
test_paginated_closure_t *tpc;
cairo_status_t status;
@@ -208,30 +185,7 @@ _cairo_boilerplate_test_paginated_get_image_surface (cairo_surface_t *surface,
return cairo_boilerplate_surface_create_in_error (status);
tpc = cairo_surface_get_user_data (surface, &test_paginated_closure_key);
-
- format = cairo_boilerplate_format_from_content (tpc->content);
-
- if (0) {
- return cairo_image_surface_create_for_data (tpc->data + tpc->stride * (tpc->height - height) + 4 * (tpc->width - width), /* hide the device offset */
- format,
- width,
- height,
- tpc->stride);
- } else {
- cairo_surface_t *image, *surface;
-
- image = cairo_image_surface_create_for_data (tpc->data,
- format,
- tpc->width,
- tpc->height,
- tpc->stride);
- cairo_surface_set_device_offset (image,
- tpc->width - width,
- tpc->height - height);
- surface = _cairo_boilerplate_get_image_surface (image, 0, width, height);
- cairo_surface_destroy (image);
- return surface;
- }
+ return _cairo_boilerplate_get_image_surface (tpc->target, 0, width, height);
}
static void
@@ -239,10 +193,40 @@ _cairo_boilerplate_test_paginated_cleanup (void *closure)
{
test_paginated_closure_t *tpc = closure;
- free (tpc->data);
+ cairo_surface_destroy (tpc->target);
free (tpc);
}
+static cairo_surface_t *
+_cairo_boilerplate_test_wrapping_create_surface (const char *name,
+ cairo_content_t content,
+ double width,
+ double height,
+ double max_width,
+ double max_height,
+ cairo_boilerplate_mode_t mode,
+ int id,
+ void **closure)
+{
+#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1,9,3)
+ cairo_surface_t *target;
+ cairo_surface_t *surface;
+ cairo_format_t format;
+
+ *closure = NULL;
+
+ format = cairo_boilerplate_format_from_content (content);
+ target = cairo_image_surface_create (format, ceil (width), ceil (height));
+ surface = _cairo_test_wrapping_surface_create (target);
+ cairo_surface_destroy (target);
+
+ return surface;
+#else
+ *closure = NULL;
+ return NULL;
+#endif
+}
+
static const cairo_boilerplate_target_t targets[] = {
{
"test-fallback", "image", NULL, NULL,
@@ -305,6 +289,15 @@ static const cairo_boilerplate_target_t targets[] = {
FALSE, TRUE
},
{
+ "test-wrapping", "image", NULL, NULL,
+ CAIRO_INTERNAL_SURFACE_TYPE_TEST_WRAPPING,
+ CAIRO_CONTENT_COLOR_ALPHA, 0,
+ _cairo_boilerplate_test_wrapping_create_surface,
+ NULL, NULL,
+ _cairo_boilerplate_get_image_surface,
+ cairo_surface_write_to_png,
+ },
+ {
"null", "image", NULL, NULL,
CAIRO_INTERNAL_SURFACE_TYPE_NULL,
CAIRO_CONTENT_COLOR_ALPHA, 0,