Skip to content

Commit

Permalink
demo(benchmark): rework benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
kisvegabor committed Oct 25, 2023
1 parent 84c8cf8 commit a61d87f
Show file tree
Hide file tree
Showing 9 changed files with 653 additions and 1,228 deletions.
1,416 changes: 395 additions & 1,021 deletions demos/benchmark/lv_demo_benchmark.c

Large diffs are not rendered by default.

31 changes: 10 additions & 21 deletions demos/benchmark/lv_demo_benchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,35 @@ extern "C" {
*********************/
#include "../lv_demos.h"

#if LV_USE_DEMO_BENCHMARK

#if LV_USE_PERF_MONITOR == 0
#error "lv_demo_benchmark: LV_USE_PERF_MONITOR is required. Enable it in lv_conf.h (LV_USE_PERF_MONITOR 1)"
#endif

/*********************
* DEFINES
*********************/

/**********************
* TYPEDEFS
**********************/
typedef enum {
/**Render the scenes and show them on the display.
* Measure rendering time but it might contain extra time when LVGL waits for the driver.
* Run each scenes for a few seconds so the performance can be seen by eye too.
* As only the rendering time is measured and converted to FPS, really high values (e.g. 1000 FPS)
* are possible.*/
LV_DEMO_BENCHMARK_MODE_RENDER_AND_DRIVER,

/**Similar to RENDER_AND_DRIVER but instead of measuring the rendering time only measure the real FPS of the system.
* E.g. even if a scene was rendered in 1 ms, but the screen is redrawn only in every 100 ms, the result will be 10 FPS.*/
LV_DEMO_BENCHMARK_MODE_REAL,

/**Temporarily display the `flush_cb` so the pure rendering time will be measured.
* The display is not updated during the benchmark, only at the end when the summary table is shown.
* Render a given number of frames from each scene and calculate the FPS from them.*/
LV_DEMO_BENCHMARK_MODE_RENDER_ONLY,
} lv_demo_benchmark_mode_t;

/**********************
* GLOBAL PROTOTYPES
**********************/

/** Run all test scenes in the LVGL benchmark with a given mode
*/
void lv_demo_benchmark(lv_demo_benchmark_mode_t mode);

/** Run a specific test scene in the LVGL benchmark with a given mode
*/
void lv_demo_benchmark_run_scene(lv_demo_benchmark_mode_t mode, uint16_t scene_no);
void lv_demo_benchmark(void);

/**********************
* MACROS
**********************/

#endif /*LV_USE_DEMO_BENCHMARK*/

#ifdef __cplusplus
} /* extern "C" */
#endif
Expand Down
36 changes: 18 additions & 18 deletions demos/lv_demos.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@

typedef void (*demo_method_cb)(void);
#if LV_USE_DEMO_BENCHMARK
typedef void (*demo_method_benchmark_cb)(lv_demo_benchmark_mode_t);
typedef void (*demo_method_benchmark_scene_cb)(lv_demo_benchmark_mode_t, uint16_t);
// typedef void (*demo_method_benchmark_cb)(lv_demo_benchmark_mode_t);
// typedef void (*demo_method_benchmark_scene_cb)(lv_demo_benchmark_mode_t, uint16_t);
#endif

