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.
10 #include "../SDL_sysvideo.h"
11 #include "../SDL_pixels_c.h"
12 #include "../../events/SDL_events_c.h"
13 #include "linux/fbdev.h"
14 #include "linux/oshide.h"
18 struct SDL_PrivateVideoData {
19 struct vout_fbdev *fbdev;
23 static int omap_available(void)
29 static void omap_free(SDL_VideoDevice *device)
35 static int omap_VideoInit(SDL_VideoDevice *this, SDL_PixelFormat *vformat)
40 vformat->BitsPerPixel = 16;
48 static void omap_VideoQuit(SDL_VideoDevice *this)
52 if (this->hidden->fbdev != NULL) {
53 vout_fbdev_finish(this->hidden->fbdev);
54 this->hidden->fbdev = NULL;
58 this->screen->pixels = NULL;
61 static SDL_Rect **omap_ListModes(SDL_VideoDevice *this, SDL_PixelFormat *format, Uint32 flags)
63 static SDL_Rect omap_mode_list[] = {
64 // XXX: we are not really restricted to fixed modes
65 // FIXME: should really check the display for max supported
74 // broken API needs this
75 static SDL_Rect *omap_modes[] = {
88 if (format->BitsPerPixel <= 8)
89 // not (yet?) supported
95 static SDL_Surface *omap_SetVideoMode(SDL_VideoDevice *this, SDL_Surface *current, int width,
96 int height, int bpp, Uint32 flags)
98 trace("%d, %d, %d, %08x", width, height, bpp, flags);
100 if (this->hidden->fbdev == NULL) {
101 this->hidden->fbdev = vout_fbdev_init("/dev/fb0", &width, &height, 0);
102 if (this->hidden->fbdev == NULL)
108 if (vout_fbdev_resize(this->hidden->fbdev, width, height, 0, 0, 0, 0, 0) < 0)
112 if (!SDL_ReallocFormat(current, 16, 0xf800, 0x07e0, 0x001f, 0))
115 current->flags = SDL_FULLSCREEN | SDL_DOUBLEBUF | SDL_HWSURFACE;
118 current->pitch = SDL_CalculatePitch(current);
120 current->pixels = vout_fbdev_flip(this->hidden->fbdev);
125 static void *flip_it(struct vout_fbdev *fbdev)
127 if (gcfg_force_vsync)
128 vout_fbdev_wait_vsync(fbdev);
130 return vout_fbdev_flip(fbdev);
133 static int omap_LockHWSurface(SDL_VideoDevice *this, SDL_Surface *surface)
135 trace("%p", surface);
140 static void omap_UnlockHWSurface(SDL_VideoDevice *this, SDL_Surface *surface)
142 trace("%p", surface);
145 static int omap_FlipHWSurface(SDL_VideoDevice *this, SDL_Surface *surface)
147 trace("%p", surface);
149 surface->pixels = flip_it(this->hidden->fbdev);
154 static int omap_SetColors(SDL_VideoDevice *this, int firstcolor, int ncolors, SDL_Color *colors)
156 trace("%d, %d, %p", firstcolor, ncolors, colors);
160 static void omap_UpdateRects(SDL_VideoDevice *this, int nrects, SDL_Rect *rects)
162 trace("%d, %p", nrects, rects);
164 if (nrects != 1 || rects->x != 0 || rects->y != 0 ||
165 rects->w != this->screen->w || rects->h != this->screen->h) {
166 static int warned = 0;
173 if (this->hidden->fbdev)
174 this->screen->pixels = flip_it(this->hidden->fbdev);
177 static void omap_InitOSKeymap(SDL_VideoDevice *this)
182 static int event_cb(void *cb_arg, int sdl_kc, int is_pressed)
184 SDL_keysym keysym = { 0, };
187 SDL_PrivateKeyboard(is_pressed, &keysym);
190 static void omap_PumpEvents(SDL_VideoDevice *this)
194 omapsdl_input_get_events(0, event_cb, NULL);
197 static SDL_VideoDevice *omap_create(int devindex)
199 SDL_VideoDevice *this;
201 this = calloc(1, sizeof(*this) + sizeof(*this->hidden));
206 this->hidden = (void *)(this + 1);
207 this->VideoInit = omap_VideoInit;
208 this->ListModes = omap_ListModes;
209 this->SetVideoMode = omap_SetVideoMode;
210 this->LockHWSurface = omap_LockHWSurface;
211 this->UnlockHWSurface = omap_UnlockHWSurface;
212 this->FlipHWSurface = omap_FlipHWSurface;
213 this->SetColors = omap_SetColors;
214 this->UpdateRects = omap_UpdateRects;
215 this->VideoQuit = omap_VideoQuit;
216 this->InitOSKeymap = omap_InitOSKeymap;
217 this->PumpEvents = omap_PumpEvents;
218 this->free = omap_free;
223 VideoBootStrap omapdss_bootstrap = {
224 "omapdss", "OMAP DSS2 Framebuffer Driver",
225 omap_available, omap_create