[cairo-commit] 2 commits - test/clip-device-offset.c test/surface-pattern-scale-down-extend.c

Andrea Canciani ranma42 at kemper.freedesktop.org
Sun Feb 13 11:51:02 PST 2011


 test/clip-device-offset.c                |    6 +++---
 test/surface-pattern-scale-down-extend.c |   13 +++++++++++++
 2 files changed, 16 insertions(+), 3 deletions(-)

New commits:
commit 5fa49462be24b7fc7f32032d8577703f1d0f463a
Author: Andrea Canciani <ranma42 at gmail.com>
Date:   Sun Feb 13 18:36:12 2011 +0100

    test: Fix surface-pattern-scale-down-extend
    
    This test creates a similar surface using cairo_push_group () and
    assumes its size will be w x h. This is not true when testing similar
    surfaces with "cairo-test-suite -a", because they are bigger than the
    actual ROI, which corresponds to the rectangle (0,0) - (w,h).
    
    Clipping to the ROI guarantees that the surface created by
    cairo_push_group () always has the same size.
    
    Fixes surface-pattern-scale-down-extend.

diff --git a/test/surface-pattern-scale-down-extend.c b/test/surface-pattern-scale-down-extend.c
index 8033861..191ab92 100644
--- a/test/surface-pattern-scale-down-extend.c
+++ b/test/surface-pattern-scale-down-extend.c
@@ -39,6 +39,17 @@ draw_with_extend (cairo_t *cr, int w, int h, cairo_extend_t extend)
     cairo_set_source_rgb (cr, 1,1,1);
     cairo_paint (cr);
 
+    cairo_save (cr);
+
+    /* When the destination surface is created by cairo-test-suite to
+     * test device-offset, it is bigger than w x h. This test expects
+     * the group to have a size which is exactly w x h, so it must
+     * clip to the this rectangle to guarantee that the group will
+     * have the correct size.
+     */
+    cairo_rectangle (cr, 0, 0, w, h);
+    cairo_clip (cr);
+
     cairo_push_group_with_content (cr, CAIRO_CONTENT_COLOR); {
         /* A two by two checkerboard with black, red and yellow
          * cells. */
@@ -52,6 +63,8 @@ draw_with_extend (cairo_t *cr, int w, int h, cairo_extend_t extend)
     pattern = cairo_pop_group (cr);
     cairo_pattern_set_extend(pattern, extend);
 
+    cairo_restore (cr);
+
     cairo_scale (cr, 0.5, 0.5);
     cairo_set_source (cr, pattern);
     cairo_paint (cr);
commit 34612c400d3b66daf265529d90a3dcd1a8afdbcb
Author: Andrea Canciani <ranma42 at gmail.com>
Date:   Sun Feb 13 17:28:31 2011 +0100

    test: Fix clip-device-offset
    
    The test was incorrectly translating the "target" of the context
    instead of the "group target" (i.e. the current destination).
    
    "cairo-test-suite -a" runs the tests on similar surfaces created using
    cairo_push_group (), thus without this change the device-offset did
    not affect the real destination surface.
    
    Fixes clip-device-offset.

diff --git a/test/clip-device-offset.c b/test/clip-device-offset.c
index eb0e249..f725b8e 100644
--- a/test/clip-device-offset.c
+++ b/test/clip-device-offset.c
@@ -54,8 +54,8 @@ draw (cairo_t *cr, int width, int height)
   cairo_pattern_t *source;
   double old_x, old_y;
 
-  cairo_surface_get_device_offset (cairo_get_target (cr), &old_x, &old_y);
-  cairo_surface_set_device_offset (cairo_get_target (cr), old_x+5, old_y+5);
+  cairo_surface_get_device_offset (cairo_get_group_target (cr), &old_x, &old_y);
+  cairo_surface_set_device_offset (cairo_get_group_target (cr), old_x+5, old_y+5);
 
   source = create_green_source ();
   cairo_set_source (cr, source);
@@ -66,7 +66,7 @@ draw (cairo_t *cr, int width, int height)
   cairo_clip (cr);
   cairo_paint (cr);
 
-  cairo_surface_set_device_offset (cairo_get_target (cr), old_x, old_y);
+  cairo_surface_set_device_offset (cairo_get_group_target (cr), old_x, old_y);
 
   return CAIRO_TEST_SUCCESS;
 }


More information about the cairo-commit mailing list