diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2009-06-21 10:08:21 +0100 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2009-06-21 10:13:31 +0100 |
commit | d0c1c9282164bffb76f7419873e93608dc6d9876 (patch) | |
tree | 98d47720e0ebac4eed1352d4ff0ffe97a2e0075b /boilerplate | |
parent | d2244053dcca687a878b1008e3a8219f11d7bd0d (diff) |
[boilerplate] Implement a reference xlib surface
Create an xlib target that uses a separate display, specified by
CAIRO_REFERENCE_DISPLAY, that can be used as a reference implementation
for the normal display. So this can be used by cairo-trace-test to create
a reference surface that mimics exactly the true surface, but if it
targets an Xvfb display will be entirely rendered in software. If
CAIRO_REFERENCE_DISPLAY is not set, the reference surface degrades into an
xlib-fallback surface which is a close approximation (but still has
behavioural differences).
Diffstat (limited to 'boilerplate')
-rw-r--r-- | boilerplate/cairo-boilerplate-xlib-private.h | 11 | ||||
-rw-r--r-- | boilerplate/cairo-boilerplate-xlib.c | 51 | ||||
-rw-r--r-- | boilerplate/cairo-boilerplate.c | 14 |
3 files changed, 74 insertions, 2 deletions
diff --git a/boilerplate/cairo-boilerplate-xlib-private.h b/boilerplate/cairo-boilerplate-xlib-private.h index 0bd911dd..265ee97c 100644 --- a/boilerplate/cairo-boilerplate-xlib-private.h +++ b/boilerplate/cairo-boilerplate-xlib-private.h @@ -41,6 +41,17 @@ _cairo_boilerplate_xlib_create_surface (const char *name, #endif cairo_surface_t * +_cairo_boilerplate_xlib_reference_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); + +cairo_surface_t * _cairo_boilerplate_xlib_fallback_create_surface (const char *name, cairo_content_t content, int width, diff --git a/boilerplate/cairo-boilerplate-xlib.c b/boilerplate/cairo-boilerplate-xlib.c index a4deeb7b..03febe90 100644 --- a/boilerplate/cairo-boilerplate-xlib.c +++ b/boilerplate/cairo-boilerplate-xlib.c @@ -224,6 +224,57 @@ _cairo_boilerplate_xlib_create_surface (const char *name, return surface; } + +cairo_surface_t * +_cairo_boilerplate_xlib_reference_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) +{ + xlib_target_closure_t *xtc; + Display *dpy; + cairo_surface_t *surface; + const char *display; + + display = getenv ("CAIRO_REFERENCE_DISPLAY"); + if (display == NULL) { + return _cairo_boilerplate_xlib_fallback_create_surface (name, content, + width, height, + max_width, + max_height, + mode, id, + closure); + } + + *closure = xtc = xcalloc (1, sizeof (xlib_target_closure_t)); + + if (width == 0) + width = 1; + if (height == 0) + height = 1; + + xtc->dpy = dpy = XOpenDisplay (display); + if (xtc->dpy == NULL) { + free (xtc); + CAIRO_BOILERPLATE_DEBUG (("Failed to open display: %s\n", display)); + return NULL; + } + + if (mode == CAIRO_BOILERPLATE_MODE_TEST) + surface = _cairo_boilerplate_xlib_test_create_surface (dpy, content, width, height, xtc); + else /* mode == CAIRO_BOILERPLATE_MODE_PERF */ + surface = _cairo_boilerplate_xlib_perf_create_surface (dpy, content, width, height, xtc); + + if (surface == NULL || cairo_surface_status (surface)) + _cairo_boilerplate_xlib_cleanup (xtc); + + return surface; +} #endif /* The xlib-fallback target differs from the xlib target in two ways: diff --git a/boilerplate/cairo-boilerplate.c b/boilerplate/cairo-boilerplate.c index 50a28f89..39a1a4a9 100644 --- a/boilerplate/cairo-boilerplate.c +++ b/boilerplate/cairo-boilerplate.c @@ -552,7 +552,7 @@ static const cairo_boilerplate_target_t targets[] = /* Acceleration architectures may make the results differ by a * bit, so we set the error tolerance to 1. */ { - "xlib", "xlib", NULL, "xlib-fallback", + "xlib", "xlib", NULL, "xlib-reference", CAIRO_SURFACE_TYPE_XLIB, CAIRO_CONTENT_COLOR_ALPHA, 1, _cairo_boilerplate_xlib_create_surface, NULL, NULL, @@ -562,7 +562,7 @@ static const cairo_boilerplate_target_t targets[] = _cairo_boilerplate_xlib_synchronize }, { - "xlib", "xlib", NULL, "xlib-fallback", + "xlib", "xlib", NULL, "xlib-reference", CAIRO_SURFACE_TYPE_XLIB, CAIRO_CONTENT_COLOR, 1, _cairo_boilerplate_xlib_create_surface, NULL, NULL, @@ -571,6 +571,16 @@ static const cairo_boilerplate_target_t targets[] = _cairo_boilerplate_xlib_cleanup, _cairo_boilerplate_xlib_synchronize }, + { + "xlib-reference", "xlib", NULL, NULL, + CAIRO_SURFACE_TYPE_XLIB, CAIRO_CONTENT_COLOR, 1, + _cairo_boilerplate_xlib_reference_create_surface, + NULL, NULL, + NULL, /* get_image */ + cairo_surface_write_to_png, + _cairo_boilerplate_xlib_cleanup, + _cairo_boilerplate_xlib_synchronize + }, #endif #if CAIRO_HAS_XLIB_SURFACE /* This is a fallback surface which uses xlib fallbacks instead of |