[cairo] New guards for cairo_xlib_surface_create_with_xrender_format()
Chris Wilson
chris at chris-wilson.co.uk
Wed Apr 2 03:48:08 PDT 2008
Inlining previous attachment as I haven't found out how to make
evolution behave...
>From e57b061a3c80aef25898ef06b891f5fc896195d4 Mon Sep 17 00:00:00 2001
From: Chris Wilson <chris at chris-wilson.co.uk>
Date: Wed, 2 Apr 2008 11:17:04 +0100
Subject: [PATCH] [cairo-xlib-surface] Check for fallback support for the
xrender_format
On the fallback path, we can only recreate an image surface for
supported pixman formats (without a Visual) so check that the
user supplied xrender_format is supported upon creation.
---
src/cairo-xlib-surface.c | 28 ++++++++++++++++++++++++++++
1 files changed, 28 insertions(+), 0 deletions(-)
diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c
index 3649ca6..7fd9198 100644
--- a/src/cairo-xlib-surface.c
+++ b/src/cairo-xlib-surface.c
@@ -2398,6 +2398,34 @@ cairo_xlib_surface_create_with_xrender_format
(Display *dpy,
int width,
int height)
{
+ pixman_format_code_t pixman_format;
+ cairo_format_masks_t xlib_masks;
+ cairo_status_t status;
+
+ xlib_masks.alpha_mask = (unsigned long)
+ format->direct.alphaMask << format->direct.alpha;
+ xlib_masks.red_mask = (unsigned long)
+ format->direct.redMask << format->direct.red;
+ xlib_masks.green_mask = (unsigned long)
+ format->direct.greenMask << format->direct.green;
+ xlib_masks.blue_mask = (unsigned long)
+ format->direct.blueMask << format->direct.blue;
+
+ if (format->depth > 16) {
+ xlib_masks.bpp = 32;
+ } else if (format->depth > 8) {
+ xlib_masks.bpp = 16;
+ } else if (format->depth > 1) {
+ xlib_masks.bpp = 8;
+ } else {
+ xlib_masks.bpp = 1;
+ }
+
+ /* check that we can handle fallbacks for this xrender_format */
+ status = _pixman_format_from_masks (&xlib_masks, &pixman_format);
+ if (status)
+ return _cairo_surface_create_in_error (_cairo_error
(CAIRO_STATUS_INVALID_VISUAL));
+
return _cairo_xlib_surface_create_internal (dpy, drawable, screen,
NULL, format, width, height, 0);
}
--
1.5.4.5
--
Chris Wilson
More information about the cairo
mailing list