| 1 |
#include <config.h> |
| 2 |
#include <glib.h> |
| 3 |
#include <gmodule.h> |
| 4 |
#include <stdlib.h> |
| 5 |
#include <clutter/clutter.h> |
| 6 |
#include <cogl/cogl.h> |
| 7 |
#include <math.h> |
| 8 |
|
| 9 |
#define STAGE_WIDTH 800 |
| 10 |
#define STAGE_HEIGHT 600 |
| 11 |
|
| 12 |
gboolean run_all = FALSE; |
| 13 |
|
| 14 |
static GOptionEntry entries[] = { |
| 15 |
{ |
| 16 |
"run-all", 'a', |
| 17 |
0, |
| 18 |
G_OPTION_ARG_NONE, &run_all, |
| 19 |
"Run all tests", "" |
| 20 |
}, |
| 21 |
{ NULL } |
| 22 |
}; |
| 23 |
|
| 24 |
typedef struct _TestState |
| 25 |
{ |
| 26 |
ClutterActor *stage; |
| 27 |
int current_test; |
| 28 |
} TestState; |
| 29 |
|
| 30 |
typedef void (*TestCallback) (TestState *state); |
| 31 |
|
| 32 |
static void |
| 33 |
test_rectangles (TestState *state) |
| 34 |
{ |
| 35 |
#define RECT_WIDTH 5 |
| 36 |
#define RECT_HEIGHT 5 |
| 37 |
int x; |
| 38 |
int y; |
| 39 |
|
| 40 |
/* Should the rectangles be randomly positioned/colored/rotated? |
| 41 |
* |
| 42 |
* It could be good to develop equivalent GL and Cairo tests so we can |
| 43 |
* have a sanity check for our Cogl performance. |
| 44 |
* |
| 45 |
* The color should vary to check that we correctly batch color changes |
| 46 |
* The use of alpha should vary so we have a variation of which rectangles |
| 47 |
* require blending. |
| 48 |
* Should this be a random variation? |
| 49 |
* It could be good to experiment with focibly enabling blending for |
| 50 |
* rectangles that don't technically need it for the sake of extending |
| 51 |
* batching. E.g. if you a long run of interleved rectangles with every |
| 52 |
* other rectangle needing blending then it may be worth enabling blending |
| 53 |
* for all the rectangles to avoid the state changes. |
| 54 |
* The modelview should change between rectangles to check the software |
| 55 |
* transform codepath. |
| 56 |
* Should we group some rectangles under the same modelview? Potentially |
| 57 |
* we could avoid software transform for long runs of rectangles with the |
| 58 |
* same modelview. |
| 59 |
* |
| 60 |
*/ |
| 61 |
|
| 62 |
for (y = 0; y < STAGE_HEIGHT; y += RECT_HEIGHT) |
| 63 |
{ |
| 64 |
for (x = 0; x < STAGE_WIDTH; x += RECT_WIDTH) |
| 65 |
{ |
| 66 |
cogl_push_matrix (); |
| 67 |
cogl_translate (x, y, 0); |
| 68 |
cogl_rotate (45, 0, 0, 1); |
| 69 |
cogl_set_source_color4f (1, |
| 70 |
(1.0f/STAGE_WIDTH)*y, |
| 71 |
(1.0f/STAGE_HEIGHT)*x, |
| 72 |
1); |
| 73 |
cogl_rectangle (0, 0, RECT_WIDTH, RECT_HEIGHT); |
| 74 |
cogl_pop_matrix (); |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
for (y = 0; y < STAGE_HEIGHT; y += RECT_HEIGHT) |
| 79 |
{ |
| 80 |
for (x = 0; x < STAGE_WIDTH; x += RECT_WIDTH) |
| 81 |
{ |
| 82 |
cogl_push_matrix (); |
| 83 |
cogl_translate (x, y, 0); |
| 84 |
cogl_rotate (0, 0, 0, 1); |
| 85 |
cogl_set_source_color4f (1, |
| 86 |
(1.0f/STAGE_WIDTH)*x, |
| 87 |
(1.0f/STAGE_HEIGHT)*y, |
| 88 |
(1.0f/STAGE_WIDTH)*x); |
| 89 |
cogl_rectangle (0, 0, RECT_WIDTH, RECT_HEIGHT); |
| 90 |
cogl_pop_matrix (); |
| 91 |
} |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
TestCallback tests[] = |
| 96 |
{ |
| 97 |
test_rectangles |
| 98 |
}; |
| 99 |
|
| 100 |
static void |
| 101 |
on_paint (ClutterActor *actor, TestState *state) |
| 102 |
{ |
| 103 |
tests[state->current_test] (state); |
| 104 |
} |
| 105 |
|
| 106 |
static gboolean |
| 107 |
queue_redraw (gpointer stage) |
| 108 |
{ |
| 109 |
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage)); |
| 110 |
|
| 111 |
return TRUE; |
| 112 |
} |
| 113 |
|
| 114 |
int |
| 115 |
main (int argc, char *argv[]) |
| 116 |
{ |
| 117 |
TestState state; |
| 118 |
ClutterActor *stage; |
| 119 |
GError *error = NULL; |
| 120 |
|
| 121 |
g_setenv ("CLUTTER_VBLANK", "none", FALSE); |
| 122 |
g_setenv ("CLUTTER_SHOW_FPS", "1", FALSE); |
| 123 |
|
| 124 |
if (clutter_init_with_args (&argc, &argv, |
| 125 |
NULL, |
| 126 |
entries, |
| 127 |
NULL, |
| 128 |
&error) != CLUTTER_INIT_SUCCESS) |
| 129 |
{ |
| 130 |
g_warning ("Unable to initialise Clutter:\n%s", |
| 131 |
error->message); |
| 132 |
g_error_free (error); |
| 133 |
|
| 134 |
return EXIT_FAILURE; |
| 135 |
} |
| 136 |
|
| 137 |
state.current_test = 0; |
| 138 |
|
| 139 |
state.stage = stage = clutter_stage_new (); |
| 140 |
|
| 141 |
clutter_actor_set_size (stage, STAGE_WIDTH, STAGE_HEIGHT); |
| 142 |
clutter_stage_set_color (CLUTTER_STAGE (stage), CLUTTER_COLOR_White); |
| 143 |
clutter_stage_set_title (CLUTTER_STAGE (stage), "Cogl Performance Test"); |
| 144 |
|
| 145 |
/* We want continuous redrawing of the stage... */ |
| 146 |
clutter_threads_add_idle (queue_redraw, stage); |
| 147 |
|
| 148 |
g_signal_connect_after (stage, "paint", G_CALLBACK (on_paint), &state); |
| 149 |
|
| 150 |
clutter_actor_show (stage); |
| 151 |
|
| 152 |
clutter_main (); |
| 153 |
|
| 154 |
clutter_actor_destroy (stage); |
| 155 |
|
| 156 |
return 0; |
| 157 |
} |
| 158 |
|