perf: Rate-limit progress bar updates to prevent redundant layout invalidation and redraws

This commit is contained in:
Adolfo Reyna
2026-07-09 22:27:44 -04:00
parent efea28e5d6
commit 12e99f896a
+10
View File
@@ -59,6 +59,7 @@ typedef struct {
cJSON* pages_array;
int page_count;
int current_page;
int last_pct;
// UI elements
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;
ctx->current_page = page_index;
ctx->last_pct = -1;
cJSON* page = cJSON_GetArrayItem(ctx->pages_array, page_index);
if (!page) return;
@@ -451,10 +453,13 @@ static void play_mp3(AppCtx* ctx) {
int pct = (int)((bytes_read_total - buffered_bytes) * 100 / file_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);
lv_bar_set_value(ctx->bar_progress, pct, LV_ANIM_OFF);
tt_lvgl_unlock();
}
}
taskYIELD();
}
@@ -611,9 +616,14 @@ static void play_wav(AppCtx* ctx) {
// Update progress bar
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);
lv_bar_set_value(ctx->bar_progress, pct, LV_ANIM_OFF);
tt_lvgl_unlock();
}
taskYIELD();
}