scroll engine: Factor out renderer function so it can be called by lcd code.

This is used by lcd_puts_scroll_worker() to render the line immediately
instead of waiting for the next scroll tick when only the text was updated.
Previously lcd_puts_scroll_worker() did not render anything in this case
which could lead to visible blinking.

This fixes blinking scrolling lines with dynamic text in the skin engine.

Change-Id: I475bde8c8eb7c92f505e3c5ecf4d32bb90690536
This commit is contained in:
Thomas Martitz 2014-01-11 19:17:58 +01:00
parent 2a471c9e84
commit 26b317e094
3 changed files with 80 additions and 53 deletions

View file

@ -398,6 +398,9 @@ static void LCDFN(puts_scroll_worker)(int x, int y, const unsigned char *string,
s->height = height; s->height = height;
s->vp = current_vp; s->vp = current_vp;
LCDFN(scroll_info).lines++; LCDFN(scroll_info).lines++;
} else {
/* if only the text was updated render immediately */
LCDFN(scroll_now(s));
} }
} }

View file

@ -123,11 +123,78 @@ void LCDFN(jump_scroll_delay)(int ms)
} }
#endif #endif
/* This renders the scrolling line described by s immediatly.
* This can be called to update a scrolling line if the text has changed
* without waiting for the next scroll tick
*
* Returns true if the text scrolled to the end */
bool LCDFN(scroll_now)(struct scrollinfo *s)
{
int width = LCDFN(getstringsize)(s->linebuffer, NULL, NULL);
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) */
static char line_buf[SCROLL_LINE_SIZE];
if (s->bidir)
{ /* scroll bidirectional */
s->line = s->linebuffer;
if (s->offset <= 0) {
/* at beginning of line */
s->offset = 0;
s->backward = false;
ended = true;
}
else if (s->offset >= width - s->width) {
/* at end of line */
s->offset = width - s->width;
s->backward = true;
ended = true;
}
}
else
{
snprintf(line_buf, sizeof(line_buf)-1, "%s%s%s",
s->linebuffer, " ", s->linebuffer);
s->line = line_buf;
width += LCDFN(getstringsize)(" ", NULL, NULL);
/* scroll forward the whole time */
if (s->offset >= width) {
s->offset = 0;
ended = true;
}
}
/* Stash and restore these three, so that the scroll_func
* can do whatever it likes without destroying the state */
#ifdef HAVE_LCD_BITMAP
unsigned drawmode;
#if LCD_DEPTH > 1
unsigned fg_pattern, bg_pattern;
fg_pattern = s->vp->fg_pattern;
bg_pattern = s->vp->bg_pattern;
#endif
drawmode = s->vp->drawmode;
#endif
s->scroll_func(s);
LCDFN(update_viewport_rect)(s->x, s->y, s->width, s->height);
#ifdef HAVE_LCD_BITMAP
#if LCD_DEPTH > 1
s->vp->fg_pattern = fg_pattern;
s->vp->bg_pattern = bg_pattern;
#endif
s->vp->drawmode = drawmode;
#endif
return ended;
}
static void LCDFN(scroll_worker)(void) static void LCDFN(scroll_worker)(void)
{ {
int index, width; int index;
bool makedelay; bool makedelay;
static char line_buf[SCROLL_LINE_SIZE];
bool is_default; bool is_default;
struct scroll_screen_info *si = &LCDFN(scroll_info); struct scroll_screen_info *si = &LCDFN(scroll_info);
struct scrollinfo *s; struct scrollinfo *s;
@ -152,7 +219,6 @@ static void LCDFN(scroll_worker)(void)
vp = LCDFN(get_viewport)(&is_default); vp = LCDFN(get_viewport)(&is_default);
LCDFN(set_viewport)(s->vp); LCDFN(set_viewport)(s->vp);
width = LCDFN(getstringsize)(s->linebuffer, NULL, NULL);
makedelay = false; makedelay = false;
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
step = si->step; step = si->step;
@ -160,62 +226,15 @@ static void LCDFN(scroll_worker)(void)
step = 1; step = 1;
#endif #endif
if (s->backward) if (s->backward)
s->offset -= step; s->offset -= step;
else else
s->offset += step; s->offset += step;
if (s->bidir) /* put the line onto the display now */
{ /* scroll bidirectional */ makedelay = LCDFN(scroll_now(s));
s->line = s->linebuffer;
if (s->offset <= 0) {
/* at beginning of line */
s->offset = 0;
s->backward = false;
makedelay = true;
}
else if (s->offset >= width - s->width) {
/* at end of line */
s->offset = width - s->width;
s->backward = true;
makedelay = true;
}
}
else
{
snprintf(line_buf, sizeof(line_buf)-1, "%s%s%s",
s->linebuffer, " ", s->linebuffer);
s->line = line_buf;
width += LCDFN(getstringsize)(" ", NULL, NULL);
/* scroll forward the whole time */
if (s->offset >= width) {
s->offset = 0;
makedelay = true;
}
}
/* Stash and restore these three, so that the scroll_func
* can do whatever it likes without destroying the state */
#ifdef HAVE_LCD_BITMAP
unsigned drawmode;
#if LCD_DEPTH > 1
unsigned fg_pattern, bg_pattern;
fg_pattern = s->vp->fg_pattern;
bg_pattern = s->vp->bg_pattern;
#endif
drawmode = s->vp->drawmode;
#endif
s->scroll_func(s);
LCDFN(update_viewport_rect)(s->x, s->y, s->width, s->height);
#ifdef HAVE_LCD_BITMAP
#if LCD_DEPTH > 1
s->vp->fg_pattern = fg_pattern;
s->vp->bg_pattern = bg_pattern;
#endif
s->vp->drawmode = drawmode;
#endif
LCDFN(set_viewport)(vp); LCDFN(set_viewport)(vp);
if (makedelay) if (makedelay)

View file

@ -30,6 +30,7 @@
#include "file.h" #include "file.h"
struct viewport; struct viewport;
struct scrollinfo;
extern void scroll_init(void) INIT_ATTR; extern void scroll_init(void) INIT_ATTR;
@ -40,6 +41,7 @@ extern void lcd_scroll_delay(int ms);
extern void lcd_scroll_stop(void); extern void lcd_scroll_stop(void);
extern void lcd_scroll_stop_viewport(const struct viewport *vp); extern void lcd_scroll_stop_viewport(const struct viewport *vp);
extern void lcd_scroll_stop_viewport_rect(const struct viewport *vp, int x, int y, int width, int height); extern void lcd_scroll_stop_viewport_rect(const struct viewport *vp, int x, int y, int width, int height);
extern bool lcd_scroll_now(struct scrollinfo *scroll);
#ifdef HAVE_REMOTE_LCD #ifdef HAVE_REMOTE_LCD
extern void lcd_remote_scroll_speed(int speed); extern void lcd_remote_scroll_speed(int speed);
extern void lcd_remote_scroll_delay(int ms); extern void lcd_remote_scroll_delay(int ms);
@ -47,8 +49,11 @@ extern void lcd_remote_scroll_delay(int ms);
extern void lcd_remote_scroll_stop(void); extern void lcd_remote_scroll_stop(void);
extern void lcd_remote_scroll_stop_viewport(const struct viewport *vp); extern void lcd_remote_scroll_stop_viewport(const struct viewport *vp);
extern void lcd_remote_scroll_stop_viewport_rect(const struct viewport *vp, int x, int y, int width, int height); extern void lcd_remote_scroll_stop_viewport_rect(const struct viewport *vp, int x, int y, int width, int height);
extern bool lcd_remote_scroll_now(struct scrollinfo *scroll);
#endif #endif
/* internal usage, but in multiple drivers /* internal usage, but in multiple drivers
* larger than the normal linebuffer since it holds the line a second * larger than the normal linebuffer since it holds the line a second
* time (+3 spaces) for non-bidir scrolling */ * time (+3 spaces) for non-bidir scrolling */