summaryrefslogtreecommitdiff
path: root/boilerplate/cairo-boilerplate-ps.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2008-08-18 12:53:43 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2008-08-18 16:18:52 +0100
commit17fbb652b1c74ba0ccced48c14c63a4d24bb3891 (patch)
treed8204d532d21318140eb266c0a7a728e05b6b918 /boilerplate/cairo-boilerplate-ps.c
parent9b0b55cea724f91eb2835294f929c49224bd0bac (diff)
downloadcairo-17fbb652b1c74ba0ccced48c14c63a4d24bb3891.tar.gz
[test] Avoid redundant writes/reads of test surfaces via png.
As Behdad suggested, we can dramatically speed up the test suite by short-circuiting the write to a png file, only to then immediately read it back in. So for the raster based surfaces, we avoid the round-trip through libpng by implementing a new boilerplate method to directly extract the image buffer from the test result. A secondary speedup is achieved by caching the most recent reference image.
Diffstat (limited to 'boilerplate/cairo-boilerplate-ps.c')
-rw-r--r--boilerplate/cairo-boilerplate-ps.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/boilerplate/cairo-boilerplate-ps.c b/boilerplate/cairo-boilerplate-ps.c
index f5bd28c0e..f21d17207 100644
--- a/boilerplate/cairo-boilerplate-ps.c
+++ b/boilerplate/cairo-boilerplate-ps.c
@@ -103,7 +103,8 @@ _cairo_boilerplate_ps_create_surface (const char *name,
cairo_status_t
_cairo_boilerplate_ps_surface_write_to_png (cairo_surface_t *surface, const char *filename)
{
- ps_target_closure_t *ptc = cairo_surface_get_user_data (surface, &ps_closure_key);
+ ps_target_closure_t *ptc = cairo_surface_get_user_data (surface,
+ &ps_closure_key);
char command[4096];
cairo_status_t status;
@@ -149,6 +150,32 @@ _cairo_boilerplate_ps_surface_write_to_png (cairo_surface_t *surface, const char
return CAIRO_STATUS_WRITE_ERROR;
}
+cairo_surface_t *
+_cairo_boilerplate_ps_get_image_surface (cairo_surface_t *surface,
+ int width,
+ int height)
+{
+ ps_target_closure_t *ptc = cairo_surface_get_user_data (surface,
+ &ps_closure_key);
+ char *filename;
+ cairo_status_t status;
+
+ xasprintf (&filename, "%s.png", ptc->filename);
+ status = _cairo_boilerplate_ps_surface_write_to_png (surface, filename);
+ if (status)
+ return cairo_boilerplate_surface_create_in_error (status);
+
+ surface = cairo_boilerplate_get_image_surface_from_png (filename,
+ width,
+ height,
+ ptc->target == NULL);
+
+ remove (filename);
+ free (filename);
+
+ return surface;
+}
+
void
_cairo_boilerplate_ps_cleanup (void *closure)
{