[cairo-commit] 2 commits - src/cairo.c test/push-group-path-offset.c

Benjamin Otte company at kemper.freedesktop.org
Fri Jun 25 05:12:22 PDT 2010


 src/cairo.c                   |    8 ++++---
 test/push-group-path-offset.c |   45 ++++++++++++++----------------------------
 2 files changed, 21 insertions(+), 32 deletions(-)

New commits:
commit 1373675ef7602363aeca0d9ec12be79719ea066d
Author: Benjamin Otte <otte at redhat.com>
Date:   Fri Jun 25 14:10:12 2010 +0200

    pop-group: Translate existing path properly
    
    This fixes the reverse case of the push_group case fixed a few commits
    ago.

diff --git a/src/cairo.c b/src/cairo.c
index d43c031..748a637 100644
--- a/src/cairo.c
+++ b/src/cairo.c
@@ -691,7 +691,7 @@ cairo_pop_group (cairo_t *cr)
 {
     cairo_surface_t *group_surface, *parent_target;
     cairo_pattern_t *group_pattern;
-    cairo_matrix_t group_matrix;
+    cairo_matrix_t group_matrix, device_transform_matrix;
     cairo_status_t status;
 
     if (unlikely (cr->status))
@@ -740,8 +740,10 @@ cairo_pop_group (cairo_t *cr)
 
     /* If we have a current path, we need to adjust it to compensate for
      * the device offset just removed. */
-    _cairo_path_fixed_transform (cr->path,
-				 &group_surface->device_transform_inverse);
+    cairo_matrix_multiply (&device_transform_matrix, 
+                           &_cairo_gstate_get_target (cr->gstate)->device_transform,
+			   &group_surface->device_transform_inverse);
+    _cairo_path_fixed_transform (cr->path, &device_transform_matrix);
 
 done:
     cairo_surface_destroy (group_surface);
commit 59076776674e3ae47099f20e1d86064fbd856008
Author: Benjamin Otte <otte at redhat.com>
Date:   Fri Jun 25 14:08:49 2010 +0200

    test: improve push-group-path-offset to also catch the pop_group() case
    
    cairo_pop_group() also trasnforms the path wrong, so we use cairo_fill()
    to copy data instead of cairo_paint().
    
    (Also, unbust the testcase.)

diff --git a/test/push-group-path-offset.c b/test/push-group-path-offset.c
index ec6015b..6b73ca4 100644
--- a/test/push-group-path-offset.c
+++ b/test/push-group-path-offset.c
@@ -26,8 +26,7 @@
 
 #include "cairo-test.h"
 
-#define DEVICE_OFFSET -10
-#define CLIP_OFFSET 25
+#define CLIP_OFFSET 15
 #define CLIP_SIZE 20
 
 #define WIDTH 50
@@ -36,47 +35,35 @@
 static cairo_test_status_t
 draw (cairo_t *cr, int width, int height)
 {
-    cairo_surface_t *similar;
-    cairo_t *similar_cr;
-
-    similar = cairo_surface_create_similar (cairo_get_target (cr), 
-                                            cairo_surface_get_content (cairo_get_target (cr)),
-                                            width, height);
-    cairo_surface_set_device_offset (similar, DEVICE_OFFSET, DEVICE_OFFSET);
-
-    similar_cr = cairo_create (similar);
-
     /* Neutral gray background */
-    cairo_set_source_rgb (similar_cr, 0.51613, 0.55555, 0.51613);
-    cairo_paint (similar_cr);
+    cairo_set_source_rgb (cr, 0.51613, 0.55555, 0.51613);
+    cairo_paint (cr);
+
+    /* the rest uses CAIRO_OPERATOR_SOURCE so we see better when something goes wrong */
+    cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
 
     /* add a rectangle */
-    cairo_rectangle (similar_cr, CLIP_OFFSET, CLIP_OFFSET, CLIP_SIZE, CLIP_SIZE);
+    cairo_rectangle (cr, CLIP_OFFSET, CLIP_OFFSET, CLIP_SIZE, CLIP_SIZE);
 
     /* clip to the rectangle */
-    cairo_clip_preserve (similar_cr);
+    cairo_clip_preserve (cr);
 
     /* push a group. We now have a device offset. */
-    cairo_push_group (similar_cr);
+    cairo_push_group (cr);
 
     /* push a group again. This is where the bug used to happen. */
+    cairo_push_group (cr);
 
     /* draw something */
-    cairo_set_source_rgb (similar_cr, 1, 0, 0);
-    cairo_fill (similar_cr);
+    cairo_set_source_rgb (cr, 1, 0, 0);
+    cairo_fill_preserve (cr);
 
     /* make sure the stuff we drew ends up on the output */
-    cairo_pop_group_to_source (similar_cr);
-    cairo_paint (similar_cr);
-
-    cairo_pop_group_to_source (similar_cr);
-    cairo_paint (similar_cr);
-
-    cairo_destroy (similar_cr);
+    cairo_pop_group_to_source (cr);
+    cairo_fill_preserve (cr);
 
-    cairo_set_source_surface (cr, similar, DEVICE_OFFSET, DEVICE_OFFSET);
-    cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
-    cairo_paint (cr);
+    cairo_pop_group_to_source (cr);
+    cairo_fill_preserve (cr);
 
     return CAIRO_TEST_SUCCESS;
 }


More information about the cairo-commit mailing list