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->handles_any_size = 1;
53 this->info.hw_available = 1;
58 static void omap_VideoQuit(SDL_VideoDevice *this)
62 osdl_video_finish(this->hidden);
63 this->screen->pixels = NULL;
64 omapsdl_input_finish();
67 static SDL_Rect **omap_ListModes(SDL_VideoDevice *this, SDL_PixelFormat *format, Uint32 flags)
69 static SDL_Rect omap_mode_max = {
70 /* with handles_any_size, should accept anything up to this
71 * XXX: possibly set this dynamically based on free vram? */
74 /* broken API needs this stupidity */
75 static SDL_Rect *omap_modes[] = {
82 if (format->BitsPerPixel <= 8)
83 // not (yet?) supported
89 static SDL_Surface *omap_SetVideoMode(SDL_VideoDevice *this, SDL_Surface *current, int width,
90 int height, int bpp, Uint32 flags)
92 trace("%d, %d, %d, %08x", width, height, bpp, flags);
94 if (osdl_video_set_mode(this->hidden, width, height, bpp) < 0)
97 if (!SDL_ReallocFormat(current, 16, 0xf800, 0x07e0, 0x001f, 0))
100 current->flags = SDL_FULLSCREEN | SDL_DOUBLEBUF | SDL_HWSURFACE;
103 current->pitch = SDL_CalculatePitch(current);
105 current->pixels = osdl_video_flip(this->hidden);
110 static int omap_LockHWSurface(SDL_VideoDevice *this, SDL_Surface *surface)
112 trace("%p", surface);
117 static void omap_UnlockHWSurface(SDL_VideoDevice *this, SDL_Surface *surface)
119 trace("%p", surface);
122 static int omap_FlipHWSurface(SDL_VideoDevice *this, SDL_Surface *surface)
124 trace("%p", surface);
126 surface->pixels = osdl_video_flip(this->hidden);
131 /* we can't do hw surfaces (besides screen one) yet */
132 static int omap_AllocHWSurface(SDL_VideoDevice *this, SDL_Surface *surface)
134 trace("%p", surface);
138 static void omap_FreeHWSurface(SDL_VideoDevice *this, SDL_Surface *surface)
140 trace("%p", surface);
143 static int omap_SetColors(SDL_VideoDevice *this, int firstcolor, int ncolors, SDL_Color *colors)
145 trace("%d, %d, %p", firstcolor, ncolors, colors);
149 static void omap_UpdateRects(SDL_VideoDevice *this, int nrects, SDL_Rect *rects)
151 trace("%d, %p", nrects, rects);
153 if (nrects != 1 || rects->x != 0 || rects->y != 0 ||
154 rects->w != this->screen->w || rects->h != this->screen->h) {
155 static int warned = 0;
162 this->screen->pixels = osdl_video_flip(this->hidden);
165 static void omap_InitOSKeymap(SDL_VideoDevice *this)
170 static int key_event_cb(void *cb_arg, int sdl_kc, int is_pressed)
172 SDL_keysym keysym = { 0, };
175 SDL_PrivateKeyboard(is_pressed, &keysym);
178 static int ts_event_cb(void *cb_arg, int x, int y, unsigned int pressure)
180 static int was_pressed;
182 SDL_PrivateMouseMotion(0, 0, x, y);
184 pressure = !!pressure;
185 if (pressure != was_pressed) {
186 SDL_PrivateMouseButton(pressure ? SDL_PRESSED : SDL_RELEASED, 1, 0, 0);
187 was_pressed = pressure;
191 static void omap_PumpEvents(SDL_VideoDevice *this)
195 omapsdl_input_get_events(0, key_event_cb, ts_event_cb, NULL);
198 static SDL_VideoDevice *omap_create(int devindex)
200 SDL_VideoDevice *this;
202 this = calloc(1, sizeof(*this) + sizeof(*this->hidden));
207 this->hidden = (void *)(this + 1);
208 this->VideoInit = omap_VideoInit;
209 this->ListModes = omap_ListModes;
210 this->SetVideoMode = omap_SetVideoMode;
211 this->LockHWSurface = omap_LockHWSurface;
212 this->UnlockHWSurface = omap_UnlockHWSurface;
213 this->FlipHWSurface = omap_FlipHWSurface;
214 this->AllocHWSurface = omap_AllocHWSurface;
215 this->FreeHWSurface = omap_FreeHWSurface;
216 this->SetColors = omap_SetColors;
217 this->UpdateRects = omap_UpdateRects;
218 this->VideoQuit = omap_VideoQuit;
219 this->InitOSKeymap = omap_InitOSKeymap;
220 this->PumpEvents = omap_PumpEvents;
221 this->free = omap_free;
226 VideoBootStrap omapdss_bootstrap = {
227 "omapdss", "OMAP DSS2 Framebuffer Driver",
228 omap_available, omap_create