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" |
f9b3f440 |
14 | |
15 | #include "linux/xenv.h" |
9a8e84f8 |
16 | #include "omapsdl.h" |
17 | |
18 | |
9a8e84f8 |
19 | static int omap_available(void) |
20 | { |
21 | trace(); |
22 | return 1; |
23 | } |
24 | |
25 | static void omap_free(SDL_VideoDevice *device) |
26 | { |
27 | trace(); |
28 | free(device); |
29 | } |
30 | |
31 | static int omap_VideoInit(SDL_VideoDevice *this, SDL_PixelFormat *vformat) |
32 | { |
b9a19b44 |
33 | const char *tmp; |
34 | int w, h, ret; |
35 | |
9a8e84f8 |
36 | trace(); |
37 | |
38 | // default to 16bpp |
39 | vformat->BitsPerPixel = 16; |
40 | |
41 | omapsdl_input_init(); |
42 | omapsdl_config(); |
43 | |
b9a19b44 |
44 | tmp = getenv("SDL_OMAP_DEFAULT_MODE"); |
45 | if (tmp != NULL && sscanf(tmp, "%dx%d", &w, &h) == 2) { |
46 | this->info.current_w = w; |
47 | this->info.current_h = h; |
48 | } |
49 | else if (osdl_video_detect_screen(this->hidden) == 0) { |
50 | this->info.current_w = this->hidden->screen_w; |
51 | this->info.current_h = this->hidden->screen_h; |
52 | } |
53 | |
5d957fa5 |
54 | this->handles_any_size = 1; |
b9a19b44 |
55 | this->info.hw_available = 1; |
56 | |
9a8e84f8 |
57 | return 0; |
58 | } |
59 | |
60 | static void omap_VideoQuit(SDL_VideoDevice *this) |
61 | { |
62 | trace(); |
63 | |
f641fccb |
64 | osdl_video_finish(this->hidden); |
9a8e84f8 |
65 | this->screen->pixels = NULL; |
17e19802 |
66 | omapsdl_input_finish(); |
9a8e84f8 |
67 | } |
68 | |
69 | static SDL_Rect **omap_ListModes(SDL_VideoDevice *this, SDL_PixelFormat *format, Uint32 flags) |
70 | { |
5d957fa5 |
71 | static SDL_Rect omap_mode_max = { |
72 | /* with handles_any_size, should accept anything up to this |
73 | * XXX: possibly set this dynamically based on free vram? */ |
74 | 0, 0, 1600, 1200 |
9a8e84f8 |
75 | }; |
b9a19b44 |
76 | /* broken API needs this stupidity */ |
9a8e84f8 |
77 | static SDL_Rect *omap_modes[] = { |
5d957fa5 |
78 | &omap_mode_max, |
9a8e84f8 |
79 | NULL |
80 | }; |
81 | |
82 | trace(); |
83 | |
84 | if (format->BitsPerPixel <= 8) |
85 | // not (yet?) supported |
86 | return NULL; |
87 | |
88 | return omap_modes; |
89 | } |
90 | |
91 | static SDL_Surface *omap_SetVideoMode(SDL_VideoDevice *this, SDL_Surface *current, int width, |
92 | int height, int bpp, Uint32 flags) |
93 | { |
3576a5ac |
94 | SDL_PixelFormat *format; |
0bb19c41 |
95 | Uint32 unhandled_flags; |
96 | int ret; |
3576a5ac |
97 | |
9a8e84f8 |
98 | trace("%d, %d, %d, %08x", width, height, bpp, flags); |
99 | |
0bb19c41 |
100 | omapsdl_config_from_env(); |
101 | |
3576a5ac |
102 | switch (bpp) { |
103 | case 16: |
104 | format = SDL_ReallocFormat(current, 16, 0xf800, 0x07e0, 0x001f, 0); |
105 | break; |
106 | case 24: |
107 | format = SDL_ReallocFormat(current, 24, 0xff0000, 0xff00, 0xff, 0); |
108 | break; |
109 | case 32: |
110 | format = SDL_ReallocFormat(current, 32, 0xff0000, 0xff00, 0xff, 0xff000000); |
111 | break; |
112 | default: |
0bb19c41 |
113 | err("SetVideoMode: bpp %d not supported", bpp); |
3576a5ac |
114 | return NULL; |
115 | } |
116 | if (format == NULL) |
f641fccb |
117 | return NULL; |
9a8e84f8 |
118 | |
0bb19c41 |
119 | if (!(flags & SDL_DOUBLEBUF) && gcfg_force_doublebuf) { |
120 | log("forcing SDL_DOUBLEBUF"); |
121 | flags |= SDL_DOUBLEBUF; |
122 | } |
123 | |
124 | ret = osdl_video_set_mode(this->hidden, width, height, bpp, |
125 | (flags & SDL_DOUBLEBUF) ? 1 : 0); |
126 | if (ret < 0) |
9a8e84f8 |
127 | return NULL; |
128 | |
0bb19c41 |
129 | flags |= SDL_FULLSCREEN | SDL_HWSURFACE; |
130 | unhandled_flags = flags & ~(SDL_FULLSCREEN | SDL_HWSURFACE | SDL_DOUBLEBUF); |
131 | if (unhandled_flags != 0) { |
132 | log("dropping unhandled flags: %08x", unhandled_flags); |
133 | flags &= ~unhandled_flags; |
134 | } |
135 | |
136 | current->flags = flags; |
9a8e84f8 |
137 | current->w = width; |
138 | current->h = height; |
139 | current->pitch = SDL_CalculatePitch(current); |
140 | |
f641fccb |
141 | current->pixels = osdl_video_flip(this->hidden); |
9a8e84f8 |
142 | |
143 | return current; |
144 | } |
145 | |
9a8e84f8 |
146 | static int omap_LockHWSurface(SDL_VideoDevice *this, SDL_Surface *surface) |
147 | { |
148 | trace("%p", surface); |
149 | |
150 | return 0; |
151 | } |
152 | |
153 | static void omap_UnlockHWSurface(SDL_VideoDevice *this, SDL_Surface *surface) |
154 | { |
155 | trace("%p", surface); |
156 | } |
157 | |
158 | static int omap_FlipHWSurface(SDL_VideoDevice *this, SDL_Surface *surface) |
159 | { |
160 | trace("%p", surface); |
161 | |
f641fccb |
162 | surface->pixels = osdl_video_flip(this->hidden); |
9a8e84f8 |
163 | |
164 | return 0; |
165 | } |
166 | |
37299201 |
167 | /* we can't do hw surfaces (besides screen one) yet */ |
168 | static int omap_AllocHWSurface(SDL_VideoDevice *this, SDL_Surface *surface) |
169 | { |
170 | trace("%p", surface); |
171 | return -1; |
172 | } |
173 | |
174 | static void omap_FreeHWSurface(SDL_VideoDevice *this, SDL_Surface *surface) |
175 | { |
176 | trace("%p", surface); |
177 | } |
178 | |
9a8e84f8 |
179 | static int omap_SetColors(SDL_VideoDevice *this, int firstcolor, int ncolors, SDL_Color *colors) |
180 | { |
181 | trace("%d, %d, %p", firstcolor, ncolors, colors); |
182 | return 0; |
183 | } |
184 | |
185 | static void omap_UpdateRects(SDL_VideoDevice *this, int nrects, SDL_Rect *rects) |
186 | { |
187 | trace("%d, %p", nrects, rects); |
188 | |
0bb19c41 |
189 | /* hmh.. */ |
190 | if (nrects == 1 && rects->x == 0 && rects->y == 0 && |
191 | (this->screen->flags & SDL_DOUBLEBUF) && |
192 | rects->w == this->screen->w && rects->h == this->screen->h) |
193 | { |
194 | this->screen->pixels = osdl_video_flip(this->hidden); |
9a8e84f8 |
195 | } |
9a8e84f8 |
196 | } |
197 | |
198 | static void omap_InitOSKeymap(SDL_VideoDevice *this) |
199 | { |
200 | trace(); |
201 | } |
202 | |
17e19802 |
203 | static int key_event_cb(void *cb_arg, int sdl_kc, int is_pressed) |
9a8e84f8 |
204 | { |
205 | SDL_keysym keysym = { 0, }; |
206 | |
207 | keysym.sym = sdl_kc; |
208 | SDL_PrivateKeyboard(is_pressed, &keysym); |
209 | } |
210 | |
17e19802 |
211 | static int ts_event_cb(void *cb_arg, int x, int y, unsigned int pressure) |
212 | { |
213 | static int was_pressed; |
214 | |
215 | SDL_PrivateMouseMotion(0, 0, x, y); |
216 | |
217 | pressure = !!pressure; |
218 | if (pressure != was_pressed) { |
219 | SDL_PrivateMouseButton(pressure ? SDL_PRESSED : SDL_RELEASED, 1, 0, 0); |
220 | was_pressed = pressure; |
221 | } |
222 | } |
223 | |
9a8e84f8 |
224 | static void omap_PumpEvents(SDL_VideoDevice *this) |
225 | { |
f9b3f440 |
226 | struct SDL_PrivateVideoData *pdata = this->hidden; |
227 | int dummy; |
228 | |
9a8e84f8 |
229 | trace(); |
230 | |
17e19802 |
231 | omapsdl_input_get_events(0, key_event_cb, ts_event_cb, NULL); |
f9b3f440 |
232 | |
233 | // XXX: we might want to process some X events too |
234 | if (pdata->xenv_up) |
235 | xenv_update(&dummy); |
9a8e84f8 |
236 | } |
237 | |
238 | static SDL_VideoDevice *omap_create(int devindex) |
239 | { |
240 | SDL_VideoDevice *this; |
241 | |
242 | this = calloc(1, sizeof(*this) + sizeof(*this->hidden)); |
243 | if (this == NULL) { |
244 | SDL_OutOfMemory(); |
245 | return 0; |
246 | } |
247 | this->hidden = (void *)(this + 1); |
248 | this->VideoInit = omap_VideoInit; |
249 | this->ListModes = omap_ListModes; |
250 | this->SetVideoMode = omap_SetVideoMode; |
251 | this->LockHWSurface = omap_LockHWSurface; |
252 | this->UnlockHWSurface = omap_UnlockHWSurface; |
253 | this->FlipHWSurface = omap_FlipHWSurface; |
37299201 |
254 | this->AllocHWSurface = omap_AllocHWSurface; |
255 | this->FreeHWSurface = omap_FreeHWSurface; |
9a8e84f8 |
256 | this->SetColors = omap_SetColors; |
257 | this->UpdateRects = omap_UpdateRects; |
258 | this->VideoQuit = omap_VideoQuit; |
259 | this->InitOSKeymap = omap_InitOSKeymap; |
260 | this->PumpEvents = omap_PumpEvents; |
261 | this->free = omap_free; |
262 | |
263 | return this; |
264 | } |
265 | |
266 | VideoBootStrap omapdss_bootstrap = { |
267 | "omapdss", "OMAP DSS2 Framebuffer Driver", |
268 | omap_available, omap_create |
269 | }; |
270 | |