From 488a1b983e1c2fac14de25aa781caf12628e53c8 Mon Sep 17 00:00:00 2001 From: Thomas Martitz Date: Sun, 12 Jan 2014 01:30:26 +0100 Subject: put_line/scrolling: Make the scroll engine inform custom scrollers about start/stop of scrolling. With the new lcd_putsxy_scroll_func() code can register custom scroll functions (put_line() makes use of that). In order for the custom scroller to be able to properly manage its userdata pointer (set via struct scrollinfo::userdata) the scroll engine must inform the scroller about start and stop of scrolling. To inform about start the lcd_scroll_* functions now return true when the line will scroll. To inform about stop the scroll engine calls into the scroller one last time, with the text set to NULL. put_line() can use this to release the userdata registered per scrolling line so that it can be recycled. This fixes that some scrolling lines became glitchy after some time because the userdata was recycled too early. Change-Id: Iff0a6ce2a4f9ae2bada1b8e62f4f5950224942a9 --- apps/gui/line.c | 49 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 15 deletions(-) (limited to 'apps/gui') diff --git a/apps/gui/line.c b/apps/gui/line.c index d561f08c76..e2eb6f277b 100644 --- a/apps/gui/line.c +++ b/apps/gui/line.c @@ -50,18 +50,27 @@ static void style_line(struct screen *display, int x, int y, struct line_desc *l static void put_text(struct screen *display, int x, int y, struct line_desc *line, const char *text, bool prevent_scroll, int text_skip_pixels); +struct line_desc_scroll { + struct line_desc desc; /* must be first! */ + bool used; +}; + +#define NOINLINE __attribute__ ((noinline)) -static struct line_desc *get_line_desc(void) +struct line_desc_scroll *get_line_desc(void) NOINLINE; +struct line_desc_scroll *get_line_desc(void) { - static struct line_desc lines[MAX_LINES]; + static struct line_desc_scroll lines[MAX_LINES]; static unsigned line_index; - struct line_desc *ret; + struct line_desc_scroll *this; - ret = &lines[line_index++]; - if (line_index >= ARRAYLEN(lines)) - line_index = 0; + do { + this = &lines[line_index++]; + if (line_index >= ARRAYLEN(lines)) + line_index = 0; + } while (this->used); - return ret; + return this; } static void scroller(struct scrollinfo *s, struct screen *display) @@ -72,9 +81,17 @@ static void scroller(struct scrollinfo *s, struct screen *display) * line padding. this needs to be corrected for calling style_line(). * The alternative would be to really redraw only the text area, * but that would complicate the code a lot */ - struct line_desc *line = s->userdata; - style_line(display, s->x, s->y - (line->height/2 - display->getcharheight()/2), line); - put_text(display, s->x, s->y, line, s->line, true, s->offset); + struct line_desc_scroll *line = s->userdata; + if (!s->line) + { + line->used = false; + } + else + if (s->line) + { + style_line(display, s->x, s->y - (line->desc.height/2 - display->getcharheight()/2), &line->desc); + put_text(display, s->x, s->y, &line->desc, s->line, true, s->offset); + } } static void scroller_main(struct scrollinfo *s) @@ -126,14 +143,16 @@ static void put_text(struct screen *display, if (line->scroll && !prevent_scroll) { - struct line_desc *line_data = get_line_desc(); - *line_data = *line; + bool scrolls; + struct line_desc_scroll *line_data = get_line_desc(); + line_data->desc = *line; /* precalculate to avoid doing it in the scroller, it's save to * do this on the copy of the original line_desc*/ - if (line_data->height == -1) - line_data->height = display->getcharheight(); - display->putsxy_scroll_func(x, y, text, + if (line_data->desc.height == -1) + line_data->desc.height = display->getcharheight(); + scrolls = display->putsxy_scroll_func(x, y, text, scrollers[display->screen_type], line_data, text_skip_pixels); + line_data->used = scrolls; } else display->putsxy_scroll_func(x, y, text, NULL, NULL, text_skip_pixels); -- cgit v1.2.3