tests/frame-clock: Add test that switches frame clock mid timeline

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1285
This commit is contained in:
Jonas Ådahl 2020-03-25 19:20:42 +01:00
parent 9b054f4a1b
commit ca82cde6dd

View File

@ -108,6 +108,92 @@ frame_clock_timeline_basic (void)
g_assert_null (frame_clock); g_assert_null (frame_clock);
} }
static void
on_switch_reached (ClutterTimeline *timeline,
const char *marker_name,
unsigned int frame_number,
ClutterFrameClock *new_frame_clock)
{
ClutterFrameClock *old_frame_clock;
old_frame_clock = clutter_timeline_get_frame_clock (timeline);
clutter_frame_clock_inhibit (old_frame_clock);
clutter_timeline_set_frame_clock (timeline, new_frame_clock);
}
static void
frame_clock_timeline_switch (void)
{
GMainLoop *main_loop;
ClutterFrameClock *frame_clock2;
ClutterFrameClock *frame_clock1;
ClutterTimeline *timeline;
int frame_counter;
int64_t before_us;
int64_t after_us;
main_loop = g_main_loop_new (NULL, FALSE);
frame_clock1 = clutter_frame_clock_new (refresh_rate,
&timeline_frame_listener_iface,
NULL);
g_object_add_weak_pointer (G_OBJECT (frame_clock1), (gpointer *) &frame_clock1);
frame_clock2 = clutter_frame_clock_new (refresh_rate,
&timeline_frame_listener_iface,
NULL);
g_object_add_weak_pointer (G_OBJECT (frame_clock2), (gpointer *) &frame_clock2);
timeline = g_object_new (CLUTTER_TYPE_TIMELINE,
"duration", 1000,
"frame-clock", frame_clock1,
NULL);
g_object_add_weak_pointer (G_OBJECT (timeline), (gpointer *) &timeline);
clutter_timeline_add_marker_at_time (timeline, "switch", 500);
frame_counter = 0;
g_signal_connect (timeline, "marker-reached::switch",
G_CALLBACK (on_switch_reached),
frame_clock2);
g_signal_connect (timeline, "new-frame",
G_CALLBACK (on_timeline_new_frame),
&frame_counter);
g_signal_connect (timeline, "completed",
G_CALLBACK (on_timeline_completed),
main_loop);
clutter_timeline_start (timeline);
before_us = g_get_monotonic_time ();
g_main_loop_run (main_loop);
after_us = g_get_monotonic_time ();
g_assert_cmpint (after_us - before_us,
>=,
ms2us (clutter_timeline_get_duration (timeline)));
g_assert (clutter_timeline_get_frame_clock (timeline) == frame_clock2);
/* The duration is 1s, with a 60hz clock, and we switch after 0.5s. To verify
* we continued to get frames, check that we have a bit more than half of the
* frames accounted for.
*/
g_assert_cmpint (frame_counter, >, 35);
g_main_loop_unref (main_loop);
g_object_unref (timeline);
g_assert_null (timeline);
g_object_unref (frame_clock1);
g_assert_null (frame_clock1);
g_object_unref (frame_clock2);
g_assert_null (frame_clock2);
}
CLUTTER_TEST_SUITE ( CLUTTER_TEST_SUITE (
CLUTTER_TEST_UNIT ("/frame-clock/timeline/basic", frame_clock_timeline_basic) CLUTTER_TEST_UNIT ("/frame-clock/timeline/basic", frame_clock_timeline_basic)
CLUTTER_TEST_UNIT ("/frame-clock/timeline/switch", frame_clock_timeline_switch)
) )