9a8e84f8 |
1 | /* |
2 | * (C) GraÅžvydas "notaz" Ignotas, 2010 |
3 | * |
4 | * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. |
5 | * See the COPYING file in the top-level directory. |
6 | */ |
7 | |
b9a19b44 |
8 | #include <stdio.h> |
9a8e84f8 |
9 | #include <stdlib.h> |
10 | |
11 | #include "../SDL_sysvideo.h" |
12 | #include "../SDL_pixels_c.h" |
13 | #include "../../events/SDL_events_c.h" |
9a8e84f8 |
14 | #include "omapsdl.h" |
15 | |
16 | |
9a8e84f8 |
17 | static int omap_available(void) |
18 | { |
19 | trace(); |
20 | return 1; |
21 | } |
22 | |
23 | static void omap_free(SDL_VideoDevice *device) |
24 | { |
25 | trace(); |
26 | free(device); |
27 | } |
28 | |
29 | static int omap_VideoInit(SDL_VideoDevice *this, SDL_PixelFormat *vformat) |
30 | { |
b9a19b44 |
31 | const char *tmp; |
32 | int w, h, ret; |
33 | |
9a8e84f8 |
34 | trace(); |
35 | |
36 | // default to 16bpp |
37 | vformat->BitsPerPixel = 16; |
38 | |
39 | omapsdl_input_init(); |
40 | omapsdl_config(); |
41 | |
b9a19b44 |
42 | tmp = getenv("SDL_OMAP_DEFAULT_MODE"); |
43 | if (tmp != NULL && sscanf(tmp, "%dx%d", &w, &h) == 2) { |
44 | this->info.current_w = w; |
45 | this->info.current_h = h; |
46 | } |
47 | else if (osdl_video_detect_screen(this->hidden) == 0) { |
48 | this->info.current_w = this->hidden->screen_w; |
49 | this->info.current_h = this->hidden->screen_h; |
50 | } |
51 | |
52 | this->info.hw_available = 1; |
53 | |
9a8e84f8 |
54 | return 0; |
55 | } |
56 | |
57 | static void omap_VideoQuit(SDL_VideoDevice *this) |
58 | { |
59 | trace(); |
60 | |
f641fccb |
61 | osdl_video_finish(this->hidden); |
9a8e84f8 |
62 | this->screen->pixels = NULL; |
17e19802 |
63 | omapsdl_input_finish(); |
9a8e84f8 |
64 | } |
65 | |
66 | static SDL_Rect **omap_ListModes(SDL_VideoDevice *this, SDL_PixelFormat *format, Uint32 flags) |
67 | { |
68 | static SDL_Rect omap_mode_list[] = { |
b9a19b44 |
69 | /* XXX: we are not really restricted to fixed modes */ |
37299201 |
70 | { 0, 0, 1600, 1200 }, |
71 | { 0, 0, 1408, 1056 }, |
72 | { 0, 0, 1280, 1024 }, |
73 | { 0, 0, 1152, 864 }, |
74 | { 0, 0, 1024, 768 }, |
75 | { 0, 0, 960, 720 }, |
76 | { 0, 0, 800, 600 }, |
77 | { 0, 0, 768, 576 }, |
78 | { 0, 0, 720, 576 }, |
79 | { 0, 0, 800, 480 }, |
80 | { 0, 0, 720, 480 }, |
81 | { 0, 0, 640, 480 }, |
82 | { 0, 0, 640, 400 }, |
83 | { 0, 0, 512, 384 }, |
84 | { 0, 0, 320, 240 }, |
85 | { 0, 0, 320, 200 }, |
9a8e84f8 |
86 | }; |
b9a19b44 |
87 | /* broken API needs this stupidity */ |
9a8e84f8 |
88 | static SDL_Rect *omap_modes[] = { |
b9a19b44 |
89 | &omap_mode_list[ 0], &omap_mode_list[ 1], |
90 | &omap_mode_list[ 2], &omap_mode_list[ 3], |
91 | &omap_mode_list[ 4], &omap_mode_list[ 5], |
92 | &omap_mode_list[ 6], &omap_mode_list[ 7], |
93 | &omap_mode_list[ 8], &omap_mode_list[ 9], |
94 | &omap_mode_list[10], &omap_mode_list[11], |
95 | &omap_mode_list[12], &omap_mode_list[13], |
96 | &omap_mode_list[14], &omap_mode_list[15], |
9a8e84f8 |
97 | NULL |
98 | }; |
99 | |
100 | trace(); |
101 | |
102 | if (format->BitsPerPixel <= 8) |
103 | // not (yet?) supported |
104 | return NULL; |
105 | |
106 | return omap_modes; |
107 | } |
108 | |
109 | static SDL_Surface *omap_SetVideoMode(SDL_VideoDevice *this, SDL_Surface *current, int width, |
110 | int height, int bpp, Uint32 flags) |
111 | { |
112 | trace("%d, %d, %d, %08x", width, height, bpp, flags); |
113 | |
f641fccb |
114 | if (osdl_video_set_mode(this->hidden, width, height, bpp) < 0) |
115 | return NULL; |
9a8e84f8 |
116 | |
117 | if (!SDL_ReallocFormat(current, 16, 0xf800, 0x07e0, 0x001f, 0)) |
118 | return NULL; |
119 | |
120 | current->flags = SDL_FULLSCREEN | SDL_DOUBLEBUF | SDL_HWSURFACE; |
121 | current->w = width; |
122 | current->h = height; |
123 | current->pitch = SDL_CalculatePitch(current); |
124 | |
f641fccb |
125 | current->pixels = osdl_video_flip(this->hidden); |
9a8e84f8 |
126 | |
127 | return current; |
128 | } |
129 | |
9a8e84f8 |
130 | static int omap_LockHWSurface(SDL_VideoDevice *this, SDL_Surface *surface) |
131 | { |
132 | trace("%p", surface); |
133 | |
134 | return 0; |
135 | } |
136 | |
137 | static void omap_UnlockHWSurface(SDL_VideoDevice *this, SDL_Surface *surface) |
138 | { |
139 | trace("%p", surface); |
140 | } |
141 | |
142 | static int omap_FlipHWSurface(SDL_VideoDevice *this, SDL_Surface *surface) |
143 | { |
144 | trace("%p", surface); |
145 | |
f641fccb |
146 | surface->pixels = osdl_video_flip(this->hidden); |
9a8e84f8 |
147 | |
148 | return 0; |
149 | } |
150 | |
37299201 |
151 | /* we can't do hw surfaces (besides screen one) yet */ |
152 | static int omap_AllocHWSurface(SDL_VideoDevice *this, SDL_Surface *surface) |
153 | { |
154 | trace("%p", surface); |
155 | return -1; |
156 | } |
157 | |
158 | static void omap_FreeHWSurface(SDL_VideoDevice *this, SDL_Surface *surface) |
159 | { |
160 | trace("%p", surface); |
161 | } |
162 | |
9a8e84f8 |
163 | static int omap_SetColors(SDL_VideoDevice *this, int firstcolor, int ncolors, SDL_Color *colors) |
164 | { |
165 | trace("%d, %d, %p", firstcolor, ncolors, colors); |
166 | return 0; |
167 | } |
168 | |
169 | static void omap_UpdateRects(SDL_VideoDevice *this, int nrects, SDL_Rect *rects) |
170 | { |
171 | trace("%d, %p", nrects, rects); |
172 | |
173 | if (nrects != 1 || rects->x != 0 || rects->y != 0 || |
174 | rects->w != this->screen->w || rects->h != this->screen->h) { |
175 | static int warned = 0; |
176 | if (!warned) { |
177 | not_supported(); |
178 | warned = 1; |
179 | } |
180 | } |
181 | |
f641fccb |
182 | this->screen->pixels = osdl_video_flip(this->hidden); |
9a8e84f8 |
183 | } |
184 | |
185 | static void omap_InitOSKeymap(SDL_VideoDevice *this) |
186 | { |
187 | trace(); |
188 | } |
189 | |
17e19802 |
190 | static int key_event_cb(void *cb_arg, int sdl_kc, int is_pressed) |
9a8e84f8 |
191 | { |
192 | SDL_keysym keysym = { 0, }; |
193 | |
194 | keysym.sym = sdl_kc; |
195 | SDL_PrivateKeyboard(is_pressed, &keysym); |
196 | } |
197 | |
17e19802 |
198 | static int ts_event_cb(void *cb_arg, int x, int y, unsigned int pressure) |
199 | { |
200 | static int was_pressed; |
201 | |
202 | SDL_PrivateMouseMotion(0, 0, x, y); |
203 | |
204 | pressure = !!pressure; |
205 | if (pressure != was_pressed) { |
206 | SDL_PrivateMouseButton(pressure ? SDL_PRESSED : SDL_RELEASED, 1, 0, 0); |
207 | was_pressed = pressure; |
208 | } |
209 | } |
210 | |
9a8e84f8 |
211 | static void omap_PumpEvents(SDL_VideoDevice *this) |
212 | { |
213 | trace(); |
214 | |
17e19802 |
215 | omapsdl_input_get_events(0, key_event_cb, ts_event_cb, NULL); |
9a8e84f8 |
216 | } |
217 | |
218 | static SDL_VideoDevice *omap_create(int devindex) |
219 | { |
220 | SDL_VideoDevice *this; |
221 | |
222 | this = calloc(1, sizeof(*this) + sizeof(*this->hidden)); |
223 | if (this == NULL) { |
224 | SDL_OutOfMemory(); |
225 | return 0; |
226 | } |
227 | this->hidden = (void *)(this + 1); |
228 | this->VideoInit = omap_VideoInit; |
229 | this->ListModes = omap_ListModes; |
230 | this->SetVideoMode = omap_SetVideoMode; |
231 | this->LockHWSurface = omap_LockHWSurface; |
232 | this->UnlockHWSurface = omap_UnlockHWSurface; |
233 | this->FlipHWSurface = omap_FlipHWSurface; |
37299201 |
234 | this->AllocHWSurface = omap_AllocHWSurface; |
235 | this->FreeHWSurface = omap_FreeHWSurface; |
9a8e84f8 |
236 | this->SetColors = omap_SetColors; |
237 | this->UpdateRects = omap_UpdateRects; |
238 | this->VideoQuit = omap_VideoQuit; |
239 | this->InitOSKeymap = omap_InitOSKeymap; |
240 | this->PumpEvents = omap_PumpEvents; |
241 | this->free = omap_free; |
242 | |
243 | return this; |
244 | } |
245 | |
246 | VideoBootStrap omapdss_bootstrap = { |
247 | "omapdss", "OMAP DSS2 Framebuffer Driver", |
248 | omap_available, omap_create |
249 | }; |
250 | |