clutter/frame-clock: Add explicit destroy function

The frame clock owner should be able to explicitly destroy (i.e. make
defunct) a frame clock, e.g. when a stage view is destructed. This is so
that other objects can keep reference to its without it being left
around even after stopped being usable.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1285
This commit is contained in:
Jonas Ådahl 2020-06-10 14:43:16 +02:00
parent e12ce70385
commit d29c8e290c
5 changed files with 47 additions and 18 deletions

View File

@ -24,6 +24,15 @@
#include "clutter/clutter-timeline-private.h" #include "clutter/clutter-timeline-private.h"
#include "cogl/cogl-trace.h" #include "cogl/cogl-trace.h"
enum
{
DESTROY,
N_SIGNALS
};
static guint signals[N_SIGNALS];
/* Wait 2ms after vblank before starting to draw next frame */ /* Wait 2ms after vblank before starting to draw next frame */
#define SYNC_DELAY_US ms2us (2) #define SYNC_DELAY_US ms2us (2)
@ -495,18 +504,26 @@ clutter_frame_clock_new (float refresh_rate,
return frame_clock; return frame_clock;
} }
static void void
clutter_frame_clock_finalize (GObject *object) clutter_frame_clock_destroy (ClutterFrameClock *frame_clock)
{ {
ClutterFrameClock *frame_clock = CLUTTER_FRAME_CLOCK (object); g_object_run_dispose (G_OBJECT (frame_clock));
g_object_unref (frame_clock);
}
static void
clutter_frame_clock_dispose (GObject *object)
{
ClutterFrameClock *frame_clock = CLUTTER_FRAME_CLOCK (object);
if (frame_clock->source) if (frame_clock->source)
{ {
g_signal_emit (frame_clock, signals[DESTROY], 0);
g_source_destroy (frame_clock->source); g_source_destroy (frame_clock->source);
g_source_unref (frame_clock->source); g_clear_pointer (&frame_clock->source, g_source_unref);
} }
G_OBJECT_CLASS (clutter_frame_clock_parent_class)->finalize (object); G_OBJECT_CLASS (clutter_frame_clock_parent_class)->dispose (object);
} }
static void static void
@ -520,5 +537,14 @@ clutter_frame_clock_class_init (ClutterFrameClockClass *klass)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = clutter_frame_clock_finalize; object_class->dispose = clutter_frame_clock_dispose;
signals[DESTROY] =
g_signal_new (I_("destroy"),
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE,
0);
} }

View File

@ -56,6 +56,9 @@ ClutterFrameClock * clutter_frame_clock_new (float re
const ClutterFrameListenerIface *iface, const ClutterFrameListenerIface *iface,
gpointer user_data); gpointer user_data);
CLUTTER_EXPORT
void clutter_frame_clock_destroy (ClutterFrameClock *frame_clock);
CLUTTER_EXPORT CLUTTER_EXPORT
void clutter_frame_clock_notify_presented (ClutterFrameClock *frame_clock, void clutter_frame_clock_notify_presented (ClutterFrameClock *frame_clock,
ClutterFrameInfo *frame_info); ClutterFrameInfo *frame_info);

View File

@ -1274,7 +1274,7 @@ clutter_stage_view_dispose (GObject *object)
g_clear_pointer (&priv->offscreen, cogl_object_unref); g_clear_pointer (&priv->offscreen, cogl_object_unref);
g_clear_pointer (&priv->offscreen_pipeline, cogl_object_unref); g_clear_pointer (&priv->offscreen_pipeline, cogl_object_unref);
g_clear_pointer (&priv->redraw_clip, cairo_region_destroy); g_clear_pointer (&priv->redraw_clip, cairo_region_destroy);
g_clear_object (&priv->frame_clock); g_clear_pointer (&priv->frame_clock, clutter_frame_clock_destroy);
G_OBJECT_CLASS (clutter_stage_view_parent_class)->dispose (object); G_OBJECT_CLASS (clutter_stage_view_parent_class)->dispose (object);
} }

View File

