[gtk/misc-speedups: 4/11] gsk: Add a shortcut for a common transform case




commit b695ef916853753534ae3385af1d9b21d95777ff
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Jul 24 10:48:20 2021 -0400

    gsk: Add a shortcut for a common transform case
    
    Add a private getter for the translation part of a
    transform node, to avoid pulling it out of the transform
    over and over.

 gsk/gskrendernodeimpl.c    | 17 +++++++++++++++++
 gsk/gskrendernodeprivate.h |  4 ++++
 gsk/ngl/gsknglrenderjob.c  | 25 ++++++++++++++++++-------
 3 files changed, 39 insertions(+), 7 deletions(-)
---
diff --git a/gsk/gskrendernodeimpl.c b/gsk/gskrendernodeimpl.c
index ef008f8294..9a9705d0fd 100644
--- a/gsk/gskrendernodeimpl.c
+++ b/gsk/gskrendernodeimpl.c
@@ -2804,6 +2804,7 @@ struct _GskTransformNode
 
   GskRenderNode *child;
   GskTransform *transform;
+  float dx, dy;
 };
 
 static void
@@ -2955,6 +2956,11 @@ gsk_transform_node_new (GskRenderNode *child,
   self->child = gsk_render_node_ref (child);
   self->transform = gsk_transform_ref (transform);
 
+  if (gsk_transform_get_category (transform) >= GSK_TRANSFORM_CATEGORY_2D_TRANSLATE)
+    gsk_transform_to_translate (transform, &self->dx, &self->dy);
+  else
+    self->dx = self->dy = 0;
+
   gsk_transform_transform_bounds (self->transform,
                                   &child->bounds,
                                   &node->bounds);
@@ -2994,6 +3000,17 @@ gsk_transform_node_get_transform (const GskRenderNode *node)
   return self->transform;
 }
 
+void
+gsk_transform_node_get_translate (const GskRenderNode *node,
+                                  float               *dx,
+                                  float               *dy)
+{
+  const GskTransformNode *self = (const GskTransformNode *) node;
+
+  *dx = self->dx;
+  *dy = self->dy;
+}
+
 /*** GSK_OPACITY_NODE ***/
 
 /**
diff --git a/gsk/gskrendernodeprivate.h b/gsk/gskrendernodeprivate.h
index b9e719cdfb..ac20813b65 100644
--- a/gsk/gskrendernodeprivate.h
+++ b/gsk/gskrendernodeprivate.h
@@ -106,6 +106,10 @@ void            gsk_text_node_serialize_glyphs          (GskRenderNode
 GskRenderNode ** gsk_container_node_get_children        (const GskRenderNode *node,
                                                          guint               *n_children);
 
+void             gsk_transform_node_get_translate       (const GskRenderNode *node,
+                                                         float               *dx,
+                                                         float               *dy);
+
 
 G_END_DECLS
 
diff --git a/gsk/ngl/gsknglrenderjob.c b/gsk/ngl/gsknglrenderjob.c
index 6f87340624..2351379b2e 100644
--- a/gsk/ngl/gsknglrenderjob.c
+++ b/gsk/ngl/gsknglrenderjob.c
@@ -89,6 +89,8 @@ typedef struct _GskNglRenderModelview
   GskTransform *transform;
   float scale_x;
   float scale_y;
+  float dx;
+  float dy;
   float offset_x_before;
   float offset_y_before;
   graphene_matrix_t matrix;
@@ -424,22 +426,28 @@ gsk_ngl_render_job_set_alpha (GskNglRenderJob *job,
 static void
 extract_matrix_metadata (GskNglRenderModelview *modelview)
 {
-  float dummy;
-
   gsk_transform_to_matrix (modelview->transform, &modelview->matrix);
 
   switch (gsk_transform_get_category (modelview->transform))
     {
     case GSK_TRANSFORM_CATEGORY_IDENTITY:
+      modelview->scale_x = 1;
+      modelview->scale_y = 1;
+      modelview->dx = 0;
+      modelview->dy = 0;
+      break;
+
     case GSK_TRANSFORM_CATEGORY_2D_TRANSLATE:
       modelview->scale_x = 1;
       modelview->scale_y = 1;
+      gsk_transform_to_translate (modelview->transform,
+                                  &modelview->dx, &modelview->dy);
       break;
 
     case GSK_TRANSFORM_CATEGORY_2D_AFFINE:
       gsk_transform_to_affine (modelview->transform,
                                &modelview->scale_x, &modelview->scale_y,
-                               &dummy, &dummy);
+                               &modelview->dx, &modelview->dy);
       break;
 
     case GSK_TRANSFORM_CATEGORY_UNKNOWN:
@@ -464,6 +472,8 @@ extract_matrix_metadata (GskNglRenderModelview *modelview)
 
         modelview->scale_x = graphene_vec3_length (&col1);
         modelview->scale_y = graphene_vec3_length (&col2);
+        modelview->dx = 0;
+        modelview->dy = 0;
       }
       break;
 
@@ -743,9 +753,10 @@ gsk_ngl_render_job_transform_bounds (GskNglRenderJob       *job,
    */
   if G_LIKELY (category >= GSK_TRANSFORM_CATEGORY_2D_AFFINE)
     {
-      float dx, dy, scale_x, scale_y;
-
-      gsk_transform_to_affine (transform, &scale_x, &scale_y, &dx, &dy);
+      float scale_x = job->current_modelview->scale_x;
+      float scale_y = job->current_modelview->scale_y;
+      float dx = job->current_modelview->dx;
+      float dy = job->current_modelview->dy;
 
       /* Init directly into out rect */
       out_rect->origin.x = ((rect->origin.x + job->offset_x) * scale_x) + dx;
@@ -1956,7 +1967,7 @@ gsk_ngl_render_job_visit_transform_node (GskNglRenderJob     *job,
       {
         float dx, dy;
 
-        gsk_transform_to_translate (transform, &dx, &dy);
+        gsk_transform_node_get_translate (node, &dx, &dy);
         gsk_ngl_render_job_offset (job, dx, dy);
         gsk_ngl_render_job_visit_node (job, child);
         gsk_ngl_render_job_offset (job, -dx, -dy);


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