From 6e3d01190fae01a0edebaeb5af81ec27cbb93c48 Mon Sep 17 00:00:00 2001 From: _VIFEXTech <1290176185@qq.com> Date: Tue, 24 May 2022 18:36:22 +0800 Subject: [PATCH] feat(benchmark): make lvgl render at the highest frame rate (#3352) * feat(benchmark): make lvgl render at the highest frame rate * add lv_demo_benchmark_set_max_speed * Update comments and README Signed-off-by: pengyiqiang Co-authored-by: pengyiqiang --- demos/benchmark/README.md | 2 +- demos/benchmark/lv_demo_benchmark.c | 32 +++++++++++++++++++++++++++++ demos/benchmark/lv_demo_benchmark.h | 6 ++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/demos/benchmark/README.md b/demos/benchmark/README.md index 02f0e5bf5..5337f899a 100644 --- a/demos/benchmark/README.md +++ b/demos/benchmark/README.md @@ -16,7 +16,7 @@ On to top of the screen the title of the current test step, and the result of th - If you only want to run a specific scene for any purpose (e.g. debug, performance optimization etc.), you can call `lv_demo_benchmark_run_scene()` instead of `lv_demo_benchmark()`and pass the scene number. - If you enabled trace output by setting macro `LV_USE_LOG` to `1` and trace level `LV_LOG_LEVEL` to `LV_LOG_LEVEL_USER` or higher, benchmark results are printed out in `csv` format. - If you want to know when the testing is finished, you can register a callback function via `lv_demo_benchmark_register_finished_handler()` before calling `lv_demo_benchmark()` or `lv_demo_benchmark_run_scene()`. - +- If you want to know the maximum rendering performance of the system, call `lv_demo_benchmark_set_max_speed(true)` before `lv_demo_benchmark()`. ## Interpret the result diff --git a/demos/benchmark/lv_demo_benchmark.c b/demos/benchmark/lv_demo_benchmark.c index 966befcf1..2356625c7 100644 --- a/demos/benchmark/lv_demo_benchmark.c +++ b/demos/benchmark/lv_demo_benchmark.c @@ -69,7 +69,10 @@ typedef struct { 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; LV_IMG_DECLARE(img_benchmark_cogwheel_argb); LV_IMG_DECLARE(img_benchmark_cogwheel_rgb); @@ -636,6 +639,18 @@ 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); @@ -697,6 +712,10 @@ 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 @@ -969,6 +988,19 @@ static void scene_next_task_cb(lv_timer_t * timer) } /*Ready*/ else { + + /*Restore original frame rate*/ + if(run_max_speed) { + lv_timer_t * anim_timer = lv_anim_get_timer(); + lv_timer_set_period(anim_timer, anim_ori_timer_period); + + lv_disp_t * disp = lv_disp_get_default(); + lv_timer_t * refr_timer = _lv_disp_get_refr_timer(disp); + if(refr_timer) { + lv_timer_set_period(refr_timer, disp_ori_timer_period); + } + } + generate_report(); /* generate report */ } } diff --git a/demos/benchmark/lv_demo_benchmark.h b/demos/benchmark/lv_demo_benchmark.h index ebcd14036..6a0a4f649 100644 --- a/demos/benchmark/lv_demo_benchmark.h +++ b/demos/benchmark/lv_demo_benchmark.h @@ -34,6 +34,12 @@ void lv_demo_benchmark_run_scene(int_fast16_t scene_no); void lv_demo_benchmark_set_finished_cb(finished_cb_t * finished_cb); +/** + * Make the benchmark work at the highest frame rate + * @param en true: highest frame rate; false: default frame rate + */ +void lv_demo_benchmark_set_max_speed(bool en); + /********************** * MACROS **********************/