Run Pandora port fullscreen
[maemo-rb.git] / firmware / target / hosted / sdl / lcd-sdl.c
blob1b28d8b6db3bdebb8dd10cb69b634be24839e928
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
22 #include <SDL.h>
23 #include "lcd-sdl.h"
24 #include "sim-ui-defines.h"
25 #include "system.h" /* for MIN() and MAX() */
27 int display_zoom = 1;
29 void sdl_update_rect(SDL_Surface *surface, int x_start, int y_start, int width,
30 int height, int max_x, int max_y,
31 unsigned long (*getpixel)(int, int))
33 SDL_Rect dest;
34 #if LCD_DEPTH >= 8 && (LCD_PIXELFORMAT == RGB565) \
35 && !defined(LCD_STRIDEFORMAT) && !defined(HAVE_LCD_SPLIT) \
36 && !defined(HAVE_REMOTE_LCD)
37 SDL_Rect src;
38 (void)max_x;
39 (void)max_y;
40 (void)getpixel;
41 /* Update complete screen via one blit operation (fast) */
42 SDL_Surface *lcd = SDL_CreateRGBSurfaceFrom(lcd_framebuffer, LCD_FBWIDTH,
43 LCD_FBHEIGHT, LCD_DEPTH,
44 LCD_FBWIDTH * LCD_DEPTH/8,
45 0, 0, 0, 0);
46 src.x = x_start;
47 src.y = y_start;
48 src.w = width;
49 src.h = height;
51 if (display_zoom == 1) {
52 dest = src;
53 SDL_BlitSurface(lcd, &src, surface, &dest);
54 } else {
55 /* Note: SDL_SoftStretch is currently marked as DO NOT USE
56 but there are no real alternatives for efficent zooming. */
57 dest.x = src.x * display_zoom;
58 dest.y = src.y * display_zoom;
59 dest.w = src.w * display_zoom;
60 dest.h = src.h * display_zoom;
61 SDL_SoftStretch(lcd, &src, surface, &dest);
63 SDL_FreeSurface(lcd);
64 #else
65 int x, y;
66 int xmax, ymax;
67 /* Very slow pixel-by-pixel drawing */
68 ymax = y_start + height;
69 xmax = x_start + width;
71 if(xmax > max_x)
72 xmax = max_x;
73 if(ymax >= max_y)
74 ymax = max_y;
76 dest.w = display_zoom;
77 dest.h = display_zoom;
79 for (x = x_start; x < xmax; x++) {
80 dest.x = x * display_zoom;
82 #ifdef HAVE_LCD_SPLIT
83 for (y = y_start; y < MIN(ymax, LCD_SPLIT_POS); y++) {
84 dest.y = y * display_zoom;
86 SDL_FillRect(surface, &dest, (Uint32)(getpixel(x, y) | 0x80));
88 for (y = MAX(y_start, LCD_SPLIT_POS); y < ymax; y++) {
89 dest.y = (y + LCD_SPLIT_LINES) * display_zoom ;
91 SDL_FillRect(surface, &dest, (Uint32)getpixel(x, y));
93 #else
94 for (y = y_start; y < ymax; y++) {
95 dest.y = y * display_zoom;
97 SDL_FillRect(surface, &dest, (Uint32)getpixel(x, y));
99 #endif
101 #endif
104 void sdl_gui_update(SDL_Surface *surface, int x_start, int y_start, int width,
105 int height, int max_x, int max_y, int ui_x, int ui_y)
107 if (x_start + width > max_x)
108 width = max_x - x_start;
109 if (y_start + height > max_y)
110 height = max_y - y_start;
112 SDL_Rect src = {x_start * display_zoom, y_start * display_zoom,
113 width * display_zoom, height * display_zoom};
114 SDL_Rect dest= {(ui_x + x_start) * display_zoom,
115 (ui_y + y_start) * display_zoom,
116 width * display_zoom, height * display_zoom};
118 if (surface->flags & SDL_SRCALPHA) /* alpha needs a black background */
119 SDL_FillRect(gui_surface, &dest, 0);
121 SDL_BlitSurface(surface, &src, gui_surface, &dest);
123 SDL_Flip(gui_surface);
126 /* set a range of bitmap indices to a gradient from startcolour to endcolour */
127 void sdl_set_gradient(SDL_Surface *surface, SDL_Color *start, SDL_Color *end,
128 int first, int steps)
130 int i;
131 SDL_Color palette[steps];
133 for (i = 0; i < steps; i++) {
134 palette[i].r = start->r + (end->r - start->r) * i / (steps - 1);
135 palette[i].g = start->g + (end->g - start->g) * i / (steps - 1);
136 palette[i].b = start->b + (end->b - start->b) * i / (steps - 1);
139 SDL_SetPalette(surface, SDL_LOGPAL|SDL_PHYSPAL, palette, first, steps);
142 int lcd_get_dpi(void)
144 /* TODO: find a way to query it from the OS, SDL doesn't support it
145 * directly; for now assume the more or less standard 96 */
146 return 96;