summaryrefslogtreecommitdiff
path: root/compbench.c
blob: f6b6a93874c37f54ecd2ae4644ad7547c2afe471 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#include <Elementary.h>
#include <Efx.h>
#include <errno.h>

/* screen size
 * broken for multimonitor
 */
static int sw, sh;

static Evas_Object *win, *rect;

static unsigned int max, num = 0;

typedef enum
{
   TEST_NORMAL,
   TEST_ALPHA,
   TEST_BORDERLESS,
   TEST_BORDERLESS_ALPHA,
   TEST_OVERRIDE,
   TEST_OVERRIDE_ALPHA,
   TEST_END
} Test;

static const char *test_string[] =
{
   [TEST_NORMAL] = "NORMAL",
   [TEST_ALPHA] = "ALPHA",
   [TEST_BORDERLESS] = "BORDERLESS",
   [TEST_BORDERLESS_ALPHA] = "BORDERLESS_ALPHA",
   [TEST_OVERRIDE] = "OVERRIDE",
   [TEST_OVERRIDE_ALPHA] = "OVERRIDE_ALPHA"
};

static Test test = TEST_OVERRIDE_ALPHA;

static Eina_Bool test_override[] =
{
   [TEST_NORMAL] = EINA_FALSE,
   [TEST_ALPHA] = EINA_FALSE,
   [TEST_BORDERLESS] = EINA_FALSE,
   [TEST_BORDERLESS_ALPHA] = EINA_FALSE,
   [TEST_OVERRIDE] = EINA_TRUE,
   [TEST_OVERRIDE_ALPHA] = EINA_TRUE
};

static Eina_Bool test_borderless[] =
{
   [TEST_NORMAL] = EINA_FALSE,
   [TEST_ALPHA] = EINA_FALSE,
   [TEST_BORDERLESS] = EINA_TRUE,
   [TEST_BORDERLESS_ALPHA] = EINA_TRUE,
   [TEST_OVERRIDE] = EINA_FALSE,
   [TEST_OVERRIDE_ALPHA] = EINA_FALSE
};

static Eina_Bool test_alpha[] =
{
   [TEST_NORMAL] = EINA_FALSE,
   [TEST_ALPHA] = EINA_TRUE,
   [TEST_BORDERLESS] = EINA_FALSE,
   [TEST_BORDERLESS_ALPHA] = EINA_TRUE,
   [TEST_OVERRIDE] = EINA_FALSE,
   [TEST_OVERRIDE_ALPHA] = EINA_TRUE
};

static void _resize1(void *data EINA_UNUSED, Efx_Map_Data *emd EINA_UNUSED, Evas_Object *o EINA_UNUSED);

