From 73adac987d10b6328d1ba824346cb68f310ec2f4 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Tue, 23 Sep 2008 09:41:08 +0000 Subject: [PATCH] 2008-09-23 Emmanuele Bassi * clutter/clutter-alpha.c: (clutter_alpha_get_alpha): Do not return the cached value but just compute the current alpha value. The use case is pretty much straightforward: stop a timeline, advance it, and retrieve the alpha value before starting the timeline to adjust an animation dependent on the alpha. Caching the alpha value is not needed because the behaviours will always pass the alpha value inside the ::alpha-notify virtual function anyway, so there is no need for them to call clutter_alpha_get_alpha(). This change makes it also possible to reliably unit-test ClutterAlpha. (timeline_new_frame_cb): Call clutter_alpha_get_alpha(). --- ChangeLog | 17 ++++++++++ clutter/clutter-alpha.c | 73 +++++++++++++++++++++-------------------- 2 files changed, 55 insertions(+), 35 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6cd9e06e9..e33566e23 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2008-09-23 Emmanuele Bassi + + * clutter/clutter-alpha.c: + (clutter_alpha_get_alpha): Do not return the cached value but + just compute the current alpha value. The use case is pretty + much straightforward: stop a timeline, advance it, and retrieve + the alpha value before starting the timeline to adjust an + animation dependent on the alpha. Caching the alpha value is + not needed because the behaviours will always pass the alpha + value inside the ::alpha-notify virtual function anyway, so + there is no need for them to call clutter_alpha_get_alpha(). + + This change makes it also possible to reliably unit-test + ClutterAlpha. + + (timeline_new_frame_cb): Call clutter_alpha_get_alpha(). + 2008-09-23 Tomas Frydrych * clutter/clutter-main.c: diff --git a/clutter/clutter-alpha.c b/clutter/clutter-alpha.c index b1a4061cc..57680d573 100644 --- a/clutter/clutter-alpha.c +++ b/clutter/clutter-alpha.c @@ -92,32 +92,8 @@ timeline_new_frame_cb (ClutterTimeline *timeline, ClutterAlphaPrivate *priv = alpha->priv; /* Update alpha value and notify */ - if (G_LIKELY (priv->closure)) - { - GValue params = { 0, }; - GValue result_value = { 0, }; - - g_object_ref (alpha); - - g_value_init (&result_value, G_TYPE_UINT); - - g_value_init (¶ms, CLUTTER_TYPE_ALPHA); - g_value_set_object (¶ms, alpha); - - g_closure_invoke (priv->closure, - &result_value, - 1, - ¶ms, - NULL); - - priv->alpha = g_value_get_uint (&result_value); - - g_value_unset (&result_value); - g_value_unset (¶ms); - - g_object_notify (G_OBJECT (alpha), "alpha"); - g_object_unref (alpha); - } + priv->alpha = clutter_alpha_get_alpha (alpha); + g_object_notify (G_OBJECT (alpha), "alpha"); } static void @@ -175,9 +151,7 @@ clutter_alpha_finalize (GObject *object) ClutterAlphaPrivate *priv = CLUTTER_ALPHA (object)->priv; if (priv->closure) - { - g_closure_unref (priv->closure); - } + g_closure_unref (priv->closure); G_OBJECT_CLASS (clutter_alpha_parent_class)->finalize (object); } @@ -258,9 +232,40 @@ clutter_alpha_init (ClutterAlpha *self) guint32 clutter_alpha_get_alpha (ClutterAlpha *alpha) { - g_return_val_if_fail (CLUTTER_IS_ALPHA (alpha), FALSE); - - return alpha->priv->alpha; + ClutterAlphaPrivate *priv; + guint32 retval = 0; + + g_return_val_if_fail (CLUTTER_IS_ALPHA (alpha), 0); + + priv = alpha->priv; + + if (G_LIKELY (priv->closure)) + { + GValue params = { 0, }; + GValue result_value = { 0, }; + + g_object_ref (alpha); + + g_value_init (&result_value, G_TYPE_UINT); + + g_value_init (¶ms, CLUTTER_TYPE_ALPHA); + g_value_set_object (¶ms, alpha); + + g_closure_invoke (priv->closure, + &result_value, + 1, + ¶ms, + NULL); + + retval = g_value_get_uint (&result_value); + + g_value_unset (&result_value); + g_value_unset (¶ms); + + g_object_unref (alpha); + } + + return retval; } /** @@ -318,13 +323,11 @@ clutter_alpha_set_func (ClutterAlpha *alpha, gpointer data, GDestroyNotify destroy) { - ClutterAlphaPrivate *priv; GClosure *closure; g_return_if_fail (CLUTTER_IS_ALPHA (alpha)); + g_return_if_fail (func != NULL); - priv = alpha->priv; - closure = g_cclosure_new (G_CALLBACK (func), data, (GClosureNotify) destroy); clutter_alpha_set_closure (alpha, closure); }