typedef struct {
const char * name;
union {
demo_method_cb entry_cb;
#if LV_USE_DEMO_BENCHMARK
demo_method_benchmark_cb entry_benchmark_cb;
demo_method_benchmark_scene_cb entry_benchmark_scene_cb;
// demo_method_benchmark_cb entry_benchmark_cb;
// demo_method_benchmark_scene_cb entry_benchmark_scene_cb;
#endif
};
int arg_count : 8;
Expand Down Expand Up @@ -89,10 +89,10 @@ static const demo_entry_info_t demos_entry_info[] = {
{ "scroll", .entry_cb = lv_demo_scroll },
#endif

#if LV_USE_DEMO_BENCHMARK
{ DEMO_BENCHMARK_NAME, .entry_benchmark_cb = lv_demo_benchmark, 1 },
{ DEMO_BENCHMARK_SCENE_NAME, .entry_benchmark_scene_cb = lv_demo_benchmark_run_scene, 2 },
#endif
//#if LV_USE_DEMO_BENCHMARK
// { DEMO_BENCHMARK_NAME, .entry_benchmark_cb = lv_demo_benchmark, 1 },
// { DEMO_BENCHMARK_SCENE_NAME, .entry_benchmark_scene_cb = lv_demo_benchmark_run_scene, 2 },
//#endif
{ "", .entry_cb = NULL }
};

Expand Down Expand Up @@ -138,16 +138,16 @@ bool lv_demos_create(char * info[], int size)
return true;
}
}
#if LV_USE_DEMO_BENCHMARK
else if(demo_is_benchmark(entry_info) && entry_info->entry_benchmark_cb) {
entry_info->entry_benchmark_cb((lv_demo_benchmark_mode_t)atoi(info[1]));
return true;
}
else if(demo_is_benchmark_scene(entry_info) && entry_info->entry_benchmark_scene_cb) {
entry_info->entry_benchmark_scene_cb((lv_demo_benchmark_mode_t)atoi(info[1]), (uint16_t)atoi(info[2]));
return true;
}
#endif
//#if LV_USE_DEMO_BENCHMARK
// else if(demo_is_benchmark(entry_info) && entry_info->entry_benchmark_cb) {
// entry_info->entry_benchmark_cb((lv_demo_benchmark_mode_t)atoi(info[1]));
// return true;
// }
// else if(demo_is_benchmark_scene(entry_info) && entry_info->entry_benchmark_scene_cb) {
// entry_info->entry_benchmark_scene_cb((lv_demo_benchmark_mode_t)atoi(info[1]), (uint16_t)atoi(info[2]));
// return true;
// }
//#endif

return false;
}
Expand Down
2 changes: 1 addition & 1 deletion demos/multilang/lv_demo_multilang.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ static card_info_t card_info[] = {
CARD_INFO_SET(&img_multilang_avatar_13, "Jamal Brown", "Photographer and amateur astronomer 📸"),
CARD_INFO_SET(&img_multilang_avatar_15, "Pavel Svoboda", "Hudebník a návštěvník koncertů"),
CARD_INFO_SET(&img_multilang_avatar_16, "Elin Lindqvist", "Språkinlärare och kulturentusiast "),
CARD_INFO_SET(&img_multilang_avatar_17, "William Carter", "DIY enthusiast and home improvement guru "),
CARD_INFO_SET(&img_multilang_avatar_17, "William Carter", "DIY enthusiast and home improvement guru"),
CARD_INFO_SET(&img_multilang_avatar_22, "Ava Williams", "Artist and creative visionary 🎨"),
CARD_INFO_SET(NULL, NULL, NULL),
};
Expand Down
80 changes: 69 additions & 11 deletions demos/widgets/lv_demo_widgets.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,13 @@ static void calendar_event_cb(lv_event_t * e);
static void slider_event_cb(lv_event_t * e);
static void chart_event_cb(lv_event_t * e);
static void shop_chart_event_cb(lv_event_t * e);
static void scale2_event_cb(lv_event_t * e);
static void scale1_indic1_anim_cb(void * var, int32_t v);
static void scale2_timer_cb(lv_timer_t * timer);
static void scale3_anim_cb(void * var, int32_t v);
static void scroll_anim_y_cb(void * var, int32_t v);
static void scroll_anim_y_cb(void * var, int32_t v);
static void delete_timer_event_cb(lv_event_t * e);
static void slideshow_anim_ready_cb(lv_anim_t * a_old);

/**********************
* STATIC VARIABLES
Expand Down Expand Up @@ -195,6 +198,28 @@ void lv_demo_widgets(void)
color_changer_create(tv);
}


void lv_demo_widgets_start_slideshow(void)
{
lv_obj_update_layout(tv);

lv_obj_t * cont = lv_tabview_get_content(tv);

lv_obj_t * tab = lv_obj_get_child(cont, 0);

int32_t v = lv_obj_get_scroll_bottom(tab);
uint32_t t = lv_anim_speed_to_time(lv_display_get_dpi(NULL), 0, v);
lv_anim_t a;
lv_anim_init(&a);
lv_anim_set_exec_cb(&a, scroll_anim_y_cb);
lv_anim_set_time(&a, t);
lv_anim_set_playback_time(&a, t);
lv_anim_set_values(&a, 0, v);
lv_anim_set_var(&a, tab);
lv_anim_set_ready_cb(&a, slideshow_anim_ready_cb);
lv_anim_start(&a);
}

/**********************
* STATIC FUNCTIONS
**********************/
Expand Down Expand Up @@ -740,7 +765,7 @@ static void analytics_create(lv_obj_t * parent)
lv_obj_center(arc);

