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