| 1 |
#include <stdlib.h> |
| 2 |
#include <glib.h> |
| 3 |
#include <clutter/clutter.h> |
| 4 |
|
| 5 |
static GTimer *testtimer = NULL; |
| 6 |
static gint testframes = 0; |
| 7 |
static float testmaxtime = 1.0; |
| 8 |
|
| 9 |
/* initialize environment to be suitable for fps testing */ |
| 10 |
void clutter_perf_fps_init (void) |
| 11 |
{ |
| 12 |
/* Force not syncing to vblank, we want free-running maximum FPS */ |
| 13 |
g_setenv ("vblank_mode", "0", FALSE); |
| 14 |
g_setenv ("CLUTTER_VBLANK", "none", FALSE); |
| 15 |
|
| 16 |
/* also overrride internal default FPS */ |
| 17 |
g_setenv ("CLUTTER_DEFAULT_FPS", "1000", FALSE); |
| 18 |
|
| 19 |
if (g_getenv ("CLUTTER_PERFORMANCE_TEST_DURATION")) |
| 20 |
testmaxtime = atof(g_getenv("CLUTTER_PERFORMANCE_TEST_DURATION")); |
| 21 |
else |
| 22 |
testmaxtime = 10.0; |
| 23 |
|
| 24 |
g_random_set_seed (12345678); |
| 25 |
} |
| 26 |
|
| 27 |
static void perf_stage_paint_cb (ClutterStage *stage, gpointer *data); |
| 28 |
static gboolean perf_fake_mouse_cb (gpointer stage); |
| 29 |
|
| 30 |
void clutter_perf_fps_start (ClutterStage *stage) |
| 31 |
{ |
| 32 |
g_signal_connect (stage, "paint", G_CALLBACK (perf_stage_paint_cb), NULL); |
| 33 |
} |
| 34 |
|
| 35 |
void clutter_perf_fake_mouse (ClutterStage *stage) |
| 36 |
{ |
| 37 |
clutter_threads_add_timeout (1000/60, perf_fake_mouse_cb, stage); |
| 38 |
} |
| 39 |
|
| 40 |
void clutter_perf_fps_report (const gchar *id) |
| 41 |
{ |
| 42 |
g_print ("\n@ %s: %.2f fps \n", |
| 43 |
id, testframes / g_timer_elapsed (testtimer, NULL)); |
| 44 |
} |
| 45 |
|
| 46 |
static void perf_stage_paint_cb (ClutterStage *stage, gpointer *data) |
| 47 |
{ |
| 48 |
if (!testtimer) |
| 49 |
testtimer = g_timer_new (); |
| 50 |
testframes ++; |
| 51 |
if (g_timer_elapsed (testtimer, NULL) > testmaxtime) |
| 52 |
{ |
| 53 |
clutter_main_quit (); |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
static void wrap (gfloat *value, gfloat min, gfloat max) |
| 58 |
{ |
| 59 |
if (*value > max) |
| 60 |
*value = min; |
| 61 |
else if (*value < min) |
| 62 |
*value = max; |
| 63 |
} |
| 64 |
|
| 65 |
static gboolean perf_fake_mouse_cb (gpointer stage) |
| 66 |
{ |
| 67 |
ClutterEvent *event = clutter_event_new (CLUTTER_MOTION); |
| 68 |
static ClutterInputDevice *device = NULL; |
| 69 |
int i; |
| 70 |
static float x = 0.0; |
| 71 |
static float y = 0.0; |
| 72 |
static float xd = 0.0; |
| 73 |
static float yd = 0.0; |
| 74 |
static gboolean inited = FALSE; |
| 75 |
|
| 76 |
gfloat w, h; |
| 77 |
|
| 78 |
if (!inited) /* XXX: |
| 79 |
force clutter to do handle our motion events, |
| 80 |
by forcibly updating the input device's state |
| 81 |
this shoudl be possible to do in a better |
| 82 |
manner in the future, a versioning check |
| 83 |
will have to be added when this is possible |
| 84 |
without a hack... and the means to do the |
| 85 |
hack is deprecated |
| 86 |
*/ |
| 87 |
{ |
| 88 |
ClutterEvent *event2 = clutter_event_new (CLUTTER_ENTER); |
| 89 |
device = clutter_device_manager_get_core_device (clutter_device_manager_get_default (), CLUTTER_POINTER_DEVICE); |
| 90 |
|
| 91 |
event2->crossing.stage = stage; |
| 92 |
event2->crossing.source = stage; |
| 93 |
event2->crossing.x = 10; |
| 94 |
event2->crossing.y = 10; |
| 95 |
event2->crossing.device = device; |
| 96 |
event2->crossing.related = NULL; |
| 97 |
|
| 98 |
clutter_input_device_update_from_event (device, event2, TRUE); |
| 99 |
|
| 100 |
clutter_event_put (event2); |
| 101 |
clutter_event_free (event2); |
| 102 |
inited = TRUE; |
| 103 |
} |
| 104 |
|
| 105 |
clutter_actor_get_size (stage, &w, &h); |
| 106 |
event->motion.stage = stage; |
| 107 |
event->motion.device = device; |
| 108 |
|
| 109 |
/* called about every 60fps, and do 10 picks per stage */ |
| 110 |
for (i = 0; i < 10; i++) |
| 111 |
{ |
| 112 |
event->motion.x = x; |
| 113 |
event->motion.y = y; |
| 114 |
|
| 115 |
clutter_event_put (event); |
| 116 |
|
| 117 |
x += xd; |
| 118 |
y += yd; |
| 119 |
xd += g_random_double_range (-0.1, 0.1); |
| 120 |
yd += g_random_double_range (-0.1, 0.1); |
| 121 |
|
| 122 |
wrap (&x, 0, w); |
| 123 |
wrap (&y, 0, h); |
| 124 |
|
| 125 |
xd = CLAMP(xd, -1.3, 1.3); |
| 126 |
yd = CLAMP(yd, -1.3, 1.3); |
| 127 |
} |
| 128 |
clutter_event_free (event); |
| 129 |
return G_SOURCE_CONTINUE; |
| 130 |
} |