summaryrefslogtreecommitdiff
path: root/boilerplate
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2011-08-13 11:05:45 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2011-08-13 11:08:58 +0100
commit7a17e4362e3b149ccb3590df690b91974416bfdf (patch)
treebe69a762501d04b509622d59d6af6a4d303bf0bd /boilerplate
parent9d5d46e8466f9417febfdefef6707bae9818b02d (diff)
boilerplate: improve fidelity of surface extraction
Create an image surface of equivalent content to the original. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'boilerplate')
-rw-r--r--boilerplate/cairo-boilerplate.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/boilerplate/cairo-boilerplate.c b/boilerplate/cairo-boilerplate.c
index b89e6d817..229c4c77c 100644
--- a/boilerplate/cairo-boilerplate.c
+++ b/boilerplate/cairo-boilerplate.c
@@ -274,6 +274,7 @@ _cairo_boilerplate_get_image_surface (cairo_surface_t *src,
cairo_surface_t *surface, *image;
cairo_t *cr;
cairo_status_t status;
+ cairo_format_t format;
if (cairo_surface_status (src))
return cairo_surface_reference (src);
@@ -282,7 +283,20 @@ _cairo_boilerplate_get_image_surface (cairo_surface_t *src,
return cairo_boilerplate_surface_create_in_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
/* extract sub-surface */
- surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
+ switch (cairo_surface_get_content (src)) {
+ case CAIRO_CONTENT_ALPHA:
+ format = CAIRO_FORMAT_A8;
+ break;
+ case CAIRO_CONTENT_COLOR:
+ format = CAIRO_FORMAT_RGB24;
+ break;
+ default:
+ case CAIRO_CONTENT_COLOR_ALPHA:
+ format = CAIRO_FORMAT_ARGB32;
+ break;
+ }
+ surface = cairo_image_surface_create (format, width, height);
+ assert (cairo_surface_get_content (surface) == cairo_surface_get_content (src));
image = cairo_surface_reference (surface);
/* open a logging channel (only interesting for recording surfaces) */
@@ -309,9 +323,7 @@ _cairo_boilerplate_get_image_surface (cairo_surface_t *src,
cr = cairo_create (surface);
cairo_surface_destroy (surface);
-
cairo_set_source_surface (cr, src, 0, 0);
- cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
cairo_paint (cr);
status = cairo_status (cr);