lv_timer_t * scale2_timer = lv_timer_create(scale2_timer_cb, 100, scale2);
lv_obj_add_event(scale2, scale2_event_cb, LV_EVENT_DELETE, scale2_timer);
lv_obj_add_event(scale2, delete_timer_event_cb, LV_EVENT_DELETE, scale2_timer);

/*Scale 3*/
lv_scale_set_range(scale3, 10, 60);
Expand Down Expand Up @@ -1535,15 +1560,6 @@ static void scale1_indic1_anim_cb(void * var, int32_t v)
lv_label_set_text_fmt(label, "Revenue: %"LV_PRId32" %%", v);
}

static void scale2_event_cb(lv_event_t * e)
{
lv_event_code_t code = lv_event_get_code(e);
if(code == LV_EVENT_DELETE) {
lv_timer_t * scale2_timer = lv_event_get_user_data(e);
if(scale2_timer) lv_timer_delete(scale2_timer);
}
}

static void scale2_timer_cb(lv_timer_t * timer)
{
LV_UNUSED(timer);
Expand Down Expand Up @@ -1613,4 +1629,46 @@ static void scale3_anim_cb(void * var, int32_t v)
lv_label_set_text_fmt(label, "%"LV_PRId32, v);
}

static void scroll_anim_y_cb(void * var, int32_t v)
{
lv_obj_scroll_to_y(var, v, LV_ANIM_OFF);
}

static void delete_timer_event_cb(lv_event_t * e)
{
lv_event_code_t code = lv_event_get_code(e);
if(code == LV_EVENT_DELETE) {
lv_timer_t * t = lv_event_get_user_data(e);
if(t) lv_timer_delete(t);
}
}

static void slideshow_anim_ready_cb(lv_anim_t * a_old)
{
LV_UNUSED(a_old);

lv_obj_t * cont = lv_tabview_get_content(tv);
uint32_t tab_id = lv_tabview_get_tab_act(tv);
tab_id += 1;
if(tab_id > 2) tab_id = 0;
lv_tabview_set_act(tv, tab_id, LV_ANIM_ON);

lv_obj_t * tab = lv_obj_get_child(cont, tab_id);
lv_obj_scroll_to_y(tab, 0, LV_ANIM_OFF);
lv_obj_update_layout(tv);

int32_t v = lv_obj_get_scroll_bottom(tab);
uint32_t t = lv_anim_speed_to_time(lv_display_get_dpi(NULL), 0, v);

lv_anim_t a;
lv_anim_init(&a);
lv_anim_set_exec_cb(&a, scroll_anim_y_cb);
lv_anim_set_time(&a, t);
lv_anim_set_playback_time(&a, t);
lv_anim_set_values(&a, 0, v);
lv_anim_set_var(&a, tab);
lv_anim_set_ready_cb(&a, slideshow_anim_ready_cb);
lv_anim_start(&a);
}

#endif
1 change: 1 addition & 0 deletions demos/widgets/lv_demo_widgets.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ extern "C" {
* GLOBAL PROTOTYPES
**********************/
void lv_demo_widgets(void);
void lv_demo_widgets_start_slideshow(void);

/**********************
* MACROS
Expand Down
7 changes: 6 additions & 1 deletion src/core/lv_global.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ extern "C" {
#include "../misc/lv_profiler_builtin.h"
#include "../misc/lv_style.h"
#include "../misc/lv_timer.h"
#include "../others/sysmon/lv_sysmon.h"
#include "../stdlib/builtin/lv_tlsf.h"

#if LV_USE_FONT_COMPRESSED
Expand Down Expand Up @@ -175,7 +176,11 @@ typedef struct _lv_global_t {
#endif

#if LV_USE_SYSMON && LV_USE_PERF_MONITOR
void * sysmon_perf_info;
lv_sysmon_backend_data_t sysmon_perf;
#endif

#if LV_USE_SYSMON && LV_USE_MEM_MONITOR
lv_sysmon_backend_data_t sysmon_mem;
#endif

#if LV_USE_IME_PINYIN != 0
Expand Down
Loading

0 comments on commit a61d87f

Please sign in to comment.