static Eina_Bool
_test_init(void)
{
   Evas_Object *pwin;
   Eina_Bool ret = EINA_FALSE;

   test++;
   ret = (test == TEST_END);
   if (ret)
     test = TEST_NORMAL;

   pwin = win;
   if (pwin) evas_object_hide(pwin);
   win = elm_win_util_standard_add("compbench", "compbench");
   elm_win_autodel_set(win, 1);
   elm_win_override_set(win, test_override[test]);
   elm_win_borderless_set(win, test_borderless[test]);
   elm_win_alpha_set(win, test_alpha[test]);
   evas_object_show(win);
   elm_win_screen_size_get(win, NULL, NULL, &sw, &sh);
   /* objects start at 0,0
    * need to do some other move to force the 0,0 coords
    */
   evas_object_move(win, -1, -1);
   evas_object_move(win, 0, 0);
   evas_object_resize(win, 400, 400);
   rect = elm_bg_add(win);
   elm_bg_color_set(rect, 0, 0, 0);
   evas_object_size_hint_align_set(rect, EVAS_HINT_FILL, EVAS_HINT_FILL);
   evas_object_size_hint_expand_set(rect, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   elm_win_resize_object_add(win, rect);
   evas_object_show(rect);

   rect = evas_object_rectangle_add(evas_object_evas_get(win));
   evas_object_resize(rect, 400, 400);
   evas_object_show(rect);
   /* start with a red rect */
   efx_fade(rect, EFX_EFFECT_SPEED_LINEAR, EFX_COLOR(255, 0, 0), 255, 0.0, NULL, NULL);

   /* first effect is a resize! */
   efx_resize(rect, EFX_EFFECT_SPEED_LINEAR, NULL, 100, 100, 10.0, _resize1, NULL);
   if (pwin) evas_object_del(pwin);
   return ret;
}

static void
_reset(void *data EINA_UNUSED, Efx_Map_Data *emd EINA_UNUSED, Evas_Object *o EINA_UNUSED)
{
   /* we've completed a loop! */
   if (_test_init())
     {
        /* we've completed a test set! */
        num++;
        printf("TEST SET #%d COMPLETE!\n", num);
     }
   /* quit here if we reached the max desired loops */
   if (max && (num == max)) ecore_main_loop_quit();
   else
     printf("STARTING TEST: %s\n", test_string[test]);
}

static void
_fs_toggle(void *data EINA_UNUSED, Efx_Map_Data *emd EINA_UNUSED, Evas_Object *o EINA_UNUSED)
{
   Eina_Bool fs = elm_win_fullscreen_get(win);
   static int done = 0;

   /* toggle fullscreen */
   elm_win_fullscreen_set(win, !fs);
   printf("FULLSCREEN: %d\n", !fs);
   if (!done++) return;
   /* when coming out of fullscreen, resize ourselves to starting size */
   efx_resize(win, EFX_EFFECT_SPEED_LINEAR, NULL, 400, 400, 10.0, _reset, NULL);
   efx_follow(win, rect);
   done = 0;
}

static void
_queue_setup(void)
{
   /* this executes a series of fade ops to smoothly animate color
    * changes on the main rect. colors are not important,
    * we just want to force redraws across large areas here
    */
   efx_queue_append(rect, EFX_EFFECT_SPEED_LINEAR,
     EFX_QUEUED_EFFECT(EFX_EFFECT_FADE(0, 30, 222, 255)),
     3.0, NULL, NULL);
   efx_queue_append(rect, EFX_EFFECT_SPEED_LINEAR,
     EFX_QUEUED_EFFECT(EFX_EFFECT_FADE(0, 60, 180, 255)),
     3.0, NULL, NULL);
   efx_queue_append(rect, EFX_EFFECT_SPEED_LINEAR,
     EFX_QUEUED_EFFECT(EFX_EFFECT_FADE(0, 90, 150, 255)),
     3.0, NULL, NULL);
   efx_queue_append(rect, EFX_EFFECT_SPEED_LINEAR,
     EFX_QUEUED_EFFECT(EFX_EFFECT_FADE(0, 120, 120, 255)),
     3.0, NULL, NULL);
   efx_queue_append(rect, EFX_EFFECT_SPEED_LINEAR,
     EFX_QUEUED_EFFECT(EFX_EFFECT_FADE(30, 150, 90, 255)),
     3.0, NULL, NULL);
   efx_queue_append(rect, EFX_EFFECT_SPEED_LINEAR,
     EFX_QUEUED_EFFECT(EFX_EFFECT_FADE(60, 180, 60, 255)),
     3.0, NULL, NULL);
   efx_queue_append(rect, EFX_EFFECT_SPEED_LINEAR,
     EFX_QUEUED_EFFECT(EFX_EFFECT_FADE(90, 210, 30, 255)),
     3.0, NULL, NULL);
   efx_queue_append(rect, EFX_EFFECT_SPEED_LINEAR,
     EFX_QUEUED_EFFECT(EFX_EFFECT_FADE(120, 255, 0, 255)),
     3.0, NULL, NULL);
   efx_queue_append(rect, EFX_EFFECT_SPEED_LINEAR,
     EFX_QUEUED_EFFECT(EFX_EFFECT_FADE(150, 220, 0, 255)),
     3.0, NULL, NULL);
   efx_queue_append(rect, EFX_EFFECT_SPEED_LINEAR,
     EFX_QUEUED_EFFECT(EFX_EFFECT_FADE(180, 180, 0, 255)),
     3.0, NULL, NULL);
   efx_queue_append(rect, EFX_EFFECT_SPEED_LINEAR,
     EFX_QUEUED_EFFECT(EFX_EFFECT_FADE(210, 150, 0, 255)),
     3.0, NULL, NULL);
   efx_queue_append(rect, EFX_EFFECT_SPEED_LINEAR,
     EFX_QUEUED_EFFECT(EFX_EFFECT_FADE(230, 100, 0, 255)),
     3.0, NULL, NULL);
   efx_queue_append(rect, EFX_EFFECT_SPEED_LINEAR,
     EFX_QUEUED_EFFECT(EFX_EFFECT_FADE(255, 0, 0, 255)),
     3.0, _fs_toggle, NULL);
}

static void
_rect_resize3(void *data EINA_UNUSED, Efx_Map_Data *emd EINA_UNUSED, Evas_Object *o EINA_UNUSED)
{
   /* run the rect color fades twice:
    * - first time in windowed mode
    * - second time fullscreen
    */
   _queue_setup();
   _queue_setup();
   /* start queued ops */
   efx_queue_run(rect);
}

static void
_resize1(void *data EINA_UNUSED, Efx_Map_Data *emd EINA_UNUSED, Evas_Object *o EINA_UNUSED)
{
   Efx_Queue_Data *eqd;

   /* resize to 100x100 */
   eqd = efx_queue_append(win, EFX_EFFECT_SPEED_LINEAR,
     EFX_QUEUED_EFFECT(EFX_EFFECT_RESIZE(NULL, 100, 100)),
     10.0, NULL, NULL);
   /* resize op: move to bottom right corner and grow to half screen size */
   efx_queue_append(win, EFX_EFFECT_SPEED_LINEAR,
     EFX_QUEUED_EFFECT(EFX_EFFECT_RESIZE(EFX_POINT(sw / 2, sh / 2), sw / 2, sh / 2)),
     30.0, NULL, NULL);
   /* resize op: move to upper right corner and grow to screen size */
   efx_queue_append(win, EFX_EFFECT_SPEED_LINEAR,
     EFX_QUEUED_EFFECT(EFX_EFFECT_RESIZE(EFX_POINT(0, 0), sw, sh)),
     30.0, NULL, NULL);
   /* start queued ops */
   efx_queue_run(win);

   /* shrink to 1x1 */
   eqd = efx_queue_append(rect, EFX_EFFECT_SPEED_LINEAR,
     EFX_QUEUED_EFFECT(EFX_EFFECT_RESIZE(NULL, 1, 1)),
     10.0, NULL, NULL);
   /* fade to green during resize */
   efx_queue_effect_attach(eqd, EFX_EFFECT_SPEED_LINEAR,
     EFX_QUEUED_EFFECT(EFX_EFFECT_FADE(0, 255, 0, 255)),
     10.0, NULL, NULL);
   /* grow to half screen size */
   eqd = efx_queue_append(rect, EFX_EFFECT_SPEED_LINEAR,
     EFX_QUEUED_EFFECT(EFX_EFFECT_RESIZE(NULL, sw / 2, sh / 2)),
     30.0, NULL, NULL);
   /* fade to blue during resize */
   efx_queue_effect_attach(eqd, EFX_EFFECT_SPEED_LINEAR,
     EFX_QUEUED_EFFECT(EFX_EFFECT_FADE(0, 0, 255, 255)),
     30.0, NULL, NULL);
   /* grow to screen size */
   efx_queue_append(rect, EFX_EFFECT_SPEED_LINEAR,
     EFX_QUEUED_EFFECT(EFX_EFFECT_RESIZE(NULL, sw, sh)),
     30.0, _rect_resize3, NULL);
   /* start queued ops */
   efx_queue_run(rect);
}

int
main(int argc, char *argv[])
{
   if (argc == 2)
     {
        errno = 0;
        max = strtoul(argv[1], NULL, 10);
        if (errno) max = 0;
     }
   elm_init(argc, argv);
   efx_init();
   elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);

   _test_init();

   printf("STARTING TEST: %s\n", test_string[test]);

   ecore_main_loop_begin();
   return 0;
}