summaryrefslogtreecommitdiff
path: root/boilerplate/cairo-boilerplate.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.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.c')
-rw-r--r--boilerplate/cairo-boilerplate.c100
1 files changed, 68 insertions, 32 deletions
diff --git a/boilerplate/cairo-boilerplate.c b/boilerplate/cairo-boilerplate.c
index ea88c691e..a0810457a 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;
}