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: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1520>
This commit is contained in:
Georges Basile Stavracas Neto 2020-10-22 21:12:10 -03:00 committed by Marge Bot
parent 1fdde25b3e
commit 6c4b897d74
3 changed files with 23 additions and 0 deletions

View File

@ -635,6 +635,7 @@
#include "clutter-paint-nodes.h" #include "clutter-paint-nodes.h"
#include "clutter-paint-node-private.h" #include "clutter-paint-node-private.h"
#include "clutter-paint-volume-private.h" #include "clutter-paint-volume-private.h"
#include "clutter-pick-context-private.h"
#include "clutter-private.h" #include "clutter-private.h"
#include "clutter-property-transition.h" #include "clutter-property-transition.h"
#include "clutter-scriptable.h" #include "clutter-scriptable.h"
@ -3959,6 +3960,15 @@ clutter_actor_pick (ClutterActor *actor,
/* mark that we are in the paint process */ /* mark that we are in the paint process */
CLUTTER_SET_PRIVATE_FLAGS (actor, CLUTTER_IN_PICK); 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) if (priv->enable_model_view_transform)
{ {
graphene_matrix_t matrix; graphene_matrix_t matrix;
@ -4007,6 +4017,7 @@ clutter_actor_pick (ClutterActor *actor,
if (transform_pushed) if (transform_pushed)
clutter_pick_context_pop_transform (pick_context); clutter_pick_context_pop_transform (pick_context);
out:
/* paint sequence complete */ /* paint sequence complete */
CLUTTER_UNSET_PRIVATE_FLAGS (actor, CLUTTER_IN_PICK); CLUTTER_UNSET_PRIVATE_FLAGS (actor, CLUTTER_IN_PICK);
} }

View File

@ -30,4 +30,8 @@ clutter_pick_context_new_for_view (ClutterStageView *view,
ClutterPickStack * ClutterPickStack *
clutter_pick_context_steal_stack (ClutterPickContext *pick_context); 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 */ #endif /* CLUTTER_PICK_CONTEXT_PRIVATE_H */

View File

@ -189,3 +189,11 @@ clutter_pick_context_pop_transform (ClutterPickContext *pick_context)
{ {
clutter_pick_stack_pop_transform (pick_context->pick_stack); 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);
}