perf: Rate-limit progress bar updates to prevent redundant layout invalidation and redraws
This commit is contained in:
@@ -59,6 +59,7 @@ typedef struct {
|
|||||||
cJSON* pages_array;
|
cJSON* pages_array;
|
||||||
int page_count;
|
int page_count;
|
||||||
int current_page;
|
int current_page;
|
||||||
|
int last_pct;
|
||||||
|
|
||||||
// UI elements
|
// UI elements
|
||||||
AppHandle app;
|
AppHandle app;
|
||||||
@@ -212,6 +213,7 @@ static void load_page(AppCtx* ctx, int page_index, bool start_audio) {
|
|||||||
|
|
||||||
if (page_index < 0 || page_index >= ctx->page_count) return;
|
if (page_index < 0 || page_index >= ctx->page_count) return;
|
||||||
ctx->current_page = page_index;
|
ctx->current_page = page_index;
|
||||||
|
ctx->last_pct = -1;
|
||||||
|
|
||||||
cJSON* page = cJSON_GetArrayItem(ctx->pages_array, page_index);
|
cJSON* page = cJSON_GetArrayItem(ctx->pages_array, page_index);
|
||||||
if (!page) return;
|
if (!page) return;
|
||||||
@@ -451,10 +453,13 @@ static void play_mp3(AppCtx* ctx) {
|
|||||||
int pct = (int)((bytes_read_total - buffered_bytes) * 100 / file_size);
|
int pct = (int)((bytes_read_total - buffered_bytes) * 100 / file_size);
|
||||||
if (pct < 0) pct = 0;
|
if (pct < 0) pct = 0;
|
||||||
if (pct > 100) pct = 100;
|
if (pct > 100) pct = 100;
|
||||||
|
if (pct != ctx->last_pct) {
|
||||||
|
ctx->last_pct = pct;
|
||||||
tt_lvgl_lock(portMAX_DELAY);
|
tt_lvgl_lock(portMAX_DELAY);
|
||||||
lv_bar_set_value(ctx->bar_progress, pct, LV_ANIM_OFF);
|
lv_bar_set_value(ctx->bar_progress, pct, LV_ANIM_OFF);
|
||||||
tt_lvgl_unlock();
|
tt_lvgl_unlock();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
taskYIELD();
|
taskYIELD();
|
||||||
}
|
}
|
||||||
@@ -611,9 +616,14 @@ static void play_wav(AppCtx* ctx) {
|
|||||||
|
|
||||||
// Update progress bar
|
// Update progress bar
|
||||||
int pct = (int)((total_played * 100) / data_size);
|
int pct = (int)((total_played * 100) / data_size);
|
||||||
|
if (pct < 0) pct = 0;
|
||||||
|
if (pct > 100) pct = 100;
|
||||||
|
if (pct != ctx->last_pct) {
|
||||||
|
ctx->last_pct = pct;
|
||||||
tt_lvgl_lock(portMAX_DELAY);
|
tt_lvgl_lock(portMAX_DELAY);
|
||||||
lv_bar_set_value(ctx->bar_progress, pct, LV_ANIM_OFF);
|
lv_bar_set_value(ctx->bar_progress, pct, LV_ANIM_OFF);
|
||||||
tt_lvgl_unlock();
|
tt_lvgl_unlock();
|
||||||
|
}
|
||||||
|
|
||||||
taskYIELD();
|
taskYIELD();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user