[gtk] transformnode: Avoid matrix multiplication if we can



commit bbd4e2f60d9e060fbe3b0c2dcebcd1d6b7335a2a
Author: Timm Bäder <mail baedert org>
Date:   Tue Feb 26 07:24:18 2019 +0100

    transformnode: Avoid matrix multiplication if we can
    
    If the given matrix is explicitly of category IDENTITY, we don't need to
    do anything, and in the 2D_TRANSLATE case, just offset the child bounds.
    Those are the two most common cases.

 gsk/gskrendernodeimpl.c | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)
---
diff --git a/gsk/gskrendernodeimpl.c b/gsk/gskrendernodeimpl.c
index 1b7d5be39e..114df174c2 100644
--- a/gsk/gskrendernodeimpl.c
+++ b/gsk/gskrendernodeimpl.c
@@ -2547,9 +2547,30 @@ gsk_transform_node_new_with_category (GskRenderNode           *child,
   graphene_matrix_init_from_matrix (&self->transform, transform);
   self->category = category;
 
-  graphene_matrix_transform_bounds (&self->transform,
-                                    &child->bounds,
-                                    &self->render_node.bounds);
+  switch (category)
+    {
+    case GSK_MATRIX_CATEGORY_IDENTITY:
+      graphene_rect_init_from_rect (&self->render_node.bounds, &child->bounds);
+    break;
+
+    case GSK_MATRIX_CATEGORY_2D_TRANSLATE:
+      {
+        graphene_rect_init_from_rect (&self->render_node.bounds, &child->bounds);
+        self->render_node.bounds.origin.x += graphene_matrix_get_value (transform, 3, 0);
+        self->render_node.bounds.origin.y += graphene_matrix_get_value (transform, 3, 1);
+      }
+    break;
+
+    case GSK_MATRIX_CATEGORY_2D_AFFINE:
+    case GSK_MATRIX_CATEGORY_ANY:
+    case GSK_MATRIX_CATEGORY_UNKNOWN:
+    case GSK_MATRIX_CATEGORY_INVERTIBLE:
+    default:
+      graphene_matrix_transform_bounds (&self->transform,
+                                        &child->bounds,
+                                        &self->render_node.bounds);
+    }
+
   return &self->render_node;
 }
 


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