Bug 575521 - Add cairo_quartz_surface_get_image to get the image associated with a quartz surface, if it exists. r=jrmuizel,vlad,bas
authorJoe Drew <joe@drew.ca>
Thu, 11 Nov 2010 15:31:23 -0500
changeset 57346 1490c9277562d81443397bd50d86dc4b94bfc145
parent 57345 42244cff985a141c3a8401f92264ddd6939e9e6d
child 57347 7cfc5393907d81f28a95f4a6c0eecb04d8a380ef
push id16887
push userjdrew@mozilla.com
push dateThu, 11 Nov 2010 20:37:00 +0000
treeherdermozilla-central@182eb3c4fc44 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel, vlad, bas
bugs575521
milestone2.0b8pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 575521 - Add cairo_quartz_surface_get_image to get the image associated with a quartz surface, if it exists. r=jrmuizel,vlad,bas
gfx/cairo/README
gfx/cairo/cairo/src/cairo-quartz-surface.c
gfx/cairo/cairo/src/cairo-quartz.h
gfx/cairo/cairo/src/cairo-rename.h
gfx/cairo/quartz-get-image.patch
--- a/gfx/cairo/README
+++ b/gfx/cairo/README
@@ -69,16 +69,18 @@ quartz-state.patch: bug 522859; refactor
 quartz-cache-CGImageRef.patch: cache CGImageRef for a CGBitmapContext; when we reuse it, Quartz will cache stuff, improving performance
 
 quartz-remove-snapshot.patch: remove broken implementation of backend snapshot
 
 quartz-cglayers.patch: add support for cairo surfaces backed by CGLayers
 
 quartz-cglayers-fix-fallback.patch: Bug 572912; fix bug in fallback code in previous patch
 
+quartz-get-image.patch: Bug 575521; add a way to get the image surface associated with a surface
+
 premultiply-alpha-solid-gradients.patch: bug 539165; multiply the solid color by the alpha component before using it for a solid surface
 
 xlib-initialize-members.path: bug 548793; initialize XRender version if the server doesn't have the extension
 
 remove-comma: remove a comma from enum
 
 d2d.patch: add d2d support
 
--- a/gfx/cairo/cairo/src/cairo-quartz-surface.c
+++ b/gfx/cairo/cairo/src/cairo-quartz-surface.c
@@ -1880,24 +1880,24 @@ static cairo_status_t
     surface->cgContext = NULL;
 
     if (surface->bitmapContextImage) {
         CGImageRelease (surface->bitmapContextImage);
         surface->bitmapContextImage = NULL;
     }
 
     if (surface->imageSurfaceEquiv) {
+	_cairo_image_surface_assume_ownership_of_data (surface->imageSurfaceEquiv);
 	cairo_surface_destroy (surface->imageSurfaceEquiv);
 	surface->imageSurfaceEquiv = NULL;
+    } else if (surface->imageData) {
+        free (surface->imageData);
     }
 
-    if (surface->imageData) {
-	free (surface->imageData);
-	surface->imageData = NULL;
-    }
+    surface->imageData = NULL;
 
     if (surface->cgLayer) {
         CGLayerRelease (surface->cgLayer);
     }
 
     return CAIRO_STATUS_SUCCESS;
 }
 
@@ -3200,16 +3200,28 @@ cairo_quartz_finish_cg_context_with_clip
     cairo_quartz_surface_t *quartz = (cairo_quartz_surface_t*)surface;
 
     if (cairo_surface_get_type(surface) != CAIRO_SURFACE_TYPE_QUARTZ)
 	return;
 
     CGContextRestoreGState (quartz->cgContext);
 }
 
