From 945c8a221ade41c462a93f8452320a806e5645b3 Mon Sep 17 00:00:00 2001 From: Dave Chapman Date: Mon, 7 Jan 2008 20:34:11 +0000 Subject: Add viewport capabilities to all the LCD drivers, and adapt scrolling code. This is the firmware/ part of FS#8385 - the changes to the WPS code still need more work and will be committed at a later date. NOTE: There are no user-visible changes with this commit - just the infrastructure. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16018 a1c6a512-1295-4272-9138-f99709370657 --- firmware/drivers/lcd-2bit-vert.c | 294 +++++++++++++++++++++++++++------------ 1 file changed, 203 insertions(+), 91 deletions(-) (limited to 'firmware/drivers/lcd-2bit-vert.c') diff --git a/firmware/drivers/lcd-2bit-vert.c b/firmware/drivers/lcd-2bit-vert.c index aa3cd2cc3b..2341ddb3df 100644 --- a/firmware/drivers/lcd-2bit-vert.c +++ b/firmware/drivers/lcd-2bit-vert.c @@ -48,52 +48,93 @@ static const unsigned char pixmask[4] ICONST_ATTR = { static fb_data* lcd_backdrop = NULL; static long lcd_backdrop_offset IDATA_ATTR = 0; -static unsigned fg_pattern IDATA_ATTR = 0xFF; /* initially black */ -static unsigned bg_pattern IDATA_ATTR = 0x00; /* initially white */ -static int drawmode = DRMODE_SOLID; -static int xmargin = 0; -static int ymargin = 0; -static int curfont = FONT_SYSFIXED; +static struct viewport default_vp = +{ + .x = 0, + .y = 0, + .width = LCD_WIDTH, + .height = LCD_HEIGHT, + .font = FONT_SYSFIXED, + .drawmode = DRMODE_SOLID, + .xmargin = 0, + .ymargin = 0, + .fg_pattern = LCD_DEFAULT_FG, + .bg_pattern = LCD_DEFAULT_BG +}; + +static struct viewport* current_vp IBSS_ATTR; +static unsigned fg_pattern IBSS_ATTR; +static unsigned bg_pattern IBSS_ATTR; /* LCD init */ void lcd_init(void) { + /* Initialise the viewport */ + lcd_set_viewport(NULL); + lcd_clear_display(); /* Call device specific init */ lcd_init_device(); scroll_init(); } +/*** Viewports ***/ + +void lcd_set_viewport(struct viewport* vp) +{ + if (vp == NULL) + current_vp = &default_vp; + else + current_vp = vp; + + fg_pattern = 0x55 * (~current_vp->fg_pattern & 3); + bg_pattern = 0x55 * (~current_vp->bg_pattern & 3); +} + +void lcd_update_viewport(void) +{ + lcd_update_rect(current_vp->x, current_vp->y, + current_vp->width, current_vp->height); +} + +void lcd_update_viewport_rect(int x, int y, int width, int height) +{ + lcd_update_rect(current_vp->x + x, current_vp->y + y, width, height); +} + + /*** parameter handling ***/ void lcd_set_drawmode(int mode) { - drawmode = mode & (DRMODE_SOLID|DRMODE_INVERSEVID); + current_vp->drawmode = mode & (DRMODE_SOLID|DRMODE_INVERSEVID); } int lcd_get_drawmode(void) { - return drawmode; + return current_vp->drawmode; } void lcd_set_foreground(unsigned brightness) { + current_vp->fg_pattern = brightness; fg_pattern = 0x55 * (~brightness & 3); } unsigned lcd_get_foreground(void) { - return ~fg_pattern & 3; + return current_vp->fg_pattern; } void lcd_set_background(unsigned brightness) { + current_vp->fg_pattern = brightness; bg_pattern = 0x55 * (~brightness & 3); } unsigned lcd_get_background(void) { - return ~bg_pattern & 3; + return current_vp->bg_pattern; } void lcd_set_drawinfo(int mode, unsigned fg_brightness, unsigned bg_brightness) @@ -105,28 +146,38 @@ void lcd_set_drawinfo(int mode, unsigned fg_brightness, unsigned bg_brightness) void lcd_setmargins(int x, int y) { - xmargin = x; - ymargin = y; + current_vp->xmargin = x; + current_vp->ymargin = y; } int lcd_getxmargin(void) { - return xmargin; + return current_vp->xmargin; } int lcd_getymargin(void) { - return ymargin; + return current_vp->ymargin; +} + +int lcd_getwidth(void) +{ + return current_vp->width; +} + +int lcd_getheight(void) +{ + return current_vp->height; } void lcd_setfont(int newfont) { - curfont = newfont; + current_vp->font = newfont; } int lcd_getstringsize(const unsigned char *str, int *w, int *h) { - return font_getstringsize(str, w, h, curfont); + return font_getstringsize(str, w, h, current_vp->font); } /*** low-level drawing functions ***/ @@ -347,7 +398,7 @@ static inline void setblock(fb_data *address, unsigned mask, unsigned bits) /* Clear the whole display */ void lcd_clear_display(void) { - if (drawmode & DRMODE_INVERSEVID) + if (current_vp->drawmode & DRMODE_INVERSEVID) { memset(lcd_framebuffer, fg_pattern, sizeof lcd_framebuffer); } @@ -362,11 +413,37 @@ void lcd_clear_display(void) lcd_scroll_info.lines = 0; } +/* Clear the current viewport */ +void lcd_clear_viewport(void) +{ + int lastmode; + + if (current_vp == &default_vp) + { + lcd_clear_display(); + } + else + { + lastmode = current_vp->drawmode; + + /* Invert the INVERSEVID bit and set basic mode to SOLID */ + current_vp->drawmode = (~lastmode & DRMODE_INVERSEVID) | + DRMODE_SOLID; + + lcd_fillrect(0, 0, current_vp->width, current_vp->height); + + current_vp->drawmode = lastmode; + + lcd_scroll_stop(current_vp); + } +} + /* Set a single pixel */ void lcd_drawpixel(int x, int y) { - if (((unsigned)x < LCD_WIDTH) && ((unsigned)y < LCD_HEIGHT)) - lcd_pixelfuncs[drawmode](x, y); + if (((unsigned)x < (unsigned)current_vp->width) && + ((unsigned)y < (unsigned)current_vp->height)) + lcd_pixelfuncs[current_vp->drawmode](current_vp->x + x, current_vp->y + y); } /* Draw a line */ @@ -378,7 +455,7 @@ void lcd_drawline(int x1, int y1, int x2, int y2) int d, dinc1, dinc2; int x, xinc1, xinc2; int y, yinc1, yinc2; - lcd_pixelfunc_type *pfunc = lcd_pixelfuncs[drawmode]; + lcd_pixelfunc_type *pfunc = lcd_pixelfuncs[current_vp->drawmode]; deltax = abs(x2 - x1); deltay = abs(y2 - y1); @@ -422,8 +499,9 @@ void lcd_drawline(int x1, int y1, int x2, int y2) for (i = 0; i < numpixels; i++) { - if (((unsigned)x < LCD_WIDTH) && ((unsigned)y < LCD_HEIGHT)) - pfunc(x, y); + if (((unsigned)x < (unsigned)current_vp->width) && + ((unsigned)y < (unsigned)current_vp->height)) + pfunc(current_vp->x + x, current_vp->y + y); if (d < 0) { @@ -444,6 +522,7 @@ void lcd_drawline(int x1, int y1, int x2, int y2) void lcd_hline(int x1, int x2, int y) { int x; + int width; fb_data *dst, *dst_end; unsigned mask; lcd_blockfunc_type *bfunc; @@ -457,23 +536,30 @@ void lcd_hline(int x1, int x2, int y) } /* nothing to draw? */ - if (((unsigned)y >= LCD_HEIGHT) || (x1 >= LCD_WIDTH) || (x2 < 0)) + if (((unsigned)y >= (unsigned)current_vp->height) || (x1 >= current_vp->width) + || (x2 < 0)) return; /* clipping */ if (x1 < 0) x1 = 0; - if (x2 >= LCD_WIDTH) - x2 = LCD_WIDTH-1; - - bfunc = lcd_blockfuncs[drawmode]; + if (x2 >= current_vp->width) + x2 = current_vp->width-1; + + width = x2 - x1 + 1; + + /* adjust x1 and y to viewport */ + x1 += current_vp->x; + y += current_vp->y; + + bfunc = lcd_blockfuncs[current_vp->drawmode]; dst = &lcd_framebuffer[y>>2][x1]; mask = pixmask[y & 3]; - dst_end = dst + x2 - x1; + dst_end = dst + width; do bfunc(dst++, mask, 0xFFu); - while (dst <= dst_end); + while (dst < dst_end); } /* Draw a vertical line (optimised) */ @@ -493,16 +579,22 @@ void lcd_vline(int x, int y1, int y2) } /* nothing to draw? */ - if (((unsigned)x >= LCD_WIDTH) || (y1 >= LCD_HEIGHT) || (y2 < 0)) + if (((unsigned)x >= (unsigned)current_vp->width) || (y1 >= current_vp->height) + || (y2 < 0)) return; /* clipping */ if (y1 < 0) y1 = 0; - if (y2 >= LCD_HEIGHT) - y2 = LCD_HEIGHT-1; + if (y2 >= current_vp->height) + y2 = current_vp->height-1; - bfunc = lcd_blockfuncs[drawmode]; + /* adjust for viewport */ + y1 += current_vp->y; + y2 += current_vp->y; + x += current_vp->x; + + bfunc = lcd_blockfuncs[current_vp->drawmode]; dst = &lcd_framebuffer[y1>>2][x]; ny = y2 - (y1 & ~3); mask = 0xFFu << (2 * (y1 & 3)); @@ -544,8 +636,8 @@ void lcd_fillrect(int x, int y, int width, int height) bool fillopt = false; /* nothing to draw? */ - if ((width <= 0) || (height <= 0) || (x >= LCD_WIDTH) || (y >= LCD_HEIGHT) - || (x + width <= 0) || (y + height <= 0)) + if ((width <= 0) || (height <= 0) || (x >= current_vp->width) + || (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0)) return; /* clipping */ @@ -559,14 +651,18 @@ void lcd_fillrect(int x, int y, int width, int height) height += y; y = 0; } - if (x + width > LCD_WIDTH) - width = LCD_WIDTH - x; - if (y + height > LCD_HEIGHT) - height = LCD_HEIGHT - y; + if (x + width > current_vp->width) + width = current_vp->width - x; + if (y + height > current_vp->height) + height = current_vp->height - y; - if (drawmode & DRMODE_INVERSEVID) + /* adjust for viewport */ + x += current_vp->x; + y += current_vp->y; + + if (current_vp->drawmode & DRMODE_INVERSEVID) { - if ((drawmode & DRMODE_BG) && !lcd_backdrop) + if ((current_vp->drawmode & DRMODE_BG) && !lcd_backdrop) { fillopt = true; bits = bg_pattern; @@ -574,13 +670,13 @@ void lcd_fillrect(int x, int y, int width, int height) } else { - if (drawmode & DRMODE_FG) + if (current_vp->drawmode & DRMODE_FG) { fillopt = true; bits = fg_pattern; } } - bfunc = lcd_blockfuncs[drawmode]; + bfunc = lcd_blockfuncs[current_vp->drawmode]; dst = &lcd_framebuffer[y>>2][x]; ny = height - 1 + (y & 3); mask = 0xFFu << (2 * (y & 3)); @@ -640,8 +736,8 @@ void lcd_mono_bitmap_part(const unsigned char *src, int src_x, int src_y, lcd_blockfunc_type *bfunc; /* nothing to draw? */ - if ((width <= 0) || (height <= 0) || (x >= LCD_WIDTH) || (y >= LCD_HEIGHT) - || (x + width <= 0) || (y + height <= 0)) + if ((width <= 0) || (height <= 0) || (x >= current_vp->width) || + (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0)) return; /* clipping */ @@ -657,10 +753,14 @@ void lcd_mono_bitmap_part(const unsigned char *src, int src_x, int src_y, src_y -= y; y = 0; } - if (x + width > LCD_WIDTH) - width = LCD_WIDTH - x; - if (y + height > LCD_HEIGHT) - height = LCD_HEIGHT - y; + if (x + width > current_vp->width) + width = current_vp->width - x; + if (y + height > current_vp->height) + height = current_vp->height - y; + + /* adjust for viewport */ + x += current_vp->x; + y += current_vp->y; src += stride * (src_y >> 3) + src_x; /* move starting point */ src_y &= 7; @@ -669,7 +769,7 @@ void lcd_mono_bitmap_part(const unsigned char *src, int src_x, int src_y, shift = y & 3; ny = height - 1 + shift + src_y; - bfunc = lcd_blockfuncs[drawmode]; + bfunc = lcd_blockfuncs[current_vp->drawmode]; mask = 0xFFu << (shift + src_y); mask_bottom = 0xFFu >> (~ny & 7); @@ -807,8 +907,8 @@ void lcd_bitmap_part(const fb_data *src, int src_x, int src_y, unsigned mask, mask_bottom; /* nothing to draw? */ - if ((width <= 0) || (height <= 0) || (x >= LCD_WIDTH) || (y >= LCD_HEIGHT) - || (x + width <= 0) || (y + height <= 0)) + if ((width <= 0) || (height <= 0) || (x >= current_vp->width) + || (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0)) return; /* clipping */ @@ -824,10 +924,14 @@ void lcd_bitmap_part(const fb_data *src, int src_x, int src_y, src_y -= y; y = 0; } - if (x + width > LCD_WIDTH) - width = LCD_WIDTH - x; - if (y + height > LCD_HEIGHT) - height = LCD_HEIGHT - y; + if (x + width > current_vp->width) + width = current_vp->width - x; + if (y + height > current_vp->height) + height = current_vp->height - y; + + /* adjust for viewport */ + x += current_vp->x; + y += current_vp->y; src += stride * (src_y >> 2) + src_x; /* move starting point */ src_y &= 3; @@ -916,11 +1020,11 @@ static void lcd_putsxyofs(int x, int y, int ofs, const unsigned char *str) { unsigned short ch; unsigned short *ucs; - struct font* pf = font_get(curfont); + struct font* pf = font_get(current_vp->font); ucs = bidi_l2v(str, 1); - while ((ch = *ucs++) != 0 && x < LCD_WIDTH) + while ((ch = *ucs++) != 0 && x < current_vp->width) { int width; const unsigned char *bits; @@ -974,24 +1078,24 @@ void lcd_puts_style_offset(int x, int y, const unsigned char *str, int style, int offset) { int xpos,ypos,w,h,xrect; - int lastmode = drawmode; + int lastmode = current_vp->drawmode; /* make sure scrolling is turned off on the line we are updating */ - lcd_scroll_info.lines &= ~(1 << y); + lcd_scroll_stop_line(current_vp, y); if(!str || !str[0]) return; lcd_getstringsize(str, &w, &h); - xpos = xmargin + x*w / utf8length((char *)str); - ypos = ymargin + y*h; - drawmode = (style & STYLE_INVERT) ? - (DRMODE_SOLID|DRMODE_INVERSEVID) : DRMODE_SOLID; + xpos = current_vp->xmargin + x*w / utf8length((char *)str); + ypos = current_vp->ymargin + y*h; + current_vp->drawmode = (style & STYLE_INVERT) ? + (DRMODE_SOLID|DRMODE_INVERSEVID) : DRMODE_SOLID; lcd_putsxyofs(xpos, ypos, offset, str); - drawmode ^= DRMODE_INVERSEVID; + current_vp->drawmode ^= DRMODE_INVERSEVID; xrect = xpos + MAX(w - offset, 0); - lcd_fillrect(xrect, ypos, LCD_WIDTH - xrect, h); - drawmode = lastmode; + lcd_fillrect(xrect, ypos, current_vp->width - xrect, h); + current_vp->drawmode = lastmode; } /*** scrolling ***/ @@ -1017,9 +1121,15 @@ void lcd_puts_scroll_style_offset(int x, int y, const unsigned char *string, struct scrollinfo* s; int w, h; - if(y>=LCD_SCROLLABLE_LINES) return; + if ((unsigned)y >= (unsigned)current_vp->height) + return; + + /* remove any previously scrolling line at the same location */ + lcd_scroll_stop_line(current_vp, y); + + if (lcd_scroll_info.lines >= LCD_SCROLLABLE_LINES) return; - s = &lcd_scroll_info.scroll[y]; + s = &lcd_scroll_info.scroll[lcd_scroll_info.lines]; s->start_tick = current_tick + lcd_scroll_info.delay; s->style = style; @@ -1031,7 +1141,7 @@ void lcd_puts_scroll_style_offset(int x, int y, const unsigned char *string, lcd_getstringsize(string, &w, &h); - if (LCD_WIDTH - x * 8 - xmargin < w) { + if (current_vp->width - x * 8 - current_vp->xmargin < w) { /* prepare scroll line */ char *end; @@ -1044,7 +1154,7 @@ void lcd_puts_scroll_style_offset(int x, int y, const unsigned char *string, /* scroll bidirectional or forward only depending on the string width */ if ( lcd_scroll_info.bidir_limit ) { - s->bidir = s->width < (LCD_WIDTH - xmargin) * + s->bidir = s->width < (current_vp->width - current_vp->xmargin) * (100 + lcd_scroll_info.bidir_limit) / 100; } else @@ -1057,17 +1167,17 @@ void lcd_puts_scroll_style_offset(int x, int y, const unsigned char *string, } end = strchr(s->line, '\0'); - strncpy(end, (char *)string, LCD_WIDTH/2); + strncpy(end, (char *)string, current_vp->width/2); + s->vp = current_vp; + s->y = y; s->len = utf8length((char *)string); s->offset = offset; - s->startx = xmargin + x * s->width / s->len; + s->startx = current_vp->xmargin + x * s->width / s->len; s->backward = false; - lcd_scroll_info.lines |= (1<start_tick)) continue; + lcd_set_viewport(s->vp); + if (s->backward) s->offset -= lcd_scroll_info.step; else s->offset += lcd_scroll_info.step; - pf = font_get(curfont); + pf = font_get(current_vp->font); xpos = s->startx; - ypos = ymargin + index * pf->height; + ypos = current_vp->ymargin + s->y * pf->height; if (s->bidir) { /* scroll bidirectional */ if (s->offset <= 0) { @@ -1105,9 +1214,9 @@ void lcd_scroll_fn(void) s->backward = false; s->start_tick = current_tick + lcd_scroll_info.delay * 2; } - if (s->offset >= s->width - (LCD_WIDTH - xpos)) { + if (s->offset >= s->width - (current_vp->width - xpos)) { /* at end of line */ - s->offset = s->width - (LCD_WIDTH - xpos); + s->offset = s->width - (current_vp->width - xpos); s->backward = true; s->start_tick = current_tick + lcd_scroll_info.delay * 2; } @@ -1118,11 +1227,14 @@ void lcd_scroll_fn(void) s->offset %= s->width; } - lastmode = drawmode; - drawmode = (s->style&STYLE_INVERT) ? - (DRMODE_SOLID|DRMODE_INVERSEVID) : DRMODE_SOLID; + lastmode = current_vp->drawmode; + current_vp->drawmode = (s->style&STYLE_INVERT) ? + (DRMODE_SOLID|DRMODE_INVERSEVID) : DRMODE_SOLID; lcd_putsxyofs(xpos, ypos, s->offset, s->line); - drawmode = lastmode; - lcd_update_rect(xpos, ypos, LCD_WIDTH - xpos, pf->height); + current_vp->drawmode = lastmode; + lcd_update_viewport_rect(xpos, ypos, + current_vp->width - xpos, pf->height); } + + lcd_set_viewport(old_vp); } -- cgit v1.2.3