comparison src/video/directfb/SDL_DirectFB_events.c @ 2226:0e70b4b8cf84

Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST) From: couriersud arcor.de To: slouken@libsdl.org Subject: Directfb driver for SDL1.3 Hi, the attachment contains a patch for a SDL1.3 directfb driver. It supports: - Renderer "directfb": Hardware acceleration as supported by the underlying directfb driver. With a radeon X850, testsprite2 runs at 50% to 70% of OpenGL (X11, dri) performance. Also supports hardware accelerated yuv overlays. This must be enabled by sett ing: export SDL_DIRECTFB_YUV_DIRECT=1 - Renderer "opengl" Supports software opengl using mesa opengl (make linux-directfb). Some more information may be found in README.DirectFB There will certainly still be some bugs, and there is some debug code around. When I find some time, I will compile against directfb-0.9.25 as distributed with ubuntu 7.04. The diff also contains a fix for SDL_LockYUVOverlay fixing a bug in *pixels and pitches initialization. Kind regards, couriersud
author Sam Lantinga <slouken@libsdl.org>
date Sat, 11 Aug 2007 21:51:19 +0000
parents c121d94672cb
children 1e690901ecd7
comparison
equal deleted inserted replaced
2225:3bca1b7ca25b 2226:0e70b4b8cf84
21 */ 21 */
22 #include "SDL_config.h" 22 #include "SDL_config.h"
23 23
24 /* Handle the event stream, converting DirectFB input events into SDL events */ 24 /* Handle the event stream, converting DirectFB input events into SDL events */
25 25
26 #include <sys/types.h>
27 #include <sys/time.h>
28 #include <unistd.h>
29 #include <fcntl.h>
30 #include <termios.h>
31
32 #include <directfb.h> 26 #include <directfb.h>
33 27
34 #include "SDL.h" 28 #include "SDL.h"
35 #include "../SDL_sysvideo.h" 29 #include "../SDL_sysvideo.h"
36 #include "../../events/SDL_sysevents.h" 30 #include "../../events/SDL_sysevents.h"
37 #include "../../events/SDL_events_c.h" 31 #include "../../events/SDL_events_c.h"
38 #include "SDL_DirectFB_video.h"
39 #include "SDL_DirectFB_events.h" 32 #include "SDL_DirectFB_events.h"
40 33
41 /* The translation tables from a DirectFB keycode to a SDL keysym */ 34 /* The translation tables from a DirectFB keycode to a SDL keysym */
42 static SDLKey keymap[256]; 35 static SDLKey keymap[256];
43 static SDL_keysym *DirectFB_TranslateKey(DFBInputEvent * ev, 36
37 static SDL_keysym *DirectFB_TranslateKey(DFBInputDeviceKeyIdentifier key_id,
38 DFBInputDeviceKeySymbol key_symbol,
39 DFBInputDeviceModifierMask key_mod,
44 SDL_keysym * keysym); 40 SDL_keysym * keysym);
45 static int DirectFB_TranslateButton(DFBInputEvent * ev); 41
46 42 static int DirectFB_TranslateButton(DFBInputDeviceButtonIdentifier button);
47 static int posted = 0;
48
49 43
50 void 44 void
51 DirectFB_PumpEvents(_THIS) 45 DirectFB_PumpEventsWindow(_THIS)
52 { 46 {
53 DFBInputEvent evt; 47 SDL_DFB_DEVICEDATA(_this);
54 48 DFB_WindowData *p;
55 while (HIDDEN->eventbuffer->GetEvent(HIDDEN->eventbuffer, 49 DFBWindowEvent evt;
56 DFB_EVENT(&evt)) == DFB_OK) { 50
57 SDL_keysym keysym; 51 for (p = devdata->firstwin; p != NULL; p = p->next) {
58 52 while (p->eventbuffer->GetEvent(p->eventbuffer,
59 switch (evt.type) { 53 DFB_EVENT(&evt)) == DFB_OK) {
60 case DIET_BUTTONPRESS: 54 SDL_keysym keysym;
61 posted += SDL_PrivateMouseButton(SDL_PRESSED, 55
62 DirectFB_TranslateButton 56 if (evt.clazz = DFEC_WINDOW) {
63 (&evt), 0, 0); 57 switch (evt.type) {
64 break; 58 case DWET_BUTTONDOWN:
65 case DIET_BUTTONRELEASE: 59 SDL_SendMouseButton(devdata->mouse, SDL_PRESSED,
66 posted += SDL_PrivateMouseButton(SDL_RELEASED, 60 DirectFB_TranslateButton(evt.button));
67 DirectFB_TranslateButton 61 break;
68 (&evt), 0, 0); 62 case DWET_BUTTONUP:
69 break; 63 SDL_SendMouseButton(devdata->mouse, SDL_RELEASED,
70 case DIET_KEYPRESS: 64 DirectFB_TranslateButton(evt.button));
71 posted += 65 break;
72 SDL_PrivateKeyboard(SDL_PRESSED, 66 case DWET_MOTION:
73 DirectFB_TranslateKey(&evt, &keysym)); 67 SDL_SendMouseMotion(devdata->mouse, 0, evt.x, evt.y);
74 break; 68 break;
75 case DIET_KEYRELEASE: 69 case DWET_KEYDOWN:
76 posted += 70 DirectFB_TranslateKey(evt.key_id, evt.key_symbol,
77 SDL_PrivateKeyboard(SDL_RELEASED, 71 evt.modifiers, &keysym);
78 DirectFB_TranslateKey(&evt, &keysym)); 72 SDL_SendKeyboardKey(devdata->keyboard, SDL_PRESSED,
79 break; 73 keysym.scancode, keysym.sym);
80 case DIET_AXISMOTION: 74 break;
81 if (evt.flags & DIEF_AXISREL) { 75 case DWET_KEYUP:
82 if (evt.axis == DIAI_X) 76 DirectFB_TranslateKey(evt.key_id, evt.key_symbol,
83 posted += SDL_PrivateMouseMotion(0, 1, evt.axisrel, 0); 77 evt.modifiers, &keysym);
84 else if (evt.axis == DIAI_Y) 78 SDL_SendKeyboardKey(devdata->keyboard, SDL_RELEASED,
85 posted += SDL_PrivateMouseMotion(0, 1, 0, evt.axisrel); 79 keysym.scancode, keysym.sym);
80 break;
81 case DWET_POSITION_SIZE:
82 SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_MOVED, evt.cx,
83 evt.cy);
84 SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_RESIZED, evt.w,
85 evt.h);
86 break;
87 case DWET_POSITION:
88 SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_MOVED, evt.cx,
89 evt.cy);
90 break;
91 case DWET_SIZE:
92 SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_RESIZED, evt.w,
93 evt.h);
94 break;
95 case DWET_CLOSE:
96 SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_CLOSE, 0, 0);
97 break;
98 case DWET_GOTFOCUS:
99 //TODO: Implement for yuv-overlay DirectFB_SwitchOverlayContext(this, evt.window_id);
100 SDL_SetKeyboardFocus(devdata->keyboard, p->id);
101 break;
102 case DWET_LOSTFOCUS:
103 SDL_SetKeyboardFocus(devdata->keyboard, 0);
104 break;
105 case DWET_ENTER:
106 //SDL_DirectFB_ReshowCursor(_this, 0);
107 SDL_SetMouseFocus(devdata->mouse, p->id);
108 break;
109 case DWET_LEAVE:
110 SDL_SetMouseFocus(devdata->mouse, 0);
111 //SDL_DirectFB_ReshowCursor(_this, 1);
112 break;
113 default:
114 ;
115 }
86 } 116 }
87 break;
88 default:
89 ;
90 } 117 }
91 } 118 }
92 } 119 }
93 120
94 void 121 void
175 keymap[DIKI_CAPS_LOCK - DIKI_UNKNOWN] = SDLK_CAPSLOCK; 202 keymap[DIKI_CAPS_LOCK - DIKI_UNKNOWN] = SDLK_CAPSLOCK;
176 keymap[DIKI_NUM_LOCK - DIKI_UNKNOWN] = SDLK_NUMLOCK; 203 keymap[DIKI_NUM_LOCK - DIKI_UNKNOWN] = SDLK_NUMLOCK;
177 keymap[DIKI_SCROLL_LOCK - DIKI_UNKNOWN] = SDLK_SCROLLOCK; 204 keymap[DIKI_SCROLL_LOCK - DIKI_UNKNOWN] = SDLK_SCROLLOCK;
178 keymap[DIKI_PRINT - DIKI_UNKNOWN] = SDLK_PRINT; 205 keymap[DIKI_PRINT - DIKI_UNKNOWN] = SDLK_PRINT;
179 keymap[DIKI_PAUSE - DIKI_UNKNOWN] = SDLK_PAUSE; 206 keymap[DIKI_PAUSE - DIKI_UNKNOWN] = SDLK_PAUSE;
207
208 keymap[DIKI_KP_EQUAL - DIKI_UNKNOWN] = SDLK_KP_EQUALS;
209 keymap[DIKI_KP_DECIMAL - DIKI_UNKNOWN] = SDLK_KP_PERIOD;
210 keymap[DIKI_KP_0 - DIKI_UNKNOWN] = SDLK_KP0;
211 keymap[DIKI_KP_1 - DIKI_UNKNOWN] = SDLK_KP1;
212 keymap[DIKI_KP_2 - DIKI_UNKNOWN] = SDLK_KP2;
213 keymap[DIKI_KP_3 - DIKI_UNKNOWN] = SDLK_KP3;
214 keymap[DIKI_KP_4 - DIKI_UNKNOWN] = SDLK_KP4;
215 keymap[DIKI_KP_5 - DIKI_UNKNOWN] = SDLK_KP5;
216 keymap[DIKI_KP_6 - DIKI_UNKNOWN] = SDLK_KP6;
217 keymap[DIKI_KP_7 - DIKI_UNKNOWN] = SDLK_KP7;
218 keymap[DIKI_KP_8 - DIKI_UNKNOWN] = SDLK_KP8;
219 keymap[DIKI_KP_9 - DIKI_UNKNOWN] = SDLK_KP9;
180 keymap[DIKI_KP_DIV - DIKI_UNKNOWN] = SDLK_KP_DIVIDE; 220 keymap[DIKI_KP_DIV - DIKI_UNKNOWN] = SDLK_KP_DIVIDE;
181 keymap[DIKI_KP_MULT - DIKI_UNKNOWN] = SDLK_KP_MULTIPLY; 221 keymap[DIKI_KP_MULT - DIKI_UNKNOWN] = SDLK_KP_MULTIPLY;
182 keymap[DIKI_KP_MINUS - DIKI_UNKNOWN] = SDLK_KP_MINUS; 222 keymap[DIKI_KP_MINUS - DIKI_UNKNOWN] = SDLK_KP_MINUS;
183 keymap[DIKI_KP_PLUS - DIKI_UNKNOWN] = SDLK_KP_PLUS; 223 keymap[DIKI_KP_PLUS - DIKI_UNKNOWN] = SDLK_KP_PLUS;
184 keymap[DIKI_KP_ENTER - DIKI_UNKNOWN] = SDLK_KP_ENTER; 224 keymap[DIKI_KP_ENTER - DIKI_UNKNOWN] = SDLK_KP_ENTER;
185 } 225
186 226 keymap[DIKI_QUOTE_LEFT - DIKI_UNKNOWN] = SDLK_BACKQUOTE; /* TLDE */
227 keymap[DIKI_MINUS_SIGN - DIKI_UNKNOWN] = SDLK_MINUS; /* AE11 */
228 keymap[DIKI_EQUALS_SIGN - DIKI_UNKNOWN] = SDLK_EQUALS; /* AE12 */
229 keymap[DIKI_BRACKET_LEFT - DIKI_UNKNOWN] = SDLK_RIGHTBRACKET; /* AD11 */
230 keymap[DIKI_BRACKET_RIGHT - DIKI_UNKNOWN] = SDLK_LEFTBRACKET; /* AD12 */
231 keymap[DIKI_BACKSLASH - DIKI_UNKNOWN] = SDLK_BACKSLASH; /* BKSL */
232 keymap[DIKI_SEMICOLON - DIKI_UNKNOWN] = SDLK_SEMICOLON; /* AC10 */
233 keymap[DIKI_QUOTE_RIGHT - DIKI_UNKNOWN] = SDLK_QUOTE; /* AC11 */
234 keymap[DIKI_COMMA - DIKI_UNKNOWN] = SDLK_COMMA; /* AB08 */
235 keymap[DIKI_PERIOD - DIKI_UNKNOWN] = SDLK_PERIOD; /* AB09 */
236 keymap[DIKI_SLASH - DIKI_UNKNOWN] = SDLK_SLASH; /* AB10 */
237 keymap[DIKI_LESS_SIGN - DIKI_UNKNOWN] = SDLK_LESS; /* 103rd */
238 }
187 239
188 static SDL_keysym * 240 static SDL_keysym *
189 DirectFB_TranslateKey(DFBInputEvent * ev, SDL_keysym * keysym) 241 DirectFB_TranslateKey(DFBInputDeviceKeyIdentifier key_id,
190 { 242 DFBInputDeviceKeySymbol key_symbol,
243 DFBInputDeviceModifierMask key_mod, SDL_keysym * keysym)
244 {
245 SDLMod mod = KMOD_NONE;
246
247 /*
248 * Set modifier information
249 */
250
251 if (key_mod & DIMM_SHIFT)
252 mod = mod | KMOD_LSHIFT;
253 if (key_mod & DIMM_CONTROL)
254 mod = mod | KMOD_LCTRL;
255 if (key_mod & DIMM_ALT)
256 mod = mod | KMOD_LALT;
257 if (key_mod & DIMM_ALTGR)
258 mod = mod | KMOD_RALT;
259 if (key_mod & DIMM_META)
260 mod = mod | KMOD_LMETA;
261
191 /* Set the keysym information */ 262 /* Set the keysym information */
192 keysym->scancode = ev->key_id; 263 keysym->scancode = key_id;
193 keysym->mod = KMOD_NONE; /* FIXME */ 264
265 keysym->mod = mod;
194 keysym->unicode = 266 keysym->unicode =
195 (DFB_KEY_TYPE(ev->key_symbol) == DIKT_UNICODE) ? ev->key_symbol : 0; 267 (DFB_KEY_TYPE(key_symbol) == DIKT_UNICODE) ? key_symbol : 0;
196 268
197 if (ev->key_symbol > 0 && ev->key_symbol < 128) 269 if (key_symbol > 0 && key_symbol < 255)
198 keysym->sym = ev->key_symbol; 270 keysym->sym = key_symbol;
199 else 271 else
200 keysym->sym = keymap[ev->key_id - DIKI_UNKNOWN]; 272 keysym->sym = keymap[key_id - DIKI_UNKNOWN];
201 273
202 return keysym; 274 return keysym;
203 } 275 }
204 276
205 static int 277 static int
206 DirectFB_TranslateButton(DFBInputEvent * ev) 278 DirectFB_TranslateButton(DFBInputDeviceButtonIdentifier button)
207 { 279 {
208 switch (ev->button) { 280 switch (button) {
209 case DIBI_LEFT: 281 case DIBI_LEFT:
210 return 1; 282 return 1;
211 case DIBI_MIDDLE: 283 case DIBI_MIDDLE:
212 return 2; 284 return 2;
213 case DIBI_RIGHT: 285 case DIBI_RIGHT:
215 default: 287 default:
216 return 0; 288 return 0;
217 } 289 }
218 } 290 }
219 291
220 /* vi: set ts=4 sw=4 expandtab: */ 292 #if 0
293 void
294 DirectFB_PumpEvents(_THIS)
295 {
296 SDL_DFB_DEVICEDATA(_this);
297 DFBInputEvent evt;
298 static last_x = 0, last_y = 0;
299
300 while (devdata->eventbuffer->GetEvent(devdata->eventbuffer,
301 DFB_EVENT(&evt)) == DFB_OK) {
302 SDL_keysym keysym;
303 DFBInputDeviceModifierMask mod;
304
305 if (evt.clazz = DFEC_INPUT) {
306 if (evt.flags & DIEF_MODIFIERS)
307 mod = evt.modifiers;
308 else
309 mod = 0;
310
311 switch (evt.type) {
312 case DIET_BUTTONPRESS:
313 posted += SDL_PrivateMouseButton(SDL_PRESSED,
314 DirectFB_TranslateButton(evt.
315 button),
316 0, 0);
317 break;
318 case DIET_BUTTONRELEASE:
319 posted += SDL_PrivateMouseButton(SDL_RELEASED,
320 DirectFB_TranslateButton(evt.
321 button),
322 0, 0);
323 break;
324 case DIET_KEYPRESS:
325 posted += SDL_PrivateKeyboard(SDL_PRESSED,
326 DirectFB_TranslateKey(evt.
327 key_id,
328 evt.
329 key_symbol,
330 mod,
331 &keysym));
332 break;
333 case DIET_KEYRELEASE:
334 posted += SDL_PrivateKeyboard(SDL_RELEASED,
335 DirectFB_TranslateKey(evt.
336 key_id,
337 evt.
338 key_symbol,
339 mod,
340 &keysym));
341 break;
342 case DIET_AXISMOTION:
343 if (evt.flags & DIEF_AXISREL) {
344 if (evt.axis == DIAI_X)
345 posted +=
346 SDL_PrivateMouseMotion(0, 1, evt.axisrel, 0);
347 else if (evt.axis == DIAI_Y)
348 posted +=
349 SDL_PrivateMouseMotion(0, 1, 0, evt.axisrel);
350 } else if (evt.flags & DIEF_AXISABS) {
351 if (evt.axis == DIAI_X)
352 last_x = evt.axisabs;
353 else if (evt.axis == DIAI_Y)
354 last_y = evt.axisabs;
355 posted += SDL_PrivateMouseMotion(0, 0, last_x, last_y);
356 }
357 break;
358 default:
359 ;
360 }
361 }
362 }
363 }
364 #endif