From 54ea2e435e1a5688de4e4dcf551a1fc9c1db323f Mon Sep 17 00:00:00 2001 From: Jens Arnold Date: Sat, 31 Mar 2007 09:58:49 +0000 Subject: Charcell lcd driver: Preparations for switching to non-immediate LCD updates, using lcd_update() like on bitmap targets. * Added proper clipping. * Simplified simulator code. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12979 a1c6a512-1295-4272-9138-f99709370657 --- uisimulator/sdl/SOURCES | 2 +- uisimulator/sdl/button.c | 2 +- uisimulator/sdl/lcd-charcell.c | 222 ---------------------------------------- uisimulator/sdl/lcd-charcell.h | 32 ------ uisimulator/sdl/lcd-charcells.c | 179 ++++++++++++++++++++++++++++++++ uisimulator/sdl/lcd-charcells.h | 32 ++++++ uisimulator/sdl/uisdl.c | 2 +- 7 files changed, 214 insertions(+), 257 deletions(-) delete mode 100644 uisimulator/sdl/lcd-charcell.c delete mode 100644 uisimulator/sdl/lcd-charcell.h create mode 100644 uisimulator/sdl/lcd-charcells.c create mode 100644 uisimulator/sdl/lcd-charcells.h (limited to 'uisimulator/sdl') diff --git a/uisimulator/sdl/SOURCES b/uisimulator/sdl/SOURCES index 8f1f3e2fd7..e563cb984d 100644 --- a/uisimulator/sdl/SOURCES +++ b/uisimulator/sdl/SOURCES @@ -3,7 +3,7 @@ kernel.c #ifdef HAVE_LCD_BITMAP lcd-bitmap.c #elif defined(HAVE_LCD_CHARCELLS) -lcd-charcell.c +lcd-charcells.c #endif #ifdef HAVE_REMOTE_LCD lcd-remote-bitmap.c diff --git a/uisimulator/sdl/button.c b/uisimulator/sdl/button.c index 76a41f2230..4b03008497 100644 --- a/uisimulator/sdl/button.c +++ b/uisimulator/sdl/button.c @@ -18,7 +18,7 @@ ****************************************************************************/ #include "uisdl.h" -#include "lcd-charcell.h" +#include "lcd-charcells.h" #include "lcd-remote.h" #include "config.h" #include "button.h" diff --git a/uisimulator/sdl/lcd-charcell.c b/uisimulator/sdl/lcd-charcell.c deleted file mode 100644 index 8849efc7cd..0000000000 --- a/uisimulator/sdl/lcd-charcell.c +++ /dev/null @@ -1,222 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2006 Dan Everton - * - * All files in this archive are subject to the GNU General Public License. - * See the file COPYING in the source tree root for full license agreement. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ - -#include "debug.h" -#include "lcd.h" -#include "misc.h" -#include -#include -#include - -#include "lcd-playersim.h" -#include "uisdl.h" -#include "lcd-sdl.h" - -/* extern functions, needed for screendump() */ -extern int sim_creat(const char *name); - -SDL_Surface* lcd_surface; -SDL_Color lcd_color_zero = {UI_LCD_BGCOLOR, 0}; -SDL_Color lcd_backlight_color_zero = {UI_LCD_BGCOLORLIGHT, 0}; -SDL_Color lcd_color_max = {0, 0, 0, 0}; - -/* Defined in lcd-playersim.c */ -extern void lcd_print_char(int x, int y); - -void lcd_update(void) -{ - int x, y; - SDL_Rect dest = {UI_LCD_POSX, UI_LCD_POSY, UI_LCD_WIDTH, UI_LCD_HEIGHT}; - - SDL_LockSurface(lcd_surface); - - for (y=0; y<2; y++) { - for (x=0; x<11; x++) { - lcd_print_char(x, y); - } - } - - SDL_UnlockSurface(lcd_surface); - - if (!background) { - dest.x -= UI_LCD_POSX; - dest.y -= UI_LCD_POSY; - } - - SDL_BlitSurface(lcd_surface, NULL, gui_surface, &dest); - SDL_UpdateRect(gui_surface, dest.x, dest.y, dest.w, dest.h); - SDL_Flip(gui_surface); -} - -void drawdots(int color, struct coordinate *points, int count) -{ - SDL_Rect dest; - Uint32 sdlcolor; - - SDL_LockSurface(lcd_surface); - - if (color == 1) { - sdlcolor = SDL_MapRGB(lcd_surface->format, lcd_color_max.r, lcd_color_max.g, lcd_color_max.b); - } else { - sdlcolor = SDL_MapRGB(lcd_surface->format, lcd_color_zero.r, lcd_color_zero.g, lcd_color_zero.b); - } - - while (count--) { - dest.x = points[count].x * display_zoom; - dest.y = points[count].y * display_zoom; - dest.w = 1 * display_zoom; - dest.h = 1 * display_zoom; - - SDL_FillRect(lcd_surface, &dest, sdlcolor); - } - - SDL_UnlockSurface(lcd_surface); -} - -void drawrectangles(int color, struct rectangle *points, int count) -{ - SDL_Rect dest; - Uint32 sdlcolor; - - SDL_LockSurface(lcd_surface); - - if (color == 1) { - sdlcolor = SDL_MapRGB(lcd_surface->format, lcd_color_max.r, lcd_color_max.g, lcd_color_max.b); - } else { - sdlcolor = SDL_MapRGB(lcd_surface->format, lcd_color_zero.r, lcd_color_zero.g, lcd_color_zero.b); - } - - while (count--) { - dest.x = points[count].x * display_zoom; - dest.y = points[count].y * display_zoom; - dest.w = points[count].width * display_zoom; - dest.h = points[count].height * display_zoom; - - SDL_FillRect(lcd_surface, &dest, sdlcolor); - } - - SDL_UnlockSurface(lcd_surface); -} - -#if CONFIG_BACKLIGHT -void sim_backlight(int value) -{ - if (value > 0) { - sdl_set_gradient(lcd_surface, &lcd_backlight_color_zero, &lcd_color_max, - 0, (1<>8)&0xff -#define LE32_CONST(x) (x)&0xff, ((x)>>8)&0xff, ((x)>>16)&0xff, ((x)>>24)&0xff - -static const unsigned char bmpheader[] = -{ - 0x42, 0x4d, /* 'BM' */ - LE32_CONST(BMP_TOTALSIZE), /* Total file size */ - 0x00, 0x00, 0x00, 0x00, /* Reserved */ - LE32_CONST(BMP_HEADERSIZE), /* Offset to start of pixel data */ - - 0x28, 0x00, 0x00, 0x00, /* Size of (2nd) header */ - LE32_CONST(SIM_LCD_WIDTH), /* Width in pixels */ - LE32_CONST(SIM_LCD_HEIGHT), /* Height in pixels */ - 0x01, 0x00, /* Number of planes (always 1) */ - LE16_CONST(BMP_BPP), /* Bits per pixel 1/4/8/16/24 */ - LE32_CONST(BMP_COMPRESSION),/* Compression mode */ - LE32_CONST(BMP_DATASIZE), /* Size of bitmap data */ - 0xc4, 0x0e, 0x00, 0x00, /* Horizontal resolution (pixels/meter) */ - 0xc4, 0x0e, 0x00, 0x00, /* Vertical resolution (pixels/meter) */ - LE32_CONST(BMP_NUMCOLORS), /* Number of used colours */ - LE32_CONST(BMP_NUMCOLORS), /* Number of important colours */ - - 0x90, 0xee, 0x90, 0x00, /* Colour #0 */ - 0x00, 0x00, 0x00, 0x00 /* Colour #1 */ -}; - -void screen_dump(void) -{ - int fd; - char filename[MAX_PATH]; - int x, y; - static unsigned char line[BMP_LINESIZE]; - - create_numbered_filename(filename, "", "dump_", ".bmp", 4 - IF_CNFN_NUM_(, NULL)); - DEBUGF("screen_dump\n"); - - fd = sim_creat(filename); - if (fd < 0) - return; - - write(fd, bmpheader, sizeof(bmpheader)); - SDL_LockSurface(lcd_surface); - - /* BMP image goes bottom up */ - for (y = SIM_LCD_HEIGHT - 1; y >= 0; y--) - { - Uint8 *src = (Uint8 *)lcd_surface->pixels - + y * SIM_LCD_WIDTH * display_zoom * display_zoom; - unsigned char *dst = line; - unsigned dst_mask = 0x80; - - memset(line, 0, sizeof(line)); - for (x = SIM_LCD_WIDTH; x > 0; x--) - { - if (*src) - *dst |= dst_mask; - src += display_zoom; - dst_mask >>= 1; - if (dst_mask == 0) - { - dst++; - dst_mask = 0x80; - } - } - write(fd, line, sizeof(line)); - } - SDL_UnlockSurface(lcd_surface); - close(fd); -} diff --git a/uisimulator/sdl/lcd-charcell.h b/uisimulator/sdl/lcd-charcell.h deleted file mode 100644 index 6b1e85e549..0000000000 --- a/uisimulator/sdl/lcd-charcell.h +++ /dev/null @@ -1,32 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2006 Dan Everton - * - * All files in this archive are subject to the GNU General Public License. - * See the file COPYING in the source tree root for full license agreement. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ - -#ifndef __LCDCHARCELL_H__ -#define __LCDCHARCELL_H__ - -#include "lcd.h" -#include "SDL.h" - -#ifdef HAVE_LCD_CHARCELLS -void sim_lcd_init(void); -void screen_dump(void); -#endif - -#endif /* #ifndef __LCDCHARCELL_H__ */ - diff --git a/uisimulator/sdl/lcd-charcells.c b/uisimulator/sdl/lcd-charcells.c new file mode 100644 index 0000000000..5a08179232 --- /dev/null +++ b/uisimulator/sdl/lcd-charcells.c @@ -0,0 +1,179 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2006 Dan Everton + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "debug.h" +#include "lcd.h" +#include "lcd-charcell.h" +#include "misc.h" +#include +#include +#include + +#include "lcd-playersim.h" +#include "uisdl.h" +#include "lcd-sdl.h" + +/* extern functions, needed for screendump() */ +extern int sim_creat(const char *name); + +SDL_Surface* lcd_surface; +SDL_Color lcd_color_zero = {UI_LCD_BGCOLOR, 0}; +SDL_Color lcd_backlight_color_zero = {UI_LCD_BGCOLORLIGHT, 0}; +SDL_Color lcd_color_max = {0, 0, 0, 0}; + + +static unsigned long get_lcd_pixel(int x, int y) +{ + return sim_lcd_framebuffer[y][x]; +} + +void sim_lcd_update_rect(int x_start, int y_start, int width, int height) +{ + sdl_update_rect(lcd_surface, x_start, y_start, width, height, + SIM_LCD_WIDTH, SIM_LCD_HEIGHT, get_lcd_pixel); + sdl_gui_update(lcd_surface, x_start, y_start, width, height, + SIM_LCD_WIDTH, SIM_LCD_HEIGHT, + background ? UI_LCD_POSX : 0, background ? UI_LCD_POSY : 0); +} + +void lcd_update(void) +{ + int x, y; + + for (y = 0; y < lcd_pattern_count; y++) + if (lcd_patterns[y].count > 0) + sim_lcd_define_pattern(y, lcd_patterns[y].pattern); + + for (y = 0; y < LCD_HEIGHT; y++) + for (x = 0; x < LCD_WIDTH; x++) + lcd_print_char(x, y, lcd_charbuffer[y][x]); + + if (lcd_cursor.visible) + lcd_print_char(lcd_cursor.x, lcd_cursor.y, lcd_cursor.hw_char); + + sim_lcd_update_rect(0, ICON_HEIGHT, SIM_LCD_WIDTH, + LCD_HEIGHT*CHAR_HEIGHT*CHAR_PIXEL); +} + +#if CONFIG_BACKLIGHT +void sim_backlight(int value) +{ + if (value > 0) { + sdl_set_gradient(lcd_surface, &lcd_backlight_color_zero, &lcd_color_max, + 0, (1<>8)&0xff +#define LE32_CONST(x) (x)&0xff, ((x)>>8)&0xff, ((x)>>16)&0xff, ((x)>>24)&0xff + +static const unsigned char bmpheader[] = +{ + 0x42, 0x4d, /* 'BM' */ + LE32_CONST(BMP_TOTALSIZE), /* Total file size */ + 0x00, 0x00, 0x00, 0x00, /* Reserved */ + LE32_CONST(BMP_HEADERSIZE), /* Offset to start of pixel data */ + + 0x28, 0x00, 0x00, 0x00, /* Size of (2nd) header */ + LE32_CONST(SIM_LCD_WIDTH), /* Width in pixels */ + LE32_CONST(SIM_LCD_HEIGHT), /* Height in pixels */ + 0x01, 0x00, /* Number of planes (always 1) */ + LE16_CONST(BMP_BPP), /* Bits per pixel 1/4/8/16/24 */ + LE32_CONST(BMP_COMPRESSION),/* Compression mode */ + LE32_CONST(BMP_DATASIZE), /* Size of bitmap data */ + 0xc4, 0x0e, 0x00, 0x00, /* Horizontal resolution (pixels/meter) */ + 0xc4, 0x0e, 0x00, 0x00, /* Vertical resolution (pixels/meter) */ + LE32_CONST(BMP_NUMCOLORS), /* Number of used colours */ + LE32_CONST(BMP_NUMCOLORS), /* Number of important colours */ + + 0x90, 0xee, 0x90, 0x00, /* Colour #0 */ + 0x00, 0x00, 0x00, 0x00 /* Colour #1 */ +}; + +void screen_dump(void) +{ + int fd; + char filename[MAX_PATH]; + int x, y; + static unsigned char line[BMP_LINESIZE]; + + create_numbered_filename(filename, "", "dump_", ".bmp", 4 + IF_CNFN_NUM_(, NULL)); + DEBUGF("screen_dump\n"); + + fd = sim_creat(filename); + if (fd < 0) + return; + + write(fd, bmpheader, sizeof(bmpheader)); + SDL_LockSurface(lcd_surface); + + /* BMP image goes bottom up */ + for (y = SIM_LCD_HEIGHT - 1; y >= 0; y--) + { + Uint8 *src = (Uint8 *)lcd_surface->pixels + + y * SIM_LCD_WIDTH * display_zoom * display_zoom; + unsigned char *dst = line; + unsigned dst_mask = 0x80; + + memset(line, 0, sizeof(line)); + for (x = SIM_LCD_WIDTH; x > 0; x--) + { + if (*src) + *dst |= dst_mask; + src += display_zoom; + dst_mask >>= 1; + if (dst_mask == 0) + { + dst++; + dst_mask = 0x80; + } + } + write(fd, line, sizeof(line)); + } + SDL_UnlockSurface(lcd_surface); + close(fd); +} diff --git a/uisimulator/sdl/lcd-charcells.h b/uisimulator/sdl/lcd-charcells.h new file mode 100644 index 0000000000..6b1e85e549 --- /dev/null +++ b/uisimulator/sdl/lcd-charcells.h @@ -0,0 +1,32 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2006 Dan Everton + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#ifndef __LCDCHARCELL_H__ +#define __LCDCHARCELL_H__ + +#include "lcd.h" +#include "SDL.h" + +#ifdef HAVE_LCD_CHARCELLS +void sim_lcd_init(void); +void screen_dump(void); +#endif + +#endif /* #ifndef __LCDCHARCELL_H__ */ + diff --git a/uisimulator/sdl/uisdl.c b/uisimulator/sdl/uisdl.c index 037c54a9bf..54175ce727 100644 --- a/uisimulator/sdl/uisdl.c +++ b/uisimulator/sdl/uisdl.c @@ -28,7 +28,7 @@ #ifdef HAVE_LCD_BITMAP #include "lcd-bitmap.h" #elif defined(HAVE_LCD_CHARCELLS) -#include "lcd-charcell.h" +#include "lcd-charcells.h" #endif #ifdef HAVE_REMOTE_LCD #include "lcd-remote-bitmap.h" -- cgit v1.2.3