1 /**
2 * @file lv_demo_benchmark.c
3 *
4 */
5
6 /*********************
7 * INCLUDES
8 *********************/
9 #include "lv_demo_benchmark.h"
10
11 #if LV_USE_DEMO_BENCHMARK
12
13 /*********************
14 * DEFINES
15 *********************/
16 #define RND_NUM 64
17 #define SCENE_TIME 1000 /*ms*/
18 #define ANIM_TIME_MIN ((2 * SCENE_TIME) / 10)
19 #define ANIM_TIME_MAX (SCENE_TIME)
20 #define OBJ_NUM 8
21 #define OBJ_SIZE_MIN (LV_MAX(LV_DPI_DEF / 20, 5))
22 #define OBJ_SIZE_MAX (LV_HOR_RES / 2)
23 #define RADIUS LV_MAX(LV_DPI_DEF / 15, 2)
24 #define BORDER_WIDTH LV_MAX(LV_DPI_DEF / 40, 1)
25 #define SHADOW_WIDTH_SMALL LV_MAX(LV_DPI_DEF / 15, 5)
26 #define SHADOW_OFS_X_SMALL LV_MAX(LV_DPI_DEF / 20, 2)
27 #define SHADOW_OFS_Y_SMALL LV_MAX(LV_DPI_DEF / 20, 2)
28 #define SHADOW_SPREAD_SMALL LV_MAX(LV_DPI_DEF / 30, 2)
29 #define SHADOW_WIDTH_LARGE LV_MAX(LV_DPI_DEF / 5, 10)
30 #define SHADOW_OFS_X_LARGE LV_MAX(LV_DPI_DEF / 10, 5)
31 #define SHADOW_OFS_Y_LARGE LV_MAX(LV_DPI_DEF / 10, 5)
32 #define SHADOW_SPREAD_LARGE LV_MAX(LV_DPI_DEF / 30, 2)
33 #define IMG_WIDH 100
34 #define IMG_HEIGHT 100
35 #define IMG_NUM LV_MAX((LV_HOR_RES * LV_VER_RES) / 5 / IMG_WIDH / IMG_HEIGHT, 1)
36 #define IMG_ZOOM_MIN 128
37 #define IMG_ZOOM_MAX (256 + 64)
38 #define TXT "hello world\nit is a multi line text to test\nthe performance of text rendering"
39 #define LINE_WIDTH LV_MAX(LV_DPI_DEF / 50, 2)
40 #define LINE_POINT_NUM 16
41 #define LINE_POINT_DIFF_MIN (LV_DPI_DEF / 10)
42 #define LINE_POINT_DIFF_MAX LV_MAX(LV_HOR_RES / (LINE_POINT_NUM + 2), LINE_POINT_DIFF_MIN * 2)
43 #define ARC_WIDTH_THIN LV_MAX(LV_DPI_DEF / 50, 2)
44 #define ARC_WIDTH_THICK LV_MAX(LV_DPI_DEF / 10, 5)
45
46 #ifndef dimof
47 #define dimof(__array) (sizeof(__array) / sizeof(__array[0]))
48 #endif
49
50 /**********************
51 * TYPEDEFS
52 **********************/
53
54 typedef struct {
55 const char * name;
56 void (*create_cb)(void);
57 uint32_t time_sum_normal;
58 uint32_t time_sum_opa;
59 uint32_t refr_cnt_normal;
60 uint32_t refr_cnt_opa;
61 uint32_t fps_normal;
62 uint32_t fps_opa;
63 uint8_t weight;
64 } scene_dsc_t;
65
66 /**********************
67 * STATIC PROTOTYPES
68 **********************/
69
70 static lv_style_t style_common;
71 static bool opa_mode = true;
72 static bool run_max_speed = false;
73 static finished_cb_t * benchmark_finished_cb = NULL;
74 static uint32_t disp_ori_timer_period;
75 static uint32_t anim_ori_timer_period;
76
77 #if LV_DEMO_BENCHMARK_RGB565A8 && LV_COLOR_DEPTH == 16
78 LV_IMG_DECLARE(img_benchmark_cogwheel_rgb565a8);
79 #else
80 LV_IMG_DECLARE(img_benchmark_cogwheel_argb);
81 #endif
82 LV_IMG_DECLARE(img_benchmark_cogwheel_rgb);
83 LV_IMG_DECLARE(img_benchmark_cogwheel_chroma_keyed);
84 LV_IMG_DECLARE(img_benchmark_cogwheel_indexed16);
85 LV_IMG_DECLARE(img_benchmark_cogwheel_alpha16);
86
87 LV_FONT_DECLARE(lv_font_benchmark_montserrat_12_compr_az);
88 LV_FONT_DECLARE(lv_font_benchmark_montserrat_16_compr_az);
89 LV_FONT_DECLARE(lv_font_benchmark_montserrat_28_compr_az);
90
91 static void monitor_cb(lv_disp_drv_t * drv, uint32_t time, uint32_t px);
92 static void next_scene_timer_cb(lv_timer_t * timer);
93 static void rect_create(lv_style_t * style);
94 static void img_create(lv_style_t * style, const void * src, bool rotate, bool zoom, bool aa);
95 static void txt_create(lv_style_t * style);
96 static void line_create(lv_style_t * style);
97 static void arc_create(lv_style_t * style);
98 static void fall_anim(lv_obj_t * obj);
99 static void rnd_reset(void);
100 static int32_t rnd_next(int32_t min, int32_t max);
101 static void report_cb(lv_timer_t * timer);
102
rectangle_cb(void)103 static void rectangle_cb(void)
104 {
105 lv_style_reset(&style_common);
106 lv_style_set_bg_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
107 rect_create(&style_common);
108 }
109
rectangle_rounded_cb(void)110 static void rectangle_rounded_cb(void)
111 {
112 lv_style_reset(&style_common);
113 lv_style_set_radius(&style_common, RADIUS);
114 lv_style_set_bg_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
115 rect_create(&style_common);
116 }
117
rectangle_circle_cb(void)118 static void rectangle_circle_cb(void)
119 {
120 lv_style_reset(&style_common);
121 lv_style_set_radius(&style_common, LV_RADIUS_CIRCLE);
122 lv_style_set_bg_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
123 rect_create(&style_common);
124 }
125
border_cb(void)126 static void border_cb(void)
127 {
128 lv_style_reset(&style_common);
129 lv_style_set_border_width(&style_common, BORDER_WIDTH);
130 lv_style_set_border_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
131 rect_create(&style_common);
132 }
133
border_rounded_cb(void)134 static void border_rounded_cb(void)
135 {
136 lv_style_reset(&style_common);
137 lv_style_set_radius(&style_common, RADIUS);
138 lv_style_set_border_width(&style_common, BORDER_WIDTH);
139 lv_style_set_border_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
140 rect_create(&style_common);
141
142 }
143
border_circle_cb(void)144 static void border_circle_cb(void)
145 {
146 lv_style_reset(&style_common);
147 lv_style_set_radius(&style_common, LV_RADIUS_CIRCLE);
148 lv_style_set_border_width(&style_common, BORDER_WIDTH);
149 lv_style_set_border_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
150 rect_create(&style_common);
151 }
152
border_top_cb(void)153 static void border_top_cb(void)
154 {
155 lv_style_reset(&style_common);
156 lv_style_set_radius(&style_common, RADIUS);
157 lv_style_set_border_width(&style_common, BORDER_WIDTH);
158 lv_style_set_border_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
159 lv_style_set_border_side(&style_common, LV_BORDER_SIDE_TOP);
160 rect_create(&style_common);
161
162 }
163
border_left_cb(void)164 static void border_left_cb(void)
165 {
166 lv_style_reset(&style_common);
167 lv_style_set_radius(&style_common, RADIUS);
168 lv_style_set_border_width(&style_common, BORDER_WIDTH);
169 lv_style_set_border_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
170 lv_style_set_border_side(&style_common, LV_BORDER_SIDE_LEFT);
171 rect_create(&style_common);
172 }
173
border_top_left_cb(void)174 static void border_top_left_cb(void)
175 {
176 lv_style_reset(&style_common);
177 lv_style_set_radius(&style_common, RADIUS);
178 lv_style_set_border_width(&style_common, BORDER_WIDTH);
179 lv_style_set_border_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
180 lv_style_set_border_side(&style_common, LV_BORDER_SIDE_LEFT | LV_BORDER_SIDE_TOP);
181 rect_create(&style_common);
182 }
183
border_left_right_cb(void)184 static void border_left_right_cb(void)
185 {
186 lv_style_reset(&style_common);
187 lv_style_set_radius(&style_common, RADIUS);
188 lv_style_set_border_width(&style_common, BORDER_WIDTH);
189 lv_style_set_border_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
190 lv_style_set_border_side(&style_common, LV_BORDER_SIDE_LEFT | LV_BORDER_SIDE_RIGHT);
191 rect_create(&style_common);
192 }
193
border_top_bottom_cb(void)194 static void border_top_bottom_cb(void)
195 {
196 lv_style_reset(&style_common);
197 lv_style_set_radius(&style_common, RADIUS);
198 lv_style_set_border_width(&style_common, BORDER_WIDTH);
199 lv_style_set_border_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
200 lv_style_set_border_side(&style_common, LV_BORDER_SIDE_TOP | LV_BORDER_SIDE_BOTTOM);
201 rect_create(&style_common);
202
203 }
204
shadow_small_cb(void)205 static void shadow_small_cb(void)
206 {
207 lv_style_reset(&style_common);
208 lv_style_set_radius(&style_common, RADIUS);
209 lv_style_set_bg_opa(&style_common, LV_OPA_COVER);
210 lv_style_set_shadow_opa(&style_common, opa_mode ? LV_OPA_80 : LV_OPA_COVER);
211 lv_style_set_shadow_width(&style_common, SHADOW_WIDTH_SMALL);
212 rect_create(&style_common);
213
214 }
215
shadow_small_ofs_cb(void)216 static void shadow_small_ofs_cb(void)
217 {
218 lv_style_reset(&style_common);
219 lv_style_set_radius(&style_common, RADIUS);
220 lv_style_set_bg_opa(&style_common, LV_OPA_COVER);
221 lv_style_set_shadow_opa(&style_common, opa_mode ? LV_OPA_80 : LV_OPA_COVER);
222 lv_style_set_shadow_width(&style_common, SHADOW_WIDTH_SMALL);
223 lv_style_set_shadow_ofs_x(&style_common, SHADOW_OFS_X_SMALL);
224 lv_style_set_shadow_ofs_y(&style_common, SHADOW_OFS_Y_SMALL);
225 lv_style_set_shadow_spread(&style_common, SHADOW_SPREAD_SMALL);
226 rect_create(&style_common);
227 }
228
229
shadow_large_cb(void)230 static void shadow_large_cb(void)
231 {
232 lv_style_reset(&style_common);
233 lv_style_set_radius(&style_common, RADIUS);
234 lv_style_set_bg_opa(&style_common, LV_OPA_COVER);
235 lv_style_set_shadow_opa(&style_common, opa_mode ? LV_OPA_80 : LV_OPA_COVER);
236 lv_style_set_shadow_width(&style_common, SHADOW_WIDTH_LARGE);
237 rect_create(&style_common);
238 }
239
shadow_large_ofs_cb(void)240 static void shadow_large_ofs_cb(void)
241 {
242 lv_style_reset(&style_common);
243 lv_style_set_radius(&style_common, RADIUS);
244 lv_style_set_bg_opa(&style_common, LV_OPA_COVER);
245 lv_style_set_shadow_opa(&style_common, opa_mode ? LV_OPA_80 : LV_OPA_COVER);
246 lv_style_set_shadow_width(&style_common, SHADOW_WIDTH_LARGE);
247 lv_style_set_shadow_ofs_x(&style_common, SHADOW_OFS_X_LARGE);
248 lv_style_set_shadow_ofs_y(&style_common, SHADOW_OFS_Y_LARGE);
249 lv_style_set_shadow_spread(&style_common, SHADOW_SPREAD_LARGE);
250 rect_create(&style_common);
251 }
252
253
img_rgb_cb(void)254 static void img_rgb_cb(void)
255 {
256 lv_style_reset(&style_common);
257 lv_style_set_img_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
258 img_create(&style_common, &img_benchmark_cogwheel_rgb, false, false, false);
259 }
260
img_argb_cb(void)261 static void img_argb_cb(void)
262 {
263 lv_style_reset(&style_common);
264 lv_style_set_img_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
265
266 #if LV_DEMO_BENCHMARK_RGB565A8 && LV_COLOR_DEPTH == 16
267 img_create(&style_common, &img_benchmark_cogwheel_rgb565a8, false, false, false);
268 #else
269 img_create(&style_common, &img_benchmark_cogwheel_argb, false, false, false);
270 #endif
271 }
272
img_ckey_cb(void)273 static void img_ckey_cb(void)
274 {
275 lv_style_reset(&style_common);
276 lv_style_set_img_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
277 img_create(&style_common, &img_benchmark_cogwheel_chroma_keyed, false, false, false);
278
279 }
280
img_index_cb(void)281 static void img_index_cb(void)
282 {
283 lv_style_reset(&style_common);
284 lv_style_set_img_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
285 img_create(&style_common, &img_benchmark_cogwheel_indexed16, false, false, false);
286
287 }
288
img_alpha_cb(void)289 static void img_alpha_cb(void)
290 {
291 lv_style_reset(&style_common);
292 lv_style_set_img_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
293 img_create(&style_common, &img_benchmark_cogwheel_alpha16, false, false, false);
294 }
295
296
img_rgb_recolor_cb(void)297 static void img_rgb_recolor_cb(void)
298 {
299 lv_style_reset(&style_common);
300 lv_style_set_img_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
301 lv_style_set_img_recolor_opa(&style_common, LV_OPA_50);
302 img_create(&style_common, &img_benchmark_cogwheel_rgb, false, false, false);
303
304 }
305
img_argb_recolor_cb(void)306 static void img_argb_recolor_cb(void)
307 {
308 lv_style_reset(&style_common);
309 lv_style_set_img_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
310 lv_style_set_img_recolor_opa(&style_common, LV_OPA_50);
311 #if LV_DEMO_BENCHMARK_RGB565A8 && LV_COLOR_DEPTH == 16
312 img_create(&style_common, &img_benchmark_cogwheel_rgb565a8, false, false, false);
313 #else
314 img_create(&style_common, &img_benchmark_cogwheel_argb, false, false, false);
315 #endif
316 }
317
img_ckey_recolor_cb(void)318 static void img_ckey_recolor_cb(void)
319 {
320 lv_style_reset(&style_common);
321 lv_style_set_img_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
322 lv_style_set_img_recolor_opa(&style_common, LV_OPA_50);
323 img_create(&style_common, &img_benchmark_cogwheel_chroma_keyed, false, false, false);
324 }
325
img_index_recolor_cb(void)326 static void img_index_recolor_cb(void)
327 {
328 lv_style_reset(&style_common);
329 lv_style_set_img_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
330 lv_style_set_img_recolor_opa(&style_common, LV_OPA_50);
331 img_create(&style_common, &img_benchmark_cogwheel_indexed16, false, false, false);
332
333 }
334
img_rgb_rot_cb(void)335 static void img_rgb_rot_cb(void)
336 {
337 lv_style_reset(&style_common);
338 lv_style_set_img_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
339 img_create(&style_common, &img_benchmark_cogwheel_rgb, true, false, false);
340 }
341
img_rgb_rot_aa_cb(void)342 static void img_rgb_rot_aa_cb(void)
343 {
344 lv_style_reset(&style_common);
345 lv_style_set_img_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
346 img_create(&style_common, &img_benchmark_cogwheel_rgb, true, false, true);
347 }
348
img_argb_rot_cb(void)349 static void img_argb_rot_cb(void)
350 {
351 lv_style_reset(&style_common);
352 lv_style_set_img_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
353 #if LV_DEMO_BENCHMARK_RGB565A8 && LV_COLOR_DEPTH == 16
354 img_create(&style_common, &img_benchmark_cogwheel_rgb565a8, true, false, false);
355 #else
356 img_create(&style_common, &img_benchmark_cogwheel_argb, true, false, false);
357 #endif
358 }
359
img_argb_rot_aa_cb(void)360 static void img_argb_rot_aa_cb(void)
361 {
362 lv_style_reset(&style_common);
363 lv_style_set_img_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
364 #if LV_DEMO_BENCHMARK_RGB565A8 && LV_COLOR_DEPTH == 16
365 img_create(&style_common, &img_benchmark_cogwheel_rgb565a8, true, false, true);
366 #else
367 img_create(&style_common, &img_benchmark_cogwheel_argb, true, false, true);
368 #endif
369 }
370
img_rgb_zoom_cb(void)371 static void img_rgb_zoom_cb(void)
372 {
373 lv_style_reset(&style_common);
374 lv_style_set_img_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
375 img_create(&style_common, &img_benchmark_cogwheel_rgb, false, true, false);
376
377 }
378
img_rgb_zoom_aa_cb(void)379 static void img_rgb_zoom_aa_cb(void)
380 {
381 lv_style_reset(&style_common);
382 lv_style_set_img_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
383 img_create(&style_common, &img_benchmark_cogwheel_rgb, false, true, true);
384
385
386 }
387
img_argb_zoom_cb(void)388 static void img_argb_zoom_cb(void)
389 {
390 lv_style_reset(&style_common);
391 lv_style_set_img_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
392 #if LV_DEMO_BENCHMARK_RGB565A8 && LV_COLOR_DEPTH == 16
393 img_create(&style_common, &img_benchmark_cogwheel_rgb565a8, false, true, false);
394 #else
395 img_create(&style_common, &img_benchmark_cogwheel_argb, false, true, false);
396 #endif
397 }
398
399
img_argb_zoom_aa_cb(void)400 static void img_argb_zoom_aa_cb(void)
401 {
402 lv_style_reset(&style_common);
403 lv_style_set_img_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
404 #if LV_DEMO_BENCHMARK_RGB565A8 && LV_COLOR_DEPTH == 16
405 img_create(&style_common, &img_benchmark_cogwheel_rgb565a8, false, true, true);
406 #else
407 img_create(&style_common, &img_benchmark_cogwheel_argb, false, true, true);
408 #endif
409 }
410
txt_small_cb(void)411 static void txt_small_cb(void)
412 {
413 lv_style_reset(&style_common);
414 lv_style_set_text_font(&style_common, lv_theme_get_font_small(NULL));
415 lv_style_set_text_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
416 txt_create(&style_common);
417
418 }
419
txt_medium_cb(void)420 static void txt_medium_cb(void)
421 {
422 lv_style_reset(&style_common);
423 lv_style_set_text_font(&style_common, lv_theme_get_font_normal(NULL));
424 lv_style_set_text_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
425 txt_create(&style_common);
426
427 }
428
txt_large_cb(void)429 static void txt_large_cb(void)
430 {
431 lv_style_reset(&style_common);
432 lv_style_set_text_font(&style_common, lv_theme_get_font_large(NULL));
433 lv_style_set_text_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
434 txt_create(&style_common);
435
436 }
437
txt_small_compr_cb(void)438 static void txt_small_compr_cb(void)
439 {
440 lv_style_reset(&style_common);
441 lv_style_set_text_font(&style_common, &lv_font_benchmark_montserrat_12_compr_az);
442 lv_style_set_text_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
443 txt_create(&style_common);
444
445 }
446
txt_medium_compr_cb(void)447 static void txt_medium_compr_cb(void)
448 {
449 lv_style_reset(&style_common);
450 lv_style_set_text_font(&style_common, &lv_font_benchmark_montserrat_16_compr_az);
451 lv_style_set_text_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
452 txt_create(&style_common);
453
454 }
455
txt_large_compr_cb(void)456 static void txt_large_compr_cb(void)
457 {
458 lv_style_reset(&style_common);
459 lv_style_set_text_font(&style_common, &lv_font_benchmark_montserrat_28_compr_az);
460 lv_style_set_text_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
461 txt_create(&style_common);
462
463 }
464
465
line_cb(void)466 static void line_cb(void)
467 {
468 lv_style_reset(&style_common);
469 lv_style_set_line_width(&style_common, LINE_WIDTH);
470 lv_style_set_line_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
471 line_create(&style_common);
472
473 }
474
arc_think_cb(void)475 static void arc_think_cb(void)
476 {
477
478 lv_style_reset(&style_common);
479 lv_style_set_arc_width(&style_common, ARC_WIDTH_THIN);
480 lv_style_set_arc_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
481 arc_create(&style_common);
482 }
483
arc_thick_cb(void)484 static void arc_thick_cb(void)
485 {
486 lv_style_reset(&style_common);
487 lv_style_set_arc_width(&style_common, ARC_WIDTH_THICK);
488 lv_style_set_arc_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
489 arc_create(&style_common);
490
491 }
492
493
sub_rectangle_cb(void)494 static void sub_rectangle_cb(void)
495 {
496 lv_style_reset(&style_common);
497 lv_style_set_radius(&style_common, RADIUS);
498 lv_style_set_bg_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
499 lv_style_set_blend_mode(&style_common, LV_BLEND_MODE_SUBTRACTIVE);
500 rect_create(&style_common);
501 }
502
sub_border_cb(void)503 static void sub_border_cb(void)
504 {
505 lv_style_reset(&style_common);
506 lv_style_set_radius(&style_common, RADIUS);
507 lv_style_set_border_width(&style_common, BORDER_WIDTH);
508 lv_style_set_border_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
509 lv_style_set_blend_mode(&style_common, LV_BLEND_MODE_SUBTRACTIVE);
510 rect_create(&style_common);
511
512 }
513
sub_shadow_cb(void)514 static void sub_shadow_cb(void)
515 {
516 lv_style_reset(&style_common);
517 lv_style_set_radius(&style_common, RADIUS);
518 lv_style_set_bg_opa(&style_common, LV_OPA_COVER);
519 lv_style_set_shadow_opa(&style_common, opa_mode ? LV_OPA_80 : LV_OPA_COVER);
520 lv_style_set_shadow_width(&style_common, SHADOW_WIDTH_SMALL);
521 lv_style_set_shadow_spread(&style_common, SHADOW_WIDTH_SMALL);
522 lv_style_set_blend_mode(&style_common, LV_BLEND_MODE_SUBTRACTIVE);
523 rect_create(&style_common);
524
525 }
526
sub_img_cb(void)527 static void sub_img_cb(void)
528 {
529 lv_style_reset(&style_common);
530 lv_style_set_img_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
531 lv_style_set_blend_mode(&style_common, LV_BLEND_MODE_SUBTRACTIVE);
532 #if LV_DEMO_BENCHMARK_RGB565A8 && LV_COLOR_DEPTH == 16
533 img_create(&style_common, &img_benchmark_cogwheel_rgb565a8, false, false, false);
534 #else
535 img_create(&style_common, &img_benchmark_cogwheel_argb, false, false, false);
536 #endif
537 }
sub_line_cb(void)538 static void sub_line_cb(void)
539 {
540 lv_style_reset(&style_common);
541 lv_style_set_line_width(&style_common, LINE_WIDTH);
542 lv_style_set_line_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
543 lv_style_set_blend_mode(&style_common, LV_BLEND_MODE_SUBTRACTIVE);
544 line_create(&style_common);
545
546 }
547
sub_arc_cb(void)548 static void sub_arc_cb(void)
549 {
550 lv_style_reset(&style_common);
551 lv_style_set_arc_width(&style_common, ARC_WIDTH_THICK);
552 lv_style_set_arc_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
553 lv_style_set_blend_mode(&style_common, LV_BLEND_MODE_SUBTRACTIVE);
554 arc_create(&style_common);
555 }
556
sub_text_cb(void)557 static void sub_text_cb(void)
558 {
559 lv_style_reset(&style_common);
560 lv_style_set_text_font(&style_common, lv_theme_get_font_normal(NULL));
561 lv_style_set_text_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER);
562 lv_style_set_blend_mode(&style_common, LV_BLEND_MODE_SUBTRACTIVE);
563 txt_create(&style_common);
564 }
565
566
567
568 /**********************
569 * STATIC VARIABLES
570 **********************/
571
572 static scene_dsc_t scenes[] = {
573 {.name = "Rectangle", .weight = 30, .create_cb = rectangle_cb},
574 {.name = "Rectangle rounded", .weight = 20, .create_cb = rectangle_rounded_cb},
575 {.name = "Circle", .weight = 10, .create_cb = rectangle_circle_cb},
576 {.name = "Border", .weight = 20, .create_cb = border_cb},
577 {.name = "Border rounded", .weight = 30, .create_cb = border_rounded_cb},
578 {.name = "Circle border", .weight = 10, .create_cb = border_circle_cb},
579 {.name = "Border top", .weight = 3, .create_cb = border_top_cb},
580 {.name = "Border left", .weight = 3, .create_cb = border_left_cb},
581 {.name = "Border top + left", .weight = 3, .create_cb = border_top_left_cb},
582 {.name = "Border left + right", .weight = 3, .create_cb = border_left_right_cb},
583 {.name = "Border top + bottom", .weight = 3, .create_cb = border_top_bottom_cb},
584
585 {.name = "Shadow small", .weight = 3, .create_cb = shadow_small_cb},
586 {.name = "Shadow small offset", .weight = 5, .create_cb = shadow_small_ofs_cb},
587 {.name = "Shadow large", .weight = 5, .create_cb = shadow_large_cb},
588 {.name = "Shadow large offset", .weight = 3, .create_cb = shadow_large_ofs_cb},
589
590 {.name = "Image RGB", .weight = 20, .create_cb = img_rgb_cb},
591 {.name = "Image ARGB", .weight = 20, .create_cb = img_argb_cb},
592 {.name = "Image chorma keyed", .weight = 5, .create_cb = img_ckey_cb},
593 {.name = "Image indexed", .weight = 5, .create_cb = img_index_cb},
594 {.name = "Image alpha only", .weight = 5, .create_cb = img_alpha_cb},
595
596 {.name = "Image RGB recolor", .weight = 5, .create_cb = img_rgb_recolor_cb},
597 {.name = "Image ARGB recolor", .weight = 20, .create_cb = img_argb_recolor_cb},
598 {.name = "Image chorma keyed recolor", .weight = 3, .create_cb = img_ckey_recolor_cb},
599 {.name = "Image indexed recolor", .weight = 3, .create_cb = img_index_recolor_cb},
600
601 {.name = "Image RGB rotate", .weight = 3, .create_cb = img_rgb_rot_cb},
602 {.name = "Image RGB rotate anti aliased", .weight = 3, .create_cb = img_rgb_rot_aa_cb},
603 {.name = "Image ARGB rotate", .weight = 5, .create_cb = img_argb_rot_cb},
604 {.name = "Image ARGB rotate anti aliased", .weight = 5, .create_cb = img_argb_rot_aa_cb},
605 {.name = "Image RGB zoom", .weight = 3, .create_cb = img_rgb_zoom_cb},
606 {.name = "Image RGB zoom anti aliased", .weight = 3, .create_cb = img_rgb_zoom_aa_cb},
607 {.name = "Image ARGB zoom", .weight = 5, .create_cb = img_argb_zoom_cb},
608 {.name = "Image ARGB zoom anti aliased", .weight = 5, .create_cb = img_argb_zoom_aa_cb},
609
610 {.name = "Text small", .weight = 20, .create_cb = txt_small_cb},
611 {.name = "Text medium", .weight = 30, .create_cb = txt_medium_cb},
612 {.name = "Text large", .weight = 20, .create_cb = txt_large_cb},
613
614 {.name = "Text small compressed", .weight = 3, .create_cb = txt_small_compr_cb},
615 {.name = "Text medium compressed", .weight = 5, .create_cb = txt_medium_compr_cb},
616 {.name = "Text large compressed", .weight = 10, .create_cb = txt_large_compr_cb},
617
618 {.name = "Line", .weight = 10, .create_cb = line_cb},
619
620 {.name = "Arc think", .weight = 10, .create_cb = arc_think_cb},
621 {.name = "Arc thick", .weight = 10, .create_cb = arc_thick_cb},
622
623 {.name = "Substr. rectangle", .weight = 10, .create_cb = sub_rectangle_cb},
624 {.name = "Substr. border", .weight = 10, .create_cb = sub_border_cb},
625 {.name = "Substr. shadow", .weight = 10, .create_cb = sub_shadow_cb},
626 {.name = "Substr. image", .weight = 10, .create_cb = sub_img_cb},
627 {.name = "Substr. line", .weight = 10, .create_cb = sub_line_cb},
628 {.name = "Substr. arc", .weight = 10, .create_cb = sub_arc_cb},
629 {.name = "Substr. text", .weight = 10, .create_cb = sub_text_cb},
630
631 {.name = "", .create_cb = NULL}
632 };
633
634 static int32_t scene_act = -1;
635 static lv_obj_t * scene_bg;
636 static lv_obj_t * title;
637 static lv_obj_t * subtitle;
638 static uint32_t rnd_act;
639 static lv_timer_t * next_scene_timer;
640
641 static const uint32_t rnd_map[] = {
642 0xbd13204f, 0x67d8167f, 0x20211c99, 0xb0a7cc05,
643 0x06d5c703, 0xeafb01a7, 0xd0473b5c, 0xc999aaa2,
644 0x86f9d5d9, 0x294bdb29, 0x12a3c207, 0x78914d14,
645 0x10a30006, 0x6134c7db, 0x194443af, 0x142d1099,
646 0x376292d5, 0x20f433c5, 0x074d2a59, 0x4e74c293,
647 0x072a0810, 0xdd0f136d, 0x5cca6dbc, 0x623bfdd8,
648 0xb645eb2f, 0xbe50894a, 0xc9b56717, 0xe0f912c8,
649 0x4f6b5e24, 0xfe44b128, 0xe12d57a8, 0x9b15c9cc,
650 0xab2ae1d3, 0xb4dc5074, 0x67d457c8, 0x8e46b00c,
651 0xa29a1871, 0xcee40332, 0x80f93aa1, 0x85286096,
652 0x09bd6b49, 0x95072088, 0x2093924b, 0x6a27328f,
653 0xa796079b, 0xc3b488bc, 0xe29bcce0, 0x07048a4c,
654 0x7d81bd99, 0x27aacb30, 0x44fc7a0e, 0xa2382241,
655 0x8357a17d, 0x97e9c9cc, 0xad10ff52, 0x9923fc5c,
656 0x8f2c840a, 0x20356ba2, 0x7997a677, 0x9a7f1800,
657 0x35c7562b, 0xd901fe51, 0x8f4e053d, 0xa5b94923,
658 };
659
660 /**********************
661 * MACROS
662 **********************/
663
664 /**********************
665 * GLOBAL FUNCTIONS
666 **********************/
667
benchmark_init(void)668 static void benchmark_init(void)
669 {
670 lv_disp_t * disp = lv_disp_get_default();
671 disp->driver->monitor_cb = monitor_cb;
672
673 /*Force to run at maximum frame rate*/
674 if(run_max_speed) {
675 if(disp->refr_timer) {
676 disp_ori_timer_period = disp->refr_timer->period;
677 lv_timer_set_period(disp->refr_timer, 1);
678 }
679
680 lv_timer_t * anim_timer = lv_anim_get_timer();
681 anim_ori_timer_period = anim_timer->period;
682 lv_timer_set_period(anim_timer, 1);
683 }
684
685 lv_obj_t * scr = lv_scr_act();
686 lv_obj_remove_style_all(scr);
687 lv_obj_set_style_bg_opa(scr, LV_OPA_COVER, 0);
688
689 title = lv_label_create(scr);
690 lv_obj_set_pos(title, LV_DPI_DEF / 30, LV_DPI_DEF / 30);
691
692 subtitle = lv_label_create(scr);
693 lv_obj_align_to(subtitle, title, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0);
694
695 scene_bg = lv_obj_create(scr);
696 lv_obj_remove_style_all(scene_bg);
697 lv_obj_set_size(scene_bg, lv_obj_get_width(scr), lv_obj_get_height(scr) - subtitle->coords.y2 - LV_DPI_DEF / 30);
698 lv_obj_align(scene_bg, LV_ALIGN_BOTTOM_MID, 0, 0);
699
700 lv_style_init(&style_common);
701
702 lv_obj_update_layout(scr);
703 }
704
705
lv_demo_benchmark(void)706 void lv_demo_benchmark(void)
707 {
708 benchmark_init();
709
710 /*Manually start scenes*/
711 next_scene_timer_cb(NULL);
712 }
713
lv_demo_benchmark_close(void)714 void lv_demo_benchmark_close(void)
715 {
716 if(next_scene_timer) lv_timer_del(next_scene_timer);
717 next_scene_timer = NULL;
718
719 lv_anim_del(NULL, NULL);
720
721 lv_style_reset(&style_common);
722
723 lv_obj_clean(lv_scr_act());
724
725 }
726
lv_demo_benchmark_run_scene(int_fast16_t scene_no)727 void lv_demo_benchmark_run_scene(int_fast16_t scene_no)
728 {
729 benchmark_init();
730
731 if(((scene_no >> 1) >= dimof(scenes))) {
732 /* invalid scene number */
733 return ;
734 }
735
736 opa_mode = scene_no & 0x01;
737 scene_act = scene_no >> 1;
738
739 if(scenes[scene_act].create_cb) {
740 lv_label_set_text_fmt(title, "%"LV_PRId32"/%"LV_PRId32": %s%s", scene_act * 2 + (opa_mode ? 1 : 0),
741 (int32_t)(dimof(scenes) * 2) - 2,
742 scenes[scene_act].name, opa_mode ? " + opa" : "");
743 lv_label_set_text(subtitle, "");
744
745 rnd_reset();
746 scenes[scene_act].create_cb();
747
748 lv_timer_t * t = lv_timer_create(report_cb, SCENE_TIME, NULL);
749 lv_timer_set_repeat_count(t, 1);
750 }
751 }
752
753
lv_demo_benchmark_set_finished_cb(finished_cb_t * finished_cb)754 void lv_demo_benchmark_set_finished_cb(finished_cb_t * finished_cb)
755 {
756 benchmark_finished_cb = finished_cb;
757 }
758
lv_demo_benchmark_set_max_speed(bool en)759 void lv_demo_benchmark_set_max_speed(bool en)
760 {
761 run_max_speed = en;
762 }
763
764 /**********************
765 * STATIC FUNCTIONS
766 **********************/
767
monitor_cb(lv_disp_drv_t * drv,uint32_t time,uint32_t px)768 static void monitor_cb(lv_disp_drv_t * drv, uint32_t time, uint32_t px)
769 {
770 LV_UNUSED(drv);
771 LV_UNUSED(px);
772 if(opa_mode) {
773 scenes[scene_act].refr_cnt_opa ++;
774 scenes[scene_act].time_sum_opa += time;
775 }
776 else {
777 scenes[scene_act].refr_cnt_normal ++;
778 scenes[scene_act].time_sum_normal += time;
779 }
780
781 // lv_obj_invalidate(lv_scr_act());
782 }
783
generate_report(void)784 static void generate_report(void)
785 {
786 uint32_t weight_sum = 0;
787 uint32_t weight_normal_sum = 0;
788 uint32_t weight_opa_sum = 0;
789 uint32_t fps_sum = 0;
790 uint32_t fps_normal_sum = 0;
791 uint32_t fps_opa_sum = 0;
792 uint32_t i;
793 for(i = 0; scenes[i].create_cb; i++) {
794 fps_normal_sum += scenes[i].fps_normal * scenes[i].weight;
795 weight_normal_sum += scenes[i].weight;
796
797 uint32_t w = LV_MAX(scenes[i].weight / 2, 1);
798 fps_opa_sum += scenes[i].fps_opa * w;
799 weight_opa_sum += w;
800 }
801
802
803 fps_sum = fps_normal_sum + fps_opa_sum;
804 weight_sum = weight_normal_sum + weight_opa_sum;
805
806 uint32_t fps_weighted = fps_sum / weight_sum;
807 uint32_t fps_normal_unweighted = fps_normal_sum / weight_normal_sum;
808 uint32_t fps_opa_unweighted = fps_opa_sum / weight_opa_sum;
809
810 uint32_t opa_speed_pct = (fps_opa_unweighted * 100) / fps_normal_unweighted;
811
812 if(NULL != benchmark_finished_cb) {
813 (*benchmark_finished_cb)();
814 }
815
816 lv_obj_clean(lv_scr_act());
817 scene_bg = NULL;
818
819
820 lv_obj_set_flex_flow(lv_scr_act(), LV_FLEX_FLOW_COLUMN);
821
822 title = lv_label_create(lv_scr_act());
823 lv_label_set_text_fmt(title, "Weighted FPS: %"LV_PRIu32, fps_weighted);
824
825 subtitle = lv_label_create(lv_scr_act());
826 lv_label_set_text_fmt(subtitle, "Opa. speed: %"LV_PRIu32"%%", opa_speed_pct);
827
828 lv_coord_t w = lv_obj_get_content_width(lv_scr_act());
829 lv_obj_t * table = lv_table_create(lv_scr_act());
830 // lv_obj_clean_style_list(table, LV_PART_MAIN);
831 lv_table_set_col_cnt(table, 2);
832
833 lv_table_set_col_width(table, 0, (w * 3) / 4 - 3);
834 lv_table_set_col_width(table, 1, w / 4 - 3);
835 lv_obj_set_width(table, lv_pct(100));
836
837 // static lv_style_t style_cell_slow;
838 // static lv_style_t style_cell_very_slow;
839 // static lv_style_t style_cell_title;
840 //
841 // lv_style_init(&style_cell_title);
842 // lv_style_set_bg_color(&style_cell_title, LV_STATE_DEFAULT, lv_palette_main(LV_PALETTE_GREY));
843 // lv_style_set_bg_opa(&style_cell_title, LV_STATE_DEFAULT, LV_OPA_50);
844 //
845 // lv_style_init(&style_cell_slow);
846 // lv_style_set_text_color(&style_cell_slow, LV_STATE_DEFAULT, LV_COLOR_ORANGE);
847 //
848 // lv_style_init(&style_cell_very_slow);
849 // lv_style_set_text_color(&style_cell_very_slow, LV_STATE_DEFAULT, lv_palette_main(LV_PALETTE_RED));
850
851 // lv_obj_add_style(table, LV_TABLE_PART_CELL2, &style_cell_slow);
852 // lv_obj_add_style(table, LV_TABLE_PART_CELL3, &style_cell_very_slow);
853 // lv_obj_add_style(table, LV_TABLE_PART_CELL4, &style_cell_title);
854
855
856 uint16_t row = 0;
857 lv_table_add_cell_ctrl(table, row, 0, LV_TABLE_CELL_CTRL_MERGE_RIGHT);
858 lv_table_set_cell_value(table, row, 0, "Slow but common cases");
859 // lv_table_set_cell_type(table, row, 0, 4);
860
861 LV_LOG("\r\n"
862 "LVGL v%d.%d.%d " LVGL_VERSION_INFO
863 " Benchmark (in csv format)\r\n",
864 LVGL_VERSION_MAJOR, LVGL_VERSION_MINOR, LVGL_VERSION_PATCH);
865 LV_LOG("Weighted FPS: %"LV_PRIu32"\r\n", fps_weighted);
866 LV_LOG("Opa. speed: %"LV_PRIu32"%%\r\n", opa_speed_pct);
867
868 row++;
869 char buf[256];
870 for(i = 0; scenes[i].create_cb; i++) {
871
872 if(scenes[i].fps_normal < 20 && scenes[i].weight >= 10) {
873 lv_table_set_cell_value(table, row, 0, scenes[i].name);
874
875 lv_snprintf(buf, sizeof(buf), "%"LV_PRIu32, scenes[i].fps_normal);
876 lv_table_set_cell_value(table, row, 1, buf);
877
878 // lv_table_set_cell_type(table, row, 0, 2);
879 // lv_table_set_cell_type(table, row, 1, 2);
880
881 //LV_LOG("%s,%s\r\n", scenes[i].name, buf);
882
883 row++;
884 }
885
886 if(scenes[i].fps_opa < 20 && LV_MAX(scenes[i].weight / 2, 1) >= 10) {
887 lv_snprintf(buf, sizeof(buf), "%s + opa", scenes[i].name);
888 lv_table_set_cell_value(table, row, 0, buf);
889
890 //LV_LOG("%s,", buf);
891
892 lv_snprintf(buf, sizeof(buf), "%"LV_PRIu32, scenes[i].fps_opa);
893 lv_table_set_cell_value(table, row, 1, buf);
894
895 // lv_table_set_cell_type(table, row, 0, 2);
896 // lv_table_set_cell_type(table, row, 1, 2);
897 //LV_LOG("%s\r\n", buf);
898
899 row++;
900 }
901 }
902
903 /*No 'slow but common cases'*/
904 if(row == 1) {
905 lv_table_add_cell_ctrl(table, row, 0, LV_TABLE_CELL_CTRL_MERGE_RIGHT);
906 lv_table_set_cell_value(table, row, 0, "All good");
907 row++;
908 }
909
910 lv_table_add_cell_ctrl(table, row, 0, LV_TABLE_CELL_CTRL_MERGE_RIGHT);
911 lv_table_set_cell_value(table, row, 0, "All cases");
912 // lv_table_set_cell_type(table, row, 0, 4);
913 row++;
914
915 for(i = 0; scenes[i].create_cb; i++) {
916 lv_table_set_cell_value(table, row, 0, scenes[i].name);
917
918 lv_snprintf(buf, sizeof(buf), "%"LV_PRIu32, scenes[i].fps_normal);
919 lv_table_set_cell_value(table, row, 1, buf);
920
921 if(scenes[i].fps_normal < 10) {
922 // lv_table_set_cell_type(table, row, 0, 3);
923 // lv_table_set_cell_type(table, row, 1, 3);
924 }
925 else if(scenes[i].fps_normal < 20) {
926 // lv_table_set_cell_type(table, row, 0, 2);
927 // lv_table_set_cell_type(table, row, 1, 2);
928 }
929
930 LV_LOG("%s,%s\r\n", scenes[i].name, buf);
931
932 row++;
933
934 lv_snprintf(buf, sizeof(buf), "%s + opa", scenes[i].name);
935 lv_table_set_cell_value(table, row, 0, buf);
936
937 LV_LOG("%s,", buf);
938
939 lv_snprintf(buf, sizeof(buf), "%"LV_PRIu32, scenes[i].fps_opa);
940 lv_table_set_cell_value(table, row, 1, buf);
941
942
943 if(scenes[i].fps_opa < 10) {
944 // lv_table_set_cell_type(table, row, 0, 3);
945 // lv_table_set_cell_type(table, row, 1, 3);
946 }
947 else if(scenes[i].fps_opa < 20) {
948 // lv_table_set_cell_type(table, row, 0, 2);
949 // lv_table_set_cell_type(table, row, 1, 2);
950 }
951
952 LV_LOG("%s\r\n", buf);
953
954 row++;
955 }
956
957 // lv_page_set_scrl_layout(page, LV_LAYOUT_COLUMN_LEFT);
958 }
959
report_cb(lv_timer_t * timer)960 static void report_cb(lv_timer_t * timer)
961 {
962 if(NULL != benchmark_finished_cb) {
963 (*benchmark_finished_cb)();
964 }
965
966 if(opa_mode) {
967 if(scene_act >= 0) {
968 if(scenes[scene_act].time_sum_opa == 0) scenes[scene_act].time_sum_opa = 1;
969 scenes[scene_act].fps_opa = (1000 * scenes[scene_act].refr_cnt_opa) / scenes[scene_act].time_sum_opa;
970 }
971
972 lv_label_set_text_fmt(subtitle, "Result : %"LV_PRId32" FPS",
973 scenes[scene_act].fps_opa);
974 LV_LOG("Result of \"%s + opa\": %"LV_PRId32" FPS", scenes[scene_act].name,
975 scenes[scene_act].fps_opa);
976 }
977 else {
978 if(scenes[scene_act].time_sum_normal == 0) scenes[scene_act].time_sum_normal = 1;
979 scenes[scene_act].fps_normal = (1000 * scenes[scene_act].refr_cnt_normal) / scenes[scene_act].time_sum_normal;
980
981 lv_label_set_text_fmt(subtitle, "Result : %"LV_PRId32" FPS",
982 scenes[scene_act].fps_normal);
983 LV_LOG("Result of \"%s\": %"LV_PRId32" FPS", scenes[scene_act].name,
984 scenes[scene_act].fps_normal);
985 }
986 }
987
next_scene_timer_cb(lv_timer_t * timer)988 static void next_scene_timer_cb(lv_timer_t * timer)
989 {
990 LV_UNUSED(timer);
991 lv_obj_clean(scene_bg);
992
993 next_scene_timer = NULL;
994
995 if(opa_mode) {
996 if(scene_act >= 0) {
997 if(scenes[scene_act].time_sum_opa == 0) scenes[scene_act].time_sum_opa = 1;
998 scenes[scene_act].fps_opa = (1000 * scenes[scene_act].refr_cnt_opa) / scenes[scene_act].time_sum_opa;
999 if(scenes[scene_act].create_cb) scene_act++; /*If still there are scenes go to the next*/
1000 }
1001 else {
1002 scene_act++;
1003 }
1004 opa_mode = false;
1005 }
1006 else {
1007 if(scenes[scene_act].time_sum_normal == 0) scenes[scene_act].time_sum_normal = 1;
1008 scenes[scene_act].fps_normal = (1000 * scenes[scene_act].refr_cnt_normal) / scenes[scene_act].time_sum_normal;
1009 opa_mode = true;
1010 }
1011
1012 if(scenes[scene_act].create_cb) {
1013 lv_label_set_text_fmt(title, "%"LV_PRId32"/%"LV_PRId32": %s%s", scene_act * 2 + (opa_mode ? 1 : 0),
1014 (int32_t)(dimof(scenes) * 2) - 2, scenes[scene_act].name, opa_mode ? " + opa" : "");
1015 if(opa_mode) {
1016 lv_label_set_text_fmt(subtitle, "Result of \"%s\": %"LV_PRId32" FPS", scenes[scene_act].name,
1017 scenes[scene_act].fps_normal);
1018 }
1019 else {
1020 if(scene_act > 0) {
1021 lv_label_set_text_fmt(subtitle, "Result of \"%s + opa\": %"LV_PRId32" FPS", scenes[scene_act - 1].name,
1022 scenes[scene_act - 1].fps_opa);
1023 }
1024 else {
1025 lv_label_set_text(subtitle, "");
1026 }
1027 }
1028
1029 rnd_reset();
1030 scenes[scene_act].create_cb();
1031 next_scene_timer = lv_timer_create(next_scene_timer_cb, SCENE_TIME, NULL);
1032 lv_timer_set_repeat_count(next_scene_timer, 1);
1033
1034 }
1035 /*Ready*/
1036 else {
1037
1038 /*Restore original frame rate*/
1039 if(run_max_speed) {
1040 lv_timer_t * anim_timer = lv_anim_get_timer();
1041 lv_timer_set_period(anim_timer, anim_ori_timer_period);
1042
1043 lv_disp_t * disp = lv_disp_get_default();
1044 lv_timer_t * refr_timer = _lv_disp_get_refr_timer(disp);
1045 if(refr_timer) {
1046 lv_timer_set_period(refr_timer, disp_ori_timer_period);
1047 }
1048 }
1049
1050 generate_report(); /* generate report */
1051 }
1052 }
1053
1054
rect_create(lv_style_t * style)1055 static void rect_create(lv_style_t * style)
1056 {
1057 uint32_t i;
1058 for(i = 0; i < OBJ_NUM; i++) {
1059 lv_obj_t * obj = lv_obj_create(scene_bg);
1060 lv_obj_remove_style_all(obj);
1061 lv_obj_add_style(obj, style, 0);
1062 lv_obj_set_style_bg_color(obj, lv_color_hex(rnd_next(0, 0xFFFFF0)), 0);
1063 lv_obj_set_style_border_color(obj, lv_color_hex(rnd_next(0, 0xFFFFF0)), 0);
1064 lv_obj_set_style_shadow_color(obj, lv_color_hex(rnd_next(0, 0xFFFFF0)), 0);
1065
1066 lv_obj_set_size(obj, rnd_next(OBJ_SIZE_MIN, OBJ_SIZE_MAX), rnd_next(OBJ_SIZE_MIN, OBJ_SIZE_MAX));
1067
1068 fall_anim(obj);
1069 }
1070 }
1071
1072
img_create(lv_style_t * style,const void * src,bool rotate,bool zoom,bool aa)1073 static void img_create(lv_style_t * style, const void * src, bool rotate, bool zoom, bool aa)
1074 {
1075 uint32_t i;
1076 for(i = 0; i < (uint32_t)IMG_NUM; i++) {
1077 lv_obj_t * obj = lv_img_create(scene_bg);
1078 lv_obj_remove_style_all(obj);
1079 lv_obj_add_style(obj, style, 0);
1080 lv_img_set_src(obj, src);
1081 lv_obj_set_style_img_recolor(obj, lv_color_hex(rnd_next(0, 0xFFFFF0)), 0);
1082
1083 if(rotate) lv_img_set_angle(obj, rnd_next(0, 3599));
1084 if(zoom) lv_img_set_zoom(obj, rnd_next(IMG_ZOOM_MIN, IMG_ZOOM_MAX));
1085 lv_img_set_antialias(obj, aa);
1086
1087 fall_anim(obj);
1088 }
1089 }
1090
1091
txt_create(lv_style_t * style)1092 static void txt_create(lv_style_t * style)
1093 {
1094 uint32_t i;
1095 for(i = 0; i < OBJ_NUM; i++) {
1096 lv_obj_t * obj = lv_label_create(scene_bg);
1097 lv_obj_remove_style_all(obj);
1098 lv_obj_add_style(obj, style, 0);
1099 lv_obj_set_style_text_color(obj, lv_color_hex(rnd_next(0, 0xFFFFF0)), 0);
1100
1101 lv_label_set_text(obj, TXT);
1102
1103 fall_anim(obj);
1104 }
1105 }
1106
1107
line_create(lv_style_t * style)1108 static void line_create(lv_style_t * style)
1109 {
1110 static lv_point_t points[OBJ_NUM][LINE_POINT_NUM];
1111
1112 uint32_t i;
1113 for(i = 0; i < OBJ_NUM; i++) {
1114 points[i][0].x = 0;
1115 points[i][0].y = 0;
1116 uint32_t j;
1117 for(j = 1; j < LINE_POINT_NUM; j++) {
1118 points[i][j].x = points[i][j - 1].x + rnd_next(LINE_POINT_DIFF_MIN, LINE_POINT_DIFF_MAX);
1119 points[i][j].y = rnd_next(LINE_POINT_DIFF_MIN, LINE_POINT_DIFF_MAX);
1120 }
1121
1122
1123 lv_obj_t * obj = lv_line_create(scene_bg);
1124 lv_obj_remove_style_all(obj);
1125 lv_obj_add_style(obj, style, 0);
1126 lv_obj_set_style_line_color(obj, lv_color_hex(rnd_next(0, 0xFFFFF0)), 0);
1127
1128 lv_line_set_points(obj, points[i], LINE_POINT_NUM);
1129
1130 fall_anim(obj);
1131
1132 }
1133 }
1134
1135
arc_anim_end_angle_cb(void * var,int32_t v)1136 static void arc_anim_end_angle_cb(void * var, int32_t v)
1137 {
1138 lv_arc_set_end_angle(var, v);
1139 }
1140
arc_create(lv_style_t * style)1141 static void arc_create(lv_style_t * style)
1142 {
1143 uint32_t i;
1144 for(i = 0; i < OBJ_NUM; i++) {
1145 lv_obj_t * obj = lv_arc_create(scene_bg);
1146 lv_obj_remove_style_all(obj);
1147 lv_obj_set_size(obj, rnd_next(OBJ_SIZE_MIN, OBJ_SIZE_MAX), rnd_next(OBJ_SIZE_MIN, OBJ_SIZE_MAX));
1148 lv_obj_add_style(obj, style, LV_PART_INDICATOR);
1149 lv_obj_set_style_arc_color(obj, lv_color_hex(rnd_next(0, 0xFFFFF0)), LV_PART_INDICATOR);
1150
1151 lv_arc_set_start_angle(obj, 0);
1152
1153 uint32_t t = rnd_next(ANIM_TIME_MIN / 4, ANIM_TIME_MAX / 4);
1154
1155 lv_anim_t a;
1156 lv_anim_init(&a);
1157 lv_anim_set_var(&a, obj);
1158 lv_anim_set_exec_cb(&a, arc_anim_end_angle_cb);
1159 lv_anim_set_values(&a, 0, 359);
1160 lv_anim_set_time(&a, t);
1161 lv_anim_set_playback_time(&a, t);
1162 lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
1163 lv_anim_start(&a);
1164
1165 fall_anim(obj);
1166 }
1167 }
1168
1169
fall_anim_y_cb(void * var,int32_t v)1170 static void fall_anim_y_cb(void * var, int32_t v)
1171 {
1172 lv_obj_set_y(var, v);
1173 }
1174
fall_anim(lv_obj_t * obj)1175 static void fall_anim(lv_obj_t * obj)
1176 {
1177 lv_obj_set_x(obj, rnd_next(0, lv_obj_get_width(scene_bg) - lv_obj_get_width(obj)));
1178
1179 uint32_t t = rnd_next(ANIM_TIME_MIN, ANIM_TIME_MAX);
1180
1181 lv_anim_t a;
1182 lv_anim_init(&a);
1183 lv_anim_set_var(&a, obj);
1184 lv_anim_set_exec_cb(&a, fall_anim_y_cb);
1185 lv_anim_set_values(&a, 0, lv_obj_get_height(scene_bg) - lv_obj_get_height(obj));
1186 lv_anim_set_time(&a, t);
1187 lv_anim_set_playback_time(&a, t);
1188 lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
1189 a.act_time = a.time / 2; /*To start fro mteh middle*/
1190 lv_anim_start(&a);
1191
1192 }
1193
rnd_reset(void)1194 static void rnd_reset(void)
1195 {
1196 rnd_act = 0;
1197 }
1198
rnd_next(int32_t min,int32_t max)1199 static int32_t rnd_next(int32_t min, int32_t max)
1200 {
1201 if(min == max)
1202 return min;
1203
1204 if(min > max) {
1205 int32_t t = min;
1206 min = max;
1207 max = t;
1208 }
1209
1210 int32_t d = max - min;
1211 int32_t r = (rnd_map[rnd_act] % d) + min;
1212
1213 rnd_act++;
1214 if(rnd_act >= RND_NUM) rnd_act = 0;
1215
1216 return r;
1217
1218 }
1219
1220 #endif
1221