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

Vladimir Vukicevic vladimir at kemper.freedesktop.org
Thu Jan 24 14:33:38 PST 2008


 src/cairo-quartz-surface.c |  115 ++++++++++++++++-----------------------------
 1 file changed, 41 insertions(+), 74 deletions(-)

New commits:
commit ea9afecc9aaa87c2df14dc9126c75ac0e3e5b13f
Author: Vladimir Vukicevic <vladimir at pobox.com>
Date:   Thu Jan 24 11:48:02 2008 -0800

    [quartz] Do dynamic symbol lookups for 10.4/10.5 optimization symbols
    
    The gcc-__attribute-__ based weak linking was causing all sorts of problems;
    do dlsym lookups at runtime instead.

diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c
index c9f59ae..7adb460 100644
--- a/src/cairo-quartz-surface.c
+++ b/src/cairo-quartz-surface.c
@@ -34,6 +34,8 @@
  *	Vladimir Vukicevic <vladimir at mozilla.com>
  */
 
+#include <dlfcn.h>
+
 #include "cairoint.h"
 
 #include "cairo-quartz-private.h"
@@ -100,11 +102,12 @@ CG_EXTERN void CGContextReplacePathWithStrokedPath (CGContextRef);
 CG_EXTERN CGImageRef CGBitmapContextCreateImage (CGContextRef);
 #endif
 
-/* missing in 10.3.9 */
-extern void CGContextClipToMask (CGContextRef, CGRect, CGImageRef) __attribute__((weak_import));
+/* Only present in 10.4+ */
+static void (*CGContextClipToMaskPtr) (CGContextRef, CGRect, CGImageRef) = NULL;
+/* Only present in 10.5+ */
+static void (*CGContextDrawTiledImagePtr) (CGContextRef, CGRect, CGImageRef) = NULL;
 
-/* 10.5-only optimization */
-extern void CGContextDrawTiledImage (CGContextRef, CGRect, CGImageRef) __attribute__((weak_import));
+static cairo_bool_t _cairo_quartz_symbol_lookup_done = FALSE;
 
 /*
  * Utility functions
@@ -119,6 +122,18 @@ _cairo_quartz_surface_create_internal (CGContextRef cgContext,
 				       unsigned int width,
 				       unsigned int height);
 
+/* Load all extra symbols */
+static void quartz_ensure_symbols(void)
+{
+    if (_cairo_quartz_symbol_lookup_done)
+	return;
+
+    CGContextClipToMaskPtr = dlsym(RTLD_DEFAULT, "CGContextClipToMask");
+    CGContextDrawTiledImagePtr = dlsym(RTLD_DEFAULT, "CGContextDrawTiledImage");
+
+    _cairo_quartz_symbol_lookup_done = TRUE;
+}
+
 /* CoreGraphics limitation with flipped CTM surfaces: height must be less than signed 16-bit max */
 
 #define CG_MAX_HEIGHT   SHRT_MAX
