| 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 | |
| 18 | struct SDL_PrivateVideoData { |
| 19 | struct vout_fbdev *fbdev; |
| 20 | // void *fbmem; |
| 21 | }; |
| 22 | |
| 23 | static int omap_available(void) |
| 24 | { |
| 25 | trace(); |
| 26 | return 1; |
| 27 | } |
| 28 | |
| 29 | static void omap_free(SDL_VideoDevice *device) |
| 30 | { |
| 31 | trace(); |
| 32 | free(device); |
| 33 | } |
| 34 | |
| 35 | static 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 | |
| 48 | static 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 | omapsdl_input_finish(); |
| 60 | } |
| 61 | |
| 62 | static SDL_Rect **omap_ListModes(SDL_VideoDevice *this, SDL_PixelFormat *format, Uint32 flags) |
| 63 | { |
| 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 |
| 67 | { 0, 0, 800, 480 }, |
| 68 | { 0, 0, 720, 480 }, |
| 69 | { 0, 0, 640, 480 }, |
| 70 | { 0, 0, 640, 400 }, |
| 71 | { 0, 0, 512, 384 }, |
| 72 | { 0, 0, 320, 240 }, |
| 73 | { 0, 0, 320, 200 }, |
| 74 | }; |
| 75 | // broken API needs this |
| 76 | static SDL_Rect *omap_modes[] = { |
| 77 | &omap_mode_list[0], |
| 78 | &omap_mode_list[1], |
| 79 | &omap_mode_list[2], |
| 80 | &omap_mode_list[3], |
| 81 | &omap_mode_list[4], |
| 82 | &omap_mode_list[5], |
| 83 | &omap_mode_list[6], |
| 84 | NULL |
| 85 | }; |
| 86 | |
| 87 | trace(); |
| 88 | |
| 89 | if (format->BitsPerPixel <= 8) |
| 90 | // not (yet?) supported |
| 91 | return NULL; |
| 92 | |
| 93 | return omap_modes; |
| 94 | } |
| 95 | |
| 96 | static SDL_Surface *omap_SetVideoMode(SDL_VideoDevice *this, SDL_Surface *current, int width, |
| 97 | int height, int bpp, Uint32 flags) |
| 98 | { |
| 99 | trace("%d, %d, %d, %08x", width, height, bpp, flags); |
| 100 | |
| 101 | if (this->hidden->fbdev == NULL) { |
| 102 | this->hidden->fbdev = vout_fbdev_init("/dev/fb0", &width, &height, 0); |
| 103 | if (this->hidden->fbdev == NULL) |
| 104 | return NULL; |
| 105 | |
| 106 | oshide_init(); |
| 107 | } |
| 108 | else { |
| 109 | if (vout_fbdev_resize(this->hidden->fbdev, width, height, 0, 0, 0, 0, 0) < 0) |
| 110 | return NULL; |
| 111 | } |
| 112 | |
| 113 | if (!SDL_ReallocFormat(current, 16, 0xf800, 0x07e0, 0x001f, 0)) |
| 114 | return NULL; |
| 115 | |
| 116 | current->flags = SDL_FULLSCREEN | SDL_DOUBLEBUF | SDL_HWSURFACE; |
| 117 | current->w = width; |
| 118 | current->h = height; |
| 119 | current->pitch = SDL_CalculatePitch(current); |
| 120 | |
| 121 | current->pixels = vout_fbdev_flip(this->hidden->fbdev); |
| 122 | |
| 123 | return current; |
| 124 | } |
| 125 | |
| 126 | static void *flip_it(struct vout_fbdev *fbdev) |
| 127 | { |
| 128 | if (gcfg_force_vsync) |
| 129 | vout_fbdev_wait_vsync(fbdev); |
| 130 | |
| 131 | return vout_fbdev_flip(fbdev); |
| 132 | } |
| 133 | |
| 134 | static int omap_LockHWSurface(SDL_VideoDevice *this, SDL_Surface *surface) |
| 135 | { |
| 136 | trace("%p", surface); |
| 137 | |
| 138 | return 0; |
| 139 | } |
| 140 | |
| 141 | static void omap_UnlockHWSurface(SDL_VideoDevice *this, SDL_Surface *surface) |
| 142 | { |
| 143 | trace("%p", surface); |
| 144 | } |
| 145 | |
| 146 | static int omap_FlipHWSurface(SDL_VideoDevice *this, SDL_Surface *surface) |
| 147 | { |
| 148 | trace("%p", surface); |
| 149 | |
| 150 | surface->pixels = flip_it(this->hidden->fbdev); |
| 151 | |
| 152 | return 0; |
| 153 | } |
| 154 | |
| 155 | static int omap_SetColors(SDL_VideoDevice *this, int firstcolor, int ncolors, SDL_Color *colors) |
| 156 | { |
| 157 | trace("%d, %d, %p", firstcolor, ncolors, colors); |
| 158 | return 0; |
| 159 | } |
| 160 | |
| 161 | static void omap_UpdateRects(SDL_VideoDevice *this, int nrects, SDL_Rect *rects) |
| 162 | { |
| 163 | trace("%d, %p", nrects, rects); |
| 164 | |
| 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; |
| 168 | if (!warned) { |
| 169 | not_supported(); |
| 170 | warned = 1; |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | if (this->hidden->fbdev) |
| 175 | this->screen->pixels = flip_it(this->hidden->fbdev); |
| 176 | } |
| 177 | |
| 178 | static void omap_InitOSKeymap(SDL_VideoDevice *this) |
| 179 | { |
| 180 | trace(); |
| 181 | } |
| 182 | |
| 183 | static int key_event_cb(void *cb_arg, int sdl_kc, int is_pressed) |
| 184 | { |
| 185 | SDL_keysym keysym = { 0, }; |
| 186 | |
| 187 | keysym.sym = sdl_kc; |
| 188 | SDL_PrivateKeyboard(is_pressed, &keysym); |
| 189 | } |
| 190 | |
| 191 | static int ts_event_cb(void *cb_arg, int x, int y, unsigned int pressure) |
| 192 | { |
| 193 | static int was_pressed; |
| 194 | |
| 195 | SDL_PrivateMouseMotion(0, 0, x, y); |
| 196 | |
| 197 | pressure = !!pressure; |
| 198 | if (pressure != was_pressed) { |
| 199 | SDL_PrivateMouseButton(pressure ? SDL_PRESSED : SDL_RELEASED, 1, 0, 0); |
| 200 | was_pressed = pressure; |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | static void omap_PumpEvents(SDL_VideoDevice *this) |
| 205 | { |
| 206 | trace(); |
| 207 | |
| 208 | omapsdl_input_get_events(0, key_event_cb, ts_event_cb, NULL); |
| 209 | } |
| 210 | |
| 211 | static SDL_VideoDevice *omap_create(int devindex) |
| 212 | { |
| 213 | SDL_VideoDevice *this; |
| 214 | |
| 215 | this = calloc(1, sizeof(*this) + sizeof(*this->hidden)); |
| 216 | if (this == NULL) { |
| 217 | SDL_OutOfMemory(); |
| 218 | return 0; |
| 219 | } |
| 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; |
| 233 | |
| 234 | return this; |
| 235 | } |
| 236 | |
| 237 | VideoBootStrap omapdss_bootstrap = { |
| 238 | "omapdss", "OMAP DSS2 Framebuffer Driver", |
| 239 | omap_available, omap_create |
| 240 | }; |
| 241 | |