diff options
author | Behdad Esfahbod <behdad@behdad.org> | 2007-04-19 19:56:05 -0400 |
---|---|---|
committer | Behdad Esfahbod <behdad@behdad.org> | 2007-04-20 00:52:02 -0400 |
commit | 9b660a3d54940c68eb48f2afeca7e87e1d2bffa6 (patch) | |
tree | 6cc40d746c18bd449a866410c4e194d91b42a5ab | |
parent | d945f6434643ac35f0e86352cfe3ccf021f568de (diff) |
[boilerplate] Strip xlib boilerplate into cairo-boilerplate-xlib*
-rw-r--r-- | boilerplate/Makefile.am | 5 | ||||
-rw-r--r-- | boilerplate/cairo-boilerplate-xlib-private.h | 44 | ||||
-rw-r--r-- | boilerplate/cairo-boilerplate-xlib.c | 196 | ||||
-rw-r--r-- | boilerplate/cairo-boilerplate.c | 183 |
4 files changed, 254 insertions, 174 deletions
diff --git a/boilerplate/Makefile.am b/boilerplate/Makefile.am index f82b2e69..2f02a26d 100644 --- a/boilerplate/Makefile.am +++ b/boilerplate/Makefile.am @@ -24,6 +24,11 @@ libcairoboilerplate_la_SOURCES += cairo-boilerplate-directfb.c libcairoboilerplate_la_SOURCES += cairo-boilerplate-directfb-private.h endif +if CAIRO_HAS_XLIB_XRENDER_SURFACE +libcairoboilerplate_la_SOURCES += cairo-boilerplate-xlib.c +libcairoboilerplate_la_SOURCES += cairo-boilerplate-xlib-private.h +endif + if CAIRO_CAN_TEST_GLITZ_AGL_SURFACE libcairoboilerplate_la_LIBADD += $(GLITZ_AGL_LIBS) endif diff --git a/boilerplate/cairo-boilerplate-xlib-private.h b/boilerplate/cairo-boilerplate-xlib-private.h new file mode 100644 index 00000000..97578277 --- /dev/null +++ b/boilerplate/cairo-boilerplate-xlib-private.h @@ -0,0 +1,44 @@ +/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ +/* + * Copyright © 2004,2006 Red Hat, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of + * Red Hat, Inc. not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior + * permission. Red Hat, Inc. makes no representations about the + * suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL, + * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR + * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Author: Carl D. Worth <cworth@cworth.org> + */ + +#ifndef _CAIRO_BOILERPLATE_XLIB_PRIVATE_H_ +#define _CAIRO_BOILERPLATE_XLIB_PRIVATE_H_ + +cairo_surface_t * +_cairo_boilerplate_xlib_create_surface (const char *name, + cairo_content_t content, + int width, + int height, + cairo_boilerplate_mode_t mode, + void **closure); + +void +_cairo_boilerplate_xlib_cleanup (void *closure); + +void +_cairo_boilerplate_xlib_synchronize (void *closure); + +#endif diff --git a/boilerplate/cairo-boilerplate-xlib.c b/boilerplate/cairo-boilerplate-xlib.c new file mode 100644 index 00000000..de3746cf --- /dev/null +++ b/boilerplate/cairo-boilerplate-xlib.c @@ -0,0 +1,196 @@ +/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ +/* + * Copyright © 2004,2006 Red Hat, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of + * Red Hat, Inc. not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior + * permission. Red Hat, Inc. makes no representations about the + * suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL, + * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR + * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Author: Carl D. Worth <cworth@cworth.org> + */ + +#include "cairo-boilerplate.h" +#include "cairo-boilerplate-xlib-private.h" + +#include <cairo-xlib-xrender.h> + +typedef struct _xlib_target_closure +{ + Display *dpy; + Drawable drawable; + cairo_bool_t drawable_is_pixmap; +} xlib_target_closure_t; + +void +_cairo_boilerplate_xlib_synchronize (void *closure) +{ + xlib_target_closure_t *xtc = closure; + XImage *ximage; + + ximage = XGetImage (xtc->dpy, xtc->drawable, + 0, 0, 1, 1, AllPlanes, ZPixmap); + if (ximage != NULL) + XDestroyImage (ximage); +} + +/* For the xlib backend we distinguish between TEST and PERF mode in a + * couple of ways. + * + * For TEST, we always test against pixmaps of depth 32 (for + * COLOR_ALPHA) or 24 (for COLOR) and we use XSynchronize to make it + * easier to debug problems. + * + * For PERF, we test against 32-bit pixmaps for COLOR_ALPHA, but for + * COLOR we test against _windows_ at the depth of the default visual. + * For obvious reasons, we don't use XSynchronize. + */ +static cairo_surface_t * +create_xlib_test_surface (Display *dpy, + cairo_content_t content, + int width, + int height, + xlib_target_closure_t *xtc) +{ + XRenderPictFormat *xrender_format; + + /* This kills performance, but it makes debugging much + * easier. That's why we have it here when in TEST mode, but not + * over in PERF mode. */ + XSynchronize (xtc->dpy, 1); + + /* XXX: Currently we don't do any xlib testing when the X server + * doesn't have the Render extension. We could do better here, + * (perhaps by converting the tests from ARGB32 to RGB24). One + * step better would be to always test the non-Render fallbacks + * for each test even if the server does have the Render + * extension. That would probably be through another + * cairo_boilerplate_target which would use an extended version of + * cairo_test_xlib_disable_render. */ + switch (content) { + case CAIRO_CONTENT_COLOR_ALPHA: + xrender_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); + break; + case CAIRO_CONTENT_COLOR: + xrender_format = XRenderFindStandardFormat (dpy, PictStandardRGB24); + break; + case CAIRO_CONTENT_ALPHA: + default: + CAIRO_BOILERPLATE_LOG ("Invalid content for xlib test: %d\n", content); + return NULL; + } + if (xrender_format == NULL) { + CAIRO_BOILERPLATE_LOG ("X server does not have the Render extension.\n"); + return NULL; + } + + xtc->drawable = XCreatePixmap (dpy, DefaultRootWindow (dpy), + width, height, xrender_format->depth); + xtc->drawable_is_pixmap = TRUE; + + return cairo_xlib_surface_create_with_xrender_format (dpy, xtc->drawable, + DefaultScreenOfDisplay (dpy), + xrender_format, + width, height); +} + +static cairo_surface_t * +create_xlib_perf_surface (Display *dpy, + cairo_content_t content, + int width, + int height, + xlib_target_closure_t *xtc) +{ + XSetWindowAttributes attr; + XRenderPictFormat *xrender_format; + Visual *visual; + + switch (content) { + case CAIRO_CONTENT_COLOR_ALPHA: + xrender_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); + xtc->drawable = XCreatePixmap (dpy, DefaultRootWindow (dpy), + width, height, xrender_format->depth); + xtc->drawable_is_pixmap = TRUE; + break; + case CAIRO_CONTENT_COLOR: + visual = DefaultVisual (dpy, DefaultScreen (dpy)); + xrender_format = XRenderFindVisualFormat (dpy, visual); + attr.override_redirect = True; + xtc->drawable = XCreateWindow (dpy, DefaultRootWindow (dpy), 0, 0, + width, height, 0, xrender_format->depth, + InputOutput, visual, CWOverrideRedirect, &attr); + XMapWindow (dpy, xtc->drawable); + xtc->drawable_is_pixmap = FALSE; + break; + case CAIRO_CONTENT_ALPHA: + default: + CAIRO_BOILERPLATE_LOG ("Invalid content for xlib test: %d\n", content); + return NULL; + } + if (xrender_format == NULL) { + CAIRO_BOILERPLATE_LOG ("X server does not have the Render extension.\n"); + return NULL; + } + + return cairo_xlib_surface_create_with_xrender_format (dpy, xtc->drawable, + DefaultScreenOfDisplay (dpy), + xrender_format, + width, height); +} + +cairo_surface_t * +_cairo_boilerplate_xlib_create_surface (const char *name, + cairo_content_t content, + int width, + int height, + cairo_boilerplate_mode_t mode, + void **closure) +{ + xlib_target_closure_t *xtc; + Display *dpy; + + *closure = xtc = xmalloc (sizeof (xlib_target_closure_t)); + + if (width == 0) + width = 1; + if (height == 0) + height = 1; + + xtc->dpy = dpy = XOpenDisplay (NULL); + if (xtc->dpy == NULL) { + CAIRO_BOILERPLATE_LOG ("Failed to open display: %s\n", XDisplayName(0)); + return NULL; + } + + if (mode == CAIRO_BOILERPLATE_MODE_TEST) + return create_xlib_test_surface (dpy, content, width, height, xtc); + else /* mode == CAIRO_BOILERPLATE_MODE_PERF */ + return create_xlib_perf_surface (dpy, content, width, height, xtc); +} + +void +_cairo_boilerplate_xlib_cleanup (void *closure) +{ + xlib_target_closure_t *xtc = closure; + + if (xtc->drawable_is_pixmap) + XFreePixmap (xtc->dpy, xtc->drawable); + else + XDestroyWindow (xtc->dpy, xtc->drawable); + XCloseDisplay (xtc->dpy); + free (xtc); +} diff --git a/boilerplate/cairo-boilerplate.c b/boilerplate/cairo-boilerplate.c index 66febfb6..3e5f0dd1 100644 --- a/boilerplate/cairo-boilerplate.c +++ b/boilerplate/cairo-boilerplate.c @@ -53,6 +53,9 @@ #if CAIRO_HAS_QUARTZ_SURFACE #include "cairo-boilerplate-quartz-private.h" #endif +#if CAIRO_HAS_XLIB_XRENDER_SURFACE +#include "cairo-boilerplate-xlib-private.h" +#endif /* This is copied from cairoint.h. That makes it painful to keep in * sync, but the slim stuff makes cairoint.h "hard" to include when @@ -860,175 +863,6 @@ cleanup_xcb (void *closure) } #endif -#if CAIRO_HAS_XLIB_SURFACE -#include "cairo-xlib-xrender.h" -typedef struct _xlib_target_closure -{ - Display *dpy; - Drawable drawable; - cairo_bool_t drawable_is_pixmap; -} xlib_target_closure_t; - -static void -boilerplate_xlib_synchronize (void *closure) -{ - xlib_target_closure_t *xtc = closure; - XImage *ximage; - - ximage = XGetImage (xtc->dpy, xtc->drawable, - 0, 0, 1, 1, AllPlanes, ZPixmap); - if (ximage != NULL) - XDestroyImage (ximage); -} - -/* For the xlib backend we distinguish between TEST and PERF mode in a - * couple of ways. - * - * For TEST, we always test against pixmaps of depth 32 (for - * COLOR_ALPHA) or 24 (for COLOR) and we use XSynchronize to make it - * easier to debug problems. - * - * For PERF, we test against 32-bit pixmaps for COLOR_ALPHA, but for - * COLOR we test against _windows_ at the depth of the default visual. - * For obvious reasons, we don't use XSynchronize. - */ -static cairo_surface_t * -create_xlib_test_surface (Display *dpy, - cairo_content_t content, - int width, - int height, - xlib_target_closure_t *xtc) -{ - XRenderPictFormat *xrender_format; - - /* This kills performance, but it makes debugging much - * easier. That's why we have it here when in TEST mode, but not - * over in PERF mode. */ - XSynchronize (xtc->dpy, 1); - - /* XXX: Currently we don't do any xlib testing when the X server - * doesn't have the Render extension. We could do better here, - * (perhaps by converting the tests from ARGB32 to RGB24). One - * step better would be to always test the non-Render fallbacks - * for each test even if the server does have the Render - * extension. That would probably be through another - * cairo_boilerplate_target which would use an extended version of - * cairo_test_xlib_disable_render. */ - switch (content) { - case CAIRO_CONTENT_COLOR_ALPHA: - xrender_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); - break; - case CAIRO_CONTENT_COLOR: - xrender_format = XRenderFindStandardFormat (dpy, PictStandardRGB24); - break; - case CAIRO_CONTENT_ALPHA: - default: - CAIRO_BOILERPLATE_LOG ("Invalid content for xlib test: %d\n", content); - return NULL; - } - if (xrender_format == NULL) { - CAIRO_BOILERPLATE_LOG ("X server does not have the Render extension.\n"); - return NULL; - } - - xtc->drawable = XCreatePixmap (dpy, DefaultRootWindow (dpy), - width, height, xrender_format->depth); - xtc->drawable_is_pixmap = TRUE; - - return cairo_xlib_surface_create_with_xrender_format (dpy, xtc->drawable, - DefaultScreenOfDisplay (dpy), - xrender_format, - width, height); -} - -static cairo_surface_t * -create_xlib_perf_surface (Display *dpy, - cairo_content_t content, - int width, - int height, - xlib_target_closure_t *xtc) -{ - XSetWindowAttributes attr; - XRenderPictFormat *xrender_format; - Visual *visual; - - switch (content) { - case CAIRO_CONTENT_COLOR_ALPHA: - xrender_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); - xtc->drawable = XCreatePixmap (dpy, DefaultRootWindow (dpy), - width, height, xrender_format->depth); - xtc->drawable_is_pixmap = TRUE; - break; - case CAIRO_CONTENT_COLOR: - visual = DefaultVisual (dpy, DefaultScreen (dpy)); - xrender_format = XRenderFindVisualFormat (dpy, visual); - attr.override_redirect = True; - xtc->drawable = XCreateWindow (dpy, DefaultRootWindow (dpy), 0, 0, - width, height, 0, xrender_format->depth, - InputOutput, visual, CWOverrideRedirect, &attr); - XMapWindow (dpy, xtc->drawable); - xtc->drawable_is_pixmap = FALSE; - break; - case CAIRO_CONTENT_ALPHA: - default: - CAIRO_BOILERPLATE_LOG ("Invalid content for xlib test: %d\n", content); - return NULL; - } - if (xrender_format == NULL) { - CAIRO_BOILERPLATE_LOG ("X server does not have the Render extension.\n"); - return NULL; - } - - return cairo_xlib_surface_create_with_xrender_format (dpy, xtc->drawable, - DefaultScreenOfDisplay (dpy), - xrender_format, - width, height); -} - -static cairo_surface_t * -create_xlib_surface (const char *name, - cairo_content_t content, - int width, - int height, - cairo_boilerplate_mode_t mode, - void **closure) -{ - xlib_target_closure_t *xtc; - Display *dpy; - - *closure = xtc = xmalloc (sizeof (xlib_target_closure_t)); - - if (width == 0) - width = 1; - if (height == 0) - height = 1; - - xtc->dpy = dpy = XOpenDisplay (NULL); - if (xtc->dpy == NULL) { - CAIRO_BOILERPLATE_LOG ("Failed to open display: %s\n", XDisplayName(0)); - return NULL; - } - - if (mode == CAIRO_BOILERPLATE_MODE_TEST) - return create_xlib_test_surface (dpy, content, width, height, xtc); - else /* mode == CAIRO_BOILERPLATE_MODE_PERF */ - return create_xlib_perf_surface (dpy, content, width, height, xtc); -} - -static void -cleanup_xlib (void *closure) -{ - xlib_target_closure_t *xtc = closure; - - if (xtc->drawable_is_pixmap) - XFreePixmap (xtc->dpy, xtc->drawable); - else - XDestroyWindow (xtc->dpy, xtc->drawable); - XCloseDisplay (xtc->dpy); - free (xtc); -} -#endif - #if CAIRO_HAS_PS_SURFACE #include "cairo-ps.h" @@ -1443,15 +1277,15 @@ static cairo_boilerplate_target_t targets[] = create_xcb_surface, cairo_surface_write_to_png, cleanup_xcb, boilerplate_xcb_synchronize}, #endif -#if CAIRO_HAS_XLIB_SURFACE +#if CAIRO_HAS_XLIB_XRENDER_SURFACE /* Acceleration architectures may make the results differ by a * bit, so we set the error tolerance to 1. */ { "xlib", CAIRO_SURFACE_TYPE_XLIB, CAIRO_CONTENT_COLOR_ALPHA, 1, - create_xlib_surface, cairo_surface_write_to_png, cleanup_xlib, - boilerplate_xlib_synchronize}, + _cairo_boilerplate_xlib_create_surface, cairo_surface_write_to_png, _cairo_boilerplate_xlib_cleanup, + _cairo_boilerplate_xlib_synchronize}, { "xlib", CAIRO_SURFACE_TYPE_XLIB, CAIRO_CONTENT_COLOR, 1, - create_xlib_surface, cairo_surface_write_to_png, cleanup_xlib, - boilerplate_xlib_synchronize}, + _cairo_boilerplate_xlib_create_surface, cairo_surface_write_to_png, _cairo_boilerplate_xlib_cleanup, + _cairo_boilerplate_xlib_synchronize}, #endif #if CAIRO_HAS_PS_SURFACE { "ps", CAIRO_SURFACE_TYPE_PS, @@ -1508,6 +1342,7 @@ static cairo_boilerplate_target_t targets[] = _cairo_boilerplate_beos_create_surface_for_bitmap, cairo_surface_write_to_png, _cairo_boilerplate_beos_cleanup_bitmap}, #endif + #if CAIRO_HAS_DIRECTFB_SURFACE { "directfb", CAIRO_SURFACE_TYPE_DIRECTFB, CAIRO_CONTENT_COLOR, 0, _cairo_boilerplate_directfb_create_surface, cairo_surface_write_to_png, _cairo_boilerplate_directfb_cleanup}, |