gsk: Add gskrectprivate.h
authorBenjamin Otte <otte@redhat.com>
Thu, 20 Jul 2023 20:25:20 +0000 (22:25 +0200)
committerBenjamin Otte <otte@redhat.com>
Fri, 21 Jul 2023 23:33:44 +0000 (01:33 +0200)
Add a bunch of inline functions for graphene_rectangle_t.

We use those quite extensively in tight loops so making them as fast as
possible via inlining has massive benefits.

The current render-heavy benchmark I am playing (th paris-30k in node-editor)
went from 49fps to 85fps on my AMD.

gsk/gl/gskglrenderjob.c
gsk/gskrectprivate.h [new file with mode: 0644]
gsk/gskroundedrect.c
gsk/vulkan/gskvulkanclip.c

index 11d410a2051c95daf1f85a64daafa04f72643d2b..8382b203f59a1a115a97ef5f55dc910f6a22b9e3 100644 (file)
@@ -32,6 +32,7 @@
 #include <gdk/gdkmemorytextureprivate.h>
 #include <gsk/gsktransformprivate.h>
 #include <gsk/gskroundedrectprivate.h>
+#include <gsk/gskrectprivate.h>
 #include <math.h>
 #include <string.h>
 
@@ -353,31 +354,6 @@ color_matrix_modifies_alpha (const GskRenderNode *node)
   return !graphene_vec4_equal (graphene_vec4_w_axis (), &row3);
 }
 
-static inline gboolean G_GNUC_PURE
-rect_contains_rect (const graphene_rect_t *r1,
-                    const graphene_rect_t *r2)
-{
-  return r2->origin.x >= r1->origin.x &&
-         (r2->origin.x + r2->size.width) <= (r1->origin.x + r1->size.width) &&
-         r2->origin.y >= r1->origin.y &&
-         (r2->origin.y + r2->size.height) <= (r1->origin.y + r1->size.height);
-}
-
-static inline gboolean G_GNUC_PURE
-rect_intersects (const graphene_rect_t *r1,
-                 const graphene_rect_t *r2)
-{
-  /* Assume both rects are already normalized, as they usually are */
-  if (r1->origin.x > (r2->origin.x + r2->size.width) ||
-      (r1->origin.x + r1->size.width) < r2->origin.x)
-    return FALSE;
-  else if (r1->origin.y > (r2->origin.y + r2->size.height) ||
-      (r1->origin.y + r1->size.height) < r2->origin.y)
-    return FALSE;
-  else
-    return TRUE;
-}
-
 static inline void
 init_projection_matrix (graphene_matrix_t     *projection,
                         const graphene_rect_t *viewport)
