skin_display: simplify skin_wait_for_action
rockbox-gerrit-noreply--- via rockbox-cvs <[email protected]>
| Newsgroups | gmane.comp.systems.archos.rockbox.cvs |
|---|---|
| Message-ID | <[email protected]> |
commit 3d44fe94f3f3bf8834ced3e50de57fb395fea9df Author: Christian Soffke <[email protected]> Date: Mon Aug 17 18:59:13 2026 +0200 skin_display: simplify skin_wait_for_action Reduces GNU Complexity score from 6 to 2. Slightly adjusts behavior: 1) With TIMEOUT_NOBLOCK and peak meters enabled, skin_wait_for_action always returned BUTTON_NONE, and did nothing else. Presumably unintentional. WPS was not affected, since it always uses HZ/5 for the timeout. The FM screen uses TIMEOUT_NOBLOCK only when fms_do_button_loop is called with update_screen == true. skin_wait_for_action now returns the result of get_action in any given scenario. 2) fixes incorrect next_refresh calculation when peak_meters are enabled on multiple screens 3) button loop now refreshes peak meters when current_tick >= next_refresh, instead of when current_tick > next_refresh Change-Id: Iaca37dbdde6057f593659b2feb97b61ac4cc4b02 diff --git a/apps/gui/skin_engine/skin_display.c b/apps/gui/skin_engine/skin_display.c index 027026cd8c..106fd6f85c 100644 --- a/apps/gui/skin_engine/skin_display.c +++ b/apps/gui/skin_engine/skin_display.c @@ -756,52 +756,35 @@ bool skin_has_sbs(struct gui_wps *gwps) return draw; } -/* do the button loop as often as required for the peak meters to update - * with a good refresh rate. - */ +/* Enter button loop updating peak meter at a high refresh rate */ int skin_wait_for_action(enum skinnable_screens skin, int context, int timeout) { - int button = ACTION_NONE; - /* when the peak meter is enabled we want to have a - few extra updates to make it look smooth. On the - other hand we don't want to waste energy if it - isn't displayed */ - bool pm=false; + /* Skip updates if peak meter disabled. */ + bool peak_meter_enabled = false; FOR_NB_SCREENS(i) + peak_meter_enabled |= skin_get_gwps(skin, i)->data->peak_meter_enabled; + if (!peak_meter_enabled) + return get_action(context, timeout); + + long next_refresh = current_tick; + long timeout_tick = current_tick + timeout; + + while (true) { - if(skin_get_gwps(skin, i)->data->peak_meter_enabled) - pm = true; - } + int action = get_action(context, TIMEOUT_NOBLOCK); + if (action != ACTION_NONE || !(TIME_BEFORE(current_tick, timeout_tick))) + return action; - if (pm) { - long next_refresh = current_tick; - long next_big_refresh = current_tick + timeout; - button = BUTTON_NONE; - while (TIME_BEFORE(current_tick, next_big_refresh)) { - button = get_action(context,TIMEOUT_NOBLOCK); - if (button != ACTION_NONE) { - break; - } - peak_meter_peek(); - sleep(0); /* Sleep until end of current tick. */ + peak_meter_peek(); /* Read peak values */ + sleep(0); /* Sleep until end of current tick. */ - if (TIME_AFTER(current_tick, next_refresh)) { - FOR_NB_SCREENS(i) - { - if(skin_get_gwps(skin, i)->data->peak_meter_enabled) - skin_update(skin, i, SKIN_REFRESH_PEAK_METER); - next_refresh += HZ / PEAK_METER_FPS; - } - } - } + if (TIME_BEFORE(current_tick, next_refresh)) + continue; - } + FOR_NB_SCREENS(i) + if (skin_get_gwps(skin, i)->data->peak_meter_enabled) + skin_update(skin, i, SKIN_REFRESH_PEAK_METER); - /* The peak meter is disabled - -> no additional screen updates needed */ - else - { - button = get_action(context, timeout); + next_refresh += HZ/PEAK_METER_FPS; } - return button; } diff --git a/apps/gui/skin_engine/skin_engine.h b/apps/gui/skin_engine/skin_engine.h index 6fe3f7248b..363252794f 100644 --- a/apps/gui/skin_engine/skin_engine.h +++ b/apps/gui/skin_engine/skin_engine.h @@ -67,10 +67,7 @@ void skin_backdrop_unload(int backdrop_id); #define BACKDROP_BUFFERNAME "#backdrop_buffer#" void skin_backdrop_set_buffer(int backdrop_id, struct skin_viewport *svp); -/* do the button loop as often as required for the peak meters to update - * with a good refresh rate. - * gwps is really gwps[NB_SCREENS]! don't wrap this in FOR_NB_SCREENS() - */ +/* Enter button loop updating peak meter at a high refresh rate */ int skin_wait_for_action(enum skinnable_screens skin, int context, int timeout); struct gui_wps *skin_get_gwps(enum skinnable_screens skin, enum screen_type screen); -- rockbox-cvs mailing list [email protected] https://lists.haxx.se/mailman/listinfo/rockbox-cvs