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-horz.c | 277 +++++++++++++++++++++++++++------------ 1 file changed, 192 insertions(+), 85 deletions(-) (limited to 'firmware/drivers/lcd-2bit-horz.c') diff --git a/firmware/drivers/lcd-2bit-horz.c b/firmware/drivers/lcd-2bit-horz.c index 32ebfa7f81..1ee0addba4 100644 --- a/firmware/drivers/lcd-2bit-horz.c +++ b/firmware/drivers/lcd-2bit-horz.c @@ -46,52 +46,92 @@ 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->bg_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) @@ -103,28 +143,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 ***/ @@ -345,7 +395,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); } @@ -360,11 +410,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 */ @@ -376,7 +452,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); @@ -420,8 +496,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) { @@ -455,16 +532,22 @@ 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; + if (x2 >= current_vp->width) + x2 = current_vp->width-1; - bfunc = lcd_blockfuncs[drawmode]; + /* adjust to viewport */ + x1 += current_vp->x; + x2 += current_vp->x; + y += current_vp->y; + + bfunc = lcd_blockfuncs[current_vp->drawmode]; dst = &lcd_framebuffer[y][x1>>2]; nx = x2 - (x1 & ~3); mask = 0xFFu >> (2 * (x1 & 3)); @@ -496,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; + + /* adjust for viewport */ + y1 += current_vp->y; + y2 += current_vp->y; + x += current_vp->x; - bfunc = lcd_blockfuncs[drawmode]; + bfunc = lcd_blockfuncs[current_vp->drawmode]; dst = &lcd_framebuffer[y1][x>>2]; mask = pixmask[x & 3]; @@ -542,7 +631,7 @@ void lcd_fillrect(int x, int y, int width, int height) lcd_blockfunc_type *bfunc; /* nothing to draw? */ - if ((width <= 0) || (height <= 0) || (x >= LCD_WIDTH) || (y >= LCD_HEIGHT) + if ((width <= 0) || (height <= 0) || (x >= current_vp->width) || (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0)) return; @@ -557,12 +646,16 @@ 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; + + /* adjust for viewport */ + x += current_vp->x; + y += current_vp->y; - bfunc = lcd_blockfuncs[drawmode]; + bfunc = lcd_blockfuncs[current_vp->drawmode]; dst = &lcd_framebuffer[y][x>>2]; nx = width - 1 + (x & 3); mask = 0xFFu >> (2 * (x & 3)); @@ -616,8 +709,8 @@ void lcd_mono_bitmap_part(const unsigned char *src, int src_x, int src_y, lcd_pixelfunc_type* bgfunc; /* 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 */ @@ -633,17 +726,21 @@ 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; src_end = src + width; - fgfunc = lcd_pixelfuncs[drawmode]; - bgfunc = lcd_pixelfuncs[drawmode ^ DRMODE_INVERSEVID]; + fgfunc = lcd_pixelfuncs[current_vp->drawmode]; + bgfunc = lcd_pixelfuncs[current_vp->drawmode ^ DRMODE_INVERSEVID]; nx = x; do { @@ -704,8 +801,8 @@ void lcd_bitmap_part(const unsigned char *src, int src_x, int src_y, unsigned mask, mask_right; /* 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 */ @@ -721,10 +818,14 @@ void lcd_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; stride = (stride + 3) >> 2; /* convert to no. of bytes */ @@ -781,11 +882,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; @@ -839,24 +940,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 ***/ @@ -881,9 +982,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); - s = &lcd_scroll_info.scroll[y]; + if (lcd_scroll_info.lines >= LCD_SCROLLABLE_LINES) return; + + s = &lcd_scroll_info.scroll[lcd_scroll_info.lines]; s->start_tick = current_tick + lcd_scroll_info.delay; s->style = style; @@ -895,7 +1002,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; @@ -908,7 +1015,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 @@ -921,17 +1028,16 @@ 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) { @@ -969,9 +1074,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; } @@ -982,11 +1087,13 @@ 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