@@ -913,7 +889,7 @@ gsk_gl_render_job_update_clip (GskGLRenderJob        *job,
 
   gsk_gl_render_job_transform_bounds (job, bounds, &transformed_bounds);
 
-  if (!rect_intersects (&job->current_clip->rect.bounds, &transformed_bounds))
+  if (!gsk_rect_intersects (&job->current_clip->rect.bounds, &transformed_bounds))
     {
       /* Completely clipped away */
       return FALSE;
@@ -921,7 +897,7 @@ gsk_gl_render_job_update_clip (GskGLRenderJob        *job,
 
   if (job->current_clip->is_rectilinear)
     {
-      if (rect_contains_rect (&job->current_clip->rect.bounds, &transformed_bounds))
+      if (gsk_rect_contains_rect (&job->current_clip->rect.bounds, &transformed_bounds))
         no_clip = TRUE;
       else
         rect_clip = TRUE;
@@ -3811,7 +3787,7 @@ gsk_gl_render_job_visit_texture_scale_node (GskGLRenderJob      *job,
               slice_bounds.size.width = slice->rect.width * scale_x;
               slice_bounds.size.height = slice->rect.height * scale_y;
 
-              if (!graphene_rect_intersection (&slice_bounds, &viewport, NULL))
+              if (!gsk_rect_intersects (&slice_bounds, &viewport))
                 continue;
 
               if (i > 0)
@@ -3889,7 +3865,7 @@ gsk_gl_render_job_visit_repeat_node (GskGLRenderJob      *job,
   /* If the size of the repeat node is smaller than the size of the
    * child node, we don't repeat at all and can just draw that part
    * of the child texture... */
-  if (rect_contains_rect (child_bounds, &node->bounds))
+  if (gsk_rect_contains_rect (child_bounds, &node->bounds))
     {
       gsk_gl_render_job_visit_clipped_child (job, child, &node->bounds);
       return;
diff --git a/gsk/gskrectprivate.h b/gsk/gskrectprivate.h
new file mode 100644 (file)
index 0000000..21a73d8
--- /dev/null
@@ -0,0 +1,28 @@
+#pragma once
+
+#include <graphene.h>
+
+static inline gboolean G_GNUC_PURE
+gsk_rect_contains_rect (const graphene_rect_t *r1,
+                        const graphene_rect_t *r2)
+{
+  return r2->origin.x >= r1->origin.x &&
+         (r2->origin.x + r2->size.width) <= (r1->origin.x + r1->size.width) &&
+         r2->origin.y >= r1->origin.y &&
+         (r2->origin.y + r2->size.height) <= (r1->origin.y + r1->size.height);
+}
+
+static inline gboolean G_GNUC_PURE
+gsk_rect_intersects (const graphene_rect_t *r1,
+                     const graphene_rect_t *r2)
+{
+  /* Assume both rects are already normalized, as they usually are */
+  if (r1->origin.x >= (r2->origin.x + r2->size.width) ||
+      (r1->origin.x + r1->size.width) <= r2->origin.x ||
+      r1->origin.y >= (r2->origin.y + r2->size.height) ||
+      (r1->origin.y + r1->size.height) <= r2->origin.y)
+    return FALSE;
+  else
+    return TRUE;
+}
+
index 7c1a9cc6ec61bac06701121af94e37c070dc8bd0..628bc638dadcb2cb9cba41bcd4614f14f8f3203b 100644 (file)
@@ -42,6 +42,7 @@
 #include "gskroundedrectprivate.h"
 
 #include "gskdebugprivate.h"
+#include "gskrectprivate.h"
 
 #include <math.h>
 
@@ -507,7 +508,7 @@ gboolean
 gsk_rounded_rect_intersects_rect (const GskRoundedRect  *self,
                                   const graphene_rect_t *rect)
 {
-  if (!graphene_rect_intersection (&self->bounds, rect, NULL))
+  if (!gsk_rect_intersects (&self->bounds, rect))
     return FALSE;
 
   /* If the bounding boxes intersect but the rectangles don't,
index d9a300011fce1f29880c2dd3ecb37e8a9db491e0..6f2974f26dfc282c447b1d10f7e84c711dd719e5 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "gskvulkanclipprivate.h"
 
+#include "gskrectprivate.h"
 #include "gskroundedrectprivate.h"
 #include "gsktransform.h"
 
@@ -58,7 +59,7 @@ gsk_vulkan_clip_intersect_rect (GskVulkanClip         *dest,
       gsk_vulkan_clip_init_copy (dest, src);
       return TRUE;
     }
-  if (!graphene_rect_intersection (rect, &src->rect.bounds, NULL))
+  if (!gsk_rect_intersects (rect, &src->rect.bounds))
     {
       dest->type = GSK_VULKAN_CLIP_ALL_CLIPPED;
       return TRUE;
@@ -110,7 +111,7 @@ gsk_vulkan_clip_intersect_rounded_rect (GskVulkanClip        *dest,
       gsk_vulkan_clip_init_copy (dest, src);
       return TRUE;
     }
-  if (!graphene_rect_intersection (&rounded->bounds, &src->rect.bounds, NULL))
+  if (!gsk_rect_intersects (&rounded->bounds, &src->rect.bounds))
     {
       dest->type = GSK_VULKAN_CLIP_ALL_CLIPPED;
       return TRUE;
@@ -254,7 +255,7 @@ gsk_vulkan_clip_may_intersect_rect (const GskVulkanClip    *self,
     case GSK_VULKAN_CLIP_NONE:
     case GSK_VULKAN_CLIP_RECT:
     case GSK_VULKAN_CLIP_ROUNDED:
-      return graphene_rect_intersection (&self->rect.bounds, &r, NULL);
+      return gsk_rect_intersects (&self->rect.bounds, &r);
     }
 }