[cairo-commit] 5 commits - src/cairo-atsui-font.c src/cairo-quartz.h src/cairo-quartz-private.h src/cairo-quartz-surface.c

Anders Carlsson andersca at kemper.freedesktop.org
Mon Apr 10 16:09:27 PDT 2006


 src/cairo-atsui-font.c     |    1 
 src/cairo-quartz-private.h |   10 -
 src/cairo-quartz-surface.c |  239 +++++++++++++++++++++------------------------
 src/cairo-quartz.h         |    4 
 4 files changed, 120 insertions(+), 134 deletions(-)

New commits:
diff-tree 9231ab40437e70818c9525fa9648ff7a5d11e44a (from parents)
Merge: 1e5f5aed07137d3a823c2d22e29eb0e53e359fef baa3436e9d8ea37c1204f752cac78a8cbc891f18
Author: Anders Carlsson <andersca at luminoth.local>
Date:   Tue Apr 11 01:09:30 2006 +0200

    Merge with git+ssh://git.cairographics.org/git/cairo

diff-tree 1e5f5aed07137d3a823c2d22e29eb0e53e359fef (from 3ed576522df8a4e41e856a500539ca3e6f69e2da)
Author: Anders Carlsson <andersca at luminoth.local>
Date:   Tue Apr 11 01:07:33 2006 +0200

    Make the API more like Vlad's new API.#

