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