From d30a9e7fa9a68680b942162051224ac141aa75c4 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Thu, 20 Jul 2023 22:25:20 +0200 Subject: [PATCH] gsk: Add gskrectprivate.h 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 | 34 +++++----------------------------- gsk/gskrectprivate.h | 28 ++++++++++++++++++++++++++++ gsk/gskroundedrect.c | 3 ++- gsk/vulkan/gskvulkanclip.c | 7 ++++--- 4 files changed, 39 insertions(+), 33 deletions(-) create mode 100644 gsk/gskrectprivate.h diff --git a/gsk/gl/gskglrenderjob.c b/gsk/gl/gskglrenderjob.c index 11d410a205..8382b203f5 100644 --- a/gsk/gl/gskglrenderjob.c +++ b/gsk/gl/gskglrenderjob.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -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 index 0000000000..21a73d8ce2 --- /dev/null +++ b/gsk/gskrectprivate.h @@ -0,0 +1,28 @@ +#pragma once + +#include + +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; +} + diff --git a/gsk/gskroundedrect.c b/gsk/gskroundedrect.c index 7c1a9cc6ec..628bc638da 100644 --- a/gsk/gskroundedrect.c +++ b/gsk/gskroundedrect.c @@ -42,6 +42,7 @@ #include "gskroundedrectprivate.h" #include "gskdebugprivate.h" +#include "gskrectprivate.h" #include @@ -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, diff --git a/gsk/vulkan/gskvulkanclip.c b/gsk/vulkan/gskvulkanclip.c index d9a300011f..6f2974f26d 100644 --- a/gsk/vulkan/gskvulkanclip.c +++ b/gsk/vulkan/gskvulkanclip.c @@ -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); } }