2 * (C) GraÅžvydas "notaz" Ignotas, 2010
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.
11 #include "../SDL_sysvideo.h"
12 #include "../SDL_pixels_c.h"
13 #include "../../events/SDL_events_c.h"
17 static int omap_available(void)
23 static void omap_free(SDL_VideoDevice *device)
29 static int omap_VideoInit(SDL_VideoDevice *this, SDL_PixelFormat *vformat)
37 vformat->BitsPerPixel = 16;
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;
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;
52 this->info.hw_available = 1;
57 static void omap_VideoQuit(SDL_VideoDevice *this)
61 osdl_video_finish(this->hidden);
62 this->screen->pixels = NULL;
63 omapsdl_input_finish();
66 static SDL_Rect **omap_ListModes(SDL_VideoDevice *this, SDL_PixelFormat *format, Uint32 flags)
68 static SDL_Rect omap_mode_list[] = {
69 /* XXX: we are not really restricted to fixed modes */
87 /* broken API needs this stupidity */
88 static SDL_Rect *omap_modes[] = {
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],
102 if (format->BitsPerPixel <= 8)
103 // not (yet?) supported
109 static SDL_Surface *omap_SetVideoMode(SDL_VideoDevice *this, SDL_Surface *current, int width,
110 int height, int bpp, Uint32 flags)
112 trace("%d, %d, %d, %08x", width, height, bpp, flags);
114 if (osdl_video_set_mode(this->hidden, width, height, bpp) < 0)
117 if (!SDL_ReallocFormat(current, 16, 0xf800, 0x07e0, 0x001f, 0))
120 current->flags = SDL_FULLSCREEN | SDL_DOUBLEBUF | SDL_HWSURFACE;
123 current->pitch = SDL_CalculatePitch(current);
125 current->pixels = osdl_video_flip(this->hidden);
130 static int omap_LockHWSurface(SDL_VideoDevice *this, SDL_Surface *surface)
132 trace("%p", surface);
137 static void omap_UnlockHWSurface(SDL_VideoDevice *this, SDL_Surface *surface)
139 trace("%p", surface);
142 static int omap_FlipHWSurface(SDL_VideoDevice *this, SDL_Surface *surface)
144 trace("%p", surface);
146 surface->pixels = osdl_video_flip(this->hidden);
151 /* we can't do hw surfaces (besides screen one) yet */
152 static int omap_AllocHWSurface(SDL_VideoDevice *this, SDL_Surface *surface)
154 trace("%p", surface);
158 static void omap_FreeHWSurface(SDL_VideoDevice *this, SDL_Surface *surface)
160 trace("%p", surface);
163 static int omap_SetColors(SDL_VideoDevice *this, int firstcolor, int ncolors, SDL_Color *colors)
165 trace("%d, %d, %p", firstcolor, ncolors, colors);
169 static void omap_UpdateRects(SDL_VideoDevice *this, int nrects, SDL_Rect *rects)
171 trace("%d, %p", nrects, rects);
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;
182 this->screen->pixels = osdl_video_flip(this->hidden);
185 static void omap_InitOSKeymap(SDL_VideoDevice *this)
190 static int key_event_cb(void *cb_arg, int sdl_kc, int is_pressed)
192 SDL_keysym keysym = { 0, };
195 SDL_PrivateKeyboard(is_pressed, &keysym);
198 static int ts_event_cb(void *cb_arg, int x, int y, unsigned int pressure)
200 static int was_pressed;
202 SDL_PrivateMouseMotion(0, 0, x, y);
204 pressure = !!pressure;
205 if (pressure != was_pressed) {
206 SDL_PrivateMouseButton(pressure ? SDL_PRESSED : SDL_RELEASED, 1, 0, 0);
207 was_pressed = pressure;
211 static void omap_PumpEvents(SDL_VideoDevice *this)
215 omapsdl_input_get_events(0, key_event_cb, ts_event_cb, NULL);
218 static SDL_VideoDevice *omap_create(int devindex)
220 SDL_VideoDevice *this;
222 this = calloc(1, sizeof(*this) + sizeof(*this->hidden));
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;
234 this->AllocHWSurface = omap_AllocHWSurface;
235 this->FreeHWSurface = omap_FreeHWSurface;
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;
246 VideoBootStrap omapdss_bootstrap = {
247 "omapdss", "OMAP DSS2 Framebuffer Driver",
248 omap_available, omap_create