Sansa Clip Simulator: emulate the real screen at the price of some CPU (FS#9521)

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19347 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Rafaël Carré 2008-12-04 23:24:45 +00:00
parent e3a970f4eb
commit bba06cfd55
5 changed files with 179 additions and 33 deletions

View file

@ -24,15 +24,24 @@
#include "lcd-sdl.h" #include "lcd-sdl.h"
SDL_Surface* lcd_surface; SDL_Surface* lcd_surface;
#ifdef UI_LCD_SPLIT
SDL_Surface* lcd_real_surface; /* the surface which represents the real screen */
#endif
int lcd_backlight_val; int lcd_backlight_val;
#if LCD_DEPTH <= 8 #if LCD_DEPTH <= 8
#ifdef HAVE_BACKLIGHT #ifdef HAVE_BACKLIGHT
SDL_Color lcd_backlight_color_zero = {UI_LCD_BGCOLORLIGHT, 0}; SDL_Color lcd_backlight_color_zero = {UI_LCD_BGCOLORLIGHT, 0};
SDL_Color lcd_backlight_color_max = {UI_LCD_FGCOLORLIGHT, 0}; SDL_Color lcd_backlight_color_max = {UI_LCD_FGCOLORLIGHT, 0};
#ifdef UI_LCD_SPLIT
SDL_Color lcd_backlight_color_split= {UI_LCD_SPLIT_FGCOLORLIGHT, 0};
#endif
#endif #endif
SDL_Color lcd_color_zero = {UI_LCD_BGCOLOR, 0}; SDL_Color lcd_color_zero = {UI_LCD_BGCOLOR, 0};
SDL_Color lcd_color_max = {UI_LCD_FGCOLOR, 0}; SDL_Color lcd_color_max = {UI_LCD_FGCOLOR, 0};
#ifdef UI_LCD_SPLIT
SDL_Color lcd_color_split= {UI_LCD_SPLIT_FGCOLOR, 0};
#endif
#endif #endif
#if LCD_DEPTH < 8 #if LCD_DEPTH < 8
@ -73,8 +82,9 @@ void lcd_update_rect(int x_start, int y_start, int width, int height)
{ {
sdl_update_rect(lcd_surface, x_start, y_start, width, height, LCD_WIDTH, sdl_update_rect(lcd_surface, x_start, y_start, width, height, LCD_WIDTH,
LCD_HEIGHT, get_lcd_pixel); LCD_HEIGHT, get_lcd_pixel);
sdl_gui_update(lcd_surface, x_start, y_start, width, height, LCD_WIDTH, sdl_gui_update(lcd_surface, IFSPLIT(lcd_real_surface,) x_start, y_start,
LCD_HEIGHT, background ? UI_LCD_POSX : 0, background? UI_LCD_POSY : 0); width, height, LCD_WIDTH, LCD_HEIGHT,
background ? UI_LCD_POSX : 0, background? UI_LCD_POSY : 0);
} }
#ifdef HAVE_BACKLIGHT #ifdef HAVE_BACKLIGHT
@ -84,27 +94,51 @@ void sim_backlight(int value)
#if LCD_DEPTH <= 8 #if LCD_DEPTH <= 8
if (value > 0) { if (value > 0) {
#ifdef UI_LCD_SPLIT
sdl_set_gradient(lcd_real_surface, &lcd_backlight_color_zero,
&lcd_backlight_color_max, &lcd_backlight_color_zero,
&lcd_backlight_color_split, 0, (1<<LCD_DEPTH));
#else
sdl_set_gradient(lcd_surface, &lcd_backlight_color_zero, sdl_set_gradient(lcd_surface, &lcd_backlight_color_zero,
&lcd_backlight_color_max, 0, (1<<LCD_DEPTH)); &lcd_backlight_color_max, 0, (1<<LCD_DEPTH));
#endif
} else { } else {
sdl_set_gradient(lcd_surface, &lcd_color_zero, &lcd_color_max, #ifdef UI_LCD_SPLIT
0, (1<<LCD_DEPTH)); sdl_set_gradient(lcd_real_surface, &lcd_color_zero, &lcd_color_max,
&lcd_color_zero, &lcd_color_split, 0, (1<<LCD_DEPTH));
#else
sdl_set_gradient(lcd_surface, &lcd_color_zero, &lcd_color_max, 0,
(1<<LCD_DEPTH));
#endif
} }
#if LCD_DEPTH < 8 #if LCD_DEPTH < 8
if (lcd_ex_shades) { if (lcd_ex_shades) {
if (value > 0) { if (value > 0) {
#ifdef UI_LCD_SPLIT
sdl_set_gradient(lcd_real_surface, &lcd_backlight_color_max,
&lcd_backlight_color_zero, &lcd_backlight_color_split,
&lcd_backlight_color_zero,
(1<<LCD_DEPTH), lcd_ex_shades);
#else
sdl_set_gradient(lcd_surface, &lcd_backlight_color_max, sdl_set_gradient(lcd_surface, &lcd_backlight_color_max,
&lcd_backlight_color_zero, (1<<LCD_DEPTH), &lcd_backlight_color_zero, (1<<LCD_DEPTH), lcd_ex_shades);
lcd_ex_shades); #endif
} else { } else {
#ifdef UI_LCD_SPLIT
sdl_set_gradient(lcd_real_surface, &lcd_color_max, &lcd_color_zero,
&lcd_color_split, &lcd_color_zero, (1<<LCD_DEPTH),
lcd_ex_shades);
#else
sdl_set_gradient(lcd_surface, &lcd_color_max, &lcd_color_zero, sdl_set_gradient(lcd_surface, &lcd_color_max, &lcd_color_zero,
(1<<LCD_DEPTH), lcd_ex_shades); (1<<LCD_DEPTH), lcd_ex_shades);
#endif
} }
} }
#endif #endif
sdl_gui_update(lcd_surface, 0, 0, LCD_WIDTH, LCD_HEIGHT, LCD_WIDTH, sdl_gui_update(lcd_surface, IFSPLIT(lcd_real_surface,) 0, 0, LCD_WIDTH,
LCD_HEIGHT, background ? UI_LCD_POSX : 0, background? UI_LCD_POSY : 0); LCD_HEIGHT, LCD_WIDTH, LCD_HEIGHT,
background ? UI_LCD_POSX : 0, background? UI_LCD_POSY : 0);
#endif #endif
} }
@ -119,15 +153,26 @@ void sim_lcd_init(void)
#else #else
lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, LCD_WIDTH * display_zoom, lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, LCD_WIDTH * display_zoom,
LCD_HEIGHT * display_zoom, 8, 0, 0, 0, 0); LCD_HEIGHT * display_zoom, 8, 0, 0, 0, 0);
#ifdef UI_LCD_SPLIT
lcd_real_surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
LCD_WIDTH * display_zoom,
(LCD_HEIGHT+UI_LCD_SPLIT_BLACK_LINES) * display_zoom, 8, 0, 0, 0, 0);
#endif
#endif #endif
#if LCD_DEPTH <= 8 #if LCD_DEPTH <= 8
#ifdef HAVE_BACKLIGHT #ifdef HAVE_BACKLIGHT
sdl_set_gradient(lcd_surface, &lcd_backlight_color_zero, &lcd_color_max, #ifdef UI_LCD_SPLIT
0, (1<<LCD_DEPTH)); sdl_set_gradient(lcd_real_surface, &lcd_backlight_color_zero,
&lcd_color_max, &lcd_backlight_color_zero,
&lcd_color_split, 0, (1<<LCD_DEPTH));
#else
sdl_set_gradient(lcd_surface, &lcd_backlight_color_zero, &lcd_color_max, 0,
(1<<LCD_DEPTH));
#endif
#else #else
sdl_set_gradient(lcd_surface, &lcd_color_zero, &lcd_color_max, 0, sdl_set_gradient(lcd_surface, &lcd_color_zero, &lcd_color_max, 0,
(1<<LCD_DEPTH)); (1<<LCD_DEPTH));
#endif #endif
#endif #endif
} }
@ -140,15 +185,25 @@ void sim_lcd_ex_init(int shades, unsigned long (*getpixel)(int, int))
if (shades) { if (shades) {
#ifdef HAVE_BACKLIGHT #ifdef HAVE_BACKLIGHT
if (lcd_backlight_val > 0) { if (lcd_backlight_val > 0) {
#ifdef UI_LCD_SPLIT
sdl_set_gradient(lcd_real_surface, &lcd_color_max,
&lcd_backlight_color_zero, &lcd_color_split,
&lcd_backlight_color_zero, (1<<LCD_DEPTH), shades);
#else
sdl_set_gradient(lcd_surface, &lcd_color_max, sdl_set_gradient(lcd_surface, &lcd_color_max,
&lcd_backlight_color_zero, (1<<LCD_DEPTH), &lcd_backlight_color_zero, (1<<LCD_DEPTH), shades);
shades); #endif
} }
else else
#endif #endif
{ {
#ifdef UI_LCD_SPLIT
sdl_set_gradient(lcd_real_surface, &lcd_color_max, &lcd_color_zero,
&lcd_color_split, &lcd_color_zero, (1<<LCD_DEPTH), shades);
#else
sdl_set_gradient(lcd_surface, &lcd_color_max, &lcd_color_zero, sdl_set_gradient(lcd_surface, &lcd_color_max, &lcd_color_zero,
(1<<LCD_DEPTH), shades); (1<<LCD_DEPTH), shades);
#endif
} }
} }
} }
@ -158,8 +213,9 @@ void sim_lcd_ex_update_rect(int x_start, int y_start, int width, int height)
if (lcd_ex_getpixel) { if (lcd_ex_getpixel) {
sdl_update_rect(lcd_surface, x_start, y_start, width, height, sdl_update_rect(lcd_surface, x_start, y_start, width, height,
LCD_WIDTH, LCD_HEIGHT, lcd_ex_getpixel); LCD_WIDTH, LCD_HEIGHT, lcd_ex_getpixel);
sdl_gui_update(lcd_surface, x_start, y_start, width, height, LCD_WIDTH, sdl_gui_update(lcd_surface, IFSPLIT(lcd_real_surface,) x_start, y_start,
LCD_HEIGHT, background ? UI_LCD_POSX : 0, width, height, LCD_WIDTH, LCD_HEIGHT,
background ? UI_LCD_POSX : 0,
background? UI_LCD_POSY : 0); background? UI_LCD_POSY : 0);
} }
} }

