hook into SDL
[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
8#include <stdlib.h>
9
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"
15#include "omapsdl.h"
16
17
18struct SDL_PrivateVideoData {
19 struct vout_fbdev *fbdev;
20// void *fbmem;
21};
22
23static int omap_available(void)
24{
25 trace();
26 return 1;
27}
28
29static void omap_free(SDL_VideoDevice *device)
30{
31 trace();
32 free(device);
33}
34
35static int omap_VideoInit(SDL_VideoDevice *this, SDL_PixelFormat *vformat)
36{
37 trace();
38
39 // default to 16bpp
40 vformat->BitsPerPixel = 16;
41
42 omapsdl_input_init();
43 omapsdl_config();
44
45 return 0;
46}
47
48static void omap_VideoQuit(SDL_VideoDevice *this)
49{
50 trace();
51
52 if (this->hidden->fbdev != NULL) {
53 vout_fbdev_finish(this->hidden->fbdev);
54 this->hidden->fbdev = NULL;
55
56 oshide_finish();
57 }
58 this->screen->pixels = NULL;
59}
60
61static SDL_Rect **omap_ListModes(SDL_VideoDevice *this, SDL_PixelFormat *format, Uint32 flags)
62{
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
66 { 0, 0, 800, 480 },
67 { 0, 0, 720, 480 },
68 { 0, 0, 640, 480 },
69 { 0, 0, 640, 400 },
70 { 0, 0, 512, 384 },
71 { 0, 0, 320, 240 },
72 { 0, 0, 320, 200 },
73 };
74 // broken API needs this
75 static SDL_Rect *omap_modes[] = {
76 &omap_mode_list[0],
77 &omap_mode_list[1],
78 &omap_mode_list[2],
79 &omap_mode_list[3],
80 &omap_mode_list[4],
81 &omap_mode_list[5],
82 &omap_mode_list[6],
83 NULL
84 };
85
86 trace();
87
88 if (format->BitsPerPixel <= 8)
89 // not (yet?) supported
90 return NULL;
91
92 return omap_modes;
93}
94
95static SDL_Surface *omap_SetVideoMode(SDL_VideoDevice *this, SDL_Surface *current, int width,
96 int height, int bpp, Uint32 flags)
97{
98 trace("%d, %d, %d, %08x", width, height, bpp, flags);
99
100 if (this->hidden->fbdev == NULL) {
101 this->hidden->fbdev = vout_fbdev_init("/dev/fb0", &width, &height, 0);
102 if (this->hidden->fbdev == NULL)
103 return NULL;
104
105 oshide_init();
106 }
107 else {
108 if (vout_fbdev_resize(this->hidden->fbdev, width, height, 0, 0, 0, 0, 0) < 0)
109 return NULL;
110 }
111
112 if (!SDL_ReallocFormat(current, 16, 0xf800, 0x07e0, 0x001f, 0))
113 return NULL;
114
115 current->flags = SDL_FULLSCREEN | SDL_DOUBLEBUF | SDL_HWSURFACE;
116 current->w = width;
117 current->h = height;
118 current->pitch = SDL_CalculatePitch(current);
119
120 current->pixels = vout_fbdev_flip(this->hidden->fbdev);
121
122 return current;
123}
124
125static void *flip_it(struct vout_fbdev *fbdev)
126{
127 if (gcfg_force_vsync)
128 vout_fbdev_wait_vsync(fbdev);
129
130 return vout_fbdev_flip(fbdev);
131}
132
133static int omap_LockHWSurface(SDL_VideoDevice *this, SDL_Surface *surface)
134{
135 trace("%p", surface);
136
137 return 0;
138}
139
140static void omap_UnlockHWSurface(SDL_VideoDevice *this, SDL_Surface *surface)
141{
142 trace("%p", surface);
143}
144
145static int omap_FlipHWSurface(SDL_VideoDevice *this, SDL_Surface *surface)
146{
147 trace("%p", surface);
148
149 surface->pixels = flip_it(this->hidden->fbdev);
150
151 return 0;
152}
153
154static int omap_SetColors(SDL_VideoDevice *this, int firstcolor, int ncolors, SDL_Color *colors)
155{
156 trace("%d, %d, %p", firstcolor, ncolors, colors);
157 return 0;
158}
159
160static void omap_UpdateRects(SDL_VideoDevice *this, int nrects, SDL_Rect *rects)
161{
162 trace("%d, %p", nrects, rects);
163
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;
167 if (!warned) {
168 not_supported();
169 warned = 1;
170 }
171 }
172
173 if (this->hidden->fbdev)
174 this->screen->pixels = flip_it(this->hidden->fbdev);
175}
176
177static void omap_InitOSKeymap(SDL_VideoDevice *this)
178{
179 trace();
180}
181
182static int event_cb(void *cb_arg, int sdl_kc, int is_pressed)
183{
184 SDL_keysym keysym = { 0, };
185
186 keysym.sym = sdl_kc;
187 SDL_PrivateKeyboard(is_pressed, &keysym);
188}
189
190static void omap_PumpEvents(SDL_VideoDevice *this)
191{
192 trace();
193
194 omapsdl_input_get_events(0, event_cb, NULL);
195}
196
197static SDL_VideoDevice *omap_create(int devindex)
198{
199 SDL_VideoDevice *this;
200
201 this = calloc(1, sizeof(*this) + sizeof(*this->hidden));
202 if (this == NULL) {
203 SDL_OutOfMemory();
204 return 0;
205 }
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;
219
220 return this;
221}
222
223VideoBootStrap omapdss_bootstrap = {
224 "omapdss", "OMAP DSS2 Framebuffer Driver",
225 omap_available, omap_create
226};
227