From 6be6f04456ea4f23b99b546a616d41c7540e53f3 Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Sun, 5 Jul 2020 16:27:08 -0300 Subject: [PATCH] clutter/paint-nodes: Add opacity overriding to ClutterActorNode Some effects, such as ShellBlurEffect and ClutterOffscreenEffect, need to make sure the actor is painted fully opaque. With ClutterActorNode, however, that is currently not possible. Add a new 'opacity' parameter to clutter_actor_node_new(). It follows the opacity override heuristic, where -1 means disable, and anything else is clamped to [0, 255]. https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1340 --- clutter/clutter/clutter-actor.c | 2 +- clutter/clutter/clutter-effect.c | 2 +- clutter/clutter/clutter-paint-nodes.c | 21 ++++++++++++++++++++- clutter/clutter/clutter-paint-nodes.h | 3 ++- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/clutter/clutter/clutter-actor.c b/clutter/clutter/clutter-actor.c index 1bd88bcd3..217308a1d 100644 --- a/clutter/clutter/clutter-actor.c +++ b/clutter/clutter/clutter-actor.c @@ -3737,7 +3737,7 @@ clutter_actor_paint (ClutterActor *self, if (!CLUTTER_ACTOR_IS_MAPPED (self)) return; - actor_node = clutter_actor_node_new (self); + actor_node = clutter_actor_node_new (self, -1); root_node = clutter_paint_node_ref (actor_node); if (priv->has_clip) diff --git a/clutter/clutter/clutter-effect.c b/clutter/clutter/clutter-effect.c index 33664fabc..4fa88efb8 100644 --- a/clutter/clutter/clutter-effect.c +++ b/clutter/clutter/clutter-effect.c @@ -209,7 +209,7 @@ clutter_effect_real_paint_node (ClutterEffect *effect, actor = clutter_actor_meta_get_actor (CLUTTER_ACTOR_META (effect)); - actor_node = clutter_actor_node_new (actor); + actor_node = clutter_actor_node_new (actor, -1); clutter_paint_node_add_child (node, actor_node); clutter_paint_node_unref (actor_node); } diff --git a/clutter/clutter/clutter-paint-nodes.c b/clutter/clutter/clutter-paint-nodes.c index f39336c01..5c7b60e3e 100644 --- a/clutter/clutter/clutter-paint-nodes.c +++ b/clutter/clutter/clutter-paint-nodes.c @@ -1115,6 +1115,8 @@ struct _ClutterActorNode ClutterPaintNode parent_instance; ClutterActor *actor; + int opacity_override; + int old_opacity_override; }; struct _ClutterActorNodeClass @@ -1130,6 +1132,14 @@ clutter_actor_node_pre_draw (ClutterPaintNode *node, { ClutterActorNode *actor_node = CLUTTER_ACTOR_NODE (node); + if (actor_node->opacity_override != -1) + { + actor_node->old_opacity_override = + clutter_actor_get_opacity_override (actor_node->actor); + clutter_actor_set_opacity_override (actor_node->actor, + actor_node->opacity_override); + } + CLUTTER_SET_PRIVATE_FLAGS (actor_node->actor, CLUTTER_IN_PAINT); return TRUE; @@ -1151,6 +1161,12 @@ clutter_actor_node_post_draw (ClutterPaintNode *node, ClutterActorNode *actor_node = CLUTTER_ACTOR_NODE (node); CLUTTER_UNSET_PRIVATE_FLAGS (actor_node->actor, CLUTTER_IN_PAINT); + + if (actor_node->opacity_override != -1) + { + clutter_actor_set_opacity_override (actor_node->actor, + actor_node->old_opacity_override); + } } static JsonNode * @@ -1192,6 +1208,7 @@ clutter_actor_node_init (ClutterActorNode *self) /* * clutter_actor_node_new: * @actor: the actor to paint + * @opacity: opacity to draw the actor with, or -1 to use the actor's opacity * * Creates a new #ClutterActorNode. * @@ -1203,7 +1220,8 @@ clutter_actor_node_init (ClutterActorNode *self) * Use clutter_paint_node_unref() when done. */ ClutterPaintNode * -clutter_actor_node_new (ClutterActor *actor) +clutter_actor_node_new (ClutterActor *actor, + int opacity) { ClutterActorNode *res; @@ -1211,6 +1229,7 @@ clutter_actor_node_new (ClutterActor *actor) res = _clutter_paint_node_create (CLUTTER_TYPE_ACTOR_NODE); res->actor = actor; + res->opacity_override = CLAMP (opacity, -1, 255); return (ClutterPaintNode *) res; } diff --git a/clutter/clutter/clutter-paint-nodes.h b/clutter/clutter/clutter-paint-nodes.h index 235f4bc45..c950899c5 100644 --- a/clutter/clutter/clutter-paint-nodes.h +++ b/clutter/clutter/clutter-paint-nodes.h @@ -160,7 +160,8 @@ CLUTTER_EXPORT GType clutter_actor_node_get_type (void) G_GNUC_CONST; CLUTTER_EXPORT -ClutterPaintNode * clutter_actor_node_new (ClutterActor *actor); +ClutterPaintNode * clutter_actor_node_new (ClutterActor *actor, + int opacity); #define CLUTTER_TYPE_ROOT_NODE (clutter_root_node_get_type ()) #define CLUTTER_ROOT_NODE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_ROOT_NODE, ClutterRootNode))