Debian Codegraph @

tests/performance/test-state.c

raw
1 #include <stdlib.h>
2 #include <math.h>
3 #include <gmodule.h>
4 #include <clutter/clutter.h>
5 #include "test-common.h"
6
7 static gint times = 16;
8
9 #define STAGE_WIDTH 800
10 #define STAGE_HEIGHT 600
11
12 #define ACTOR_WIDTH 64
13 #define ACTOR_HEIGHT 64
14
15 #define COLS (STAGE_WIDTH/ACTOR_WIDTH)
16 #define ROWS (STAGE_HEIGHT/ACTOR_HEIGHT)
17 #define TOTAL (ROWS*COLS)
18
19
20 static void completed (ClutterState *state,
21 gpointer data)
22 {
23 if (g_str_equal (clutter_state_get_state (state), "right"))
24 {
25 /* skip straight to left state when reaching right */
26 clutter_state_warp_to_state (state, "left");
27 }
28 else if (g_str_equal (clutter_state_get_state (state), "active"))
29 clutter_state_set_state (state, "right");
30 else
31 {
32 clutter_state_set_state (state, "active");
33 }
34 times --;
35 if (times <=0)
36 clutter_main_quit ();
37 }
38
39 static ClutterActor *new_rect (gint r,
40 gint g,
41 gint b,
42 gint a)
43 {
44 GError *error = NULL;
45 ClutterColor *color = clutter_color_new (r, g, b, a);
46 ClutterActor *group = clutter_group_new ();
47 ClutterActor *rectangle = clutter_rectangle_new_with_color (color);
48 ClutterActor *hand = NULL;
49
50 gchar *file = g_build_filename (TESTS_DATA_DIR, "redhand.png", NULL);
51
52 hand = clutter_texture_new_from_file (file, &error);
53 if (rectangle == NULL)
54 g_error ("image load failed: %s", error->message);
55 g_free (file);
56 clutter_actor_set_size (hand, ACTOR_WIDTH,ACTOR_HEIGHT);
57
58 clutter_actor_set_size (rectangle, ACTOR_WIDTH,ACTOR_HEIGHT);
59 clutter_color_free (color);
60 clutter_container_add (CLUTTER_CONTAINER (group), rectangle, hand, NULL);
61 return group;
62 }
63
64 gint
65 main (gint argc,
66 gchar **argv)
67 {
68 ClutterActor *stage;
69 ClutterState *layout_state;
70 gint i;
71
72 clutter_perf_fps_init ();
73 if (CLUTTER_INIT_SUCCESS != clutter_init (&argc, &argv))
74 g_error ("Failed to initialize Clutter");
75
76 stage = clutter_stage_new ();
77 layout_state = clutter_state_new ();
78 clutter_stage_set_color (CLUTTER_STAGE (stage), CLUTTER_COLOR_Black);
79 clutter_stage_set_title (CLUTTER_STAGE (stage), "State Performance");
80 clutter_actor_set_size (stage, STAGE_WIDTH, STAGE_HEIGHT);
81 g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
82
83 for (i=0; i<TOTAL; i++)
84 {
85 ClutterActor *actor;
86 ClutterState *a_state;
87
88 int row = i/COLS;
89 int col = i%COLS;
90
91 actor = new_rect (255 * ( 1.0*col/COLS), 50,
92 255 * ( 1.0*row/ROWS), 255);
93 clutter_container_add_actor (CLUTTER_CONTAINER (stage), actor);
94 clutter_actor_set_position (actor, 320.0, 240.0);
95 clutter_actor_set_reactive (actor, TRUE);
96
97
98 clutter_state_set (layout_state, NULL, "active",
99 actor, "delayed::x", CLUTTER_LINEAR,
100 ACTOR_WIDTH * 1.0 * ((TOTAL-1-i) % COLS),
101 ((row*1.0/ROWS))/2, (1.0-(row*1.0/ROWS))/2,
102 actor, "delayed::y", CLUTTER_LINEAR,
103 ACTOR_HEIGHT * 1.0 * ((TOTAL-1-i) / COLS),
104 ((row*1.0/ROWS))/2, 0.0,
105 actor, "rotation-angle-x", CLUTTER_LINEAR, 0.0,
106 actor, "rotation-angle-y", CLUTTER_LINEAR, 0.0,
107 NULL);
108
109 clutter_state_set (layout_state, NULL, "right",
110 actor, "delayed::x", CLUTTER_LINEAR, STAGE_WIDTH * 1.0,
111 ((row*1.0/ROWS))/2,
112 (1.0-(row*1.0/ROWS))/2,
113 actor, "delayed::y", CLUTTER_LINEAR, STAGE_HEIGHT * 1.0,
114 ((row*1.0/ROWS))/2,
115 0.0,
116 NULL);
117
118 clutter_state_set (layout_state, NULL, "left",
119 actor, "rotation-angle-x", CLUTTER_LINEAR, 45.0,
120 actor, "rotation-angle-y", CLUTTER_LINEAR, 5.0,
121 actor, "x", CLUTTER_LINEAR, 0-64.0,
122 actor, "y", CLUTTER_LINEAR, 0-64.0,
123 NULL);
124
125 a_state = clutter_state_new ();
126 g_object_set_data_full (G_OBJECT (actor), "hover-state-machine",
127 a_state, g_object_unref);
128
129 clutter_state_set (a_state, NULL, "normal",
130 actor, "opacity", CLUTTER_LINEAR, 0x77,
131 actor, "rotation-angle-z", CLUTTER_LINEAR, 0.0,
132 NULL);
133 clutter_state_set (a_state, NULL, "hover",
134 actor, "opacity", CLUTTER_LINEAR, 0xff,
135 actor, "rotation-angle-z", CLUTTER_LINEAR, 10.0,
136 NULL);
137 clutter_actor_set_opacity (actor, 0x77);
138
139 clutter_state_set_duration (a_state, NULL, NULL, 500);
140 }
141
142 clutter_state_set_duration (layout_state, NULL, NULL, 1000);
143 clutter_state_set_duration (layout_state, "active", "left", 1400);
144
145 g_signal_connect (layout_state, "completed", G_CALLBACK (completed), NULL);
146
147 clutter_actor_show (stage);
148
149 clutter_state_warp_to_state (layout_state, "left");
150 clutter_state_set_state (layout_state, "active");
151
152 clutter_perf_fps_start (CLUTTER_STAGE (stage));
153 clutter_main ();
154 clutter_perf_fps_report ("test-state");
155 g_object_unref (layout_state);
156
157 return EXIT_SUCCESS;
158 }