@ -109,7 +109,7 @@ frame_clock_timeline_basic (void)
g_main_loop_unref (main_loop); g_main_loop_unref (main_loop);
g_object_unref (timeline); g_object_unref (timeline);
g_assert_null (timeline); g_assert_null (timeline);
g_object_unref (frame_clock); clutter_frame_clock_destroy (frame_clock);
g_assert_null (frame_clock); g_assert_null (frame_clock);
} }
@ -192,9 +192,9 @@ frame_clock_timeline_switch (void)
g_main_loop_unref (main_loop); g_main_loop_unref (main_loop);
g_object_unref (timeline); g_object_unref (timeline);
g_assert_null (timeline); g_assert_null (timeline);
g_object_unref (frame_clock1); clutter_frame_clock_destroy (frame_clock1);
g_assert_null (frame_clock1); g_assert_null (frame_clock1);
g_object_unref (frame_clock2); clutter_frame_clock_destroy (frame_clock2);
g_assert_null (frame_clock2); g_assert_null (frame_clock2);
} }

View File

@ -166,7 +166,7 @@ frame_clock_schedule_update (void)
g_main_loop_unref (test.main_loop); g_main_loop_unref (test.main_loop);
g_object_unref (frame_clock); clutter_frame_clock_destroy (frame_clock);
g_source_destroy (source); g_source_destroy (source);
g_source_unref (source); g_source_unref (source);
} }
@ -242,7 +242,7 @@ frame_clock_immediate_present (void)
g_assert_cmpint (after_us - before_us, >, 9 * refresh_interval_us); g_assert_cmpint (after_us - before_us, >, 9 * refresh_interval_us);
g_main_loop_unref (main_loop); g_main_loop_unref (main_loop);
g_object_unref (frame_clock); clutter_frame_clock_destroy (frame_clock);
} }
static gboolean static gboolean
@ -323,7 +323,7 @@ frame_clock_delayed_damage (void)
g_assert_cmpint (after_us - before_us, >, 100000 + refresh_interval_us); g_assert_cmpint (after_us - before_us, >, 100000 + refresh_interval_us);
g_main_loop_unref (test.main_loop); g_main_loop_unref (test.main_loop);
g_object_unref (frame_clock); clutter_frame_clock_destroy (frame_clock);
g_source_destroy (source); g_source_destroy (source);
g_source_unref (source); g_source_unref (source);
} }
@ -372,7 +372,7 @@ frame_clock_no_damage (void)
g_main_loop_run (main_loop); g_main_loop_run (main_loop);
g_main_loop_unref (main_loop); g_main_loop_unref (main_loop);
g_object_unref (frame_clock); clutter_frame_clock_destroy (frame_clock);
} }
typedef struct _UpdateNowFrameClockTest typedef struct _UpdateNowFrameClockTest
@ -472,7 +472,7 @@ frame_clock_schedule_update_now (void)
g_main_loop_unref (test.base.main_loop); g_main_loop_unref (test.base.main_loop);
g_object_unref (frame_clock); clutter_frame_clock_destroy (frame_clock);
g_source_destroy (source); g_source_destroy (source);
g_source_unref (source); g_source_unref (source);
} }
@ -543,7 +543,7 @@ frame_clock_before_frame (void)
g_assert_cmpint (expected_frame_count, >, 2); g_assert_cmpint (expected_frame_count, >, 2);
g_main_loop_unref (main_loop); g_main_loop_unref (main_loop);
g_object_unref (frame_clock); clutter_frame_clock_destroy (frame_clock);
} }
typedef struct _InhibitTest typedef struct _InhibitTest
@ -625,7 +625,7 @@ frame_clock_inhibit (void)
g_assert_cmpint (test.frame_count, ==, 2); g_assert_cmpint (test.frame_count, ==, 2);
g_main_loop_unref (test.main_loop); g_main_loop_unref (test.main_loop);
g_object_unref (test.frame_clock); clutter_frame_clock_destroy (test.frame_clock);
} }
typedef struct _RescheduleOnIdleFrameClockTest typedef struct _RescheduleOnIdleFrameClockTest
@ -687,7 +687,7 @@ frame_clock_reschedule_on_idle (void)
g_main_loop_run (test.base.main_loop); g_main_loop_run (test.base.main_loop);
g_main_loop_unref (test.base.main_loop); g_main_loop_unref (test.base.main_loop);
g_object_unref (frame_clock); clutter_frame_clock_destroy (frame_clock);
} }
CLUTTER_TEST_SUITE ( CLUTTER_TEST_SUITE (