summaryrefslogtreecommitdiff
path: root/src/cairo-image-surface.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2011-07-22 00:36:03 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2011-07-26 14:55:58 +0100
commita69335a84eb9225b477cc8c753470eb3805b852c (patch)
tree7a28492ebf390e513391af587f00c017e4ca6301 /src/cairo-image-surface.c
parentc6812c6a3679c3b8b9584e119e0d7fd93e09ae49 (diff)
downloadcairo-a69335a84eb9225b477cc8c753470eb3805b852c.tar.gz
API: map-to-image and create-similar-image
A common requirement is the fast upload of pixel data. In order to allocate the most appropriate image buffer, we need knowledge of the destination. The most obvious example is that we could use a shared-memory region for the image to avoid the transfer cost of uploading the pixels to the X server. Similarly, gl, win32, quartz... The other side of the equation is that for manual modification of a remote surface, it would be more efficient if we can create a similar image to reduce the transfer costs. This strategy is already followed for the destination fallbacks and this merely exposes the same capability for the application fallbacks. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'src/cairo-image-surface.c')
-rw-r--r--src/cairo-image-surface.c37
1 files changed, 36 insertions, 1 deletions
diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c
index c14aac064..369f1728e 100644
--- a/src/cairo-image-surface.c
+++ b/src/cairo-image-surface.c
@@ -728,6 +728,36 @@ _cairo_image_surface_create_similar (void *abstract_other,
width, height);
}
+static cairo_surface_t *
+_cairo_image_surface_map_to_image (void *abstract_other,
+ const cairo_rectangle_int_t *extents)
+{
+ cairo_image_surface_t *other = abstract_other;
+ cairo_surface_t *surface;
+ uint8_t *data;
+
+ data = other->data;
+ data += extents->y * other->stride;
+ data += extents->x * PIXMAN_FORMAT_BPP (other->pixman_format)/ 8;
+
+ surface =
+ _cairo_image_surface_create_with_pixman_format (data,
+ other->pixman_format,
+ extents->width,
+ extents->height,
+ other->stride);
+
+ cairo_surface_set_device_offset (surface, -extents->x, -extents->y);
+ return surface;
+}
+
+static cairo_int_status_t
+_cairo_image_surface_unmap_image (void *abstract_surface,
+ cairo_image_surface_t *image)
+{
+ return CAIRO_INT_STATUS_SUCCESS;
+}
+
static cairo_status_t
_cairo_image_surface_finish (void *abstract_surface)
{
@@ -4655,10 +4685,15 @@ _cairo_surface_is_image (const cairo_surface_t *surface)
const cairo_surface_backend_t _cairo_image_surface_backend = {
CAIRO_SURFACE_TYPE_IMAGE,
+ _cairo_image_surface_finish,
+
_cairo_default_context_create,
_cairo_image_surface_create_similar,
- _cairo_image_surface_finish,
+ NULL, /* create similar image */
+ _cairo_image_surface_map_to_image,
+ _cairo_image_surface_unmap_image,
+
_cairo_image_surface_acquire_source_image,
_cairo_image_surface_release_source_image,
_cairo_image_surface_acquire_dest_image,