summaryrefslogtreecommitdiff
path: root/boilerplate
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
parentf5a1cdf283a6aa1f4409ccbf3c2274fb587724fe (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 'boilerplate')
-rw-r--r--boilerplate/cairo-boilerplate-glitz-glx.c4
-rw-r--r--boilerplate/cairo-boilerplate-pdf.c1
-rw-r--r--boilerplate/cairo-boilerplate-ps.c8
-rw-r--r--boilerplate/cairo-boilerplate-qt.cpp4
-rw-r--r--boilerplate/cairo-boilerplate-svg.c1
-rw-r--r--boilerplate/cairo-boilerplate-test-surfaces.c113
-rw-r--r--boilerplate/cairo-boilerplate.c100
-rw-r--r--boilerplate/cairo-boilerplate.h2
8 files changed, 128 insertions, 105 deletions
diff --git a/boilerplate/cairo-boilerplate-glitz-glx.c b/boilerplate/cairo-boilerplate-glitz-glx.c
index 6dfdb7fe..6e3cfec3 100644
--- a/boilerplate/cairo-boilerplate-glitz-glx.c
+++ b/boilerplate/cairo-boilerplate-glitz-glx.c
@@ -33,7 +33,6 @@
static const cairo_user_data_key_t glitz_closure_key;
typedef struct _glitz_glx_target_closure {
- glitz_target_closure_base_t base;
Display *dpy;
int scr;
Window win;
@@ -206,9 +205,6 @@ _cairo_boilerplate_glitz_glx_create_surface (const char *name,
if (cairo_surface_status (surface))
goto FAIL_CLOSE_DISPLAY;
- gxtc->base.width = width;
- gxtc->base.height = height;
- gxtc->base.content = content;
status = cairo_surface_set_user_data (surface,
&glitz_closure_key, gxtc, NULL);
if (status == CAIRO_STATUS_SUCCESS)
diff --git a/boilerplate/cairo-boilerplate-pdf.c b/boilerplate/cairo-boilerplate-pdf.c
index 166ba1c9..e941d46f 100644
--- a/boilerplate/cairo-boilerplate-pdf.c
+++ b/boilerplate/cairo-boilerplate-pdf.c
@@ -129,7 +129,6 @@ _cairo_boilerplate_pdf_finish_surface (cairo_surface_t *surface)
if (status)
return status;
- cairo_surface_finish (surface);
status = cairo_surface_status (surface);
if (status)
return status;
diff --git a/boilerplate/cairo-boilerplate-ps.c b/boilerplate/cairo-boilerplate-ps.c
index 0fdd0cfa..40148dde 100644
--- a/boilerplate/cairo-boilerplate-ps.c
+++ b/boilerplate/cairo-boilerplate-ps.c
@@ -178,6 +178,7 @@ _cairo_boilerplate_ps_finish_surface (cairo_surface_t *surface)
if (ptc->target) {
cairo_t *cr;
+
cr = cairo_create (ptc->target);
cairo_set_source_surface (cr, surface, 0, 0);
cairo_paint (cr);
@@ -188,7 +189,6 @@ _cairo_boilerplate_ps_finish_surface (cairo_surface_t *surface)
if (status)
return status;
- cairo_surface_finish (surface);
status = cairo_surface_status (surface);
if (status)
return status;
@@ -197,11 +197,7 @@ _cairo_boilerplate_ps_finish_surface (cairo_surface_t *surface)
}
cairo_surface_finish (surface);
- status = cairo_surface_status (surface);
- if (status)
- return status;
-
- return CAIRO_STATUS_SUCCESS;
+ return cairo_surface_status (surface);
}
static cairo_status_t
diff --git a/boilerplate/cairo-boilerplate-qt.cpp b/boilerplate/cairo-boilerplate-qt.cpp
index 5d8d3f93..8f19811f 100644
--- a/boilerplate/cairo-boilerplate-qt.cpp
+++ b/boilerplate/cairo-boilerplate-qt.cpp
@@ -30,7 +30,7 @@
* The Initial Developer of the Original Code is Chris Wilson.
*/
-#include "cairo-boilerplate.h"
+#include "cairo-boilerplate-private.h"
#include <cairo-qt.h>
@@ -108,4 +108,6 @@ static const cairo_boilerplate_target_t targets[] = {
_cairo_boilerplate_qt_cleanup
},
};
+extern "C" {
CAIRO_BOILERPLATE (qt, targets)
+}
diff --git a/boilerplate/cairo-boilerplate-svg.c b/boilerplate/cairo-boilerplate-svg.c
index 9d03b203..45e085ce 100644
--- a/boilerplate/cairo-boilerplate-svg.c
+++ b/boilerplate/cairo-boilerplate-svg.c
@@ -166,7 +166,6 @@ _cairo_boilerplate_svg_finish_surface (cairo_surface_t *surface)
if (status)
return status;
- cairo_surface_finish (surface);
status = cairo_surface_status (surface);
if (status)
return status;
diff --git a/boilerplate/cairo-boilerplate-test-surfaces.c b/boilerplate/cairo-boilerplate-test-surfaces.c
index 849627fd..501866ba 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,
diff --git a/boilerplate/cairo-boilerplate.c b/boilerplate/cairo-boilerplate.c
index ea88c691..a0810457 100644
--- a/boilerplate/cairo-boilerplate.c
+++ b/boilerplate/cairo-boilerplate.c
@@ -32,6 +32,10 @@
#include <cairo-types-private.h>
#include <cairo-scaled-font-private.h>
+#if CAIRO_HAS_SCRIPT_SURFACE
+#include <cairo-script.h>
+#endif
+
/* get the "real" version info instead of dummy cairo-version.h */
#undef CAIRO_VERSION_H
#include "../cairo-version.h"
@@ -136,48 +140,74 @@ _cairo_boilerplate_meta_create_surface (const char *name,
int id,
void **closure)
{
+ cairo_rectangle_t extents;
+
*closure = NULL;
- return cairo_meta_surface_create (content, width, height);
+
+ extents.x = 0;
+ extents.y = 0;
+ extents.width = width;
+ extents.height = height;
+ return cairo_meta_surface_create (content, &extents);
}
+const cairo_user_data_key_t cairo_boilerplate_output_basename_key;
+
+#if CAIRO_HAS_SCRIPT_SURFACE
+static cairo_status_t
+stdio_write (void *closure, const unsigned char *data, unsigned int len)
+{
+ if (fwrite (data, len, 1, closure) != 1)
+ return CAIRO_STATUS_WRITE_ERROR;
+
+ return CAIRO_STATUS_SUCCESS;
+}
+#endif
+
cairo_surface_t *
_cairo_boilerplate_get_image_surface (cairo_surface_t *src,
int page,
int width,
int height)
{
- cairo_surface_t *surface;
+ FILE *file = NULL;
+ cairo_surface_t *surface, *image;
cairo_t *cr;
+ cairo_status_t status;
if (cairo_surface_status (src))
return cairo_surface_reference (src);
-#if 0
- if (cairo_surface_get_type (src) == CAIRO_SURFACE_TYPE_IMAGE) {
- int ww = cairo_image_surface_get_width (src);
- int hh = cairo_image_surface_get_height (src);
- if (width == ww && hh == height) {
- return cairo_surface_reference (src);
- } else {
- cairo_format_t format = cairo_image_surface_get_format (src);
- unsigned char *data = cairo_image_surface_get_data (src);
- int stride = cairo_image_surface_get_stride (src);
-
- data += stride * (hh - height) + 4 * (ww - width);
- return cairo_image_surface_create_for_data (data,
- format,
- width,
- height,
- stride);
- }
- }
-#endif
-
if (page != 0)
return cairo_boilerplate_surface_create_in_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
/* extract sub-surface */
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
+ image = cairo_surface_reference (surface);
+
+ /* open a logging channel (only interesting for meta surfaces) */
+#if CAIRO_HAS_SCRIPT_SURFACE
+ if (cairo_surface_get_type (src) == CAIRO_SURFACE_TYPE_META) {
+ const char *test_name;
+
+ test_name = cairo_surface_get_user_data (src,
+ &cairo_boilerplate_output_basename_key);
+ if (test_name != NULL) {
+ char *filename;
+
+ xasprintf (&filename, "%s.out.trace", test_name);
+ file = fopen (filename, "w");
+ free (filename);
+
+ if (file != NULL) {
+ surface = cairo_script_surface_create_for_target (image,
+ stdio_write,
+ file);
+ }
+ }
+ }
+#endif
+
cr = cairo_create (surface);
cairo_surface_destroy (surface);
@@ -185,10 +215,17 @@ _cairo_boilerplate_get_image_surface (cairo_surface_t *src,
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
cairo_paint (cr);
- surface = cairo_surface_reference (cairo_get_target (cr));
+ status = cairo_status (cr);
+ if (status) {
+ cairo_surface_destroy (image);
+ image = cairo_surface_reference (cairo_get_target (cr));
+ }
cairo_destroy (cr);
- return surface;
+ if (file != NULL)
+ fclose (file);
+
+ return image;
}
cairo_surface_t *
@@ -705,8 +742,13 @@ cairo_boilerplate_convert_to_image (const char *filename, int page)
image = cairo_boilerplate_image_surface_create_from_ppm_stream (file);
ret = pclose (file);
+ /* check for fatal errors from the interpreter */
+ if (ret) { /* any2pmm should never die... */
+ cairo_surface_destroy (image);
+ return cairo_boilerplate_surface_create_in_error (CAIRO_STATUS_INVALID_STATUS);
+ }
- if (cairo_surface_status (image) == CAIRO_STATUS_READ_ERROR) {
+ if (ret == 0 && cairo_surface_status (image) == CAIRO_STATUS_READ_ERROR) {
if (flags == 0) {
/* Try again in a standalone process. */
cairo_surface_destroy (image);
@@ -715,12 +757,6 @@ cairo_boilerplate_convert_to_image (const char *filename, int page)
}
}
- if (cairo_surface_status (image) == CAIRO_STATUS_SUCCESS && ret != 0) {
- cairo_surface_destroy (image);
- image =
- cairo_boilerplate_surface_create_in_error (CAIRO_STATUS_READ_ERROR);
- };
-
return image;
}
diff --git a/boilerplate/cairo-boilerplate.h b/boilerplate/cairo-boilerplate.h
index aaa196c5..377d2f91 100644
--- a/boilerplate/cairo-boilerplate.h
+++ b/boilerplate/cairo-boilerplate.h
@@ -99,6 +99,8 @@ CAIRO_BEGIN_DECLS
* PDF surfaces. */
#define CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED ((unsigned int) -1)
+extern const cairo_user_data_key_t cairo_boilerplate_output_basename_key;
+
cairo_content_t
cairo_boilerplate_content (cairo_content_t content);