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"
15 #include "linux/xenv.h"
19 static int omap_available(void)
25 static void omap_free(SDL_VideoDevice *device)
31 static int omap_VideoInit(SDL_VideoDevice *this, SDL_PixelFormat *vformat)
39 vformat->BitsPerPixel = 16;
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;
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;
54 this->handles_any_size = 1;
55 this->info.hw_available = 1;
60 static void omap_VideoQuit(SDL_VideoDevice *this)
64 osdl_video_finish(this->hidden);
65 this->screen->pixels = NULL;
66 omapsdl_input_finish();
69 static SDL_Rect **omap_ListModes(SDL_VideoDevice *this, SDL_PixelFormat *format, Uint32 flags)
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? */
76 /* broken API needs this stupidity */
77 static SDL_Rect *omap_modes[] = {
84 if (format->BitsPerPixel <= 8)
85 // not (yet?) supported
91 static SDL_Surface *omap_SetVideoMode(SDL_VideoDevice *this, SDL_Surface *current, int width,
92 int height, int bpp, Uint32 flags)
94 SDL_PixelFormat *format;
96 trace("%d, %d, %d, %08x", width, height, bpp, flags);
100 format = SDL_ReallocFormat(current, 16, 0xf800, 0x07e0, 0x001f, 0);
103 format = SDL_ReallocFormat(current, 24, 0xff0000, 0xff00, 0xff, 0);
106 format = SDL_ReallocFormat(current, 32, 0xff0000, 0xff00, 0xff, 0xff000000);
109 err("SetVideoMode: bpp %d not supported\n", bpp);
115 if (osdl_video_set_mode(this->hidden, width, height, bpp) < 0)
118 current->flags = SDL_FULLSCREEN | SDL_DOUBLEBUF | SDL_HWSURFACE;
121 current->pitch = SDL_CalculatePitch(current);
123 current->pixels = osdl_video_flip(this->hidden);
128 static int omap_LockHWSurface(SDL_VideoDevice *this, SDL_Surface *surface)
130 trace("%p", surface);
135 static void omap_UnlockHWSurface(SDL_VideoDevice *this, SDL_Surface *surface)
137 trace("%p", surface);
140 static int omap_FlipHWSurface(SDL_VideoDevice *this, SDL_Surface *surface)
142 trace("%p", surface);
144 surface->pixels = osdl_video_flip(this->hidden);
149 /* we can't do hw surfaces (besides screen one) yet */
150 static int omap_AllocHWSurface(SDL_VideoDevice *this, SDL_Surface *surface)
152 trace("%p", surface);
156 static void omap_FreeHWSurface(SDL_VideoDevice *this, SDL_Surface *surface)
158 trace("%p", surface);
161 static int omap_SetColors(SDL_VideoDevice *this, int firstcolor, int ncolors, SDL_Color *colors)
163 trace("%d, %d, %p", firstcolor, ncolors, colors);
167 static void omap_UpdateRects(SDL_VideoDevice *this, int nrects, SDL_Rect *rects)
169 trace("%d, %p", nrects, rects);
171 if (nrects != 1 || rects->x != 0 || rects->y != 0 ||
172 rects->w != this->screen->w || rects->h != this->screen->h) {
173 static int warned = 0;
180 this->screen->pixels = osdl_video_flip(this->hidden);
183 static void omap_InitOSKeymap(SDL_VideoDevice *this)
188 static int key_event_cb(void *cb_arg, int sdl_kc, int is_pressed)
190 SDL_keysym keysym = { 0, };
193 SDL_PrivateKeyboard(is_pressed, &keysym);
196 static int ts_event_cb(void *cb_arg, int x, int y, unsigned int pressure)
198 static int was_pressed;
200 SDL_PrivateMouseMotion(0, 0, x, y);
202 pressure = !!pressure;
203 if (pressure != was_pressed) {
204 SDL_PrivateMouseButton(pressure ? SDL_PRESSED : SDL_RELEASED, 1, 0, 0);
205 was_pressed = pressure;
209 static void omap_PumpEvents(SDL_VideoDevice *this)
211 struct SDL_PrivateVideoData *pdata = this->hidden;
216 omapsdl_input_get_events(0, key_event_cb, ts_event_cb, NULL);
218 // XXX: we might want to process some X events too
223 static SDL_VideoDevice *omap_create(int devindex)
225 SDL_VideoDevice *this;
227 this = calloc(1, sizeof(*this) + sizeof(*this->hidden));
232 this->hidden = (void *)(this + 1);
233 this->VideoInit = omap_VideoInit;
234 this->ListModes = omap_ListModes;
235 this->SetVideoMode = omap_SetVideoMode;
236 this->LockHWSurface = omap_LockHWSurface;
237 this->UnlockHWSurface = omap_UnlockHWSurface;
238 this->FlipHWSurface = omap_FlipHWSurface;
239 this->AllocHWSurface = omap_AllocHWSurface;
240 this->FreeHWSurface = omap_FreeHWSurface;
241 this->SetColors = omap_SetColors;
242 this->UpdateRects = omap_UpdateRects;
243 this->VideoQuit = omap_VideoQuit;
244 this->InitOSKeymap = omap_InitOSKeymap;
245 this->PumpEvents = omap_PumpEvents;
246 this->free = omap_free;
251 VideoBootStrap omapdss_bootstrap = {
252 "omapdss", "OMAP DSS2 Framebuffer Driver",
253 omap_available, omap_create