1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2006 Dan Everton
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
23 #include "sim-ui-defines.h"
25 #include "button-sdl.h"
27 #include "screendump.h"
28 #if (CONFIG_PLATFORM & PLATFORM_MAEMO)
29 #include "maemo-thread.h"
32 SDL_Surface
* lcd_surface
;
36 SDL_Color lcd_bl_color_dark
= {RED_CMP(LCD_BL_DARKCOLOR
),
37 GREEN_CMP(LCD_BL_DARKCOLOR
),
38 BLUE_CMP(LCD_BL_DARKCOLOR
), 0};
39 SDL_Color lcd_bl_color_bright
= {RED_CMP(LCD_BL_BRIGHTCOLOR
),
40 GREEN_CMP(LCD_BL_BRIGHTCOLOR
),
41 BLUE_CMP(LCD_BL_BRIGHTCOLOR
), 0};
43 SDL_Color lcd_bl_color2_dark
= {RED_CMP(LCD_BL_DARKCOLOR_2
),
44 GREEN_CMP(LCD_BL_DARKCOLOR_2
),
45 BLUE_CMP(LCD_BL_DARKCOLOR_2
), 0};
46 SDL_Color lcd_bl_color2_bright
= {RED_CMP(LCD_BL_BRIGHTCOLOR_2
),
47 GREEN_CMP(LCD_BL_BRIGHTCOLOR_2
),
48 BLUE_CMP(LCD_BL_BRIGHTCOLOR_2
), 0};
50 #endif /* HAVE_BACKLIGHT */
51 SDL_Color lcd_color_dark
= {RED_CMP(LCD_DARKCOLOR
),
52 GREEN_CMP(LCD_DARKCOLOR
),
53 BLUE_CMP(LCD_DARKCOLOR
), 0};
54 SDL_Color lcd_color_bright
= {RED_CMP(LCD_BRIGHTCOLOR
),
55 GREEN_CMP(LCD_BRIGHTCOLOR
),
56 BLUE_CMP(LCD_BRIGHTCOLOR
), 0};
58 SDL_Color lcd_color2_dark
= {RED_CMP(LCD_DARKCOLOR_2
),
59 GREEN_CMP(LCD_DARKCOLOR_2
),
60 BLUE_CMP(LCD_DARKCOLOR_2
), 0};
61 SDL_Color lcd_color2_bright
= {RED_CMP(LCD_BRIGHTCOLOR_2
),
62 GREEN_CMP(LCD_BRIGHTCOLOR_2
),
63 BLUE_CMP(LCD_BRIGHTCOLOR_2
), 0};
67 #define NUM_SHADES 128
69 #define NUM_SHADES 129
72 #else /* LCD_DEPTH > 8 */
74 #ifdef HAVE_TRANSFLECTIVE_LCD
75 #define BACKLIGHT_OFF_ALPHA 85 /* 1/3 brightness */
77 #define BACKLIGHT_OFF_ALPHA 0 /* pitch black */
80 #endif /* LCD_DEPTH */
83 unsigned long (*lcd_ex_getpixel
)(int, int) = NULL
;
84 #endif /* LCD_DEPTH < 8 */
87 /* Only defined for positive, non-split LCD for now */
88 static const unsigned char colorindex
[4] = {128, 85, 43, 0};
91 static unsigned long get_lcd_pixel(int x
, int y
)
94 #ifdef HAVE_NEGATIVE_LCD
95 return (*FBADDR(x
, y
/8) & (1 << (y
& 7))) ? (NUM_SHADES
-1) : 0;
97 return (*FBADDR(x
, y
/8) & (1 << (y
& 7))) ? 0 : (NUM_SHADES
-1);
100 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
101 return colorindex
[(*FBADDR(x
/4, y
) >> (2 * (~x
& 3))) & 3];
102 #elif LCD_PIXELFORMAT == VERTICAL_PACKING
103 return colorindex
[(*FBADDR(x
, y
/4) >> (2 * (y
& 3))) & 3];
104 #elif LCD_PIXELFORMAT == VERTICAL_INTERLEAVED
105 unsigned bits
= (*FBADDR(x
, y
/8) >> (y
& 7)) & 0x0101;
106 return colorindex
[(bits
| (bits
>> 7)) & 3];
108 #elif LCD_DEPTH == 16
109 #if LCD_PIXELFORMAT == RGB565SWAPPED
110 unsigned bits
= *FBADDR(x
, y
);
111 return (bits
>> 8) | (bits
<< 8);
113 return *FBADDR(x
, y
);
118 void lcd_update(void)
120 /* update a full screen rect */
121 lcd_update_rect(0, 0, LCD_WIDTH
, LCD_HEIGHT
);
124 void lcd_update_rect(int x_start
, int y_start
, int width
, int height
)
126 #if (CONFIG_PLATFORM & PLATFORM_MAEMO)
127 /* Don't update display if not shown */
128 if (!maemo_display_on
)
131 /* Don't update if we don't have the input focus */
132 if (!sdl_app_has_input_focus
)
136 sdl_update_rect(lcd_surface
, x_start
, y_start
, width
, height
,
137 LCD_WIDTH
, LCD_HEIGHT
, get_lcd_pixel
);
138 sdl_gui_update(lcd_surface
, x_start
, y_start
, width
,
139 height
+ LCD_SPLIT_LINES
, SIM_LCD_WIDTH
, SIM_LCD_HEIGHT
,
140 background
? UI_LCD_POSX
: 0, background
? UI_LCD_POSY
: 0);
143 #ifdef HAVE_BACKLIGHT
144 void sim_backlight(int value
)
148 sdl_set_gradient(lcd_surface
, &lcd_bl_color_dark
,
149 &lcd_bl_color_bright
, 0, NUM_SHADES
);
150 #ifdef HAVE_LCD_SPLIT
151 sdl_set_gradient(lcd_surface
, &lcd_bl_color2_dark
,
152 &lcd_bl_color2_bright
, NUM_SHADES
, NUM_SHADES
);
155 sdl_set_gradient(lcd_surface
, &lcd_color_dark
,
156 &lcd_color_bright
, 0, NUM_SHADES
);
157 #ifdef HAVE_LCD_SPLIT
158 sdl_set_gradient(lcd_surface
, &lcd_color2_dark
,
159 &lcd_color2_bright
, NUM_SHADES
, NUM_SHADES
);
162 #else /* LCD_DEPTH > 8 */
163 SDL_SetAlpha(lcd_surface
, SDL_SRCALPHA
, (value
* 255) / 100);
164 #endif /* LCD_DEPTH */
166 sdl_gui_update(lcd_surface
, 0, 0, SIM_LCD_WIDTH
, SIM_LCD_HEIGHT
,
167 SIM_LCD_WIDTH
, SIM_LCD_HEIGHT
,
168 background
? UI_LCD_POSX
: 0, background
? UI_LCD_POSY
: 0);
170 #endif /* HAVE_BACKLIGHT */
172 /* initialise simulator lcd driver */
173 void lcd_init_device(void)
176 lcd_surface
= SDL_CreateRGBSurface(SDL_SWSURFACE
,
177 SIM_LCD_WIDTH
* display_zoom
,
178 SIM_LCD_HEIGHT
* display_zoom
,
179 LCD_DEPTH
, 0, 0, 0, 0);
181 lcd_surface
= SDL_CreateRGBSurface(SDL_SWSURFACE
,
182 SIM_LCD_WIDTH
* display_zoom
,
183 SIM_LCD_HEIGHT
* display_zoom
,
186 #ifdef HAVE_BACKLIGHT
187 sdl_set_gradient(lcd_surface
, &lcd_bl_color_dark
,
188 &lcd_bl_color_bright
, 0, NUM_SHADES
);
189 #ifdef HAVE_LCD_SPLIT
190 sdl_set_gradient(lcd_surface
, &lcd_bl_color2_dark
,
191 &lcd_bl_color2_bright
, NUM_SHADES
, NUM_SHADES
);
193 #else /* !HAVE_BACKLIGHT */
194 sdl_set_gradient(lcd_surface
, &lcd_color_dark
,
195 &lcd_color_bright
, 0, NUM_SHADES
);
196 #ifdef HAVE_LCD_SPLIT
197 sdl_set_gradient(lcd_surface
, &lcd_color2_dark
,
198 &lcd_color2_bright
, NUM_SHADES
, NUM_SHADES
);
200 #endif /* !HAVE_BACKLIGHT */
201 #endif /* LCD_DEPTH */
205 void sim_lcd_ex_init(unsigned long (*getpixel
)(int, int))
207 lcd_ex_getpixel
= getpixel
;
210 void sim_lcd_ex_update_rect(int x_start
, int y_start
, int width
, int height
)
212 if (lcd_ex_getpixel
) {
213 sdl_update_rect(lcd_surface
, x_start
, y_start
, width
, height
,
214 LCD_WIDTH
, LCD_HEIGHT
, lcd_ex_getpixel
);
215 sdl_gui_update(lcd_surface
, x_start
, y_start
, width
,
216 height
+ LCD_SPLIT_LINES
, SIM_LCD_WIDTH
, SIM_LCD_HEIGHT
,
217 background
? UI_LCD_POSX
: 0,
218 background
? UI_LCD_POSY
: 0);