diff options
author | William Wilgus <wilgus.william@gmail.com> | 2020-10-07 02:01:35 -0400 |
---|---|---|
committer | William Wilgus <wilgus.william@gmail.com> | 2020-10-26 12:28:48 -0400 |
commit | 3237ae4a4ff9296a377ff9194a11038da161208f (patch) | |
tree | af4338c78467b9b0845d76c39da1fbe10f25e23e /firmware/drivers/lcd-2bit-vi.c | |
parent | 12f3ed1699d6bef25bed90ba95cbcc1a6bb4934a (diff) |
LCD core move buf ptr and address look up function viewport struct
I'm currently running up against the limitations of the lcd_draw functions
I want these functions to be able to be used on any size buffer not
just buffers with a stride matching the underlying device
[DONE] allow the framebuffer to be decoupled from the device framebuffer
[DONE need examples] allow for some simple blit like transformations
[DONE] remove the device framebuffer from the plugin api
[DONE}ditto remote framebuffer
[DONE] remove _viewport_get_framebuffer you can call struct *vp = lcd_set_viewport(NULL) and vp->buffer->fb_ptr
while remote lcds may compile (and work in the sim) its not been tested on targets
[FIXED] backdrops need work to be screen agnostic
[FIXED] screen statusbar is not being combined into the main viewport correctly yet
[FIXED] screen elements are displayed incorrectly after switch to void*
[FIXED] core didn't restore proper viewport on splash etc.
[NEEDS TESTING] remote lcd garbled data
[FIXED] osd lib garbled screen on bmp_part
[FIXED] grey_set_vp needs to return old viewport like lcd_set_viewport
[FIXED] Viewport update now handles viewports with differing buffers/strides by copying to the main buffer
[FIXED] splash on top of WPS leaves old framebuffer data (doesn't redraw)
[UPDATE] refined this a bit more to have clear_viewport set the clean bit and have skin_render do its own screen clear
scrolling viewports no longer trigger wps refresh
also fixed a bug where guisyncyesno was displaying and then disappearing
[ADDED!] New LCD macros that allow you to create properly size frame buffers in you desired size without wasting bytes
(LCD_ and LCD_REMOTE_)
LCD_STRIDE(w, h) same as STRIDE_MAIN
LCD_FBSTRIDE(w, h) returns target specific stride for a buffer W x H
LCD_NBELEMS(w, h) returns the number of fb_data sized elemenst needed for a buffer W x H
LCD_NATIVE_STRIDE(s) conversion between rockbox native vertical and lcd native stride (2bitH)
test_viewports.c has an example of usage
[FIXED!!] 2bit targets don't respect non-native strides
[FIXED] Few define snags
Change-Id: I0d04c3834e464eca84a5a715743a297a0cefd0af
Diffstat (limited to 'firmware/drivers/lcd-2bit-vi.c')
-rw-r--r-- | firmware/drivers/lcd-2bit-vi.c | 202 |
1 files changed, 121 insertions, 81 deletions
diff --git a/firmware/drivers/lcd-2bit-vi.c b/firmware/drivers/lcd-2bit-vi.c index 0608dfaa46..035e8b6d0d 100644 --- a/firmware/drivers/lcd-2bit-vi.c +++ b/firmware/drivers/lcd-2bit-vi.c @@ -46,17 +46,32 @@ #define MAIN_LCD #endif -/*** globals ***/ +#ifdef MAIN_LCD +#define THIS_STRIDE STRIDE_MAIN +#else +#define THIS_STRIDE STRIDE_REMOTE +#endif -FBFN(data) LCDFN(static_framebuffer)[LCDM(FBHEIGHT)][LCDM(FBWIDTH)] IRAM_LCDFRAMEBUFFER; -FBFN(data) *LCDFN(framebuffer) = &LCDFN(static_framebuffer)[0][0]; +#define CURRENT_VP LCDFN(current_viewport) +/*** globals ***/ +static FBFN(data) LCDFN(static_framebuffer)[LCDM(FBHEIGHT)][LCDM(FBWIDTH)] IRAM_LCDFRAMEBUFFER; +static void *LCDFN(frameaddress_default)(int x, int y); static const FBFN(data) patterns[4] = {0xFFFF, 0xFF00, 0x00FF, 0x0000}; static FBFN(data) *backdrop = NULL; static long backdrop_offset IDATA_ATTR = 0; +/* shouldn't be changed unless you want system-wide framebuffer changes! */ +struct frame_buffer_t LCDFN(framebuffer_default) = +{ + .FBFN(ptr) = &LCDFN(static_framebuffer)[0][0], + .get_address_fn = &LCDFN(frameaddress_default), + .stride = THIS_STRIDE(LCDM(WIDTH), LCDM(HEIGHT)), + .elems = (LCDM(FBWIDTH)*LCDM(FBHEIGHT)), +}; + static struct viewport default_vp = { .x = 0, @@ -65,19 +80,34 @@ static struct viewport default_vp = .height = LCDM(HEIGHT), .font = FONT_SYSFIXED, .drawmode = DRMODE_SOLID, + .buffer = NULL, .fg_pattern = LCDM(DEFAULT_FG), .bg_pattern = LCDM(DEFAULT_BG) }; -static struct viewport * current_vp IBSS_ATTR; +struct viewport * CURRENT_VP IBSS_ATTR; static unsigned fg_pattern IBSS_ATTR; static unsigned bg_pattern IBSS_ATTR; +static void *LCDFN(frameaddress_default)(int x, int y) +{ + /* the default expects a buffer the same size as the screen */ + struct frame_buffer_t *fb = CURRENT_VP->buffer; +#if defined(LCD_STRIDEFORMAT) && LCD_STRIDEFORMAT == VERTICAL_STRIDE + size_t element = (x * LCDM(NATIVE_STRIDE)(fb->stride)) + y; +#else + size_t element = (y * LCDM(NATIVE_STRIDE)(fb->stride)) + x; +#endif + return fb->FBFN(ptr) + element;/*(element % fb->elems);*/ +} + /* LCD init */ void LCDFN(init)(void) { + /* Initialize the viewport */ LCDFN(set_viewport)(NULL); + LCDFN(clear_display)(); LCDFN(init_device)(); #ifdef MAIN_LCD @@ -105,34 +135,34 @@ unsigned lcd_remote_color_to_native(unsigned color) void LCDFN(set_drawmode)(int mode) { - current_vp->drawmode = mode & (DRMODE_SOLID|DRMODE_INVERSEVID); + CURRENT_VP->drawmode = mode & (DRMODE_SOLID|DRMODE_INVERSEVID); } int LCDFN(get_drawmode)(void) { - return current_vp->drawmode; + return CURRENT_VP->drawmode; } void LCDFN(set_foreground)(unsigned brightness) { - current_vp->fg_pattern = brightness; + CURRENT_VP->fg_pattern = brightness; fg_pattern = patterns[brightness & 3]; } unsigned LCDFN(get_foreground)(void) { - return current_vp->fg_pattern; + return CURRENT_VP->fg_pattern; } void LCDFN(set_background)(unsigned brightness) { - current_vp->bg_pattern = brightness; + CURRENT_VP->bg_pattern = brightness; bg_pattern = patterns[brightness & 3]; } unsigned LCDFN(get_background)(void) { - return current_vp->bg_pattern; + return CURRENT_VP->bg_pattern; } void LCDFN(set_drawinfo)(int mode, unsigned fg_brightness, @@ -145,26 +175,26 @@ void LCDFN(set_drawinfo)(int mode, unsigned fg_brightness, int LCDFN(getwidth)(void) { - return current_vp->width; + return CURRENT_VP->width; } int LCDFN(getheight)(void) { - return current_vp->height; + return CURRENT_VP->height; } void LCDFN(setfont)(int newfont) { - current_vp->font = newfont; + CURRENT_VP->font = newfont; } int LCDFN(getfont)(void) { - return current_vp->font; + return CURRENT_VP->font; } int LCDFN(getstringsize)(const unsigned char *str, int *w, int *h) { - return font_getstringsize(str, w, h, current_vp->font); + return font_getstringsize(str, w, h, CURRENT_VP->font); } /*** low-level drawing functions ***/ @@ -345,7 +375,7 @@ void LCDFN(set_backdrop)(FBFN(data) *bd) backdrop = bd; if (bd) { - backdrop_offset = (long)bd - (long)LCDFN(framebuffer); + backdrop_offset = (long)bd - (long)LCDFB(0, 0); LCDFN(pixelfuncs) = LCDFN(pixelfuncs_backdrop); LCDFN(blockfuncs) = LCDFN(blockfuncs_backdrop); } @@ -377,15 +407,15 @@ void LCDFN(clear_display)(void) { if (default_vp.drawmode & DRMODE_INVERSEVID) { - memset(LCDFN(framebuffer), patterns[default_vp.fg_pattern & 3], + memset(LCDFB(0, 0), patterns[default_vp.fg_pattern & 3], FBSIZE); } else { if (backdrop) - memcpy(LCDFN(framebuffer), backdrop, FBSIZE); + memcpy(LCDFB(0, 0), backdrop, FBSIZE); else - memset(LCDFN(framebuffer), patterns[default_vp.bg_pattern & 3], + memset(LCDFB(0, 0), patterns[default_vp.bg_pattern & 3], FBSIZE); } @@ -397,37 +427,39 @@ void LCDFN(clear_viewport)(void) { int lastmode; - if (current_vp == &default_vp) + if (CURRENT_VP == &default_vp && + default_vp.buffer == &LCDFN(framebuffer_default)) { LCDFN(clear_display)(); } else { - lastmode = current_vp->drawmode; + lastmode = CURRENT_VP->drawmode; /* Invert the INVERSEVID bit and set basic mode to SOLID */ - current_vp->drawmode = (~lastmode & DRMODE_INVERSEVID) | + CURRENT_VP->drawmode = (~lastmode & DRMODE_INVERSEVID) | DRMODE_SOLID; - LCDFN(fillrect)(0, 0, current_vp->width, current_vp->height); + LCDFN(fillrect)(0, 0, CURRENT_VP->width, CURRENT_VP->height); - current_vp->drawmode = lastmode; + CURRENT_VP->drawmode = lastmode; - LCDFN(scroll_stop_viewport)(current_vp); + LCDFN(scroll_stop_viewport)(CURRENT_VP); } + CURRENT_VP->flags &= ~(VP_FLAG_VP_SET_CLEAN); } /* Set a single pixel */ void LCDFN(drawpixel)(int x, int y) { - if ( ((unsigned)x < (unsigned)current_vp->width) - && ((unsigned)y < (unsigned)current_vp->height) + if ( ((unsigned)x < (unsigned)CURRENT_VP->width) + && ((unsigned)y < (unsigned)CURRENT_VP->height) #if defined(HAVE_VIEWPORT_CLIP) && ((unsigned)x < (unsigned)LCDM(WIDTH)) && ((unsigned)y < (unsigned)LCDM(HEIGHT)) #endif ) - LCDFN(pixelfuncs)[current_vp->drawmode](current_vp->x+x, current_vp->y+y); + LCDFN(pixelfuncs)[CURRENT_VP->drawmode](CURRENT_VP->x+x, CURRENT_VP->y+y); } /* Draw a line */ @@ -439,7 +471,7 @@ void LCDFN(drawline)(int x1, int y1, int x2, int y2) int d, dinc1, dinc2; int x, xinc1, xinc2; int y, yinc1, yinc2; - LCDFN(pixelfunc_type) *pfunc = LCDFN(pixelfuncs)[current_vp->drawmode]; + LCDFN(pixelfunc_type) *pfunc = LCDFN(pixelfuncs)[CURRENT_VP->drawmode]; deltax = abs(x2 - x1); if (deltax == 0) @@ -495,14 +527,14 @@ void LCDFN(drawline)(int x1, int y1, int x2, int y2) for (i = 0; i < numpixels; i++) { - if ( ((unsigned)x < (unsigned)current_vp->width) - && ((unsigned)y < (unsigned)current_vp->height) + if ( ((unsigned)x < (unsigned)CURRENT_VP->width) + && ((unsigned)y < (unsigned)CURRENT_VP->height) #if defined(HAVE_VIEWPORT_CLIP) && ((unsigned)x < (unsigned)LCDM(WIDTH)) && ((unsigned)y < (unsigned)LCDM(HEIGHT)) #endif ) - pfunc(current_vp->x + x, current_vp->y + y); + pfunc(CURRENT_VP->x + x, CURRENT_VP->y + y); if (d < 0) { @@ -538,19 +570,19 @@ void LCDFN(hline)(int x1, int x2, int y) /******************** In viewport clipping **********************/ /* nothing to draw? */ - if (((unsigned)y >= (unsigned)current_vp->height) || (x1 >= current_vp->width) + if (((unsigned)y >= (unsigned)CURRENT_VP->height) || (x1 >= CURRENT_VP->width) || (x2 < 0)) return; if (x1 < 0) x1 = 0; - if (x2 >= current_vp->width) - x2 = current_vp->width-1; + if (x2 >= CURRENT_VP->width) + x2 = CURRENT_VP->width-1; /* adjust x1 and y to viewport */ - x1 += current_vp->x; - x2 += current_vp->x; - y += current_vp->y; + x1 += CURRENT_VP->x; + x2 += CURRENT_VP->x; + y += CURRENT_VP->y; #if defined(HAVE_VIEWPORT_CLIP) /********************* Viewport on screen clipping ********************/ @@ -568,7 +600,7 @@ void LCDFN(hline)(int x1, int x2, int y) width = x2 - x1 + 1; - bfunc = LCDFN(blockfuncs)[current_vp->drawmode]; + bfunc = LCDFN(blockfuncs)[CURRENT_VP->drawmode]; dst = LCDFB(x1,y>>3); mask = 0x0101 << (y & 7); @@ -583,6 +615,7 @@ void LCDFN(vline)(int x, int y1, int y2) { int ny; FBFN(data) *dst; + int stride_dst; unsigned mask, mask_bottom; LCDFN(blockfunc_type) *bfunc; @@ -596,19 +629,19 @@ void LCDFN(vline)(int x, int y1, int y2) /******************** In viewport clipping **********************/ /* nothing to draw? */ - if (((unsigned)x >= (unsigned)current_vp->width) || (y1 >= current_vp->height) + if (((unsigned)x >= (unsigned)CURRENT_VP->width) || (y1 >= CURRENT_VP->height) || (y2 < 0)) return; if (y1 < 0) y1 = 0; - if (y2 >= current_vp->height) - y2 = current_vp->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; + y1 += CURRENT_VP->y; + y2 += CURRENT_VP->y; + x += CURRENT_VP->x; #if defined(HAVE_VIEWPORT_CLIP) /********************* Viewport on screen clipping ********************/ @@ -624,8 +657,9 @@ void LCDFN(vline)(int x, int y1, int y2) y2 = LCDM(HEIGHT)-1; #endif - bfunc = LCDFN(blockfuncs)[current_vp->drawmode]; + bfunc = LCDFN(blockfuncs)[CURRENT_VP->drawmode]; dst = LCDFB(x,y1>>3); + stride_dst = CURRENT_VP->buffer->stride; ny = y2 - (y1 & ~7); mask = (0xFFu << (y1 & 7)) & 0xFFu; mask |= mask << 8; @@ -635,7 +669,7 @@ void LCDFN(vline)(int x, int y1, int y2) for (; ny >= 8; ny -= 8) { bfunc(dst, mask, 0xFFFFu); - dst += LCDM(WIDTH); + dst += stride_dst; mask = 0xFFFFu; } mask &= mask_bottom; @@ -662,6 +696,7 @@ void LCDFN(fillrect)(int x, int y, int width, int height) { int ny; FBFN(data) *dst, *dst_end; + int stride_dst; unsigned mask, mask_bottom; unsigned bits = 0; LCDFN(blockfunc_type) *bfunc; @@ -669,8 +704,8 @@ void LCDFN(fillrect)(int x, int y, int width, int height) /******************** In viewport clipping **********************/ /* nothing to draw? */ - if ((width <= 0) || (height <= 0) || (x >= current_vp->width) - || (y >= current_vp->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; if (x < 0) @@ -683,14 +718,14 @@ void LCDFN(fillrect)(int x, int y, int width, int height) height += y; y = 0; } - if (x + width > current_vp->width) - width = current_vp->width - x; - if (y + height > current_vp->height) - height = current_vp->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; + x += CURRENT_VP->x; + y += CURRENT_VP->y; #if defined(HAVE_VIEWPORT_CLIP) /********************* Viewport on screen clipping ********************/ @@ -717,9 +752,9 @@ void LCDFN(fillrect)(int x, int y, int width, int height) #endif - if (current_vp->drawmode & DRMODE_INVERSEVID) + if (CURRENT_VP->drawmode & DRMODE_INVERSEVID) { - if ((current_vp->drawmode & DRMODE_BG) && !backdrop) + if ((CURRENT_VP->drawmode & DRMODE_BG) && !backdrop) { fillopt = true; bits = bg_pattern; @@ -727,14 +762,15 @@ void LCDFN(fillrect)(int x, int y, int width, int height) } else { - if (current_vp->drawmode & DRMODE_FG) + if (CURRENT_VP->drawmode & DRMODE_FG) { fillopt = true; bits = fg_pattern; } } - bfunc = LCDFN(blockfuncs)[current_vp->drawmode]; + bfunc = LCDFN(blockfuncs)[CURRENT_VP->drawmode]; dst = LCDFB(x,y>>3); + stride_dst = CURRENT_VP->buffer->stride; ny = height - 1 + (y & 7); mask = (0xFFu << (y & 7)) & 0xFFu; mask |= mask << 8; @@ -755,7 +791,7 @@ void LCDFN(fillrect)(int x, int y, int width, int height) while (dst_row < dst_end); } - dst += LCDM(WIDTH); + dst += stride_dst; mask = 0xFFFFu; } mask &= mask_bottom; @@ -789,13 +825,14 @@ void ICODE_ATTR LCDFN(mono_bitmap_part)(const unsigned char *src, int src_x, { int shift, ny; FBFN(data) *dst, *dst_end; + int stride_dst; unsigned data, mask, mask_bottom; LCDFN(blockfunc_type) *bfunc; /******************** Image in viewport clipping **********************/ /* nothing to draw? */ - if ((width <= 0) || (height <= 0) || (x >= current_vp->width) || - (y >= current_vp->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; if (x < 0) @@ -810,14 +847,14 @@ void ICODE_ATTR LCDFN(mono_bitmap_part)(const unsigned char *src, int src_x, src_y -= y; y = 0; } - if (x + width > current_vp->width) - width = current_vp->width - x; - if (y + height > current_vp->height) - height = current_vp->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; + x += CURRENT_VP->x; + y += CURRENT_VP->y; #if defined(HAVE_VIEWPORT_CLIP) /********************* Viewport on screen clipping ********************/ @@ -849,10 +886,11 @@ void ICODE_ATTR LCDFN(mono_bitmap_part)(const unsigned char *src, int src_x, src_y &= 7; y -= src_y; dst = LCDFB(x,y>>3); + stride_dst = CURRENT_VP->buffer->stride; shift = y & 7; ny = height - 1 + shift + src_y; - bfunc = LCDFN(blockfuncs)[current_vp->drawmode]; + bfunc = LCDFN(blockfuncs)[CURRENT_VP->drawmode]; mask = 0xFFu << (shift + src_y); /* not byte-doubled here because shift+src_y can be > 7 */ mask_bottom = 0xFFu >> (~ny & 7); @@ -877,7 +915,7 @@ void ICODE_ATTR LCDFN(mono_bitmap_part)(const unsigned char *src, int src_x, while (dst_row < dst_end); src += stride; - dst += LCDM(WIDTH); + dst += stride_dst; mask = 0xFFFFu; } mask &= mask_bottom; @@ -921,7 +959,7 @@ void ICODE_ATTR LCDFN(mono_bitmap_part)(const unsigned char *src, int src_x, } src_col += stride; - dst_col += LCDM(WIDTH); + dst_col += stride_dst; data >>= 8; } data |= *src_col << shift; @@ -958,12 +996,13 @@ void ICODE_ATTR LCDFN(bitmap_part)(const FBFN(data) *src, int src_x, { int shift, ny; FBFN(data) *dst, *dst_end; + int stride_dst; unsigned mask, mask_bottom; /******************** Image in viewport clipping **********************/ /* nothing to draw? */ - if ((width <= 0) || (height <= 0) || (x >= current_vp->width) - || (y >= current_vp->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; if (x < 0) @@ -978,14 +1017,14 @@ void ICODE_ATTR LCDFN(bitmap_part)(const FBFN(data) *src, int src_x, src_y -= y; y = 0; } - if (x + width > current_vp->width) - width = current_vp->width - x; - if (y + height > current_vp->height) - height = current_vp->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; + x += CURRENT_VP->x; + y += CURRENT_VP->y; #if defined(HAVE_VIEWPORT_CLIP) /********************* Viewport on screen clipping ********************/ @@ -1017,6 +1056,7 @@ void ICODE_ATTR LCDFN(bitmap_part)(const FBFN(data) *src, int src_x, src_y &= 7; y -= src_y; dst = LCDFB(x,y>>3); + stride_dst = CURRENT_VP->buffer->stride; shift = y & 7; ny = height - 1 + shift + src_y; @@ -1045,7 +1085,7 @@ void ICODE_ATTR LCDFN(bitmap_part)(const FBFN(data) *src, int src_x, while (dst_row < dst_end); } src += stride; - dst += LCDM(WIDTH); + dst += stride_dst; mask = 0xFFFFu; } mask &= mask_bottom; @@ -1092,7 +1132,7 @@ void ICODE_ATTR LCDFN(bitmap_part)(const FBFN(data) *src, int src_x, mask_col |= mask_col << 8; } src_col += stride; - dst_col += LCDM(WIDTH); + dst_col += stride_dst; olddata = data >> 8; } data = *src_col << shift; |