[cairo-commit] 2 commits - src/cairo-clip-boxes.c src/cairo-image-source.c src/cairoint.h src/cairo-pattern.c src/cairo-spans-compositor.c src/cairo-surface.c src/cairo-traps-compositor.c

Andrea Canciani ranma42 at kemper.freedesktop.org
Sun Jan 15 09:30:58 PST 2012


 src/cairo-clip-boxes.c       |    7 +------
 src/cairo-image-source.c     |   10 ++--------
 src/cairo-pattern.c          |   34 ++++++++++------------------------
 src/cairo-spans-compositor.c |   10 +---------
 src/cairo-surface.c          |    5 +----
 src/cairo-traps-compositor.c |   10 +---------
 src/cairoint.h               |   10 ++++++++++
 7 files changed, 26 insertions(+), 60 deletions(-)

New commits:
commit a2f419b546f620ede105b5a6b5958260925d9a50
Author: Andrea Canciani <ranma42 at gmail.com>
Date:   Sat Jan 7 16:19:43 2012 +0100

    rectangle: Implement _cairo_rectangle_contains_rectangle()
    
    And reuse it.

diff --git a/src/cairo-clip-boxes.c b/src/cairo-clip-boxes.c
index f42b53d..be4497c 100644
--- a/src/cairo-clip-boxes.c
+++ b/src/cairo-clip-boxes.c
@@ -82,13 +82,8 @@ _cairo_clip_contains_rectangle_box (const cairo_clip_t *clip,
     if (clip->path)
 	return FALSE;
 
-    if (clip->extents.x > rect->x ||
-	clip->extents.y > rect->y ||
-	clip->extents.x + clip->extents.width  < rect->x + rect->width ||
-	clip->extents.y + clip->extents.height < rect->y + rect->height)
-    {
+    if (! _cairo_rectangle_contains_rectangle (&clip->extents, rect))
 	return FALSE;
-    }
 
     /* Check for a clip-box that wholly contains the rectangle */
     for (i = 0; i < clip->num_boxes; i++) {
diff --git a/src/cairo-image-source.c b/src/cairo-image-source.c
index 26f245a..047a049 100644
--- a/src/cairo-image-source.c
+++ b/src/cairo-image-source.c
@@ -621,18 +621,12 @@ _pixman_image_for_recording (cairo_image_surface_t *dst,
 
     extend = pattern->base.extend;
     if (_cairo_surface_get_extents (source, &limit)) {
-	if (sample->x >= limit.x &&
-	    sample->y >= limit.y &&
-	    sample->x + sample->width  <= limit.x + limit.width &&
-	    sample->y + sample->height <= limit.y + limit.height)
+	if (_cairo_rectangle_contains_rectangle (&limit, sample))
 	{
 	    extend = CAIRO_EXTEND_NONE;
 	}
 	else if (extend == CAIRO_EXTEND_NONE &&
-		 (sample->x + sample->width <= limit.x ||
-		  sample->x >= limit.x + limit.width ||
-		  sample->y + sample->height <= limit.y ||
-		  sample->y >= limit.y + limit.height))
+		 ! _cairo_rectangle_intersects (&limit, sample))
 	{
 	    return _pixman_transparent_image ();
 	}
diff --git a/src/cairo-pattern.c b/src/cairo-pattern.c
index 41d7384..ea47b6a 100644
--- a/src/cairo-pattern.c
+++ b/src/cairo-pattern.c
@@ -3143,17 +3143,10 @@ _surface_is_opaque (const cairo_surface_pattern_t *pattern,
     if (! _cairo_surface_get_extents (pattern->surface, &extents))
 	return TRUE;
 
-    if (sample != NULL) {
-	if (sample->x >= extents.x &&
-	    sample->y >= extents.y &&
-	    sample->x + sample->width  <= extents.x + extents.width &&
-	    sample->y + sample->height <= extents.y + extents.height)
-	{
-	    return TRUE;
-	}
-    }
+    if (sample == NULL)
+	return FALSE;
 
-    return FALSE;
+    return _cairo_rectangle_contains_rectangle (&extents, sample);
 }
 
 static cairo_bool_t
@@ -3166,17 +3159,10 @@ _raster_source_is_opaque (const cairo_raster_source_pattern_t *pattern,
     if (pattern->base.extend != CAIRO_EXTEND_NONE)
 	return TRUE;
 
-    if (sample != NULL) {
-	if (sample->x >= pattern->extents.x &&
-	    sample->y >= pattern->extents.y &&
-	    sample->x + sample->width  <= pattern->extents.x + pattern->extents.width &&
-	    sample->y + sample->height <= pattern->extents.y + pattern->extents.height)
-	{
-	    return TRUE;
-	}
-    }
+    if (sample == NULL)
+	return FALSE;
 
-    return FALSE;
+    return _cairo_rectangle_contains_rectangle (&pattern->extents, sample);
 }
 
 static cairo_bool_t
diff --git a/src/cairo-spans-compositor.c b/src/cairo-spans-compositor.c
index 468f338..0e94be8 100644
--- a/src/cairo-spans-compositor.c
+++ b/src/cairo-spans-compositor.c
@@ -421,15 +421,7 @@ recording_pattern_contains_sample (const cairo_pattern_t *pattern,
     if (surface->unbounded)
 	return TRUE;
 
-    if (sample->x >= surface->extents.x &&
-	sample->y >= surface->extents.y &&
-	sample->x + sample->width <= surface->extents.x + surface->extents.width &&
-	sample->y + sample->height <= surface->extents.y + surface->extents.height)
-    {
-	return TRUE;
-    }
-
-    return FALSE;
+    return _cairo_rectangle_contains_rectangle (&surface->extents, sample);
 }
 
 static cairo_bool_t
diff --git a/src/cairo-surface.c b/src/cairo-surface.c
index 88f306a..2607f29 100644
--- a/src/cairo-surface.c
+++ b/src/cairo-surface.c
@@ -631,10 +631,7 @@ cairo_surface_map_to_image (cairo_surface_t  *surface,
 	/* If this surface is bounded, we can't map parts
 	 * that are outside of it. */
 	if (likely (surface->backend->get_extents (surface, &surface_extents))) {
-	    if (unlikely (extents->x < surface_extents.x ||
-			  extents->y < surface_extents.y ||
-			  extents->x + extents->width > surface_extents.x + surface_extents.width ||
-			  extents->y + extents->height > surface_extents.y + surface_extents.height))
+	    if (unlikely (! _cairo_rectangle_contains_rectangle (&surface_extents, extents)))
 		return _cairo_surface_create_in_error (CAIRO_STATUS_INVALID_SIZE);
 	}
     }
diff --git a/src/cairo-traps-compositor.c b/src/cairo-traps-compositor.c
index 0371c80..ac0a56f 100644
--- a/src/cairo-traps-compositor.c
+++ b/src/cairo-traps-compositor.c
@@ -959,15 +959,7 @@ recording_pattern_contains_sample (const cairo_pattern_t *pattern,
     if (surface->unbounded)
 	return TRUE;
 
-    if (sample->x >= surface->extents.x &&
-	sample->y >= surface->extents.y &&
-	sample->x + sample->width <= surface->extents.x + surface->extents.width &&
-	sample->y + sample->height <= surface->extents.y + surface->extents.height)
-    {
-	return TRUE;
-    }
-
-    return FALSE;
+    return _cairo_rectangle_contains_rectangle (&surface->extents, sample);
 }
 
 static cairo_bool_t
diff --git a/src/cairoint.h b/src/cairoint.h
index 8f4c370..f08462c 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -310,6 +310,16 @@ _cairo_rectangle_intersects (const cairo_rectangle_int_t *dst,
 	     src->y + (int) src->height <= dst->y);
 }
 
+static inline cairo_bool_t
+_cairo_rectangle_contains_rectangle (const cairo_rectangle_int_t *a,
+				     const cairo_rectangle_int_t *b)
+{
+    return (a->x <= b->x &&
+	    a->x + (int) a->width >= b->x + (int) b->width &&
+	    a->y <= b->y &&
+	    a->y + (int) a->height >= b->y + (int) b->height);
+}
+
 cairo_private void
 _cairo_rectangle_int_from_double (cairo_rectangle_int_t *recti,
 				  const cairo_rectangle_t *rectf);
commit 2808bf5b95e84f3a4d8ee7b56c340860d0348a8a
Author: Andrea Canciani <ranma42 at gmail.com>
Date:   Sat Jan 7 16:44:48 2012 +0100

    pattern: Infinite color-only sources are always opaque
    
    No matter what the sampling extents are, infinite color-only sources
    are opaque.

diff --git a/src/cairo-pattern.c b/src/cairo-pattern.c
index bcc0035..41d7384 100644
--- a/src/cairo-pattern.c
+++ b/src/cairo-pattern.c
@@ -3132,18 +3132,18 @@ static cairo_bool_t
 _surface_is_opaque (const cairo_surface_pattern_t *pattern,
 		    const cairo_rectangle_int_t *sample)
 {
+    cairo_rectangle_int_t extents;
+
     if (pattern->surface->content & CAIRO_CONTENT_ALPHA)
 	return FALSE;
 
     if (pattern->base.extend != CAIRO_EXTEND_NONE)
 	return TRUE;
 
-    if (sample != NULL) {
-	cairo_rectangle_int_t extents;
-
-	if (! _cairo_surface_get_extents (pattern->surface, &extents))
-	    return TRUE;
+    if (! _cairo_surface_get_extents (pattern->surface, &extents))
+	return TRUE;
 
+    if (sample != NULL) {
 	if (sample->x >= extents.x &&
 	    sample->y >= extents.y &&
 	    sample->x + sample->width  <= extents.x + extents.width &&


More information about the cairo-commit mailing list