@@ -761,7 +776,7 @@ _cairo_quartz_setup_source (cairo_quartz_surface_t *surface,
 	return _cairo_quartz_setup_radial_source (surface, rpat);
 
     } else if (source->type == CAIRO_PATTERN_TYPE_SURFACE &&
-	       (source->extend == CAIRO_EXTEND_NONE || (CGContextDrawTiledImage && source->extend == CAIRO_EXTEND_REPEAT)))
+	       (source->extend == CAIRO_EXTEND_NONE || (CGContextDrawTiledImagePtr && source->extend == CAIRO_EXTEND_REPEAT)))
     {
 	    cairo_surface_pattern_t *spat = (cairo_surface_pattern_t *) source;
 	    cairo_surface_t *pat_surf = spat->surface;
@@ -1247,7 +1262,7 @@ _cairo_quartz_surface_paint (void *abstract_surface,
 	if (action == DO_IMAGE)
 	    CGContextDrawImage (surface->cgContext, surface->sourceImageRect, surface->sourceImage);
 	else
-	    CGContextDrawTiledImage (surface->cgContext, surface->sourceImageRect, surface->sourceImage);
+	    CGContextDrawTiledImagePtr (surface->cgContext, surface->sourceImageRect, surface->sourceImage);
 	CGContextRestoreGState (surface->cgContext);
     } else if (action != DO_NOTHING) {
 	rv = CAIRO_INT_STATUS_UNSUPPORTED;
@@ -1337,7 +1352,7 @@ _cairo_quartz_surface_fill (void *abstract_surface,
 	if (action == DO_IMAGE)
 	    CGContextDrawImage (surface->cgContext, surface->sourceImageRect, surface->sourceImage);
 	else
-	    CGContextDrawTiledImage (surface->cgContext, surface->sourceImageRect, surface->sourceImage);
+	    CGContextDrawTiledImagePtr (surface->cgContext, surface->sourceImageRect, surface->sourceImage);
     } else if (action != DO_NOTHING) {
 	rv = CAIRO_INT_STATUS_UNSUPPORTED;
     }
@@ -1445,7 +1460,7 @@ _cairo_quartz_surface_stroke (void *abstract_surface,
 	if (action == DO_IMAGE)
 	    CGContextDrawImage (surface->cgContext, surface->sourceImageRect, surface->sourceImage);
 	else
-	    CGContextDrawTiledImage (surface->cgContext, surface->sourceImageRect, surface->sourceImage);
+	    CGContextDrawTiledImagePtr (surface->cgContext, surface->sourceImageRect, surface->sourceImage);
     } else if (action == DO_SHADING) {
 	CGContextReplacePathWithStrokedPath (surface->cgContext);
 	CGContextClip (surface->cgContext);
@@ -1605,7 +1620,7 @@ _cairo_quartz_surface_show_glyphs (void *abstract_surface,
 	if (action == DO_IMAGE)
 	    CGContextDrawImage (surface->cgContext, surface->sourceImageRect, surface->sourceImage);
 	else
-	    CGContextDrawTiledImage (surface->cgContext, surface->sourceImageRect, surface->sourceImage);
+	    CGContextDrawTiledImagePtr (surface->cgContext, surface->sourceImageRect, surface->sourceImage);
     } else if (action == DO_SHADING) {
 	CGContextDrawShading (surface->cgContext, surface->sourceShading);
     }
@@ -1660,7 +1675,7 @@ _cairo_quartz_surface_mask_with_surface (cairo_quartz_surface_t *surface,
 
     rect = CGRectMake (-mask->base.matrix.x0, -mask->base.matrix.y0, extents.width, extents.height);
     CGContextSaveGState (surface->cgContext);
-    CGContextClipToMask (surface->cgContext, rect, img);
+    CGContextClipToMaskPtr (surface->cgContext, rect, img);
     status = _cairo_quartz_surface_paint (surface, op, source);
 
     CGContextRestoreGState (surface->cgContext);
@@ -1689,7 +1704,7 @@ _cairo_quartz_surface_mask (void *abstract_surface,
 	cairo_solid_pattern_t *solid_mask = (cairo_solid_pattern_t *) mask;
 
 	CGContextSetAlpha (surface->cgContext, solid_mask->color.alpha);
-    } else if (CGContextClipToMask &&
+    } else if (CGContextClipToMaskPtr &&
                mask->type == CAIRO_PATTERN_TYPE_SURFACE &&
 	       mask->extend == CAIRO_EXTEND_NONE) {
 	return _cairo_quartz_surface_mask_with_surface (surface, op, source, (cairo_surface_pattern_t *) mask);
@@ -1813,6 +1828,8 @@ _cairo_quartz_surface_create_internal (CGContextRef cgContext,
 {
     cairo_quartz_surface_t *surface;
 
+    quartz_ensure_symbols();
+
     /* Init the base surface */
     surface = malloc(sizeof(cairo_quartz_surface_t));
     if (surface == NULL)
commit 287de2ce5883daa4238c534e0d4890cb640d7fb7
Author: Vladimir Vukicevic <vladimir at pobox.com>
Date:   Wed Jan 23 21:30:42 2008 -0800

    [quartz] Clean up unused APIs a bit
    
    The data parameter from get_image was never really used; get rid of it and clean up
    callers.  Also get rid of a chunk of dead code in release_dest_image.

diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c
index 3cb6389..c9f59ae 100644
--- a/src/cairo-quartz-surface.c
+++ b/src/cairo-quartz-surface.c
@@ -867,27 +867,16 @@ _cairo_quartz_teardown_source (cairo_quartz_surface_t *surface,
  * get source/dest image implementation
  */
 
-static void
-ImageDataReleaseFunc(void *info, const void *data, size_t size)
-{
-    if (data != NULL) {
-	free((void *) data);
-    }
-}
-
 /* Read the image from the surface's front buffer */
 static cairo_int_status_t
 _cairo_quartz_get_image (cairo_quartz_surface_t *surface,
-			  cairo_image_surface_t **image_out,
-			  unsigned char **data_out)
+			 cairo_image_surface_t **image_out)
 {
     unsigned char *imageData;
     cairo_image_surface_t *isurf;
 
     if (IS_EMPTY(surface)) {
 	*image_out = (cairo_image_surface_t*) cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 0, 0);
-	if (data_out)
-	    *data_out = NULL;
 	return CAIRO_STATUS_SUCCESS;
     }
 
@@ -1001,12 +990,12 @@ _cairo_quartz_surface_acquire_source_image (void *abstract_surface,
 
     //ND((stderr, "%p _cairo_quartz_surface_acquire_source_image\n", surface));
 
-    *image_extra = NULL;
-
-    status = _cairo_quartz_get_image (surface, image_out, NULL);
+    status = _cairo_quartz_get_image (surface, image_out);
     if (status)
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
+    *image_extra = NULL;
+
     return CAIRO_STATUS_SUCCESS;
 }
 
@@ -1028,17 +1017,15 @@ _cairo_quartz_surface_acquire_dest_image (void *abstract_surface,
 {
     cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) abstract_surface;
     cairo_int_status_t status;
-    unsigned char *data;
 
     ND((stderr, "%p _cairo_quartz_surface_acquire_dest_image\n", surface));
 
-    *image_rect = surface->extents;
-
-    status = _cairo_quartz_get_image (surface, image_out, &data);
+    status = _cairo_quartz_get_image (surface, image_out);
     if (status)
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
-    *image_extra = data;
+    *image_rect = surface->extents;
+    *image_extra = NULL;
 
     return CAIRO_STATUS_SUCCESS;
 }
@@ -1050,48 +1037,10 @@ _cairo_quartz_surface_release_dest_image (void *abstract_surface,
 					  cairo_rectangle_int_t *image_rect,
 					  void *image_extra)
 {
-    cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) abstract_surface;
-    unsigned char *imageData = (unsigned char *) image_extra;
+    //cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) abstract_surface;
 
     //ND((stderr, "%p _cairo_quartz_surface_release_dest_image\n", surface));
 
-    if (IS_EMPTY(surface)) {
-	cairo_surface_destroy ((cairo_surface_t*) image);
-	return;
-    }
-
-    if (!CGBitmapContextGetData (surface->cgContext)) {
-	CGDataProviderRef dataProvider;
-	CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();
-	CGImageRef img;
-
-	dataProvider = CGDataProviderCreateWithData (NULL, imageData,
-						     surface->extents.width * surface->extents.height * 4,
-						     ImageDataReleaseFunc);
-
-	img = CGImageCreate (surface->extents.width, surface->extents.height,
-			     8, 32,
-			     surface->extents.width * 4,
-			     rgb,
-			     kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host,
-			     dataProvider,
-			     NULL,
-			     false,
-			     kCGRenderingIntentDefault);
-	CGColorSpaceRelease (rgb);
-
-	CGContextSetCompositeOperation (surface->cgContext, kPrivateCGCompositeCopy);
-
-	CGContextDrawImage (surface->cgContext,
-			    CGRectMake (0, 0, surface->extents.width, surface->extents.height),
-			    img);
-
-	CGImageRelease (img);
-	CGDataProviderRelease (dataProvider);
-
-	ND((stderr, "Image for surface %p was recovered from a bitmap\n", surface));
-    }
-
     cairo_surface_destroy ((cairo_surface_t *) image);
 }
 
@@ -1537,6 +1486,7 @@ _cairo_quartz_surface_show_glyphs (void *abstract_surface,
     cairo_quartz_action_t action;
     float xprev, yprev;
     int i;
+    CGFontRef cgfref;
 
     if (IS_EMPTY(surface))
 	return CAIRO_STATUS_SUCCESS;
@@ -1566,7 +1516,7 @@ _cairo_quartz_surface_show_glyphs (void *abstract_surface,
     CGContextSetCompositeOperation (surface->cgContext, _cairo_quartz_cairo_operator_to_quartz (op));
 
     /* this doesn't addref */
-    CGFontRef cgfref = _cairo_atsui_scaled_font_get_cg_font_ref (scaled_font);
+    cgfref = _cairo_atsui_scaled_font_get_cg_font_ref (scaled_font);
     CGContextSetFont (surface->cgContext, cgfref);
 
     /* So this should include the size; I don't know if I need to extract the
@@ -1866,7 +1816,7 @@ _cairo_quartz_surface_create_internal (CGContextRef cgContext,
     /* Init the base surface */
     surface = malloc(sizeof(cairo_quartz_surface_t));
     if (surface == NULL)
-	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
+	return (cairo_quartz_surface_t*) _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
 
     memset(surface, 0, sizeof(cairo_quartz_surface_t));
 
@@ -1941,7 +1891,7 @@ cairo_quartz_surface_create_for_cg_context (CGContextRef cgContext,
     if (surf->base.status) {
 	CGContextRelease (cgContext);
 	// create_internal will have set an error
-	return surf;
+	return (cairo_surface_t*) surf;
     }
 
     return (cairo_surface_t *) surf;
@@ -2044,7 +1994,7 @@ cairo_quartz_surface_create (cairo_format_t format,
 	CGContextRelease (cgc);
 	free (imageData);
 	// create_internal will have set an error
-	return surf;
+	return (cairo_surface_t*) surf;
     }
 
     surf->imageData = imageData;


More information about the cairo-commit mailing list