summaryrefslogtreecommitdiff
path: root/boilerplate/cairo-boilerplate-ps.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2008-08-11 21:12:45 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2008-08-13 21:54:59 +0100
commit436c0c8be28546813139f391a62303d4c1894fc3 (patch)
tree7134b42ba4af4da886f8bd7906f4d6a144d1a134 /boilerplate/cairo-boilerplate-ps.c
parentc73b3e43e120065e40d8fc48c9bdbd88ebe8ab40 (diff)
downloadcairo-436c0c8be28546813139f391a62303d4c1894fc3.tar.gz
[test] Preparatory work for running under memfault.
In order to run under memfault, the framework is first extended to handle running concurrent tests - i.e. multi-threading. (Not that this is a requirement for memfault, instead it shares a common goal of storing per-test data). To that end all the global data is moved into a per-test context and the targets are adjusted to avoid overlap on shared, global resources (such as output files and frame buffers). In order to preserve the simplicity of the standard draw routines, the context is not passed explicitly as a parameter to the routines, but is instead attached to the cairo_t via the user_data. For the masochist, to enable the tests to be run across multiple threads simply set the environment variable CAIRO_TEST_NUM_THREADS to the desired number. In the long run, we can hope the need for memfault (runtime testing of error paths) will be mitigated by static analysis. A promising candidate for this task would appear to be http://hal.cs.berkeley.edu/cil/.
Diffstat (limited to 'boilerplate/cairo-boilerplate-ps.c')
-rw-r--r--boilerplate/cairo-boilerplate-ps.c54
1 files changed, 36 insertions, 18 deletions
diff --git a/boilerplate/cairo-boilerplate-ps.c b/boilerplate/cairo-boilerplate-ps.c
index 7d5ea7d47..08580cd1b 100644
--- a/boilerplate/cairo-boilerplate-ps.c
+++ b/boilerplate/cairo-boilerplate-ps.c
@@ -47,11 +47,15 @@ _cairo_boilerplate_ps_create_surface (const char *name,
cairo_content_t content,
int width,
int height,
+ int max_width,
+ int max_height,
cairo_boilerplate_mode_t mode,
+ int id,
void **closure)
{
ps_target_closure_t *ptc;
cairo_surface_t *surface;
+ cairo_status_t status;
/* Sanitize back to a real cairo_content_t value. */
if (content == CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED)
@@ -59,18 +63,16 @@ _cairo_boilerplate_ps_create_surface (const char *name,
*closure = ptc = xmalloc (sizeof (ps_target_closure_t));
- xasprintf (&ptc->filename, "%s-ps-%s-out.ps",
- name, cairo_boilerplate_content_name (content));
+ xasprintf (&ptc->filename, "%s-ps-%s-%d-out.ps",
+ name, cairo_boilerplate_content_name (content), id);
ptc->width = width;
ptc->height = height;
surface = cairo_ps_surface_create (ptc->filename, width, height);
- if (cairo_surface_status (surface)) {
- free (ptc->filename);
- free (ptc);
- return NULL;
- }
+ if (cairo_surface_status (surface))
+ goto CLEANUP_FILENAME;
+
cairo_surface_set_fallback_resolution (surface, 72., 72.);
if (content == CAIRO_CONTENT_COLOR) {
@@ -78,22 +80,24 @@ _cairo_boilerplate_ps_create_surface (const char *name,
surface = cairo_surface_create_similar (ptc->target,
CAIRO_CONTENT_COLOR,
width, height);
+ if (cairo_surface_status (surface))
+ goto CLEANUP_TARGET;
} else {
ptc->target = NULL;
}
- if (cairo_surface_set_user_data (surface,
- &ps_closure_key,
- ptc,
- NULL) != CAIRO_STATUS_SUCCESS) {
- cairo_surface_destroy (surface);
- if (ptc->target != NULL)
- cairo_surface_destroy (ptc->target);
- free (ptc->filename);
- free (ptc);
- return NULL;
- }
+ status = cairo_surface_set_user_data (surface, &ps_closure_key, ptc, NULL);
+ if (status == CAIRO_STATUS_SUCCESS)
+ return surface;
+ cairo_surface_destroy (surface);
+ surface = cairo_boilerplate_surface_create_in_error (status);
+
+ CLEANUP_TARGET:
+ cairo_surface_destroy (ptc->target);
+ CLEANUP_FILENAME:
+ free (ptc->filename);
+ free (ptc);
return surface;
}
@@ -102,6 +106,7 @@ _cairo_boilerplate_ps_surface_write_to_png (cairo_surface_t *surface, const char
{
ps_target_closure_t *ptc = cairo_surface_get_user_data (surface, &ps_closure_key);
char command[4096];
+ cairo_status_t status;
/* Both surface and ptc->target were originally created at the
* same dimensions. We want a 1:1 copy here, so we first clear any
@@ -118,17 +123,30 @@ _cairo_boilerplate_ps_surface_write_to_png (cairo_surface_t *surface, const char
cairo_set_source_surface (cr, surface, 0, 0);
cairo_paint (cr);
cairo_show_page (cr);
+ status = cairo_status (cr);
cairo_destroy (cr);
+ if (status)
+ return status;
+
cairo_surface_finish (surface);
+ status = cairo_surface_status (surface);
+ if (status)
+ return status;
+
surface = ptc->target;
}
cairo_surface_finish (surface);
+ status = cairo_surface_status (surface);
+ if (status)
+ return status;
+
sprintf (command, "gs -q -r72 -g%dx%d -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pngalpha -sOutputFile=%s %s",
ptc->width, ptc->height, filename, ptc->filename);
if (system (command) == 0)
return CAIRO_STATUS_SUCCESS;
+
return CAIRO_STATUS_WRITE_ERROR;
}