[cairo-commit] src/cairo-surface-subsurface.c

Andrea Canciani ranma42 at kemper.freedesktop.org
Sun Jan 24 14:54:36 PST 2010


 src/cairo-surface-subsurface.c |   36 +++++++++++++++---------------------
 1 file changed, 15 insertions(+), 21 deletions(-)

New commits:
commit a9a73e5df42840148fd4db60cc0d1ba5d137b764
Author: Andrea Canciani <ranma42 at gmail.com>
Date:   Sun Jan 24 23:26:28 2010 +0100

    Constrain subsurface creation
    
    Force the subsurface extents to be inside the target extents and
    compose subsubsurfaces offsets correctly.
    Reviewed-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/src/cairo-surface-subsurface.c b/src/cairo-surface-subsurface.c
index f027c8c..52748a0 100644
--- a/src/cairo-surface-subsurface.c
+++ b/src/cairo-surface-subsurface.c
@@ -421,30 +421,12 @@ cairo_surface_create_for_region (cairo_surface_t *target,
 				 int width, int height)
 {
     cairo_surface_subsurface_t *surface;
+    cairo_rectangle_int_t target_extents;
+    cairo_bool_t is_empty;
 
     if (unlikely (target->status))
 	return _cairo_surface_create_in_error (target->status);
 
-    if (target->backend->type == CAIRO_INTERNAL_SURFACE_TYPE_SUBSURFACE) {
-	/* Maintain subsurfaces as 1-depth */
-	cairo_surface_subsurface_t *sub = (cairo_surface_subsurface_t *) target;
-	cairo_rectangle_int_t r;
-	cairo_bool_t is_empty;
-
-	r.x = x;
-	r.y = y;
-	r.width  = width;
-	r.height = height;
-
-	is_empty = _cairo_rectangle_intersect (&r, &sub->extents);
-
-	x = r.x;
-	y = r.y;
-	width = r.width;
-	height = r.height;
-	target = sub->target;
-    }
-
     surface = malloc (sizeof (cairo_surface_subsurface_t));
     if (unlikely (surface == NULL))
 	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
@@ -455,11 +437,23 @@ cairo_surface_create_for_region (cairo_surface_t *target,
 			 target->content);
     surface->base.type = target->type;
 
-    surface->target = cairo_surface_reference (target);
     surface->extents.x = x;
     surface->extents.y = y;
     surface->extents.width = width;
     surface->extents.height = height;
 
+    if (_cairo_surface_get_extents (target, &target_extents))
+        is_empty = _cairo_rectangle_intersect (&surface->extents, &target_extents);
+
+    if (target->backend->type == CAIRO_INTERNAL_SURFACE_TYPE_SUBSURFACE) {
+	/* Maintain subsurfaces as 1-depth */
+	cairo_surface_subsurface_t *sub = (cairo_surface_subsurface_t *) target;
+	surface->extents.x += sub->extents.x;
+	surface->extents.y += sub->extents.y;
+	target = sub->target;
+    }
+
+    surface->target = cairo_surface_reference (target);
+
     return &surface->base;
 }


More information about the cairo-commit mailing list