Date: Sun, 20 Jul 2008 22:34:37 +0200
authorSam Lantinga
Tue, 26 Aug 2008 02:32:45 +0000
changeset 2721e82a0e3e9b0e
parent 2720 4eb759edddf5
child 2722 91f1706b27be
Date: Sun, 20 Jul 2008 22:34:37 +0200
From: Couriersud
Subject: Updated DirectFB driver for SDL1.3

please find attached a patch for an updated directfb driver for SDL1.3.
It does now
- properly supported the new input api.
- send unicode text events
- support directfb windows
- support multiple screens
- support hardware YUV scaling for the first YUV texture created.
- support hardware scaling for textures.
- properly interpret streaming access
- support software opengl if one manages to install the mesa directfb
driver (broken/not broken in mesa svn)

Within bugzilla (http://bugzilla.libsdl.org/show_bug.cgi?id=603) there
is another patch which fixes a crash due to GL context creation.

Kind regards,

couriersud
src/video/directfb/SDL_DirectFB_events.c
src/video/directfb/SDL_DirectFB_events.h
src/video/directfb/SDL_DirectFB_mouse.c
src/video/directfb/SDL_DirectFB_render.c
src/video/directfb/SDL_DirectFB_video.c
src/video/directfb/SDL_DirectFB_video.h
     1.1 --- a/src/video/directfb/SDL_DirectFB_events.c	Tue Aug 26 02:26:18 2008 +0000
     1.2 +++ b/src/video/directfb/SDL_DirectFB_events.c	Tue Aug 26 02:32:45 2008 +0000
     1.3 @@ -25,28 +25,55 @@
     1.4  
     1.5  #include <directfb.h>
     1.6  
     1.7 -#include "SDL.h"
     1.8  #include "../SDL_sysvideo.h"
     1.9  #include "../../events/SDL_sysevents.h"
    1.10  #include "../../events/SDL_events_c.h"
    1.11 +#include "../../events/SDL_keyboard_c.h"
    1.12 +#include "../../events/scancodes_linux.h"
    1.13  #include "SDL_DirectFB_events.h"
    1.14  
    1.15  /* The translation tables from a DirectFB keycode to a SDL keysym */
    1.16  static SDLKey keymap[256];
    1.17  
    1.18 -static SDL_keysym *DirectFB_TranslateKey(DFBInputDeviceKeyIdentifier key_id,
    1.19 -                                         DFBInputDeviceKeySymbol key_symbol,
    1.20 -                                         DFBInputDeviceModifierMask key_mod,
    1.21 +static SDL_keysym *DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt,
    1.22                                           SDL_keysym * keysym);
    1.23  
    1.24 +static void DirectFB_InitOSKeymap(_THIS);
    1.25  static int DirectFB_TranslateButton(DFBInputDeviceButtonIdentifier button);
    1.26  
    1.27 +static void
    1.28 +DirectFB_SetContext(_THIS, SDL_WindowID id)
    1.29 +{
    1.30 +#if (DIRECTFB_MAJOR_VERSION >= 1)
    1.31 +    /* FIXME: does not work on 1.0/1.2 with radeon driver
    1.32 +     *        the approach did work with the matrox driver
    1.33 +     *        Perhaps make this depending on env var, e.g. SDLDIRECTFB_SWITCHCONTEXT_SUPPORTED
    1.34 +     */
    1.35 +
    1.36 +    if (getenv("SDLDIRECTFB_SWITCHCONTEXT_SUPPORTED") != NULL) {
    1.37 +        SDL_DFB_DEVICEDATA(_this);
    1.38 +        SDL_Window *window = SDL_GetWindowFromID(id);
    1.39 +        SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
    1.40 +        DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
    1.41 +        if (dispdata->vidID >= 0 && dispdata->vidIDinuse) {
    1.42 +            IDirectFBDisplayLayer *lay = NULL;
    1.43 +            devdata->dfb->GetDisplayLayer(devdata->dfb, dispdata->vidID,
    1.44 +                                          &lay);
    1.45 +            if (lay)
    1.46 +                lay->SwitchContext(lay, DFB_TRUE);
    1.47 +        }
    1.48 +    }
    1.49 +#endif
    1.50 +
    1.51 +}
    1.52 +
    1.53  void
    1.54  DirectFB_PumpEventsWindow(_THIS)
    1.55  {
    1.56      SDL_DFB_DEVICEDATA(_this);
    1.57      DFB_WindowData *p;
    1.58      DFBWindowEvent evt;
    1.59 +    char text[5];
    1.60  
    1.61      for (p = devdata->firstwin; p != NULL; p = p->next) {
    1.62          while (p->eventbuffer->GetEvent(p->eventbuffer,
    1.63 @@ -67,16 +94,21 @@
    1.64                      SDL_SendMouseMotion(devdata->mouse, 0, evt.cx, evt.cy);
    1.65                      break;
    1.66                  case DWET_KEYDOWN:
    1.67 -                    DirectFB_TranslateKey(evt.key_id, evt.key_symbol,
    1.68 -                                          evt.modifiers, &keysym);
    1.69 +                    DirectFB_TranslateKey(_this, &evt, &keysym);
    1.70                      SDL_SendKeyboardKey(devdata->keyboard, SDL_PRESSED,
    1.71 -                                        keysym.scancode, keysym.sym);
    1.72 +                                        keysym.scancode);
    1.73 +                    if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
    1.74 +                        SDL_memcpy(text, &keysym.unicode, 4);
    1.75 +                        text[4] = 0;
    1.76 +                        if (*text) {
    1.77 +                            SDL_SendKeyboardText(devdata->keyboard, text);
    1.78 +                        }
    1.79 +                    }
    1.80                      break;
    1.81                  case DWET_KEYUP:
    1.82 -                    DirectFB_TranslateKey(evt.key_id, evt.key_symbol,
    1.83 -                                          evt.modifiers, &keysym);
    1.84 +                    DirectFB_TranslateKey(_this, &evt, &keysym);
    1.85                      SDL_SendKeyboardKey(devdata->keyboard, SDL_RELEASED,
    1.86 -                                        keysym.scancode, keysym.sym);
    1.87 +                                        keysym.scancode);
    1.88                      break;
    1.89                  case DWET_POSITION_SIZE:
    1.90                      SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_MOVED, evt.x,
    1.91 @@ -96,17 +128,23 @@
    1.92                      SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_CLOSE, 0, 0);
    1.93                      break;
    1.94                  case DWET_GOTFOCUS:
    1.95 -                    //TODO: Implement for yuv-overlay DirectFB_SwitchOverlayContext(this, evt.window_id);
    1.96 +                    DirectFB_SetContext(_this, p->id);
    1.97                      SDL_SetKeyboardFocus(devdata->keyboard, p->id);
    1.98 +                    SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_FOCUS_GAINED,
    1.99 +                                        0, 0);
   1.100                      break;
   1.101                  case DWET_LOSTFOCUS:
   1.102 +                    SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_FOCUS_LOST, 0,
   1.103 +                                        0);
   1.104                      SDL_SetKeyboardFocus(devdata->keyboard, 0);
   1.105                      break;
   1.106                  case DWET_ENTER:
   1.107                      //SDL_DirectFB_ReshowCursor(_this, 0);
   1.108                      SDL_SetMouseFocus(devdata->mouse, p->id);
   1.109 +                    SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_ENTER, 0, 0);
   1.110                      break;
   1.111                  case DWET_LEAVE:
   1.112 +                    SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_LEAVE, 0, 0);
   1.113                      SDL_SetMouseFocus(devdata->mouse, 0);
   1.114                      //SDL_DirectFB_ReshowCursor(_this, 1);
   1.115                      break;
   1.116 @@ -125,151 +163,149 @@
   1.117  
   1.118      /* Initialize the DirectFB key translation table */
   1.119      for (i = 0; i < SDL_arraysize(keymap); ++i)
   1.120 -        keymap[i] = SDLK_UNKNOWN;
   1.121 +        keymap[i] = SDL_SCANCODE_UNKNOWN;
   1.122  
   1.123 -    keymap[DIKI_A - DIKI_UNKNOWN] = SDLK_a;
   1.124 -    keymap[DIKI_B - DIKI_UNKNOWN] = SDLK_b;
   1.125 -    keymap[DIKI_C - DIKI_UNKNOWN] = SDLK_c;
   1.126 -    keymap[DIKI_D - DIKI_UNKNOWN] = SDLK_d;
   1.127 -    keymap[DIKI_E - DIKI_UNKNOWN] = SDLK_e;
   1.128 -    keymap[DIKI_F - DIKI_UNKNOWN] = SDLK_f;
   1.129 -    keymap[DIKI_G - DIKI_UNKNOWN] = SDLK_g;
   1.130 -    keymap[DIKI_H - DIKI_UNKNOWN] = SDLK_h;
   1.131 -    keymap[DIKI_I - DIKI_UNKNOWN] = SDLK_i;
   1.132 -    keymap[DIKI_J - DIKI_UNKNOWN] = SDLK_j;
   1.133 -    keymap[DIKI_K - DIKI_UNKNOWN] = SDLK_k;
   1.134 -    keymap[DIKI_L - DIKI_UNKNOWN] = SDLK_l;
   1.135 -    keymap[DIKI_M - DIKI_UNKNOWN] = SDLK_m;
   1.136 -    keymap[DIKI_N - DIKI_UNKNOWN] = SDLK_n;
   1.137 -    keymap[DIKI_O - DIKI_UNKNOWN] = SDLK_o;
   1.138 -    keymap[DIKI_P - DIKI_UNKNOWN] = SDLK_p;
   1.139 -    keymap[DIKI_Q - DIKI_UNKNOWN] = SDLK_q;
   1.140 -    keymap[DIKI_R - DIKI_UNKNOWN] = SDLK_r;
   1.141 -    keymap[DIKI_S - DIKI_UNKNOWN] = SDLK_s;
   1.142 -    keymap[DIKI_T - DIKI_UNKNOWN] = SDLK_t;
   1.143 -    keymap[DIKI_U - DIKI_UNKNOWN] = SDLK_u;
   1.144 -    keymap[DIKI_V - DIKI_UNKNOWN] = SDLK_v;
   1.145 -    keymap[DIKI_W - DIKI_UNKNOWN] = SDLK_w;
   1.146 -    keymap[DIKI_X - DIKI_UNKNOWN] = SDLK_x;
   1.147 -    keymap[DIKI_Y - DIKI_UNKNOWN] = SDLK_y;
   1.148 -    keymap[DIKI_Z - DIKI_UNKNOWN] = SDLK_z;
   1.149 +    keymap[DIKI_A - DIKI_UNKNOWN] = SDL_SCANCODE_A;
   1.150 +    keymap[DIKI_B - DIKI_UNKNOWN] = SDL_SCANCODE_B;
   1.151 +    keymap[DIKI_C - DIKI_UNKNOWN] = SDL_SCANCODE_C;
   1.152 +    keymap[DIKI_D - DIKI_UNKNOWN] = SDL_SCANCODE_D;
   1.153 +    keymap[DIKI_E - DIKI_UNKNOWN] = SDL_SCANCODE_E;
   1.154 +    keymap[DIKI_F - DIKI_UNKNOWN] = SDL_SCANCODE_F;
   1.155 +    keymap[DIKI_G - DIKI_UNKNOWN] = SDL_SCANCODE_G;
   1.156 +    keymap[DIKI_H - DIKI_UNKNOWN] = SDL_SCANCODE_H;
   1.157 +    keymap[DIKI_I - DIKI_UNKNOWN] = SDL_SCANCODE_I;
   1.158 +    keymap[DIKI_J - DIKI_UNKNOWN] = SDL_SCANCODE_J;
   1.159 +    keymap[DIKI_K - DIKI_UNKNOWN] = SDL_SCANCODE_K;
   1.160 +    keymap[DIKI_L - DIKI_UNKNOWN] = SDL_SCANCODE_L;
   1.161 +    keymap[DIKI_M - DIKI_UNKNOWN] = SDL_SCANCODE_M;
   1.162 +    keymap[DIKI_N - DIKI_UNKNOWN] = SDL_SCANCODE_N;
   1.163 +    keymap[DIKI_O - DIKI_UNKNOWN] = SDL_SCANCODE_O;
   1.164 +    keymap[DIKI_P - DIKI_UNKNOWN] = SDL_SCANCODE_P;
   1.165 +    keymap[DIKI_Q - DIKI_UNKNOWN] = SDL_SCANCODE_Q;
   1.166 +    keymap[DIKI_R - DIKI_UNKNOWN] = SDL_SCANCODE_R;
   1.167 +    keymap[DIKI_S - DIKI_UNKNOWN] = SDL_SCANCODE_S;
   1.168 +    keymap[DIKI_T - DIKI_UNKNOWN] = SDL_SCANCODE_T;
   1.169 +    keymap[DIKI_U - DIKI_UNKNOWN] = SDL_SCANCODE_U;
   1.170 +    keymap[DIKI_V - DIKI_UNKNOWN] = SDL_SCANCODE_V;
   1.171 +    keymap[DIKI_W - DIKI_UNKNOWN] = SDL_SCANCODE_W;
   1.172 +    keymap[DIKI_X - DIKI_UNKNOWN] = SDL_SCANCODE_X;
   1.173 +    keymap[DIKI_Y - DIKI_UNKNOWN] = SDL_SCANCODE_Y;
   1.174 +    keymap[DIKI_Z - DIKI_UNKNOWN] = SDL_SCANCODE_Z;
   1.175  
   1.176 -    keymap[DIKI_0 - DIKI_UNKNOWN] = SDLK_0;
   1.177 -    keymap[DIKI_1 - DIKI_UNKNOWN] = SDLK_1;
   1.178 -    keymap[DIKI_2 - DIKI_UNKNOWN] = SDLK_2;
   1.179 -    keymap[DIKI_3 - DIKI_UNKNOWN] = SDLK_3;
   1.180 -    keymap[DIKI_4 - DIKI_UNKNOWN] = SDLK_4;
   1.181 -    keymap[DIKI_5 - DIKI_UNKNOWN] = SDLK_5;
   1.182 -    keymap[DIKI_6 - DIKI_UNKNOWN] = SDLK_6;
   1.183 -    keymap[DIKI_7 - DIKI_UNKNOWN] = SDLK_7;
   1.184 -    keymap[DIKI_8 - DIKI_UNKNOWN] = SDLK_8;
   1.185 -    keymap[DIKI_9 - DIKI_UNKNOWN] = SDLK_9;
   1.186 +    keymap[DIKI_0 - DIKI_UNKNOWN] = SDL_SCANCODE_0;
   1.187 +    keymap[DIKI_1 - DIKI_UNKNOWN] = SDL_SCANCODE_1;
   1.188 +    keymap[DIKI_2 - DIKI_UNKNOWN] = SDL_SCANCODE_2;
   1.189 +    keymap[DIKI_3 - DIKI_UNKNOWN] = SDL_SCANCODE_3;
   1.190 +    keymap[DIKI_4 - DIKI_UNKNOWN] = SDL_SCANCODE_4;
   1.191 +    keymap[DIKI_5 - DIKI_UNKNOWN] = SDL_SCANCODE_5;
   1.192 +    keymap[DIKI_6 - DIKI_UNKNOWN] = SDL_SCANCODE_6;
   1.193 +    keymap[DIKI_7 - DIKI_UNKNOWN] = SDL_SCANCODE_7;
   1.194 +    keymap[DIKI_8 - DIKI_UNKNOWN] = SDL_SCANCODE_8;
   1.195 +    keymap[DIKI_9 - DIKI_UNKNOWN] = SDL_SCANCODE_9;
   1.196  
   1.197 -    keymap[DIKI_F1 - DIKI_UNKNOWN] = SDLK_F1;
   1.198 -    keymap[DIKI_F2 - DIKI_UNKNOWN] = SDLK_F2;
   1.199 -    keymap[DIKI_F3 - DIKI_UNKNOWN] = SDLK_F3;
   1.200 -    keymap[DIKI_F4 - DIKI_UNKNOWN] = SDLK_F4;
   1.201 -    keymap[DIKI_F5 - DIKI_UNKNOWN] = SDLK_F5;
   1.202 -    keymap[DIKI_F6 - DIKI_UNKNOWN] = SDLK_F6;
   1.203 -    keymap[DIKI_F7 - DIKI_UNKNOWN] = SDLK_F7;
   1.204 -    keymap[DIKI_F8 - DIKI_UNKNOWN] = SDLK_F8;
   1.205 -    keymap[DIKI_F9 - DIKI_UNKNOWN] = SDLK_F9;
   1.206 -    keymap[DIKI_F10 - DIKI_UNKNOWN] = SDLK_F10;
   1.207 -    keymap[DIKI_F11 - DIKI_UNKNOWN] = SDLK_F11;
   1.208 -    keymap[DIKI_F12 - DIKI_UNKNOWN] = SDLK_F12;
   1.209 +    keymap[DIKI_F1 - DIKI_UNKNOWN] = SDL_SCANCODE_F1;
   1.210 +    keymap[DIKI_F2 - DIKI_UNKNOWN] = SDL_SCANCODE_F2;
   1.211 +    keymap[DIKI_F3 - DIKI_UNKNOWN] = SDL_SCANCODE_F3;
   1.212 +    keymap[DIKI_F4 - DIKI_UNKNOWN] = SDL_SCANCODE_F4;
   1.213 +    keymap[DIKI_F5 - DIKI_UNKNOWN] = SDL_SCANCODE_F5;
   1.214 +    keymap[DIKI_F6 - DIKI_UNKNOWN] = SDL_SCANCODE_F6;
   1.215 +    keymap[DIKI_F7 - DIKI_UNKNOWN] = SDL_SCANCODE_F7;
   1.216 +    keymap[DIKI_F8 - DIKI_UNKNOWN] = SDL_SCANCODE_F8;
   1.217 +    keymap[DIKI_F9 - DIKI_UNKNOWN] = SDL_SCANCODE_F9;
   1.218 +    keymap[DIKI_F10 - DIKI_UNKNOWN] = SDL_SCANCODE_F10;
   1.219 +    keymap[DIKI_F11 - DIKI_UNKNOWN] = SDL_SCANCODE_F11;
   1.220 +    keymap[DIKI_F12 - DIKI_UNKNOWN] = SDL_SCANCODE_F12;
   1.221  
   1.222 -    keymap[DIKI_ESCAPE - DIKI_UNKNOWN] = SDLK_ESCAPE;
   1.223 -    keymap[DIKI_LEFT - DIKI_UNKNOWN] = SDLK_LEFT;
   1.224 -    keymap[DIKI_RIGHT - DIKI_UNKNOWN] = SDLK_RIGHT;
   1.225 -    keymap[DIKI_UP - DIKI_UNKNOWN] = SDLK_UP;
   1.226 -    keymap[DIKI_DOWN - DIKI_UNKNOWN] = SDLK_DOWN;
   1.227 -    keymap[DIKI_CONTROL_L - DIKI_UNKNOWN] = SDLK_LCTRL;
   1.228 -    keymap[DIKI_CONTROL_R - DIKI_UNKNOWN] = SDLK_RCTRL;
   1.229 -    keymap[DIKI_SHIFT_L - DIKI_UNKNOWN] = SDLK_LSHIFT;
   1.230 -    keymap[DIKI_SHIFT_R - DIKI_UNKNOWN] = SDLK_RSHIFT;
   1.231 -    keymap[DIKI_ALT_L - DIKI_UNKNOWN] = SDLK_LALT;
   1.232 -    keymap[DIKI_ALT_R - DIKI_UNKNOWN] = SDLK_RALT;
   1.233 -    keymap[DIKI_TAB - DIKI_UNKNOWN] = SDLK_TAB;
   1.234 -    keymap[DIKI_ENTER - DIKI_UNKNOWN] = SDLK_RETURN;
   1.235 -    keymap[DIKI_SPACE - DIKI_UNKNOWN] = SDLK_SPACE;
   1.236 -    keymap[DIKI_BACKSPACE - DIKI_UNKNOWN] = SDLK_BACKSPACE;
   1.237 -    keymap[DIKI_INSERT - DIKI_UNKNOWN] = SDLK_INSERT;
   1.238 -    keymap[DIKI_DELETE - DIKI_UNKNOWN] = SDLK_DELETE;
   1.239 -    keymap[DIKI_HOME - DIKI_UNKNOWN] = SDLK_HOME;
   1.240 -    keymap[DIKI_END - DIKI_UNKNOWN] = SDLK_END;
   1.241 -    keymap[DIKI_PAGE_UP - DIKI_UNKNOWN] = SDLK_PAGEUP;
   1.242 -    keymap[DIKI_PAGE_DOWN - DIKI_UNKNOWN] = SDLK_PAGEDOWN;
   1.243 -    keymap[DIKI_CAPS_LOCK - DIKI_UNKNOWN] = SDLK_CAPSLOCK;
   1.244 -    keymap[DIKI_NUM_LOCK - DIKI_UNKNOWN] = SDLK_NUMLOCK;
   1.245 -    keymap[DIKI_SCROLL_LOCK - DIKI_UNKNOWN] = SDLK_SCROLLOCK;
   1.246 -    keymap[DIKI_PRINT - DIKI_UNKNOWN] = SDLK_PRINT;
   1.247 -    keymap[DIKI_PAUSE - DIKI_UNKNOWN] = SDLK_PAUSE;
   1.248 +    keymap[DIKI_ESCAPE - DIKI_UNKNOWN] = SDL_SCANCODE_ESCAPE;
   1.249 +    keymap[DIKI_LEFT - DIKI_UNKNOWN] = SDL_SCANCODE_LEFT;
   1.250 +    keymap[DIKI_RIGHT - DIKI_UNKNOWN] = SDL_SCANCODE_RIGHT;
   1.251 +    keymap[DIKI_UP - DIKI_UNKNOWN] = SDL_SCANCODE_UP;
   1.252 +    keymap[DIKI_DOWN - DIKI_UNKNOWN] = SDL_SCANCODE_DOWN;
   1.253 +    keymap[DIKI_CONTROL_L - DIKI_UNKNOWN] = SDL_SCANCODE_LCTRL;
   1.254 +    keymap[DIKI_CONTROL_R - DIKI_UNKNOWN] = SDL_SCANCODE_RCTRL;
   1.255 +    keymap[DIKI_SHIFT_L - DIKI_UNKNOWN] = SDL_SCANCODE_LSHIFT;
   1.256 +    keymap[DIKI_SHIFT_R - DIKI_UNKNOWN] = SDL_SCANCODE_RSHIFT;
   1.257 +    keymap[DIKI_ALT_L - DIKI_UNKNOWN] = SDL_SCANCODE_LALT;
   1.258 +    keymap[DIKI_ALT_R - DIKI_UNKNOWN] = SDL_SCANCODE_RALT;
   1.259 +    keymap[DIKI_META_L - DIKI_UNKNOWN] = SDL_SCANCODE_LGUI;
   1.260 +    keymap[DIKI_META_R - DIKI_UNKNOWN] = SDL_SCANCODE_RGUI;
   1.261 +    keymap[DIKI_SUPER_L - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION;
   1.262 +    keymap[DIKI_SUPER_R - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION;
   1.263 +    //FIXME:Do we read hyper keys ?
   1.264 +    //keymap[DIKI_HYPER_L - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION;
   1.265 +    //keymap[DIKI_HYPER_R - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION;
   1.266 +    keymap[DIKI_TAB - DIKI_UNKNOWN] = SDL_SCANCODE_TAB;
   1.267 +    keymap[DIKI_ENTER - DIKI_UNKNOWN] = SDL_SCANCODE_RETURN;
   1.268 +    keymap[DIKI_SPACE - DIKI_UNKNOWN] = SDL_SCANCODE_SPACE;
   1.269 +    keymap[DIKI_BACKSPACE - DIKI_UNKNOWN] = SDL_SCANCODE_BACKSPACE;
   1.270 +    keymap[DIKI_INSERT - DIKI_UNKNOWN] = SDL_SCANCODE_INSERT;
   1.271 +    keymap[DIKI_DELETE - DIKI_UNKNOWN] = SDL_SCANCODE_DELETE;
   1.272 +    keymap[DIKI_HOME - DIKI_UNKNOWN] = SDL_SCANCODE_HOME;
   1.273 +    keymap[DIKI_END - DIKI_UNKNOWN] = SDL_SCANCODE_END;
   1.274 +    keymap[DIKI_PAGE_UP - DIKI_UNKNOWN] = SDL_SCANCODE_PAGEUP;
   1.275 +    keymap[DIKI_PAGE_DOWN - DIKI_UNKNOWN] = SDL_SCANCODE_PAGEDOWN;
   1.276 +    keymap[DIKI_CAPS_LOCK - DIKI_UNKNOWN] = SDL_SCANCODE_CAPSLOCK;
   1.277 +    keymap[DIKI_NUM_LOCK - DIKI_UNKNOWN] = SDL_SCANCODE_NUMLOCKCLEAR;
   1.278 +    keymap[DIKI_SCROLL_LOCK - DIKI_UNKNOWN] = SDL_SCANCODE_SCROLLLOCK;
   1.279 +    keymap[DIKI_PRINT - DIKI_UNKNOWN] = SDL_SCANCODE_PRINTSCREEN;
   1.280 +    keymap[DIKI_PAUSE - DIKI_UNKNOWN] = SDL_SCANCODE_PAUSE;
   1.281  
   1.282 -    keymap[DIKI_KP_EQUAL - DIKI_UNKNOWN] = SDLK_KP_EQUALS;
   1.283 -    keymap[DIKI_KP_DECIMAL - DIKI_UNKNOWN] = SDLK_KP_PERIOD;
   1.284 -    keymap[DIKI_KP_0 - DIKI_UNKNOWN] = SDLK_KP0;
   1.285 -    keymap[DIKI_KP_1 - DIKI_UNKNOWN] = SDLK_KP1;
   1.286 -    keymap[DIKI_KP_2 - DIKI_UNKNOWN] = SDLK_KP2;
   1.287 -    keymap[DIKI_KP_3 - DIKI_UNKNOWN] = SDLK_KP3;
   1.288 -    keymap[DIKI_KP_4 - DIKI_UNKNOWN] = SDLK_KP4;
   1.289 -    keymap[DIKI_KP_5 - DIKI_UNKNOWN] = SDLK_KP5;
   1.290 -    keymap[DIKI_KP_6 - DIKI_UNKNOWN] = SDLK_KP6;
   1.291 -    keymap[DIKI_KP_7 - DIKI_UNKNOWN] = SDLK_KP7;
   1.292 -    keymap[DIKI_KP_8 - DIKI_UNKNOWN] = SDLK_KP8;
   1.293 -    keymap[DIKI_KP_9 - DIKI_UNKNOWN] = SDLK_KP9;
   1.294 -    keymap[DIKI_KP_DIV - DIKI_UNKNOWN] = SDLK_KP_DIVIDE;
   1.295 -    keymap[DIKI_KP_MULT - DIKI_UNKNOWN] = SDLK_KP_MULTIPLY;
   1.296 -    keymap[DIKI_KP_MINUS - DIKI_UNKNOWN] = SDLK_KP_MINUS;
   1.297 -    keymap[DIKI_KP_PLUS - DIKI_UNKNOWN] = SDLK_KP_PLUS;
   1.298 -    keymap[DIKI_KP_ENTER - DIKI_UNKNOWN] = SDLK_KP_ENTER;
   1.299 +    keymap[DIKI_KP_EQUAL - DIKI_UNKNOWN] = SDL_SCANCODE_KP_EQUALS;
   1.300 +    keymap[DIKI_KP_DECIMAL - DIKI_UNKNOWN] = SDL_SCANCODE_KP_PERIOD;
   1.301 +    keymap[DIKI_KP_0 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_0;
   1.302 +    keymap[DIKI_KP_1 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_1;
   1.303 +    keymap[DIKI_KP_2 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_2;
   1.304 +    keymap[DIKI_KP_3 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_3;
   1.305 +    keymap[DIKI_KP_4 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_4;
   1.306 +    keymap[DIKI_KP_5 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_5;
   1.307 +    keymap[DIKI_KP_6 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_6;
   1.308 +    keymap[DIKI_KP_7 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_7;
   1.309 +    keymap[DIKI_KP_8 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_8;
   1.310 +    keymap[DIKI_KP_9 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_9;
   1.311 +    keymap[DIKI_KP_DIV - DIKI_UNKNOWN] = SDL_SCANCODE_KP_DIVIDE;
   1.312 +    keymap[DIKI_KP_MULT - DIKI_UNKNOWN] = SDL_SCANCODE_KP_MULTIPLY;
   1.313 +    keymap[DIKI_KP_MINUS - DIKI_UNKNOWN] = SDL_SCANCODE_KP_MINUS;
   1.314 +    keymap[DIKI_KP_PLUS - DIKI_UNKNOWN] = SDL_SCANCODE_KP_PLUS;
   1.315 +    keymap[DIKI_KP_ENTER - DIKI_UNKNOWN] = SDL_SCANCODE_KP_ENTER;
   1.316  
   1.317 -    keymap[DIKI_QUOTE_LEFT - DIKI_UNKNOWN] = SDLK_BACKQUOTE;    /*  TLDE  */
   1.318 -    keymap[DIKI_MINUS_SIGN - DIKI_UNKNOWN] = SDLK_MINUS;        /*  AE11  */
   1.319 -    keymap[DIKI_EQUALS_SIGN - DIKI_UNKNOWN] = SDLK_EQUALS;      /*  AE12  */
   1.320 -    keymap[DIKI_BRACKET_LEFT - DIKI_UNKNOWN] = SDLK_RIGHTBRACKET;       /*  AD11  */
   1.321 -    keymap[DIKI_BRACKET_RIGHT - DIKI_UNKNOWN] = SDLK_LEFTBRACKET;       /*  AD12  */
   1.322 -    keymap[DIKI_BACKSLASH - DIKI_UNKNOWN] = SDLK_BACKSLASH;     /*  BKSL  */
   1.323 -    keymap[DIKI_SEMICOLON - DIKI_UNKNOWN] = SDLK_SEMICOLON;     /*  AC10  */
   1.324 -    keymap[DIKI_QUOTE_RIGHT - DIKI_UNKNOWN] = SDLK_QUOTE;       /*  AC11  */
   1.325 -    keymap[DIKI_COMMA - DIKI_UNKNOWN] = SDLK_COMMA;     /*  AB08  */
   1.326 -    keymap[DIKI_PERIOD - DIKI_UNKNOWN] = SDLK_PERIOD;   /*  AB09  */
   1.327 -    keymap[DIKI_SLASH - DIKI_UNKNOWN] = SDLK_SLASH;     /*  AB10  */
   1.328 -    keymap[DIKI_LESS_SIGN - DIKI_UNKNOWN] = SDLK_LESS;  /*  103rd  */
   1.329 +    keymap[DIKI_QUOTE_LEFT - DIKI_UNKNOWN] = SDL_SCANCODE_GRAVE;        /*  TLDE  */
   1.330 +    keymap[DIKI_MINUS_SIGN - DIKI_UNKNOWN] = SDL_SCANCODE_MINUS;        /*  AE11  */
   1.331 +    keymap[DIKI_EQUALS_SIGN - DIKI_UNKNOWN] = SDL_SCANCODE_EQUALS;      /*  AE12  */
   1.332 +    keymap[DIKI_BRACKET_LEFT - DIKI_UNKNOWN] = SDL_SCANCODE_RIGHTBRACKET;       /*  AD11  */
   1.333 +    keymap[DIKI_BRACKET_RIGHT - DIKI_UNKNOWN] = SDL_SCANCODE_LEFTBRACKET;       /*  AD12  */
   1.334 +    keymap[DIKI_BACKSLASH - DIKI_UNKNOWN] = SDL_SCANCODE_BACKSLASH;     /*  BKSL  */
   1.335 +    keymap[DIKI_SEMICOLON - DIKI_UNKNOWN] = SDL_SCANCODE_SEMICOLON;     /*  AC10  */
   1.336 +    keymap[DIKI_QUOTE_RIGHT - DIKI_UNKNOWN] = SDL_SCANCODE_APOSTROPHE;  /*  AC11  */
   1.337 +    keymap[DIKI_COMMA - DIKI_UNKNOWN] = SDL_SCANCODE_COMMA;     /*  AB08  */
   1.338 +    keymap[DIKI_PERIOD - DIKI_UNKNOWN] = SDL_SCANCODE_PERIOD;   /*  AB09  */
   1.339 +    keymap[DIKI_SLASH - DIKI_UNKNOWN] = SDL_SCANCODE_SLASH;     /*  AB10  */
   1.340 +    keymap[DIKI_LESS_SIGN - DIKI_UNKNOWN] = SDL_SCANCODE_NONUSBACKSLASH;        /*  103rd  */
   1.341 +
   1.342  }
   1.343  
   1.344  static SDL_keysym *
   1.345 -DirectFB_TranslateKey(DFBInputDeviceKeyIdentifier key_id,
   1.346 -                      DFBInputDeviceKeySymbol key_symbol,
   1.347 -                      DFBInputDeviceModifierMask key_mod, SDL_keysym * keysym)
   1.348 +DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt, SDL_keysym * keysym)
   1.349  {
   1.350 -    SDLMod mod = KMOD_NONE;
   1.351 +    SDL_DFB_DEVICEDATA(_this);
   1.352  
   1.353 -    /*
   1.354 -     *  Set modifier information 
   1.355 -     */
   1.356 +    if (evt->key_code >= 0
   1.357 +        && evt->key_code < SDL_arraysize(linux_scancode_table))
   1.358 +        keysym->scancode = linux_scancode_table[evt->key_code]; // key_id;
   1.359 +    else
   1.360 +        keysym->scancode = SDL_SCANCODE_UNKNOWN;
   1.361  
   1.362 -    if (key_mod & DIMM_SHIFT)
   1.363 -        mod = mod | KMOD_LSHIFT;
   1.364 -    if (key_mod & DIMM_CONTROL)
   1.365 -        mod = mod | KMOD_LCTRL;
   1.366 -    if (key_mod & DIMM_ALT)
   1.367 -        mod = mod | KMOD_LALT;
   1.368 -    if (key_mod & DIMM_ALTGR)
   1.369 -        mod = mod | KMOD_RALT;
   1.370 -    if (key_mod & DIMM_META)
   1.371 -        mod = mod | KMOD_LMETA;
   1.372 +    if (keysym->scancode == SDL_SCANCODE_UNKNOWN || devdata->kbdgeneric) {
   1.373 +        if (evt->key_id - DIKI_UNKNOWN < SDL_arraysize(keymap))
   1.374 +            keysym->scancode = keymap[evt->key_id - DIKI_UNKNOWN];
   1.375 +        else
   1.376 +            keysym->scancode = SDL_SCANCODE_UNKNOWN;
   1.377 +    }
   1.378  
   1.379 -    /* Set the keysym information */
   1.380 -    keysym->scancode = key_id;
   1.381 -
   1.382 -    keysym->mod = mod;
   1.383      keysym->unicode =
   1.384 -        (DFB_KEY_TYPE(key_symbol) == DIKT_UNICODE) ? key_symbol : 0;
   1.385 -
   1.386 -    if (key_symbol > 0 && key_symbol < 255)
   1.387 -        keysym->sym = key_symbol;
   1.388 -    else
   1.389 -        keysym->sym = keymap[key_id - DIKI_UNKNOWN];
   1.390 +        (DFB_KEY_TYPE(evt->key_symbol) == DIKT_UNICODE) ? evt->key_symbol : 0;
   1.391 +    if (keysym->unicode == 0
   1.392 +        && (evt->key_symbol > 0 && evt->key_symbol < 255))
   1.393 +        keysym->unicode = evt->key_symbol;
   1.394  
   1.395      return keysym;
   1.396  }
   1.397 @@ -289,7 +325,43 @@
   1.398      }
   1.399  }
   1.400  
   1.401 +static DFBEnumerationResult
   1.402 +input_device_cb(DFBInputDeviceID device_id, DFBInputDeviceDescription desc,
   1.403 +                void *callbackdata)
   1.404 +{
   1.405 +    DFB_DeviceData *devdata = callbackdata;
   1.406 +    SDL_Keyboard keyboard;
   1.407 +    SDL_scancode scancode;
   1.408 +    SDLKey keymap[SDL_NUM_SCANCODES];
   1.409 +
   1.410 +    if ((desc.caps & DIDTF_KEYBOARD) && device_id == DIDID_KEYBOARD) {
   1.411 +        SDL_zero(keyboard);
   1.412 +        devdata->keyboard = SDL_AddKeyboard(&keyboard, -1);
   1.413 +        if (!strncmp("X11", desc.name, 3))
   1.414 +            devdata->kbdgeneric = 1;
   1.415 +
   1.416 +        SDL_GetDefaultKeymap(keymap);
   1.417 +        SDL_SetKeymap(devdata->keyboard, 0, keymap, SDL_NUM_SCANCODES);
   1.418 +    }
   1.419 +    return DFB_OK;
   1.420 +}
   1.421 +
   1.422 +void
   1.423 +DirectFB_InitKeyboard(_THIS)
   1.424 +{
   1.425 +    SDL_DFB_DEVICEDATA(_this);
   1.426 +    int ret;
   1.427 +
   1.428 +    DirectFB_InitOSKeymap(_this);
   1.429 +
   1.430 +    devdata->kbdgeneric = 0;
   1.431 +
   1.432 +    SDL_DFB_CHECK(devdata->dfb->
   1.433 +                  EnumInputDevices(devdata->dfb, input_device_cb, devdata));
   1.434 +}
   1.435 +
   1.436  #if 0
   1.437 +/* FIXME: Remove once determined this is not needed in fullscreen mode */
   1.438  void
   1.439  DirectFB_PumpEvents(_THIS)
   1.440  {
     2.1 --- a/src/video/directfb/SDL_DirectFB_events.h	Tue Aug 26 02:26:18 2008 +0000
     2.2 +++ b/src/video/directfb/SDL_DirectFB_events.h	Tue Aug 26 02:32:45 2008 +0000
     2.3 @@ -24,5 +24,6 @@
     2.4  #include "SDL_DirectFB_video.h"
     2.5  
     2.6  /* Functions to be exported */
     2.7 -extern void DirectFB_InitOSKeymap(_THIS);
     2.8 +extern void DirectFB_InitKeyboard(_THIS);
     2.9  extern void DirectFB_PumpEventsWindow(_THIS);
    2.10 +extern SDLKey DirectFB_GetLayoutKey(_THIS, SDLKey physicalKey);
     3.1 --- a/src/video/directfb/SDL_DirectFB_mouse.c	Tue Aug 26 02:26:18 2008 +0000
     3.2 +++ b/src/video/directfb/SDL_DirectFB_mouse.c	Tue Aug 26 02:32:45 2008 +0000
     3.3 @@ -80,7 +80,7 @@
     3.4  
     3.5      dsc.flags =
     3.6          DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS;
     3.7 -    dsc.caps = DSCAPS_NONE;     //DSCAPS_SYSTEMONLY;
     3.8 +    dsc.caps = DSCAPS_VIDEOONLY;
     3.9      dsc.width = surface->w;
    3.10      dsc.height = surface->h;
    3.11      dsc.pixelformat = DSPF_ARGB;
    3.12 @@ -101,7 +101,6 @@
    3.13              dest[i] = 0x00000000;
    3.14          else
    3.15              dest[i] = p[i];
    3.16 -    //memcpy(dest, surface->pixels, surface->w * surface->h * 4);
    3.17      curdata->surf->Unlock(curdata->surf);
    3.18      return cursor;
    3.19    error:
    3.20 @@ -112,7 +111,6 @@
    3.21  static int
    3.22  DirectFB_ShowCursor(SDL_Cursor * cursor)
    3.23  {
    3.24 -    //FIXME check for null cursor here
    3.25      SDL_DFB_CURSORDATA(cursor);
    3.26      SDL_VideoDevice *dev = SDL_GetVideoDevice();
    3.27      SDL_DFB_DEVICEDATA(dev);
    3.28 @@ -136,7 +134,6 @@
    3.29              SDL_DFB_CHECKERR(windata->window->
    3.30                               SetCursorShape(windata->window, curdata->surf,
    3.31                                              curdata->hotx, curdata->hoty));
    3.32 -        //FIXME: This is somehow a directfb issue
    3.33          //TODO: Check administrative 
    3.34          SDL_DFB_CHECKERR(dispdata->layer->
    3.35                           SetCooperativeLevel(dispdata->layer,
    3.36 @@ -176,7 +173,6 @@
    3.37  static void
    3.38  DirectFB_WarpMouse(SDL_Mouse * mouse, SDL_WindowID windowID, int x, int y)
    3.39  {
    3.40 -//      SDL_DFB_CURSORDATA(cursor);     
    3.41      SDL_Window *window = SDL_GetWindowFromID(windowID);
    3.42      SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
    3.43      DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
     4.1 --- a/src/video/directfb/SDL_DirectFB_render.c	Tue Aug 26 02:26:18 2008 +0000
     4.2 +++ b/src/video/directfb/SDL_DirectFB_render.c	Tue Aug 26 02:32:45 2008 +0000
     4.3 @@ -87,7 +87,8 @@
     4.4       (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR |
     4.5        SDL_TEXTUREMODULATE_ALPHA),
     4.6       (SDL_TEXTUREBLENDMODE_NONE | SDL_TEXTUREBLENDMODE_MASK |
     4.7 -      SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_MOD),
     4.8 +      SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD |
     4.9 +      SDL_TEXTUREBLENDMODE_MOD),
    4.10       (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST),
    4.11       14,
    4.12       {
    4.13 @@ -124,16 +125,9 @@
    4.14      void *pixels;
    4.15      int pitch;
    4.16      IDirectFBPalette *palette;
    4.17 +    DFB_DisplayData *display;
    4.18  } DirectFB_TextureData;
    4.19  
    4.20 -static void
    4.21 -UpdateYUVTextureData(SDL_Texture * texture)
    4.22 -{
    4.23 -    /*
    4.24 -     * Not needed - directfb supports yuv surfaces
    4.25 -     */
    4.26 -}
    4.27 -
    4.28  void
    4.29  DirectFB_AddRenderDriver(_THIS)
    4.30  {
    4.31 @@ -178,7 +172,7 @@
    4.32      renderer->DestroyTexture = DirectFB_DestroyTexture;
    4.33      renderer->DestroyRenderer = DirectFB_DestroyRenderer;
    4.34      renderer->info = DirectFB_RenderDriver.info;
    4.35 -    renderer->window = window->id;      // SDL window id
    4.36 +    renderer->window = window->id;      /* SDL window id */
    4.37      renderer->driverdata = data;
    4.38  
    4.39      renderer->info.flags =
    4.40 @@ -200,7 +194,7 @@
    4.41      else
    4.42          renderer->info.flags |= SDL_RENDERER_SINGLEBUFFER;
    4.43  
    4.44 -    data->isyuvdirect = 0;
    4.45 +    data->isyuvdirect = 1;      /* default is on! */
    4.46      p = getenv("SDL_DIRECTFB_YUV_DIRECT");
    4.47      if (p)
    4.48          data->isyuvdirect = atoi(p);
    4.49 @@ -293,6 +287,55 @@
    4.50  }
    4.51  
    4.52  static int
    4.53 +DirectFB_AcquireVidLayer(SDL_Renderer * renderer, SDL_Texture * texture)
    4.54 +{
    4.55 +    SDL_DFB_RENDERERDATA(renderer);
    4.56 +    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
    4.57 +    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
    4.58 +    SDL_DFB_DEVICEDATA(display->device);
    4.59 +    DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
    4.60 +    DirectFB_TextureData *data = texture->driverdata;
    4.61 +    DFBDisplayLayerConfig layconf;
    4.62 +    int ret;
    4.63 +
    4.64 +    if (renddata->isyuvdirect && (dispdata->vidID >= 0)
    4.65 +        && (!dispdata->vidIDinuse)
    4.66 +        && SDL_ISPIXELFORMAT_FOURCC(data->format)) {
    4.67 +        layconf.flags = DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT;
    4.68 +        layconf.width = texture->w;
    4.69 +        layconf.height = texture->h;
    4.70 +        layconf.pixelformat = SDLToDFBPixelFormat(data->format);
    4.71 +
    4.72 +        SDL_DFB_CHECKERR(devdata->dfb->
    4.73 +                         GetDisplayLayer(devdata->dfb, dispdata->vidID,
    4.74 +                                         &data->vidlayer));
    4.75 +        SDL_DFB_CHECKERR(data->vidlayer->
    4.76 +                         SetCooperativeLevel(data->vidlayer,
    4.77 +                                             DLSCL_EXCLUSIVE));
    4.78 +        SDL_DFB_CHECKERR(data->vidlayer->
    4.79 +                         SetConfiguration(data->vidlayer, &layconf));
    4.80 +        SDL_DFB_CHECKERR(data->vidlayer->
    4.81 +                         GetSurface(data->vidlayer, &data->surface));
    4.82 +        //SDL_DFB_CHECKERR(data->vidlayer->GetDescription(data->vidlayer, laydsc));
    4.83 +        dispdata->vidIDinuse = 1;
    4.84 +        data->display = dispdata;
    4.85 +        SDL_DFB_DEBUG("Created HW YUV surface\n");
    4.86 +
    4.87 +        return 0;
    4.88 +    }
    4.89 +    return 1;
    4.90 +  error:
    4.91 +    if (data->vidlayer) {
    4.92 +        SDL_DFB_RELEASE(data->surface);
    4.93 +        SDL_DFB_CHECKERR(data->vidlayer->
    4.94 +                         SetCooperativeLevel(data->vidlayer,
    4.95 +                                             DLSCL_ADMINISTRATIVE));
    4.96 +        SDL_DFB_RELEASE(data->vidlayer);
    4.97 +    }
    4.98 +    return 1;
    4.99 +}
   4.100 +
   4.101 +static int
   4.102  DirectFB_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   4.103  {
   4.104      SDL_DFB_RENDERERDATA(renderer);
   4.105 @@ -300,7 +343,6 @@
   4.106      SDL_DFB_WINDOWDATA(window);
   4.107      SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   4.108      SDL_DFB_DEVICEDATA(display->device);
   4.109 -    DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
   4.110      DirectFB_TextureData *data;
   4.111      DFBResult ret;
   4.112      DFBSurfaceDescription dsc;
   4.113 @@ -313,37 +355,23 @@
   4.114      data->format = texture->format;
   4.115      data->pitch = (texture->w * SDL_BYTESPERPIXEL(data->format));
   4.116      data->vidlayer = NULL;
   4.117 -    if (renddata->isyuvdirect && (dispdata->vidID >= 0)
   4.118 -        && SDL_ISPIXELFORMAT_FOURCC(data->format)) {
   4.119 -        SDL_DFB_CHECKERR(devdata->dfb->
   4.120 -                         GetDisplayLayer(devdata->dfb, dispdata->vidID,
   4.121 -                                         &data->vidlayer));
   4.122 -        layconf.flags = DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT;
   4.123 -        layconf.width = texture->w;
   4.124 -        layconf.height = texture->h;
   4.125 -        layconf.pixelformat = SDLToDFBPixelFormat(data->format);
   4.126  
   4.127 -        SDL_DFB_CHECKERR(data->vidlayer->
   4.128 -                         SetCooperativeLevel(data->vidlayer,
   4.129 -                                             DLSCL_EXCLUSIVE));
   4.130 -        SDL_DFB_CHECKERR(data->vidlayer->
   4.131 -                         SetConfiguration(data->vidlayer, &layconf));
   4.132 -        SDL_DFB_CHECKERR(data->vidlayer->
   4.133 -                         GetSurface(data->vidlayer, &data->surface));
   4.134 -        SDL_DFB_CHECKERR(data->vidlayer->
   4.135 -                         GetDescription(data->vidlayer, &laydsc));
   4.136 -        SDL_DFB_DEBUG("Created HW YUV surface\n");
   4.137 -    }
   4.138 -    if (!data->vidlayer) {
   4.139 +    if (DirectFB_AcquireVidLayer(renderer, texture) != 0) {
   4.140          /* fill surface description */
   4.141          dsc.flags =
   4.142              DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS;
   4.143          dsc.width = texture->w;
   4.144          dsc.height = texture->h;
   4.145 -        /* Never use DSCAPS_VIDEOONLY here. It kills performance
   4.146 +        /* <1.2 Never use DSCAPS_VIDEOONLY here. It kills performance
   4.147           * No DSCAPS_SYSTEMONLY either - let dfb decide
   4.148 +         * 1.2: DSCAPS_SYSTEMONLY boosts performance by factor ~8
   4.149           */
   4.150 -        dsc.caps = 0;           //DSCAPS_PREMULTIPLIED;
   4.151 +        dsc.caps = DSCAPS_PREMULTIPLIED;
   4.152 +
   4.153 +        if (texture->access == SDL_TEXTUREACCESS_STREAMING)
   4.154 +            dsc.caps |= DSCAPS_SYSTEMONLY;
   4.155 +        else
   4.156 +            dsc.caps |= DSCAPS_VIDEOONLY;
   4.157  
   4.158          /* find the right pixelformat */
   4.159  
   4.160 @@ -469,6 +497,7 @@
   4.161      case SDL_TEXTUREBLENDMODE_NONE:
   4.162      case SDL_TEXTUREBLENDMODE_MASK:
   4.163      case SDL_TEXTUREBLENDMODE_BLEND:
   4.164 +    case SDL_TEXTUREBLENDMODE_ADD:
   4.165      case SDL_TEXTUREBLENDMODE_MOD:
   4.166          return 0;
   4.167      default:
   4.168 @@ -513,8 +542,8 @@
   4.169      size_t length;
   4.170  
   4.171      SDL_DFB_CHECKERR(data->surface->Lock(data->surface,
   4.172 -                                         DSLF_WRITE | DSLF_READ, &dpixels,
   4.173 -                                         &dpitch));
   4.174 +                                         DSLF_WRITE | DSLF_READ,
   4.175 +                                         ((void **) &dpixels), &dpitch));
   4.176      src = (Uint8 *) pixels;
   4.177      dst =
   4.178          (Uint8 *) dpixels + rect->y * dpitch +
   4.179 @@ -648,27 +677,52 @@
   4.180          if (texture->
   4.181              modMode & (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA))
   4.182          {
   4.183 -            u8 alpha = 0xFF;
   4.184 -            if (texture->modMode & SDL_TEXTUREMODULATE_ALPHA)
   4.185 +            Uint8 alpha = 0xFF;
   4.186 +            if (texture->modMode & SDL_TEXTUREMODULATE_ALPHA) {
   4.187                  alpha = texture->a;
   4.188 -            if (texture->modMode & SDL_TEXTUREMODULATE_COLOR)
   4.189 +                flags |= DSBLIT_SRC_PREMULTCOLOR;
   4.190 +                SDL_DFB_CHECKERR(data->surface->SetColor(data->surface, 0xFF,
   4.191 +                                                         0xFF, 0xFF, alpha));
   4.192 +            }
   4.193 +            if (texture->modMode & SDL_TEXTUREMODULATE_COLOR) {
   4.194                  SDL_DFB_CHECKERR(data->surface->
   4.195                                   SetColor(data->surface, texture->r,
   4.196                                            texture->g, texture->b, alpha));
   4.197 -            else
   4.198 -                SDL_DFB_CHECKERR(data->surface->SetColor(data->surface, 0xFF,
   4.199 -                                                         0xFF, 0xFF, alpha));
   4.200 -            // Only works together ....
   4.201 -            flags |= DSBLIT_COLORIZE | DSBLIT_SRC_PREMULTCOLOR;
   4.202 +                /* Only works together .... */
   4.203 +                flags |= DSBLIT_COLORIZE | DSBLIT_SRC_PREMULTCOLOR;
   4.204 +            }
   4.205          }
   4.206  
   4.207 -        if (texture->
   4.208 -            blendMode & (SDL_TEXTUREBLENDMODE_MASK |
   4.209 -                         SDL_TEXTUREBLENDMODE_BLEND)) {
   4.210 +        switch (texture->blendMode) {
   4.211 +        case SDL_TEXTUREBLENDMODE_NONE: /**< No blending */
   4.212 +            flags |= DSBLIT_NOFX;
   4.213 +            data->surface->SetSrcBlendFunction(data->surface, DSBF_ONE);
   4.214 +            data->surface->SetDstBlendFunction(data->surface, DSBF_ZERO);
   4.215 +            break;
   4.216 +        case SDL_TEXTUREBLENDMODE_MASK: /**< dst = A ? src : dst (alpha is mask) */
   4.217 +            flags |= DSBLIT_BLEND_ALPHACHANNEL;
   4.218 +            data->surface->SetSrcBlendFunction(data->surface, DSBF_SRCALPHA);
   4.219 +            data->surface->SetDstBlendFunction(data->surface,
   4.220 +                                               DSBF_INVSRCALPHA);
   4.221 +            break;
   4.222 +        case SDL_TEXTUREBLENDMODE_BLEND:/**< dst = (src * A) + (dst * (1-A)) */
   4.223              flags |= DSBLIT_BLEND_ALPHACHANNEL;
   4.224 -        } else {
   4.225 -            flags |= DSBLIT_NOFX;
   4.226 +            data->surface->SetSrcBlendFunction(data->surface, DSBF_SRCALPHA);
   4.227 +            data->surface->SetDstBlendFunction(data->surface,
   4.228 +                                               DSBF_INVSRCALPHA);
   4.229 +            break;
   4.230 +        case SDL_TEXTUREBLENDMODE_ADD:  /**< dst = (src * A) + dst */
   4.231 +            flags |= DSBLIT_BLEND_ALPHACHANNEL;
   4.232 +            data->surface->SetSrcBlendFunction(data->surface, DSBF_SRCALPHA);
   4.233 +            data->surface->SetDstBlendFunction(data->surface, DSBF_ONE);
   4.234 +            break;
   4.235 +        case SDL_TEXTUREBLENDMODE_MOD:  /**< dst = src * dst */
   4.236 +            flags |= DSBLIT_BLEND_ALPHACHANNEL;
   4.237 +            data->surface->SetSrcBlendFunction(data->surface, DSBF_DESTCOLOR);
   4.238 +            data->surface->SetDstBlendFunction(data->surface, DSBF_ZERO);
   4.239 +            break;
   4.240          }
   4.241 +
   4.242          SDL_DFB_CHECKERR(data->surface->
   4.243                           SetBlittingFlags(data->surface, flags));
   4.244          if (srcrect->w == dstrect->w && srcrect->h == dstrect->h) {
   4.245 @@ -720,6 +774,11 @@
   4.246      }
   4.247      SDL_DFB_RELEASE(data->palette);
   4.248      SDL_DFB_RELEASE(data->surface);
   4.249 +    if (data->display) {
   4.250 +        data->display->vidIDinuse = 0;
   4.251 +        data->vidlayer->SetCooperativeLevel(data->vidlayer,
   4.252 +                                            DLSCL_ADMINISTRATIVE);
   4.253 +    }
   4.254      SDL_DFB_RELEASE(data->vidlayer);
   4.255      SDL_free(data);
   4.256      texture->driverdata = NULL;
     5.1 --- a/src/video/directfb/SDL_DirectFB_video.c	Tue Aug 26 02:26:18 2008 +0000
     5.2 +++ b/src/video/directfb/SDL_DirectFB_video.c	Tue Aug 26 02:32:45 2008 +0000
     5.3 @@ -23,11 +23,6 @@
     5.4  	
     5.5  */
     5.6  
     5.7 -/* TODO: Various
     5.8 - * Add Mouse support from 1.2 directfb driver
     5.9 - * - Interface is defined in SDL_Mouse.c.h
    5.10 - * - Default Cursor automatically created
    5.11 - */
    5.12  
    5.13  #include "SDL_config.h"
    5.14  
    5.15 @@ -141,7 +136,6 @@
    5.16      device->GetDisplayGammaRamp = NULL;
    5.17  #endif
    5.18      device->PumpEvents = DirectFB_PumpEventsWindow;
    5.19 -
    5.20      device->CreateWindow = DirectFB_CreateWindow;
    5.21      device->CreateWindowFrom = DirectFB_CreateWindowFrom;
    5.22      device->SetWindowTitle = DirectFB_SetWindowTitle;
    5.23 @@ -299,14 +293,11 @@
    5.24      DFB_DisplayData *dispdata;
    5.25      DFB_DeviceData *devdata;
    5.26      SDL_DisplayMode mode;
    5.27 -    SDL_Keyboard keyboard;
    5.28      int i;
    5.29      DFBResult ret;
    5.30      int tcw[DFB_MAX_SCREENS];
    5.31      int tch[DFB_MAX_SCREENS];
    5.32  
    5.33 -    SDL_zero(keyboard);
    5.34 -
    5.35      SDL_DFB_CHECKERR(DirectFBInit(NULL, NULL));
    5.36      SDL_DFB_CHECKERR(DirectFBCreate(&dfb));
    5.37  
    5.38 @@ -325,7 +316,15 @@
    5.39          devdata->aux = i;
    5.40          SDL_DFB_CHECKERR(screen->
    5.41                           EnumDisplayLayers(screen, &cbLayers, devdata));
    5.42 +#if (DIRECTFB_MAJOR_VERSION >= 1)
    5.43          screen->GetSize(screen, &tcw[i], &tch[i]);
    5.44 +#else
    5.45 +        /* FIXME: this is only used to center windows
    5.46 +         *        Should be done otherwise, e.g. get surface from layer
    5.47 +         */
    5.48 +        tcw[i] = 800;
    5.49 +        tch[i] = 600;
    5.50 +#endif
    5.51          screen->Release(screen);
    5.52      }
    5.53  
    5.54 @@ -369,6 +368,7 @@
    5.55          /* YUV - Video layer */
    5.56  
    5.57          dispdata->vidID = devdata->vidlayer[i];
    5.58 +        dispdata->vidIDinuse = 0;
    5.59  
    5.60          SDL_zero(display);
    5.61  
    5.62 @@ -400,9 +400,8 @@
    5.63  
    5.64      DirectFB_AddRenderDriver(_this);
    5.65      DirectFB_InitMouse(_this);
    5.66 +    DirectFB_InitKeyboard(_this);
    5.67      //devdata->mouse = SDL_AddMouse(&mouse, -1);
    5.68 -    devdata->keyboard = SDL_AddKeyboard(&keyboard, -1);
    5.69 -    DirectFB_InitOSKeymap(_this);
    5.70  
    5.71      return 0;
    5.72  
    5.73 @@ -453,8 +452,6 @@
    5.74          //SDL_free(dispdata);
    5.75      }
    5.76  
    5.77 -    //SDL_DFB_RELEASE(devdata->eventbuffer);
    5.78 -
    5.79      SDL_DFB_RELEASE(devdata->dfb);
    5.80  
    5.81      SDL_DelMouse(devdata->mouse);
    5.82 @@ -579,12 +576,13 @@
    5.83      DFBDisplayLayerConfig config, rconfig;
    5.84      DFBDisplayLayerConfigFlags fail = 0;
    5.85      DFBResult ret;
    5.86 +    DFB_WindowData *win;
    5.87  
    5.88      SDL_DFB_CHECKERR(data->layer->
    5.89                       SetCooperativeLevel(data->layer, DLSCL_ADMINISTRATIVE));
    5.90  
    5.91      SDL_DFB_CHECKERR(data->layer->GetConfiguration(data->layer, &config));
    5.92 -    config.flags = DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_BUFFERMODE;
    5.93 +    config.flags = DLCONF_WIDTH | DLCONF_HEIGHT;        // | DLCONF_BUFFERMODE;
    5.94      if (mode->format != SDL_PIXELFORMAT_UNKNOWN) {
    5.95          config.flags |= DLCONF_PIXELFORMAT;
    5.96          config.pixelformat = SDLToDFBPixelFormat(mode->format);
    5.97 @@ -593,7 +591,7 @@
    5.98      config.width = mode->w;
    5.99      config.height = mode->h;
   5.100  
   5.101 -    config.buffermode = DLBM_BACKVIDEO;
   5.102 +    //config.buffermode = DLBM_BACKVIDEO;
   5.103  
   5.104      //config.pixelformat = GetFormatForBpp (bpp, HIDDEN->layer);
   5.105  
   5.106 @@ -614,12 +612,35 @@
   5.107  
   5.108      if ((config.width != rconfig.width) ||
   5.109          (config.height != rconfig.height) ||
   5.110 -        (config.pixelformat != rconfig.pixelformat)) {
   5.111 +        ((mode->format != SDL_PIXELFORMAT_UNKNOWN)
   5.112 +         && (config.pixelformat != rconfig.pixelformat))) {
   5.113          SDL_DFB_DEBUG("Error setting mode %dx%d-%x\n", mode->w, mode->h,
   5.114                        mode->format);
   5.115          return -1;
   5.116      }
   5.117  
   5.118 +    data->pixelformat = rconfig.pixelformat;
   5.119 +    data->cw = config.width;
   5.120 +    data->ch = config.height;
   5.121 +    SDL_CurrentDisplay.current_mode = *mode;
   5.122 +
   5.123 +    /*
   5.124 +     * FIXME: video mode switch is currently broken
   5.125 +     * 
   5.126 +     * DirectFB 1.2.0-rc1 even has a broken cursor after a switch
   5.127 +     * The following code needs to be revisited whether it is still 
   5.128 +     * needed once the switch works again.
   5.129 +     */
   5.130 +
   5.131 +    win = devdata->firstwin;
   5.132 +
   5.133 +    while (win) {
   5.134 +        SDL_DFB_RELEASE(win->surface);
   5.135 +        SDL_DFB_CHECKERR(win->window->GetSurface(win->window, &win->surface));
   5.136 +        win = win->next;
   5.137 +    }
   5.138 +
   5.139 +
   5.140      return 0;
   5.141    error:
   5.142      return -1;
   5.143 @@ -680,8 +701,16 @@
   5.144      }
   5.145  
   5.146      desc.flags =
   5.147 -        DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_CAPS | DWDESC_PIXELFORMAT |
   5.148 +        DWDESC_WIDTH | DWDESC_HEIGHT /*| DWDESC_CAPS */  | DWDESC_PIXELFORMAT
   5.149 +        |
   5.150          DWDESC_SURFACE_CAPS;
   5.151 +
   5.152 +#if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 0)
   5.153 +    /* Needed for 1.2 */
   5.154 +    desc.flags |= DWDESC_POSX | DWDESC_POSY;
   5.155 +    desc.posx = x;
   5.156 +    desc.posy = y;
   5.157 +#else
   5.158      if (!(window->flags & SDL_WINDOW_FULLSCREEN)
   5.159          && window->x != SDL_WINDOWPOS_UNDEFINED
   5.160          && window->y != SDL_WINDOWPOS_UNDEFINED) {
   5.161 @@ -689,12 +718,13 @@
   5.162          desc.posx = x;
   5.163          desc.posy = y;
   5.164      }
   5.165 +#endif
   5.166  
   5.167      desc.width = window->w;
   5.168      desc.height = window->h;
   5.169      desc.pixelformat = dispdata->pixelformat;
   5.170 -    desc.caps = 0;              //DWCAPS_DOUBLEBUFFER;
   5.171 -    desc.surface_caps = DSCAPS_DOUBLE | DSCAPS_TRIPLE;  //| DSCAPS_PREMULTIPLIED;
   5.172 +    desc.caps = 0;              // DWCAPS_DOUBLEBUFFER;
   5.173 +    desc.surface_caps = DSCAPS_DOUBLE | DSCAPS_TRIPLE / DSCAPS_PREMULTIPLIED;
   5.174  
   5.175      /* Create the window. */
   5.176      SDL_DFB_CHECKERR(dispdata->layer->
   5.177 @@ -790,21 +820,52 @@
   5.178      SDL_DFB_DEVICEDATA(_this);
   5.179      SDL_DFB_WINDOWDATA(window);
   5.180      SDL_DFB_DISPLAYDATA(_this, window);
   5.181 +    int x, y;
   5.182  
   5.183 -    if (!(window->flags & SDL_WINDOW_FULLSCREEN))
   5.184 -        windata->window->MoveTo(windata->window, window->x, window->y);
   5.185 +    if (window->y == SDL_WINDOWPOS_UNDEFINED)
   5.186 +        y = 0;
   5.187 +    else
   5.188 +        y = window->y;
   5.189 +
   5.190 +    if (window->x == SDL_WINDOWPOS_UNDEFINED)
   5.191 +        x = 0;
   5.192 +    else
   5.193 +        x = window->x;
   5.194 +
   5.195 +    if (window->flags & SDL_WINDOW_FULLSCREEN) {
   5.196 +        x = 0;
   5.197 +        y = 0;
   5.198 +    }
   5.199 +    //if (!(window->flags & SDL_WINDOW_FULLSCREEN))
   5.200 +    windata->window->MoveTo(windata->window, x, y);
   5.201  }
   5.202  
   5.203  static void
   5.204  DirectFB_SetWindowSize(_THIS, SDL_Window * window)
   5.205  {
   5.206 +    int ret;
   5.207      SDL_DFB_DEVICEDATA(_this);
   5.208      SDL_DFB_WINDOWDATA(window);
   5.209      SDL_DFB_DISPLAYDATA(_this, window);
   5.210  
   5.211 -    if (!(window->flags & SDL_WINDOW_FULLSCREEN))
   5.212 -        windata->window->Resize(windata->window, window->w, window->h);
   5.213 +    if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
   5.214 +        int ch, cw;
   5.215 +
   5.216 +        //      SDL_DFB_DEBUG("Resize %d %d %d %d\n", cw, ch, window->w, window->h);
   5.217 +#if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 0)
   5.218 +        SDL_DFB_CHECKERR(windata->window->
   5.219 +                         ResizeSurface(windata->window, window->w,
   5.220 +                                       window->h));
   5.221 +#else
   5.222 +        SDL_DFB_CHECKERR(windata->window->
   5.223 +                         Resize(windata->window, window->w, window->h));
   5.224 +#endif
   5.225 +        SDL_DFB_CHECKERR(windata->window->GetSize(windata->window, &window->w, &window->h));    /* if a window manager should have decided otherwise */
   5.226 +    }
   5.227 +  error:
   5.228 +    return;
   5.229  }
   5.230 +
   5.231  static void
   5.232  DirectFB_ShowWindow(_THIS, SDL_Window * window)
   5.233  {
     6.1 --- a/src/video/directfb/SDL_DirectFB_video.h	Tue Aug 26 02:26:18 2008 +0000
     6.2 +++ b/src/video/directfb/SDL_DirectFB_video.h	Tue Aug 26 02:32:45 2008 +0000
     6.3 @@ -114,8 +114,11 @@
     6.4  {
     6.5      IDirectFBDisplayLayer *layer;
     6.6      DFBSurfacePixelFormat pixelformat;
     6.7 +    //FIXME: support for multiple layer ...
     6.8      DFBDisplayLayerID vidID;
     6.9  
    6.10 +    int vidIDinuse;
    6.11 +
    6.12      int cw;
    6.13      int ch;
    6.14  
    6.15 @@ -139,9 +142,9 @@
    6.16      IDirectFBGL *gl_context;
    6.17      IDirectFBEventBuffer *eventbuffer;
    6.18      DFBWindowID windowID;
    6.19 -    int id;                     // SDL window id
    6.20 +    int id;                     /* SDL window id */
    6.21      DFB_WindowData *next;
    6.22 -    u8 opacity;
    6.23 +    Uint8 opacity;
    6.24  };
    6.25  
    6.26  typedef struct _DFB_DeviceData DFB_DeviceData;
    6.27 @@ -152,6 +155,7 @@
    6.28      IDirectFB *dfb;
    6.29      int mouse;
    6.30      int keyboard;
    6.31 +    int kbdgeneric;
    6.32      DFB_WindowData *firstwin;
    6.33  
    6.34      int numscreens;
    6.35 @@ -159,10 +163,9 @@
    6.36      DFBDisplayLayerID gralayer[DFB_MAX_SCREENS];
    6.37      DFBDisplayLayerID vidlayer[DFB_MAX_SCREENS];
    6.38  
    6.39 -    // auxiliary integer for callbacks
    6.40 -    int aux;
    6.41 +    int aux;                    /* auxiliary integer for callbacks */
    6.42  
    6.43 -    // OpenGL
    6.44 +    /* OpenGL */
    6.45      void (*glFinish) (void);
    6.46      void (*glFlush) (void);
    6.47  };