+cairo_surface_t *
+cairo_quartz_surface_get_image (cairo_surface_t *surface)
+{
+    cairo_quartz_surface_t *quartz = (cairo_quartz_surface_t *)surface;
+    cairo_image_surface_t *image;
+
+    if (_cairo_quartz_get_image(quartz, &image))
+        return NULL;
+
+    return (cairo_surface_t *)image;
+}
+
 /* Debug stuff */
 
 #ifdef QUARTZ_DEBUG
 
 #include <Movies.h>
 
 void ExportCGImageToPNGFile(CGImageRef inImageRef, char* dest)
 {
--- a/gfx/cairo/cairo/src/cairo-quartz.h
+++ b/gfx/cairo/cairo/src/cairo-quartz.h
@@ -63,16 +63,19 @@ cairo_public CGContextRef
 cairo_quartz_surface_get_cg_context (cairo_surface_t *surface);
 
 cairo_public CGContextRef
 cairo_quartz_get_cg_context_with_clip (cairo_t *cr);
 
 cairo_public void
 cairo_quartz_finish_cg_context_with_clip (cairo_t *cr);
 
+cairo_public cairo_surface_t *
+cairo_quartz_surface_get_image (cairo_surface_t *surface);
+
 #if CAIRO_HAS_QUARTZ_FONT
 
 /*
  * Quartz font support
  */
 
 cairo_public cairo_font_face_t *
 cairo_quartz_font_face_create_for_cgfont (CGFontRef font);
--- a/gfx/cairo/cairo/src/cairo-rename.h
+++ b/gfx/cairo/cairo/src/cairo-rename.h
@@ -178,16 +178,17 @@
 #define cairo_qpainter_surface_get_qpainter _moz_cairo_qpainter_surface_get_qpainter
 #define cairo_quartz_font_face_create_for_atsu_font_id _moz_cairo_quartz_font_face_create_for_atsu_font_id
 #define cairo_quartz_font_face_create_for_cgfont _moz_cairo_quartz_font_face_create_for_cgfont
 #define cairo_quartz_image_surface_create _moz_cairo_quartz_image_surface_create
 #define cairo_quartz_image_surface_get_image _moz_cairo_quartz_image_surface_get_image
 #define cairo_quartz_surface_create _moz_cairo_quartz_surface_create
 #define cairo_quartz_surface_create_for_cg_context _moz_cairo_quartz_surface_create_for_cg_context
 #define cairo_quartz_surface_get_cg_context _moz_cairo_quartz_surface_get_cg_context
+#define cairo_quartz_surface_get_image _moz_cairo_quartz_surface_get_image
 #define cairo_rectangle _moz_cairo_rectangle
 #define cairo_rectangle_list_destroy _moz_cairo_rectangle_list_destroy
 #define cairo_reference _moz_cairo_reference
 #define cairo_rel_curve_to _moz_cairo_rel_curve_to
 #define cairo_rel_line_to _moz_cairo_rel_line_to
 #define cairo_rel_move_to _moz_cairo_rel_move_to
 #define cairo_reset_clip _moz_cairo_reset_clip
 #define cairo_restore _moz_cairo_restore
new file mode 100644
--- /dev/null
+++ b/gfx/cairo/quartz-get-image.patch
@@ -0,0 +1,127 @@
+diff --git a/gfx/cairo/README b/gfx/cairo/README
+--- a/gfx/cairo/README
++++ b/gfx/cairo/README
+@@ -69,16 +69,18 @@ quartz-state.patch: bug 522859; refactor
+ quartz-cache-CGImageRef.patch: cache CGImageRef for a CGBitmapContext; when we reuse it, Quartz will cache stuff, improving performance
+ 
+ quartz-remove-snapshot.patch: remove broken implementation of backend snapshot
+ 
+ quartz-cglayers.patch: add support for cairo surfaces backed by CGLayers
+ 
+ quartz-cglayers-fix-fallback.patch: Bug 572912; fix bug in fallback code in previous patch
+ 
++quartz-get-image.patch: Bug 575521; add a way to get the image surface associated with a surface
++
+ premultiply-alpha-solid-gradients.patch: bug 539165; multiply the solid color by the alpha component before using it for a solid surface
+ 
+ xlib-initialize-members.path: bug 548793; initialize XRender version if the server doesn't have the extension
+ 
+ remove-comma: remove a comma from enum
+ 
+ d2d.patch: add d2d support
+ 
+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
+@@ -1880,24 +1880,24 @@ _cairo_quartz_surface_finish (void *abst
+     surface->cgContext = NULL;
+ 
+     if (surface->bitmapContextImage) {
+         CGImageRelease (surface->bitmapContextImage);
+         surface->bitmapContextImage = NULL;
+     }
+ 
+     if (surface->imageSurfaceEquiv) {
++	_cairo_image_surface_assume_ownership_of_data (surface->imageSurfaceEquiv);
+ 	cairo_surface_destroy (surface->imageSurfaceEquiv);
+ 	surface->imageSurfaceEquiv = NULL;
++    } else if (surface->imageData) {
++        free (surface->imageData);
+     }
+ 
+-    if (surface->imageData) {
+-	free (surface->imageData);
+-	surface->imageData = NULL;
+-    }
++    surface->imageData = NULL;
+ 
+     if (surface->cgLayer) {
+         CGLayerRelease (surface->cgLayer);
+     }
+ 
+     return CAIRO_STATUS_SUCCESS;
+ }
+ 
+@@ -3200,16 +3200,28 @@ cairo_quartz_finish_cg_context_with_clip
+     cairo_quartz_surface_t *quartz = (cairo_quartz_surface_t*)surface;
+ 
+     if (cairo_surface_get_type(surface) != CAIRO_SURFACE_TYPE_QUARTZ)
+ 	return;
+ 
+     CGContextRestoreGState (quartz->cgContext);
+ }
+ 
++cairo_surface_t *
++cairo_quartz_surface_get_image (cairo_surface_t *surface)
++{
++    cairo_quartz_surface_t *quartz = (cairo_quartz_surface_t *)surface;
++    cairo_image_surface_t *image;
++
++    if (_cairo_quartz_get_image(quartz, &image))
++        return NULL;
++
++    return (cairo_surface_t *)image;
++}
++
+ /* Debug stuff */
+ 
+ #ifdef QUARTZ_DEBUG
+ 
+ #include <Movies.h>
+ 
+ void ExportCGImageToPNGFile(CGImageRef inImageRef, char* dest)
+ {
+diff --git a/gfx/cairo/cairo/src/cairo-quartz.h b/gfx/cairo/cairo/src/cairo-quartz.h
+--- a/gfx/cairo/cairo/src/cairo-quartz.h
++++ b/gfx/cairo/cairo/src/cairo-quartz.h
+@@ -63,16 +63,19 @@ cairo_public CGContextRef
+ cairo_quartz_surface_get_cg_context (cairo_surface_t *surface);
+ 
+ cairo_public CGContextRef
+ cairo_quartz_get_cg_context_with_clip (cairo_t *cr);
+ 
+ cairo_public void
+ cairo_quartz_finish_cg_context_with_clip (cairo_t *cr);
+ 
++cairo_public cairo_surface_t *
++cairo_quartz_surface_get_image (cairo_surface_t *surface);
++
+ #if CAIRO_HAS_QUARTZ_FONT
+ 
+ /*
+  * Quartz font support
+  */
+ 
+ cairo_public cairo_font_face_t *
+ cairo_quartz_font_face_create_for_cgfont (CGFontRef font);
+diff --git a/gfx/cairo/cairo/src/cairo-rename.h b/gfx/cairo/cairo/src/cairo-rename.h
+--- a/gfx/cairo/cairo/src/cairo-rename.h
++++ b/gfx/cairo/cairo/src/cairo-rename.h
+@@ -178,16 +178,17 @@
+ #define cairo_qpainter_surface_get_qpainter _moz_cairo_qpainter_surface_get_qpainter
+ #define cairo_quartz_font_face_create_for_atsu_font_id _moz_cairo_quartz_font_face_create_for_atsu_font_id
+ #define cairo_quartz_font_face_create_for_cgfont _moz_cairo_quartz_font_face_create_for_cgfont
+ #define cairo_quartz_image_surface_create _moz_cairo_quartz_image_surface_create
+ #define cairo_quartz_image_surface_get_image _moz_cairo_quartz_image_surface_get_image
+ #define cairo_quartz_surface_create _moz_cairo_quartz_surface_create
+ #define cairo_quartz_surface_create_for_cg_context _moz_cairo_quartz_surface_create_for_cg_context
+ #define cairo_quartz_surface_get_cg_context _moz_cairo_quartz_surface_get_cg_context
++#define cairo_quartz_surface_get_image _moz_cairo_quartz_surface_get_image
+ #define cairo_rectangle _moz_cairo_rectangle
+ #define cairo_rectangle_list_destroy _moz_cairo_rectangle_list_destroy
+ #define cairo_reference _moz_cairo_reference
+ #define cairo_rel_curve_to _moz_cairo_rel_curve_to
+ #define cairo_rel_line_to _moz_cairo_rel_line_to
+ #define cairo_rel_move_to _moz_cairo_rel_move_to
+ #define cairo_reset_clip _moz_cairo_reset_clip
+ #define cairo_restore _moz_cairo_restore