2020-03-25 11:31:41 -04:00
|
|
|
#define CLUTTER_DISABLE_DEPRECATION_WARNINGS
|
2008-03-05 11:04:06 -05:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <glib.h>
|
|
|
|
#include <clutter/clutter.h>
|
|
|
|
|
2020-03-25 11:31:41 -04:00
|
|
|
#include "tests/clutter-test-utils.h"
|
2008-11-07 14:32:28 -05:00
|
|
|
|
2008-03-05 11:04:06 -05:00
|
|
|
/* We ask for 1 frame per millisecond.
|
|
|
|
* Whenever this rate can't be achieved then the timeline
|
|
|
|
* will interpolate the number frames that should have
|
|
|
|
* passed between timeouts. */
|
|
|
|
#define TEST_TIMELINE_FPS 1000
|
2009-06-04 08:05:12 -04:00
|
|
|
#define TEST_TIMELINE_DURATION 5000
|
2008-03-05 11:04:06 -05:00
|
|
|
|
|
|
|
/* We are at the mercy of the system scheduler so this
|
2020-03-25 11:31:41 -04:00
|
|
|
* may not be a very reliable tolerance.
|
|
|
|
*
|
2020-06-05 18:25:55 -04:00
|
|
|
* It's set as very tolerable (1 ms shorter than the frame interval) as
|
|
|
|
* otherwise CI, which are very prone to not get CPU time scheduled, tend to
|
|
|
|
* often fail.
|
2020-03-25 11:31:41 -04:00
|
|
|
*/
|
2020-06-05 18:25:55 -04:00
|
|
|
#define TEST_ERROR_TOLERANCE ((TEST_TIMELINE_FPS / 4) - 1)
|
2008-03-05 11:04:06 -05:00
|
|
|
|
2009-05-01 10:08:42 -04:00
|
|
|
typedef struct _TestState
|
|
|
|
{
|
|
|
|
ClutterTimeline *timeline;
|
2019-07-31 18:21:03 -04:00
|
|
|
int64_t start_time;
|
2009-05-01 10:08:42 -04:00
|
|
|
guint new_frame_counter;
|
|
|
|
gint expected_frame;
|
|
|
|
gint completion_count;
|
|
|
|
gboolean passed;
|
|
|
|
} TestState;
|
2008-03-05 11:04:06 -05:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
new_frame_cb (ClutterTimeline *timeline,
|
2008-11-07 14:32:28 -05:00
|
|
|
gint frame_num,
|
2008-03-05 11:04:06 -05:00
|
|
|
TestState *state)
|
|
|
|
{
|
2019-07-31 18:21:03 -04:00
|
|
|
int64_t current_time;
|
2008-03-05 11:04:06 -05:00
|
|
|
gint current_frame;
|
|
|
|
glong msec_diff;
|
|
|
|
gint loop_overflow = 0;
|
|
|
|
static gint step = 1;
|
2008-11-07 14:32:28 -05:00
|
|
|
|
2019-07-31 18:21:03 -04:00
|
|
|
current_time = g_get_real_time ();
|
2008-03-05 11:04:06 -05:00
|
|
|
|
2009-06-04 08:05:12 -04:00
|
|
|
current_frame = clutter_timeline_get_elapsed_time (state->timeline);
|
2008-11-07 14:32:28 -05:00
|
|
|
|
2019-07-31 18:21:03 -04:00
|
|
|
msec_diff = (current_time - state->start_time) / G_TIME_SPAN_MILLISECOND;
|
2008-11-07 14:32:28 -05:00
|
|
|
|
2008-03-05 11:04:06 -05:00
|
|
|
/* If we expect to have interpolated past the end of the timeline
|
|
|
|
* we keep track of the overflow so we can determine when
|
2009-06-11 05:55:52 -04:00
|
|
|
* the next timeout will happen. We then clip expected_frames
|
|
|
|
* to TEST_TIMELINE_DURATION since clutter-timeline
|
|
|
|
* semantics guaranty this frame is always signaled before
|
|
|
|
* looping */
|
2009-06-04 08:05:12 -04:00
|
|
|
if (state->expected_frame > TEST_TIMELINE_DURATION)
|
2008-03-05 11:04:06 -05:00
|
|
|
{
|
2009-06-04 08:05:12 -04:00
|
|
|
loop_overflow = state->expected_frame - TEST_TIMELINE_DURATION;
|
2009-06-11 05:55:52 -04:00
|
|
|
state->expected_frame = TEST_TIMELINE_DURATION;
|
2008-03-05 11:04:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (current_frame >= (state->expected_frame-TEST_ERROR_TOLERANCE)
|
|
|
|
&& current_frame <= (state->expected_frame+TEST_ERROR_TOLERANCE))
|
|
|
|
{
|
2009-06-11 06:38:49 -04:00
|
|
|
g_test_message ("elapsed milliseconds=%-5li "
|
|
|
|
"expected frame=%-4i actual frame=%-4i (OK)",
|
2008-11-07 14:32:28 -05:00
|
|
|
msec_diff,
|
|
|
|
state->expected_frame,
|
|
|
|
current_frame);
|
2008-03-05 11:04:06 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-06-11 06:38:49 -04:00
|
|
|
g_test_message ("elapsed milliseconds=%-5li "
|
|
|
|
"expected frame=%-4i actual frame=%-4i (FAILED)",
|
2008-11-07 14:32:28 -05:00
|
|
|
msec_diff,
|
|
|
|
state->expected_frame,
|
|
|
|
current_frame);
|
2008-03-05 11:04:06 -05:00
|
|
|
state->passed = FALSE;
|
|
|
|
}
|
2008-11-07 14:32:28 -05:00
|
|
|
|
2008-03-05 11:04:06 -05:00
|
|
|
if (step>0)
|
|
|
|
{
|
|
|
|
state->expected_frame = current_frame + (TEST_TIMELINE_FPS / 4);
|
2008-11-07 14:32:28 -05:00
|
|
|
g_test_message ("Sleeping for 250ms "
|
2009-06-11 06:38:49 -04:00
|
|
|
"so next frame should be (%i + %i) = %i",
|
2008-11-07 14:32:28 -05:00
|
|
|
current_frame,
|
|
|
|
(TEST_TIMELINE_FPS / 4),
|
|
|
|
state->expected_frame);
|
2008-03-05 11:04:06 -05:00
|
|
|
g_usleep (250000);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
state->expected_frame = current_frame + TEST_TIMELINE_FPS;
|
2008-11-07 14:32:28 -05:00
|
|
|
g_test_message ("Sleeping for 1sec "
|
2009-06-11 06:38:49 -04:00
|
|
|
"so next frame should be (%i + %i) = %i",
|
2008-11-07 14:32:28 -05:00
|
|
|
current_frame,
|
|
|
|
TEST_TIMELINE_FPS,
|
|
|
|
state->expected_frame);
|
2008-03-05 11:04:06 -05:00
|
|
|
g_usleep (1000000);
|
|
|
|
}
|
2008-11-07 14:32:28 -05:00
|
|
|
|
2009-06-04 08:05:12 -04:00
|
|
|
if (current_frame >= TEST_TIMELINE_DURATION)
|
2008-03-05 11:04:06 -05:00
|
|
|
{
|
|
|
|
state->expected_frame += loop_overflow;
|
2009-06-04 08:05:12 -04:00
|
|
|
state->expected_frame -= TEST_TIMELINE_DURATION;
|
2008-11-07 14:32:28 -05:00
|
|
|
g_test_message ("End of timeline reached: "
|
2009-06-11 06:38:49 -04:00
|
|
|
"Wrapping expected frame too %i",
|
2008-11-07 14:32:28 -05:00
|
|
|
state->expected_frame);
|
2008-03-05 11:04:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
state->new_frame_counter++;
|
|
|
|
step = -step;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
completed_cb (ClutterTimeline *timeline,
|
2008-11-07 14:32:28 -05:00
|
|
|
TestState *state)
|
2008-03-05 11:04:06 -05:00
|
|
|
{
|
2008-11-07 14:32:28 -05:00
|
|
|
state->completion_count++;
|
|
|
|
|
|
|
|
if (state->completion_count == 2)
|
|
|
|
{
|
|
|
|
if (state->passed)
|
2020-03-25 11:31:41 -04:00
|
|
|
clutter_main_quit ();
|
2008-11-07 14:32:28 -05:00
|
|
|
else
|
2020-03-25 11:31:41 -04:00
|
|
|
g_assert_not_reached ();
|
2008-11-07 14:32:28 -05:00
|
|
|
}
|
2008-03-05 11:04:06 -05:00
|
|
|
}
|
|
|
|
|
2020-03-25 11:31:41 -04:00
|
|
|
static void
|
2010-10-12 12:31:15 -04:00
|
|
|
timeline_interpolation (void)
|
2008-03-05 11:04:06 -05:00
|
|
|
{
|
2020-05-29 13:31:22 -04:00
|
|
|
ClutterActor *stage;
|
2008-03-05 11:04:06 -05:00
|
|
|
TestState state;
|
|
|
|
|
2020-05-29 13:31:22 -04:00
|
|
|
stage = clutter_test_get_stage ();
|
|
|
|
|
2008-03-05 11:04:06 -05:00
|
|
|
state.timeline =
|
2020-04-17 03:03:44 -04:00
|
|
|
clutter_timeline_new_for_actor (stage, TEST_TIMELINE_DURATION);
|
2020-04-16 04:04:04 -04:00
|
|
|
clutter_timeline_set_repeat_count (state.timeline, -1);
|
2008-03-05 11:04:06 -05:00
|
|
|
g_signal_connect (G_OBJECT(state.timeline),
|
2008-11-07 14:32:28 -05:00
|
|
|
"new-frame",
|
|
|
|
G_CALLBACK(new_frame_cb),
|
|
|
|
&state);
|
2008-03-05 11:04:06 -05:00
|
|
|
g_signal_connect (G_OBJECT(state.timeline),
|
2008-11-07 14:32:28 -05:00
|
|
|
"completed",
|
|
|
|
G_CALLBACK(completed_cb),
|
|
|
|
&state);
|
2008-03-05 11:04:06 -05:00
|
|
|
|
|
|
|
state.completion_count = 0;
|
|
|
|
state.new_frame_counter = 0;
|
|
|
|
state.passed = TRUE;
|
|
|
|
state.expected_frame = 0;
|
2009-05-01 10:08:42 -04:00
|
|
|
|
2020-05-29 13:31:22 -04:00
|
|
|
clutter_actor_show (stage);
|
|
|
|
|
2019-07-31 18:21:03 -04:00
|
|
|
state.start_time = g_get_real_time ();
|
2008-03-05 11:04:06 -05:00
|
|
|
clutter_timeline_start (state.timeline);
|
2008-11-07 14:32:28 -05:00
|
|
|
|
2008-03-05 11:04:06 -05:00
|
|
|
clutter_main();
|
|
|
|
|
2008-11-07 14:32:28 -05:00
|
|
|
g_object_unref (state.timeline);
|
2008-03-05 11:04:06 -05:00
|
|
|
}
|
2020-03-25 11:31:41 -04:00
|
|
|
|
|
|
|
CLUTTER_TEST_SUITE (
|
|
|
|
CLUTTER_TEST_UNIT ("/timeline/interpolate", timeline_interpolation)
|
|
|
|
)
|