d6d208da7d
With the recent change to internal floating point values, ClutterUnit has become a redundant type, defined to be a float. All integer entry points are being internally converted to floating point values to be passed to the GL pipeline with the least amount of conversion. ClutterUnit is thus exposed as just a "pixel with fractionary bits", and not -- as users might think -- as generic, resolution and device independent units. not that it was the case, but a definitive amount of people was convinced it did provide this "feature", and was flummoxed about the mere existence of this type. So, having ClutterUnit exposed in the public API doubles the entry points and has the following disadvantages: - we have to maintain twice the amount of entry points in ClutterActor - we still do an integer-to-float implicit conversion - we introduce a weird impedance between pixels and "pixels with fractionary bits" - language bindings will have to choose what to bind, and resort to manually overriding the API + *except* for language bindings based on GObject-Introspection, as they cannot do manual overrides, thus will replicate the entire set of entry points For these reason, we should coalesces every Actor entry point for pixels and for ClutterUnit into a single entry point taking a float, like: void clutter_actor_set_x (ClutterActor *self, gfloat x); void clutter_actor_get_size (ClutterActor *self, gfloat *width, gfloat *height); gfloat clutter_actor_get_height (ClutterActor *self); etc. The issues I have identified are: - we'll have a two cases of compiler warnings: - printf() format of the return values from %d to %f - clutter_actor_get_size() taking floats instead of unsigned ints - we'll have a problem with varargs when passing an integer instead of a floating point value, except on 64bit platforms where the size of a float is the same as the size of an int To be clear: the *intent* of the API should not change -- we still use pixels everywhere -- but: - we remove ambiguity in the API with regard to pixels and units - we remove entry points we get to maintain for the whole 1.0 version of the API - we make things simpler to bind for both manual language bindings and automatic (gobject-introspection based) ones - we have the simplest API possible while still exposing the capabilities of the underlying GL implementation
130 lines
3.0 KiB
C
130 lines
3.0 KiB
C
#include <stdlib.h>
|
|
#include <glib.h>
|
|
#include <clutter/clutter.h>
|
|
|
|
#include "test-conform-common.h"
|
|
|
|
#define TEST_TIMELINE_FPS 10
|
|
#define TEST_TIMELINE_FRAME_COUNT 5
|
|
#define TEST_WATCHDOG_KICK_IN_SECONDS 10
|
|
|
|
typedef struct _TestState
|
|
{
|
|
ClutterTimeline *timeline;
|
|
gint rewind_count;
|
|
guint source_id;
|
|
GTimeVal prev_tick;
|
|
gulong msecs_delta;
|
|
} TestState;
|
|
|
|
static gboolean
|
|
watchdog_timeout (TestState *state)
|
|
{
|
|
g_test_message ("Watchdog timer kicking in\n");
|
|
g_test_message ("rewind_count=%i\n", state->rewind_count);
|
|
if (state->rewind_count <= 3)
|
|
{
|
|
/* The test has hung */
|
|
g_test_message ("Failed (This test shouldn't have hung!)\n");
|
|
exit (EXIT_FAILURE);
|
|
}
|
|
else
|
|
{
|
|
g_test_message ("Passed\n");
|
|
clutter_main_quit ();
|
|
}
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
static void
|
|
new_frame_cb (ClutterTimeline *timeline,
|
|
gint frame_num,
|
|
TestState *state)
|
|
{
|
|
gint current_frame = clutter_timeline_get_current_frame (timeline);
|
|
|
|
if (current_frame == TEST_TIMELINE_FRAME_COUNT)
|
|
{
|
|
g_test_message ("new-frame signal recieved (end of timeline)\n");
|
|
g_test_message ("Rewinding timeline\n");
|
|
clutter_timeline_rewind (timeline);
|
|
state->rewind_count++;
|
|
}
|
|
else
|
|
{
|
|
if (current_frame == 0)
|
|
{
|
|
g_test_message ("new-frame signal recieved (start of timeline)\n");
|
|
}
|
|
else
|
|
{
|
|
g_test_message ("new-frame signal recieved (mid frame)\n");
|
|
}
|
|
|
|
if (state->rewind_count >= 2)
|
|
{
|
|
g_test_message ("Sleeping for 1 second\n");
|
|
g_usleep (1000000);
|
|
}
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
void
|
|
test_timeline_rewind (TestConformSimpleFixture *fixture,
|
|
gconstpointer data)
|
|
{
|
|
TestState state;
|
|
|
|
state.timeline =
|
|
clutter_timeline_new (TEST_TIMELINE_FRAME_COUNT,
|
|
TEST_TIMELINE_FPS);
|
|
g_signal_connect (G_OBJECT(state.timeline),
|
|
"new-frame",
|
|
G_CALLBACK(new_frame_cb),
|
|
&state);
|
|
g_test_message ("Installing a watchdog timeout "
|
|
"to determine if this test hangs\n");
|
|
g_timeout_add (TEST_WATCHDOG_KICK_IN_SECONDS*1000,
|
|
(GSourceFunc)watchdog_timeout,
|
|
&state);
|
|
state.rewind_count = 0;
|
|
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);
|
|
|
|
clutter_timeline_start (state.timeline);
|
|
|
|
clutter_main();
|
|
|
|
g_source_remove (state.source_id);
|
|
g_object_unref (state.timeline);
|
|
}
|