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 scene_next_task_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 
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     scene_next_task_cb(NULL);
712 }
713 
714 
lv_demo_benchmark_run_scene(int_fast16_t scene_no)715 void lv_demo_benchmark_run_scene(int_fast16_t scene_no)
716 {
717     benchmark_init();
718 
719     if(((scene_no >> 1) >= dimof(scenes))) {
720         /* invalid scene number */
721         return ;
722     }
723 
724     opa_mode = scene_no & 0x01;
725     scene_act = scene_no >> 1;
726 
727     if(scenes[scene_act].create_cb) {
728         lv_label_set_text_fmt(title, "%"LV_PRId32"/%"LV_PRId32": %s%s", scene_act * 2 + (opa_mode ? 1 : 0),
729                               (int32_t)(dimof(scenes) * 2) - 2,
730                               scenes[scene_act].name, opa_mode ? " + opa" : "");
731         lv_label_set_text(subtitle, "");
732 
733         rnd_reset();
734         scenes[scene_act].create_cb();
735 
736         lv_timer_t * t = lv_timer_create(report_cb, SCENE_TIME, NULL);
737         lv_timer_set_repeat_count(t, 1);
738     }
739 }
740 
741 
lv_demo_benchmark_set_finished_cb(finished_cb_t * finished_cb)742 void lv_demo_benchmark_set_finished_cb(finished_cb_t * finished_cb)
743 {
744     benchmark_finished_cb = finished_cb;
745 }
746 
lv_demo_benchmark_set_max_speed(bool en)747 void lv_demo_benchmark_set_max_speed(bool en)
748 {
749     run_max_speed = en;
750 }
751 
752 /**********************
753  *   STATIC FUNCTIONS
754  **********************/
755 
monitor_cb(lv_disp_drv_t * drv,uint32_t time,uint32_t px)756 static void monitor_cb(lv_disp_drv_t * drv, uint32_t time, uint32_t px)
757 {
758     LV_UNUSED(drv);
759     LV_UNUSED(px);
760     if(opa_mode) {
761         scenes[scene_act].refr_cnt_opa ++;
762         scenes[scene_act].time_sum_opa += time;
763     }
764     else {
765         scenes[scene_act].refr_cnt_normal ++;
766         scenes[scene_act].time_sum_normal += time;
767     }
768 
769     //    lv_obj_invalidate(lv_scr_act());
770 }
771 
generate_report(void)772 static void generate_report(void)
773 {
774     uint32_t weight_sum = 0;
775     uint32_t weight_normal_sum = 0;
776     uint32_t weight_opa_sum = 0;
777     uint32_t fps_sum = 0;
778     uint32_t fps_normal_sum = 0;
779     uint32_t fps_opa_sum = 0;
780     uint32_t i;
781     for(i = 0; scenes[i].create_cb; i++) {
782         fps_normal_sum += scenes[i].fps_normal * scenes[i].weight;
783         weight_normal_sum += scenes[i].weight;
784 
785         uint32_t w = LV_MAX(scenes[i].weight / 2, 1);
786         fps_opa_sum += scenes[i].fps_opa * w;
787         weight_opa_sum += w;
788     }
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 
808     lv_obj_set_flex_flow(lv_scr_act(), LV_FLEX_FLOW_COLUMN);
809 
810     title = lv_label_create(lv_scr_act());
811     lv_label_set_text_fmt(title, "Weighted FPS: %"LV_PRIu32, fps_weighted);
812 
813     subtitle = lv_label_create(lv_scr_act());
814     lv_label_set_text_fmt(subtitle, "Opa. speed: %"LV_PRIu32"%%", opa_speed_pct);
815 
816     lv_coord_t w = lv_obj_get_content_width(lv_scr_act());
817     lv_obj_t * table = lv_table_create(lv_scr_act());
818     //        lv_obj_clean_style_list(table, LV_PART_MAIN);
819     lv_table_set_col_cnt(table, 2);
820 
821     lv_table_set_col_width(table, 0, (w * 3) / 4 - 3);
822     lv_table_set_col_width(table, 1, w  / 4 - 3);
823     lv_obj_set_width(table, lv_pct(100));
824 
825     //        static lv_style_t style_cell_slow;
826     //        static lv_style_t style_cell_very_slow;
827     //        static lv_style_t style_cell_title;
828     //
829     //        lv_style_init(&style_cell_title);
830     //        lv_style_set_bg_color(&style_cell_title, LV_STATE_DEFAULT, lv_palette_main(LV_PALETTE_GREY));
831     //        lv_style_set_bg_opa(&style_cell_title, LV_STATE_DEFAULT, LV_OPA_50);
832     //
833     //        lv_style_init(&style_cell_slow);
834     //        lv_style_set_text_color(&style_cell_slow, LV_STATE_DEFAULT, LV_COLOR_ORANGE);
835     //
836     //        lv_style_init(&style_cell_very_slow);
837     //        lv_style_set_text_color(&style_cell_very_slow, LV_STATE_DEFAULT, lv_palette_main(LV_PALETTE_RED));
838 
839     //        lv_obj_add_style(table, LV_TABLE_PART_CELL2, &style_cell_slow);
840     //        lv_obj_add_style(table, LV_TABLE_PART_CELL3, &style_cell_very_slow);
841     //        lv_obj_add_style(table, LV_TABLE_PART_CELL4, &style_cell_title);
842 
843 
844     uint16_t row = 0;
845     lv_table_add_cell_ctrl(table, row, 0, LV_TABLE_CELL_CTRL_MERGE_RIGHT);
846     lv_table_set_cell_value(table, row, 0, "Slow but common cases");
847     //        lv_table_set_cell_type(table, row, 0, 4);
848 
849     LV_LOG("\r\n"
850            "LVGL v%d.%d.%d " LVGL_VERSION_INFO
851            " Benchmark (in csv format)\r\n",
852            LVGL_VERSION_MAJOR, LVGL_VERSION_MINOR, LVGL_VERSION_PATCH);
853     LV_LOG("Weighted FPS: %"LV_PRIu32"\r\n", fps_weighted);
854     LV_LOG("Opa. speed: %"LV_PRIu32"%%\r\n", opa_speed_pct);
855 
856     row++;
857     char buf[256];
858     for(i = 0; scenes[i].create_cb; i++) {
859 
860         if(scenes[i].fps_normal < 20 && scenes[i].weight >= 10) {
861             lv_table_set_cell_value(table, row, 0, scenes[i].name);
862 
863             lv_snprintf(buf, sizeof(buf), "%"LV_PRIu32, scenes[i].fps_normal);
864             lv_table_set_cell_value(table, row, 1, buf);
865 
866             //                lv_table_set_cell_type(table, row, 0, 2);
867             //                lv_table_set_cell_type(table, row, 1, 2);
868 
869             //LV_LOG("%s,%s\r\n", scenes[i].name, buf);
870 
871             row++;
872         }
873 
874         if(scenes[i].fps_opa < 20 && LV_MAX(scenes[i].weight / 2, 1) >= 10) {
875             lv_snprintf(buf, sizeof(buf), "%s + opa", scenes[i].name);
876             lv_table_set_cell_value(table, row, 0, buf);
877 
878             //LV_LOG("%s,", buf);
879 
880             lv_snprintf(buf, sizeof(buf), "%"LV_PRIu32, scenes[i].fps_opa);
881             lv_table_set_cell_value(table, row, 1, buf);
882 
883             //                lv_table_set_cell_type(table, row, 0, 2);
884             //                lv_table_set_cell_type(table, row, 1, 2);
885             //LV_LOG("%s\r\n", buf);
886 
887             row++;
888         }
889     }
890 
891     /*No 'slow but common cases'*/
892     if(row == 1) {
893         lv_table_add_cell_ctrl(table, row, 0, LV_TABLE_CELL_CTRL_MERGE_RIGHT);
894         lv_table_set_cell_value(table, row, 0, "All good");
895         row++;
896     }
897 
898     lv_table_add_cell_ctrl(table, row, 0, LV_TABLE_CELL_CTRL_MERGE_RIGHT);
899     lv_table_set_cell_value(table, row, 0, "All cases");
900     //        lv_table_set_cell_type(table, row, 0, 4);
901     row++;
902 
903     for(i = 0; scenes[i].create_cb; i++) {
904         lv_table_set_cell_value(table, row, 0, scenes[i].name);
905 
906         lv_snprintf(buf, sizeof(buf), "%"LV_PRIu32, scenes[i].fps_normal);
907         lv_table_set_cell_value(table, row, 1, buf);
908 
909         if(scenes[i].fps_normal < 10) {
910             //                lv_table_set_cell_type(table, row, 0, 3);
911             //                lv_table_set_cell_type(table, row, 1, 3);
912         }
913         else if(scenes[i].fps_normal < 20) {
914             //                lv_table_set_cell_type(table, row, 0, 2);
915             //                lv_table_set_cell_type(table, row, 1, 2);
916         }
917 
918         LV_LOG("%s,%s\r\n", scenes[i].name, buf);
919 
920         row++;
921 
922         lv_snprintf(buf, sizeof(buf), "%s + opa", scenes[i].name);
923         lv_table_set_cell_value(table, row, 0, buf);
924 
925         LV_LOG("%s,", buf);
926 
927         lv_snprintf(buf, sizeof(buf), "%"LV_PRIu32, scenes[i].fps_opa);
928         lv_table_set_cell_value(table, row, 1, buf);
929 
930 
931         if(scenes[i].fps_opa < 10) {
932             //                lv_table_set_cell_type(table, row, 0, 3);
933             //                lv_table_set_cell_type(table, row, 1, 3);
934         }
935         else if(scenes[i].fps_opa < 20) {
936             //                lv_table_set_cell_type(table, row, 0, 2);
937             //                lv_table_set_cell_type(table, row, 1, 2);
938         }
939 
940         LV_LOG("%s\r\n", buf);
941 
942         row++;
943     }
944 
945     //        lv_page_set_scrl_layout(page, LV_LAYOUT_COLUMN_LEFT);
946 }
947 
report_cb(lv_timer_t * timer)948 static void report_cb(lv_timer_t * timer)
949 {
950     if(NULL != benchmark_finished_cb) {
951         (*benchmark_finished_cb)();
952     }
953 
954     if(opa_mode) {
955         if(scene_act >= 0) {
956             if(scenes[scene_act].time_sum_opa == 0) scenes[scene_act].time_sum_opa = 1;
957             scenes[scene_act].fps_opa = (1000 * scenes[scene_act].refr_cnt_opa) / scenes[scene_act].time_sum_opa;
958         }
959 
960         lv_label_set_text_fmt(subtitle, "Result : %"LV_PRId32" FPS",
961                               scenes[scene_act].fps_opa);
962         LV_LOG("Result of \"%s + opa\": %"LV_PRId32" FPS", scenes[scene_act].name,
963                scenes[scene_act].fps_opa);
964     }
965     else {
966         if(scenes[scene_act].time_sum_normal == 0) scenes[scene_act].time_sum_normal = 1;
967         scenes[scene_act].fps_normal = (1000 * scenes[scene_act].refr_cnt_normal) / scenes[scene_act].time_sum_normal;
968 
969         lv_label_set_text_fmt(subtitle, "Result : %"LV_PRId32" FPS",
970                               scenes[scene_act].fps_normal);
971         LV_LOG("Result of \"%s\": %"LV_PRId32" FPS", scenes[scene_act].name,
972                scenes[scene_act].fps_normal);
973     }
974 }
975 
scene_next_task_cb(lv_timer_t * timer)976 static void scene_next_task_cb(lv_timer_t * timer)
977 {
978     LV_UNUSED(timer);
979     lv_obj_clean(scene_bg);
980 
981     if(opa_mode) {
982         if(scene_act >= 0) {
983             if(scenes[scene_act].time_sum_opa == 0) scenes[scene_act].time_sum_opa = 1;
984             scenes[scene_act].fps_opa = (1000 * scenes[scene_act].refr_cnt_opa) / scenes[scene_act].time_sum_opa;
985             if(scenes[scene_act].create_cb) scene_act++;    /*If still there are scenes go to the next*/
986         }
987         else {
988             scene_act++;
989         }
990         opa_mode = false;
991     }
992     else {
993         if(scenes[scene_act].time_sum_normal == 0) scenes[scene_act].time_sum_normal = 1;
994         scenes[scene_act].fps_normal = (1000 * scenes[scene_act].refr_cnt_normal) / scenes[scene_act].time_sum_normal;
995         opa_mode = true;
996     }
997 
998     if(scenes[scene_act].create_cb) {
999         lv_label_set_text_fmt(title, "%"LV_PRId32"/%"LV_PRId32": %s%s", scene_act * 2 + (opa_mode ? 1 : 0),
1000                               (int32_t)(dimof(scenes) * 2) - 2,  scenes[scene_act].name, opa_mode ? " + opa" : "");
1001         if(opa_mode) {
1002             lv_label_set_text_fmt(subtitle, "Result of \"%s\": %"LV_PRId32" FPS", scenes[scene_act].name,
1003                                   scenes[scene_act].fps_normal);
1004         }
1005         else {
1006             if(scene_act > 0) {
1007                 lv_label_set_text_fmt(subtitle, "Result of \"%s + opa\": %"LV_PRId32" FPS", scenes[scene_act - 1].name,
1008                                       scenes[scene_act - 1].fps_opa);
1009             }
1010             else {
1011                 lv_label_set_text(subtitle, "");
1012             }
1013         }
1014 
1015         rnd_reset();
1016         scenes[scene_act].create_cb();
1017         lv_timer_t * t = lv_timer_create(scene_next_task_cb, SCENE_TIME, NULL);
1018         lv_timer_set_repeat_count(t, 1);
1019 
1020     }
1021     /*Ready*/
1022     else {
1023 
1024         /*Restore original frame rate*/
1025         if(run_max_speed) {
1026             lv_timer_t * anim_timer = lv_anim_get_timer();
1027             lv_timer_set_period(anim_timer, anim_ori_timer_period);
1028 
1029             lv_disp_t * disp = lv_disp_get_default();
1030             lv_timer_t * refr_timer = _lv_disp_get_refr_timer(disp);
1031             if(refr_timer) {
1032                 lv_timer_set_period(refr_timer, disp_ori_timer_period);
1033             }
1034         }
1035 
1036         generate_report();      /* generate report */
1037     }
1038 }
1039 
1040 
rect_create(lv_style_t * style)1041 static void rect_create(lv_style_t * style)
1042 {
1043     uint32_t i;
1044     for(i = 0; i < OBJ_NUM; i++) {
1045         lv_obj_t * obj = lv_obj_create(scene_bg);
1046         lv_obj_remove_style_all(obj);
1047         lv_obj_add_style(obj, style, 0);
1048         lv_obj_set_style_bg_color(obj, lv_color_hex(rnd_next(0, 0xFFFFF0)), 0);
1049         lv_obj_set_style_border_color(obj, lv_color_hex(rnd_next(0, 0xFFFFF0)), 0);
1050         lv_obj_set_style_shadow_color(obj, lv_color_hex(rnd_next(0, 0xFFFFF0)), 0);
1051 
1052         lv_obj_set_size(obj, rnd_next(OBJ_SIZE_MIN, OBJ_SIZE_MAX), rnd_next(OBJ_SIZE_MIN, OBJ_SIZE_MAX));
1053 
1054         fall_anim(obj);
1055     }
1056 }
1057 
1058 
img_create(lv_style_t * style,const void * src,bool rotate,bool zoom,bool aa)1059 static void img_create(lv_style_t * style, const void * src, bool rotate, bool zoom, bool aa)
1060 {
1061     uint32_t i;
1062     for(i = 0; i < (uint32_t)IMG_NUM; i++) {
1063         lv_obj_t * obj = lv_img_create(scene_bg);
1064         lv_obj_remove_style_all(obj);
1065         lv_obj_add_style(obj, style, 0);
1066         lv_img_set_src(obj, src);
1067         lv_obj_set_style_img_recolor(obj, lv_color_hex(rnd_next(0, 0xFFFFF0)), 0);
1068 
1069         if(rotate) lv_img_set_angle(obj, rnd_next(0, 3599));
1070         if(zoom) lv_img_set_zoom(obj, rnd_next(IMG_ZOOM_MIN, IMG_ZOOM_MAX));
1071         lv_img_set_antialias(obj, aa);
1072 
1073         fall_anim(obj);
1074     }
1075 }
1076 
1077 
txt_create(lv_style_t * style)1078 static void txt_create(lv_style_t * style)
1079 {
1080     uint32_t i;
1081     for(i = 0; i < OBJ_NUM; i++) {
1082         lv_obj_t * obj = lv_label_create(scene_bg);
1083         lv_obj_remove_style_all(obj);
1084         lv_obj_add_style(obj, style, 0);
1085         lv_obj_set_style_text_color(obj, lv_color_hex(rnd_next(0, 0xFFFFF0)), 0);
1086 
1087         lv_label_set_text(obj, TXT);
1088 
1089         fall_anim(obj);
1090     }
1091 }
1092 
1093 
line_create(lv_style_t * style)1094 static void line_create(lv_style_t * style)
1095 {
1096     static lv_point_t points[OBJ_NUM][LINE_POINT_NUM];
1097 
1098     uint32_t i;
1099     for(i = 0; i < OBJ_NUM; i++) {
1100         points[i][0].x = 0;
1101         points[i][0].y = 0;
1102         uint32_t j;
1103         for(j = 1; j < LINE_POINT_NUM; j++) {
1104             points[i][j].x = points[i][j - 1].x + rnd_next(LINE_POINT_DIFF_MIN, LINE_POINT_DIFF_MAX);
1105             points[i][j].y = rnd_next(LINE_POINT_DIFF_MIN, LINE_POINT_DIFF_MAX);
1106         }
1107 
1108 
1109         lv_obj_t * obj = lv_line_create(scene_bg);
1110         lv_obj_remove_style_all(obj);
1111         lv_obj_add_style(obj, style, 0);
1112         lv_obj_set_style_line_color(obj, lv_color_hex(rnd_next(0, 0xFFFFF0)), 0);
1113 
1114         lv_line_set_points(obj, points[i], LINE_POINT_NUM);
1115 
1116         fall_anim(obj);
1117 
1118     }
1119 }
1120 
1121 
arc_anim_end_angle_cb(void * var,int32_t v)1122 static void arc_anim_end_angle_cb(void * var, int32_t v)
1123 {
1124     lv_arc_set_end_angle(var, v);
1125 }
1126 
arc_create(lv_style_t * style)1127 static void arc_create(lv_style_t * style)
1128 {
1129     uint32_t i;
1130     for(i = 0; i < OBJ_NUM; i++) {
1131         lv_obj_t * obj = lv_arc_create(scene_bg);
1132         lv_obj_remove_style_all(obj);
1133         lv_obj_set_size(obj, rnd_next(OBJ_SIZE_MIN, OBJ_SIZE_MAX), rnd_next(OBJ_SIZE_MIN, OBJ_SIZE_MAX));
1134         lv_obj_add_style(obj, style, LV_PART_INDICATOR);
1135         lv_obj_set_style_arc_color(obj, lv_color_hex(rnd_next(0, 0xFFFFF0)), LV_PART_INDICATOR);
1136 
1137         lv_arc_set_start_angle(obj, 0);
1138 
1139         uint32_t t = rnd_next(ANIM_TIME_MIN / 4, ANIM_TIME_MAX / 4);
1140 
1141         lv_anim_t a;
1142         lv_anim_init(&a);
1143         lv_anim_set_var(&a, obj);
1144         lv_anim_set_exec_cb(&a, arc_anim_end_angle_cb);
1145         lv_anim_set_values(&a, 0, 359);
1146         lv_anim_set_time(&a, t);
1147         lv_anim_set_playback_time(&a, t);
1148         lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
1149         lv_anim_start(&a);
1150 
1151         fall_anim(obj);
1152     }
1153 }
1154 
1155 
fall_anim_y_cb(void * var,int32_t v)1156 static void fall_anim_y_cb(void * var, int32_t v)
1157 {
1158     lv_obj_set_y(var, v);
1159 }
1160 
fall_anim(lv_obj_t * obj)1161 static void fall_anim(lv_obj_t * obj)
1162 {
1163     lv_obj_set_x(obj, rnd_next(0, lv_obj_get_width(scene_bg) - lv_obj_get_width(obj)));
1164 
1165     uint32_t t = rnd_next(ANIM_TIME_MIN, ANIM_TIME_MAX);
1166 
1167     lv_anim_t a;
1168     lv_anim_init(&a);
1169     lv_anim_set_var(&a, obj);
1170     lv_anim_set_exec_cb(&a, fall_anim_y_cb);
1171     lv_anim_set_values(&a, 0, lv_obj_get_height(scene_bg) - lv_obj_get_height(obj));
1172     lv_anim_set_time(&a, t);
1173     lv_anim_set_playback_time(&a, t);
1174     lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
1175     a.act_time = a.time / 2;    /*To start fro mteh middle*/
1176     lv_anim_start(&a);
1177 
1178 }
1179 
rnd_reset(void)1180 static void rnd_reset(void)
1181 {
1182     rnd_act = 0;
1183 }
1184 
rnd_next(int32_t min,int32_t max)1185 static int32_t rnd_next(int32_t min, int32_t max)
1186 {
1187     if(min == max)
1188         return min;
1189 
1190     if(min > max) {
1191         int32_t t = min;
1192         min = max;
1193         max = t;
1194     }
1195 
1196     int32_t d = max - min;
1197     int32_t r = (rnd_map[rnd_act] % d) + min;
1198 
1199     rnd_act++;
1200     if(rnd_act >= RND_NUM) rnd_act = 0;
1201 
1202     return r;
1203 
1204 }
1205 
1206 #endif
1207