DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (31ec81b5d7bb)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
changeset:   42954:7881873b2b5d
user:        Robert O'Callahan <robert@ocallahan.org>
date:        Tue Jun 01 11:19:45 2010 +1200
summary:     Bug 552537. Cache the CGImageRef that we create for a CGBitmapContext so that we can take advantage of Quartz caching optimizations. r=jrmuizel

diff --git a/gfx/cairo/cairo/src/cairo-quartz-private.h b/gfx/cairo/cairo/src/cairo-quartz-private.h
--- a/gfx/cairo/cairo/src/cairo-quartz-private.h
+++ b/gfx/cairo/cairo/src/cairo-quartz-private.h
@@ -49,16 +49,24 @@ typedef struct cairo_quartz_surface {
 
     CGContextRef cgContext;
     CGAffineTransform cgContextBaseCTM;
 
     void *imageData;
     cairo_surface_t *imageSurfaceEquiv;
 
     cairo_surface_clipper_t clipper;
+
+    /**
+     * If non-null, this is a CGImage representing the contents of the surface.
+     * We clear this out before any painting into the surface, so that we
+     * don't force a copy to be created.
+     */
+    CGImageRef bitmapContextImage;
+
     cairo_rectangle_int_t extents;
 } cairo_quartz_surface_t;
 
 typedef struct cairo_quartz_image_surface {
     cairo_surface_t base;
 
     cairo_rectangle_int_t extents;
 
diff --git a/gfx/cairo/cairo/src/cairo-quartz-surface.c b/gfx/cairo/cairo/src/cairo-quartz-surface.c
--- a/gfx/cairo/cairo/src/cairo-quartz-surface.c
+++ b/gfx/cairo/cairo/src/cairo-quartz-surface.c
@@ -1134,19 +1134,24 @@ _cairo_surface_to_cgimage (cairo_surface
     if (stype == CAIRO_SURFACE_TYPE_QUARTZ) {
 	cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) source;
 	if (IS_EMPTY(surface)) {
 	    *image_out = NULL;
 	    return CAIRO_STATUS_SUCCESS;
 	}
 
 	if (_cairo_quartz_is_cgcontext_bitmap_context (surface->cgContext)) {
-	    *image_out = CGBitmapContextCreateImage (surface->cgContext);
-	    if (*image_out)
-		return CAIRO_STATUS_SUCCESS;
+	    if (!surface->bitmapContextImage) {
+	        surface->bitmapContextImage =
+	            CGBitmapContextCreateImage (surface->cgContext);
+	    }
+	    if (surface->bitmapContextImage) {
+                *image_out = CGImageRetain (surface->bitmapContextImage);
+                return CAIRO_STATUS_SUCCESS;
+            }
 	}
     }
 
     if (stype != CAIRO_SURFACE_TYPE_IMAGE) {
 	status = _cairo_surface_acquire_source_image (source,
 						      &isurf, &image_extra);
 	if (status)
 	    return status;
@@ -1589,16 +1594,29 @@ _cairo_quartz_setup_radial_source (cairo
 
     CGColorSpaceRelease(rgb);
     CGFunctionRelease(gradFunc);
 
     state->action = DO_SHADING;
 }
 
 /**
+ * Call this before any operation that can modify the contents of a
+ * cairo_quartz_surface_t.
+ */
+static void
+_cairo_quartz_surface_will_change (cairo_quartz_surface_t *surface)
+{
+    if (surface->bitmapContextImage) {
+        CGImageRelease (surface->bitmapContextImage);
+        surface->bitmapContextImage = NULL;
+    }
+}
+
+/**
  * Sets up internal state to be used to draw the source mask, stored in
  * cairo_quartz_state_t. Guarantees to call CGContextSaveGState on
  * surface->cgContext.
  */
 static cairo_quartz_drawing_state_t
 _cairo_quartz_setup_state (cairo_quartz_surface_t *surface,
 			   const cairo_pattern_t *source,
 			   cairo_operator_t op,
@@ -1609,16 +1627,18 @@ _cairo_quartz_setup_state (cairo_quartz_
     cairo_status_t status;
 
     state.context = context;
     state.image = NULL;
     state.imageSurface = NULL;
     state.shading = NULL;
     state.pattern = NULL;
 
+    _cairo_quartz_surface_will_change (surface);
+
     // Save before we change the pattern, colorspace, etc. so that
     // we can restore and make sure that quartz releases our
     // pattern (which may be stack allocated)
     CGContextSaveGState(context);
 
     CGContextSetInterpolationQuality (context, _cairo_quartz_filter_to_quartz (source->filter));
 
     status = _cairo_quartz_surface_set_cairo_operator (surface, op);
@@ -1936,16 +1956,21 @@ _cairo_quartz_surface_finish (void *abst
     /* Restore our saved gstate that we use to reset clipping */
     CGContextRestoreGState (surface->cgContext);
     _cairo_surface_clipper_reset (&surface->clipper);
 
     CGContextRelease (surface->cgContext);
 
     surface->cgContext = NULL;
 
+    if (surface->bitmapContextImage) {
+        CGImageRelease (surface->bitmapContextImage);
+        surface->bitmapContextImage = NULL;
+    }
+
     if (surface->imageSurfaceEquiv) {
 	cairo_surface_destroy (surface->imageSurfaceEquiv);
 	surface->imageSurfaceEquiv = NULL;
     }
 
     if (surface->imageData) {
 	free (surface->imageData);
 	surface->imageData = NULL;
@@ -2006,16 +2031,18 @@ _cairo_quartz_surface_acquire_dest_image
 					  cairo_rectangle_int_t *image_rect,
 					  void **image_extra)
 {
     cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) abstract_surface;
     cairo_int_status_t status;
 
     ND((stderr, "%p _cairo_quartz_surface_acquire_dest_image\n", surface));
 
+    _cairo_quartz_surface_will_change (surface);
+
     status = _cairo_quartz_get_image (surface, image_out);
     if (status)
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     *image_rect = surface->extents;
     *image_extra = NULL;
 
     return CAIRO_STATUS_SUCCESS;
@@ -2939,16 +2966,17 @@ _cairo_quartz_surface_create_internal (C
      */
     CGContextSaveGState (cgContext);
 
     surface->cgContext = cgContext;
     surface->cgContextBaseCTM = CGContextGetCTM (cgContext);
 
     surface->imageData = NULL;
     surface->imageSurfaceEquiv = NULL;
+    surface->bitmapContextImage = NULL;
 
     return surface;
 }
 
 /**
  * cairo_quartz_surface_create_for_cg_context
  * @cgContext: the existing CGContext for which to create the surface
  * @width: width of the surface, in pixels