2 * (C) GraÅžvydas "notaz" Ignotas, 2010-2012
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;
42 omapsdl_config(this->hidden);
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->phys_w;
51 this->info.current_h = this->hidden->phys_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 struct SDL_PrivateVideoData *pdata = this->hidden;
95 SDL_PixelFormat *format;
96 Uint32 unhandled_flags;
100 trace("%d, %d, %d, %08x", width, height, bpp, flags);
102 omapsdl_config_from_env(pdata);
106 format = SDL_ReallocFormat(current, 16, 0xf800, 0x07e0, 0x001f, 0);
109 format = SDL_ReallocFormat(current, 24, 0xff0000, 0xff00, 0xff, 0);
112 format = SDL_ReallocFormat(current, 32, 0xff0000, 0xff00, 0xff, 0);
115 err("SetVideoMode: bpp %d not supported", bpp);
121 if (!(flags & SDL_DOUBLEBUF) && pdata->cfg_force_doublebuf) {
122 log("forcing SDL_DOUBLEBUF");
123 flags |= SDL_DOUBLEBUF;
126 if (pdata->border_l | pdata->border_r | pdata->border_t | pdata->border_b) {
127 if (pdata->border_l + pdata->border_r >= width
128 || pdata->border_t + pdata->border_b >= height)
130 err("specified border too large, ignoring");
131 pdata->border_l = pdata->border_r = pdata->border_t = pdata->border_b = 0;
135 doublebuf = (flags & SDL_DOUBLEBUF) ? 1 : 0;
136 fbmem = osdl_video_set_mode(pdata,
137 pdata->border_l, pdata->border_r, pdata->border_t, pdata->border_b,
138 width, height, bpp, &doublebuf);
140 err("failing on mode %dx%d@%d, doublebuf %s, border %d,%d,%d,%d",
141 width, height, bpp, (flags & SDL_DOUBLEBUF) ? "on" : "off",
142 pdata->border_l, pdata->border_r, pdata->border_t, pdata->border_b);
145 if ((flags & SDL_DOUBLEBUF) && !doublebuf) {
146 log("doublebuffering could not be set\n");
147 flags &= ~SDL_DOUBLEBUF;
150 flags |= SDL_FULLSCREEN | SDL_HWSURFACE;
151 unhandled_flags = flags & ~(SDL_FULLSCREEN | SDL_HWSURFACE | SDL_DOUBLEBUF);
152 if (unhandled_flags != 0) {
153 log("dropping unhandled flags: %08x", unhandled_flags);
154 flags &= ~unhandled_flags;
157 current->flags = flags;
160 current->pitch = SDL_CalculatePitch(current);
161 current->pixels = fbmem;
162 pdata->app_uses_flip = 0;
164 if (pdata->layer_w != 0 && pdata->layer_h != 0) {
165 int v_width = width - (pdata->border_l + pdata->border_r);
166 int v_height = height - (pdata->border_t + pdata->border_b);
167 pdata->ts_xmul = (v_width << 16) / pdata->layer_w;
168 pdata->ts_ymul = (v_height << 16) / pdata->layer_h;
174 static int omap_LockHWSurface(SDL_VideoDevice *this, SDL_Surface *surface)
176 trace("%p", surface);
181 static void omap_UnlockHWSurface(SDL_VideoDevice *this, SDL_Surface *surface)
183 trace("%p", surface);
186 static int omap_FlipHWSurface(SDL_VideoDevice *this, SDL_Surface *surface)
188 struct SDL_PrivateVideoData *pdata = this->hidden;
190 trace("%p", surface);
192 surface->pixels = osdl_video_flip(pdata);
193 pdata->app_uses_flip = 1;
198 /* we can't do hw surfaces (besides screen one) yet */
199 static int omap_AllocHWSurface(SDL_VideoDevice *this, SDL_Surface *surface)
201 trace("%p", surface);
205 static void omap_FreeHWSurface(SDL_VideoDevice *this, SDL_Surface *surface)
207 trace("%p", surface);
210 static int omap_SetColors(SDL_VideoDevice *this, int firstcolor, int ncolors, SDL_Color *colors)
212 trace("%d, %d, %p", firstcolor, ncolors, colors);
216 static void omap_UpdateRects(SDL_VideoDevice *this, int nrects, SDL_Rect *rects)
218 struct SDL_PrivateVideoData *pdata = this->hidden;
220 trace("%d, %p", nrects, rects);
222 /* for doublebuf forcing on apps */
223 if (nrects == 1 && rects->x == 0 && rects->y == 0
224 && !pdata->app_uses_flip && (this->screen->flags & SDL_DOUBLEBUF)
225 && rects->w == this->screen->w && rects->h == this->screen->h)
227 this->screen->pixels = osdl_video_flip(pdata);
231 static void omap_InitOSKeymap(SDL_VideoDevice *this)
236 static int key_event_cb(void *cb_arg, int sdl_kc, int is_pressed)
238 SDL_keysym keysym = { 0, };
241 SDL_PrivateKeyboard(is_pressed, &keysym);
244 /* clamp x to min..max-1 */
245 #define clamp(x, min, max) \
246 if (x < (min)) x = min; \
247 if (x >= (max)) x = max
249 static int ts_event_cb(void *cb_arg, int x, int y, unsigned int pressure)
251 static int was_pressed;
252 SDL_VideoDevice *this = cb_arg;
253 struct SDL_PrivateVideoData *pdata = this->hidden;
256 if (!pdata->cfg_no_ts_translate && pdata->layer_w != 0 && pdata->layer_h != 0) {
257 x = pdata->border_l + ((x - pdata->layer_x) * pdata->ts_xmul >> 16);
258 y = pdata->border_t + ((y - pdata->layer_y) * pdata->ts_ymul >> 16);
259 clamp(x, 0, this->screen->w);
260 clamp(y, 0, this->screen->h);
263 SDL_PrivateMouseMotion(0, 0, x, y);
265 pressure = !!pressure;
266 if (pressure != was_pressed) {
267 SDL_PrivateMouseButton(pressure ? SDL_PRESSED : SDL_RELEASED, 1, 0, 0);
268 was_pressed = pressure;
272 static void omap_PumpEvents(SDL_VideoDevice *this)
274 struct SDL_PrivateVideoData *pdata = this->hidden;
279 omapsdl_input_get_events(0, key_event_cb, ts_event_cb, this);
281 // XXX: we might want to process some X events too
286 static SDL_VideoDevice *omap_create(int devindex)
288 SDL_VideoDevice *this;
290 this = calloc(1, sizeof(*this) + sizeof(*this->hidden));
295 this->hidden = (void *)(this + 1);
296 this->VideoInit = omap_VideoInit;
297 this->ListModes = omap_ListModes;
298 this->SetVideoMode = omap_SetVideoMode;
299 this->LockHWSurface = omap_LockHWSurface;
300 this->UnlockHWSurface = omap_UnlockHWSurface;
301 this->FlipHWSurface = omap_FlipHWSurface;
302 this->AllocHWSurface = omap_AllocHWSurface;
303 this->FreeHWSurface = omap_FreeHWSurface;
304 this->SetColors = omap_SetColors;
305 this->UpdateRects = omap_UpdateRects;
306 this->VideoQuit = omap_VideoQuit;
307 this->InitOSKeymap = omap_InitOSKeymap;
308 this->PumpEvents = omap_PumpEvents;
309 this->free = omap_free;
314 VideoBootStrap omapdss_bootstrap = {
315 "omapdss", "OMAP DSS2 Framebuffer Driver",
316 omap_available, omap_create