[gtk/wip/otte/no-clip-on-draw: 3/8] rendernode: Avoid rounding errors



commit c3842f903b7e7ce7b92b0854f7f42d0a09dd6164
Author: Benjamin Otte <otte redhat com>
Date:   Wed Feb 12 18:44:11 2020 +0100

    rendernode: Avoid rounding errors
    
    Compute the pattern matrix directly instead of transforming the cairo_t.
    
    This ensures that when node_size / texture_size is some obscure floating
    point value, we don't get rounding issues from scaling by it once we
    draw the texture_size rectangle.
    
    I have no actual failure where this comes in handy, but I had written
    the code anyway, so decided to keep it.

 gsk/gskrendernodeimpl.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
---
diff --git a/gsk/gskrendernodeimpl.c b/gsk/gskrendernodeimpl.c
index a6957ff657..43844cd1e2 100644
--- a/gsk/gskrendernodeimpl.c
+++ b/gsk/gskrendernodeimpl.c
@@ -638,28 +638,28 @@ gsk_texture_node_draw (GskRenderNode *node,
   GskTextureNode *self = (GskTextureNode *) node;
   cairo_surface_t *surface;
   cairo_pattern_t *pattern;
+  cairo_matrix_t matrix;
 
   surface = gdk_texture_download_surface (self->texture);
-
-  cairo_save (cr);
-
-  cairo_translate (cr, node->bounds.origin.x, node->bounds.origin.y);
-  cairo_scale (cr,
-               node->bounds.size.width / gdk_texture_get_width (self->texture),
-               node->bounds.size.height / gdk_texture_get_height (self->texture));
-
   pattern = cairo_pattern_create_for_surface (surface);
   cairo_pattern_set_extend (pattern, CAIRO_EXTEND_PAD);
-  cairo_set_source (cr, pattern);
-  cairo_rectangle (cr,
-                   0, 0,
-                   gdk_texture_get_width (self->texture), gdk_texture_get_height (self->texture));
-  cairo_fill (cr);
 
-  cairo_restore (cr);
+  cairo_matrix_init_scale (&matrix,
+                           gdk_texture_get_width (self->texture) / node->bounds.size.width,
+                           gdk_texture_get_height (self->texture) / node->bounds.size.height);
+  cairo_matrix_translate (&matrix,
+                          -node->bounds.origin.x,
+                          -node->bounds.origin.y);
+  cairo_pattern_set_matrix (pattern, &matrix);
 
+  cairo_set_source (cr, pattern);
   cairo_pattern_destroy (pattern);
   cairo_surface_destroy (surface);
+
+  cairo_rectangle (cr,
+                   node->bounds.origin.x, node->bounds.origin.y,
+                   node->bounds.size.width, node->bounds.size.height);
+  cairo_fill (cr);
 }
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]