From 6c4b897d74522b4a45689c5529e7afdbab3e2509 Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Thu, 22 Oct 2020 21:12:10 -0300 Subject: [PATCH] clutter/actor: Cull out when picking Testing points and rays against boxes is substantially cheaper - in fact, almost trivial - compared to triangles. Check if the actor's paint volume doesn't intersect with the current pick point / ray, and skip recursing altogether in those cases. Part-of: --- clutter/clutter/clutter-actor.c | 11 +++++++++++ clutter/clutter/clutter-pick-context-private.h | 4 ++++ clutter/clutter/clutter-pick-context.c | 8 ++++++++ 3 files changed, 23 insertions(+) diff --git a/clutter/clutter/clutter-actor.c b/clutter/clutter/clutter-actor.c index 20070df4e..0d5eae782 100644 --- a/clutter/clutter/clutter-actor.c +++ b/clutter/clutter/clutter-actor.c @@ -635,6 +635,7 @@ #include "clutter-paint-nodes.h" #include "clutter-paint-node-private.h" #include "clutter-paint-volume-private.h" +#include "clutter-pick-context-private.h" #include "clutter-private.h" #include "clutter-property-transition.h" #include "clutter-scriptable.h" @@ -3959,6 +3960,15 @@ clutter_actor_pick (ClutterActor *actor, /* mark that we are in the paint process */ CLUTTER_SET_PRIVATE_FLAGS (actor, CLUTTER_IN_PICK); + if (priv->paint_volume_valid && priv->last_paint_volume_valid) + { + graphene_box_t box; + + clutter_paint_volume_to_box (&priv->last_paint_volume, &box); + if (!clutter_pick_context_intersects_box (pick_context, &box)) + goto out; + } + if (priv->enable_model_view_transform) { graphene_matrix_t matrix; @@ -4007,6 +4017,7 @@ clutter_actor_pick (ClutterActor *actor, if (transform_pushed) clutter_pick_context_pop_transform (pick_context); +out: /* paint sequence complete */ CLUTTER_UNSET_PRIVATE_FLAGS (actor, CLUTTER_IN_PICK); } diff --git a/clutter/clutter/clutter-pick-context-private.h b/clutter/clutter/clutter-pick-context-private.h index cc8baf881..f40de6f3d 100644 --- a/clutter/clutter/clutter-pick-context-private.h +++ b/clutter/clutter/clutter-pick-context-private.h @@ -30,4 +30,8 @@ clutter_pick_context_new_for_view (ClutterStageView *view, ClutterPickStack * clutter_pick_context_steal_stack (ClutterPickContext *pick_context); +gboolean +clutter_pick_context_intersects_box (ClutterPickContext *pick_context, + const graphene_box_t *box); + #endif /* CLUTTER_PICK_CONTEXT_PRIVATE_H */ diff --git a/clutter/clutter/clutter-pick-context.c b/clutter/clutter/clutter-pick-context.c index b9758366d..2f054d318 100644 --- a/clutter/clutter/clutter-pick-context.c +++ b/clutter/clutter/clutter-pick-context.c @@ -189,3 +189,11 @@ clutter_pick_context_pop_transform (ClutterPickContext *pick_context) { clutter_pick_stack_pop_transform (pick_context->pick_stack); } + +gboolean +clutter_pick_context_intersects_box (ClutterPickContext *pick_context, + const graphene_box_t *box) +{ + return graphene_box_contains_point (box, &pick_context->point) || + graphene_ray_intersects_box (&pick_context->ray, box); +}