acid-drop- Hacking the planet from a LilyGo T-Deck using custom firmware |
git clone git://git.acid.vegas/acid-drop.git |
Log | Files | Refs | Archive | README | LICENSE |
lv_demo_benchmark.c (42062B)
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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 #if LV_GPU_SDL_CUSTOM_BLEND_MODE 500 lv_style_set_blend_mode(&style_common, LV_BLEND_MODE_SUBTRACTIVE); 501 #else 502 lv_style_set_blend_mode(&style_common, LV_BLEND_MODE_NORMAL); 503 #endif 504 rect_create(&style_common); 505 } 506 507 static void sub_border_cb(void) 508 { 509 lv_style_reset(&style_common); 510 lv_style_set_radius(&style_common, RADIUS); 511 lv_style_set_border_width(&style_common, BORDER_WIDTH); 512 lv_style_set_border_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER); 513 #if LV_GPU_SDL_CUSTOM_BLEND_MODE 514 lv_style_set_blend_mode(&style_common, LV_BLEND_MODE_SUBTRACTIVE); 515 #else 516 lv_style_set_blend_mode(&style_common, LV_BLEND_MODE_NORMAL); 517 #endif 518 rect_create(&style_common); 519 520 } 521 522 static void sub_shadow_cb(void) 523 { 524 lv_style_reset(&style_common); 525 lv_style_set_radius(&style_common, RADIUS); 526 lv_style_set_bg_opa(&style_common, LV_OPA_COVER); 527 lv_style_set_shadow_opa(&style_common, opa_mode ? LV_OPA_80 : LV_OPA_COVER); 528 lv_style_set_shadow_width(&style_common, SHADOW_WIDTH_SMALL); 529 lv_style_set_shadow_spread(&style_common, SHADOW_WIDTH_SMALL); 530 #if LV_GPU_SDL_CUSTOM_BLEND_MODE 531 lv_style_set_blend_mode(&style_common, LV_BLEND_MODE_SUBTRACTIVE); 532 #else 533 lv_style_set_blend_mode(&style_common, LV_BLEND_MODE_NORMAL); 534 #endif 535 rect_create(&style_common); 536 537 } 538 539 static void sub_img_cb(void) 540 { 541 lv_style_reset(&style_common); 542 lv_style_set_img_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER); 543 #if LV_GPU_SDL_CUSTOM_BLEND_MODE 544 lv_style_set_blend_mode(&style_common, LV_BLEND_MODE_SUBTRACTIVE); 545 #else 546 lv_style_set_blend_mode(&style_common, LV_BLEND_MODE_NORMAL); 547 #endif 548 #if LV_DEMO_BENCHMARK_RGB565A8 && LV_COLOR_DEPTH == 16 549 img_create(&style_common, &img_benchmark_cogwheel_rgb565a8, false, false, false); 550 #else 551 img_create(&style_common, &img_benchmark_cogwheel_argb, false, false, false); 552 #endif 553 } 554 static void sub_line_cb(void) 555 { 556 lv_style_reset(&style_common); 557 lv_style_set_line_width(&style_common, LINE_WIDTH); 558 lv_style_set_line_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER); 559 #if LV_GPU_SDL_CUSTOM_BLEND_MODE 560 lv_style_set_blend_mode(&style_common, LV_BLEND_MODE_SUBTRACTIVE); 561 #else 562 lv_style_set_blend_mode(&style_common, LV_BLEND_MODE_NORMAL); 563 #endif 564 line_create(&style_common); 565 566 } 567 568 static void sub_arc_cb(void) 569 { 570 lv_style_reset(&style_common); 571 lv_style_set_arc_width(&style_common, ARC_WIDTH_THICK); 572 lv_style_set_arc_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER); 573 #if LV_GPU_SDL_CUSTOM_BLEND_MODE 574 lv_style_set_blend_mode(&style_common, LV_BLEND_MODE_SUBTRACTIVE); 575 #else 576 lv_style_set_blend_mode(&style_common, LV_BLEND_MODE_NORMAL); 577 #endif 578 arc_create(&style_common); 579 } 580 581 static void sub_text_cb(void) 582 { 583 lv_style_reset(&style_common); 584 lv_style_set_text_font(&style_common, lv_theme_get_font_normal(NULL)); 585 lv_style_set_text_opa(&style_common, opa_mode ? LV_OPA_50 : LV_OPA_COVER); 586 #if LV_GPU_SDL_CUSTOM_BLEND_MODE 587 lv_style_set_blend_mode(&style_common, LV_BLEND_MODE_SUBTRACTIVE); 588 #else 589 lv_style_set_blend_mode(&style_common, LV_BLEND_MODE_NORMAL); 590 #endif 591 txt_create(&style_common); 592 } 593 594 595 596 /********************** 597 * STATIC VARIABLES 598 **********************/ 599 600 static scene_dsc_t scenes[] = { 601 {.name = "Rectangle", .weight = 30, .create_cb = rectangle_cb}, 602 {.name = "Rectangle rounded", .weight = 20, .create_cb = rectangle_rounded_cb}, 603 {.name = "Circle", .weight = 10, .create_cb = rectangle_circle_cb}, 604 {.name = "Border", .weight = 20, .create_cb = border_cb}, 605 {.name = "Border rounded", .weight = 30, .create_cb = border_rounded_cb}, 606 {.name = "Circle border", .weight = 10, .create_cb = border_circle_cb}, 607 {.name = "Border top", .weight = 3, .create_cb = border_top_cb}, 608 {.name = "Border left", .weight = 3, .create_cb = border_left_cb}, 609 {.name = "Border top + left", .weight = 3, .create_cb = border_top_left_cb}, 610 {.name = "Border left + right", .weight = 3, .create_cb = border_left_right_cb}, 611 {.name = "Border top + bottom", .weight = 3, .create_cb = border_top_bottom_cb}, 612 613 {.name = "Shadow small", .weight = 3, .create_cb = shadow_small_cb}, 614 {.name = "Shadow small offset", .weight = 5, .create_cb = shadow_small_ofs_cb}, 615 {.name = "Shadow large", .weight = 5, .create_cb = shadow_large_cb}, 616 {.name = "Shadow large offset", .weight = 3, .create_cb = shadow_large_ofs_cb}, 617 618 {.name = "Image RGB", .weight = 20, .create_cb = img_rgb_cb}, 619 {.name = "Image ARGB", .weight = 20, .create_cb = img_argb_cb}, 620 {.name = "Image chorma keyed", .weight = 5, .create_cb = img_ckey_cb}, 621 {.name = "Image indexed", .weight = 5, .create_cb = img_index_cb}, 622 {.name = "Image alpha only", .weight = 5, .create_cb = img_alpha_cb}, 623 624 {.name = "Image RGB recolor", .weight = 5, .create_cb = img_rgb_recolor_cb}, 625 {.name = "Image ARGB recolor", .weight = 20, .create_cb = img_argb_recolor_cb}, 626 {.name = "Image chorma keyed recolor", .weight = 3, .create_cb = img_ckey_recolor_cb}, 627 {.name = "Image indexed recolor", .weight = 3, .create_cb = img_index_recolor_cb}, 628 629 {.name = "Image RGB rotate", .weight = 3, .create_cb = img_rgb_rot_cb}, 630 {.name = "Image RGB rotate anti aliased", .weight = 3, .create_cb = img_rgb_rot_aa_cb}, 631 {.name = "Image ARGB rotate", .weight = 5, .create_cb = img_argb_rot_cb}, 632 {.name = "Image ARGB rotate anti aliased", .weight = 5, .create_cb = img_argb_rot_aa_cb}, 633 {.name = "Image RGB zoom", .weight = 3, .create_cb = img_rgb_zoom_cb}, 634 {.name = "Image RGB zoom anti aliased", .weight = 3, .create_cb = img_rgb_zoom_aa_cb}, 635 {.name = "Image ARGB zoom", .weight = 5, .create_cb = img_argb_zoom_cb}, 636 {.name = "Image ARGB zoom anti aliased", .weight = 5, .create_cb = img_argb_zoom_aa_cb}, 637 638 {.name = "Text small", .weight = 20, .create_cb = txt_small_cb}, 639 {.name = "Text medium", .weight = 30, .create_cb = txt_medium_cb}, 640 {.name = "Text large", .weight = 20, .create_cb = txt_large_cb}, 641 642 {.name = "Text small compressed", .weight = 3, .create_cb = txt_small_compr_cb}, 643 {.name = "Text medium compressed", .weight = 5, .create_cb = txt_medium_compr_cb}, 644 {.name = "Text large compressed", .weight = 10, .create_cb = txt_large_compr_cb}, 645 646 {.name = "Line", .weight = 10, .create_cb = line_cb}, 647 648 {.name = "Arc think", .weight = 10, .create_cb = arc_think_cb}, 649 {.name = "Arc thick", .weight = 10, .create_cb = arc_thick_cb}, 650 651 {.name = "Substr. rectangle", .weight = 10, .create_cb = sub_rectangle_cb}, 652 {.name = "Substr. border", .weight = 10, .create_cb = sub_border_cb}, 653 {.name = "Substr. shadow", .weight = 10, .create_cb = sub_shadow_cb}, 654 {.name = "Substr. image", .weight = 10, .create_cb = sub_img_cb}, 655 {.name = "Substr. line", .weight = 10, .create_cb = sub_line_cb}, 656 {.name = "Substr. arc", .weight = 10, .create_cb = sub_arc_cb}, 657 {.name = "Substr. text", .weight = 10, .create_cb = sub_text_cb}, 658 659 {.name = "", .create_cb = NULL} 660 }; 661 662 static int32_t scene_act = -1; 663 static lv_obj_t * scene_bg; 664 static lv_obj_t * title; 665 static lv_obj_t * subtitle; 666 static uint32_t rnd_act; 667 668 669 static const uint32_t rnd_map[] = { 670 0xbd13204f, 0x67d8167f, 0x20211c99, 0xb0a7cc05, 671 0x06d5c703, 0xeafb01a7, 0xd0473b5c, 0xc999aaa2, 672 0x86f9d5d9, 0x294bdb29, 0x12a3c207, 0x78914d14, 673 0x10a30006, 0x6134c7db, 0x194443af, 0x142d1099, 674 0x376292d5, 0x20f433c5, 0x074d2a59, 0x4e74c293, 675 0x072a0810, 0xdd0f136d, 0x5cca6dbc, 0x623bfdd8, 676 0xb645eb2f, 0xbe50894a, 0xc9b56717, 0xe0f912c8, 677 0x4f6b5e24, 0xfe44b128, 0xe12d57a8, 0x9b15c9cc, 678 0xab2ae1d3, 0xb4dc5074, 0x67d457c8, 0x8e46b00c, 679 0xa29a1871, 0xcee40332, 0x80f93aa1, 0x85286096, 680 0x09bd6b49, 0x95072088, 0x2093924b, 0x6a27328f, 681 0xa796079b, 0xc3b488bc, 0xe29bcce0, 0x07048a4c, 682 0x7d81bd99, 0x27aacb30, 0x44fc7a0e, 0xa2382241, 683 0x8357a17d, 0x97e9c9cc, 0xad10ff52, 0x9923fc5c, 684 0x8f2c840a, 0x20356ba2, 0x7997a677, 0x9a7f1800, 685 0x35c7562b, 0xd901fe51, 0x8f4e053d, 0xa5b94923, 686 }; 687 688 /********************** 689 * MACROS 690 **********************/ 691 692 /********************** 693 * GLOBAL FUNCTIONS 694 **********************/ 695 696 static void benchmark_init(void) 697 { 698 lv_disp_t * disp = lv_disp_get_default(); 699 disp->driver->monitor_cb = monitor_cb; 700 701 /*Force to run at maximum frame rate*/ 702 if(run_max_speed) { 703 if(disp->refr_timer) { 704 disp_ori_timer_period = disp->refr_timer->period; 705 lv_timer_set_period(disp->refr_timer, 1); 706 } 707 708 lv_timer_t * anim_timer = lv_anim_get_timer(); 709 anim_ori_timer_period = anim_timer->period; 710 lv_timer_set_period(anim_timer, 1); 711 } 712 713 lv_obj_t * scr = lv_scr_act(); 714 lv_obj_remove_style_all(scr); 715 lv_obj_set_style_bg_opa(scr, LV_OPA_COVER, 0); 716 717 title = lv_label_create(scr); 718 lv_obj_set_pos(title, LV_DPI_DEF / 30, LV_DPI_DEF / 30); 719 720 subtitle = lv_label_create(scr); 721 lv_obj_align_to(subtitle, title, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0); 722 723 scene_bg = lv_obj_create(scr); 724 lv_obj_remove_style_all(scene_bg); 725 lv_obj_set_size(scene_bg, lv_obj_get_width(scr), lv_obj_get_height(scr) - subtitle->coords.y2 - LV_DPI_DEF / 30); 726 lv_obj_align(scene_bg, LV_ALIGN_BOTTOM_MID, 0, 0); 727 728 lv_style_init(&style_common); 729 730 lv_obj_update_layout(scr); 731 } 732 733 734 void lv_demo_benchmark(void) 735 { 736 benchmark_init(); 737 738 /*Manually start scenes*/ 739 scene_next_task_cb(NULL); 740 } 741 742 743 void lv_demo_benchmark_run_scene(int_fast16_t scene_no) 744 { 745 benchmark_init(); 746 747 if(((scene_no >> 1) >= dimof(scenes))) { 748 /* invalid scene number */ 749 return ; 750 } 751 752 opa_mode = scene_no & 0x01; 753 scene_act = scene_no >> 1; 754 755 if(scenes[scene_act].create_cb) { 756 lv_label_set_text_fmt(title, "%"LV_PRId32"/%d: %s%s", scene_act * 2 + (opa_mode ? 1 : 0), (int)(dimof(scenes) * 2) - 2, 757 scenes[scene_act].name, opa_mode ? " + opa" : ""); 758 lv_label_set_text(subtitle, ""); 759 760 rnd_reset(); 761 scenes[scene_act].create_cb(); 762 763 lv_timer_t * t = lv_timer_create(report_cb, SCENE_TIME, NULL); 764 lv_timer_set_repeat_count(t, 1); 765 } 766 } 767 768 769 void lv_demo_benchmark_set_finished_cb(finished_cb_t * finished_cb) 770 { 771 benchmark_finished_cb = finished_cb; 772 } 773 774 void lv_demo_benchmark_set_max_speed(bool en) 775 { 776 run_max_speed = en; 777 } 778 779 /********************** 780 * STATIC FUNCTIONS 781 **********************/ 782 783 static void monitor_cb(lv_disp_drv_t * drv, uint32_t time, uint32_t px) 784 { 785 LV_UNUSED(drv); 786 LV_UNUSED(px); 787 if(opa_mode) { 788 scenes[scene_act].refr_cnt_opa ++; 789 scenes[scene_act].time_sum_opa += time; 790 } 791 else { 792 scenes[scene_act].refr_cnt_normal ++; 793 scenes[scene_act].time_sum_normal += time; 794 } 795 796 // lv_obj_invalidate(lv_scr_act()); 797 } 798 799 static void generate_report(void) 800 { 801 uint32_t weight_sum = 0; 802 uint32_t weight_normal_sum = 0; 803 uint32_t weight_opa_sum = 0; 804 uint32_t fps_sum = 0; 805 uint32_t fps_normal_sum = 0; 806 uint32_t fps_opa_sum = 0; 807 uint32_t i; 808 for(i = 0; scenes[i].create_cb; i++) { 809 fps_normal_sum += scenes[i].fps_normal * scenes[i].weight; 810 weight_normal_sum += scenes[i].weight; 811 812 uint32_t w = LV_MAX(scenes[i].weight / 2, 1); 813 fps_opa_sum += scenes[i].fps_opa * w; 814 weight_opa_sum += w; 815 } 816 817 818 fps_sum = fps_normal_sum + fps_opa_sum; 819 weight_sum = weight_normal_sum + weight_opa_sum; 820 821 uint32_t fps_weighted = fps_sum / weight_sum; 822 uint32_t fps_normal_unweighted = fps_normal_sum / weight_normal_sum; 823 uint32_t fps_opa_unweighted = fps_opa_sum / weight_opa_sum; 824 825 uint32_t opa_speed_pct = (fps_opa_unweighted * 100) / fps_normal_unweighted; 826 827 if(NULL != benchmark_finished_cb) { 828 (*benchmark_finished_cb)(); 829 } 830 831 lv_obj_clean(lv_scr_act()); 832 scene_bg = NULL; 833 834 835 lv_obj_set_flex_flow(lv_scr_act(), LV_FLEX_FLOW_COLUMN); 836 837 title = lv_label_create(lv_scr_act()); 838 lv_label_set_text_fmt(title, "Arduino_GFX screen size: %"LV_PRIu32" x %"LV_PRIu32, LV_HOR_RES, LV_VER_RES); 839 840 subtitle = lv_label_create(lv_scr_act()); 841 lv_label_set_text_fmt(subtitle, "LVGL weighted FPS: %"LV_PRIu32", Opa. speed: %"LV_PRIu32"%%", fps_weighted, opa_speed_pct); 842 843 lv_coord_t w = lv_obj_get_content_width(lv_scr_act()); 844 lv_obj_t * table = lv_table_create(lv_scr_act()); 845 // lv_obj_clean_style_list(table, LV_PART_MAIN); 846 lv_table_set_col_cnt(table, 2); 847 848 lv_table_set_col_width(table, 0, (w * 3) / 4 - 3); 849 lv_table_set_col_width(table, 1, w / 4 - 3); 850 lv_obj_set_width(table, lv_pct(100)); 851 852 // static lv_style_t style_cell_slow; 853 // static lv_style_t style_cell_very_slow; 854 // static lv_style_t style_cell_title; 855 // 856 // lv_style_init(&style_cell_title); 857 // lv_style_set_bg_color(&style_cell_title, LV_STATE_DEFAULT, lv_palette_main(LV_PALETTE_GREY)); 858 // lv_style_set_bg_opa(&style_cell_title, LV_STATE_DEFAULT, LV_OPA_50); 859 // 860 // lv_style_init(&style_cell_slow); 861 // lv_style_set_text_color(&style_cell_slow, LV_STATE_DEFAULT, LV_COLOR_ORANGE); 862 // 863 // lv_style_init(&style_cell_very_slow); 864 // lv_style_set_text_color(&style_cell_very_slow, LV_STATE_DEFAULT, lv_palette_main(LV_PALETTE_RED)); 865 866 // lv_obj_add_style(table, LV_TABLE_PART_CELL2, &style_cell_slow); 867 // lv_obj_add_style(table, LV_TABLE_PART_CELL3, &style_cell_very_slow); 868 // lv_obj_add_style(table, LV_TABLE_PART_CELL4, &style_cell_title); 869 870 871 uint16_t row = 0; 872 lv_table_add_cell_ctrl(table, row, 0, LV_TABLE_CELL_CTRL_MERGE_RIGHT); 873 lv_table_set_cell_value(table, row, 0, "Slow but common cases"); 874 // lv_table_set_cell_type(table, row, 0, 4); 875 876 LV_LOG("\r\n" 877 "LVGL v%d.%d.%d " LVGL_VERSION_INFO 878 " Benchmark (in csv format)\r\n", 879 LVGL_VERSION_MAJOR, LVGL_VERSION_MINOR, LVGL_VERSION_PATCH); 880 LV_LOG("Weighted FPS: %"LV_PRIu32"\r\n", fps_weighted); 881 LV_LOG("Opa. speed: %"LV_PRIu32"%%\r\n", opa_speed_pct); 882 883 row++; 884 char buf[256]; 885 for(i = 0; scenes[i].create_cb; i++) { 886 887 if(scenes[i].fps_normal < 20 && scenes[i].weight >= 10) { 888 lv_table_set_cell_value(table, row, 0, scenes[i].name); 889 890 lv_snprintf(buf, sizeof(buf), "%"LV_PRIu32, scenes[i].fps_normal); 891 lv_table_set_cell_value(table, row, 1, buf); 892 893 // lv_table_set_cell_type(table, row, 0, 2); 894 // lv_table_set_cell_type(table, row, 1, 2); 895 896 //LV_LOG("%s,%s\r\n", scenes[i].name, buf); 897 898 row++; 899 } 900 901 if(scenes[i].fps_opa < 20 && LV_MAX(scenes[i].weight / 2, 1) >= 10) { 902 lv_snprintf(buf, sizeof(buf), "%s + opa", scenes[i].name); 903 lv_table_set_cell_value(table, row, 0, buf); 904 905 //LV_LOG("%s,", buf); 906 907 lv_snprintf(buf, sizeof(buf), "%"LV_PRIu32, scenes[i].fps_opa); 908 lv_table_set_cell_value(table, row, 1, buf); 909 910 // lv_table_set_cell_type(table, row, 0, 2); 911 // lv_table_set_cell_type(table, row, 1, 2); 912 //LV_LOG("%s\r\n", buf); 913 914 row++; 915 } 916 } 917 918 /*No 'slow but common cases'*/ 919 if(row == 1) { 920 lv_table_add_cell_ctrl(table, row, 0, LV_TABLE_CELL_CTRL_MERGE_RIGHT); 921 lv_table_set_cell_value(table, row, 0, "All good"); 922 row++; 923 } 924 925 lv_table_add_cell_ctrl(table, row, 0, LV_TABLE_CELL_CTRL_MERGE_RIGHT); 926 lv_table_set_cell_value(table, row, 0, "All cases"); 927 // lv_table_set_cell_type(table, row, 0, 4); 928 row++; 929 930 for(i = 0; scenes[i].create_cb; i++) { 931 lv_table_set_cell_value(table, row, 0, scenes[i].name); 932 933 lv_snprintf(buf, sizeof(buf), "%"LV_PRIu32, scenes[i].fps_normal); 934 lv_table_set_cell_value(table, row, 1, buf); 935 936 if(scenes[i].fps_normal < 10) { 937 // lv_table_set_cell_type(table, row, 0, 3); 938 // lv_table_set_cell_type(table, row, 1, 3); 939 } 940 else if(scenes[i].fps_normal < 20) { 941 // lv_table_set_cell_type(table, row, 0, 2); 942 // lv_table_set_cell_type(table, row, 1, 2); 943 } 944 945 LV_LOG("%s,%s\r\n", scenes[i].name, buf); 946 947 row++; 948 949 lv_snprintf(buf, sizeof(buf), "%s + opa", scenes[i].name); 950 lv_table_set_cell_value(table, row, 0, buf); 951 952 LV_LOG("%s,", buf); 953 954 lv_snprintf(buf, sizeof(buf), "%"LV_PRIu32, scenes[i].fps_opa); 955 lv_table_set_cell_value(table, row, 1, buf); 956 957 958 if(scenes[i].fps_opa < 10) { 959 // lv_table_set_cell_type(table, row, 0, 3); 960 // lv_table_set_cell_type(table, row, 1, 3); 961 } 962 else if(scenes[i].fps_opa < 20) { 963 // lv_table_set_cell_type(table, row, 0, 2); 964 // lv_table_set_cell_type(table, row, 1, 2); 965 } 966 967 LV_LOG("%s\r\n", buf); 968 969 row++; 970 } 971 972 // lv_page_set_scrl_layout(page, LV_LAYOUT_COLUMN_LEFT); 973 } 974 975 static void report_cb(lv_timer_t * timer) 976 { 977 if(NULL != benchmark_finished_cb) { 978 (*benchmark_finished_cb)(); 979 } 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 } 986 987 lv_label_set_text_fmt(subtitle, "Result : %"LV_PRId32" FPS", 988 scenes[scene_act].fps_opa); 989 LV_LOG("Result of \"%s + opa\": %"LV_PRId32" FPS", scenes[scene_act].name, 990 scenes[scene_act].fps_opa); 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 996 lv_label_set_text_fmt(subtitle, "Result : %"LV_PRId32" FPS", 997 scenes[scene_act].fps_normal); 998 LV_LOG("Result of \"%s\": %"LV_PRId32" FPS", scenes[scene_act].name, 999 scenes[scene_act].fps_normal); 1000 } 1001 } 1002 1003 static void scene_next_task_cb(lv_timer_t * timer) 1004 { 1005 LV_UNUSED(timer); 1006 lv_obj_clean(scene_bg); 1007 1008 if(opa_mode) { 1009 if(scene_act >= 0) { 1010 if(scenes[scene_act].time_sum_opa == 0) scenes[scene_act].time_sum_opa = 1; 1011 scenes[scene_act].fps_opa = (1000 * scenes[scene_act].refr_cnt_opa) / scenes[scene_act].time_sum_opa; 1012 if(scenes[scene_act].create_cb) scene_act++; /*If still there are scenes go to the next*/ 1013 } 1014 else { 1015 scene_act++; 1016 } 1017 opa_mode = false; 1018 } 1019 else { 1020 if(scenes[scene_act].time_sum_normal == 0) scenes[scene_act].time_sum_normal = 1; 1021 scenes[scene_act].fps_normal = (1000 * scenes[scene_act].refr_cnt_normal) / scenes[scene_act].time_sum_normal; 1022 opa_mode = true; 1023 } 1024 1025 if(scenes[scene_act].create_cb) { 1026 lv_label_set_text_fmt(title, "%"LV_PRId32"/%d: %s%s", scene_act * 2 + (opa_mode ? 1 : 0), 1027 (int)(dimof(scenes) * 2) - 2, scenes[scene_act].name, opa_mode ? " + opa" : ""); 1028 if(opa_mode) { 1029 lv_label_set_text_fmt(subtitle, "Result of \"%s\": %"LV_PRId32" FPS", scenes[scene_act].name, 1030 scenes[scene_act].fps_normal); 1031 } 1032 else { 1033 if(scene_act > 0) { 1034 lv_label_set_text_fmt(subtitle, "Result of \"%s + opa\": %"LV_PRId32" FPS", scenes[scene_act - 1].name, 1035 scenes[scene_act - 1].fps_opa); 1036 } 1037 else { 1038 lv_label_set_text(subtitle, ""); 1039 } 1040 } 1041 1042 rnd_reset(); 1043 scenes[scene_act].create_cb(); 1044 lv_timer_t * t = lv_timer_create(scene_next_task_cb, SCENE_TIME, NULL); 1045 lv_timer_set_repeat_count(t, 1); 1046 1047 } 1048 /*Ready*/ 1049 else { 1050 1051 /*Restore original frame rate*/ 1052 if(run_max_speed) { 1053 lv_timer_t * anim_timer = lv_anim_get_timer(); 1054 lv_timer_set_period(anim_timer, anim_ori_timer_period); 1055 1056 lv_disp_t * disp = lv_disp_get_default(); 1057 lv_timer_t * refr_timer = _lv_disp_get_refr_timer(disp); 1058 if(refr_timer) { 1059 lv_timer_set_period(refr_timer, disp_ori_timer_period); 1060 } 1061 } 1062 1063 generate_report(); /* generate report */ 1064 } 1065 } 1066 1067 1068 static void rect_create(lv_style_t * style) 1069 { 1070 uint32_t i; 1071 for(i = 0; i < OBJ_NUM; i++) { 1072 lv_obj_t * obj = lv_obj_create(scene_bg); 1073 lv_obj_remove_style_all(obj); 1074 lv_obj_add_style(obj, style, 0); 1075 lv_obj_set_style_bg_color(obj, lv_color_hex(rnd_next(0, 0xFFFFF0)), 0); 1076 lv_obj_set_style_border_color(obj, lv_color_hex(rnd_next(0, 0xFFFFF0)), 0); 1077 lv_obj_set_style_shadow_color(obj, lv_color_hex(rnd_next(0, 0xFFFFF0)), 0); 1078 1079 lv_obj_set_size(obj, rnd_next(OBJ_SIZE_MIN, OBJ_SIZE_MAX), rnd_next(OBJ_SIZE_MIN, OBJ_SIZE_MAX)); 1080 1081 fall_anim(obj); 1082 } 1083 } 1084 1085 1086 static void img_create(lv_style_t * style, const void * src, bool rotate, bool zoom, bool aa) 1087 { 1088 uint32_t i; 1089 for(i = 0; i < (uint32_t)IMG_NUM; i++) { 1090 lv_obj_t * obj = lv_img_create(scene_bg); 1091 lv_obj_remove_style_all(obj); 1092 lv_obj_add_style(obj, style, 0); 1093 lv_img_set_src(obj, src); 1094 lv_obj_set_style_img_recolor(obj, lv_color_hex(rnd_next(0, 0xFFFFF0)), 0); 1095 1096 if(rotate) lv_img_set_angle(obj, rnd_next(0, 3599)); 1097 if(zoom) lv_img_set_zoom(obj, rnd_next(IMG_ZOOM_MIN, IMG_ZOOM_MAX)); 1098 lv_img_set_antialias(obj, aa); 1099 1100 fall_anim(obj); 1101 } 1102 } 1103 1104 1105 static void txt_create(lv_style_t * style) 1106 { 1107 uint32_t i; 1108 for(i = 0; i < OBJ_NUM; i++) { 1109 lv_obj_t * obj = lv_label_create(scene_bg); 1110 lv_obj_remove_style_all(obj); 1111 lv_obj_add_style(obj, style, 0); 1112 lv_obj_set_style_text_color(obj, lv_color_hex(rnd_next(0, 0xFFFFF0)), 0); 1113 1114 lv_label_set_text(obj, TXT); 1115 1116 fall_anim(obj); 1117 } 1118 } 1119 1120 1121 static void line_create(lv_style_t * style) 1122 { 1123 static lv_point_t points[OBJ_NUM][LINE_POINT_NUM]; 1124 1125 uint32_t i; 1126 for(i = 0; i < OBJ_NUM; i++) { 1127 points[i][0].x = 0; 1128 points[i][0].y = 0; 1129 uint32_t j; 1130 for(j = 1; j < LINE_POINT_NUM; j++) { 1131 points[i][j].x = points[i][j - 1].x + rnd_next(LINE_POINT_DIFF_MIN, LINE_POINT_DIFF_MAX); 1132 points[i][j].y = rnd_next(LINE_POINT_DIFF_MIN, LINE_POINT_DIFF_MAX); 1133 } 1134 1135 1136 lv_obj_t * obj = lv_line_create(scene_bg); 1137 lv_obj_remove_style_all(obj); 1138 lv_obj_add_style(obj, style, 0); 1139 lv_obj_set_style_line_color(obj, lv_color_hex(rnd_next(0, 0xFFFFF0)), 0); 1140 1141 lv_line_set_points(obj, points[i], LINE_POINT_NUM); 1142 1143 fall_anim(obj); 1144 1145 } 1146 } 1147 1148 1149 static void arc_anim_end_angle_cb(void * var, int32_t v) 1150 { 1151 lv_arc_set_end_angle(var, v); 1152 } 1153 1154 static void arc_create(lv_style_t * style) 1155 { 1156 uint32_t i; 1157 for(i = 0; i < OBJ_NUM; i++) { 1158 lv_obj_t * obj = lv_arc_create(scene_bg); 1159 lv_obj_remove_style_all(obj); 1160 lv_obj_set_size(obj, rnd_next(OBJ_SIZE_MIN, OBJ_SIZE_MAX), rnd_next(OBJ_SIZE_MIN, OBJ_SIZE_MAX)); 1161 lv_obj_add_style(obj, style, LV_PART_INDICATOR); 1162 lv_obj_set_style_arc_color(obj, lv_color_hex(rnd_next(0, 0xFFFFF0)), LV_PART_INDICATOR); 1163 1164 lv_arc_set_start_angle(obj, 0); 1165 1166 uint32_t t = rnd_next(ANIM_TIME_MIN / 4, ANIM_TIME_MAX / 4); 1167 1168 lv_anim_t a; 1169 lv_anim_init(&a); 1170 lv_anim_set_var(&a, obj); 1171 lv_anim_set_exec_cb(&a, arc_anim_end_angle_cb); 1172 lv_anim_set_values(&a, 0, 359); 1173 lv_anim_set_time(&a, t); 1174 lv_anim_set_playback_time(&a, t); 1175 lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE); 1176 lv_anim_start(&a); 1177 1178 fall_anim(obj); 1179 } 1180 } 1181 1182 1183 static void fall_anim_y_cb(void * var, int32_t v) 1184 { 1185 lv_obj_set_y(var, v); 1186 } 1187 1188 static void fall_anim(lv_obj_t * obj) 1189 { 1190 lv_obj_set_x(obj, rnd_next(0, lv_obj_get_width(scene_bg) - lv_obj_get_width(obj))); 1191 1192 uint32_t t = rnd_next(ANIM_TIME_MIN, ANIM_TIME_MAX); 1193 1194 lv_anim_t a; 1195 lv_anim_init(&a); 1196 lv_anim_set_var(&a, obj); 1197 lv_anim_set_exec_cb(&a, fall_anim_y_cb); 1198 lv_anim_set_values(&a, 0, lv_obj_get_height(scene_bg) - lv_obj_get_height(obj)); 1199 lv_anim_set_time(&a, t); 1200 lv_anim_set_playback_time(&a, t); 1201 lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE); 1202 a.act_time = a.time / 2; /*To start fro mteh middle*/ 1203 lv_anim_start(&a); 1204 1205 } 1206 1207 static void rnd_reset(void) 1208 { 1209 rnd_act = 0; 1210 } 1211 1212 static int32_t rnd_next(int32_t min, int32_t max) 1213 { 1214 if(min == max) 1215 return min; 1216 1217 if(min > max) { 1218 int32_t t = min; 1219 min = max; 1220 max = t; 1221 } 1222 1223 int32_t d = max - min; 1224 int32_t r = (rnd_map[rnd_act] % d) + min; 1225 1226 rnd_act++; 1227 if(rnd_act >= RND_NUM) rnd_act = 0; 1228 1229 return r; 1230 1231 } 1232 1233 #endif