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