mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-11 13:10:07 +00:00
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.
This commit is contained in:
parent
6e75e26a0c
commit
d30a9e7fa9
@ -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;
|
||||
|
28
gsk/gskrectprivate.h
Normal file
28
gsk/gskrectprivate.h
Normal file
@ -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;
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user