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