diff --git a/src/cairo-quartz-private.h b/src/cairo-quartz-private.h
index a57e078..8b90135 100644
--- a/src/cairo-quartz-private.h
+++ b/src/cairo-quartz-private.h
@@ -44,7 +44,7 @@ typedef struct cairo_quartz_surface {
 
     CGContextRef context;
 
-    cairo_bool_t flipped;
+    cairo_bool_t y_grows_down;
 
     cairo_rectangle_t extents;
 
diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c
index ed6a825..e5b683a 100644
--- a/src/cairo-quartz-surface.c
+++ b/src/cairo-quartz-surface.c
@@ -161,7 +161,7 @@ _cairo_quartz_surface_release_dest_image
 
     rect = CGRectMake (image_rect->x, image_rect->y, image_rect->width, image_rect->height);
 
-    if (surface->flipped) {
+    if (surface->y_grows_down) {
 	CGContextSaveGState (surface->context);
 	CGContextTranslateCTM (surface->context, 0, image_rect->height + 2 * image_rect->y);
 	CGContextScaleCTM (surface->context, 1, -1);
@@ -170,7 +170,7 @@ _cairo_quartz_surface_release_dest_image
     CGContextDrawImage(surface->context, rect, image_ref);
     CFRelease (image_ref);
     
-    if (surface->flipped) {
+    if (surface->y_grows_down) {
 	CGContextRestoreGState (surface->context);
     }
     
@@ -229,8 +229,9 @@ static const struct _cairo_surface_backe
 
 
 cairo_surface_t *cairo_quartz_surface_create(CGContextRef context,
-					     cairo_bool_t flipped,
-                                             int width, int height)
+					     int width, 
+					     int height,
+					     cairo_bool_t y_grows_down)
 {
     cairo_quartz_surface_t *surface;
     CGRect clip_box;
@@ -245,7 +246,7 @@ cairo_surface_t *cairo_quartz_surface_cr
 
     surface->context = context;
     surface->clip_region = NULL;
-    surface->flipped = flipped;
+    surface->y_grows_down = y_grows_down;
 
     clip_box = CGContextGetClipBoundingBox (context);
     surface->extents.x = clip_box.origin.x;
diff --git a/src/cairo-quartz.h b/src/cairo-quartz.h
index 9ef537e..b3072df 100644
--- a/src/cairo-quartz.h
+++ b/src/cairo-quartz.h
@@ -47,9 +47,9 @@ CAIRO_BEGIN_DECLS
 
 cairo_public cairo_surface_t *
 cairo_quartz_surface_create (CGContextRef    context,
-			     cairo_bool_t    flipped,
 			     int	     width,
-			     int	     height);
+			     int	     height,
+			     cairo_bool_t    y_grows_down);
 
 CAIRO_END_DECLS
 
diff-tree 3ed576522df8a4e41e856a500539ca3e6f69e2da (from 8ba59b0336ddc581c8f43b4aa5cf9acdb2c001ad)
Author: Anders Carlsson <andersca at luminoth.local>
Date:   Mon Apr 10 22:29:51 2006 +0200

    Remove unused function

diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c
index 0f84661..ed6a825 100644
--- a/src/cairo-quartz-surface.c
+++ b/src/cairo-quartz-surface.c
@@ -37,14 +37,6 @@
 #include "cairo-private.h"
 #include "cairo-quartz-private.h"
 
-static void
-ImageDataReleaseFunc(void *info, const void *data, size_t size)
-{
-    if (data != NULL) {
-        free((void *) data);
-    }
-}
-
 static cairo_status_t
 _cairo_quartz_surface_finish(void *abstract_surface)
 {
diff-tree 8ba59b0336ddc581c8f43b4aa5cf9acdb2c001ad (from df3c02c9ca0c704df3960416fbe689af0cedf2fa)
Author: Anders Carlsson <andersca at luminoth.local>
Date:   Mon Apr 10 22:24:02 2006 +0200

    Rework the quartz backend to not always hold an image but instead to create it on demand.#

diff --git a/src/cairo-quartz-private.h b/src/cairo-quartz-private.h
index d291c76..a57e078 100644
--- a/src/cairo-quartz-private.h
+++ b/src/cairo-quartz-private.h
@@ -46,13 +46,9 @@ typedef struct cairo_quartz_surface {
 
     cairo_bool_t flipped;
 
-    int width;
-    int height;
+    cairo_rectangle_t extents;
 
-    cairo_image_surface_t *image;
-	 pixman_region16_t *clip_region;
-	
-    CGImageRef cgImage;
+    pixman_region16_t *clip_region;
 } cairo_quartz_surface_t;
 
 cairo_bool_t
diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c
index 5bf01bb..0f84661 100644
--- a/src/cairo-quartz-surface.c
+++ b/src/cairo-quartz-surface.c
@@ -50,14 +50,8 @@ _cairo_quartz_surface_finish(void *abstr
 {
     cairo_quartz_surface_t *surface = abstract_surface;
 
-    if (surface->image)
-        cairo_surface_destroy(&surface->image->base);
-
-    if (surface->cgImage)
-        CGImageRelease(surface->cgImage);
-
-	if (surface->clip_region)
-		pixman_region_destroy (surface->clip_region);
+    if (surface->clip_region)
+      pixman_region_destroy (surface->clip_region);
 		
     return CAIRO_STATUS_SUCCESS;
 }
@@ -67,64 +61,13 @@ _cairo_quartz_surface_acquire_source_ima
 					   cairo_image_surface_t **image_out,
 					   void **image_extra)
 {
-    cairo_quartz_surface_t *surface = abstract_surface;
-    CGColorSpaceRef colorSpace;
-    void *imageData;
-    UInt32 imageDataSize, rowBytes;
-    CGDataProviderRef dataProvider;
-
-    /* We keep a cached (cairo_image_surface_t *) in the cairo_quartz_surface_t
-     * struct. If the window is ever drawn to without going through Cairo, then
-     * we would need to refetch the pixel data from the window into the cached
-     * image surface. 
-     */
-    if (surface->image) {
-        cairo_surface_reference(&surface->image->base);
-
-	*image_out = surface->image;
-	return CAIRO_STATUS_SUCCESS;
-    }
-
-    colorSpace = CGColorSpaceCreateDeviceRGB();
-
+  cairo_quartz_surface_t *surface = abstract_surface;
 
-    rowBytes = surface->width * 4;
-    imageDataSize = rowBytes * surface->height;
-    imageData = malloc(imageDataSize);
-
-    dataProvider =
-        CGDataProviderCreateWithData(NULL, imageData, imageDataSize,
-                                     ImageDataReleaseFunc);
-
-    surface->cgImage = CGImageCreate(surface->width,
-                                     surface->height,
-                                     8,
-                                     32,
-                                     rowBytes,
-                                     colorSpace,
-                                     kCGImageAlphaPremultipliedFirst,
-                                     dataProvider,
-                                     NULL,
-                                     false, kCGRenderingIntentDefault);
-
-    CGColorSpaceRelease(colorSpace);
-    CGDataProviderRelease(dataProvider);
-
-    surface->image = (cairo_image_surface_t *)
-        cairo_image_surface_create_for_data(imageData,
-                                            CAIRO_FORMAT_ARGB32,
-                                            surface->width,
-                                            surface->height, rowBytes);
-    if (surface->image->base.status) {
-	if (surface->cgImage)
-	    CGImageRelease(surface->cgImage);
-	return CAIRO_STATUS_NO_MEMORY;
-    }
-
-    *image_out = surface->image;
-    *image_extra = NULL;
+  if (CGBitmapContextGetBitmapInfo (surface->context) != 0) {
+    /* XXX: We can create an image out of the bitmap here */
+  }
 
-    return CAIRO_STATUS_SUCCESS;
+  return CAIRO_INT_STATUS_UNSUPPORTED;
 }
 
 static cairo_status_t
@@ -136,19 +79,79 @@ _cairo_quartz_surface_acquire_dest_image
                                          void **image_extra)
 {
     cairo_quartz_surface_t *surface = abstract_surface;
+    cairo_surface_t *image_surface;
+    unsigned char *data;
+    int x1, y1, x2, y2;
+
+    x1 = surface->extents.x;
+    x2 = surface->extents.x + surface->extents.width;
+    y1 = surface->extents.y;
+    y2 = surface->extents.y + surface->extents.height;
+
+    if (interest_rect->x > x1)
+	x1 = interest_rect->x;
+    if (interest_rect->y > y1)
+	y1 = interest_rect->y;
+    if (interest_rect->x + interest_rect->width < x2)
+	x2 = interest_rect->x + interest_rect->width;
+    if (interest_rect->y + interest_rect->height < y2)
+	y2 = interest_rect->y + interest_rect->height;
 
-    image_rect->x = 0;
-    image_rect->y = 0;
-    image_rect->width = surface->image->width;
-    image_rect->height = surface->image->height;
-
-    *image_out = surface->image;
-    if (image_extra)
+    if (x1 >= x2 || y1 >= y2) {
+	*image_out = NULL;
 	*image_extra = NULL;
+	
+	return CAIRO_STATUS_SUCCESS;
+    }
+
+    image_rect->x = x1;
+    image_rect->y = y1;
+    image_rect->width = x2 - x1;
+    image_rect->height = y2 - y1;
+
+    data = calloc (image_rect->width * image_rect->height * 4, 1);
+    image_surface = cairo_image_surface_create_for_data (data, 
+							 CAIRO_FORMAT_ARGB32,
+							 image_rect->width,
+							 image_rect->height,
+							 image_rect->width * 4);
+
+    *image_out = (cairo_image_surface_t *)image_surface;
+    *image_extra = data;
 
     return CAIRO_STATUS_SUCCESS;
+
+    return CAIRO_INT_STATUS_UNSUPPORTED;
 }
 
+static CGImageRef
+create_image_from_surface (cairo_image_surface_t *image_surface, void *data)
+{
+  CGImageRef image;
+  CGColorSpaceRef color_space;
+  CGDataProviderRef data_provider;
+  int width, height;
+
+  width = cairo_image_surface_get_width ((cairo_surface_t *)image_surface);
+  height = cairo_image_surface_get_height ((cairo_surface_t *)image_surface);
+  
+  color_space = CGColorSpaceCreateDeviceRGB();
+  data_provider = CGDataProviderCreateWithData (NULL, data, 
+						width * height * 4, NULL);
+  image = CGImageCreate (width, height,
+			 8, 32,
+			 width * 4,
+			 color_space,
+			 kCGImageAlphaPremultipliedFirst,
+			 data_provider,
+			 NULL,
+			 FALSE, kCGRenderingIntentDefault);
+
+  CGColorSpaceRelease (color_space);
+  CGDataProviderRelease (data_provider);
+			   
+  return image;
+}
 
 static void
 _cairo_quartz_surface_release_dest_image(void *abstract_surface,
@@ -159,25 +162,28 @@ _cairo_quartz_surface_release_dest_image
                                          void *image_extra)
 {
     cairo_quartz_surface_t *surface = abstract_surface;
+    CGImageRef image_ref;
+    CGRect rect;
+    
+    image_ref = create_image_from_surface (image, image_extra);
+
+    rect = CGRectMake (image_rect->x, image_rect->y, image_rect->width, image_rect->height);
+
+    if (surface->flipped) {
+	CGContextSaveGState (surface->context);
+	CGContextTranslateCTM (surface->context, 0, image_rect->height + 2 * image_rect->y);
+	CGContextScaleCTM (surface->context, 1, -1);
+    }
 
-    if (surface->image == image) {
-        CGRect rect;
-
-        rect = CGRectMake(0, 0, surface->width, surface->height);
-
-	if (surface->flipped) {
-	    CGContextSaveGState (surface->context);
-	    CGContextTranslateCTM (surface->context, 0, surface->height);
-	    CGContextScaleCTM (surface->context, 1, -1);
-	}
-
-        CGContextDrawImage(surface->context, rect, surface->cgImage);
-
-	if (surface->flipped)
-	    CGContextRestoreGState (surface->context);
-
-	memset(surface->image->data, 0, surface->width * surface->height * 4);
+    CGContextDrawImage(surface->context, rect, image_ref);
+    CFRelease (image_ref);
+    
+    if (surface->flipped) {
+	CGContextRestoreGState (surface->context);
     }
+    
+    cairo_surface_destroy ((cairo_surface_t *)image);
+    free (image_extra);
 }
 
 static cairo_int_status_t
@@ -185,21 +191,17 @@ _cairo_quartz_surface_set_clip_region(vo
                                       pixman_region16_t * region)
 {
     cairo_quartz_surface_t *surface = abstract_surface;
-    unsigned int serial;
-
-    serial = _cairo_surface_allocate_clip_serial (&surface->image->base);
 
-	if (surface->clip_region)
-		pixman_region_destroy (surface->clip_region);
+    if (surface->clip_region)
+	pixman_region_destroy (surface->clip_region);
 		
-	if (region) {
-		surface->clip_region = pixman_region_create ();
-		pixman_region_copy (surface->clip_region, region);
-	} else
-		surface->clip_region = NULL;
-		
-    return _cairo_surface_set_clip_region(&surface->image->base,
-					  region, serial);
+    if (region) {
+	surface->clip_region = pixman_region_create ();
+	pixman_region_copy (surface->clip_region, region);
+    } else
+	surface->clip_region = NULL;
+
+    return CAIRO_STATUS_SUCCESS;
 }
 
 static cairo_int_status_t
@@ -208,10 +210,7 @@ _cairo_quartz_surface_get_extents (void 
 {
     cairo_quartz_surface_t *surface = abstract_surface;
 
-    rectangle->x = 0;
-    rectangle->y = 0;
-    rectangle->width = surface->width;
-    rectangle->height = surface->height;
+    *rectangle = surface->extents;
 
     return CAIRO_STATUS_SUCCESS;
 }
@@ -242,6 +241,7 @@ cairo_surface_t *cairo_quartz_surface_cr
                                              int width, int height)
 {
     cairo_quartz_surface_t *surface;
+    CGRect clip_box;
 
     surface = malloc(sizeof(cairo_quartz_surface_t));
     if (surface == NULL) {
@@ -252,16 +252,14 @@ cairo_surface_t *cairo_quartz_surface_cr
     _cairo_surface_init(&surface->base, &cairo_quartz_surface_backend);
 
     surface->context = context;
-    surface->width = width;
-    surface->height = height;
-    surface->image = NULL;
-    surface->cgImage = NULL;
-	surface->clip_region = NULL;
+    surface->clip_region = NULL;
     surface->flipped = flipped;
 
-    /* Set up the image surface which Cairo draws into and we blit to & from. */
-    void *foo;
-    _cairo_quartz_surface_acquire_source_image(surface, &surface->image, &foo);
+    clip_box = CGContextGetClipBoundingBox (context);
+    surface->extents.x = clip_box.origin.x;
+    surface->extents.y = clip_box.origin.y;
+    surface->extents.width = clip_box.size.width;
+    surface->extents.height = clip_box.size.height;
 
     return (cairo_surface_t *) surface;
 }
diff-tree df3c02c9ca0c704df3960416fbe689af0cedf2fa (from 807f64d57c616e2ce8a61202cd9b59ac7a6a26cb)
Author: Anders Carlsson <andersca at luminoth.local>
Date:   Mon Apr 10 22:23:39 2006 +0200

    Don't set can_draw_directly to FALSE.

diff --git a/src/cairo-atsui-font.c b/src/cairo-atsui-font.c
index 6c9f715..76b5a3c 100644
--- a/src/cairo-atsui-font.c
+++ b/src/cairo-atsui-font.c
@@ -576,7 +576,6 @@ _cairo_atsui_font_old_show_glyphs (void	
 	_cairo_pattern_is_opaque_solid (pattern) &&
 	op == CAIRO_OPERATOR_OVER;
 
-    can_draw_directly = FALSE;
     if (!can_draw_directly) {
 	rect.x = dest_x;
 	rect.y = dest_y;


More information about the cairo-commit mailing list