map remaining fn keys to something
[sdl_omap.git] / src / video / omapdss / sdlif.c
CommitLineData
9a8e84f8 1/*
2 * (C) GraÅžvydas "notaz" Ignotas, 2010
3 *
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.
6 */
7
b9a19b44 8#include <stdio.h>
9a8e84f8 9#include <stdlib.h>
10
11#include "../SDL_sysvideo.h"
12#include "../SDL_pixels_c.h"
13#include "../../events/SDL_events_c.h"
9a8e84f8 14#include "omapsdl.h"
15
16
9a8e84f8 17static int omap_available(void)
18{
19 trace();
20 return 1;
21}
22
23static void omap_free(SDL_VideoDevice *device)
24{
25 trace();
26 free(device);
27}
28
29static int omap_VideoInit(SDL_VideoDevice *this, SDL_PixelFormat *vformat)
30{
b9a19b44 31 const char *tmp;
32 int w, h, ret;
33
9a8e84f8 34 trace();
35
36 // default to 16bpp
37 vformat->BitsPerPixel = 16;
38
39 omapsdl_input_init();
40 omapsdl_config();
41
b9a19b44 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;
46 }
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;
50 }
51
5d957fa5 52 this->handles_any_size = 1;
b9a19b44 53 this->info.hw_available = 1;
54
9a8e84f8 55 return 0;
56}
57
58static void omap_VideoQuit(SDL_VideoDevice *this)
59{
60 trace();
61
f641fccb 62 osdl_video_finish(this->hidden);
9a8e84f8 63 this->screen->pixels = NULL;
17e19802 64 omapsdl_input_finish();
9a8e84f8 65}
66
67static SDL_Rect **omap_ListModes(SDL_VideoDevice *this, SDL_PixelFormat *format, Uint32 flags)
68{
5d957fa5 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? */
72 0, 0, 1600, 1200
9a8e84f8 73 };
b9a19b44 74 /* broken API needs this stupidity */
9a8e84f8 75 static SDL_Rect *omap_modes[] = {
5d957fa5 76 &omap_mode_max,
9a8e84f8 77 NULL
78 };
79
80 trace();
81
82 if (format->BitsPerPixel <= 8)
83 // not (yet?) supported
84 return NULL;
85
86 return omap_modes;
87}
88
89static SDL_Surface *omap_SetVideoMode(SDL_VideoDevice *this, SDL_Surface *current, int width,
90 int height, int bpp, Uint32 flags)
91{
92 trace("%d, %d, %d, %08x", width, height, bpp, flags);
93
f641fccb 94 if (osdl_video_set_mode(this->hidden, width, height, bpp) < 0)
95 return NULL;
9a8e84f8 96
97 if (!SDL_ReallocFormat(current, 16, 0xf800, 0x07e0, 0x001f, 0))
98 return NULL;
99
100 current->flags = SDL_FULLSCREEN | SDL_DOUBLEBUF | SDL_HWSURFACE;
101 current->w = width;
102 current->h = height;
103 current->pitch = SDL_CalculatePitch(current);
104
f641fccb 105 current->pixels = osdl_video_flip(this->hidden);
9a8e84f8 106
107 return current;
108}
109
9a8e84f8 110static int omap_LockHWSurface(SDL_VideoDevice *this, SDL_Surface *surface)
111{
112 trace("%p", surface);
113
114 return 0;
115}
116
117static void omap_UnlockHWSurface(SDL_VideoDevice *this, SDL_Surface *surface)
118{
119 trace("%p", surface);
120}
121
122static int omap_FlipHWSurface(SDL_VideoDevice *this, SDL_Surface *surface)
123{
124 trace("%p", surface);
125
f641fccb 126 surface->pixels = osdl_video_flip(this->hidden);
9a8e84f8 127
128 return 0;
129}
130
37299201 131/* we can't do hw surfaces (besides screen one) yet */
132static int omap_AllocHWSurface(SDL_VideoDevice *this, SDL_Surface *surface)
133{
134 trace("%p", surface);
135 return -1;
136}
137
138static void omap_FreeHWSurface(SDL_VideoDevice *this, SDL_Surface *surface)
139{
140 trace("%p", surface);
141}
142
9a8e84f8 143static int omap_SetColors(SDL_VideoDevice *this, int firstcolor, int ncolors, SDL_Color *colors)
144{
145 trace("%d, %d, %p", firstcolor, ncolors, colors);
146 return 0;
147}
148
149static void omap_UpdateRects(SDL_VideoDevice *this, int nrects, SDL_Rect *rects)
150{
151 trace("%d, %p", nrects, rects);
152
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;
156 if (!warned) {
157 not_supported();
158 warned = 1;
159 }
160 }
161
f641fccb 162 this->screen->pixels = osdl_video_flip(this->hidden);
9a8e84f8 163}
164
165static void omap_InitOSKeymap(SDL_VideoDevice *this)
166{
167 trace();
168}
169
17e19802 170static int key_event_cb(void *cb_arg, int sdl_kc, int is_pressed)
9a8e84f8 171{
172 SDL_keysym keysym = { 0, };
173
174 keysym.sym = sdl_kc;
175 SDL_PrivateKeyboard(is_pressed, &keysym);
176}
177
17e19802 178static int ts_event_cb(void *cb_arg, int x, int y, unsigned int pressure)
179{
180 static int was_pressed;
181
182 SDL_PrivateMouseMotion(0, 0, x, y);
183
184 pressure = !!pressure;
185 if (pressure != was_pressed) {
186 SDL_PrivateMouseButton(pressure ? SDL_PRESSED : SDL_RELEASED, 1, 0, 0);
187 was_pressed = pressure;
188 }
189}
190
9a8e84f8 191static void omap_PumpEvents(SDL_VideoDevice *this)
192{
193 trace();
194
17e19802 195 omapsdl_input_get_events(0, key_event_cb, ts_event_cb, NULL);
9a8e84f8 196}
197
198static SDL_VideoDevice *omap_create(int devindex)
199{
200 SDL_VideoDevice *this;
201
202 this = calloc(1, sizeof(*this) + sizeof(*this->hidden));
203 if (this == NULL) {
204 SDL_OutOfMemory();
205 return 0;
206 }
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;
37299201 214 this->AllocHWSurface = omap_AllocHWSurface;
215 this->FreeHWSurface = omap_FreeHWSurface;
9a8e84f8 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;
222
223 return this;
224}
225
226VideoBootStrap omapdss_bootstrap = {
227 "omapdss", "OMAP DSS2 Framebuffer Driver",
228 omap_available, omap_create
229};
230