[cairo-commit] src/cairo-quartz-surface.c

Vladimir Vukicevic vladimir at kemper.freedesktop.org
Mon Mar 3 17:40:38 PST 2008


 src/cairo-quartz-surface.c |   17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

New commits:
commit 9dd55f6fe854ec2365a5c1d264e39ca03f6eceb5
Author: Vladimir Vukicevic <vladimir at pobox.com>
Date:   Mon Mar 3 17:40:21 2008 -0800

    [quartz] use CGContextGetType API if available
    
    We need to have a way to figure out if a context is a bitmap context;
    the current method works, but it prints a warning to the system console
    if called on a non-bitmap context.  There's a private CGContextGetType
    API that seems to let us get this information.

diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c
index bd59386..e39ba56 100644
--- a/src/cairo-quartz-surface.c
+++ b/src/cairo-quartz-surface.c
@@ -106,6 +106,7 @@ CG_EXTERN CGImageRef CGBitmapContextCreateImage (CGContextRef);
 static void (*CGContextClipToMaskPtr) (CGContextRef, CGRect, CGImageRef) = NULL;
 /* Only present in 10.5+ */
 static void (*CGContextDrawTiledImagePtr) (CGContextRef, CGRect, CGImageRef) = NULL;
+static unsigned int (*CGContextGetTypePtr) (CGContextRef) = NULL;
 
 static cairo_bool_t _cairo_quartz_symbol_lookup_done = FALSE;
 
@@ -130,10 +131,24 @@ static void quartz_ensure_symbols(void)
 
     CGContextClipToMaskPtr = dlsym(RTLD_DEFAULT, "CGContextClipToMask");
     CGContextDrawTiledImagePtr = dlsym(RTLD_DEFAULT, "CGContextDrawTiledImage");
+    CGContextGetTypePtr = dlsym(RTLD_DEFAULT, "CGContextGetTypePtr");
 
     _cairo_quartz_symbol_lookup_done = TRUE;
 }
 
+static inline cairo_bool_t
+_cairo_quartz_is_cgcontext_bitmap_context (CGContextRef cgc) {
+    if (CGContextGetTypePtr) {
+	/* 4 is the type value of a bitmap context */
+	if (CGContextGetTypePtr(cgc) == 4)
+	    return TRUE;
+	return FALSE;
+    }
+
+    /* This will cause a (harmless) warning to be printed if called on a non-bitmap context */
+    return CGBitmapContextGetBitsPerPixel(surface->cgContext) != 0;
+}
+
 /* CoreGraphics limitation with flipped CTM surfaces: height must be less than signed 16-bit max */
 
 #define CG_MAX_HEIGHT   SHRT_MAX
@@ -924,7 +939,7 @@ _cairo_quartz_get_image (cairo_quartz_surface_t *surface,
 	return CAIRO_STATUS_SUCCESS;
     }
 
-    if (CGBitmapContextGetBitsPerPixel(surface->cgContext) != 0) {
+    if (_cairo_quartz_is_cgcontext_bitmap_context(surface->cgContext)) {
 	unsigned int stride;
 	unsigned int bitinfo;
 	unsigned int bpc, bpp;


More information about the cairo-commit mailing list