View file

@ -23,6 +23,9 @@
#include "uisdl.h" #include "uisdl.h"
int display_zoom = 1; int display_zoom = 1;
#ifdef UI_LCD_SPLIT
static int gradient_steps = 0;
#endif
void sdl_update_rect(SDL_Surface *surface, int x_start, int y_start, int width, void sdl_update_rect(SDL_Surface *surface, int x_start, int y_start, int width,
int height, int max_x, int max_y, int height, int max_x, int max_y,
@ -58,9 +61,11 @@ void sdl_update_rect(SDL_Surface *surface, int x_start, int y_start, int width,
SDL_UnlockSurface(surface); SDL_UnlockSurface(surface);
} }
void sdl_gui_update(SDL_Surface *surface, int x_start, int y_start, int width, void sdl_gui_update(SDL_Surface *surface, IFSPLIT(SDL_Surface *real_surface,)
int x_start, int y_start, int width,
int height, int max_x, int max_y, int ui_x, int ui_y) int height, int max_x, int max_y, int ui_x, int ui_y)
{ {
printf("(%d, %d, %d, %d);\n", x_start, y_start, width, height);
int xmax, ymax; int xmax, ymax;
ymax = y_start + height; ymax = y_start + height;
@ -76,16 +81,73 @@ void sdl_gui_update(SDL_Surface *surface, int x_start, int y_start, int width,
SDL_Rect dest= {(ui_x + x_start) * display_zoom, (ui_y + y_start) * display_zoom, SDL_Rect dest= {(ui_x + x_start) * display_zoom, (ui_y + y_start) * display_zoom,
xmax * display_zoom, ymax * display_zoom}; xmax * display_zoom, ymax * display_zoom};
#ifdef UI_LCD_SPLIT
/* fix real screen coordinates */
if(ymax >= UI_LCD_SPLIT_LINES)
src.h += UI_LCD_SPLIT_BLACK_LINES * display_zoom;
SDL_LockSurface(surface);
SDL_LockSurface(real_surface);
int pixel, npixels;
#if LCD_DEPTH != 1
#error "Split screen only works for monochrome displays !"
#endif
npixels = display_zoom * display_zoom * UI_LCD_SPLIT_LINES * surface->pitch;
const unsigned char * pixels_src = (const unsigned char*)surface->pixels;
unsigned char * pixels_dst = (unsigned char*)real_surface->pixels;
const int start_pixel = UI_LCD_SPLIT_LINES * surface->pitch * display_zoom;
const int stop_pixel = (UI_LCD_SPLIT_LINES+UI_LCD_SPLIT_BLACK_LINES)
* surface->pitch * display_zoom;
/* draw top pixels, change the color */
for (pixel = 0; pixel < npixels ; pixel++)
{
int pix = pixels_src[pixel] + gradient_steps;
if(pix > 255) pix = 255;
pixels_dst[pixel] = pix;
}
/* copy bottom pixels */
memcpy(&pixels_dst[stop_pixel], &pixels_src[start_pixel],
(UI_LCD_HEIGHT - UI_LCD_SPLIT_LINES) * surface->pitch * display_zoom);
/* separation lines are off */
for (pixel = start_pixel; pixel < stop_pixel ; pixel++)
pixels_dst[pixel] = 0;
SDL_UnlockSurface(surface);
SDL_UnlockSurface(real_surface);
SDL_BlitSurface(real_surface, &src, gui_surface, &dest);
#else
SDL_BlitSurface(surface, &src, gui_surface, &dest); SDL_BlitSurface(surface, &src, gui_surface, &dest);
#endif
SDL_Flip(gui_surface); SDL_Flip(gui_surface);
} }
/* set a range of bitmap indices to a gradient from startcolour to endcolour */ /* set a range of bitmap indices to a gradient from startcolour to endcolour */
void sdl_set_gradient(SDL_Surface *surface, SDL_Color *start, SDL_Color *end, void sdl_set_gradient(SDL_Surface *surface, SDL_Color *start, SDL_Color *end,
int first, int steps) IFSPLIT(SDL_Color *split_start,)
IFSPLIT(SDL_Color *split_end ,) int first, int steps)
{ {
int i; int i;
SDL_Color palette[steps];
#ifdef UI_LCD_SPLIT
int tot_steps = steps * 2;
if (tot_steps > 256)
tot_steps = 256;
gradient_steps = steps;
#else
#define tot_steps steps
#endif
SDL_Color palette[tot_steps];
for (i = 0; i < steps; i++) { for (i = 0; i < steps; i++) {
palette[i].r = start->r + (end->r - start->r) * i / (steps - 1); palette[i].r = start->r + (end->r - start->r) * i / (steps - 1);
@ -93,6 +155,14 @@ void sdl_set_gradient(SDL_Surface *surface, SDL_Color *start, SDL_Color *end,
palette[i].b = start->b + (end->b - start->b) * i / (steps - 1); palette[i].b = start->b + (end->b - start->b) * i / (steps - 1);
} }
SDL_SetPalette(surface, SDL_LOGPAL|SDL_PHYSPAL, palette, first, steps); #ifdef UI_LCD_SPLIT /* extra color */
for (i = steps ; i < tot_steps; i++) {
palette[i].r = split_start->r + (split_end->r - split_start->r) * (i - steps) / (tot_steps - steps - 1);
palette[i].g = split_start->g + (split_end->g - split_start->g) * (i - steps) / (tot_steps - steps - 1);
palette[i].b = split_start->b + (split_end->b - split_start->b) * (i - steps) / (tot_steps - steps - 1);
}
#endif
SDL_SetPalette(surface, SDL_LOGPAL|SDL_PHYSPAL, palette, first, tot_steps);
} }

View file

@ -25,6 +25,13 @@
#include "lcd.h" #include "lcd.h"
#include "SDL.h" #include "SDL.h"
#include "uisdl.h"
#ifdef UI_LCD_SPLIT
#define IFSPLIT(x,y) x,y
#else
#define IFSPLIT(x,y)
#endif
/* Default display zoom level */ /* Default display zoom level */
extern int display_zoom; extern int display_zoom;
@ -32,11 +39,13 @@ void sdl_update_rect(SDL_Surface *surface, int x_start, int y_start, int width,
int height, int max_x, int max_y, int height, int max_x, int max_y,
unsigned long (*getpixel)(int, int)); unsigned long (*getpixel)(int, int));
void sdl_gui_update(SDL_Surface *surface, int x_start, int y_start, int width, void sdl_gui_update(SDL_Surface *surface, IFSPLIT(SDL_Surface *real_surface,)
int x_start, int y_start, int width,
int height, int max_x, int max_y, int ui_x, int ui_y); int height, int max_x, int max_y, int ui_x, int ui_y);
void sdl_set_gradient(SDL_Surface *surface, SDL_Color *start, SDL_Color *end, void sdl_set_gradient(SDL_Surface *surface, SDL_Color *start, SDL_Color *end,
int first, int steps); IFSPLIT( SDL_Color *split_start ,)
IFSPLIT( SDL_Color *split_end ,) int first, int steps);
#endif /* #ifndef __LCDSDL_H__ */ #endif /* #ifndef __LCDSDL_H__ */

View file

@ -134,7 +134,11 @@ bool gui_startup(void)
height = UI_LCD_HEIGHT + UI_REMOTE_HEIGHT; height = UI_LCD_HEIGHT + UI_REMOTE_HEIGHT;
#else #else
width = UI_LCD_WIDTH; width = UI_LCD_WIDTH;
height = UI_LCD_HEIGHT; height = UI_LCD_HEIGHT
#ifdef UI_LCD_SPLIT
+ UI_LCD_SPLIT_BLACK_LINES
#endif
;
#endif #endif
} }

View file

@ -459,6 +459,13 @@
#define UI_LCD_FGCOLOR 0, 0, 0 /* foreground color of LCD (no backlight) */ #define UI_LCD_FGCOLOR 0, 0, 0 /* foreground color of LCD (no backlight) */
#define UI_LCD_FGCOLORLIGHT 13, 226, 229 /* foreground color of LCD (backlight) */ #define UI_LCD_FGCOLORLIGHT 13, 226, 229 /* foreground color of LCD (backlight) */
#define UI_LCD_SPLIT /* The screen is split in 2 areas */
#define UI_LCD_SPLIT_LINES 16 /* the top 16 lines have a different color */
#define UI_LCD_SPLIT_BLACK_LINES 2 /* The 2 areas are separated by 2 empty lines */
/* Colors for the top part of the screen */
#define UI_LCD_SPLIT_FGCOLOR 0, 0, 0 /* foreground color of LCD (no backlight) */
#define UI_LCD_SPLIT_FGCOLORLIGHT 255, 230, 15 /* foreground color of LCD (backlight) */
#endif #endif
extern SDL_Surface *gui_surface; extern SDL_Surface *gui_surface;
extern bool background; /* True if the background image is enabled */ extern bool background; /* True if the background image is enabled */