Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
authorSam Lantinga <slouken@libsdl.org>
Sat, 11 Aug 2007 21:51:19 +0000
changeset 22260e70b4b8cf84
parent 2225 3bca1b7ca25b
child 2227 b252359547ed
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
README.DirectFB
src/SDL_compat.c
src/video/directfb/SDL_DirectFB_events.c
src/video/directfb/SDL_DirectFB_events.h
src/video/directfb/SDL_DirectFB_keys.h
src/video/directfb/SDL_DirectFB_mouse.c
src/video/directfb/SDL_DirectFB_mouse.h
src/video/directfb/SDL_DirectFB_render.c
src/video/directfb/SDL_DirectFB_render.h
src/video/directfb/SDL_DirectFB_video.c
src/video/directfb/SDL_DirectFB_video.h
src/video/directfb/SDL_DirectFB_yuv.c
src/video/directfb/SDL_DirectFB_yuv.h
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/README.DirectFB	Sat Aug 11 21:51:19 2007 +0000
     1.3 @@ -0,0 +1,45 @@
     1.4 +SDL on DirectFB
     1.5 +
     1.6 +Supports:
     1.7 +
     1.8 +- Hardware YUV overlays
     1.9 +- OpenGL - software only
    1.10 +- 2D/3D accelerations (depends on directfb driver)
    1.11 +
    1.12 +What you need:
    1.13 +
    1.14 +DirectFB 1.0.0 - required
    1.15 +Kernel-Framebuffer support: required: vesafb, radeonfb .... 
    1.16 +Mesa 7.0.x	   - optional for OpenGL
    1.17 +
    1.18 +As of this writing 20070810 you need to pull Mesa from git and do the following:
    1.19 +
    1.20 +------------------------
    1.21 +cd mesa 
    1.22 +make linux-directfb
    1.23 +make
    1.24 +
    1.25 +echo Installing - pleaser enter sudo pw.
    1.26 +
    1.27 +sudo make install INSTALL_DIR=/usr/local/dfb_GL
    1.28 +cd src/mesa/drivers/directfb
    1.29 +make
    1.30 +sudo make install INSTALL_DIR=/usr/local/dfb_GL
    1.31 +------------------------
    1.32 +
    1.33 +To run the SDL - testprograms:
    1.34 +
    1.35 +export SDL_VIDEODRIVER=directfb
    1.36 +export LD_LIBRARY_PATH=/usr/local/dfb_GL/lib
    1.37 +export LD_PRELOAD=/usr/local/dfb_GL/libGL.so.7
    1.38 +
    1.39 +./testgl
    1.40 +
    1.41 +To use hardware accelerated YUV-overlays for YUV-textures, use:
    1.42 +
    1.43 +export SDL_DIRECTFB_YUV_DIRECT=1
    1.44 +
    1.45 +This is disabled by default. It will only support one concurrent 
    1.46 +overlay and may behave strange if not used with SDL_CreateYUvOverlay
    1.47 +from SDLcompat.c. 
    1.48 + 
     2.1 --- a/src/SDL_compat.c	Sat Aug 11 21:44:49 2007 +0000
     2.2 +++ b/src/SDL_compat.c	Sat Aug 11 21:51:19 2007 +0000
     2.3 @@ -1440,19 +1440,21 @@
     2.4          < 0) {
     2.5          return -1;
     2.6      }
     2.7 +    overlay->pixels[0] = (Uint8 *) pixels;
     2.8 +    overlay->pitches[0] = pitch;
     2.9      switch (overlay->format) {
    2.10      case SDL_YV12_OVERLAY:
    2.11      case SDL_IYUV_OVERLAY:
    2.12 -        overlay->pixels[0] = (Uint8 *) pixels;
    2.13 +        overlay->pitches[1] = pitch / 2;
    2.14 +        overlay->pitches[2] = pitch / 2;
    2.15          overlay->pixels[1] =
    2.16              overlay->pixels[0] + overlay->pitches[0] * overlay->h;
    2.17          overlay->pixels[2] =
    2.18 -            overlay->pixels[1] + overlay->pitches[1] * overlay->h;
    2.19 +            overlay->pixels[1] + overlay->pitches[1] * overlay->h / 2;
    2.20          break;
    2.21      case SDL_YUY2_OVERLAY:
    2.22      case SDL_UYVY_OVERLAY:
    2.23      case SDL_YVYU_OVERLAY:
    2.24 -        overlay->pixels[0] = (Uint8 *) pixels;
    2.25          break;
    2.26      }
    2.27      return 0;
     3.1 --- a/src/video/directfb/SDL_DirectFB_events.c	Sat Aug 11 21:44:49 2007 +0000
     3.2 +++ b/src/video/directfb/SDL_DirectFB_events.c	Sat Aug 11 21:51:19 2007 +0000
     3.3 @@ -23,70 +23,97 @@
     3.4  
     3.5  /* Handle the event stream, converting DirectFB input events into SDL events */
     3.6  
     3.7 -#include <sys/types.h>
     3.8 -#include <sys/time.h>
     3.9 -#include <unistd.h>
    3.10 -#include <fcntl.h>
    3.11 -#include <termios.h>
    3.12 -
    3.13  #include <directfb.h>
    3.14  
    3.15  #include "SDL.h"
    3.16  #include "../SDL_sysvideo.h"
    3.17  #include "../../events/SDL_sysevents.h"
    3.18  #include "../../events/SDL_events_c.h"
    3.19 -#include "SDL_DirectFB_video.h"
    3.20  #include "SDL_DirectFB_events.h"
    3.21  
    3.22  /* The translation tables from a DirectFB keycode to a SDL keysym */
    3.23  static SDLKey keymap[256];
    3.24 -static SDL_keysym *DirectFB_TranslateKey(DFBInputEvent * ev,
    3.25 +
    3.26 +static SDL_keysym *DirectFB_TranslateKey(DFBInputDeviceKeyIdentifier key_id,
    3.27 +                                         DFBInputDeviceKeySymbol key_symbol,
    3.28 +                                         DFBInputDeviceModifierMask key_mod,
    3.29                                           SDL_keysym * keysym);
    3.30 -static int DirectFB_TranslateButton(DFBInputEvent * ev);
    3.31  
    3.32 -static int posted = 0;
    3.33 -
    3.34 +static int DirectFB_TranslateButton(DFBInputDeviceButtonIdentifier button);
    3.35  
    3.36  void
    3.37 -DirectFB_PumpEvents(_THIS)
    3.38 +DirectFB_PumpEventsWindow(_THIS)
    3.39  {
    3.40 -    DFBInputEvent evt;
    3.41 +    SDL_DFB_DEVICEDATA(_this);
    3.42 +    DFB_WindowData *p;
    3.43 +    DFBWindowEvent evt;
    3.44  
    3.45 -    while (HIDDEN->eventbuffer->GetEvent(HIDDEN->eventbuffer,
    3.46 -                                         DFB_EVENT(&evt)) == DFB_OK) {
    3.47 -        SDL_keysym keysym;
    3.48 +    for (p = devdata->firstwin; p != NULL; p = p->next) {
    3.49 +        while (p->eventbuffer->GetEvent(p->eventbuffer,
    3.50 +                                        DFB_EVENT(&evt)) == DFB_OK) {
    3.51 +            SDL_keysym keysym;
    3.52  
    3.53 -        switch (evt.type) {
    3.54 -        case DIET_BUTTONPRESS:
    3.55 -            posted += SDL_PrivateMouseButton(SDL_PRESSED,
    3.56 -                                             DirectFB_TranslateButton
    3.57 -                                             (&evt), 0, 0);
    3.58 -            break;
    3.59 -        case DIET_BUTTONRELEASE:
    3.60 -            posted += SDL_PrivateMouseButton(SDL_RELEASED,
    3.61 -                                             DirectFB_TranslateButton
    3.62 -                                             (&evt), 0, 0);
    3.63 -            break;
    3.64 -        case DIET_KEYPRESS:
    3.65 -            posted +=
    3.66 -                SDL_PrivateKeyboard(SDL_PRESSED,
    3.67 -                                    DirectFB_TranslateKey(&evt, &keysym));
    3.68 -            break;
    3.69 -        case DIET_KEYRELEASE:
    3.70 -            posted +=
    3.71 -                SDL_PrivateKeyboard(SDL_RELEASED,
    3.72 -                                    DirectFB_TranslateKey(&evt, &keysym));
    3.73 -            break;
    3.74 -        case DIET_AXISMOTION:
    3.75 -            if (evt.flags & DIEF_AXISREL) {
    3.76 -                if (evt.axis == DIAI_X)
    3.77 -                    posted += SDL_PrivateMouseMotion(0, 1, evt.axisrel, 0);
    3.78 -                else if (evt.axis == DIAI_Y)
    3.79 -                    posted += SDL_PrivateMouseMotion(0, 1, 0, evt.axisrel);
    3.80 +            if (evt.clazz = DFEC_WINDOW) {
    3.81 +                switch (evt.type) {
    3.82 +                case DWET_BUTTONDOWN:
    3.83 +                    SDL_SendMouseButton(devdata->mouse, SDL_PRESSED,
    3.84 +                                        DirectFB_TranslateButton(evt.button));
    3.85 +                    break;
    3.86 +                case DWET_BUTTONUP:
    3.87 +                    SDL_SendMouseButton(devdata->mouse, SDL_RELEASED,
    3.88 +                                        DirectFB_TranslateButton(evt.button));
    3.89 +                    break;
    3.90 +                case DWET_MOTION:
    3.91 +                    SDL_SendMouseMotion(devdata->mouse, 0, evt.x, evt.y);
    3.92 +                    break;
    3.93 +                case DWET_KEYDOWN:
    3.94 +                    DirectFB_TranslateKey(evt.key_id, evt.key_symbol,
    3.95 +                                          evt.modifiers, &keysym);
    3.96 +                    SDL_SendKeyboardKey(devdata->keyboard, SDL_PRESSED,
    3.97 +                                        keysym.scancode, keysym.sym);
    3.98 +                    break;
    3.99 +                case DWET_KEYUP:
   3.100 +                    DirectFB_TranslateKey(evt.key_id, evt.key_symbol,
   3.101 +                                          evt.modifiers, &keysym);
   3.102 +                    SDL_SendKeyboardKey(devdata->keyboard, SDL_RELEASED,
   3.103 +                                        keysym.scancode, keysym.sym);
   3.104 +                    break;
   3.105 +                case DWET_POSITION_SIZE:
   3.106 +                    SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_MOVED, evt.cx,
   3.107 +                                        evt.cy);
   3.108 +                    SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_RESIZED, evt.w,
   3.109 +                                        evt.h);
   3.110 +                    break;
   3.111 +                case DWET_POSITION:
   3.112 +                    SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_MOVED, evt.cx,
   3.113 +                                        evt.cy);
   3.114 +                    break;
   3.115 +                case DWET_SIZE:
   3.116 +                    SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_RESIZED, evt.w,
   3.117 +                                        evt.h);
   3.118 +                    break;
   3.119 +                case DWET_CLOSE:
   3.120 +                    SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_CLOSE, 0, 0);
   3.121 +                    break;
   3.122 +                case DWET_GOTFOCUS:
   3.123 +                    //TODO: Implement for yuv-overlay DirectFB_SwitchOverlayContext(this, evt.window_id);
   3.124 +                    SDL_SetKeyboardFocus(devdata->keyboard, p->id);
   3.125 +                    break;
   3.126 +                case DWET_LOSTFOCUS:
   3.127 +                    SDL_SetKeyboardFocus(devdata->keyboard, 0);
   3.128 +                    break;
   3.129 +                case DWET_ENTER:
   3.130 +                    //SDL_DirectFB_ReshowCursor(_this, 0);
   3.131 +                    SDL_SetMouseFocus(devdata->mouse, p->id);
   3.132 +                    break;
   3.133 +                case DWET_LEAVE:
   3.134 +                    SDL_SetMouseFocus(devdata->mouse, 0);
   3.135 +                    //SDL_DirectFB_ReshowCursor(_this, 1);
   3.136 +                    break;
   3.137 +                default:
   3.138 +                    ;
   3.139 +                }
   3.140              }
   3.141 -            break;
   3.142 -        default:
   3.143 -            ;
   3.144          }
   3.145      }
   3.146  }
   3.147 @@ -177,35 +204,80 @@
   3.148      keymap[DIKI_SCROLL_LOCK - DIKI_UNKNOWN] = SDLK_SCROLLOCK;
   3.149      keymap[DIKI_PRINT - DIKI_UNKNOWN] = SDLK_PRINT;
   3.150      keymap[DIKI_PAUSE - DIKI_UNKNOWN] = SDLK_PAUSE;
   3.151 +
   3.152 +    keymap[DIKI_KP_EQUAL - DIKI_UNKNOWN] = SDLK_KP_EQUALS;
   3.153 +    keymap[DIKI_KP_DECIMAL - DIKI_UNKNOWN] = SDLK_KP_PERIOD;
   3.154 +    keymap[DIKI_KP_0 - DIKI_UNKNOWN] = SDLK_KP0;
   3.155 +    keymap[DIKI_KP_1 - DIKI_UNKNOWN] = SDLK_KP1;
   3.156 +    keymap[DIKI_KP_2 - DIKI_UNKNOWN] = SDLK_KP2;
   3.157 +    keymap[DIKI_KP_3 - DIKI_UNKNOWN] = SDLK_KP3;
   3.158 +    keymap[DIKI_KP_4 - DIKI_UNKNOWN] = SDLK_KP4;
   3.159 +    keymap[DIKI_KP_5 - DIKI_UNKNOWN] = SDLK_KP5;
   3.160 +    keymap[DIKI_KP_6 - DIKI_UNKNOWN] = SDLK_KP6;
   3.161 +    keymap[DIKI_KP_7 - DIKI_UNKNOWN] = SDLK_KP7;
   3.162 +    keymap[DIKI_KP_8 - DIKI_UNKNOWN] = SDLK_KP8;
   3.163 +    keymap[DIKI_KP_9 - DIKI_UNKNOWN] = SDLK_KP9;
   3.164      keymap[DIKI_KP_DIV - DIKI_UNKNOWN] = SDLK_KP_DIVIDE;
   3.165      keymap[DIKI_KP_MULT - DIKI_UNKNOWN] = SDLK_KP_MULTIPLY;
   3.166      keymap[DIKI_KP_MINUS - DIKI_UNKNOWN] = SDLK_KP_MINUS;
   3.167      keymap[DIKI_KP_PLUS - DIKI_UNKNOWN] = SDLK_KP_PLUS;
   3.168      keymap[DIKI_KP_ENTER - DIKI_UNKNOWN] = SDLK_KP_ENTER;
   3.169 +
   3.170 +    keymap[DIKI_QUOTE_LEFT - DIKI_UNKNOWN] = SDLK_BACKQUOTE;    /*  TLDE  */
   3.171 +    keymap[DIKI_MINUS_SIGN - DIKI_UNKNOWN] = SDLK_MINUS;        /*  AE11  */
   3.172 +    keymap[DIKI_EQUALS_SIGN - DIKI_UNKNOWN] = SDLK_EQUALS;      /*  AE12  */
   3.173 +    keymap[DIKI_BRACKET_LEFT - DIKI_UNKNOWN] = SDLK_RIGHTBRACKET;       /*  AD11  */
   3.174 +    keymap[DIKI_BRACKET_RIGHT - DIKI_UNKNOWN] = SDLK_LEFTBRACKET;       /*  AD12  */
   3.175 +    keymap[DIKI_BACKSLASH - DIKI_UNKNOWN] = SDLK_BACKSLASH;     /*  BKSL  */
   3.176 +    keymap[DIKI_SEMICOLON - DIKI_UNKNOWN] = SDLK_SEMICOLON;     /*  AC10  */
   3.177 +    keymap[DIKI_QUOTE_RIGHT - DIKI_UNKNOWN] = SDLK_QUOTE;       /*  AC11  */
   3.178 +    keymap[DIKI_COMMA - DIKI_UNKNOWN] = SDLK_COMMA;     /*  AB08  */
   3.179 +    keymap[DIKI_PERIOD - DIKI_UNKNOWN] = SDLK_PERIOD;   /*  AB09  */
   3.180 +    keymap[DIKI_SLASH - DIKI_UNKNOWN] = SDLK_SLASH;     /*  AB10  */
   3.181 +    keymap[DIKI_LESS_SIGN - DIKI_UNKNOWN] = SDLK_LESS;  /*  103rd  */
   3.182  }
   3.183  
   3.184 +static SDL_keysym *
   3.185 +DirectFB_TranslateKey(DFBInputDeviceKeyIdentifier key_id,
   3.186 +                      DFBInputDeviceKeySymbol key_symbol,
   3.187 +                      DFBInputDeviceModifierMask key_mod, SDL_keysym * keysym)
   3.188 +{
   3.189 +    SDLMod mod = KMOD_NONE;
   3.190  
   3.191 -static SDL_keysym *
   3.192 -DirectFB_TranslateKey(DFBInputEvent * ev, SDL_keysym * keysym)
   3.193 -{
   3.194 +    /*
   3.195 +     *  Set modifier information 
   3.196 +     */
   3.197 +
   3.198 +    if (key_mod & DIMM_SHIFT)
   3.199 +        mod = mod | KMOD_LSHIFT;
   3.200 +    if (key_mod & DIMM_CONTROL)
   3.201 +        mod = mod | KMOD_LCTRL;
   3.202 +    if (key_mod & DIMM_ALT)
   3.203 +        mod = mod | KMOD_LALT;
   3.204 +    if (key_mod & DIMM_ALTGR)
   3.205 +        mod = mod | KMOD_RALT;
   3.206 +    if (key_mod & DIMM_META)
   3.207 +        mod = mod | KMOD_LMETA;
   3.208 +
   3.209      /* Set the keysym information */
   3.210 -    keysym->scancode = ev->key_id;
   3.211 -    keysym->mod = KMOD_NONE;    /* FIXME */
   3.212 +    keysym->scancode = key_id;
   3.213 +
   3.214 +    keysym->mod = mod;
   3.215      keysym->unicode =
   3.216 -        (DFB_KEY_TYPE(ev->key_symbol) == DIKT_UNICODE) ? ev->key_symbol : 0;
   3.217 +        (DFB_KEY_TYPE(key_symbol) == DIKT_UNICODE) ? key_symbol : 0;
   3.218  
   3.219 -    if (ev->key_symbol > 0 && ev->key_symbol < 128)
   3.220 -        keysym->sym = ev->key_symbol;
   3.221 +    if (key_symbol > 0 && key_symbol < 255)
   3.222 +        keysym->sym = key_symbol;
   3.223      else
   3.224 -        keysym->sym = keymap[ev->key_id - DIKI_UNKNOWN];
   3.225 +        keysym->sym = keymap[key_id - DIKI_UNKNOWN];
   3.226  
   3.227      return keysym;
   3.228  }
   3.229  
   3.230  static int
   3.231 -DirectFB_TranslateButton(DFBInputEvent * ev)
   3.232 +DirectFB_TranslateButton(DFBInputDeviceButtonIdentifier button)
   3.233  {
   3.234 -    switch (ev->button) {
   3.235 +    switch (button) {
   3.236      case DIBI_LEFT:
   3.237          return 1;
   3.238      case DIBI_MIDDLE:
   3.239 @@ -217,4 +289,76 @@
   3.240      }
   3.241  }
   3.242  
   3.243 -/* vi: set ts=4 sw=4 expandtab: */
   3.244 +#if 0
   3.245 +void
   3.246 +DirectFB_PumpEvents(_THIS)
   3.247 +{
   3.248 +    SDL_DFB_DEVICEDATA(_this);
   3.249 +    DFBInputEvent evt;
   3.250 +    static last_x = 0, last_y = 0;
   3.251 +
   3.252 +    while (devdata->eventbuffer->GetEvent(devdata->eventbuffer,
   3.253 +                                          DFB_EVENT(&evt)) == DFB_OK) {
   3.254 +        SDL_keysym keysym;
   3.255 +        DFBInputDeviceModifierMask mod;
   3.256 +
   3.257 +        if (evt.clazz = DFEC_INPUT) {
   3.258 +            if (evt.flags & DIEF_MODIFIERS)
   3.259 +                mod = evt.modifiers;
   3.260 +            else
   3.261 +                mod = 0;
   3.262 +
   3.263 +            switch (evt.type) {
   3.264 +            case DIET_BUTTONPRESS:
   3.265 +                posted += SDL_PrivateMouseButton(SDL_PRESSED,
   3.266 +                                                 DirectFB_TranslateButton(evt.
   3.267 +                                                                          button),
   3.268 +                                                 0, 0);
   3.269 +                break;
   3.270 +            case DIET_BUTTONRELEASE:
   3.271 +                posted += SDL_PrivateMouseButton(SDL_RELEASED,
   3.272 +                                                 DirectFB_TranslateButton(evt.
   3.273 +                                                                          button),
   3.274 +                                                 0, 0);
   3.275 +                break;
   3.276 +            case DIET_KEYPRESS:
   3.277 +                posted += SDL_PrivateKeyboard(SDL_PRESSED,
   3.278 +                                              DirectFB_TranslateKey(evt.
   3.279 +                                                                    key_id,
   3.280 +                                                                    evt.
   3.281 +                                                                    key_symbol,
   3.282 +                                                                    mod,
   3.283 +                                                                    &keysym));
   3.284 +                break;
   3.285 +            case DIET_KEYRELEASE:
   3.286 +                posted += SDL_PrivateKeyboard(SDL_RELEASED,
   3.287 +                                              DirectFB_TranslateKey(evt.
   3.288 +                                                                    key_id,
   3.289 +                                                                    evt.
   3.290 +                                                                    key_symbol,
   3.291 +                                                                    mod,
   3.292 +                                                                    &keysym));
   3.293 +                break;
   3.294 +            case DIET_AXISMOTION:
   3.295 +                if (evt.flags & DIEF_AXISREL) {
   3.296 +                    if (evt.axis == DIAI_X)
   3.297 +                        posted +=
   3.298 +                            SDL_PrivateMouseMotion(0, 1, evt.axisrel, 0);
   3.299 +                    else if (evt.axis == DIAI_Y)
   3.300 +                        posted +=
   3.301 +                            SDL_PrivateMouseMotion(0, 1, 0, evt.axisrel);
   3.302 +                } else if (evt.flags & DIEF_AXISABS) {
   3.303 +                    if (evt.axis == DIAI_X)
   3.304 +                        last_x = evt.axisabs;
   3.305 +                    else if (evt.axis == DIAI_Y)
   3.306 +                        last_y = evt.axisabs;
   3.307 +                    posted += SDL_PrivateMouseMotion(0, 0, last_x, last_y);
   3.308 +                }
   3.309 +                break;
   3.310 +            default:
   3.311 +                ;
   3.312 +            }
   3.313 +        }
   3.314 +    }
   3.315 +}
   3.316 +#endif
     4.1 --- a/src/video/directfb/SDL_DirectFB_events.h	Sat Aug 11 21:44:49 2007 +0000
     4.2 +++ b/src/video/directfb/SDL_DirectFB_events.h	Sat Aug 11 21:51:19 2007 +0000
     4.3 @@ -25,5 +25,4 @@
     4.4  
     4.5  /* Functions to be exported */
     4.6  extern void DirectFB_InitOSKeymap(_THIS);
     4.7 -extern void DirectFB_PumpEvents(_THIS);
     4.8 -/* vi: set ts=4 sw=4 expandtab: */
     4.9 +extern void DirectFB_PumpEventsWindow(_THIS);
     5.1 --- a/src/video/directfb/SDL_DirectFB_keys.h	Sat Aug 11 21:44:49 2007 +0000
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,135 +0,0 @@
     5.4 -
     5.5 -#define SCANCODE_ESCAPE			1
     5.6 -
     5.7 -#define SCANCODE_1			2
     5.8 -#define SCANCODE_2			3
     5.9 -#define SCANCODE_3			4
    5.10 -#define SCANCODE_4			5
    5.11 -#define SCANCODE_5			6
    5.12 -#define SCANCODE_6			7
    5.13 -#define SCANCODE_7			8
    5.14 -#define SCANCODE_8			9
    5.15 -#define SCANCODE_9			10
    5.16 -#define SCANCODE_0			11
    5.17 -
    5.18 -#define SCANCODE_MINUS			12
    5.19 -#define SCANCODE_EQUAL			13
    5.20 -
    5.21 -#define SCANCODE_BACKSPACE		14
    5.22 -#define SCANCODE_TAB			15
    5.23 -
    5.24 -#define SCANCODE_Q			16
    5.25 -#define SCANCODE_W			17
    5.26 -#define SCANCODE_E			18
    5.27 -#define SCANCODE_R			19
    5.28 -#define SCANCODE_T			20
    5.29 -#define SCANCODE_Y			21
    5.30 -#define SCANCODE_U			22
    5.31 -#define SCANCODE_I			23
    5.32 -#define SCANCODE_O			24
    5.33 -#define SCANCODE_P			25
    5.34 -#define SCANCODE_BRACKET_LEFT		26
    5.35 -#define SCANCODE_BRACKET_RIGHT		27
    5.36 -
    5.37 -#define SCANCODE_ENTER			28
    5.38 -
    5.39 -#define SCANCODE_LEFTCONTROL		29
    5.40 -
    5.41 -#define SCANCODE_A			30
    5.42 -#define SCANCODE_S			31
    5.43 -#define SCANCODE_D			32
    5.44 -#define SCANCODE_F			33
    5.45 -#define SCANCODE_G			34
    5.46 -#define SCANCODE_H			35
    5.47 -#define SCANCODE_J			36
    5.48 -#define SCANCODE_K			37
    5.49 -#define SCANCODE_L			38
    5.50 -#define SCANCODE_SEMICOLON		39
    5.51 -#define SCANCODE_APOSTROPHE		40
    5.52 -#define SCANCODE_GRAVE			41
    5.53 -
    5.54 -#define SCANCODE_LEFTSHIFT		42
    5.55 -#define SCANCODE_BACKSLASH		43
    5.56 -
    5.57 -#define SCANCODE_Z			44
    5.58 -#define SCANCODE_X			45
    5.59 -#define SCANCODE_C			46
    5.60 -#define SCANCODE_V			47
    5.61 -#define SCANCODE_B			48
    5.62 -#define SCANCODE_N			49
    5.63 -#define SCANCODE_M			50
    5.64 -#define SCANCODE_COMMA			51
    5.65 -#define SCANCODE_PERIOD			52
    5.66 -#define SCANCODE_SLASH			53
    5.67 -
    5.68 -#define SCANCODE_RIGHTSHIFT		54
    5.69 -#define SCANCODE_KEYPADMULTIPLY		55
    5.70 -
    5.71 -#define SCANCODE_LEFTALT		56
    5.72 -#define SCANCODE_SPACE			57
    5.73 -#define SCANCODE_CAPSLOCK		58
    5.74 -
    5.75 -#define SCANCODE_F1			59
    5.76 -#define SCANCODE_F2			60
    5.77 -#define SCANCODE_F3			61
    5.78 -#define SCANCODE_F4			62
    5.79 -#define SCANCODE_F5			63
    5.80 -#define SCANCODE_F6			64
    5.81 -#define SCANCODE_F7			65
    5.82 -#define SCANCODE_F8			66
    5.83 -#define SCANCODE_F9			67
    5.84 -#define SCANCODE_F10			68
    5.85 -
    5.86 -#define SCANCODE_NUMLOCK		69
    5.87 -#define SCANCODE_SCROLLLOCK		70
    5.88 -
    5.89 -#define SCANCODE_KEYPAD7		71
    5.90 -#define SCANCODE_CURSORUPLEFT		71
    5.91 -#define SCANCODE_KEYPAD8		72
    5.92 -#define SCANCODE_CURSORUP		72
    5.93 -#define SCANCODE_KEYPAD9		73
    5.94 -#define SCANCODE_CURSORUPRIGHT		73
    5.95 -#define SCANCODE_KEYPADMINUS		74
    5.96 -#define SCANCODE_KEYPAD4		75
    5.97 -#define SCANCODE_CURSORLEFT		75
    5.98 -#define SCANCODE_KEYPAD5		76
    5.99 -#define SCANCODE_KEYPAD6		77
   5.100 -#define SCANCODE_CURSORRIGHT		77
   5.101 -#define SCANCODE_KEYPADPLUS		78
   5.102 -#define SCANCODE_KEYPAD1		79
   5.103 -#define SCANCODE_CURSORDOWNLEFT		79
   5.104 -#define SCANCODE_KEYPAD2		80
   5.105 -#define SCANCODE_CURSORDOWN		80
   5.106 -#define SCANCODE_KEYPAD3		81
   5.107 -#define SCANCODE_CURSORDOWNRIGHT	81
   5.108 -#define SCANCODE_KEYPAD0		82
   5.109 -#define SCANCODE_KEYPADPERIOD		83
   5.110 -
   5.111 -#define SCANCODE_LESS			86
   5.112 -
   5.113 -#define SCANCODE_F11			87
   5.114 -#define SCANCODE_F12			88
   5.115 -
   5.116 -#define SCANCODE_KEYPADENTER		96
   5.117 -#define SCANCODE_RIGHTCONTROL		97
   5.118 -#define SCANCODE_CONTROL		97
   5.119 -#define SCANCODE_KEYPADDIVIDE		98
   5.120 -#define SCANCODE_PRINTSCREEN		99
   5.121 -#define SCANCODE_RIGHTALT		100
   5.122 -#define SCANCODE_BREAK			101     /* Beware: is 119     */
   5.123 -#define SCANCODE_BREAK_ALTERNATIVE	119     /* on some keyboards! */
   5.124 -
   5.125 -#define SCANCODE_HOME			102
   5.126 -#define SCANCODE_CURSORBLOCKUP		90      /* Cursor key block */
   5.127 -#define SCANCODE_PAGEUP			104
   5.128 -#define SCANCODE_CURSORBLOCKLEFT	92      /* Cursor key block */
   5.129 -#define SCANCODE_CURSORBLOCKRIGHT	94      /* Cursor key block */
   5.130 -#define SCANCODE_END			107
   5.131 -#define SCANCODE_CURSORBLOCKDOWN	108     /* Cursor key block */
   5.132 -#define SCANCODE_PAGEDOWN		109
   5.133 -#define SCANCODE_INSERT			110
   5.134 -#define SCANCODE_REMOVE			111
   5.135 -
   5.136 -#define SCANCODE_RIGHTWIN		126
   5.137 -#define SCANCODE_LEFTWIN		125
   5.138 -/* vi: set ts=4 sw=4 expandtab: */
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/video/directfb/SDL_DirectFB_mouse.c	Sat Aug 11 21:51:19 2007 +0000
     6.3 @@ -0,0 +1,212 @@
     6.4 +/*
     6.5 +    SDL - Simple DirectMedia Layer
     6.6 +    Copyright (C) 1997-2006 Sam Lantinga
     6.7 +
     6.8 +    This library is free software; you can redistribute it and/or
     6.9 +    modify it under the terms of the GNU Lesser General Public
    6.10 +    License as published by the Free Software Foundation; either
    6.11 +    version 2.1 of the License, or (at your option) any later version.
    6.12 +
    6.13 +    This library is distributed in the hope that it will be useful,
    6.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    6.16 +    Lesser General Public License for more details.
    6.17 +
    6.18 +    You should have received a copy of the GNU Lesser General Public
    6.19 +    License along with this library; if not, write to the Free Software
    6.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    6.21 +
    6.22 +    Sam Lantinga
    6.23 +    slouken@libsdl.org
    6.24 +*/
    6.25 +#include "SDL_config.h"
    6.26 +
    6.27 +#include "SDL_DirectFB_video.h"
    6.28 +#include "SDL_DirectFB_mouse.h"
    6.29 +
    6.30 +#include "../SDL_sysvideo.h"
    6.31 +#include "../../events/SDL_mouse_c.h"
    6.32 +
    6.33 +static SDL_Cursor *DirectFB_CreateCursor(SDL_Surface * surface, int hot_x,
    6.34 +                                         int hot_y);
    6.35 +static int DirectFB_ShowCursor(SDL_Cursor * cursor);
    6.36 +static void DirectFB_MoveCursor(SDL_Cursor * cursor);
    6.37 +static void DirectFB_FreeCursor(SDL_Cursor * cursor);
    6.38 +static void DirectFB_WarpMouse(SDL_Mouse * mouse, SDL_WindowID windowID,
    6.39 +                               int x, int y);
    6.40 +static void DirectFB_FreeMouse(SDL_Mouse * mouse);
    6.41 +
    6.42 +void
    6.43 +DirectFB_InitMouse(_THIS)
    6.44 +{
    6.45 +    SDL_DFB_DEVICEDATA(_this);
    6.46 +    SDL_Mouse mouse;
    6.47 +
    6.48 +    SDL_zero(mouse);
    6.49 +    mouse.CreateCursor = DirectFB_CreateCursor;
    6.50 +    mouse.ShowCursor = DirectFB_ShowCursor;
    6.51 +    mouse.MoveCursor = DirectFB_MoveCursor;
    6.52 +    mouse.FreeCursor = DirectFB_FreeCursor;
    6.53 +    mouse.WarpMouse = DirectFB_WarpMouse;
    6.54 +    mouse.FreeMouse = DirectFB_FreeMouse;
    6.55 +    devdata->mouse = SDL_AddMouse(&mouse, -1);
    6.56 +}
    6.57 +
    6.58 +void
    6.59 +DirectFB_QuitMouse(_THIS)
    6.60 +{
    6.61 +    SDL_DFB_DEVICEDATA(_this);
    6.62 +
    6.63 +    SDL_DelMouse(devdata->mouse);
    6.64 +}
    6.65 +
    6.66 +/* Create a cursor from a surface */
    6.67 +static SDL_Cursor *
    6.68 +DirectFB_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
    6.69 +{
    6.70 +    SDL_VideoDevice *dev = SDL_GetVideoDevice();
    6.71 +
    6.72 +    SDL_DFB_DEVICEDATA(dev);
    6.73 +    DFB_CursorData *curdata;
    6.74 +    DFBResult ret;
    6.75 +    DFBSurfaceDescription dsc;
    6.76 +    SDL_Cursor *cursor;
    6.77 +    Uint32 *dest;
    6.78 +    Uint32 *p;
    6.79 +    int pitch, i;
    6.80 +
    6.81 +    SDL_DFB_CALLOC(cursor, 1, sizeof(*cursor));
    6.82 +    SDL_DFB_CALLOC(curdata, 1, sizeof(*curdata));
    6.83 +
    6.84 +    dsc.flags =
    6.85 +        DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS;
    6.86 +    dsc.caps = DSCAPS_NONE;     //DSCAPS_SYSTEMONLY;
    6.87 +    dsc.width = surface->w;
    6.88 +    dsc.height = surface->h;
    6.89 +    dsc.pixelformat = DSPF_ARGB;
    6.90 +
    6.91 +    SDL_DFB_CHECKERR(devdata->dfb->
    6.92 +                     CreateSurface(devdata->dfb, &dsc, &curdata->surf));
    6.93 +    curdata->hotx = hot_x;
    6.94 +    curdata->hoty = hot_y;
    6.95 +    cursor->driverdata = curdata;
    6.96 +
    6.97 +    SDL_DFB_CHECKERR(curdata->surf->
    6.98 +                     Lock(curdata->surf, DSLF_WRITE, (void *) &dest, &pitch));
    6.99 +
   6.100 +    //FIXME: Implies a lot of things, e.g. rgba format for SDL_SURFACE ....
   6.101 +    p = surface->pixels;
   6.102 +    for (i = 0; i < surface->w * surface->h; i++)
   6.103 +        if (p[i] == 0x00000000)
   6.104 +            dest[i] = 0x00000000;
   6.105 +        else
   6.106 +            dest[i] = p[i];
   6.107 +    //memcpy(dest, surface->pixels, surface->w * surface->h * 4);
   6.108 +    curdata->surf->Unlock(curdata->surf);
   6.109 +    return cursor;
   6.110 +  error:
   6.111 +    return NULL;
   6.112 +}
   6.113 +
   6.114 +/* Show the specified cursor, or hide if cursor is NULL */
   6.115 +static int
   6.116 +DirectFB_ShowCursor(SDL_Cursor * cursor)
   6.117 +{
   6.118 +    SDL_DFB_CURSORDATA(cursor);
   6.119 +    SDL_VideoDevice *dev = SDL_GetVideoDevice();
   6.120 +    SDL_DFB_DEVICEDATA(dev);
   6.121 +#if 0
   6.122 +    DFB_DisplayData *dispdata =
   6.123 +        (DFB_DisplayData *) dev->displays[dev->current_display].driverdata;
   6.124 +#endif
   6.125 +    DFBResult ret;
   6.126 +    SDL_WindowID wid;
   6.127 +
   6.128 +    wid = SDL_GetFocusWindow();
   6.129 +    if (!wid)
   6.130 +        return -1;
   6.131 +    else {
   6.132 +        SDL_Window *window = SDL_GetWindowFromID(wid);
   6.133 +        SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   6.134 +        DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
   6.135 +        DFB_WindowData *windata = (DFB_WindowData *) window->driverdata;
   6.136 +        SDL_DFB_CHECKERR(windata->window->
   6.137 +                         SetCursorShape(windata->window, curdata->surf,
   6.138 +                                        curdata->hotx, curdata->hoty));
   6.139 +        //FIXME: This is somehow a directfb issue
   6.140 +        SDL_DFB_CHECKERR(dispdata->layer->
   6.141 +                         SetCooperativeLevel(dispdata->layer,
   6.142 +                                             DLSCL_ADMINISTRATIVE));
   6.143 +        SDL_DFB_CHECKERR(dispdata->layer->
   6.144 +                         SetCursorOpacity(dispdata->layer, 0xC0));
   6.145 +        SDL_DFB_CHECKERR(dispdata->layer->
   6.146 +                         SetCooperativeLevel(dispdata->layer, DLSCL_SHARED));
   6.147 +    }
   6.148 +#if 0
   6.149 +    //TODO: Check administrative 
   6.150 +    SDL_DFB_CHECKERR(dispdata->layer->
   6.151 +                     SetCooperativeLevel(dispdata->layer,
   6.152 +                                         DLSCL_ADMINISTRATIVE));
   6.153 +    SDL_DFB_CHECKERR(dispdata->layer->
   6.154 +                     SetCursorShape(dispdata->layer, curdata->surf,
   6.155 +                                    curdata->hotx, curdata->hoty));
   6.156 +    SDL_DFB_CHECKERR(dispdata->layer->
   6.157 +                     SetCursorOpacity(dispdata->layer, 0xC0));
   6.158 +    SDL_DFB_CHECKERR(dispdata->layer->
   6.159 +                     SetCooperativeLevel(dispdata->layer, DLSCL_SHARED));
   6.160 +
   6.161 +#endif
   6.162 +
   6.163 +    return 0;
   6.164 +  error:
   6.165 +    return -1;
   6.166 +}
   6.167 +
   6.168 +/* This is called when a mouse motion event occurs */
   6.169 +static void
   6.170 +DirectFB_MoveCursor(SDL_Cursor * cursor)
   6.171 +{
   6.172 +    SDL_DFB_CURSORDATA(cursor);
   6.173 +    /* Do we need to do something here ? */
   6.174 +}
   6.175 +
   6.176 +/* Free a window manager cursor */
   6.177 +static void
   6.178 +DirectFB_FreeCursor(SDL_Cursor * cursor)
   6.179 +{
   6.180 +    SDL_DFB_CURSORDATA(cursor);
   6.181 +
   6.182 +    SDL_DFB_RELEASE(curdata->surf);
   6.183 +    SDL_DFB_FREE(cursor->driverdata);
   6.184 +    SDL_DFB_FREE(cursor);
   6.185 +}
   6.186 +
   6.187 +/* Warp the mouse to (x,y) */
   6.188 +static void
   6.189 +DirectFB_WarpMouse(SDL_Mouse * mouse, SDL_WindowID windowID, int x, int y)
   6.190 +{
   6.191 +//      SDL_DFB_CURSORDATA(cursor);     
   6.192 +    SDL_Window *window = SDL_GetWindowFromID(windowID);
   6.193 +    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   6.194 +    DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
   6.195 +    DFB_WindowData *windata = (DFB_WindowData *) window->driverdata;
   6.196 +    DFBResult ret;
   6.197 +    int cx, cy;
   6.198 +
   6.199 +    SDL_DFB_CHECKERR(windata->window->GetPosition(windata->window, &cx, &cy));
   6.200 +    SDL_DFB_CHECKERR(dispdata->layer->
   6.201 +                     WarpCursor(dispdata->layer, cx + x, cy + y));
   6.202 +
   6.203 +  error:
   6.204 +    return;
   6.205 +}
   6.206 +
   6.207 +/* Free the mouse when it's time */
   6.208 +static void
   6.209 +DirectFB_FreeMouse(SDL_Mouse * mouse)
   6.210 +{
   6.211 +    // nothing yet  
   6.212 +
   6.213 +}
   6.214 +
   6.215 +/* vi: set ts=4 sw=4 expandtab: */
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/video/directfb/SDL_DirectFB_mouse.h	Sat Aug 11 21:51:19 2007 +0000
     7.3 @@ -0,0 +1,43 @@
     7.4 +/*
     7.5 +    SDL - Simple DirectMedia Layer
     7.6 +    Copyright (C) 1997-2006 Sam Lantinga
     7.7 +
     7.8 +    This library is free software; you can redistribute it and/or
     7.9 +    modify it under the terms of the GNU Lesser General Public
    7.10 +    License as published by the Free Software Foundation; either
    7.11 +    version 2.1 of the License, or (at your option) any later version.
    7.12 +
    7.13 +    This library is distributed in the hope that it will be useful,
    7.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    7.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    7.16 +    Lesser General Public License for more details.
    7.17 +
    7.18 +    You should have received a copy of the GNU Lesser General Public
    7.19 +    License along with this library; if not, write to the Free Software
    7.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    7.21 +
    7.22 +    Sam Lantinga
    7.23 +    slouken@libsdl.org
    7.24 +*/
    7.25 +#include "SDL_config.h"
    7.26 +
    7.27 +#ifndef _SDL_DirectFB_mouse_h
    7.28 +#define _SDL_DirectFB_mouse_h
    7.29 +
    7.30 +typedef struct _DFB_CursorData DFB_CursorData;
    7.31 +
    7.32 +struct _DFB_CursorData
    7.33 +{
    7.34 +    IDirectFBSurface *surf;
    7.35 +    int hotx;
    7.36 +    int hoty;
    7.37 +};
    7.38 +
    7.39 +#define SDL_DFB_CURSORDATA(curs)  DFB_CursorData *curdata = (DFB_CursorData *) ((curs)->driverdata)
    7.40 +
    7.41 +extern void DirectFB_InitMouse(_THIS);
    7.42 +extern void DirectFB_QuitMouse(_THIS);
    7.43 +
    7.44 +#endif /* _SDL_DirectFB_mouse_h */
    7.45 +
    7.46 +/* vi: set ts=4 sw=4 expandtab: */
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/video/directfb/SDL_DirectFB_render.c	Sat Aug 11 21:51:19 2007 +0000
     8.3 @@ -0,0 +1,737 @@
     8.4 +/*
     8.5 +    SDL - Simple DirectMedia Layer
     8.6 +    Copyright (C) 1997-2006 Sam Lantinga
     8.7 +
     8.8 +    This library is free software; you can redistribute it and/or
     8.9 +    modify it under the terms of the GNU Lesser General Public
    8.10 +    License as published by the Free Software Foundation; either
    8.11 +    version 2.1 of the License, or (at your option) any later version.
    8.12 +
    8.13 +    This library is distributed in the hope that it will be useful,
    8.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    8.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    8.16 +    Lesser General Public License for more details.
    8.17 +
    8.18 +    You should have received a copy of the GNU Lesser General Public
    8.19 +    License along with this library; if not, write to the Free Software
    8.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    8.21 +
    8.22 +    Sam Lantinga
    8.23 +    slouken@libsdl.org
    8.24 +    
    8.25 +    SDL1.3 implementation by couriersud@arcor.de
    8.26 +    
    8.27 +*/
    8.28 +#include "SDL_config.h"
    8.29 +
    8.30 +#include "SDL_DirectFB_video.h"
    8.31 +#include "SDL_DirectFB_render.h"
    8.32 +#include "../SDL_rect_c.h"
    8.33 +#include "../SDL_yuv_sw_c.h"
    8.34 +
    8.35 +/* GDI renderer implementation */
    8.36 +
    8.37 +static SDL_Renderer *DirectFB_CreateRenderer(SDL_Window * window,
    8.38 +                                             Uint32 flags);
    8.39 +static int DirectFB_DisplayModeChanged(SDL_Renderer * renderer);
    8.40 +static int DirectFB_CreateTexture(SDL_Renderer * renderer,
    8.41 +                                  SDL_Texture * texture);
    8.42 +static int DirectFB_QueryTexturePixels(SDL_Renderer * renderer,
    8.43 +                                       SDL_Texture * texture, void **pixels,
    8.44 +                                       int *pitch);
    8.45 +static int DirectFB_SetTexturePalette(SDL_Renderer * renderer,
    8.46 +                                      SDL_Texture * texture,
    8.47 +                                      const SDL_Color * colors,
    8.48 +                                      int firstcolor, int ncolors);
    8.49 +static int DirectFB_GetTexturePalette(SDL_Renderer * renderer,
    8.50 +                                      SDL_Texture * texture,
    8.51 +                                      SDL_Color * colors, int firstcolor,
    8.52 +                                      int ncolors);
    8.53 +static int DirectFB_SetTextureAlphaMod(SDL_Renderer * renderer,
    8.54 +                                       SDL_Texture * texture);
    8.55 +static int DirectFB_SetTextureColorMod(SDL_Renderer * renderer,
    8.56 +                                       SDL_Texture * texture);
    8.57 +static int DirectFB_SetTextureBlendMode(SDL_Renderer * renderer,
    8.58 +                                        SDL_Texture * texture);
    8.59 +static int DirectFB_SetTextureScaleMode(SDL_Renderer * renderer,
    8.60 +                                        SDL_Texture * texture);
    8.61 +static int DirectFB_UpdateTexture(SDL_Renderer * renderer,
    8.62 +                                  SDL_Texture * texture,
    8.63 +                                  const SDL_Rect * rect, const void *pixels,
    8.64 +                                  int pitch);
    8.65 +static int DirectFB_LockTexture(SDL_Renderer * renderer,
    8.66 +                                SDL_Texture * texture, const SDL_Rect * rect,
    8.67 +                                int markDirty, void **pixels, int *pitch);
    8.68 +static void DirectFB_UnlockTexture(SDL_Renderer * renderer,
    8.69 +                                   SDL_Texture * texture);
    8.70 +static void DirectFB_DirtyTexture(SDL_Renderer * renderer,
    8.71 +                                  SDL_Texture * texture, int numrects,
    8.72 +                                  const SDL_Rect * rects);
    8.73 +static int DirectFB_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g,
    8.74 +                               Uint8 b, Uint8 a, const SDL_Rect * rect);
    8.75 +static int DirectFB_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
    8.76 +                               const SDL_Rect * srcrect,
    8.77 +                               const SDL_Rect * dstrect);
    8.78 +static void DirectFB_RenderPresent(SDL_Renderer * renderer);
    8.79 +static void DirectFB_DestroyTexture(SDL_Renderer * renderer,
    8.80 +                                    SDL_Texture * texture);
    8.81 +static void DirectFB_DestroyRenderer(SDL_Renderer * renderer);
    8.82 +
    8.83 +SDL_RenderDriver DirectFB_RenderDriver = {
    8.84 +    DirectFB_CreateRenderer,
    8.85 +    {
    8.86 +     "directfb",
    8.87 +     (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY |
    8.88 +      SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 |
    8.89 +      SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_ACCELERATED),
    8.90 +     (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR |
    8.91 +      SDL_TEXTUREMODULATE_ALPHA),
    8.92 +     (SDL_TEXTUREBLENDMODE_NONE | SDL_TEXTUREBLENDMODE_MASK |
    8.93 +      SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_MOD),
    8.94 +     (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST),
    8.95 +     14,
    8.96 +     {
    8.97 +      SDL_PIXELFORMAT_INDEX8,
    8.98 +      SDL_PIXELFORMAT_INDEX4LSB,
    8.99 +      SDL_PIXELFORMAT_RGB332,
   8.100 +      SDL_PIXELFORMAT_RGB555,
   8.101 +      SDL_PIXELFORMAT_RGB565,
   8.102 +      SDL_PIXELFORMAT_RGB888,
   8.103 +      SDL_PIXELFORMAT_ARGB8888,
   8.104 +      SDL_PIXELFORMAT_ARGB4444,
   8.105 +      SDL_PIXELFORMAT_ARGB1555,
   8.106 +      SDL_PIXELFORMAT_RGB24,
   8.107 +      SDL_PIXELFORMAT_YV12,
   8.108 +      SDL_PIXELFORMAT_IYUV,
   8.109 +      SDL_PIXELFORMAT_YUY2,
   8.110 +      SDL_PIXELFORMAT_UYVY},
   8.111 +     0,
   8.112 +     0}
   8.113 +};
   8.114 +
   8.115 +typedef struct
   8.116 +{
   8.117 +    IDirectFBSurface *surface;
   8.118 +    DFBSurfaceFlipFlags flipflags;
   8.119 +    int isyuvdirect;
   8.120 +} DirectFB_RenderData;
   8.121 +
   8.122 +typedef struct
   8.123 +{
   8.124 +    IDirectFBDisplayLayer *vidlayer;
   8.125 +    IDirectFBSurface *surface;
   8.126 +    Uint32 format;
   8.127 +    void *pixels;
   8.128 +    int pitch;
   8.129 +    IDirectFBPalette *palette;
   8.130 +} DirectFB_TextureData;
   8.131 +
   8.132 +static void
   8.133 +UpdateYUVTextureData(SDL_Texture * texture)
   8.134 +{
   8.135 +    /*
   8.136 +     * Not needed - directfb supports yuv surfaces
   8.137 +     */
   8.138 +}
   8.139 +
   8.140 +void
   8.141 +DirectFB_AddRenderDriver(_THIS)
   8.142 +{
   8.143 +    int i;
   8.144 +    for (i = 0; i < _this->num_displays; i++)
   8.145 +        SDL_AddRenderDriver(i, &DirectFB_RenderDriver);
   8.146 +}
   8.147 +
   8.148 +SDL_Renderer *
   8.149 +DirectFB_CreateRenderer(SDL_Window * window, Uint32 flags)
   8.150 +{
   8.151 +    SDL_DFB_WINDOWDATA(window);
   8.152 +    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   8.153 +    SDL_DFB_DEVICEDATA(display->device);
   8.154 +    SDL_Renderer *renderer = NULL;
   8.155 +    DirectFB_RenderData *data = NULL;
   8.156 +    DFBResult ret;
   8.157 +    DFBSurfaceDescription dsc;
   8.158 +    DFBSurfaceCapabilities scaps;
   8.159 +    char *p;
   8.160 +    int i, n;
   8.161 +
   8.162 +    SDL_DFB_CALLOC(renderer, 1, sizeof(*renderer));
   8.163 +    SDL_DFB_CALLOC(data, 1, sizeof(*data));
   8.164 +
   8.165 +    renderer->DisplayModeChanged = DirectFB_DisplayModeChanged;
   8.166 +    renderer->CreateTexture = DirectFB_CreateTexture;
   8.167 +    renderer->QueryTexturePixels = DirectFB_QueryTexturePixels;
   8.168 +    renderer->SetTexturePalette = DirectFB_SetTexturePalette;
   8.169 +    renderer->GetTexturePalette = DirectFB_GetTexturePalette;
   8.170 +    renderer->SetTextureAlphaMod = DirectFB_SetTextureAlphaMod;
   8.171 +    renderer->SetTextureColorMod = DirectFB_SetTextureColorMod;
   8.172 +    renderer->SetTextureBlendMode = DirectFB_SetTextureBlendMode;
   8.173 +    renderer->SetTextureScaleMode = DirectFB_SetTextureScaleMode;
   8.174 +    renderer->UpdateTexture = DirectFB_UpdateTexture;
   8.175 +    renderer->LockTexture = DirectFB_LockTexture;
   8.176 +    renderer->UnlockTexture = DirectFB_UnlockTexture;
   8.177 +    renderer->DirtyTexture = DirectFB_DirtyTexture;
   8.178 +    renderer->RenderFill = DirectFB_RenderFill;
   8.179 +    renderer->RenderCopy = DirectFB_RenderCopy;
   8.180 +    renderer->RenderPresent = DirectFB_RenderPresent;
   8.181 +    renderer->DestroyTexture = DirectFB_DestroyTexture;
   8.182 +    renderer->DestroyRenderer = DirectFB_DestroyRenderer;
   8.183 +    renderer->info = DirectFB_RenderDriver.info;
   8.184 +    renderer->window = window->id;      // SDL window id
   8.185 +    renderer->driverdata = data;
   8.186 +
   8.187 +    renderer->info.flags =
   8.188 +        SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTDISCARD;
   8.189 +
   8.190 +    data->surface = windata->surface;
   8.191 +    data->flipflags = 0;
   8.192 +
   8.193 +    if (flags & SDL_RENDERER_PRESENTVSYNC) {
   8.194 +        data->flipflags = DSFLIP_ONSYNC;
   8.195 +        renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
   8.196 +    }
   8.197 +
   8.198 +    data->surface->GetCapabilities(data->surface, &scaps);
   8.199 +    if (scaps & DSCAPS_DOUBLE)
   8.200 +        renderer->info.flags |= SDL_RENDERER_PRESENTFLIP2;
   8.201 +    else if (scaps & DSCAPS_TRIPLE)
   8.202 +        renderer->info.flags |= SDL_RENDERER_PRESENTFLIP3;
   8.203 +    else
   8.204 +        renderer->info.flags |= SDL_RENDERER_SINGLEBUFFER;
   8.205 +
   8.206 +    data->isyuvdirect = 0;
   8.207 +    p = getenv("SDL_DIRECTFB_YUV_DIRECT");
   8.208 +    if (p)
   8.209 +        data->isyuvdirect = atoi(p);
   8.210 +
   8.211 +    return renderer;
   8.212 +
   8.213 +  error:
   8.214 +    SDL_DFB_FREE(renderer);
   8.215 +    SDL_DFB_FREE(data);
   8.216 +    return NULL;
   8.217 +}
   8.218 +
   8.219 +static DFBSurfacePixelFormat
   8.220 +SDLToDFBPixelFormat(Uint32 format)
   8.221 +{
   8.222 +    switch (format) {
   8.223 +    case SDL_PIXELFORMAT_INDEX4LSB:
   8.224 +        return DSPF_ALUT44;
   8.225 +    case SDL_PIXELFORMAT_INDEX8:
   8.226 +        return DSPF_LUT8;
   8.227 +    case SDL_PIXELFORMAT_RGB332:
   8.228 +        return DSPF_RGB332;
   8.229 +    case SDL_PIXELFORMAT_RGB555:
   8.230 +        return DSPF_ARGB1555;
   8.231 +    case SDL_PIXELFORMAT_ARGB4444:
   8.232 +        return DSPF_ARGB4444;
   8.233 +    case SDL_PIXELFORMAT_ARGB1555:
   8.234 +        return DSPF_ARGB1555;
   8.235 +    case SDL_PIXELFORMAT_RGB565:
   8.236 +        return DSPF_RGB16;
   8.237 +    case SDL_PIXELFORMAT_RGB24:
   8.238 +        return DSPF_RGB24;
   8.239 +    case SDL_PIXELFORMAT_RGB888:
   8.240 +        return DSPF_RGB32;
   8.241 +    case SDL_PIXELFORMAT_ARGB8888:
   8.242 +        return DSPF_ARGB;
   8.243 +    case SDL_PIXELFORMAT_YV12:
   8.244 +        return DSPF_YV12;       /* Planar mode: Y + V + U  (3 planes) */
   8.245 +    case SDL_PIXELFORMAT_IYUV:
   8.246 +        return DSPF_I420;       /* Planar mode: Y + U + V  (3 planes) */
   8.247 +    case SDL_PIXELFORMAT_YUY2:
   8.248 +        return DSPF_YUY2;       /* Packed mode: Y0+U0+Y1+V0 (1 plane) */
   8.249 +    case SDL_PIXELFORMAT_UYVY:
   8.250 +        return DSPF_UYVY;       /* Packed mode: U0+Y0+V0+Y1 (1 plane) */
   8.251 +    case SDL_PIXELFORMAT_YVYU:
   8.252 +        return DSPF_UNKNOWN;    /* Packed mode: Y0+V0+Y1+U0 (1 plane) */
   8.253 +    case SDL_PIXELFORMAT_INDEX1LSB:
   8.254 +        return DSPF_UNKNOWN;
   8.255 +    case SDL_PIXELFORMAT_INDEX1MSB:
   8.256 +        return DSPF_UNKNOWN;
   8.257 +    case SDL_PIXELFORMAT_INDEX4MSB:
   8.258 +        return DSPF_UNKNOWN;
   8.259 +    case SDL_PIXELFORMAT_RGB444:
   8.260 +        return DSPF_UNKNOWN;
   8.261 +    case SDL_PIXELFORMAT_BGR24:
   8.262 +        return DSPF_UNKNOWN;
   8.263 +    case SDL_PIXELFORMAT_BGR888:
   8.264 +        return DSPF_UNKNOWN;
   8.265 +    case SDL_PIXELFORMAT_RGBA8888:
   8.266 +        return DSPF_UNKNOWN;
   8.267 +    case SDL_PIXELFORMAT_ABGR8888:
   8.268 +        return DSPF_UNKNOWN;
   8.269 +    case SDL_PIXELFORMAT_BGRA8888:
   8.270 +        return DSPF_UNKNOWN;
   8.271 +    case SDL_PIXELFORMAT_ARGB2101010:
   8.272 +        return DSPF_UNKNOWN;
   8.273 +    default:
   8.274 +        return DSPF_UNKNOWN;
   8.275 +    }
   8.276 +}
   8.277 +
   8.278 +static int
   8.279 +DirectFB_DisplayModeChanged(SDL_Renderer * renderer)
   8.280 +{
   8.281 +    SDL_DFB_RENDERERDATA(renderer);
   8.282 +    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   8.283 +    SDL_DFB_WINDOWDATA(window);
   8.284 +    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   8.285 +    SDL_DFB_DEVICEDATA(display->device);
   8.286 +    DFBResult ret;
   8.287 +    DFBSurfaceDescription dsc;
   8.288 +    int i, n;
   8.289 +
   8.290 +    /*
   8.291 +     * Nothing to do here
   8.292 +     */
   8.293 +    return 0;
   8.294 +  error:
   8.295 +    return -1;
   8.296 +}
   8.297 +
   8.298 +static int
   8.299 +DirectFB_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   8.300 +{
   8.301 +    SDL_DFB_RENDERERDATA(renderer);
   8.302 +    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   8.303 +    SDL_DFB_WINDOWDATA(window);
   8.304 +    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   8.305 +    SDL_DFB_DEVICEDATA(display->device);
   8.306 +    DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
   8.307 +    DirectFB_TextureData *data;
   8.308 +    DFBResult ret;
   8.309 +    DFBSurfaceDescription dsc;
   8.310 +    DFBDisplayLayerDescription laydsc;
   8.311 +    DFBDisplayLayerConfig layconf;
   8.312 +
   8.313 +    SDL_DFB_CALLOC(data, 1, sizeof(*data));
   8.314 +    texture->driverdata = data;
   8.315 +
   8.316 +    data->format = texture->format;
   8.317 +    data->pitch = (texture->w * SDL_BYTESPERPIXEL(data->format));
   8.318 +    data->vidlayer = NULL;
   8.319 +    if (renddata->isyuvdirect && (dispdata->vidID >= 0)
   8.320 +        && SDL_ISPIXELFORMAT_FOURCC(data->format)) {
   8.321 +        SDL_DFB_CHECKERR(devdata->dfb->
   8.322 +                         GetDisplayLayer(devdata->dfb, dispdata->vidID,
   8.323 +                                         &data->vidlayer));
   8.324 +        layconf.flags = DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT;
   8.325 +        layconf.width = texture->w;
   8.326 +        layconf.height = texture->h;
   8.327 +        layconf.pixelformat = SDLToDFBPixelFormat(data->format);
   8.328 +
   8.329 +        SDL_DFB_CHECKERR(data->vidlayer->
   8.330 +                         SetCooperativeLevel(data->vidlayer,
   8.331 +                                             DLSCL_EXCLUSIVE));
   8.332 +        SDL_DFB_CHECKERR(data->vidlayer->
   8.333 +                         SetConfiguration(data->vidlayer, &layconf));
   8.334 +        SDL_DFB_CHECKERR(data->vidlayer->
   8.335 +                         GetSurface(data->vidlayer, &data->surface));
   8.336 +        SDL_DFB_CHECKERR(data->vidlayer->
   8.337 +                         GetDescription(data->vidlayer, &laydsc));
   8.338 +        SDL_DFB_DEBUG("Created HW YUV surface\n");
   8.339 +    }
   8.340 +    if (!data->vidlayer) {
   8.341 +        /* fill surface description */
   8.342 +        dsc.flags =
   8.343 +            DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS;
   8.344 +        dsc.width = texture->w;
   8.345 +        dsc.height = texture->h;
   8.346 +        /* Never use DSCAPS_VIDEOONLY here. It kills performance
   8.347 +         * No DSCAPS_SYSTEMONLY either - let dfb decide
   8.348 +         */
   8.349 +        dsc.caps = 0;           //DSCAPS_PREMULTIPLIED;
   8.350 +
   8.351 +        /* find the right pixelformat */
   8.352 +
   8.353 +        dsc.pixelformat = SDLToDFBPixelFormat(data->format);
   8.354 +        if (dsc.pixelformat == DSPF_UNKNOWN) {
   8.355 +            SDL_SetError("Unknown pixel format %d\n", data->format);
   8.356 +            goto error;
   8.357 +        }
   8.358 +
   8.359 +        data->pixels = NULL;
   8.360 +
   8.361 +        /* Create the surface */
   8.362 +        SDL_DFB_CHECKERR(devdata->dfb->
   8.363 +                         CreateSurface(devdata->dfb, &dsc, &data->surface));
   8.364 +        if (SDL_ISPIXELFORMAT_INDEXED(data->format)
   8.365 +            && !SDL_ISPIXELFORMAT_FOURCC(data->format)) {
   8.366 +            SDL_DFB_CHECKERR(data->surface->
   8.367 +                             GetPalette(data->surface, &data->palette));
   8.368 +        }
   8.369 +
   8.370 +    }
   8.371 +    return 0;
   8.372 +
   8.373 +  error:
   8.374 +    SDL_DFB_RELEASE(data->palette);
   8.375 +    SDL_DFB_RELEASE(data->surface);
   8.376 +    SDL_DFB_FREE(texture->driverdata);
   8.377 +    return -1;
   8.378 +}
   8.379 +
   8.380 +static int
   8.381 +DirectFB_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
   8.382 +                            void **pixels, int *pitch)
   8.383 +{
   8.384 +    DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
   8.385 +
   8.386 +    /*
   8.387 +     * Always fail here so in compat mode SDL_HWSURFACE is set !
   8.388 +     */
   8.389 +
   8.390 +    return -1;
   8.391 +}
   8.392 +
   8.393 +static int
   8.394 +DirectFB_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
   8.395 +                           const SDL_Color * colors, int firstcolor,
   8.396 +                           int ncolors)
   8.397 +{
   8.398 +    DirectFB_RenderData *renderdata =
   8.399 +        (DirectFB_RenderData *) renderer->driverdata;
   8.400 +    DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
   8.401 +    DFBResult ret;
   8.402 +
   8.403 +    if (SDL_ISPIXELFORMAT_INDEXED(data->format)
   8.404 +        && !SDL_ISPIXELFORMAT_FOURCC(data->format)) {
   8.405 +        DFBColor entries[256];
   8.406 +        int i;
   8.407 +
   8.408 +        for (i = 0; i < ncolors; ++i) {
   8.409 +            entries[i].r = colors[i].r;
   8.410 +            entries[i].g = colors[i].g;
   8.411 +            entries[i].b = colors[i].b;
   8.412 +            entries[i].a = 0xFF;
   8.413 +        }
   8.414 +        SDL_DFB_CHECKERR(data->palette->
   8.415 +                         SetEntries(data->palette, entries, ncolors,
   8.416 +                                    firstcolor));
   8.417 +        return 0;
   8.418 +    } else {
   8.419 +        SDL_SetError("YUV textures don't have a palette");
   8.420 +        return -1;
   8.421 +    }
   8.422 +  error:
   8.423 +    return -1;
   8.424 +}
   8.425 +
   8.426 +static int
   8.427 +DirectFB_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
   8.428 +                           SDL_Color * colors, int firstcolor, int ncolors)
   8.429 +{
   8.430 +    DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
   8.431 +    DFBResult ret;
   8.432 +
   8.433 +    if (SDL_ISPIXELFORMAT_INDEXED(data->format)
   8.434 +        && !SDL_ISPIXELFORMAT_FOURCC(data->format)) {
   8.435 +        DFBColor entries[256];
   8.436 +        int i;
   8.437 +
   8.438 +        SDL_DFB_CHECKERR(data->palette->
   8.439 +                         GetEntries(data->palette, entries, ncolors,
   8.440 +                                    firstcolor));
   8.441 +
   8.442 +        for (i = 0; i < ncolors; ++i) {
   8.443 +            colors[i].r = entries[i].r;
   8.444 +            colors[i].g = entries[i].g;
   8.445 +            colors[i].b = entries[i].b;
   8.446 +        }
   8.447 +        return 0;
   8.448 +    } else {
   8.449 +        SDL_SetError("YUV textures don't have a palette");
   8.450 +        return -1;
   8.451 +    }
   8.452 +  error:
   8.453 +    return -1;
   8.454 +}
   8.455 +
   8.456 +static int
   8.457 +DirectFB_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture)
   8.458 +{
   8.459 +    return 0;
   8.460 +}
   8.461 +
   8.462 +static int
   8.463 +DirectFB_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture)
   8.464 +{
   8.465 +    return 0;
   8.466 +}
   8.467 +
   8.468 +static int
   8.469 +DirectFB_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
   8.470 +{
   8.471 +    switch (texture->blendMode) {
   8.472 +    case SDL_TEXTUREBLENDMODE_NONE:
   8.473 +    case SDL_TEXTUREBLENDMODE_MASK:
   8.474 +    case SDL_TEXTUREBLENDMODE_BLEND:
   8.475 +    case SDL_TEXTUREBLENDMODE_MOD:
   8.476 +        return 0;
   8.477 +    default:
   8.478 +        SDL_Unsupported();
   8.479 +        texture->blendMode = SDL_TEXTUREBLENDMODE_NONE;
   8.480 +        return -1;
   8.481 +    }
   8.482 +}
   8.483 +
   8.484 +static int
   8.485 +DirectFB_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
   8.486 +{
   8.487 +    switch (texture->scaleMode) {
   8.488 +    case SDL_TEXTURESCALEMODE_NONE:
   8.489 +    case SDL_TEXTURESCALEMODE_FAST:
   8.490 +        return 0;
   8.491 +    case SDL_TEXTURESCALEMODE_SLOW:
   8.492 +    case SDL_TEXTURESCALEMODE_BEST:
   8.493 +        SDL_Unsupported();
   8.494 +        texture->scaleMode = SDL_TEXTURESCALEMODE_FAST;
   8.495 +        return -1;
   8.496 +    default:
   8.497 +        SDL_Unsupported();
   8.498 +        texture->scaleMode = SDL_TEXTURESCALEMODE_NONE;
   8.499 +        return -1;
   8.500 +    }
   8.501 +    return 0;
   8.502 +}
   8.503 +
   8.504 +static int
   8.505 +DirectFB_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   8.506 +                       const SDL_Rect * rect, const void *pixels, int pitch)
   8.507 +{
   8.508 +    DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
   8.509 +    DirectFB_RenderData *renderdata =
   8.510 +        (DirectFB_RenderData *) renderer->driverdata;
   8.511 +
   8.512 +    if (data->pixels) {
   8.513 +        Uint8 *src, *dst;
   8.514 +        int row;
   8.515 +        size_t length;
   8.516 +
   8.517 +        src = (Uint8 *) pixels;
   8.518 +        dst =
   8.519 +            (Uint8 *) data->pixels + rect->y * data->pitch +
   8.520 +            rect->x * SDL_BYTESPERPIXEL(texture->format);
   8.521 +        length = rect->w * SDL_BYTESPERPIXEL(texture->format);
   8.522 +        for (row = 0; row < rect->h; ++row) {
   8.523 +            SDL_memcpy(dst, src, length);
   8.524 +            src += pitch;
   8.525 +            dst += data->pitch;
   8.526 +        }
   8.527 +    } else {
   8.528 +        SDL_SetError("FIXME: Update without lock!\n");
   8.529 +        return -1;
   8.530 +    }
   8.531 +    return 0;
   8.532 +}
   8.533 +
   8.534 +static int
   8.535 +DirectFB_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   8.536 +                     const SDL_Rect * rect, int markDirty, void **pixels,
   8.537 +                     int *pitch)
   8.538 +{
   8.539 +    DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
   8.540 +    DFBResult ret;
   8.541 +    void *fdata;
   8.542 +    int fpitch;
   8.543 +
   8.544 +    SDL_DFB_CHECKERR(data->surface->Lock(data->surface,
   8.545 +                                         DSLF_WRITE | DSLF_READ, &fdata,
   8.546 +                                         &fpitch));
   8.547 +    data->pixels = fdata;
   8.548 +    data->pitch = fpitch;
   8.549 +
   8.550 +    switch (texture->format) {
   8.551 +    case SDL_PIXELFORMAT_YV12:
   8.552 +    case SDL_PIXELFORMAT_IYUV:
   8.553 +        if (rect
   8.554 +            && (rect->x != 0 || rect->y != 0 || rect->w != texture->w
   8.555 +                || rect->h != texture->h)) {
   8.556 +            SDL_SetError
   8.557 +                ("YV12 and IYUV textures only support full surface locks");
   8.558 +            return -1;
   8.559 +        }
   8.560 +        break;
   8.561 +    default:
   8.562 +        /* Only one plane, no worries */
   8.563 +        break;
   8.564 +    }
   8.565 +
   8.566 +    *pitch = data->pitch;
   8.567 +    *pixels = data->pixels;
   8.568 +
   8.569 +    return 0;
   8.570 +  error:
   8.571 +    return -1;
   8.572 +}
   8.573 +
   8.574 +static void
   8.575 +DirectFB_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   8.576 +{
   8.577 +    DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
   8.578 +
   8.579 +    data->surface->Unlock(data->surface);
   8.580 +    data->pixels = NULL;
   8.581 +}
   8.582 +
   8.583 +static void
   8.584 +DirectFB_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   8.585 +                      int numrects, const SDL_Rect * rects)
   8.586 +{
   8.587 +    //TODO: DirtyTexture
   8.588 +}
   8.589 +
   8.590 +static int
   8.591 +DirectFB_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b,
   8.592 +                    Uint8 a, const SDL_Rect * rect)
   8.593 +{
   8.594 +    DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
   8.595 +    DFBResult ret;
   8.596 +
   8.597 +    SDL_DFB_CHECKERR(data->surface->SetColor(data->surface, r, g, b, a));
   8.598 +    SDL_DFB_CHECKERR(data->surface->
   8.599 +                     FillRectangle(data->surface, rect->x, rect->y, rect->w,
   8.600 +                                   rect->h));
   8.601 +
   8.602 +    return 0;
   8.603 +  error:
   8.604 +    return -1;
   8.605 +}
   8.606 +
   8.607 +static int
   8.608 +DirectFB_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
   8.609 +                    const SDL_Rect * srcrect, const SDL_Rect * dstrect)
   8.610 +{
   8.611 +    DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
   8.612 +    DirectFB_TextureData *texturedata =
   8.613 +        (DirectFB_TextureData *) texture->driverdata;
   8.614 +    DFBResult ret;
   8.615 +
   8.616 +    if (texturedata->vidlayer) {
   8.617 +        int px, py;
   8.618 +        SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   8.619 +        SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   8.620 +        SDL_DFB_DEVICEDATA(display->device);
   8.621 +        DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
   8.622 +        SDL_DFB_WINDOWDATA(window);
   8.623 +
   8.624 +        SDL_DFB_CHECKERR(texturedata->vidlayer->
   8.625 +                         SetSourceRectangle(texturedata->vidlayer, srcrect->x,
   8.626 +                                            srcrect->y, srcrect->w,
   8.627 +                                            srcrect->h));
   8.628 +        windata->window->GetPosition(windata->window, &px, &py);
   8.629 +        SDL_DFB_CHECKERR(texturedata->vidlayer->
   8.630 +                         SetScreenRectangle(texturedata->vidlayer,
   8.631 +                                            px + dstrect->x, py + dstrect->y,
   8.632 +                                            dstrect->w, dstrect->h));
   8.633 +    } else {
   8.634 +        DFBRectangle sr, dr;
   8.635 +        DFBSurfaceBlittingFlags flags = 0;
   8.636 +
   8.637 +        sr.x = srcrect->x;
   8.638 +        sr.y = srcrect->y;
   8.639 +        sr.w = srcrect->w;
   8.640 +        sr.h = srcrect->h;
   8.641 +
   8.642 +        dr.x = dstrect->x;
   8.643 +        dr.y = dstrect->y;
   8.644 +        dr.w = dstrect->w;
   8.645 +        dr.h = dstrect->h;
   8.646 +
   8.647 +        if (texture->
   8.648 +            modMode & (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA))
   8.649 +        {
   8.650 +            u8 alpha = 0xFF;
   8.651 +            if (texture->modMode & SDL_TEXTUREMODULATE_ALPHA)
   8.652 +                alpha = texture->a;
   8.653 +            if (texture->modMode & SDL_TEXTUREMODULATE_COLOR)
   8.654 +                SDL_DFB_CHECKERR(data->surface->
   8.655 +                                 SetColor(data->surface, texture->r,
   8.656 +                                          texture->g, texture->b, alpha));
   8.657 +            else
   8.658 +                SDL_DFB_CHECKERR(data->surface->SetColor(data->surface, 0xFF,
   8.659 +                                                         0xFF, 0xFF, alpha));
   8.660 +            // Only works together ....
   8.661 +            flags |= DSBLIT_COLORIZE | DSBLIT_SRC_PREMULTCOLOR;
   8.662 +        }
   8.663 +
   8.664 +        if (texture->
   8.665 +            blendMode & (SDL_TEXTUREBLENDMODE_MASK |
   8.666 +                         SDL_TEXTUREBLENDMODE_BLEND)) {
   8.667 +            flags |= DSBLIT_BLEND_ALPHACHANNEL;
   8.668 +        } else {
   8.669 +            flags |= DSBLIT_NOFX;
   8.670 +        }
   8.671 +        SDL_DFB_CHECKERR(data->surface->
   8.672 +                         SetBlittingFlags(data->surface, flags));
   8.673 +        if (srcrect->w == dstrect->w && srcrect->h == dstrect->h) {
   8.674 +            SDL_DFB_CHECKERR(data->surface->
   8.675 +                             Blit(data->surface, texturedata->surface, &sr,
   8.676 +                                  dr.x, dr.y));
   8.677 +        } else {
   8.678 +            SDL_DFB_CHECKERR(data->surface->
   8.679 +                             StretchBlit(data->surface, texturedata->surface,
   8.680 +                                         &sr, &dr));
   8.681 +        }
   8.682 +    }
   8.683 +    return 0;
   8.684 +  error:
   8.685 +    return -1;
   8.686 +}
   8.687 +
   8.688 +static void
   8.689 +DirectFB_RenderPresent(SDL_Renderer * renderer)
   8.690 +{
   8.691 +    DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
   8.692 +    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   8.693 +
   8.694 +    SDL_DirtyRect *dirty;
   8.695 +    DFBRectangle sr;
   8.696 +    DFBResult ret;
   8.697 +
   8.698 +    sr.x = 0;
   8.699 +    sr.y = 0;
   8.700 +    sr.w = window->w;
   8.701 +    sr.h = window->h;
   8.702 +
   8.703 +    /* Send the data to the display */
   8.704 +    SDL_DFB_CHECKERR(data->surface->
   8.705 +                     Flip(data->surface, NULL, data->flipflags));
   8.706 +
   8.707 +    return;
   8.708 +  error:
   8.709 +    return;
   8.710 +}
   8.711 +
   8.712 +static void
   8.713 +DirectFB_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   8.714 +{
   8.715 +    DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
   8.716 +
   8.717 +    if (!data) {
   8.718 +        return;
   8.719 +    }
   8.720 +    SDL_DFB_RELEASE(data->palette);
   8.721 +    SDL_DFB_RELEASE(data->surface);
   8.722 +    SDL_DFB_RELEASE(data->vidlayer);
   8.723 +    SDL_free(data);
   8.724 +    texture->driverdata = NULL;
   8.725 +}
   8.726 +
   8.727 +static void
   8.728 +DirectFB_DestroyRenderer(SDL_Renderer * renderer)
   8.729 +{
   8.730 +    DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
   8.731 +    int i;
   8.732 +
   8.733 +    if (data) {
   8.734 +        data->surface = NULL;
   8.735 +        SDL_free(data);
   8.736 +    }
   8.737 +    SDL_free(renderer);
   8.738 +}
   8.739 +
   8.740 +/* vi: set ts=4 sw=4 expandtab: */
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/src/video/directfb/SDL_DirectFB_render.h	Sat Aug 11 21:51:19 2007 +0000
     9.3 @@ -0,0 +1,30 @@
     9.4 +/*
     9.5 +    SDL - Simple DirectMedia Layer
     9.6 +    Copyright (C) 1997-2006 Sam Lantinga
     9.7 +
     9.8 +    This library is free software; you can redistribute it and/or
     9.9 +    modify it under the terms of the GNU Lesser General Public
    9.10 +    License as published by the Free Software Foundation; either
    9.11 +    version 2.1 of the License, or (at your option) any later version.
    9.12 +
    9.13 +    This library is distributed in the hope that it will be useful,
    9.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    9.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    9.16 +    Lesser General Public License for more details.
    9.17 +
    9.18 +    You should have received a copy of the GNU Lesser General Public
    9.19 +    License along with this library; if not, write to the Free Software
    9.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    9.21 +
    9.22 +    Sam Lantinga
    9.23 +    slouken@libsdl.org
    9.24 +*/
    9.25 +#include "SDL_config.h"
    9.26 +
    9.27 +/* SDL surface based renderer implementation */
    9.28 +
    9.29 +#define SDL_DFB_RENDERERDATA(rend) DirectFB_RenderData *renddata = ((rend) ? (DirectFB_RenderData *) (rend)->driverdata : NULL)
    9.30 +
    9.31 +extern void DirectFB_AddRenderDriver(_THIS);
    9.32 +
    9.33 +/* vi: set ts=4 sw=4 expandtab: */
    10.1 --- a/src/video/directfb/SDL_DirectFB_video.c	Sat Aug 11 21:44:49 2007 +0000
    10.2 +++ b/src/video/directfb/SDL_DirectFB_video.c	Sat Aug 11 21:51:19 2007 +0000
    10.3 @@ -19,10 +19,16 @@
    10.4      Sam Lantinga
    10.5      slouken@libsdl.org
    10.6  
    10.7 -	MGA CRTC2 support by Thomas Jarosch - tomj@simonv.com
    10.8 -	CRTC2 support is inspired by mplayer's dfbmga driver
    10.9 -	written by Ville Syrj��<syrjala@sci.fi>
   10.10 +    SDL1.3 implementation by couriersud@arcor.de
   10.11 +	
   10.12  */
   10.13 +
   10.14 +/* TODO: Various
   10.15 + * Add Mouse support from 1.2 directfb driver
   10.16 + * - Interface is defined in SDL_Mouse.c.h
   10.17 + * - Default Cursor automatically created
   10.18 + */
   10.19 +
   10.20  #include "SDL_config.h"
   10.21  
   10.22  /* DirectFB video driver implementation.
   10.23 @@ -42,44 +48,6 @@
   10.24  #include "../../events/SDL_events_c.h"
   10.25  #include "SDL_DirectFB_video.h"
   10.26  #include "SDL_DirectFB_events.h"
   10.27 -#include "SDL_DirectFB_yuv.h"
   10.28 -
   10.29 -/* The implementation dependent data for the window manager cursor */
   10.30 -struct WMcursor
   10.31 -{
   10.32 -    int unused;
   10.33 -};
   10.34 -
   10.35 -
   10.36 -/* Initialization/Query functions */
   10.37 -static int DirectFB_VideoInit(_THIS, SDL_PixelFormat * vformat);
   10.38 -static SDL_Rect **DirectFB_ListModes(_THIS, SDL_PixelFormat * format,
   10.39 -                                     Uint32 flags);
   10.40 -static SDL_Surface *DirectFB_SetVideoMode(_THIS, SDL_Surface * current,
   10.41 -                                          int width, int height, int bpp,
   10.42 -                                          Uint32 flags);
   10.43 -static int DirectFB_SetColors(_THIS, int firstcolor, int ncolors,
   10.44 -                              SDL_Color * colors);
   10.45 -static void DirectFB_VideoQuit(_THIS);
   10.46 -
   10.47 -/* Hardware surface functions */
   10.48 -static int DirectFB_AllocHWSurface(_THIS, SDL_Surface * surface);
   10.49 -static int DirectFB_FillHWRect(_THIS, SDL_Surface * dst, SDL_Rect * dstrect,
   10.50 -                               Uint32 color);
   10.51 -static int DirectFB_LockHWSurface(_THIS, SDL_Surface * surface);
   10.52 -static void DirectFB_UnlockHWSurface(_THIS, SDL_Surface * surface);
   10.53 -static void DirectFB_FreeHWSurface(_THIS, SDL_Surface * surface);
   10.54 -static int DirectFB_CheckHWBlit(_THIS, SDL_Surface * src, SDL_Surface * dst);
   10.55 -static int DirectFB_HWAccelBlit(SDL_Surface * src, SDL_Rect * srcrect,
   10.56 -                                SDL_Surface * dst, SDL_Rect * dstrect);
   10.57 -static int DirectFB_SetHWColorKey(_THIS, SDL_Surface * surface, Uint32 key);
   10.58 -static int DirectFB_SetHWAlpha(_THIS, SDL_Surface * surface, Uint8 alpha);
   10.59 -static int DirectFB_FlipHWSurface(_THIS, SDL_Surface * surface);
   10.60 -static int DirectFB_ShowWMCursor(_THIS, WMcursor * cursor);
   10.61 -
   10.62 -/* Various screen update functions available */
   10.63 -static void DirectFB_DirectUpdate(_THIS, int numrects, SDL_Rect * rects);
   10.64 -static void DirectFB_WindowedUpdate(_THIS, int numrects, SDL_Rect * rects);
   10.65  
   10.66  /* This is the rect EnumModes2 uses */
   10.67  struct DirectFBEnumRect
   10.68 @@ -88,8 +56,51 @@
   10.69      struct DirectFBEnumRect *next;
   10.70  };
   10.71  
   10.72 -static struct DirectFBEnumRect *enumlist = NULL;
   10.73 +struct DirectFB_GLContext
   10.74 +{
   10.75 +    IDirectFBGL *context;
   10.76 +};
   10.77  
   10.78 +/* Initialization/Query functions */
   10.79 +static int DirectFB_VideoInit(_THIS);
   10.80 +static void DirectFB_VideoQuit(_THIS);
   10.81 +
   10.82 +static int DirectFB_CreateWindow(_THIS, SDL_Window * window);
   10.83 +static int DirectFB_CreateWindowFrom(_THIS, SDL_Window * window,
   10.84 +                                     const void *data);
   10.85 +static void DirectFB_SetWindowTitle(_THIS, SDL_Window * window);
   10.86 +static void DirectFB_SetWindowPosition(_THIS, SDL_Window * window);
   10.87 +static void DirectFB_SetWindowSize(_THIS, SDL_Window * window);
   10.88 +static void DirectFB_ShowWindow(_THIS, SDL_Window * window);
   10.89 +static void DirectFB_HideWindow(_THIS, SDL_Window * window);
   10.90 +static void DirectFB_RaiseWindow(_THIS, SDL_Window * window);
   10.91 +static void DirectFB_MaximizeWindow(_THIS, SDL_Window * window);
   10.92 +static void DirectFB_MinimizeWindow(_THIS, SDL_Window * window);
   10.93 +static void DirectFB_RestoreWindow(_THIS, SDL_Window * window);
   10.94 +static void DirectFB_SetWindowGrab(_THIS, SDL_Window * window);
   10.95 +static void DirectFB_DestroyWindow(_THIS, SDL_Window * window);
   10.96 +static SDL_bool DirectFB_GetWindowWMInfo(_THIS, SDL_Window * window,
   10.97 +                                         struct SDL_SysWMinfo *info);
   10.98 +
   10.99 +static void DirectFB_GetDisplayModes(_THIS);
  10.100 +static int DirectFB_SetDisplayMode(_THIS, SDL_DisplayMode * mode);
  10.101 +
  10.102 +static int DirectFB_SetDisplayGammaRamp(_THIS, Uint16 * ramp);
  10.103 +static int DirectFB_GetDisplayGammaRamp(_THIS, Uint16 * ramp);
  10.104 +
  10.105 +#if SDL_DIRECTFB_OPENGL
  10.106 +static int DirectFB_GL_LoadLibrary(_THIS, const char *path);
  10.107 +static void DirectFB_GL_UnloadLibrary(_THIS);
  10.108 +static void *DirectFB_GL_GetProcAddress(_THIS, const char *proc);
  10.109 +static SDL_GLContext DirectFB_GL_CreateContext(_THIS, SDL_Window * window);
  10.110 +static int DirectFB_GL_MakeCurrent(_THIS, SDL_Window * window,
  10.111 +                                   SDL_GLContext context);
  10.112 +static int DirectFB_GL_SetSwapInterval(_THIS, int interval);
  10.113 +static int DirectFB_GL_GetSwapInterval(_THIS);
  10.114 +static void DirectFB_GL_SwapWindow(_THIS, SDL_Window * window);
  10.115 +static void DirectFB_GL_DeleteContext(_THIS, SDL_GLContext context);
  10.116 +
  10.117 +#endif
  10.118  
  10.119  /* DirectFB driver bootstrap functions */
  10.120  
  10.121 @@ -102,7 +113,7 @@
  10.122  static void
  10.123  DirectFB_DeleteDevice(SDL_VideoDevice * device)
  10.124  {
  10.125 -    SDL_free(device->hidden);
  10.126 +    SDL_free(device->driverdata);
  10.127      SDL_free(device);
  10.128  }
  10.129  
  10.130 @@ -112,50 +123,60 @@
  10.131      SDL_VideoDevice *device;
  10.132  
  10.133      /* Initialize all variables that we clean on shutdown */
  10.134 -    device = (SDL_VideoDevice *) SDL_malloc(sizeof(SDL_VideoDevice));
  10.135 -    if (device) {
  10.136 -        SDL_memset(device, 0, (sizeof *device));
  10.137 -        device->hidden = (struct SDL_PrivateVideoData *)
  10.138 -            malloc(sizeof(*device->hidden));
  10.139 -    }
  10.140 -    if (device == NULL || device->hidden == NULL) {
  10.141 -        SDL_OutOfMemory();
  10.142 -        if (device) {
  10.143 -            free(device);
  10.144 -        }
  10.145 -        return (0);
  10.146 -    }
  10.147 -    SDL_memset(device->hidden, 0, sizeof(*device->hidden));
  10.148 +    SDL_DFB_CALLOC(device, 1, sizeof(SDL_VideoDevice));
  10.149 +    SDL_DFB_CALLOC(device->gl_data, 1, sizeof(*device->gl_data));
  10.150 +
  10.151 +    /* Set the function pointers */
  10.152  
  10.153      /* Set the function pointers */
  10.154      device->VideoInit = DirectFB_VideoInit;
  10.155 -    device->ListModes = DirectFB_ListModes;
  10.156 -    device->SetVideoMode = DirectFB_SetVideoMode;
  10.157 -    device->SetColors = DirectFB_SetColors;
  10.158 -    device->UpdateRects = NULL;
  10.159 -    device->CreateYUVOverlay = DirectFB_CreateYUVOverlay;
  10.160      device->VideoQuit = DirectFB_VideoQuit;
  10.161 -    device->AllocHWSurface = DirectFB_AllocHWSurface;
  10.162 -    device->CheckHWBlit = DirectFB_CheckHWBlit;
  10.163 -    device->FillHWRect = DirectFB_FillHWRect;
  10.164 -    device->SetHWColorKey = DirectFB_SetHWColorKey;
  10.165 -    device->SetHWAlpha = DirectFB_SetHWAlpha;
  10.166 -    device->LockHWSurface = DirectFB_LockHWSurface;
  10.167 -    device->UnlockHWSurface = DirectFB_UnlockHWSurface;
  10.168 -    device->FlipHWSurface = DirectFB_FlipHWSurface;
  10.169 -    device->FreeHWSurface = DirectFB_FreeHWSurface;
  10.170 -    device->ShowWMCursor = DirectFB_ShowWMCursor;
  10.171 -    device->SetCaption = NULL;
  10.172 -    device->SetIcon = NULL;
  10.173 -    device->IconifyWindow = NULL;
  10.174 -    device->GrabInput = NULL;
  10.175 -    device->GetWMInfo = NULL;
  10.176 -    device->InitOSKeymap = DirectFB_InitOSKeymap;
  10.177 -    device->PumpEvents = DirectFB_PumpEvents;
  10.178 +    device->GetDisplayModes = DirectFB_GetDisplayModes;
  10.179 +    device->SetDisplayMode = DirectFB_SetDisplayMode;
  10.180 +#if 0
  10.181 +    device->SetDisplayGammaRamp = DirectFB_SetDisplayGammaRamp;
  10.182 +    device->GetDisplayGammaRamp = DirectFB_GetDisplayGammaRamp;
  10.183 +#else
  10.184 +    device->SetDisplayGammaRamp = NULL;
  10.185 +    device->GetDisplayGammaRamp = NULL;
  10.186 +#endif
  10.187 +    device->PumpEvents = DirectFB_PumpEventsWindow;
  10.188 +
  10.189 +    device->CreateWindow = DirectFB_CreateWindow;
  10.190 +    device->CreateWindowFrom = DirectFB_CreateWindowFrom;
  10.191 +    device->SetWindowTitle = DirectFB_SetWindowTitle;
  10.192 +    device->SetWindowPosition = DirectFB_SetWindowPosition;
  10.193 +    device->SetWindowSize = DirectFB_SetWindowSize;
  10.194 +    device->ShowWindow = DirectFB_ShowWindow;
  10.195 +    device->HideWindow = DirectFB_HideWindow;
  10.196 +    device->RaiseWindow = DirectFB_RaiseWindow;
  10.197 +    device->MaximizeWindow = DirectFB_MaximizeWindow;
  10.198 +    device->MinimizeWindow = DirectFB_MinimizeWindow;
  10.199 +    device->RestoreWindow = DirectFB_RestoreWindow;
  10.200 +    device->SetWindowGrab = DirectFB_SetWindowGrab;
  10.201 +    device->DestroyWindow = DirectFB_DestroyWindow;
  10.202 +    device->GetWindowWMInfo = DirectFB_GetWindowWMInfo;
  10.203 +
  10.204 +#if SDL_DIRECTFB_OPENGL
  10.205 +    device->GL_LoadLibrary = DirectFB_GL_LoadLibrary;
  10.206 +    device->GL_GetProcAddress = DirectFB_GL_GetProcAddress;
  10.207 +    device->GL_MakeCurrent = DirectFB_GL_MakeCurrent;
  10.208 +
  10.209 +    device->GL_CreateContext = DirectFB_GL_CreateContext;
  10.210 +    device->GL_SetSwapInterval = DirectFB_GL_SetSwapInterval;
  10.211 +    device->GL_GetSwapInterval = DirectFB_GL_GetSwapInterval;
  10.212 +    device->GL_SwapWindow = DirectFB_GL_SwapWindow;
  10.213 +    device->GL_DeleteContext = DirectFB_GL_DeleteContext;
  10.214 +
  10.215 +#endif
  10.216  
  10.217      device->free = DirectFB_DeleteDevice;
  10.218  
  10.219      return device;
  10.220 +  error:
  10.221 +    if (device)
  10.222 +        free(device);
  10.223 +    return (0);
  10.224  }
  10.225  
  10.226  VideoBootStrap DirectFB_bootstrap = {
  10.227 @@ -163,214 +184,107 @@
  10.228      DirectFB_Available, DirectFB_CreateDevice
  10.229  };
  10.230  
  10.231 -static DFBSurfacePixelFormat
  10.232 -GetFormatForBpp(int bpp, IDirectFBDisplayLayer * layer)
  10.233 +static DFBEnumerationResult
  10.234 +EnumModesCallback(int width, int height, int bpp, void *data)
  10.235  {
  10.236 -    DFBDisplayLayerConfig dlc;
  10.237 -    int bytes = (bpp + 7) / 8;
  10.238 +    SDL_VideoDisplay *this = (SDL_VideoDisplay *) data;
  10.239 +    DFB_DisplayData *dispdata = (DFB_DisplayData *) this->driverdata;
  10.240 +    SDL_DisplayMode mode;
  10.241  
  10.242 -    layer->GetConfiguration(layer, &dlc);
  10.243 +    mode.w = width;
  10.244 +    mode.h = height;
  10.245 +    mode.refresh_rate = 0;
  10.246 +    mode.driverdata = NULL;
  10.247 +    mode.format = 0;
  10.248  
  10.249 -    if (bytes == DFB_BYTES_PER_PIXEL(dlc.pixelformat) && bytes > 1)
  10.250 -        return dlc.pixelformat;
  10.251 -
  10.252 -    switch (bytes) {
  10.253 -    case 1:
  10.254 -        return DSPF_LUT8;
  10.255 -    case 2:
  10.256 -        return DSPF_RGB16;
  10.257 -    case 3:
  10.258 -        return DSPF_RGB24;
  10.259 -    case 4:
  10.260 -        return DSPF_RGB32;
  10.261 +    if (dispdata->nummodes < DFB_MAX_MODES) {
  10.262 +        dispdata->modelist[dispdata->nummodes++] = mode;
  10.263      }
  10.264  
  10.265 -    return DSPF_UNKNOWN;
  10.266 +    SDL_DFB_DEBUG("w %d h %d bpp %d\n", width, height, bpp);
  10.267 +    return DFENUM_OK;
  10.268 +}
  10.269 +
  10.270 +static int
  10.271 +DFBToSDLPixelFormat(DFBSurfacePixelFormat pixelformat, Uint32 * fmt)
  10.272 +{
  10.273 +    switch (pixelformat) {
  10.274 +    case DSPF_ALUT44:
  10.275 +        *fmt = SDL_PIXELFORMAT_INDEX4LSB;
  10.276 +        break;
  10.277 +    case DSPF_LUT8:
  10.278 +        *fmt = SDL_PIXELFORMAT_INDEX8;
  10.279 +        break;
  10.280 +    case DSPF_RGB332:
  10.281 +        *fmt = SDL_PIXELFORMAT_RGB332;
  10.282 +        break;
  10.283 +    case DSPF_ARGB4444:
  10.284 +        *fmt = SDL_PIXELFORMAT_ARGB4444;
  10.285 +        break;
  10.286 +    case SDL_PIXELFORMAT_ARGB1555:
  10.287 +        *fmt = SDL_PIXELFORMAT_ARGB1555;
  10.288 +        break;
  10.289 +    case DSPF_RGB16:
  10.290 +        *fmt = SDL_PIXELFORMAT_RGB565;
  10.291 +        break;
  10.292 +    case DSPF_RGB24:
  10.293 +        *fmt = SDL_PIXELFORMAT_RGB24;
  10.294 +        break;
  10.295 +    case DSPF_RGB32:
  10.296 +        *fmt = SDL_PIXELFORMAT_RGB888;
  10.297 +        break;
  10.298 +    case DSPF_ARGB:
  10.299 +        *fmt = SDL_PIXELFORMAT_ARGB8888;
  10.300 +        break;
  10.301 +    case DSPF_YV12:
  10.302 +        *fmt = SDL_PIXELFORMAT_YV12;
  10.303 +        break;                  /* Planar mode: Y + V + U  (3 planes) */
  10.304 +    case DSPF_I420:
  10.305 +        *fmt = SDL_PIXELFORMAT_IYUV;
  10.306 +        break;                  /* Planar mode: Y + U + V  (3 planes) */
  10.307 +    case DSPF_YUY2:
  10.308 +        *fmt = SDL_PIXELFORMAT_YUY2;
  10.309 +        break;                  /* Packed mode: Y0+U0+Y1+V0 (1 plane) */
  10.310 +    case DSPF_UYVY:
  10.311 +        *fmt = SDL_PIXELFORMAT_UYVY;
  10.312 +        break;                  /* Packed mode: U0+Y0+V0+Y1 (1 plane) */
  10.313 +    default:
  10.314 +        return -1;
  10.315 +    }
  10.316 +    return 0;
  10.317  }
  10.318  
  10.319  static DFBEnumerationResult
  10.320 -EnumModesCallback(int width, int height, int bpp, void *data)
  10.321 +cbScreens(DFBScreenID screen_id, DFBScreenDescription desc,
  10.322 +          void *callbackdata)
  10.323  {
  10.324 -    SDL_VideoDevice *this = (SDL_VideoDevice *) data;
  10.325 -    struct DirectFBEnumRect *enumrect;
  10.326 +    DFB_DeviceData *devdata = (DFB_DeviceData *) callbackdata;
  10.327  
  10.328 -    HIDDEN->nummodes++;
  10.329 -
  10.330 -    if (enumlist && enumlist->r.w == width && enumlist->r.h == height)
  10.331 -        return DFENUM_OK;
  10.332 -
  10.333 -    enumrect = SDL_calloc(1, sizeof(struct DirectFBEnumRect));
  10.334 -    if (!enumrect) {
  10.335 -        SDL_OutOfMemory();
  10.336 -        return DFENUM_CANCEL;
  10.337 -    }
  10.338 -
  10.339 -    enumrect->r.w = (Uint16) width;
  10.340 -    enumrect->r.h = (Uint16) height;
  10.341 -    enumrect->next = enumlist;
  10.342 -
  10.343 -    enumlist = enumrect;
  10.344 -
  10.345 +    devdata->screenid[devdata->numscreens++] = screen_id;
  10.346      return DFENUM_OK;
  10.347  }
  10.348  
  10.349 -struct private_hwdata
  10.350 +DFBEnumerationResult
  10.351 +cbLayers(DFBDisplayLayerID layer_id, DFBDisplayLayerDescription desc,
  10.352 +         void *callbackdata)
  10.353  {
  10.354 -    IDirectFBSurface *surface;
  10.355 -    IDirectFBPalette *palette;
  10.356 -};
  10.357 +    DFB_DeviceData *devdata = (DFB_DeviceData *) callbackdata;
  10.358  
  10.359 -void
  10.360 -SetDirectFBerror(const char *function, DFBResult code)
  10.361 -{
  10.362 -    const char *error = DirectFBErrorString(code);
  10.363 -
  10.364 -    if (error)
  10.365 -        SDL_SetError("%s: %s", function, error);
  10.366 -    else
  10.367 -        SDL_SetError("Unknown error code from %s", function);
  10.368 -}
  10.369 -
  10.370 -static DFBSurfacePixelFormat
  10.371 -SDLToDFBPixelFormat(SDL_PixelFormat * format)
  10.372 -{
  10.373 -    if (format->Rmask && format->Gmask && format->Bmask) {
  10.374 -        switch (format->BitsPerPixel) {
  10.375 -        case 8:
  10.376 -            return DSPF_LUT8;
  10.377 -
  10.378 -        case 16:
  10.379 -            if (format->Rmask == 0xF800 &&
  10.380 -                format->Gmask == 0x07E0 && format->Bmask == 0x001F)
  10.381 -                return DSPF_RGB16;
  10.382 -            /* fall through */
  10.383 -
  10.384 -        case 15:
  10.385 -            if (format->Rmask == 0x7C00 &&
  10.386 -                format->Gmask == 0x03E0 && format->Bmask == 0x001F)
  10.387 -                return DSPF_ARGB1555;
  10.388 -            break;
  10.389 -
  10.390 -        case 24:
  10.391 -            if (format->Rmask == 0xFF0000 &&
  10.392 -                format->Gmask == 0x00FF00 && format->Bmask == 0x0000FF)
  10.393 -                return DSPF_RGB24;
  10.394 -            break;
  10.395 -
  10.396 -        case 32:
  10.397 -            if (format->Rmask == 0xFF0000 &&
  10.398 -                format->Gmask == 0x00FF00 && format->Bmask == 0x0000FF) {
  10.399 -                if (format->Amask == 0xFF000000)
  10.400 -                    return DSPF_ARGB;
  10.401 -                else
  10.402 -                    return DSPF_RGB32;
  10.403 -            }
  10.404 -            break;
  10.405 -        }
  10.406 -    } else {
  10.407 -        switch (format->BitsPerPixel) {
  10.408 -        case 8:
  10.409 -            return DSPF_LUT8;
  10.410 -        case 15:
  10.411 -            return DSPF_ARGB1555;
  10.412 -        case 16:
  10.413 -            return DSPF_RGB16;
  10.414 -        case 24:
  10.415 -            return DSPF_RGB24;
  10.416 -        case 32:
  10.417 -            return DSPF_RGB32;
  10.418 +    if (desc.caps & DLCAPS_SURFACE) {
  10.419 +        if ((desc.type & DLTF_GRAPHICS) && (desc.type & DLTF_VIDEO)) {
  10.420 +            if (devdata->vidlayer[devdata->aux] == -1)
  10.421 +                devdata->vidlayer[devdata->aux] = layer_id;
  10.422 +        } else if (desc.type & DLTF_GRAPHICS) {
  10.423 +            if (devdata->gralayer[devdata->aux] == -1)
  10.424 +                devdata->gralayer[devdata->aux] = layer_id;
  10.425          }
  10.426      }
  10.427 -
  10.428 -    return DSPF_UNKNOWN;
  10.429 -}
  10.430 -
  10.431 -static SDL_Palette *
  10.432 -AllocatePalette(int size)
  10.433 -{
  10.434 -    SDL_Palette *palette;
  10.435 -    SDL_Color *colors;
  10.436 -
  10.437 -    palette = SDL_calloc(1, sizeof(SDL_Palette));
  10.438 -    if (!palette) {
  10.439 -        SDL_OutOfMemory();
  10.440 -        return NULL;
  10.441 -    }
  10.442 -
  10.443 -    colors = SDL_calloc(size, sizeof(SDL_Color));
  10.444 -    if (!colors) {
  10.445 -        SDL_OutOfMemory();
  10.446 -        return NULL;
  10.447 -    }
  10.448 -
  10.449 -    palette->ncolors = size;
  10.450 -    palette->colors = colors;
  10.451 -
  10.452 -    return palette;
  10.453 +    return DFENUM_OK;
  10.454  }
  10.455  
  10.456  static int
  10.457 -DFBToSDLPixelFormat(DFBSurfacePixelFormat pixelformat,
  10.458 -                    SDL_PixelFormat * format)
  10.459 +DirectFB_VideoInit(_THIS)
  10.460  {
  10.461 -    format->Amask = format->Rmask = format->Gmask = format->Bmask = 0;
  10.462 -    format->BitsPerPixel = format->BytesPerPixel = 0;
  10.463 -
  10.464 -    switch (pixelformat) {
  10.465 -    case DSPF_A8:
  10.466 -        format->Amask = 0x000000FF;
  10.467 -        break;
  10.468 -
  10.469 -    case DSPF_ARGB1555:
  10.470 -        format->Rmask = 0x00007C00;
  10.471 -        format->Gmask = 0x000003E0;
  10.472 -        format->Bmask = 0x0000001F;
  10.473 -        break;
  10.474 -
  10.475 -    case DSPF_RGB16:
  10.476 -        format->Rmask = 0x0000F800;
  10.477 -        format->Gmask = 0x000007E0;
  10.478 -        format->Bmask = 0x0000001F;
  10.479 -        break;
  10.480 -
  10.481 -    case DSPF_ARGB:
  10.482 -        format->Amask = 0;      /* apps don't seem to like that:  0xFF000000; */
  10.483 -        /* fall through */
  10.484 -    case DSPF_RGB24:
  10.485 -    case DSPF_RGB32:
  10.486 -        format->Rmask = 0x00FF0000;
  10.487 -        format->Gmask = 0x0000FF00;
  10.488 -        format->Bmask = 0x000000FF;
  10.489 -        break;
  10.490 -
  10.491 -    case DSPF_LUT8:
  10.492 -        format->Rmask = 0x000000FF;
  10.493 -        format->Gmask = 0x000000FF;
  10.494 -        format->Bmask = 0x000000FF;
  10.495 -
  10.496 -        if (!format->palette)
  10.497 -            format->palette = AllocatePalette(256);
  10.498 -        break;
  10.499 -
  10.500 -    default:
  10.501 -        fprintf(stderr,
  10.502 -                "SDL_DirectFB: Unsupported pixelformat (0x%08x)!\n",
  10.503 -                pixelformat);
  10.504 -        return -1;
  10.505 -    }
  10.506 -
  10.507 -    format->BitsPerPixel = DFB_BYTES_PER_PIXEL(pixelformat) * 8;
  10.508 -    format->BytesPerPixel = DFB_BYTES_PER_PIXEL(pixelformat);
  10.509 -
  10.510 -    return 0;
  10.511 -}
  10.512 -
  10.513 -
  10.514 -int
  10.515 -DirectFB_VideoInit(_THIS, SDL_PixelFormat * vformat)
  10.516 -{
  10.517 -    int i;
  10.518 -    DFBResult ret;
  10.519  #if (DIRECTFB_MAJOR_VERSION == 0) && (DIRECTFB_MINOR_VERSION == 9) && (DIRECTFB_MICRO_VERSION < 23)
  10.520      DFBCardCapabilities caps;
  10.521  #else
  10.522 @@ -380,801 +294,816 @@
  10.523      struct DirectFBEnumRect *rect;
  10.524      IDirectFB *dfb = NULL;
  10.525      IDirectFBDisplayLayer *layer = NULL;
  10.526 -    IDirectFBEventBuffer *events = NULL;
  10.527  
  10.528 -    HIDDEN->c2layer = NULL, HIDDEN->c2frame = NULL;
  10.529 -    HIDDEN->enable_mga_crtc2 = 0;
  10.530 -    HIDDEN->mga_crtc2_stretch_overscan = 1;
  10.531 +    SDL_VideoDisplay display;
  10.532 +    DFB_DisplayData *dispdata;
  10.533 +    DFB_DeviceData *devdata;
  10.534 +    SDL_DisplayMode mode;
  10.535 +    SDL_Keyboard keyboard;
  10.536 +    int i;
  10.537 +    DFBResult ret;
  10.538 +    int tcw[DFB_MAX_SCREENS];
  10.539 +    int tch[DFB_MAX_SCREENS];
  10.540  
  10.541 -    ret = DirectFBInit(NULL, NULL);
  10.542 -    if (ret) {
  10.543 -        SetDirectFBerror("DirectFBInit", ret);
  10.544 -        goto error;
  10.545 +    SDL_zero(keyboard);
  10.546 +
  10.547 +    SDL_DFB_CHECKERR(DirectFBInit(NULL, NULL));
  10.548 +    SDL_DFB_CHECKERR(DirectFBCreate(&dfb));
  10.549 +
  10.550 +    SDL_DFB_CALLOC(devdata, 1, sizeof(*devdata));
  10.551 +    devdata->numscreens = 0;
  10.552 +    for (i = 0; i < DFB_MAX_SCREENS; i++) {
  10.553 +        devdata->gralayer[i] = -1;
  10.554 +        devdata->vidlayer[i] = -1;
  10.555 +    }
  10.556 +    SDL_DFB_CHECKERR(dfb->EnumScreens(dfb, &cbScreens, devdata));
  10.557 +    for (i = 0; i < devdata->numscreens; i++) {
  10.558 +        IDirectFBScreen *screen;
  10.559 +
  10.560 +        SDL_DFB_CHECKERR(dfb->GetScreen(dfb, devdata->screenid[i], &screen));
  10.561 +
  10.562 +        devdata->aux = i;
  10.563 +        SDL_DFB_CHECKERR(screen->
  10.564 +                         EnumDisplayLayers(screen, &cbLayers, devdata));
  10.565 +        screen->GetSize(screen, &tcw[i], &tch[i]);
  10.566 +        screen->Release(screen);
  10.567      }
  10.568  
  10.569 -    ret = DirectFBCreate(&dfb);
  10.570 -    if (ret) {
  10.571 -        SetDirectFBerror("DirectFBCreate", ret);
  10.572 -        goto error;
  10.573 +    /* Query card capabilities */
  10.574 +
  10.575 +    dfb->GetDeviceDescription(dfb, &caps);
  10.576 +
  10.577 +    SDL_DFB_DEBUG("SDL directfb video driver - %s %s\n", __DATE__, __TIME__);
  10.578 +    SDL_DFB_DEBUG("Using %s (%s) driver.\n", caps.name, caps.vendor);
  10.579 +    SDL_DFB_DEBUG("Found %d screens\n", devdata->numscreens);
  10.580 +
  10.581 +    for (i = 0; i < devdata->numscreens; i++) {
  10.582 +        //SDL_DFB_CHECKERR( dfb->GetDisplayLayer (dfb, DLID_PRIMARY, &layer) );
  10.583 +        SDL_DFB_CHECKERR(dfb->
  10.584 +                         GetDisplayLayer(dfb, devdata->gralayer[i], &layer));
  10.585 +        //SDL_DFB_CHECKERR( dfb->CreateInputEventBuffer (dfb, DICAPS_ALL, DFB_FALSE, &events) );
  10.586 +
  10.587 +        SDL_DFB_CHECKERR(layer->
  10.588 +                         SetCooperativeLevel(layer, DLSCL_ADMINISTRATIVE));
  10.589 +        layer->EnableCursor(layer, 1);
  10.590 +        SDL_DFB_CHECKERR(layer->SetCursorOpacity(layer, 0xC0));
  10.591 +        SDL_DFB_CHECKERR(layer->SetCooperativeLevel(layer, DLSCL_SHARED));
  10.592 +
  10.593 +        /* Query layer configuration to determine the current mode and pixelformat */
  10.594 +        layer->GetConfiguration(layer, &dlc);
  10.595 +
  10.596 +        DFBToSDLPixelFormat(dlc.pixelformat, &mode.format);
  10.597 +
  10.598 +        mode.w = dlc.width;
  10.599 +        mode.h = dlc.height;
  10.600 +        mode.refresh_rate = 0;
  10.601 +        mode.driverdata = NULL;
  10.602 +
  10.603 +        SDL_DFB_CALLOC(dispdata, 1, sizeof(*dispdata));
  10.604 +
  10.605 +        dispdata->layer = layer;
  10.606 +        dispdata->pixelformat = dlc.pixelformat;
  10.607 +        dispdata->cw = tcw[i];
  10.608 +        dispdata->ch = tch[i];
  10.609 +
  10.610 +        /* YUV - Video layer */
  10.611 +
  10.612 +        dispdata->vidID = devdata->vidlayer[i];
  10.613 +
  10.614 +        SDL_zero(display);
  10.615 +
  10.616 +        display.desktop_mode = mode;
  10.617 +        display.current_mode = mode;
  10.618 +        display.driverdata = dispdata;
  10.619 +
  10.620 +        /* Enumerate the available fullscreen modes */
  10.621 +        SDL_DFB_CALLOC(dispdata->modelist, DFB_MAX_MODES,
  10.622 +                       sizeof(SDL_DisplayMode));
  10.623 +        SDL_DFB_CHECKERR(dfb->
  10.624 +                         EnumVideoModes(dfb, EnumModesCallback, &display));
  10.625 +
  10.626 +        SDL_AddVideoDisplay(&display);
  10.627      }
  10.628  
  10.629 -    ret = dfb->GetDisplayLayer(dfb, DLID_PRIMARY, &layer);
  10.630 -    if (ret) {
  10.631 -        SetDirectFBerror("dfb->GetDisplayLayer", ret);
  10.632 -        goto error;
  10.633 +    devdata->initialized = 1;
  10.634 +    devdata->dfb = dfb;
  10.635 +    devdata->firstwin = NULL;
  10.636 +
  10.637 +    _this->driverdata = devdata;
  10.638 +
  10.639 +
  10.640 +#if SDL_DIRECTFB_OPENGL
  10.641 +    /* Opengl */
  10.642 +    _this->gl_data->gl_active = 0;
  10.643 +    _this->gl_data->gl_context = NULL;
  10.644 +#endif
  10.645 +
  10.646 +    DirectFB_AddRenderDriver(_this);
  10.647 +    DirectFB_InitMouse(_this);
  10.648 +    //devdata->mouse = SDL_AddMouse(&mouse, -1);
  10.649 +    devdata->keyboard = SDL_AddKeyboard(&keyboard, -1);
  10.650 +    DirectFB_InitOSKeymap(_this);
  10.651 +
  10.652 +    return 0;
  10.653 +
  10.654 +
  10.655 +  error:
  10.656 +    //FIXME: Cleanup not complete, Free existing displays
  10.657 +    SDL_DFB_FREE(dispdata);
  10.658 +    SDL_DFB_FREE(dispdata->modelist);
  10.659 +    SDL_DFB_RELEASE(layer);
  10.660 +    SDL_DFB_RELEASE(dfb);
  10.661 +    return -1;
  10.662 +}
  10.663 +
  10.664 +static void
  10.665 +DirectFB_VideoQuit(_THIS)
  10.666 +{
  10.667 +    DFB_DeviceData *devdata = (DFB_DeviceData *) _this->driverdata;
  10.668 +    SDL_DisplayMode tmode;
  10.669 +    DFBResult ret;
  10.670 +    int i;
  10.671 +
  10.672 +    tmode = _this->displays[0].desktop_mode;
  10.673 +    tmode.format = SDL_PIXELFORMAT_UNKNOWN;
  10.674 +    DirectFB_SetDisplayMode(_this, &tmode);
  10.675 +    tmode = _this->displays[0].desktop_mode;
  10.676 +    DirectFB_SetDisplayMode(_this, &tmode);
  10.677 +
  10.678 +    for (i = 0; i < devdata->numscreens; i++) {
  10.679 +        DFB_DisplayData *dispdata =
  10.680 +            (DFB_DisplayData *) _this->displays[i].driverdata;
  10.681 +        if (dispdata->layer) {
  10.682 +            SDL_DFB_CHECK(dispdata->layer->
  10.683 +                          SetCooperativeLevel(dispdata->layer,
  10.684 +                                              DLSCL_ADMINISTRATIVE));
  10.685 +            SDL_DFB_CHECK(dispdata->layer->
  10.686 +                          SetCursorOpacity(dispdata->layer, 0x00));
  10.687 +            SDL_DFB_CHECK(dispdata->layer->
  10.688 +                          SetCooperativeLevel(dispdata->layer, DLSCL_SHARED));
  10.689 +        }
  10.690 +        SDL_DFB_RELEASE(dispdata->layer);
  10.691 +
  10.692 +        /* Free video mode list */
  10.693 +        if (dispdata->modelist) {
  10.694 +            SDL_free(dispdata->modelist);
  10.695 +            dispdata->modelist = NULL;
  10.696 +        }
  10.697 +        // Done by core
  10.698 +        //SDL_free(dispdata);
  10.699      }
  10.700  
  10.701 -    ret = dfb->CreateInputEventBuffer(dfb, DICAPS_ALL, DFB_FALSE, &events);
  10.702 -    if (ret) {
  10.703 -        SetDirectFBerror("dfb->CreateEventBuffer", ret);
  10.704 -        goto error;
  10.705 -    }
  10.706 +    //SDL_DFB_RELEASE(devdata->eventbuffer);
  10.707  
  10.708 -    layer->EnableCursor(layer, 1);
  10.709 +    SDL_DFB_RELEASE(devdata->dfb);
  10.710  
  10.711 -    /* Query layer configuration to determine the current mode and pixelformat */
  10.712 -    layer->GetConfiguration(layer, &dlc);
  10.713 +    SDL_DelMouse(devdata->mouse);
  10.714 +    SDL_DelKeyboard(devdata->keyboard);
  10.715  
  10.716 -    /* If current format is not supported use LUT8 as the default */
  10.717 -    if (DFBToSDLPixelFormat(dlc.pixelformat, vformat))
  10.718 -        DFBToSDLPixelFormat(DSPF_LUT8, vformat);
  10.719 -
  10.720 -    /* Enumerate the available fullscreen modes */
  10.721 -    ret = dfb->EnumVideoModes(dfb, EnumModesCallback, this);
  10.722 -    if (ret) {
  10.723 -        SetDirectFBerror("dfb->EnumVideoModes", ret);
  10.724 -        goto error;
  10.725 -    }
  10.726 -
  10.727 -    HIDDEN->modelist = SDL_calloc(HIDDEN->nummodes + 1, sizeof(SDL_Rect *));
  10.728 -    if (!HIDDEN->modelist) {
  10.729 -        SDL_OutOfMemory();
  10.730 -        goto error;
  10.731 -    }
  10.732 -
  10.733 -    for (i = 0, rect = enumlist; rect; ++i, rect = rect->next) {
  10.734 -        HIDDEN->modelist[i] = &rect->r;
  10.735 -    }
  10.736 -
  10.737 -    HIDDEN->modelist[i] = NULL;
  10.738 -
  10.739 -
  10.740 -    /* Query card capabilities to get the video memory size */
  10.741 -#if (DIRECTFB_MAJOR_VERSION == 0) && (DIRECTFB_MINOR_VERSION == 9) && (DIRECTFB_MICRO_VERSION < 23)
  10.742 -    dfb->GetCardCapabilities(dfb, &caps);
  10.743 -#else
  10.744 -    dfb->GetDeviceDescription(dfb, &caps);
  10.745 +#if SDL_DIRECTFB_OPENGL
  10.746 +    DirectFB_GL_UnloadLibrary(_this);
  10.747  #endif
  10.748  
  10.749 -    this->info.wm_available = 1;
  10.750 -    this->info.hw_available = 1;
  10.751 -    this->info.blit_hw = 1;
  10.752 -    this->info.blit_hw_CC = 1;
  10.753 -    this->info.blit_hw_A = 1;
  10.754 -    this->info.blit_fill = 1;
  10.755 -    this->info.video_mem = caps.video_memory / 1024;
  10.756 -    this->info.current_w = dlc.width;
  10.757 -    this->info.current_h = dlc.height;
  10.758 +    devdata->initialized = 0;
  10.759 +}
  10.760  
  10.761 -    HIDDEN->initialized = 1;
  10.762 -    HIDDEN->dfb = dfb;
  10.763 -    HIDDEN->layer = layer;
  10.764 -    HIDDEN->eventbuffer = events;
  10.765  
  10.766 -    if (SDL_getenv("SDL_DIRECTFB_MGA_CRTC2") != NULL)
  10.767 -        HIDDEN->enable_mga_crtc2 = 1;
  10.768 +static DFBSurfacePixelFormat
  10.769 +SDLToDFBPixelFormat(Uint32 format)
  10.770 +{
  10.771 +    switch (format) {
  10.772 +    case SDL_PIXELFORMAT_INDEX4LSB:
  10.773 +        return DSPF_ALUT44;
  10.774 +    case SDL_PIXELFORMAT_INDEX8:
  10.775 +        return DSPF_LUT8;
  10.776 +    case SDL_PIXELFORMAT_RGB332:
  10.777 +        return DSPF_RGB332;
  10.778 +    case SDL_PIXELFORMAT_RGB555:
  10.779 +        return DSPF_ARGB1555;
  10.780 +    case SDL_PIXELFORMAT_ARGB4444:
  10.781 +        return DSPF_ARGB4444;
  10.782 +    case SDL_PIXELFORMAT_ARGB1555:
  10.783 +        return DSPF_ARGB1555;
  10.784 +    case SDL_PIXELFORMAT_RGB565:
  10.785 +        return DSPF_RGB16;
  10.786 +    case SDL_PIXELFORMAT_RGB24:
  10.787 +        return DSPF_RGB24;
  10.788 +    case SDL_PIXELFORMAT_RGB888:
  10.789 +        return DSPF_RGB32;
  10.790 +    case SDL_PIXELFORMAT_ARGB8888:
  10.791 +        return DSPF_ARGB;
  10.792 +    case SDL_PIXELFORMAT_YV12:
  10.793 +        return DSPF_YV12;       /* Planar mode: Y + V + U  (3 planes) */
  10.794 +    case SDL_PIXELFORMAT_IYUV:
  10.795 +        return DSPF_I420;       /* Planar mode: Y + U + V  (3 planes) */
  10.796 +    case SDL_PIXELFORMAT_YUY2:
  10.797 +        return DSPF_YUY2;       /* Packed mode: Y0+U0+Y1+V0 (1 plane) */
  10.798 +    case SDL_PIXELFORMAT_UYVY:
  10.799 +        return DSPF_UYVY;       /* Packed mode: U0+Y0+V0+Y1 (1 plane) */
  10.800 +    case SDL_PIXELFORMAT_YVYU:
  10.801 +        return DSPF_UNKNOWN;    /* Packed mode: Y0+V0+Y1+U0 (1 plane) */
  10.802 +    case SDL_PIXELFORMAT_INDEX1LSB:
  10.803 +        return DSPF_UNKNOWN;
  10.804 +    case SDL_PIXELFORMAT_INDEX1MSB:
  10.805 +        return DSPF_UNKNOWN;
  10.806 +    case SDL_PIXELFORMAT_INDEX4MSB:
  10.807 +        return DSPF_UNKNOWN;
  10.808 +    case SDL_PIXELFORMAT_RGB444:
  10.809 +        return DSPF_UNKNOWN;
  10.810 +    case SDL_PIXELFORMAT_BGR24:
  10.811 +        return DSPF_UNKNOWN;
  10.812 +    case SDL_PIXELFORMAT_BGR888:
  10.813 +        return DSPF_UNKNOWN;
  10.814 +    case SDL_PIXELFORMAT_RGBA8888:
  10.815 +        return DSPF_UNKNOWN;
  10.816 +    case SDL_PIXELFORMAT_ABGR8888:
  10.817 +        return DSPF_UNKNOWN;
  10.818 +    case SDL_PIXELFORMAT_BGRA8888:
  10.819 +        return DSPF_UNKNOWN;
  10.820 +    case SDL_PIXELFORMAT_ARGB2101010:
  10.821 +        return DSPF_UNKNOWN;
  10.822 +    default:
  10.823 +        return DSPF_UNKNOWN;
  10.824 +    }
  10.825 +}
  10.826  
  10.827 -    if (HIDDEN->enable_mga_crtc2) {
  10.828 -        DFBDisplayLayerConfig dlc;
  10.829 -        DFBDisplayLayerConfigFlags failed;
  10.830 +static void
  10.831 +CheckSetDisplayMode(_THIS, DFB_DisplayData * data, SDL_DisplayMode * mode)
  10.832 +{
  10.833 +    DFBDisplayLayerConfig config;
  10.834 +    DFBDisplayLayerConfigFlags failed;
  10.835  
  10.836 -        ret = dfb->GetDisplayLayer(dfb, 2, &HIDDEN->c2layer);
  10.837 -        if (ret) {
  10.838 -            SetDirectFBerror("dfb->GetDisplayLayer(CRTC2)", ret);
  10.839 -            goto error;
  10.840 -        }
  10.841 +    config.width = mode->w;
  10.842 +    config.height = mode->h;
  10.843 +    config.pixelformat = SDLToDFBPixelFormat(mode->format);
  10.844 +    config.flags = DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT;
  10.845 +    failed = 0;
  10.846 +    data->layer->TestConfiguration(data->layer, &config, &failed);
  10.847 +    if (failed == 0)
  10.848 +        SDL_AddDisplayMode(_this->current_display, mode);
  10.849  
  10.850 -        ret =
  10.851 -            HIDDEN->layer->SetCooperativeLevel(HIDDEN->layer,
  10.852 -                                               DLSCL_EXCLUSIVE);
  10.853 -        if (ret) {
  10.854 -            SetDirectFBerror
  10.855 -                ("layer->SetCooperativeLevel(CRTC2, EXCLUSIVE)", ret);
  10.856 -            goto error;
  10.857 -        }
  10.858 +}
  10.859  
  10.860 -        ret =
  10.861 -            HIDDEN->c2layer->SetCooperativeLevel(HIDDEN->c2layer,
  10.862 -                                                 DLSCL_EXCLUSIVE);
  10.863 -        if (ret) {
  10.864 -            SetDirectFBerror
  10.865 -                ("c2layer->SetCooperativeLevel(CRTC2, EXCLUSIVE)", ret);
  10.866 -            goto error;
  10.867 -        }
  10.868 +static void
  10.869 +DirectFB_GetDisplayModes(_THIS)
  10.870 +{
  10.871 +    //SDL_DisplayData *data = (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
  10.872 +    //SDL_DisplayMode mode;
  10.873 +    //SDL_AddDisplayMode(_this->current_display, &mode);
  10.874  
  10.875 -        HIDDEN->c2layer->SetOpacity(HIDDEN->c2layer, 0x0);
  10.876 +    SDL_DFB_DEVICEDATA(_this);
  10.877 +    DFB_DisplayData *data = (DFB_DisplayData *) SDL_CurrentDisplay.driverdata;
  10.878 +    int i;
  10.879 +    SDL_DisplayMode mode;
  10.880  
  10.881 -        /* Init the surface here as it got a fixed size */
  10.882 -        dlc.flags = DLCONF_PIXELFORMAT | DLCONF_BUFFERMODE;
  10.883 -        dlc.buffermode = DLBM_BACKVIDEO;
  10.884 -        dlc.pixelformat = DSPF_RGB32;
  10.885 +    for (i = 0; i < data->nummodes; ++i) {
  10.886 +        mode = data->modelist[i];
  10.887 +        //mode.format = SDL_PIXELFORMAT_UNKNOWN;
  10.888  
  10.889 -        ret =
  10.890 -            HIDDEN->c2layer->TestConfiguration(HIDDEN->c2layer, &dlc,
  10.891 -                                               &failed);
  10.892 -        if (ret) {
  10.893 -            SetDirectFBerror("c2layer->TestConfiguration", ret);
  10.894 -            goto error;
  10.895 -        }
  10.896 +        mode.format = SDL_PIXELFORMAT_INDEX8;
  10.897 +        CheckSetDisplayMode(_this, data, &mode);
  10.898 +        mode.format = SDL_PIXELFORMAT_RGB565;
  10.899 +        CheckSetDisplayMode(_this, data, &mode);
  10.900 +        mode.format = SDL_PIXELFORMAT_RGB24;
  10.901 +        CheckSetDisplayMode(_this, data, &mode);
  10.902 +        mode.format = SDL_PIXELFORMAT_RGB888;
  10.903 +        CheckSetDisplayMode(_this, data, &mode);
  10.904 +    }
  10.905 +}
  10.906  
  10.907 -        ret = HIDDEN->c2layer->SetConfiguration(HIDDEN->c2layer, &dlc);
  10.908 -        if (ret) {
  10.909 -            SetDirectFBerror("c2layer->SetConfiguration", ret);
  10.910 -            goto error;
  10.911 -        }
  10.912 +int
  10.913 +DirectFB_SetDisplayMode(_THIS, SDL_DisplayMode * mode)
  10.914 +{
  10.915 +    SDL_DFB_DEVICEDATA(_this);
  10.916 +    DFB_DisplayData *data = (DFB_DisplayData *) SDL_CurrentDisplay.driverdata;
  10.917 +    DFBDisplayLayerConfig config, rconfig;
  10.918 +    DFBDisplayLayerConfigFlags fail = 0;
  10.919 +    DFBResult ret;
  10.920  
  10.921 -        ret = HIDDEN->c2layer->GetSurface(HIDDEN->c2layer, &HIDDEN->c2frame);
  10.922 -        if (ret) {
  10.923 -            SetDirectFBerror("c2layer->GetSurface", ret);
  10.924 -            goto error;
  10.925 -        }
  10.926 +    SDL_DFB_CHECKERR(data->layer->
  10.927 +                     SetCooperativeLevel(data->layer, DLSCL_ADMINISTRATIVE));
  10.928  
  10.929 -        HIDDEN->c2framesize.x = 0;
  10.930 -        HIDDEN->c2framesize.y = 0;
  10.931 -        HIDDEN->c2frame->GetSize(HIDDEN->c2frame, &HIDDEN->c2framesize.w,
  10.932 -                                 &HIDDEN->c2framesize.h);
  10.933 +    SDL_DFB_CHECKERR(data->layer->GetConfiguration(data->layer, &config));
  10.934 +    config.flags = DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_BUFFERMODE;
  10.935 +    if (mode->format != SDL_PIXELFORMAT_UNKNOWN) {
  10.936 +        config.flags |= DLCONF_PIXELFORMAT;
  10.937 +        config.pixelformat = SDLToDFBPixelFormat(mode->format);
  10.938 +        data->pixelformat = config.pixelformat;
  10.939 +    }
  10.940 +    config.width = mode->w;
  10.941 +    config.height = mode->h;
  10.942  
  10.943 -        HIDDEN->c2frame->SetBlittingFlags(HIDDEN->c2frame, DSBLIT_NOFX);
  10.944 -        HIDDEN->c2frame->SetColor(HIDDEN->c2frame, 0, 0, 0, 0xff);
  10.945 +    config.buffermode = DLBM_BACKVIDEO;
  10.946  
  10.947 -        /* Clear CRTC2 */
  10.948 -        HIDDEN->c2frame->Clear(HIDDEN->c2frame, 0, 0, 0, 0xff);
  10.949 -        HIDDEN->c2frame->Flip(HIDDEN->c2frame, NULL, 0);
  10.950 -        HIDDEN->c2frame->Clear(HIDDEN->c2frame, 0, 0, 0, 0xff);
  10.951 -        HIDDEN->c2frame->Flip(HIDDEN->c2frame, NULL, 0);
  10.952 -        HIDDEN->c2frame->Clear(HIDDEN->c2frame, 0, 0, 0, 0xff);
  10.953 +    //config.pixelformat = GetFormatForBpp (bpp, HIDDEN->layer);
  10.954  
  10.955 -        HIDDEN->c2layer->SetOpacity(HIDDEN->c2layer, 0xFF);
  10.956 +    data->layer->TestConfiguration(data->layer, &config, &fail);
  10.957 +    if (fail & (DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT)) {
  10.958 +        SDL_DFB_DEBUG("Error setting mode %dx%d-%x\n", mode->w, mode->h,
  10.959 +                      mode->format);
  10.960 +        return -1;
  10.961 +    }
  10.962 +    SDL_DFB_DEBUG("Trace\n");
  10.963 +    config.flags &= ~fail;
  10.964 +    SDL_DFB_CHECKERR(data->layer->SetConfiguration(data->layer, &config));
  10.965 +    SDL_DFB_CHECKERR(data->layer->
  10.966 +                     SetCooperativeLevel(data->layer, DLSCL_ADMINISTRATIVE));
  10.967  
  10.968 -        /* Check if overscan is possibly set */
  10.969 -        if (SDL_getenv("SDL_DIRECTFB_MGA_OVERSCAN") != NULL) {
  10.970 -            float overscan = 0;
  10.971 -            if (SDL_sscanf
  10.972 -                (SDL_getenv("SDL_DIRECTFB_MGA_OVERSCAN"), "%f",
  10.973 -                 &overscan) == 1)
  10.974 -                if (overscan > 0 && overscan < 2)
  10.975 -                    HIDDEN->mga_crtc2_stretch_overscan = overscan;
  10.976 -        }
  10.977 -#ifdef DIRECTFB_CRTC2_DEBUG
  10.978 -        printf("CRTC2 overscan: %f\n", HIDDEN->mga_crtc2_stretch_overscan);
  10.979 -#endif
  10.980 +    /* Double check */
  10.981 +    SDL_DFB_CHECKERR(data->layer->GetConfiguration(data->layer, &rconfig));
  10.982 +
  10.983 +    if ((config.width != rconfig.width) ||
  10.984 +        (config.height != rconfig.height) ||
  10.985 +        (config.pixelformat != rconfig.pixelformat)) {
  10.986 +        SDL_DFB_DEBUG("Error setting mode %dx%d-%x\n", mode->w, mode->h,
  10.987 +                      mode->format);
  10.988 +        return -1;
  10.989      }
  10.990  
  10.991      return 0;
  10.992 -
  10.993    error:
  10.994 -    if (events)
  10.995 -        events->Release(events);
  10.996 -
  10.997 -    if (HIDDEN->c2frame)
  10.998 -        HIDDEN->c2frame->Release(HIDDEN->c2frame);
  10.999 -
 10.1000 -    if (HIDDEN->c2layer)
 10.1001 -        HIDDEN->c2layer->Release(HIDDEN->c2layer);
 10.1002 -
 10.1003 -    if (layer)
 10.1004 -        layer->Release(layer);
 10.1005 -
 10.1006 -    if (dfb)
 10.1007 -        dfb->Release(dfb);
 10.1008 -
 10.1009      return -1;
 10.1010  }
 10.1011  
 10.1012 -static SDL_Rect **
 10.1013 -DirectFB_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags)
 10.1014 +static int
 10.1015 +DirectFB_SetDisplayGammaRamp(_THIS, Uint16 * ramp)
 10.1016  {
 10.1017 -    if (flags & SDL_FULLSCREEN)
 10.1018 -        return HIDDEN->modelist;
 10.1019 -    else if (SDLToDFBPixelFormat(format) != DSPF_UNKNOWN)
 10.1020 -        return (SDL_Rect **) - 1;
 10.1021 -
 10.1022 -    return NULL;
 10.1023 +    return -1;
 10.1024  }
 10.1025  
 10.1026 -static SDL_Surface *
 10.1027 -DirectFB_SetVideoMode(_THIS, SDL_Surface * current, int width, int height,
 10.1028 -                      int bpp, Uint32 flags)
 10.1029 +static int
 10.1030 +DirectFB_GetDisplayGammaRamp(_THIS, Uint16 * ramp)
 10.1031  {
 10.1032 -    DFBResult ret;
 10.1033 -    DFBSurfaceDescription dsc;
 10.1034 -    DFBSurfacePixelFormat pixelformat;
 10.1035 -    IDirectFBSurface *surface;
 10.1036 +    return -1;
 10.1037 +}
 10.1038  
 10.1039 -    fprintf(stderr, "SDL DirectFB_SetVideoMode: %dx%d@%d, flags: 0x%08x\n",
 10.1040 -            width, height, bpp, flags);
 10.1041 +static int
 10.1042 +DirectFB_CreateWindow(_THIS, SDL_Window * window)
 10.1043 +{
 10.1044 +    SDL_DFB_DEVICEDATA(_this);
 10.1045 +    SDL_DFB_DISPLAYDATA(_this, window);
 10.1046 +    DFB_WindowData *windata;
 10.1047 +    DFBWindowOptions wopts;
 10.1048 +    DFBWindowDescription desc;
 10.1049 +    int ret, x, y;
 10.1050  
 10.1051 -    flags |= SDL_FULLSCREEN;
 10.1052 +    SDL_DFB_DEBUG("Trace x %d y %d w %d h %d\n", window->x, window->y,
 10.1053 +                  window->w, window->h);
 10.1054 +    window->driverdata = NULL;
 10.1055 +    SDL_DFB_CALLOC(window->driverdata, 1, sizeof(DFB_WindowData));
 10.1056 +    windata = (DFB_WindowData *) window->driverdata;
 10.1057  
 10.1058 -    /* Release previous primary surface */
 10.1059 -    if (current->hwdata && current->hwdata->surface) {
 10.1060 -        current->hwdata->surface->Release(current->hwdata->surface);
 10.1061 -        current->hwdata->surface = NULL;
 10.1062 +    SDL_DFB_CHECKERR(devdata->dfb->
 10.1063 +                     SetCooperativeLevel(devdata->dfb, DFSCL_NORMAL));
 10.1064 +    SDL_DFB_CHECKERR(dispdata->layer->
 10.1065 +                     SetCooperativeLevel(dispdata->layer,
 10.1066 +                                         DLSCL_ADMINISTRATIVE));
 10.1067  
 10.1068 -        /* And its palette if present */
 10.1069 -        if (current->hwdata->palette) {
 10.1070 -            current->hwdata->palette->Release(current->hwdata->palette);
 10.1071 -            current->hwdata->palette = NULL;
 10.1072 +    /* Fill the window description. */
 10.1073 +    if (window->x == SDL_WINDOWPOS_CENTERED) {
 10.1074 +        x = (dispdata->cw - window->w) / 2;
 10.1075 +    } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
 10.1076 +        x = 0;
 10.1077 +    } else {
 10.1078 +        x = window->x;
 10.1079 +    }
 10.1080 +    if (window->y == SDL_WINDOWPOS_CENTERED) {
 10.1081 +        y = (dispdata->ch - window->h) / 2;
 10.1082 +    } else if (window->y == SDL_WINDOWPOS_UNDEFINED) {
 10.1083 +        y = 0;
 10.1084 +    } else {
 10.1085 +        y = window->y;
 10.1086 +    }
 10.1087 +
 10.1088 +    desc.flags =
 10.1089 +        DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_CAPS | DWDESC_PIXELFORMAT;
 10.1090 +    desc.flags |= DWDESC_POSX | DWDESC_POSY | DWDESC_SURFACE_CAPS;
 10.1091 +    desc.posx = x;
 10.1092 +    desc.posy = y;
 10.1093 +    desc.width = window->w;
 10.1094 +    desc.height = window->h;
 10.1095 +
 10.1096 +    desc.pixelformat = dispdata->pixelformat;
 10.1097 +
 10.1098 +    desc.caps = 0;              //DWCAPS_DOUBLEBUFFER;
 10.1099 +    desc.surface_caps = DSCAPS_DOUBLE | DSCAPS_TRIPLE;  //| DSCAPS_PREMULTIPLIED;
 10.1100 +
 10.1101 +    /* Create the window. */
 10.1102 +    SDL_DFB_CHECKERR(dispdata->layer->
 10.1103 +                     CreateWindow(dispdata->layer, &desc, &windata->window));
 10.1104 +
 10.1105 +    windata->window->GetOptions(windata->window, &wopts);
 10.1106 +#if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 0)
 10.1107 +
 10.1108 +    if (window->flags & SDL_WINDOW_RESIZABLE)
 10.1109 +        wopts |= DWOP_SCALE;
 10.1110 +    else
 10.1111 +        wopts |= DWOP_KEEP_SIZE;
 10.1112 +#else
 10.1113 +    wopts |= DWOP_KEEP_SIZE;    // if not we will crash ...
 10.1114 +#endif
 10.1115 +
 10.1116 +    if (window->flags & SDL_WINDOW_FULLSCREEN)
 10.1117 +        wopts |= DWOP_KEEP_POSITION | DWOP_KEEP_STACKING | DWOP_KEEP_SIZE;
 10.1118 +
 10.1119 +    windata->window->SetOptions(windata->window, wopts);
 10.1120 +    /* Get the window's surface. */
 10.1121 +    SDL_DFB_CHECKERR(windata->window->
 10.1122 +                     GetSurface(windata->window, &windata->surface));
 10.1123 +    windata->window->SetOpacity(windata->window, 0xFF);
 10.1124 +    SDL_DFB_CHECKERR(windata->window->
 10.1125 +                     CreateEventBuffer(windata->window,
 10.1126 +                                       &(windata->eventbuffer)));
 10.1127 +    SDL_DFB_CHECKERR(windata->window->
 10.1128 +                     EnableEvents(windata->window,
 10.1129 +                                  DWET_POSITION | DWET_SIZE | DWET_CLOSE |
 10.1130 +                                  DWET_ALL));
 10.1131 +
 10.1132 +    if (window->flags & SDL_WINDOW_FULLSCREEN)
 10.1133 +        windata->window->SetStackingClass(windata->window, DWSC_UPPER);
 10.1134 +    /* Make it the top most window. */
 10.1135 +    windata->window->RaiseToTop(windata->window);
 10.1136 +
 10.1137 +    windata->window->GetID(windata->window, &windata->windowID);
 10.1138 +    windata->id = window->id;
 10.1139 +
 10.1140 +#if SDL_DIRECTFB_OPENGL
 10.1141 +    if (window->flags & SDL_WINDOW_OPENGL) {
 10.1142 +        if (!_this->gl_config.driver_loaded) {
 10.1143 +            /* no driver has been loaded, use default (ourselves) */
 10.1144 +            if (DirectFB_GL_LoadLibrary(_this, NULL) < 0) {
 10.1145 +                goto error;
 10.1146 +            }
 10.1147          }
 10.1148 -    } else if (!current->hwdata) {
 10.1149 -        /* Allocate the hardware acceleration data */
 10.1150 -        current->hwdata =
 10.1151 -            (struct private_hwdata *) SDL_calloc(1, sizeof(*current->hwdata));
 10.1152 -        if (!current->hwdata) {
 10.1153 -            SDL_OutOfMemory();
 10.1154 -            return NULL;
 10.1155 +        _this->gl_data->gl_active = 1;
 10.1156 +    }
 10.1157 +#endif
 10.1158 +
 10.1159 +    /* Add to list ... */
 10.1160 +
 10.1161 +    windata->next = devdata->firstwin;
 10.1162 +    windata->opacity = 0xFF;
 10.1163 +    devdata->firstwin = windata;
 10.1164 +
 10.1165 +    //SDL_DFB_CHECKERR( windata->surface->GetPalette(windata->surface, &windata->palette) );
 10.1166 +
 10.1167 +    return 0;
 10.1168 +  error:
 10.1169 +    SDL_DFB_RELEASE(windata->window);
 10.1170 +    SDL_DFB_RELEASE(windata->surface);
 10.1171 +    return -1;
 10.1172 +}
 10.1173 +
 10.1174 +static int
 10.1175 +DirectFB_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
 10.1176 +{
 10.1177 +    SDL_DFB_DEVICEDATA(_this);
 10.1178 +    SDL_DFB_WINDOWDATA(window);
 10.1179 +    SDL_DFB_DISPLAYDATA(_this, window);
 10.1180 +
 10.1181 +    SDL_Unsupported();
 10.1182 +    return -1;
 10.1183 +}
 10.1184 +
 10.1185 +static void
 10.1186 +DirectFB_SetWindowTitle(_THIS, SDL_Window * window)
 10.1187 +{
 10.1188 +    SDL_DFB_DEVICEDATA(_this);
 10.1189 +    SDL_DFB_WINDOWDATA(window);
 10.1190 +    SDL_DFB_DISPLAYDATA(_this, window);
 10.1191 +
 10.1192 +    SDL_Unsupported();
 10.1193 +    //return -1;
 10.1194 +
 10.1195 +}
 10.1196 +static void
 10.1197 +DirectFB_SetWindowPosition(_THIS, SDL_Window * window)
 10.1198 +{
 10.1199 +    SDL_DFB_DEVICEDATA(_this);
 10.1200 +    SDL_DFB_WINDOWDATA(window);
 10.1201 +    SDL_DFB_DISPLAYDATA(_this, window);
 10.1202 +
 10.1203 +    windata->window->MoveTo(windata->window, window->x, window->y);
 10.1204 +}
 10.1205 +
 10.1206 +static void
 10.1207 +DirectFB_SetWindowSize(_THIS, SDL_Window * window)
 10.1208 +{
 10.1209 +    SDL_DFB_DEVICEDATA(_this);
 10.1210 +    SDL_DFB_WINDOWDATA(window);
 10.1211 +    SDL_DFB_DISPLAYDATA(_this, window);
 10.1212 +
 10.1213 +    windata->window->Resize(windata->window, window->w, window->h);
 10.1214 +
 10.1215 +}
 10.1216 +static void
 10.1217 +DirectFB_ShowWindow(_THIS, SDL_Window * window)
 10.1218 +{
 10.1219 +    SDL_DFB_DEVICEDATA(_this);
 10.1220 +    SDL_DFB_WINDOWDATA(window);
 10.1221 +    SDL_DFB_DISPLAYDATA(_this, window);
 10.1222 +
 10.1223 +    windata->window->SetOpacity(windata->window, windata->opacity);
 10.1224 +
 10.1225 +}
 10.1226 +
 10.1227 +static void
 10.1228 +DirectFB_HideWindow(_THIS, SDL_Window * window)
 10.1229 +{
 10.1230 +    SDL_DFB_DEVICEDATA(_this);
 10.1231 +    SDL_DFB_WINDOWDATA(window);
 10.1232 +    SDL_DFB_DISPLAYDATA(_this, window);
 10.1233 +
 10.1234 +    windata->window->GetOpacity(windata->window, &windata->opacity);
 10.1235 +    windata->window->SetOpacity(windata->window, 0);
 10.1236 +
 10.1237 +}
 10.1238 +static void
 10.1239 +DirectFB_RaiseWindow(_THIS, SDL_Window * window)
 10.1240 +{
 10.1241 +    SDL_DFB_DEVICEDATA(_this);
 10.1242 +    SDL_DFB_WINDOWDATA(window);
 10.1243 +    SDL_DFB_DISPLAYDATA(_this, window);
 10.1244 +
 10.1245 +    windata->window->Raise(windata->window);
 10.1246 +
 10.1247 +}
 10.1248 +
 10.1249 +static void
 10.1250 +DirectFB_MaximizeWindow(_THIS, SDL_Window * window)
 10.1251 +{
 10.1252 +    SDL_DFB_DEVICEDATA(_this);
 10.1253 +    SDL_DFB_WINDOWDATA(window);
 10.1254 +    SDL_DFB_DISPLAYDATA(_this, window);
 10.1255 +
 10.1256 +    SDL_Unsupported();
 10.1257 +
 10.1258 +}
 10.1259 +static void
 10.1260 +DirectFB_MinimizeWindow(_THIS, SDL_Window * window)
 10.1261 +{
 10.1262 +    SDL_DFB_DEVICEDATA(_this);
 10.1263 +    SDL_DFB_WINDOWDATA(window);
 10.1264 +    SDL_DFB_DISPLAYDATA(_this, window);
 10.1265 +
 10.1266 +    SDL_Unsupported();
 10.1267 +
 10.1268 +}
 10.1269 +
 10.1270 +static void
 10.1271 +DirectFB_RestoreWindow(_THIS, SDL_Window * window)
 10.1272 +{
 10.1273 +    SDL_DFB_DEVICEDATA(_this);
 10.1274 +    SDL_DFB_WINDOWDATA(window);
 10.1275 +    SDL_DFB_DISPLAYDATA(_this, window);
 10.1276 +
 10.1277 +    SDL_Unsupported();
 10.1278 +
 10.1279 +}
 10.1280 +static void
 10.1281 +DirectFB_SetWindowGrab(_THIS, SDL_Window * window)
 10.1282 +{
 10.1283 +    SDL_DFB_DEVICEDATA(_this);
 10.1284 +    SDL_DFB_WINDOWDATA(window);
 10.1285 +    SDL_DFB_DISPLAYDATA(_this, window);
 10.1286 +
 10.1287 +    SDL_Unsupported();
 10.1288 +
 10.1289 +}
 10.1290 +
 10.1291 +static void
 10.1292 +DirectFB_DestroyWindow(_THIS, SDL_Window * window)
 10.1293 +{
 10.1294 +    SDL_DFB_DEVICEDATA(_this);
 10.1295 +    SDL_DFB_WINDOWDATA(window);
 10.1296 +    SDL_DFB_DISPLAYDATA(_this, window);
 10.1297 +    DFB_WindowData *p;
 10.1298 +
 10.1299 +    SDL_DFB_DEBUG("Trace\n");
 10.1300 +
 10.1301 +    SDL_DFB_RELEASE(windata->palette);
 10.1302 +    SDL_DFB_RELEASE(windata->eventbuffer);
 10.1303 +    SDL_DFB_RELEASE(windata->surface);
 10.1304 +    SDL_DFB_RELEASE(windata->window);
 10.1305 +
 10.1306 +    /* Remove from list ... */
 10.1307 +
 10.1308 +    p = devdata->firstwin;
 10.1309 +    while (p && p->next != windata)
 10.1310 +        p = p->next;
 10.1311 +    if (p)
 10.1312 +        p->next = windata->next;
 10.1313 +    else
 10.1314 +        devdata->firstwin = windata->next;
 10.1315 +    SDL_free(windata);
 10.1316 +}
 10.1317 +static SDL_bool
 10.1318 +DirectFB_GetWindowWMInfo(_THIS, SDL_Window * window,
 10.1319 +                         struct SDL_SysWMinfo *info)
 10.1320 +{
 10.1321 +    SDL_DFB_DEVICEDATA(_this);
 10.1322 +    SDL_DFB_WINDOWDATA(window);
 10.1323 +    SDL_DFB_DISPLAYDATA(_this, window);
 10.1324 +
 10.1325 +    SDL_Unsupported();
 10.1326 +    return SDL_FALSE;
 10.1327 +}
 10.1328 +
 10.1329 +#if SDL_DIRECTFB_OPENGL
 10.1330 +
 10.1331 +#define OPENGL_REQUIRS_DLOPEN
 10.1332 +#if defined(OPENGL_REQUIRS_DLOPEN) && defined(SDL_LOADSO_DLOPEN)
 10.1333 +#include <dlfcn.h>
 10.1334 +#define GL_LoadObject(X)	dlopen(X, (RTLD_NOW|RTLD_GLOBAL))
 10.1335 +#define GL_LoadFunction		dlsym
 10.1336 +#define GL_UnloadObject		dlclose
 10.1337 +#else
 10.1338 +#define GL_LoadObject	SDL_LoadObject
 10.1339 +#define GL_LoadFunction	SDL_LoadFunction
 10.1340 +#define GL_UnloadObject	SDL_UnloadObject
 10.1341 +#endif
 10.1342 +
 10.1343 +static int
 10.1344 +DirectFB_GL_LoadLibrary(_THIS, const char *path)
 10.1345 +{
 10.1346 +    SDL_DFB_DEVICEDATA(_this);
 10.1347 +#
 10.1348 +    void *handle = NULL;
 10.1349 +
 10.1350 +    SDL_DFB_DEBUG("Loadlibrary : %s\n", path);
 10.1351 +
 10.1352 +    if (_this->gl_data->gl_active) {
 10.1353 +        SDL_SetError("OpenGL context already created");
 10.1354 +        return -1;
 10.1355 +    }
 10.1356 +
 10.1357 +
 10.1358 +    if (path == NULL) {
 10.1359 +        path = SDL_getenv("SDL_VIDEO_GL_DRIVER");
 10.1360 +        if (path == NULL) {
 10.1361 +            path = "libGL.so";
 10.1362          }
 10.1363      }
 10.1364  
 10.1365 -    /* Set cooperative level depending on flag SDL_FULLSCREEN */
 10.1366 -    if (flags & SDL_FULLSCREEN) {
 10.1367 -        ret = HIDDEN->dfb->SetCooperativeLevel(HIDDEN->dfb, DFSCL_FULLSCREEN);
 10.1368 -        if (ret && !HIDDEN->enable_mga_crtc2) {
 10.1369 -            DirectFBError("dfb->SetCooperativeLevel", ret);
 10.1370 -            flags &= ~SDL_FULLSCREEN;
 10.1371 -        }
 10.1372 -    } else
 10.1373 -        HIDDEN->dfb->SetCooperativeLevel(HIDDEN->dfb, DFSCL_NORMAL);
 10.1374 -
 10.1375 -    /* Set video mode */
 10.1376 -    ret = HIDDEN->dfb->SetVideoMode(HIDDEN->dfb, width, height, bpp);
 10.1377 -    if (ret) {
 10.1378 -        if (flags & SDL_FULLSCREEN) {
 10.1379 -            flags &= ~SDL_FULLSCREEN;
 10.1380 -            HIDDEN->dfb->SetCooperativeLevel(HIDDEN->dfb, DFSCL_NORMAL);
 10.1381 -            ret = HIDDEN->dfb->SetVideoMode(HIDDEN->dfb, width, height, bpp);
 10.1382 -        }
 10.1383 -
 10.1384 -        if (ret) {
 10.1385 -            SetDirectFBerror("dfb->SetVideoMode", ret);
 10.1386 -            return NULL;
 10.1387 -        }
 10.1388 -    }
 10.1389 -
 10.1390 -    /* Create primary surface */
 10.1391 -    dsc.flags = DSDESC_CAPS | DSDESC_PIXELFORMAT;
 10.1392 -    dsc.caps =
 10.1393 -        DSCAPS_PRIMARY | ((flags & SDL_DOUBLEBUF) ? DSCAPS_FLIPPING : 0);
 10.1394 -    dsc.pixelformat = GetFormatForBpp(bpp, HIDDEN->layer);
 10.1395 -
 10.1396 -    ret = HIDDEN->dfb->CreateSurface(HIDDEN->dfb, &dsc, &surface);
 10.1397 -    if (ret && (flags & SDL_DOUBLEBUF)) {
 10.1398 -        /* Try without double buffering */
 10.1399 -        dsc.caps &= ~DSCAPS_FLIPPING;
 10.1400 -        ret = HIDDEN->dfb->CreateSurface(HIDDEN->dfb, &dsc, &surface);
 10.1401 -    }
 10.1402 -    if (ret) {
 10.1403 -        SetDirectFBerror("dfb->CreateSurface", ret);
 10.1404 -        return NULL;
 10.1405 -    }
 10.1406 -
 10.1407 -    current->w = width;
 10.1408 -    current->h = height;
 10.1409 -    current->flags = SDL_HWSURFACE | SDL_PREALLOC;
 10.1410 -
 10.1411 -    if (flags & SDL_FULLSCREEN) {
 10.1412 -        current->flags |= SDL_FULLSCREEN;
 10.1413 -        this->UpdateRects = DirectFB_DirectUpdate;
 10.1414 -    } else
 10.1415 -        this->UpdateRects = DirectFB_WindowedUpdate;
 10.1416 -
 10.1417 -    if (dsc.caps & DSCAPS_FLIPPING)
 10.1418 -        current->flags |= SDL_DOUBLEBUF;
 10.1419 -
 10.1420 -    surface->GetPixelFormat(surface, &pixelformat);
 10.1421 -
 10.1422 -    DFBToSDLPixelFormat(pixelformat, current->format);
 10.1423 -
 10.1424 -    /* Get the surface palette (if supported) */
 10.1425 -    if (DFB_PIXELFORMAT_IS_INDEXED(pixelformat)) {
 10.1426 -        surface->GetPalette(surface, &current->hwdata->palette);
 10.1427 -
 10.1428 -        current->flags |= SDL_HWPALETTE;
 10.1429 -    }
 10.1430 -
 10.1431 -    current->hwdata->surface = surface;
 10.1432 -
 10.1433 -    /* MGA CRTC2 stuff */
 10.1434 -    if (HIDDEN->enable_mga_crtc2) {
 10.1435 -        /* no stretching if c2ssize == c2framesize */
 10.1436 -        HIDDEN->c2ssize.x = 0, HIDDEN->c2ssize.y = 0;
 10.1437 -        HIDDEN->c2ssize.w = width;
 10.1438 -        HIDDEN->c2ssize.h = height;
 10.1439 -
 10.1440 -        HIDDEN->c2dsize.x = 0, HIDDEN->c2dsize.y = 0;
 10.1441 -        HIDDEN->c2dsize.w = width;
 10.1442 -        HIDDEN->c2dsize.h = height;
 10.1443 -
 10.1444 -        HIDDEN->mga_crtc2_stretch = 0;
 10.1445 -
 10.1446 -        if (SDL_getenv("SDL_DIRECTFB_MGA_STRETCH") != NULL) {
 10.1447 -            /* Normally assume a picture aspect ratio of 4:3 */
 10.1448 -            int zoom_aspect_x = 4, zoom_aspect_y = 3, i, j;
 10.1449 -
 10.1450 -            for (i = 1; i < 20; i++) {
 10.1451 -                for (j = 1; j < 10; j++) {
 10.1452 -                    if ((float) width / (float) i * (float) j == height) {
 10.1453 -                        zoom_aspect_x = i;
 10.1454 -                        zoom_aspect_y = j;
 10.1455 -
 10.1456 -                        /* break the loop */
 10.1457 -                        i = 21;
 10.1458 -                        break;
 10.1459 -                    }
 10.1460 -                }
 10.1461 -            }
 10.1462 -
 10.1463 -#ifdef DIRECTFB_CRTC2_DEBUG
 10.1464 -            printf
 10.1465 -                ("Source resolution: X: %d, Y: %d, Aspect ratio: %d:%d\n",
 10.1466 -                 width, height, zoom_aspect_x, zoom_aspect_y);
 10.1467 -            printf("CRTC2 resolution: X: %d, Y: %d\n",
 10.1468 -                   HIDDEN->c2framesize.w, HIDDEN->c2framesize.h);
 10.1469 -#endif
 10.1470 -
 10.1471 -            /* don't stretch only slightly smaller/larger images */
 10.1472 -            if ((float) width < (float) HIDDEN->c2framesize.w * 0.95
 10.1473 -                || (float) height < (float) HIDDEN->c2framesize.h * 0.95) {
 10.1474 -                while ((float) HIDDEN->c2dsize.w <
 10.1475 -                       (float) HIDDEN->c2framesize.w *
 10.1476 -                       HIDDEN->mga_crtc2_stretch_overscan
 10.1477 -                       && (float) HIDDEN->c2dsize.h <
 10.1478 -                       (float) HIDDEN->c2framesize.h *
 10.1479 -                       HIDDEN->mga_crtc2_stretch_overscan) {
 10.1480 -                    HIDDEN->c2dsize.w += zoom_aspect_x;
 10.1481 -                    HIDDEN->c2dsize.h += zoom_aspect_y;
 10.1482 -                }
 10.1483 -
 10.1484 -                /* one step down */
 10.1485 -                HIDDEN->c2dsize.w -= zoom_aspect_x;
 10.1486 -                HIDDEN->c2dsize.h -= zoom_aspect_y;
 10.1487 -
 10.1488 -#ifdef DIRECTFB_CRTC2_DEBUG
 10.1489 -                printf("Stretched resolution: X: %d, Y: %d\n",
 10.1490 -                       HIDDEN->c2dsize.w, HIDDEN->c2dsize.h);
 10.1491 -#endif
 10.1492 -
 10.1493 -                HIDDEN->mga_crtc2_stretch = 1;
 10.1494 -            } else if ((float) width > (float) HIDDEN->c2framesize.w * 0.95
 10.1495 -                       || (float) height >
 10.1496 -                       (float) HIDDEN->c2framesize.h * 0.95) {
 10.1497 -                while ((float) HIDDEN->c2dsize.w >
 10.1498 -                       (float) HIDDEN->c2framesize.w *
 10.1499 -                       HIDDEN->mga_crtc2_stretch_overscan
 10.1500 -                       || (float) HIDDEN->c2dsize.h >
 10.1501 -                       (float) HIDDEN->c2framesize.h *
 10.1502 -                       HIDDEN->mga_crtc2_stretch_overscan) {
 10.1503 -                    HIDDEN->c2dsize.w -= zoom_aspect_x;
 10.1504 -                    HIDDEN->c2dsize.h -= zoom_aspect_y;
 10.1505 -                }
 10.1506 -
 10.1507 -#ifdef DIRECTFB_CRTC2_DEBUG
 10.1508 -                printf("Down-Stretched resolution: X: %d, Y: %d\n",
 10.1509 -                       HIDDEN->c2dsize.w, HIDDEN->c2dsize.h);
 10.1510 -#endif
 10.1511 -
 10.1512 -                HIDDEN->mga_crtc2_stretch = 1;
 10.1513 -            } else {
 10.1514 -#ifdef DIRECTFB_CRTC2_DEBUG
 10.1515 -                printf("Not stretching image\n");
 10.1516 -#endif
 10.1517 -            }
 10.1518 -
 10.1519 -            /* Panning */
 10.1520 -            if (HIDDEN->c2framesize.w > HIDDEN->c2dsize.w)
 10.1521 -                HIDDEN->c2dsize.x =
 10.1522 -                    (HIDDEN->c2framesize.w - HIDDEN->c2dsize.w) / 2;
 10.1523 -            else
 10.1524 -                HIDDEN->c2dsize.x =
 10.1525 -                    (HIDDEN->c2dsize.w - HIDDEN->c2framesize.w) / 2;
 10.1526 -
 10.1527 -            if (HIDDEN->c2framesize.h > HIDDEN->c2dsize.h)
 10.1528 -                HIDDEN->c2dsize.y =
 10.1529 -                    (HIDDEN->c2framesize.h - HIDDEN->c2dsize.h) / 2;
 10.1530 -            else
 10.1531 -                HIDDEN->c2dsize.y =
 10.1532 -                    (HIDDEN->c2dsize.h - HIDDEN->c2framesize.h) / 2;
 10.1533 -
 10.1534 -#ifdef DIRECTFB_CRTC2_DEBUG
 10.1535 -            printf("CRTC2 position X: %d, Y: %d\n", HIDDEN->c2dsize.x,
 10.1536 -                   HIDDEN->c2dsize.y);
 10.1537 -#endif
 10.1538 -        }
 10.1539 -    }
 10.1540 -
 10.1541 -    return current;
 10.1542 -}
 10.1543 -
 10.1544 -static int
 10.1545 -DirectFB_AllocHWSurface(_THIS, SDL_Surface * surface)
 10.1546 -{
 10.1547 -    DFBResult ret;
 10.1548 -    DFBSurfaceDescription dsc;
 10.1549 -
 10.1550 -    /*  fprintf(stderr, "SDL: DirectFB_AllocHWSurface (%dx%d@%d, flags: 0x%08x)\n",
 10.1551 -       surface->w, surface->h, surface->format->BitsPerPixel, surface->flags); */
 10.1552 -
 10.1553 -    if (surface->w < 8 || surface->h < 8)
 10.1554 -        return -1;
 10.1555 -
 10.1556 -    /* fill surface description */
 10.1557 -    dsc.flags =
 10.1558 -        DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS;
 10.1559 -    dsc.width = surface->w;
 10.1560 -    dsc.height = surface->h;
 10.1561 -    dsc.caps = (surface->flags & SDL_DOUBLEBUF) ? DSCAPS_FLIPPING : 0;
 10.1562 -
 10.1563 -    /* find the right pixelformat */
 10.1564 -    dsc.pixelformat = SDLToDFBPixelFormat(surface->format);
 10.1565 -    if (dsc.pixelformat == DSPF_UNKNOWN)
 10.1566 -        return -1;
 10.1567 -
 10.1568 -    /* Allocate the hardware acceleration data */
 10.1569 -    surface->hwdata =
 10.1570 -        (struct private_hwdata *) SDL_calloc(1, sizeof(*surface->hwdata));
 10.1571 -    if (surface->hwdata == NULL) {
 10.1572 -        SDL_OutOfMemory();
 10.1573 +    handle = GL_LoadObject(path);
 10.1574 +    if (handle == NULL) {
 10.1575 +        SDL_DFB_ERR("Library not found: %s\n", path);
 10.1576 +        /* SDL_LoadObject() will call SDL_SetError() for us. */
 10.1577          return -1;
 10.1578      }
 10.1579  
 10.1580 -    /* Create the surface */
 10.1581 -    ret =
 10.1582 -        HIDDEN->dfb->CreateSurface(HIDDEN->dfb, &dsc,
 10.1583 -                                   &surface->hwdata->surface);
 10.1584 -    if (ret) {
 10.1585 -        SetDirectFBerror("dfb->CreateSurface", ret);
 10.1586 -        free(surface->hwdata);
 10.1587 -        surface->hwdata = NULL;
 10.1588 -        return -1;
 10.1589 +    SDL_DFB_DEBUG("Loaded library: %s\n", path);
 10.1590 +
 10.1591 +    /* Unload the old driver and reset the pointers */
 10.1592 +    DirectFB_GL_UnloadLibrary(_this);
 10.1593 +
 10.1594 +    _this->gl_config.dll_handle = handle;
 10.1595 +    _this->gl_config.driver_loaded = 1;
 10.1596 +    if (path) {
 10.1597 +        SDL_strlcpy(_this->gl_config.driver_path, path,
 10.1598 +                    SDL_arraysize(_this->gl_config.driver_path));
 10.1599 +    } else {
 10.1600 +        *_this->gl_config.driver_path = '\0';
 10.1601      }
 10.1602  
 10.1603 -    surface->flags |= SDL_HWSURFACE | SDL_PREALLOC;
 10.1604 -
 10.1605 +    devdata->glFinish = DirectFB_GL_GetProcAddress(_this, "glFinish");
 10.1606 +    devdata->glFlush = DirectFB_GL_GetProcAddress(_this, "glFlush");
 10.1607      return 0;
 10.1608  }
 10.1609  
 10.1610  static void
 10.1611 -DirectFB_FreeHWSurface(_THIS, SDL_Surface * surface)
 10.1612 +DirectFB_GL_UnloadLibrary(_THIS)
 10.1613  {
 10.1614 -    if (surface->hwdata && HIDDEN->initialized) {
 10.1615 -        surface->hwdata->surface->Release(surface->hwdata->surface);
 10.1616 -        free(surface->hwdata);
 10.1617 -        surface->hwdata = NULL;
 10.1618 +    SDL_DFB_DEVICEDATA(_this);
 10.1619 +
 10.1620 +    int ret;
 10.1621 +
 10.1622 +    if (_this->gl_config.driver_loaded) {
 10.1623 +
 10.1624 +        ret = GL_UnloadObject(_this->gl_config.dll_handle);
 10.1625 +        if (ret)
 10.1626 +            SDL_DFB_ERR("Error #%d trying to unload library.\n", ret);
 10.1627 +        _this->gl_config.dll_handle = NULL;
 10.1628 +        _this->gl_config.driver_loaded = 0;
 10.1629      }
 10.1630  }
 10.1631  
 10.1632 -static int
 10.1633 -DirectFB_CheckHWBlit(_THIS, SDL_Surface * src, SDL_Surface * dst)
 10.1634 +static void *
 10.1635 +DirectFB_GL_GetProcAddress(_THIS, const char *proc)
 10.1636  {
 10.1637 -    /*  fprintf(stderr, "SDL: DirectFB_CheckHWBlit (src->hwdata: %p, dst->hwdata: %p)\n",
 10.1638 -       src->hwdata, dst->hwdata); */
 10.1639 +    SDL_DFB_DEVICEDATA(_this);
 10.1640 +    int ret;
 10.1641 +    void *handle;
 10.1642  
 10.1643 -    if (!src->hwdata || !dst->hwdata)
 10.1644 -        return 0;
 10.1645 +    SDL_DFB_DEBUG("Trace %s\n", proc);
 10.1646 +    handle = _this->gl_config.dll_handle;
 10.1647 +    return GL_LoadFunction(handle, proc);
 10.1648 +}
 10.1649  
 10.1650 -    src->flags |= SDL_HWACCEL;
 10.1651 -    src->map->hw_blit = DirectFB_HWAccelBlit;
 10.1652 +static SDL_GLContext
 10.1653 +DirectFB_GL_CreateContext(_THIS, SDL_Window * window)
 10.1654 +{
 10.1655 +    SDL_DFB_DEVICEDATA(_this);
 10.1656 +    SDL_DFB_WINDOWDATA(window);
 10.1657 +    SDL_DFB_DISPLAYDATA(_this, window);
 10.1658 +    int ret;
 10.1659 +    IDirectFBGL *context = NULL;
 10.1660  
 10.1661 -    return 1;
 10.1662 +    SDL_DFB_DEBUG("Trace\n");
 10.1663 +    SDL_DFB_CHECKERR(windata->surface->GetGL(windata->surface, &context));
 10.1664 +    SDL_DFB_CHECKERR(context->Unlock(context));
 10.1665 +
 10.1666 +    if (DirectFB_GL_MakeCurrent(_this, window, context) < 0) {
 10.1667 +        DirectFB_GL_DeleteContext(_this, context);
 10.1668 +        return NULL;
 10.1669 +    }
 10.1670 +
 10.1671 +    return context;
 10.1672 +
 10.1673 +  error:
 10.1674 +    return NULL;
 10.1675  }
 10.1676  
 10.1677  static int
 10.1678 -DirectFB_HWAccelBlit(SDL_Surface * src, SDL_Rect * srcrect,
 10.1679 -                     SDL_Surface * dst, SDL_Rect * dstrect)
 10.1680 +DirectFB_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
 10.1681  {
 10.1682 -    DFBSurfaceBlittingFlags flags = DSBLIT_NOFX;
 10.1683 +    SDL_DFB_DEVICEDATA(_this);
 10.1684 +    SDL_DFB_WINDOWDATA(window);
 10.1685 +    SDL_DFB_DISPLAYDATA(_this, window);
 10.1686 +    IDirectFBGL *dfb_context = (IDirectFBGL *) context;
 10.1687 +    int ret;
 10.1688  
 10.1689 -    DFBRectangle sr = { srcrect->x, srcrect->y, srcrect->w, srcrect->h };
 10.1690 -    DFBRectangle dr = { dstrect->x, dstrect->y, dstrect->w, dstrect->h };
 10.1691 -
 10.1692 -    IDirectFBSurface *surface = dst->hwdata->surface;
 10.1693 -
 10.1694 -    if (src->flags & SDL_SRCCOLORKEY) {
 10.1695 -        flags |= DSBLIT_SRC_COLORKEY;
 10.1696 -        DirectFB_SetHWColorKey(NULL, src, src->format->colorkey);
 10.1697 +    if (dfb_context) {
 10.1698 +        dfb_context->Unlock(dfb_context);
 10.1699 +        SDL_DFB_CHECKERR(dfb_context->Lock(dfb_context));
 10.1700      }
 10.1701 -
 10.1702 -    if (src->flags & SDL_SRCALPHA) {
 10.1703 -        flags |= DSBLIT_BLEND_COLORALPHA;
 10.1704 -        surface->SetColor(surface, 0xff, 0xff, 0xff, src->format->alpha);
 10.1705 -    }
 10.1706 -
 10.1707 -    surface->SetBlittingFlags(surface, flags);
 10.1708 -
 10.1709 -    if (sr.w == dr.w && sr.h == dr.h)
 10.1710 -        surface->Blit(surface, src->hwdata->surface, &sr, dr.x, dr.y);
 10.1711 -    else
 10.1712 -        surface->StretchBlit(surface, src->hwdata->surface, &sr, &dr);
 10.1713 +    if (windata)
 10.1714 +        windata->gl_context = dfb_context;
 10.1715  
 10.1716      return 0;
 10.1717 +  error:
 10.1718 +    return -1;
 10.1719  }
 10.1720  
 10.1721  static int
 10.1722 -DirectFB_FillHWRect(_THIS, SDL_Surface * dst, SDL_Rect * dstrect,
 10.1723 -                    Uint32 color)
 10.1724 +DirectFB_GL_SetSwapInterval(_THIS, int interval)
 10.1725  {
 10.1726 -    SDL_PixelFormat *fmt = dst->format;
 10.1727 -    IDirectFBSurface *surface = dst->hwdata->surface;
 10.1728 +    SDL_DFB_DEVICEDATA(_this);
 10.1729  
 10.1730 -    /* ugly */
 10.1731 -    surface->SetColor(surface,
 10.1732 -                      (color & fmt->Rmask) >> (fmt->Rshift - fmt->Rloss),
 10.1733 -                      (color & fmt->Gmask) >> (fmt->Gshift - fmt->Gloss),
 10.1734 -                      (color & fmt->Bmask) << (fmt->Bloss - fmt->Bshift),
 10.1735 -                      0xFF);
 10.1736 -    surface->FillRectangle(surface, dstrect->x, dstrect->y, dstrect->w,
 10.1737 -                           dstrect->h);
 10.1738 +    SDL_Unsupported();
 10.1739 +    return -1;
 10.1740  
 10.1741 -    return 0;
 10.1742  }
 10.1743  
 10.1744  static int
 10.1745 -DirectFB_SetHWColorKey(_THIS, SDL_Surface * src, Uint32 key)
 10.1746 +DirectFB_GL_GetSwapInterval(_THIS)
 10.1747  {
 10.1748 -    SDL_PixelFormat *fmt = src->format;
 10.1749 -    IDirectFBSurface *surface = src->hwdata->surface;
 10.1750 +    SDL_DFB_DEVICEDATA(_this);
 10.1751  
 10.1752 -    if (fmt->BitsPerPixel == 8)
 10.1753 -        surface->SetSrcColorKeyIndex(surface, key);
 10.1754 -    else
 10.1755 -        /* ugly */
 10.1756 -        surface->SetSrcColorKey(surface,
 10.1757 -                                (key & fmt->Rmask) >> (fmt->Rshift -
 10.1758 -                                                       fmt->Rloss),
 10.1759 -                                (key & fmt->Gmask) >> (fmt->Gshift -
 10.1760 -                                                       fmt->Gloss),
 10.1761 -                                (key & fmt->Bmask) << (fmt->Bloss -
 10.1762 -                                                       fmt->Bshift));
 10.1763 +    SDL_Unsupported();
 10.1764 +    return -1;
 10.1765  
 10.1766 -    return 0;
 10.1767 -}
 10.1768 -
 10.1769 -static int
 10.1770 -DirectFB_SetHWAlpha(_THIS, SDL_Surface * surface, Uint8 alpha)
 10.1771 -{
 10.1772 -    return 0;
 10.1773 -}
 10.1774 -
 10.1775 -static int
 10.1776 -DirectFB_FlipHWSurface(_THIS, SDL_Surface * surface)
 10.1777 -{
 10.1778 -    if (HIDDEN->enable_mga_crtc2) {
 10.1779 -        int rtn =
 10.1780 -            surface->hwdata->surface->Flip(surface->hwdata->surface, NULL,
 10.1781 -                                           0);
 10.1782 -        if (HIDDEN->mga_crtc2_stretch)
 10.1783 -            HIDDEN->c2frame->StretchBlit(HIDDEN->c2frame,
 10.1784 -                                         surface->hwdata->surface,
 10.1785 -                                         &HIDDEN->c2ssize, &HIDDEN->c2dsize);
 10.1786 -        else
 10.1787 -            HIDDEN->c2frame->Blit(HIDDEN->c2frame,
 10.1788 -                                  surface->hwdata->surface, NULL,
 10.1789 -                                  HIDDEN->c2dsize.x, HIDDEN->c2dsize.y);
 10.1790 -
 10.1791 -        HIDDEN->c2frame->Flip(HIDDEN->c2frame, NULL, DSFLIP_WAITFORSYNC);
 10.1792 -        return rtn;
 10.1793 -    } else
 10.1794 -        return surface->hwdata->surface->Flip(surface->hwdata->surface, NULL,
 10.1795 -                                              DSFLIP_WAITFORSYNC);
 10.1796 -}
 10.1797 -
 10.1798 -static int
 10.1799 -DirectFB_LockHWSurface(_THIS, SDL_Surface * surface)
 10.1800 -{
 10.1801 -    DFBResult ret;
 10.1802 -    void *data;
 10.1803 -    int pitch;
 10.1804 -
 10.1805 -    ret = surface->hwdata->surface->Lock(surface->hwdata->surface,
 10.1806 -                                         DSLF_WRITE, &data, &pitch);
 10.1807 -    if (ret) {
 10.1808 -        SetDirectFBerror("surface->Lock", ret);
 10.1809 -        return -1;
 10.1810 -    }
 10.1811 -
 10.1812 -    surface->pixels = data;
 10.1813 -    surface->pitch = pitch;
 10.1814 -
 10.1815 -    return 0;
 10.1816  }
 10.1817  
 10.1818  static void
 10.1819 -DirectFB_UnlockHWSurface(_THIS, SDL_Surface * surface)
 10.1820 +DirectFB_GL_SwapWindow(_THIS, SDL_Window * window)
 10.1821  {
 10.1822 -    surface->hwdata->surface->Unlock(surface->hwdata->surface);
 10.1823 -    surface->pixels = NULL;
 10.1824 +    SDL_DFB_DEVICEDATA(_this);
 10.1825 +    SDL_DFB_WINDOWDATA(window);
 10.1826 +    SDL_DFB_DISPLAYDATA(_this, window);
 10.1827 +    int ret;
 10.1828 +    void *p;
 10.1829 +    int pitch;
 10.1830 +    DFBRegion region;
 10.1831 +
 10.1832 +    region.x1 = 0;
 10.1833 +    region.y1 = 0;
 10.1834 +    region.x2 = window->w;
 10.1835 +    region.y2 = window->h;
 10.1836 +
 10.1837 +    if (devdata->glFinish)
 10.1838 +        devdata->glFinish();
 10.1839 +    else if (devdata->glFlush)
 10.1840 +        devdata->glFlush();
 10.1841 +
 10.1842 +    SDL_DFB_CHECKERR(windata->gl_context->Unlock(windata->gl_context));
 10.1843 +    SDL_DFB_CHECKERR(windata->surface->
 10.1844 +                     Flip(windata->surface, &region, DSFLIP_ONSYNC));
 10.1845 +    SDL_DFB_CHECKERR(windata->gl_context->Lock(windata->gl_context));
 10.1846 +
 10.1847 +    return;
 10.1848 +  error:
 10.1849 +    return;
 10.1850  }
 10.1851  
 10.1852  static void
 10.1853 -DirectFB_DirectUpdate(_THIS, int numrects, SDL_Rect * rects)
 10.1854 +DirectFB_GL_DeleteContext(_THIS, SDL_GLContext context)
 10.1855  {
 10.1856 -    if (HIDDEN->enable_mga_crtc2) {
 10.1857 -        if (HIDDEN->mga_crtc2_stretch)
 10.1858 -            HIDDEN->c2frame->StretchBlit(HIDDEN->c2frame,
 10.1859 -                                         this->screen->hwdata->surface,
 10.1860 -                                         &HIDDEN->c2ssize, &HIDDEN->c2dsize);
 10.1861 -        else
 10.1862 -            HIDDEN->c2frame->Blit(HIDDEN->c2frame,
 10.1863 -                                  this->screen->hwdata->surface, NULL,
 10.1864 -                                  HIDDEN->c2dsize.x, HIDDEN->c2dsize.y);
 10.1865 +    IDirectFBGL *dfb_context = (IDirectFBGL *) context;
 10.1866 +    SDL_DFB_DEVICEDATA(_this);
 10.1867  
 10.1868 -        HIDDEN->c2frame->Flip(HIDDEN->c2frame, NULL, DSFLIP_WAITFORSYNC);
 10.1869 -    }
 10.1870 +    dfb_context->Unlock(dfb_context);
 10.1871 +    dfb_context->Release(dfb_context);
 10.1872  }
 10.1873  
 10.1874 -static void
 10.1875 -DirectFB_WindowedUpdate(_THIS, int numrects, SDL_Rect * rects)
 10.1876 -{
 10.1877 -    DFBRegion region;
 10.1878 -    int i;
 10.1879 -    int region_valid = 0;
 10.1880 -    IDirectFBSurface *surface = this->screen->hwdata->surface;
 10.1881 -
 10.1882 -    for (i = 0; i < numrects; ++i) {
 10.1883 -        int x2, y2;
 10.1884 -
 10.1885 -        if (!rects[i].w)        /* Clipped? */
 10.1886 -            continue;
 10.1887 -
 10.1888 -        x2 = rects[i].x + rects[i].w - 1;
 10.1889 -        y2 = rects[i].y + rects[i].h - 1;
 10.1890 -
 10.1891 -        if (region_valid) {
 10.1892 -            if (rects[i].x < region.x1)
 10.1893 -                region.x1 = rects[i].x;
 10.1894 -
 10.1895 -            if (rects[i].y < region.y1)
 10.1896 -                region.y1 = rects[i].y;
 10.1897 -
 10.1898 -            if (x2 > region.x2)
 10.1899 -                region.x2 = x2;
 10.1900 -
 10.1901 -            if (y2 > region.y2)
 10.1902 -                region.y2 = y2;
 10.1903 -        } else {
 10.1904 -            region.x1 = rects[i].x;
 10.1905 -            region.y1 = rects[i].y;
 10.1906 -            region.x2 = x2;
 10.1907 -            region.y2 = y2;
 10.1908 -
 10.1909 -            region_valid = 1;
 10.1910 -        }
 10.1911 -    }
 10.1912 -
 10.1913 -    if (region_valid) {
 10.1914 -        if (HIDDEN->enable_mga_crtc2) {
 10.1915 -            if (HIDDEN->mga_crtc2_stretch)
 10.1916 -                HIDDEN->c2frame->StretchBlit(HIDDEN->c2frame, surface,
 10.1917 -                                             &HIDDEN->c2ssize,
 10.1918 -                                             &HIDDEN->c2dsize);
 10.1919 -            else
 10.1920 -                HIDDEN->c2frame->Blit(HIDDEN->c2frame, surface, NULL,
 10.1921 -                                      HIDDEN->c2dsize.x, HIDDEN->c2dsize.y);
 10.1922 -
 10.1923 -            HIDDEN->c2frame->Flip(HIDDEN->c2frame, NULL, DSFLIP_WAITFORSYNC);
 10.1924 -        } else
 10.1925 -            surface->Flip(surface, &region, DSFLIP_WAITFORSYNC);
 10.1926 -    }
 10.1927 -}
 10.1928 -
 10.1929 -int
 10.1930 -DirectFB_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors)
 10.1931 -{
 10.1932 -    IDirectFBPalette *palette = this->screen->hwdata->palette;
 10.1933 -
 10.1934 -    if (!palette)
 10.1935 -        return 0;
 10.1936 -
 10.1937 -    if (firstcolor > 255)
 10.1938 -        return 0;
 10.1939 -
 10.1940 -    if (firstcolor + ncolors > 256)
 10.1941 -        ncolors = 256 - firstcolor;
 10.1942 -
 10.1943 -    if (ncolors > 0) {
 10.1944 -        int i;
 10.1945 -        DFBColor entries[ncolors];
 10.1946 -
 10.1947 -        for (i = 0; i < ncolors; i++) {
 10.1948 -            entries[i].a = 0xff;
 10.1949 -            entries[i].r = colors[i].r;
 10.1950 -            entries[i].g = colors[i].g;
 10.1951 -            entries[i].b = colors[i].b;
 10.1952 -        }
 10.1953 -
 10.1954 -        palette->SetEntries(palette, entries, ncolors, firstcolor);
 10.1955 -    }
 10.1956 -
 10.1957 -    return 1;
 10.1958 -}
 10.1959 -
 10.1960 -void
 10.1961 -DirectFB_VideoQuit(_THIS)
 10.1962 -{
 10.1963 -    struct DirectFBEnumRect *rect = enumlist;
 10.1964 -
 10.1965 -    if (this->screen && this->screen->hwdata) {
 10.1966 -        IDirectFBSurface *surface = this->screen->hwdata->surface;
 10.1967 -        IDirectFBPalette *palette = this->screen->hwdata->palette;
 10.1968 -
 10.1969 -        if (palette)
 10.1970 -            palette->Release(palette);
 10.1971 -
 10.1972 -        if (surface)
 10.1973 -            surface->Release(surface);
 10.1974 -
 10.1975 -        this->screen->hwdata->surface = NULL;
 10.1976 -        this->screen->hwdata->palette = NULL;
 10.1977 -    }
 10.1978 -
 10.1979 -    if (HIDDEN->c2frame) {
 10.1980 -        HIDDEN->c2frame->Release(HIDDEN->c2frame);
 10.1981 -        HIDDEN->c2frame = NULL;
 10.1982 -    }
 10.1983 -
 10.1984 -    if (HIDDEN->eventbuffer) {
 10.1985 -        HIDDEN->eventbuffer->Release(HIDDEN->eventbuffer);
 10.1986 -        HIDDEN->eventbuffer = NULL;
 10.1987 -    }
 10.1988 -
 10.1989 -    if (HIDDEN->c2layer) {
 10.1990 -        HIDDEN->c2layer->Release(HIDDEN->c2layer);
 10.1991 -        HIDDEN->c2layer = NULL;
 10.1992 -    }
 10.1993 -
 10.1994 -    if (HIDDEN->layer) {
 10.1995 -        HIDDEN->layer->Release(HIDDEN->layer);
 10.1996 -        HIDDEN->layer = NULL;
 10.1997 -    }
 10.1998 -
 10.1999 -    if (HIDDEN->dfb) {
 10.2000 -        HIDDEN->dfb->Release(HIDDEN->dfb);
 10.2001 -        HIDDEN->dfb = NULL;
 10.2002 -    }
 10.2003 -
 10.2004 -    /* Free video mode list */
 10.2005 -    if (HIDDEN->modelist) {
 10.2006 -        free(HIDDEN->modelist);
 10.2007 -        HIDDEN->modelist = NULL;
 10.2008 -    }
 10.2009 -
 10.2010 -    /* Free mode enumeration list */
 10.2011 -    while (rect) {
 10.2012 -        struct DirectFBEnumRect *next = rect->next;
 10.2013 -        free(rect);
 10.2014 -        rect = next;
 10.2015 -    }
 10.2016 -    enumlist = NULL;
 10.2017 -
 10.2018 -    HIDDEN->initialized = 0;
 10.2019 -}
 10.2020 -
 10.2021 -
 10.2022 -int
 10.2023 -DirectFB_ShowWMCursor(_THIS, WMcursor * cursor)
 10.2024 -{
 10.2025 -    /* We can only hide or show the default cursor */
 10.2026 -    if (cursor == NULL) {
 10.2027 -        HIDDEN->layer->SetCursorOpacity(HIDDEN->layer, 0x00);
 10.2028 -    } else {
 10.2029 -        HIDDEN->layer->SetCursorOpacity(HIDDEN->layer, 0xFF);
 10.2030 -    }
 10.2031 -    return 1;
 10.2032 -}
 10.2033 -
 10.2034 -void
 10.2035 -DirectFB_FinalQuit(void)
 10.2036 -{
 10.2037 -}
 10.2038 -
 10.2039 -/* vi: set ts=4 sw=4 expandtab: */
 10.2040 +#endif
    11.1 --- a/src/video/directfb/SDL_DirectFB_video.h	Sat Aug 11 21:44:49 2007 +0000
    11.2 +++ b/src/video/directfb/SDL_DirectFB_video.h	Sat Aug 11 21:51:19 2007 +0000
    11.3 @@ -25,39 +25,155 @@
    11.4  #define _SDL_DirectFB_video_h
    11.5  
    11.6  #include <directfb.h>
    11.7 +#include <directfb_version.h>
    11.8 +
    11.9 +#define LOG_CHANNEL 	stdout
   11.10 +
   11.11 +#if (DIRECTFB_MAJOR_VERSION == 0) && (DIRECTFB_MINOR_VERSION == 9) && (DIRECTFB_MICRO_VERSION < 23)
   11.12 +#error "SDL_DIRECTFB: Please compile against libdirectfb version >=0.9.24"
   11.13 +#endif
   11.14 +
   11.15 +#if (DIRECTFB_MAJOR_VERSION >= 1) && (DIRECTFB_MINOR_VERSION >= 0) && (DIRECTFB_MICRO_VERSION >= 0 )
   11.16 +#define SDL_DIRECTFB_OPENGL 1
   11.17 +#include <directfbgl.h>
   11.18 +#endif
   11.19 +
   11.20 +#if SDL_DIRECTFB_OPENGL
   11.21 +#include "SDL_loadso.h"
   11.22 +#endif
   11.23  
   11.24  #include "SDL_mouse.h"
   11.25  #include "../SDL_sysvideo.h"
   11.26  
   11.27 -#define _THIS SDL_VideoDevice *this
   11.28 +#define DEBUG 1
   11.29 +
   11.30 +#define SDL_DFB_RELEASE(x) do { if ( x ) { x->Release(x); x = NULL; } } while (0)
   11.31 +#define SDL_DFB_FREE(x) do { if ( x ) { SDL_free(x); x = NULL; } } while (0)
   11.32 +#define SDL_DFB_UNLOCK(x) do { if ( x ) { x->Unlock(x); } } while (0)
   11.33 +
   11.34 +#if DEBUG
   11.35 +#define SDL_DFB_DEBUG(x...) do { fprintf(LOG_CHANNEL, "%s:", __FUNCTION__); fprintf(LOG_CHANNEL, x); } while (0)
   11.36 +#define SDL_DFB_DEBUGC(x...) do { fprintf(LOG_CHANNEL, x); } while (0)
   11.37 +#else
   11.38 +#define SDL_DFB_DEBUG(x...) do { } while (0)
   11.39 +#define SDL_DFB_DEBUGC(x...) do { } while (0)
   11.40 +#endif
   11.41 +
   11.42 +#define SDL_DFB_CONTEXT "SDL_DirectFB"
   11.43 +
   11.44 +#define SDL_DFB_ERR(x...) 							\
   11.45 +	do {											\
   11.46 +		fprintf(LOG_CHANNEL, "%s: %s <%d>:\n\t",			\
   11.47 +			SDL_DFB_CONTEXT, __FILE__, __LINE__ );	\
   11.48 +		fprintf(LOG_CHANNEL, x );						\
   11.49 +	} while (0)
   11.50 +
   11.51 +#define SDL_DFB_CHECK(x...) \
   11.52 +     do {                                                                \
   11.53 +          ret = x;                                                    \
   11.54 +          if (ret != DFB_OK) {                                        \
   11.55 +               fprintf(LOG_CHANNEL, "%s <%d>:\n\t", __FILE__, __LINE__ ); 	      \
   11.56 +               SDL_SetError( #x, DirectFBErrorString (ret) );         \
   11.57 +          }                                                           \
   11.58 +     } while (0)
   11.59 +
   11.60 +#define SDL_DFB_CHECKERR(x...) \
   11.61 +     do {                                                                \
   11.62 +          ret = x;                                                    \
   11.63 +          if (ret != DFB_OK) {                                        \
   11.64 +               fprintf(LOG_CHANNEL, "%s <%d>:\n", __FILE__, __LINE__ ); \
   11.65 +               fprintf(LOG_CHANNEL, "\t%s\n", #x ); \
   11.66 +               fprintf(LOG_CHANNEL, "\t%s\n", DirectFBErrorString (ret) ); \
   11.67 +               SDL_SetError( #x, DirectFBErrorString (ret) );         \
   11.68 +               goto error; 					      \
   11.69 +          }                                                           \
   11.70 +     } while (0)
   11.71 +
   11.72 +#define SDL_DFB_CALLOC(r, n, s) \
   11.73 +     do {                                                                \
   11.74 +          r = SDL_calloc (n, s);                                      \
   11.75 +          if (!(r)) {                                                 \
   11.76 +               fprintf( LOG_CHANNEL, "%s <%d>:\n\t", __FILE__, __LINE__ ); \
   11.77 +               SDL_OutOfMemory();                                     \
   11.78 +               goto error; 					      \
   11.79 +          }                                                           \
   11.80 +     } while (0)
   11.81  
   11.82  /* Private display data */
   11.83  
   11.84 -struct SDL_PrivateVideoData
   11.85 +#define SDL_DFB_DEVICEDATA(dev)  DFB_DeviceData *devdata = (DFB_DeviceData *) ((dev)->driverdata)
   11.86 +#define SDL_DFB_WINDOWDATA(win)  DFB_WindowData *windata = ((win) ? (DFB_WindowData *) ((win)->driverdata) : NULL)
   11.87 +#define SDL_DFB_DISPLAYDATA(dev, win)  DFB_DisplayData *dispdata = ((win && dev) ? (DFB_DisplayData *) (dev)->displays[(win)->display].driverdata : NULL)
   11.88 +
   11.89 +typedef struct _DFB_DisplayData DFB_DisplayData;
   11.90 +
   11.91 +#define DFB_MAX_SCREENS 10
   11.92 +#define DFB_MAX_MODES 50
   11.93 +
   11.94 +struct _DFB_DisplayData
   11.95 +{
   11.96 +    IDirectFBDisplayLayer *layer;
   11.97 +    DFBSurfacePixelFormat pixelformat;
   11.98 +    DFBDisplayLayerID vidID;
   11.99 +
  11.100 +    int cw;
  11.101 +    int ch;
  11.102 +
  11.103 +    int nummodes;
  11.104 +    SDL_DisplayMode *modelist;
  11.105 +
  11.106 +#if 0
  11.107 +    WMcursor *last_cursor;
  11.108 +    WMcursor *blank_cursor;
  11.109 +    WMcursor *default_cursor;
  11.110 +#endif
  11.111 +};
  11.112 +
  11.113 +
  11.114 +typedef struct _DFB_WindowData DFB_WindowData;
  11.115 +struct _DFB_WindowData
  11.116 +{
  11.117 +    IDirectFBSurface *surface;
  11.118 +    IDirectFBPalette *palette;
  11.119 +    IDirectFBWindow *window;
  11.120 +    IDirectFBGL *gl_context;
  11.121 +    IDirectFBEventBuffer *eventbuffer;
  11.122 +    DFBWindowID windowID;
  11.123 +    int id;                     // SDL window id
  11.124 +    DFB_WindowData *next;
  11.125 +    u8 opacity;
  11.126 +};
  11.127 +
  11.128 +typedef struct _DFB_DeviceData DFB_DeviceData;
  11.129 +struct _DFB_DeviceData
  11.130  {
  11.131      int initialized;
  11.132  
  11.133      IDirectFB *dfb;
  11.134 -    IDirectFBDisplayLayer *layer;
  11.135 -    IDirectFBEventBuffer *eventbuffer;
  11.136 +    int mouse;
  11.137 +    int keyboard;
  11.138 +    DFB_WindowData *firstwin;
  11.139  
  11.140 -    int nummodes;
  11.141 -    SDL_Rect **modelist;
  11.142 +    int numscreens;
  11.143 +    DFBScreenID screenid[DFB_MAX_SCREENS];
  11.144 +    DFBDisplayLayerID gralayer[DFB_MAX_SCREENS];
  11.145 +    DFBDisplayLayerID vidlayer[DFB_MAX_SCREENS];
  11.146  
  11.147 -    /* MGA CRTC2 support */
  11.148 -    int enable_mga_crtc2;
  11.149 -    int mga_crtc2_stretch;
  11.150 -    float mga_crtc2_stretch_overscan;
  11.151 -    IDirectFBDisplayLayer *c2layer;
  11.152 -    IDirectFBSurface *c2frame;
  11.153 -    DFBRectangle c2ssize;       /* Real screen size */
  11.154 -    DFBRectangle c2dsize;       /* Stretched screen size */
  11.155 -    DFBRectangle c2framesize;   /* CRTC2 screen size */
  11.156 +    // auxiliary integer for callbacks
  11.157 +    int aux;
  11.158 +
  11.159 +    // OpenGL
  11.160 +    void (*glFinish) (void);
  11.161 +    void (*glFlush) (void);
  11.162  };
  11.163  
  11.164 -#define HIDDEN (this->hidden)
  11.165 +struct SDL_GLDriverData
  11.166 +{
  11.167 +    int gl_active;              /* to stop switching drivers while we have a valid context */
  11.168  
  11.169 -void SetDirectFBerror(const char *function, DFBResult code);
  11.170 +#if SDL_DIRECTFB_OPENGL
  11.171 +    IDirectFBGL *gl_context;
  11.172 +#endif                          /* SDL_DIRECTFB_OPENGL */
  11.173 +};
  11.174  
  11.175  #endif /* _SDL_DirectFB_video_h */
  11.176 -/* vi: set ts=4 sw=4 expandtab: */
    12.1 --- a/src/video/directfb/SDL_DirectFB_yuv.c	Sat Aug 11 21:44:49 2007 +0000
    12.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.3 @@ -1,290 +0,0 @@
    12.4 -/*
    12.5 -    SDL - Simple DirectMedia Layer
    12.6 -    Copyright (C) 1997-2006 Sam Lantinga
    12.7 -
    12.8 -    This library is free software; you can redistribute it and/or
    12.9 -    modify it under the terms of the GNU Lesser General Public
   12.10 -    License as published by the Free Software Foundation; either
   12.11 -    version 2.1 of the License, or (at your option) any later version.
   12.12 -
   12.13 -    This library is distributed in the hope that it will be useful,
   12.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
   12.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   12.16 -    Lesser General Public License for more details.
   12.17 -
   12.18 -    You should have received a copy of the GNU Lesser General Public
   12.19 -    License along with this library; if not, write to the Free Software
   12.20 -    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   12.21 -
   12.22 -    Sam Lantinga
   12.23 -    slouken@libsdl.org
   12.24 -*/
   12.25 -#include "SDL_config.h"
   12.26 -
   12.27 -/* This is the DirectFB implementation of YUV video overlays */
   12.28 -
   12.29 -#include "SDL_video.h"
   12.30 -#include "SDL_DirectFB_yuv.h"
   12.31 -#include "../SDL_yuvfuncs.h"
   12.32 -
   12.33 -
   12.34 -/* The functions used to manipulate software video overlays */
   12.35 -static struct private_yuvhwfuncs directfb_yuvfuncs = {
   12.36 -    DirectFB_LockYUVOverlay,
   12.37 -    DirectFB_UnlockYUVOverlay,
   12.38 -    DirectFB_DisplayYUVOverlay,
   12.39 -    DirectFB_FreeYUVOverlay
   12.40 -};
   12.41 -
   12.42 -struct private_yuvhwdata
   12.43 -{
   12.44 -    DFBDisplayLayerID layer_id;
   12.45 -
   12.46 -    IDirectFBDisplayLayer *layer;
   12.47 -    IDirectFBSurface *surface;
   12.48 -
   12.49 -    /* These are just so we don't have to allocate them separately */
   12.50 -    Uint16 pitches[3];
   12.51 -    Uint8 *planes[3];
   12.52 -};
   12.53 -
   12.54 -static DFBEnumerationResult
   12.55 -enum_layers_callback(DFBDisplayLayerID id,
   12.56 -                     DFBDisplayLayerDescription desc, void *data)
   12.57 -{
   12.58 -    struct private_yuvhwdata *hwdata = (struct private_yuvhwdata *) data;
   12.59 -
   12.60 -    /* we don't want the primary */
   12.61 -    if (id == DLID_PRIMARY)
   12.62 -        return DFENUM_OK;
   12.63 -
   12.64 -    /* take the one with a surface for video */
   12.65 -    if ((desc.caps & DLCAPS_SURFACE) && (desc.type & DLTF_VIDEO)) {
   12.66 -        hwdata->layer_id = id;
   12.67 -
   12.68 -        return DFENUM_CANCEL;
   12.69 -    }
   12.70 -
   12.71 -    return DFENUM_OK;
   12.72 -}
   12.73 -
   12.74 -
   12.75 -static DFBResult
   12.76 -CreateYUVSurface(_THIS, struct private_yuvhwdata *hwdata,
   12.77 -                 int width, int height, Uint32 format)
   12.78 -{
   12.79 -    DFBResult ret;
   12.80 -    IDirectFB *dfb = HIDDEN->dfb;
   12.81 -    IDirectFBDisplayLayer *layer;
   12.82 -    DFBDisplayLayerConfig conf;
   12.83 -
   12.84 -    ret = dfb->EnumDisplayLayers(dfb, enum_layers_callback, hwdata);
   12.85 -    if (ret) {
   12.86 -        SetDirectFBerror("IDirectFB::EnumDisplayLayers", ret);
   12.87 -        return ret;
   12.88 -    }
   12.89 -
   12.90 -    if (!hwdata->layer_id)
   12.91 -        return DFB_UNSUPPORTED;
   12.92 -
   12.93 -    ret = dfb->GetDisplayLayer(dfb, hwdata->layer_id, &layer);
   12.94 -    if (ret) {
   12.95 -        SetDirectFBerror("IDirectFB::GetDisplayLayer", ret);
   12.96 -        return ret;
   12.97 -    }
   12.98 -
   12.99 -    conf.flags = DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT;
  12.100 -    conf.width = width;
  12.101 -    conf.height = height;
  12.102 -
  12.103 -    switch (format) {
  12.104 -    case SDL_YV12_OVERLAY:
  12.105 -        conf.pixelformat = DSPF_YV12;
  12.106 -        break;
  12.107 -    case SDL_IYUV_OVERLAY:
  12.108 -        conf.pixelformat = DSPF_I420;
  12.109 -        break;
  12.110 -    case SDL_YUY2_OVERLAY:
  12.111 -        conf.pixelformat = DSPF_YUY2;
  12.112 -        break;
  12.113 -    case SDL_UYVY_OVERLAY:
  12.114 -        conf.pixelformat = DSPF_UYVY;
  12.115 -        break;
  12.116 -    default:
  12.117 -        fprintf(stderr, "SDL_DirectFB: Unsupported YUV format (0x%08x)!\n",
  12.118 -                format);
  12.119 -        break;
  12.120 -    }
  12.121 -
  12.122 -    /* Need to set coop level or newer DirectFB versions will fail here. */
  12.123 -    ret = layer->SetCooperativeLevel(layer, DLSCL_ADMINISTRATIVE);
  12.124 -    if (ret) {
  12.125 -        SetDirectFBError
  12.126 -            ("IDirectFBDisplayLayer::SetCooperativeLevel() failed", ret);
  12.127 -        layer->Release(layer);
  12.128 -        return ret;
  12.129 -    }
  12.130 -
  12.131 -    ret = layer->SetConfiguration(layer, &conf);
  12.132 -    if (ret) {
  12.133 -        SetDirectFBerror("IDirectFBDisplayLayer::SetConfiguration", ret);
  12.134 -        layer->Release(layer);
  12.135 -        return ret;
  12.136 -    }
  12.137 -
  12.138 -    ret = layer->GetSurface(layer, &hwdata->surface);
  12.139 -    if (ret) {
  12.140 -        SetDirectFBerror("IDirectFBDisplayLayer::GetSurface", ret);
  12.141 -        layer->Release(layer);
  12.142 -        return ret;
  12.143 -    }
  12.144 -
  12.145 -    hwdata->layer = layer;
  12.146 -
  12.147 -    return DFB_OK;
  12.148 -}
  12.149 -
  12.150 -SDL_Overlay *
  12.151 -DirectFB_CreateYUVOverlay(_THIS, int width, int height, Uint32 format,
  12.152 -                          SDL_Surface * display)
  12.153 -{
  12.154 -    SDL_Overlay *overlay;
  12.155 -    struct private_yuvhwdata *hwdata;
  12.156 -
  12.157 -    /* Create the overlay structure */
  12.158 -    overlay = SDL_calloc(1, sizeof(SDL_Overlay));
  12.159 -    if (!overlay) {
  12.160 -        SDL_OutOfMemory();
  12.161 -        return NULL;
  12.162 -    }
  12.163 -
  12.164 -    /* Fill in the basic members */
  12.165 -    overlay->format = format;
  12.166 -    overlay->w = width;
  12.167 -    overlay->h = height;
  12.168 -
  12.169 -    /* Set up the YUV surface function structure */
  12.170 -    overlay->hwfuncs = &directfb_yuvfuncs;
  12.171 -
  12.172 -    /* Create the pixel data and lookup tables */
  12.173 -    hwdata = SDL_calloc(1, sizeof(struct private_yuvhwdata));
  12.174 -    overlay->hwdata = hwdata;
  12.175 -    if (!hwdata) {
  12.176 -        SDL_OutOfMemory();
  12.177 -        SDL_FreeYUVOverlay(overlay);
  12.178 -        return NULL;
  12.179 -    }
  12.180 -
  12.181 -    if (CreateYUVSurface(this, hwdata, width, height, format)) {
  12.182 -        SDL_FreeYUVOverlay(overlay);
  12.183 -        return NULL;
  12.184 -    }
  12.185 -
  12.186 -    overlay->hw_overlay = 1;
  12.187 -
  12.188 -    /* Set up the plane pointers */
  12.189 -    overlay->pitches = hwdata->pitches;
  12.190 -    overlay->pixels = hwdata->planes;
  12.191 -    switch (format) {
  12.192 -    case SDL_YV12_OVERLAY:
  12.193 -    case SDL_IYUV_OVERLAY:
  12.194 -        overlay->planes = 3;
  12.195 -        break;
  12.196 -    default:
  12.197 -        overlay->planes = 1;
  12.198 -        break;
  12.199 -    }
  12.200 -
  12.201 -    /* We're all done.. */
  12.202 -    return overlay;
  12.203 -}
  12.204 -
  12.205 -int
  12.206 -DirectFB_LockYUVOverlay(_THIS, SDL_Overlay * overlay)
  12.207 -{
  12.208 -    DFBResult ret;
  12.209 -    void *data;
  12.210 -    int pitch;
  12.211 -    IDirectFBSurface *surface = overlay->hwdata->surface;
  12.212 -
  12.213 -    ret = surface->Lock(surface, DSLF_READ | DSLF_WRITE, &data, &pitch);
  12.214 -    if (ret) {
  12.215 -        SetDirectFBerror("IDirectFBSurface::Lock", ret);
  12.216 -        return -1;
  12.217 -    }
  12.218 -
  12.219 -    /* Find the pitch and offset values for the overlay */
  12.220 -    overlay->pitches[0] = (Uint16) pitch;
  12.221 -    overlay->pixels[0] = (Uint8 *) data;
  12.222 -
  12.223 -    switch (overlay->format) {
  12.224 -    case SDL_YV12_OVERLAY:
  12.225 -    case SDL_IYUV_OVERLAY:
  12.226 -        /* Add the two extra planes */
  12.227 -        overlay->pitches[1] = overlay->pitches[0] / 2;
  12.228 -        overlay->pitches[2] = overlay->pitches[0] / 2;
  12.229 -        overlay->pixels[1] =
  12.230 -            overlay->pixels[0] + overlay->pitches[0] * overlay->h;
  12.231 -        overlay->pixels[2] =
  12.232 -            overlay->pixels[1] + overlay->pitches[1] * overlay->h / 2;
  12.233 -        break;
  12.234 -    default:
  12.235 -        /* Only one plane, no worries */
  12.236 -        break;
  12.237 -    }
  12.238 -
  12.239 -    return 0;
  12.240 -}
  12.241 -
  12.242 -void
  12.243 -DirectFB_UnlockYUVOverlay(_THIS, SDL_Overlay * overlay)
  12.244 -{
  12.245 -    IDirectFBSurface *surface = overlay->hwdata->surface;
  12.246 -
  12.247 -    overlay->pixels[0] = overlay->pixels[1] = overlay->pixels[2] = NULL;
  12.248 -
  12.249 -    surface->Unlock(surface);
  12.250 -}
  12.251 -
  12.252 -int
  12.253 -DirectFB_DisplayYUVOverlay(_THIS, SDL_Overlay * overlay, SDL_Rect * src,
  12.254 -                           SDL_Rect * dst)
  12.255 -{
  12.256 -    DFBResult ret;
  12.257 -    DFBDisplayLayerConfig conf;
  12.258 -    IDirectFBDisplayLayer *primary = HIDDEN->layer;
  12.259 -    IDirectFBDisplayLayer *layer = overlay->hwdata->layer;
  12.260 -
  12.261 -    primary->GetConfiguration(primary, &conf);
  12.262 -
  12.263 -    ret = layer->SetScreenLocation(layer,
  12.264 -                                   dst->x / (float) conf.width,
  12.265 -                                   dst->y / (float) conf.height,
  12.266 -                                   dst->w / (float) conf.width,
  12.267 -                                   dst->h / (float) conf.height);
  12.268 -    if (ret) {
  12.269 -        SetDirectFBerror("IDirectFBDisplayLayer::SetScreenLocation", ret);
  12.270 -        return -1;
  12.271 -    }
  12.272 -
  12.273 -    return 0;
  12.274 -}
  12.275 -
  12.276 -void
  12.277 -DirectFB_FreeYUVOverlay(_THIS, SDL_Overlay * overlay)
  12.278 -{
  12.279 -    struct private_yuvhwdata *hwdata;
  12.280 -
  12.281 -    hwdata = overlay->hwdata;
  12.282 -    if (hwdata) {
  12.283 -        if (hwdata->surface)
  12.284 -            hwdata->surface->Release(hwdata->surface);
  12.285 -
  12.286 -        if (hwdata->layer)
  12.287 -            hwdata->layer->Release(hwdata->layer);
  12.288 -
  12.289 -        free(hwdata);
  12.290 -    }
  12.291 -}
  12.292 -
  12.293 -/* vi: set ts=4 sw=4 expandtab: */
    13.1 --- a/src/video/directfb/SDL_DirectFB_yuv.h	Sat Aug 11 21:44:49 2007 +0000
    13.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.3 @@ -1,41 +0,0 @@
    13.4 -/*
    13.5 -    SDL - Simple DirectMedia Layer
    13.6 -    Copyright (C) 1997-2006 Sam Lantinga
    13.7 -
    13.8 -    This library is free software; you can redistribute it and/or
    13.9 -    modify it under the terms of the GNU Lesser General Public
   13.10 -    License as published by the Free Software Foundation; either
   13.11 -    version 2.1 of the License, or (at your option) any later version.
   13.12 -
   13.13 -    This library is distributed in the hope that it will be useful,
   13.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
   13.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   13.16 -    Lesser General Public License for more details.
   13.17 -
   13.18 -    You should have received a copy of the GNU Lesser General Public
   13.19 -    License along with this library; if not, write to the Free Software
   13.20 -    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   13.21 -
   13.22 -    Sam Lantinga
   13.23 -    slouken@libsdl.org
   13.24 -*/
   13.25 -#include "SDL_config.h"
   13.26 -
   13.27 -/* This is the DirectFB implementation of YUV video overlays */
   13.28 -
   13.29 -#include "SDL_video.h"
   13.30 -#include "SDL_DirectFB_video.h"
   13.31 -
   13.32 -extern SDL_Overlay *DirectFB_CreateYUVOverlay(_THIS, int width, int height,
   13.33 -                                              Uint32 format,
   13.34 -                                              SDL_Surface * display);
   13.35 -
   13.36 -extern int DirectFB_LockYUVOverlay(_THIS, SDL_Overlay * overlay);
   13.37 -
   13.38 -extern void DirectFB_UnlockYUVOverlay(_THIS, SDL_Overlay * overlay);
   13.39 -
   13.40 -extern int DirectFB_DisplayYUVOverlay(_THIS, SDL_Overlay * overlay,
   13.41 -                                      SDL_Rect * src, SDL_Rect * dst);
   13.42 -
   13.43 -extern void DirectFB_FreeYUVOverlay(_THIS, SDL_Overlay * overlay);
   13.44 -/* vi: set ts=4 sw=4 expandtab: */