summaryrefslogtreecommitdiff
path: root/src/cairo-image-surface.c
diff options
context:
space:
mode:
authorAndrea Canciani <ranma42@gmail.com>2012-01-08 15:30:03 +0100
committerAndrea Canciani <ranma42@gmail.com>2012-05-26 16:06:21 +0200
commit10c0a1c68c34677273d2f48c5d5a6c1c15a320c0 (patch)
tree7ba50c9b2f5250a086a8978cef8ab255d514b281 /src/cairo-image-surface.c
parent3e9895e95100ced3a6fcbedcba75e50ca450b4f0 (diff)
downloadcairo-10c0a1c68c34677273d2f48c5d5a6c1c15a320c0.tar.gz
surface: Define private map/unmap functions
Cairo backends often need to map/unmap to a raster surface but they don't care about the pixel format, as Pixman will be doing the format handling. Cairo users cannot know how to access the raw data if the format is invalid. The two different scenarios call for different guarantees on the returned surface. The private map/unmap functions also makes it possible to simply return the status upon unmapping.
Diffstat (limited to 'src/cairo-image-surface.c')
-rw-r--r--src/cairo-image-surface.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c
index 98f70c585..00369b61a 100644
--- a/src/cairo-image-surface.c
+++ b/src/cairo-image-surface.c
@@ -1202,3 +1202,44 @@ _cairo_image_analyze_color (cairo_image_surface_t *image)
return image->color = CAIRO_IMAGE_IS_COLOR;
}
+
+static const cairo_user_data_key_t clone_key;
+
+cairo_image_surface_t *
+_cairo_image_surface_clone_subimage (cairo_surface_t *surface,
+ const cairo_rectangle_int_t *extents)
+{
+ cairo_surface_t *image;
+ cairo_surface_pattern_t pattern;
+ cairo_status_t ignored;
+
+ image = cairo_surface_create_similar_image (surface,
+ _cairo_format_from_content (surface->content),
+ extents->width,
+ extents->height);
+ /* TODO: check me with non-identity device_transform. Should we
+ * clone the scaling, too? */
+ cairo_surface_set_device_offset (image,
+ -extents->x,
+ -extents->y);
+
+ _cairo_pattern_init_for_surface (&pattern, surface);
+ pattern.base.filter = CAIRO_FILTER_NEAREST;
+
+ ignored = _cairo_surface_paint (image,
+ CAIRO_OPERATOR_SOURCE,
+ &pattern.base,
+ NULL);
+
+ _cairo_pattern_fini (&pattern.base);
+
+ cairo_surface_set_user_data (image, &clone_key, surface, NULL);
+
+ return (cairo_image_surface_t *) image;
+}
+
+cairo_bool_t
+_cairo_image_surface_is_clone (cairo_image_surface_t *image)
+{
+ return cairo_surface_get_user_data (&image->base, &clone_key) != NULL;
+}