diff options
author | William Wilgus <wilgus.william@gmail.com> | 2024-12-19 12:28:07 -0500 |
---|---|---|
committer | William Wilgus <me.theuser@yahoo.com> | 2024-12-20 10:31:46 -0500 |
commit | 660fa3ffdc929a02d63aaa9c49613df045730e49 (patch) | |
tree | ebb2757861f749d985817a61b3484629524838cc | |
parent | f179fc1079b4d72cdc07fd7d227d08aa746e8089 (diff) | |
download | rockbox-660fa3ffdc.tar.gz rockbox-660fa3ffdc.zip |
scroll engine calculate stringsize only when scroll line updated
we calculate the size of the scrolling line every scroll update
the line data doesn't ever change without a call to update
instead calculate the string size when the line is updated
re-use this value while scrolling the line
in theory the current font could change but in practice
I can't find a case when the string size needs to be updated
that the scroll engine isn't already updating the line
if this is later an issue we can recalculate the stringsize each time
the line is finished scrolling which still saves quite a few calculations
Other:
I don't think we have any targets with pixel counts exceeding 65535 pixels
where unsigned short stringsize will be an issue
Change-Id: I83d6374377ed648d9a320d4fd69f9d6a17095b0c
-rw-r--r-- | firmware/drivers/lcd-bitmap-common.c | 4 | ||||
-rw-r--r-- | firmware/drivers/lcd-scroll.c | 54 | ||||
-rw-r--r-- | firmware/export/scroll_engine.h | 2 |
3 files changed, 33 insertions, 27 deletions
diff --git a/firmware/drivers/lcd-bitmap-common.c b/firmware/drivers/lcd-bitmap-common.c index 3200d2dd1a..13f6a9e57a 100644 --- a/firmware/drivers/lcd-bitmap-common.c +++ b/firmware/drivers/lcd-bitmap-common.c @@ -684,7 +684,7 @@ static bool LCDFN(puts_scroll_worker)(int x, int y, const unsigned char *string, cwidth = font_get(vp->font)->maxwidth; /* get width (pixels) of the string */ - LCDFN(getstringsize)(string, &w, &h); + font_getstringsize(string, &w, &h, vp->font); height = h; y = y * (linebased ? height : 1); @@ -713,6 +713,8 @@ static bool LCDFN(puts_scroll_worker)(int x, int y, const unsigned char *string, /* copy contents to the line buffer */ strmemccpy(s->linebuffer, string, sizeof(s->linebuffer)); + s->line_stringsize = w; + /* scroll bidirectional or forward only depending on the string width */ if ( LCDFN(scroll_info).bidir_limit ) { s->bidir = w < (vp->width) * diff --git a/firmware/drivers/lcd-scroll.c b/firmware/drivers/lcd-scroll.c index 7c5492e983..14789be64a 100644 --- a/firmware/drivers/lcd-scroll.c +++ b/firmware/drivers/lcd-scroll.c @@ -122,7 +122,9 @@ void LCDFN(bidir_scroll)(int percent) * Returns true if the text scrolled to the end */ bool LCDFN(scroll_now)(struct scrollinfo *s) { - int width = LCDFN(getstringsize)(s->linebuffer, NULL, NULL); + int width = s->line_stringsize; /* Calculated by LCDFN puts_scroll_worker() */ + /*int width = font_getstringsize(s->linebuffer, NULL, NULL, s->vp->font);*/ + bool ended = false; /* assume s->scroll_func() don't yield; otherwise this buffer might need * to be mutex'd (the worst case would be minor glitches though) */ @@ -149,7 +151,7 @@ bool LCDFN(scroll_now)(struct scrollinfo *s) snprintf(line_buf, sizeof(line_buf)-1, "%s%s%s", s->linebuffer, " ", s->linebuffer); s->line = line_buf; - width += LCDFN(getstringsize)(" ", NULL, NULL); + width += font_getstringsize(" ", NULL, NULL, s->vp->font) * 3; /* scroll forward the whole time */ if (s->offset >= width) { s->offset = 0; @@ -184,53 +186,53 @@ bool LCDFN(scroll_now)(struct scrollinfo *s) static void LCDFN(scroll_worker)(void) { int index; - bool makedelay; struct scroll_screen_info *si = &LCDFN(scroll_info); - struct scrollinfo *s; struct viewport *oldvp; - int step; + + if (global_settings.disable_mainmenu_scrolling + && get_current_activity() == ACTIVITY_MAINMENU) { + /* No scrolling on the main menu if disabled + (to not break themes with lockscreens) */ + return; + } for ( index = 0; index < si->lines; index++ ) { - s = &si->scroll[index]; + struct scrollinfo *s = &si->scroll[index]; /* check pause */ if (TIME_BEFORE(current_tick, s->start_tick)) { continue; } - if (global_settings.disable_mainmenu_scrolling && get_current_activity() == ACTIVITY_MAINMENU) { - // No scrolling on the main menu if disabled (to not break themes with lockscreens) - continue; - } - s->start_tick = current_tick; - /* this runs out of the ui thread, thus we need to - * save and restore the current viewport since the ui thread - * is unaware of the swapped viewports. the vp must - * be switched early so that lcd_getstringsize() picks the - * correct font */ - oldvp = LCDFN(set_viewport_ex)(s->vp, 0); /* don't mark the last vp as dirty */ - - makedelay = false; - step = si->step; - if (s->backward) - s->offset -= step; + s->offset -= si->step; else - s->offset += step; + s->offset += si->step; + + /* this runs out of the ui thread, thus we need to + * save and restore the current viewport since the + * ui thread is unaware of the swapped viewports. */ + oldvp = LCDFN(set_viewport_ex)(s->vp, 0); /* don't mark the last vp as dirty */ /* put the line onto the display now */ - makedelay = LCDFN(scroll_now(s)); + bool makedelay = LCDFN(scroll_now(s)); + if (makedelay) + { +#if 0 /* haven't found a case in which this matters .. yet?? --Bilgus */ + /* re-calculate stringsize in case the font changed */ + s->line_stringsize = font_getstringsize(s->linebuffer, NULL, NULL, s->vp->font); +#endif + s->start_tick += si->delay + si->ticks; + } #ifdef SIMULATOR /* Bugfix sim won't update screen unless called from active thread */ LCDFN(set_viewport)(oldvp); #else LCDFN(set_viewport_ex)(oldvp, 0); /* don't mark the last vp as dirty */ #endif - if (makedelay) - s->start_tick += si->delay + si->ticks; } } #endif /*!BOOTLOADER*/ diff --git a/firmware/export/scroll_engine.h b/firmware/export/scroll_engine.h index ba7cc3c4d5..ed8f93b476 100644 --- a/firmware/export/scroll_engine.h +++ b/firmware/export/scroll_engine.h @@ -124,6 +124,8 @@ struct scrollinfo int width, height; /* pixel to skip from the beginning of the string, increments as the text scrolls */ int offset; + /* getstringsize width of linebuffer */ + unsigned short line_stringsize; /* scroll presently forward or backward? */ bool backward; bool bidir; |