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;
59 omapsdl_input_finish();
62 static SDL_Rect **omap_ListModes(SDL_VideoDevice *this, SDL_PixelFormat *format, Uint32 flags)
64 static SDL_Rect omap_mode_list[] = {
65 // XXX: we are not really restricted to fixed modes
66 // FIXME: should really check the display for max supported
75 // broken API needs this
76 static SDL_Rect *omap_modes[] = {
89 if (format->BitsPerPixel <= 8)
90 // not (yet?) supported
96 static SDL_Surface *omap_SetVideoMode(SDL_VideoDevice *this, SDL_Surface *current, int width,
97 int height, int bpp, Uint32 flags)
99 trace("%d, %d, %d, %08x", width, height, bpp, flags);
101 if (this->hidden->fbdev == NULL) {
102 this->hidden->fbdev = vout_fbdev_init("/dev/fb0", &width, &height, 0);
103 if (this->hidden->fbdev == NULL)
109 if (vout_fbdev_resize(this->hidden->fbdev, width, height, 0, 0, 0, 0, 0) < 0)
113 if (!SDL_ReallocFormat(current, 16, 0xf800, 0x07e0, 0x001f, 0))
116 current->flags = SDL_FULLSCREEN | SDL_DOUBLEBUF | SDL_HWSURFACE;
119 current->pitch = SDL_CalculatePitch(current);
121 current->pixels = vout_fbdev_flip(this->hidden->fbdev);
126 static void *flip_it(struct vout_fbdev *fbdev)
128 if (gcfg_force_vsync)
129 vout_fbdev_wait_vsync(fbdev);
131 return vout_fbdev_flip(fbdev);
134 static int omap_LockHWSurface(SDL_VideoDevice *this, SDL_Surface *surface)
136 trace("%p", surface);
141 static void omap_UnlockHWSurface(SDL_VideoDevice *this, SDL_Surface *surface)
143 trace("%p", surface);
146 static int omap_FlipHWSurface(SDL_VideoDevice *this, SDL_Surface *surface)
148 trace("%p", surface);
150 surface->pixels = flip_it(this->hidden->fbdev);
155 static int omap_SetColors(SDL_VideoDevice *this, int firstcolor, int ncolors, SDL_Color *colors)
157 trace("%d, %d, %p", firstcolor, ncolors, colors);
161 static void omap_UpdateRects(SDL_VideoDevice *this, int nrects, SDL_Rect *rects)
163 trace("%d, %p", nrects, rects);
165 if (nrects != 1 || rects->x != 0 || rects->y != 0 ||
166 rects->w != this->screen->w || rects->h != this->screen->h) {
167 static int warned = 0;
174 if (this->hidden->fbdev)
175 this->screen->pixels = flip_it(this->hidden->fbdev);
178 static void omap_InitOSKeymap(SDL_VideoDevice *this)
183 static int key_event_cb(void *cb_arg, int sdl_kc, int is_pressed)
185 SDL_keysym keysym = { 0, };
188 SDL_PrivateKeyboard(is_pressed, &keysym);
191 static int ts_event_cb(void *cb_arg, int x, int y, unsigned int pressure)
193 static int was_pressed;
195 SDL_PrivateMouseMotion(0, 0, x, y);
197 pressure = !!pressure;
198 if (pressure != was_pressed) {
199 SDL_PrivateMouseButton(pressure ? SDL_PRESSED : SDL_RELEASED, 1, 0, 0);
200 was_pressed = pressure;
204 static void omap_PumpEvents(SDL_VideoDevice *this)
208 omapsdl_input_get_events(0, key_event_cb, ts_event_cb, NULL);
211 static SDL_VideoDevice *omap_create(int devindex)
213 SDL_VideoDevice *this;
215 this = calloc(1, sizeof(*this) + sizeof(*this->hidden));
220 this->hidden = (void *)(this + 1);
221 this->VideoInit = omap_VideoInit;
222 this->ListModes = omap_ListModes;
223 this->SetVideoMode = omap_SetVideoMode;
224 this->LockHWSurface = omap_LockHWSurface;
225 this->UnlockHWSurface = omap_UnlockHWSurface;
226 this->FlipHWSurface = omap_FlipHWSurface;
227 this->SetColors = omap_SetColors;
228 this->UpdateRects = omap_UpdateRects;
229 this->VideoQuit = omap_VideoQuit;
230 this->InitOSKeymap = omap_InitOSKeymap;
231 this->PumpEvents = omap_PumpEvents;
232 this->free = omap_free;
237 VideoBootStrap omapdss_bootstrap = {
238 "omapdss", "OMAP DSS2 Framebuffer Driver",
239 omap_available, omap_create