2008-03-05 16:04:06 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <glib.h>
|
|
|
|
#include <clutter/clutter.h>
|
|
|
|
|
2008-11-07 19:32:28 +00:00
|
|
|
#include "test-conform-common.h"
|
|
|
|
|
2008-03-05 16:04:06 +00: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 12:05:12 +00:00
|
|
|
#define TEST_TIMELINE_DURATION 5000
|
2008-03-05 16:04:06 +00:00
|
|
|
|
|
|
|
/* We are at the mercy of the system scheduler so this
|
|
|
|
* may not be a very reliable tolerance. */
|
|
|
|
#define TEST_ERROR_TOLERANCE 20
|
|
|
|
|
2009-05-01 14:08:42 +00:00
|
|
|
typedef struct _TestState
|
|
|
|
{
|
|
|
|
ClutterTimeline *timeline;
|
|
|
|
GTimeVal start_time;
|
|
|
|
guint new_frame_counter;
|
|
|
|
gint expected_frame;
|
|
|
|
gint completion_count;
|
|
|
|
gboolean passed;
|
|
|
|
guint source_id;
|
|
|
|
GTimeVal prev_tick;
|
|
|
|
gulong msecs_delta;
|
|
|
|
} TestState;
|
2008-03-05 16:04:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
new_frame_cb (ClutterTimeline *timeline,
|
2008-11-07 19:32:28 +00:00
|
|
|
gint frame_num,
|
2008-03-05 16:04:06 +00:00
|
|
|
TestState *state)
|
|
|
|
{
|
|
|
|
GTimeVal current_time;
|
|
|
|
gint current_frame;
|
|
|
|
glong msec_diff;
|
|
|
|
gint loop_overflow = 0;
|
|
|
|
static gint step = 1;
|
2008-11-07 19:32:28 +00:00
|
|
|
|
2008-03-05 16:04:06 +00:00
|
|
|
g_get_current_time (¤t_time);
|
|
|
|
|
2009-06-04 12:05:12 +00:00
|
|
|
current_frame = clutter_timeline_get_elapsed_time (state->timeline);
|
2008-11-07 19:32:28 +00:00
|
|
|
|
2008-03-05 16:04:06 +00:00
|
|
|
msec_diff = (current_time.tv_sec - state->start_time.tv_sec) * 1000;
|
|
|
|
msec_diff += (current_time.tv_usec - state->start_time.tv_usec)/1000;
|
2008-11-07 19:32:28 +00:00
|
|
|
|
2008-03-05 16:04:06 +00:00
|
|
|
/* If we expect to have interpolated past the end of the timeline
|
|
|
|
* we keep track of the overflow so we can determine when
|
|
|
|
* the next timeout will happen. We then clip expected_frames
|
2009-06-04 12:05:12 +00:00
|
|
|
* to TEST_TIMELINE_DURATION since clutter-timeline
|
2008-03-05 16:04:06 +00:00
|
|
|
* semantics guaranty this frame is always signaled before
|
|
|
|
* looping */
|
2009-06-04 12:05:12 +00:00
|
|
|
if (state->expected_frame > TEST_TIMELINE_DURATION)
|
2008-03-05 16:04:06 +00:00
|
|
|
{
|
2009-06-04 12:05:12 +00:00
|
|
|
loop_overflow = state->expected_frame - TEST_TIMELINE_DURATION;
|
|
|
|
state->expected_frame = TEST_TIMELINE_DURATION;
|
2008-03-05 16:04:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (current_frame >= (state->expected_frame-TEST_ERROR_TOLERANCE)
|
|
|
|
&& current_frame <= (state->expected_frame+TEST_ERROR_TOLERANCE))
|
|
|
|
{
|
2008-11-07 19:32:28 +00:00
|
|
|
g_test_message ("\nelapsed milliseconds=%-5li "
|
|
|
|
"expected frame=%-4i actual frame=%-4i (OK)\n",
|
|
|
|
msec_diff,
|
|
|
|
state->expected_frame,
|
|
|
|
current_frame);
|
2008-03-05 16:04:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-11-07 19:32:28 +00:00
|
|
|
g_test_message ("\nelapsed milliseconds=%-5li "
|
|
|
|
"expected frame=%-4i actual frame=%-4i (FAILED)\n",
|
|
|
|
msec_diff,
|
|
|
|
state->expected_frame,
|
|
|
|
current_frame);
|
2008-03-05 16:04:06 +00:00
|
|
|
state->passed = FALSE;
|
|
|
|
}
|
2008-11-07 19:32:28 +00:00
|
|
|
|
2008-03-05 16:04:06 +00:00
|
|
|
if (step>0)
|
|
|
|
{
|
|
|
|
state->expected_frame = current_frame + (TEST_TIMELINE_FPS / 4);
|
2008-11-07 19:32:28 +00:00
|
|
|
g_test_message ("Sleeping for 250ms "
|
|
|
|
"so next frame should be (%i + %i) = %i\n",
|
|
|
|
current_frame,
|
|
|
|
(TEST_TIMELINE_FPS / 4),
|
|
|
|
state->expected_frame);
|
2008-03-05 16:04:06 +00:00
|
|
|
g_usleep (250000);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
state->expected_frame = current_frame + TEST_TIMELINE_FPS;
|
2008-11-07 19:32:28 +00:00
|
|
|
g_test_message ("Sleeping for 1sec "
|
|
|
|
"so next frame should be (%i + %i) = %i\n",
|
|
|
|
current_frame,
|
|
|
|
TEST_TIMELINE_FPS,
|
|
|
|
state->expected_frame);
|
2008-03-05 16:04:06 +00:00
|
|
|
g_usleep (1000000);
|
|
|
|
}
|
2008-11-07 19:32:28 +00:00
|
|
|
|
2009-06-04 12:05:12 +00:00
|
|
|
if (current_frame >= TEST_TIMELINE_DURATION)
|
2008-03-05 16:04:06 +00:00
|
|
|
{
|
|
|
|
state->expected_frame += loop_overflow;
|
2009-06-04 12:05:12 +00:00
|
|
|
state->expected_frame -= TEST_TIMELINE_DURATION;
|
2008-11-07 19:32:28 +00:00
|
|
|
g_test_message ("End of timeline reached: "
|
|
|
|
"Wrapping expected frame too %i\n",
|
|
|
|
state->expected_frame);
|
2008-03-05 16:04:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
state->new_frame_counter++;
|
|
|
|
step = -step;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
completed_cb (ClutterTimeline *timeline,
|
2008-11-07 19:32:28 +00:00
|
|
|
TestState *state)
|
2008-03-05 16:04:06 +00:00
|
|
|
{
|
2008-11-07 19:32:28 +00:00
|
|
|
state->completion_count++;
|
|
|
|
|
|
|
|
if (state->completion_count == 2)
|
|
|
|
{
|
|
|
|
if (state->passed)
|
|
|
|
{
|
|
|
|
g_test_message ("Passed\n");
|
|
|
|
clutter_main_quit ();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_test_message ("Failed\n");
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
2008-03-05 16:04:06 +00:00
|
|
|
}
|
|
|
|
|
2009-05-01 14:08:42 +00:00
|
|
|
static gboolean
|
|
|
|
frame_tick (gpointer data)
|
|
|
|
{
|
|
|
|
TestState *state = data;
|
|
|
|
GTimeVal cur_tick = { 0, };
|
|
|
|
gulong msecs;
|
|
|
|
|
|
|
|
g_get_current_time (&cur_tick);
|
|
|
|
|
|
|
|
if (state->prev_tick.tv_sec == 0)
|
|
|
|
state->prev_tick = cur_tick;
|
|
|
|
|
|
|
|
msecs = (cur_tick.tv_sec - state->prev_tick.tv_sec) * 1000
|
|
|
|
+ (cur_tick.tv_usec - state->prev_tick.tv_usec) / 1000;
|
|
|
|
|
|
|
|
if (clutter_timeline_is_playing (state->timeline))
|
|
|
|
clutter_timeline_advance_delta (state->timeline, msecs);
|
|
|
|
|
|
|
|
state->msecs_delta = msecs;
|
|
|
|
state->prev_tick = cur_tick;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2008-03-05 16:04:06 +00:00
|
|
|
|
2008-11-07 19:32:28 +00:00
|
|
|
void
|
|
|
|
test_timeline_interpolate (TestConformSimpleFixture *fixture,
|
|
|
|
gconstpointer data)
|
2008-03-05 16:04:06 +00:00
|
|
|
{
|
|
|
|
TestState state;
|
|
|
|
|
|
|
|
state.timeline =
|
2009-06-04 12:05:12 +00:00
|
|
|
clutter_timeline_new (TEST_TIMELINE_DURATION);
|
2008-03-05 16:04:06 +00:00
|
|
|
clutter_timeline_set_loop (state.timeline, TRUE);
|
|
|
|
g_signal_connect (G_OBJECT(state.timeline),
|
2008-11-07 19:32:28 +00:00
|
|
|
"new-frame",
|
|
|
|
G_CALLBACK(new_frame_cb),
|
|
|
|
&state);
|
2008-03-05 16:04:06 +00:00
|
|
|
g_signal_connect (G_OBJECT(state.timeline),
|
2008-11-07 19:32:28 +00:00
|
|
|
"completed",
|
|
|
|
G_CALLBACK(completed_cb),
|
|
|
|
&state);
|
2008-03-05 16:04:06 +00:00
|
|
|
|
|
|
|
state.completion_count = 0;
|
|
|
|
state.new_frame_counter = 0;
|
|
|
|
state.passed = TRUE;
|
|
|
|
state.expected_frame = 0;
|
2009-05-01 14:08:42 +00:00
|
|
|
state.prev_tick.tv_sec = 0;
|
|
|
|
state.prev_tick.tv_usec = 0;
|
|
|
|
state.msecs_delta = 0;
|
|
|
|
|
|
|
|
state.source_id =
|
|
|
|
clutter_threads_add_frame_source (60, frame_tick, &state);
|
2008-03-05 16:04:06 +00:00
|
|
|
|
|
|
|
g_get_current_time (&state.start_time);
|
|
|
|
clutter_timeline_start (state.timeline);
|
2008-11-07 19:32:28 +00:00
|
|
|
|
2008-03-05 16:04:06 +00:00
|
|
|
clutter_main();
|
|
|
|
|
2009-05-01 14:08:42 +00:00
|
|
|
g_source_remove (state.source_id);
|
2008-11-07 19:32:28 +00:00
|
|
|
g_object_unref (state.timeline);
|
2008-03-05 16:04:06 +00:00
|
|
|
}
|