summaryrefslogtreecommitdiffstats
path: root/uisimulator
diff options
context:
space:
mode:
authorRafaël Carré <rafael.carre@gmail.com>2008-12-04 23:24:45 +0000
committerRafaël Carré <rafael.carre@gmail.com>2008-12-04 23:24:45 +0000
commitbba06cfd551c7d34308ef7ea52455f07a5e2cfee (patch)
tree47a70eb6c2e63c71345dcf700bc0f88d4c33ac09 /uisimulator
parente3a970f4eb3068055f806a3194883eb157f8b1ed (diff)
downloadrockbox-bba06cfd551c7d34308ef7ea52455f07a5e2cfee.tar.gz
rockbox-bba06cfd551c7d34308ef7ea52455f07a5e2cfee.tar.bz2
rockbox-bba06cfd551c7d34308ef7ea52455f07a5e2cfee.zip
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
Diffstat (limited to 'uisimulator')
-rw-r--r--uisimulator/sdl/lcd-bitmap.c104
-rw-r--r--uisimulator/sdl/lcd-sdl.c82
-rw-r--r--uisimulator/sdl/lcd-sdl.h13
-rw-r--r--uisimulator/sdl/uisdl.c6
-rw-r--r--uisimulator/sdl/uisdl.h7
5 files changed, 179 insertions, 33 deletions
diff --git a/uisimulator/sdl/lcd-bitmap.c b/uisimulator/sdl/lcd-bitmap.c
index 92480396bc..b9f5732dc7 100644
--- a/uisimulator/sdl/lcd-bitmap.c
+++ b/uisimulator/sdl/lcd-bitmap.c
@@ -24,15 +24,24 @@
#include "lcd-sdl.h"
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;
#if LCD_DEPTH <= 8
#ifdef HAVE_BACKLIGHT
SDL_Color lcd_backlight_color_zero = {UI_LCD_BGCOLORLIGHT, 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
SDL_Color lcd_color_zero = {UI_LCD_BGCOLOR, 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
#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,
LCD_HEIGHT, get_lcd_pixel);
- sdl_gui_update(lcd_surface, x_start, y_start, width, height, LCD_WIDTH,
- LCD_HEIGHT, background ? UI_LCD_POSX : 0, background? UI_LCD_POSY : 0);
+ sdl_gui_update(lcd_surface, IFSPLIT(lcd_real_surface,) x_start, y_start,
+ width, height, LCD_WIDTH, LCD_HEIGHT,
+ background ? UI_LCD_POSX : 0, background? UI_LCD_POSY : 0);
}
#ifdef HAVE_BACKLIGHT
@@ -84,27 +94,51 @@ void sim_backlight(int value)
#if LCD_DEPTH <= 8
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,
- &lcd_backlight_color_max, 0, (1<<LCD_DEPTH));
+ &lcd_backlight_color_max, 0, (1<<LCD_DEPTH));
+#endif
} else {
- sdl_set_gradient(lcd_surface, &lcd_color_zero, &lcd_color_max,
- 0, (1<<LCD_DEPTH));
+#ifdef UI_LCD_SPLIT
+ 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_ex_shades) {
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,
- &lcd_backlight_color_zero, (1<<LCD_DEPTH),
- lcd_ex_shades);
+ &lcd_backlight_color_zero, (1<<LCD_DEPTH), lcd_ex_shades);
+#endif
} 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,
- (1<<LCD_DEPTH), lcd_ex_shades);
+ (1<<LCD_DEPTH), lcd_ex_shades);
+#endif
}
}
#endif
- sdl_gui_update(lcd_surface, 0, 0, LCD_WIDTH, LCD_HEIGHT, LCD_WIDTH,
- LCD_HEIGHT, background ? UI_LCD_POSX : 0, background? UI_LCD_POSY : 0);
+ sdl_gui_update(lcd_surface, IFSPLIT(lcd_real_surface,) 0, 0, LCD_WIDTH,
+ LCD_HEIGHT, LCD_WIDTH, LCD_HEIGHT,
+ background ? UI_LCD_POSX : 0, background? UI_LCD_POSY : 0);
#endif
}
@@ -119,15 +153,26 @@ void sim_lcd_init(void)
#else
lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, LCD_WIDTH * display_zoom,
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
#if LCD_DEPTH <= 8
#ifdef HAVE_BACKLIGHT
- sdl_set_gradient(lcd_surface, &lcd_backlight_color_zero, &lcd_color_max,
- 0, (1<<LCD_DEPTH));
+#ifdef UI_LCD_SPLIT
+ 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
- sdl_set_gradient(lcd_surface, &lcd_color_zero, &lcd_color_max, 0,
- (1<<LCD_DEPTH));
+ sdl_set_gradient(lcd_surface, &lcd_color_zero, &lcd_color_max, 0,
+ (1<<LCD_DEPTH));
#endif
#endif
}
@@ -140,15 +185,25 @@ void sim_lcd_ex_init(int shades, unsigned long (*getpixel)(int, int))
if (shades) {
#ifdef HAVE_BACKLIGHT
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,
- &lcd_backlight_color_zero, (1<<LCD_DEPTH),
- shades);
+ &lcd_backlight_color_zero, (1<<LCD_DEPTH), shades);
+#endif
}
- else
+ else
#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,
- (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) {
sdl_update_rect(lcd_surface, x_start, y_start, width, height,
LCD_WIDTH, LCD_HEIGHT, lcd_ex_getpixel);
- sdl_gui_update(lcd_surface, x_start, y_start, width, height, LCD_WIDTH,
- LCD_HEIGHT, background ? UI_LCD_POSX : 0,
+ sdl_gui_update(lcd_surface, IFSPLIT(lcd_real_surface,) x_start, y_start,
+ width, height, LCD_WIDTH, LCD_HEIGHT,
+ background ? UI_LCD_POSX : 0,
background? UI_LCD_POSY : 0);
}
}
@@ -256,7 +312,7 @@ void lcd_blit_yuv(unsigned char * const src[3],
*dst = LCD_RGBPACK_LCD(r >> 9, g >> 8, b >> 9);
#if LCD_WIDTH >= LCD_HEIGHT
- dst++;
+ dst++;
#else
dst += LCD_WIDTH;
#endif
@@ -276,7 +332,7 @@ void lcd_blit_yuv(unsigned char * const src[3],
*dst = LCD_RGBPACK_LCD(r >> 9, g >> 8, b >> 9);
#if LCD_WIDTH >= LCD_HEIGHT
- dst++;
+ dst++;
#else
dst += LCD_WIDTH;
#endif
@@ -321,7 +377,7 @@ void lcd_blit_yuv(unsigned char * const src[3],
*dst = LCD_RGBPACK_LCD(r >> 9, g >> 8, b >> 9);
#if LCD_WIDTH >= LCD_HEIGHT
- dst++;
+ dst++;
#else
dst += LCD_WIDTH;
#endif
@@ -341,7 +397,7 @@ void lcd_blit_yuv(unsigned char * const src[3],
*dst = LCD_RGBPACK_LCD(r >> 9, g >> 8, b >> 9);
#if LCD_WIDTH >= LCD_HEIGHT
- dst++;
+ dst++;
#else
dst += LCD_WIDTH;
#endif
diff --git a/uisimulator/sdl/lcd-sdl.c b/uisimulator/sdl/lcd-sdl.c
index 1014a371c0..a3dc87fed0 100644
--- a/uisimulator/sdl/lcd-sdl.c
+++ b/uisimulator/sdl/lcd-sdl.c
@@ -23,6 +23,9 @@
#include "uisdl.h"
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,
int height, int max_x, int max_y,
@@ -44,13 +47,13 @@ void sdl_update_rect(SDL_Surface *surface, int x_start, int y_start, int width,
dest.w = display_zoom;
dest.h = display_zoom;
-
+
for (x = x_start; x < xmax; x++) {
dest.x = x * display_zoom;
for (y = y_start; y < ymax; y++) {
dest.y = y * display_zoom;
-
+
SDL_FillRect(surface, &dest, (Uint32)getpixel(x, y));
}
}
@@ -58,9 +61,11 @@ void sdl_update_rect(SDL_Surface *surface, int x_start, int y_start, int width,
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)
{
+ printf("(%d, %d, %d, %d);\n", x_start, y_start, width, height);
int xmax, ymax;
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,
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);
+#endif
+
SDL_Flip(gui_surface);
}
/* 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,
- int first, int steps)
+ IFSPLIT(SDL_Color *split_start,)
+ IFSPLIT(SDL_Color *split_end ,) int first, int steps)
{
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++) {
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);
}
- 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);
}
diff --git a/uisimulator/sdl/lcd-sdl.h b/uisimulator/sdl/lcd-sdl.h
index 9ffa5246cf..b177eb14c9 100644
--- a/uisimulator/sdl/lcd-sdl.h
+++ b/uisimulator/sdl/lcd-sdl.h
@@ -25,6 +25,13 @@
#include "lcd.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 */
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,
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);
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__ */
diff --git a/uisimulator/sdl/uisdl.c b/uisimulator/sdl/uisdl.c
index 156e4203f6..f161d40567 100644
--- a/uisimulator/sdl/uisdl.c
+++ b/uisimulator/sdl/uisdl.c
@@ -134,7 +134,11 @@ bool gui_startup(void)
height = UI_LCD_HEIGHT + UI_REMOTE_HEIGHT;
#else
width = UI_LCD_WIDTH;
- height = UI_LCD_HEIGHT;
+ height = UI_LCD_HEIGHT
+#ifdef UI_LCD_SPLIT
+ + UI_LCD_SPLIT_BLACK_LINES
+#endif
+ ;
#endif
}
diff --git a/uisimulator/sdl/uisdl.h b/uisimulator/sdl/uisdl.h
index 0a97df56fa..cb4158500c 100644
--- a/uisimulator/sdl/uisdl.h
+++ b/uisimulator/sdl/uisdl.h
@@ -459,6 +459,13 @@
#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_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
extern SDL_Surface *gui_surface;
extern bool background; /* True if the background image is enabled */