Date: Sun, 31 Aug 2008 17:53:59 +0200
authorSam Lantinga <slouken@libsdl.org>
Sun, 31 Aug 2008 16:04:32 +0000
changeset 2737140a7edcf2bd
parent 2736 ae653575d4af
child 2738 79c1bd651f04
Date: Sun, 31 Aug 2008 17:53:59 +0200
From: Couriersud
Subject: Re: Updated DirectFB driver for SDL1.3

attached is a patch which brings the directfb driver in line with
current svn. In addition:

* driver now is in line with the structure of the X11 driver.
This adds a couple of files.
* driver now supports relative mouse movements
src/video/directfb/SDL_DirectFB_events.c
src/video/directfb/SDL_DirectFB_events.h
src/video/directfb/SDL_DirectFB_modes.c
src/video/directfb/SDL_DirectFB_modes.h
src/video/directfb/SDL_DirectFB_mouse.c
src/video/directfb/SDL_DirectFB_opengl.c
src/video/directfb/SDL_DirectFB_opengl.h
src/video/directfb/SDL_DirectFB_render.c
src/video/directfb/SDL_DirectFB_video.c
src/video/directfb/SDL_DirectFB_video.h
src/video/directfb/SDL_DirectFB_window.c
src/video/directfb/SDL_DirectFB_window.h
     1.1 --- a/src/video/directfb/SDL_DirectFB_events.c	Sun Aug 31 16:03:55 2008 +0000
     1.2 +++ b/src/video/directfb/SDL_DirectFB_events.c	Sun Aug 31 16:04:32 2008 +0000
     1.3 @@ -47,22 +47,20 @@
     1.4  #if (DIRECTFB_MAJOR_VERSION >= 1)
     1.5      /* FIXME: does not work on 1.0/1.2 with radeon driver
     1.6       *        the approach did work with the matrox driver
     1.7 -     *        Perhaps make this depending on env var, e.g. SDLDIRECTFB_SWITCHCONTEXT_SUPPORTED
     1.8 +     *        This has simply no effect.
     1.9       */
    1.10  
    1.11 -    if (getenv("SDLDIRECTFB_SWITCHCONTEXT_SUPPORTED") != NULL) {
    1.12 -        SDL_DFB_DEVICEDATA(_this);
    1.13 -        SDL_Window *window = SDL_GetWindowFromID(id);
    1.14 -        SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
    1.15 -        DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
    1.16 -        if (dispdata->vidID >= 0 && dispdata->vidIDinuse) {
    1.17 -            IDirectFBDisplayLayer *lay = NULL;
    1.18 -            devdata->dfb->GetDisplayLayer(devdata->dfb, dispdata->vidID,
    1.19 -                                          &lay);
    1.20 -            if (lay)
    1.21 -                lay->SwitchContext(lay, DFB_TRUE);
    1.22 -        }
    1.23 -    }
    1.24 +    SDL_Window *window = SDL_GetWindowFromID(id);
    1.25 +    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
    1.26 +    DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
    1.27 +    int ret;
    1.28 +
    1.29 +    if (dispdata->vidIDinuse)
    1.30 +        SDL_DFB_CHECKERR(dispdata->vidlayer->
    1.31 +                         SwitchContext(dispdata->vidlayer, DFB_TRUE));
    1.32 +
    1.33 +  error:
    1.34 +    return;
    1.35  #endif
    1.36  
    1.37  }
    1.38 @@ -73,14 +71,24 @@
    1.39      SDL_DFB_DEVICEDATA(_this);
    1.40      DFB_WindowData *p;
    1.41      DFBWindowEvent evt;
    1.42 +    DFBInputEvent ievt;
    1.43 +    SDL_WindowID grabbed_window;
    1.44      char text[5];
    1.45  
    1.46 +    grabbed_window = -1;
    1.47 +
    1.48      for (p = devdata->firstwin; p != NULL; p = p->next) {
    1.49 +        SDL_Window *w = SDL_GetWindowFromID(p->id);
    1.50 +
    1.51 +        if (w->flags & SDL_WINDOW_INPUT_GRABBED) {
    1.52 +            grabbed_window = p->id;
    1.53 +        }
    1.54 +
    1.55          while (p->eventbuffer->GetEvent(p->eventbuffer,
    1.56                                          DFB_EVENT(&evt)) == DFB_OK) {
    1.57              SDL_keysym keysym;
    1.58  
    1.59 -            if (evt.clazz = DFEC_WINDOW) {
    1.60 +            if (evt.clazz == DFEC_WINDOW) {
    1.61                  switch (evt.type) {
    1.62                  case DWET_BUTTONDOWN:
    1.63                      SDL_SendMouseButton(devdata->mouse, SDL_PRESSED,
    1.64 @@ -91,7 +99,9 @@
    1.65                                          DirectFB_TranslateButton(evt.button));
    1.66                      break;
    1.67                  case DWET_MOTION:
    1.68 -                    SDL_SendMouseMotion(devdata->mouse, 0, evt.cx, evt.cy);
    1.69 +                    if (!(w->flags & SDL_WINDOW_INPUT_GRABBED))
    1.70 +                        SDL_SendMouseMotion(devdata->mouse, 0, evt.cx, evt.cy,
    1.71 +                                            0);
    1.72                      break;
    1.73                  case DWET_KEYDOWN:
    1.74                      DirectFB_TranslateKey(_this, &evt, &keysym);
    1.75 @@ -111,18 +121,22 @@
    1.76                                          keysym.scancode);
    1.77                      break;
    1.78                  case DWET_POSITION_SIZE:
    1.79 -                    SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_MOVED, evt.x,
    1.80 -                                        evt.y);
    1.81 -                    SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_RESIZED, evt.w,
    1.82 -                                        evt.h);
    1.83 +                    if (evt.x != w->x || evt.y != w->y)
    1.84 +                        SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_MOVED,
    1.85 +                                            evt.x, evt.y);
    1.86 +                    if (evt.w != w->w || evt.h != w->h)
    1.87 +                        SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_RESIZED,
    1.88 +                                            evt.w, evt.h);
    1.89                      break;
    1.90                  case DWET_POSITION:
    1.91 -                    SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_MOVED, evt.x,
    1.92 -                                        evt.y);
    1.93 +                    if (evt.x != w->x || evt.y != w->y)
    1.94 +                        SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_MOVED,
    1.95 +                                            evt.x, evt.y);
    1.96                      break;
    1.97                  case DWET_SIZE:
    1.98 -                    SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_RESIZED, evt.w,
    1.99 -                                        evt.h);
   1.100 +                    if (evt.w != w->w || evt.h != w->h)
   1.101 +                        SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_RESIZED,
   1.102 +                                            evt.w, evt.h);
   1.103                      break;
   1.104                  case DWET_CLOSE:
   1.105                      SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_CLOSE, 0, 0);
   1.106 @@ -139,18 +153,41 @@
   1.107                      SDL_SetKeyboardFocus(devdata->keyboard, 0);
   1.108                      break;
   1.109                  case DWET_ENTER:
   1.110 -                    //SDL_DirectFB_ReshowCursor(_this, 0);
   1.111 +                    /* SDL_DirectFB_ReshowCursor(_this, 0); */
   1.112                      SDL_SetMouseFocus(devdata->mouse, p->id);
   1.113                      SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_ENTER, 0, 0);
   1.114                      break;
   1.115                  case DWET_LEAVE:
   1.116                      SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_LEAVE, 0, 0);
   1.117                      SDL_SetMouseFocus(devdata->mouse, 0);
   1.118 -                    //SDL_DirectFB_ReshowCursor(_this, 1);
   1.119 +                    /* SDL_DirectFB_ReshowCursor(_this, 1); */
   1.120                      break;
   1.121                  default:
   1.122                      ;
   1.123                  }
   1.124 +            } else
   1.125 +                printf("Event Clazz %d\n", evt.clazz);
   1.126 +
   1.127 +        }
   1.128 +    }
   1.129 +
   1.130 +    /* Now get relative events in case we need them */
   1.131 +    while (devdata->events->GetEvent(devdata->events,
   1.132 +                                     DFB_EVENT(&ievt)) == DFB_OK) {
   1.133 +        if (grabbed_window >= 0) {
   1.134 +            switch (ievt.type) {
   1.135 +            case DIET_AXISMOTION:
   1.136 +                if (ievt.flags & DIEF_AXISREL) {
   1.137 +                    if (ievt.axis == DIAI_X)
   1.138 +                        SDL_SendMouseMotion(devdata->mouse, 1, ievt.axisrel,
   1.139 +                                            0, 0);
   1.140 +                    else if (ievt.axis == DIAI_Y)
   1.141 +                        SDL_SendMouseMotion(devdata->mouse, 1, 0,
   1.142 +                                            ievt.axisrel, 0);
   1.143 +                }
   1.144 +                break;
   1.145 +            default:
   1.146 +                ;
   1.147              }
   1.148          }
   1.149      }
   1.150 @@ -231,9 +268,10 @@
   1.151      keymap[DIKI_META_R - DIKI_UNKNOWN] = SDL_SCANCODE_RGUI;
   1.152      keymap[DIKI_SUPER_L - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION;
   1.153      keymap[DIKI_SUPER_R - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION;
   1.154 -    //FIXME:Do we read hyper keys ?
   1.155 -    //keymap[DIKI_HYPER_L - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION;
   1.156 -    //keymap[DIKI_HYPER_R - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION;
   1.157 +    /* FIXME:Do we read hyper keys ?
   1.158 +     * keymap[DIKI_HYPER_L - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION;
   1.159 +     * keymap[DIKI_HYPER_R - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION;
   1.160 +     */
   1.161      keymap[DIKI_TAB - DIKI_UNKNOWN] = SDL_SCANCODE_TAB;
   1.162      keymap[DIKI_ENTER - DIKI_UNKNOWN] = SDL_SCANCODE_RETURN;
   1.163      keymap[DIKI_SPACE - DIKI_UNKNOWN] = SDL_SCANCODE_SPACE;
   1.164 @@ -290,7 +328,7 @@
   1.165  
   1.166      if (evt->key_code >= 0
   1.167          && evt->key_code < SDL_arraysize(linux_scancode_table))
   1.168 -        keysym->scancode = linux_scancode_table[evt->key_code]; // key_id;
   1.169 +        keysym->scancode = linux_scancode_table[evt->key_code];
   1.170      else
   1.171          keysym->scancode = SDL_SCANCODE_UNKNOWN;
   1.172  
   1.173 @@ -331,7 +369,6 @@
   1.174  {
   1.175      DFB_DeviceData *devdata = callbackdata;
   1.176      SDL_Keyboard keyboard;
   1.177 -    SDL_scancode scancode;
   1.178      SDLKey keymap[SDL_NUM_SCANCODES];
   1.179  
   1.180      if ((desc.caps & DIDTF_KEYBOARD) && device_id == DIDID_KEYBOARD) {
   1.181 @@ -360,6 +397,16 @@
   1.182                    EnumInputDevices(devdata->dfb, input_device_cb, devdata));
   1.183  }
   1.184  
   1.185 +void
   1.186 +DirectFB_QuitKeyboard(_THIS)
   1.187 +{
   1.188 +    SDL_DFB_DEVICEDATA(_this);
   1.189 +    int ret;
   1.190 +
   1.191 +    SDL_DelKeyboard(devdata->keyboard);
   1.192 +
   1.193 +}
   1.194 +
   1.195  #if 0
   1.196  /* FIXME: Remove once determined this is not needed in fullscreen mode */
   1.197  void
   1.198 @@ -383,25 +430,33 @@
   1.199              switch (evt.type) {
   1.200              case DIET_BUTTONPRESS:
   1.201                  posted += SDL_PrivateMouseButton(SDL_PRESSED,
   1.202 -                                                 DirectFB_TranslateButton
   1.203 -                                                 (evt.button), 0, 0);
   1.204 +                                                 DirectFB_TranslateButton(evt.
   1.205 +                                                                          button),
   1.206 +                                                 0, 0);
   1.207                  break;
   1.208              case DIET_BUTTONRELEASE:
   1.209                  posted += SDL_PrivateMouseButton(SDL_RELEASED,
   1.210 -                                                 DirectFB_TranslateButton
   1.211 -                                                 (evt.button), 0, 0);
   1.212 +                                                 DirectFB_TranslateButton(evt.
   1.213 +                                                                          button),
   1.214 +                                                 0, 0);
   1.215                  break;
   1.216              case DIET_KEYPRESS:
   1.217                  posted += SDL_PrivateKeyboard(SDL_PRESSED,
   1.218 -                                              DirectFB_TranslateKey
   1.219 -                                              (evt.key_id, evt.key_symbol,
   1.220 -                                               mod, &keysym));
   1.221 +                                              DirectFB_TranslateKey(evt.
   1.222 +                                                                    key_id,
   1.223 +                                                                    evt.
   1.224 +                                                                    key_symbol,
   1.225 +                                                                    mod,
   1.226 +                                                                    &keysym));
   1.227                  break;
   1.228              case DIET_KEYRELEASE:
   1.229                  posted += SDL_PrivateKeyboard(SDL_RELEASED,
   1.230 -                                              DirectFB_TranslateKey
   1.231 -                                              (evt.key_id, evt.key_symbol,
   1.232 -                                               mod, &keysym));
   1.233 +                                              DirectFB_TranslateKey(evt.
   1.234 +                                                                    key_id,
   1.235 +                                                                    evt.
   1.236 +                                                                    key_symbol,
   1.237 +                                                                    mod,
   1.238 +                                                                    &keysym));
   1.239                  break;
   1.240              case DIET_AXISMOTION:
   1.241                  if (evt.flags & DIEF_AXISREL) {
     2.1 --- a/src/video/directfb/SDL_DirectFB_events.h	Sun Aug 31 16:03:55 2008 +0000
     2.2 +++ b/src/video/directfb/SDL_DirectFB_events.h	Sun Aug 31 16:04:32 2008 +0000
     2.3 @@ -25,5 +25,6 @@
     2.4  
     2.5  /* Functions to be exported */
     2.6  extern void DirectFB_InitKeyboard(_THIS);
     2.7 +extern void DirectFB_QuitKeyboard(_THIS);
     2.8  extern void DirectFB_PumpEventsWindow(_THIS);
     2.9  extern SDLKey DirectFB_GetLayoutKey(_THIS, SDLKey physicalKey);
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/video/directfb/SDL_DirectFB_modes.c	Sun Aug 31 16:04:32 2008 +0000
     3.3 @@ -0,0 +1,507 @@
     3.4 +/*
     3.5 +    SDL - Simple DirectMedia Layer
     3.6 +    Copyright (C) 1997-2006 Sam Lantinga
     3.7 +
     3.8 +    This library is free software; you can redistribute it and/or
     3.9 +    modify it under the terms of the GNU Lesser General Public
    3.10 +    License as published by the Free Software Foundation; either
    3.11 +    version 2.1 of the License, or (at your option) any later version.
    3.12 +
    3.13 +    This library is distributed in the hope that it will be useful,
    3.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    3.16 +    Lesser General Public License for more details.
    3.17 +
    3.18 +    You should have received a copy of the GNU Lesser General Public
    3.19 +    License along with this library; if not, write to the Free Software
    3.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    3.21 +
    3.22 +    Sam Lantinga
    3.23 +    slouken@libsdl.org
    3.24 +*/
    3.25 +#include "SDL_config.h"
    3.26 +
    3.27 +#include "SDL_DirectFB_video.h"
    3.28 +
    3.29 +#define DFB_MAX_MODES 200
    3.30 +
    3.31 +struct scn_callback_t
    3.32 +{
    3.33 +    int numscreens;
    3.34 +    DFBScreenID screenid[DFB_MAX_SCREENS];
    3.35 +    DFBDisplayLayerID gralayer[DFB_MAX_SCREENS];
    3.36 +    DFBDisplayLayerID vidlayer[DFB_MAX_SCREENS];
    3.37 +    int aux;                    /* auxiliary integer for callbacks */
    3.38 +};
    3.39 +
    3.40 +struct modes_callback_t
    3.41 +{
    3.42 +    int nummodes;
    3.43 +    SDL_DisplayMode *modelist;
    3.44 +};
    3.45 +
    3.46 +static int
    3.47 +DFBToSDLPixelFormat(DFBSurfacePixelFormat pixelformat, Uint32 * fmt)
    3.48 +{
    3.49 +    switch (pixelformat) {
    3.50 +    case DSPF_ALUT44:
    3.51 +        *fmt = SDL_PIXELFORMAT_INDEX4LSB;
    3.52 +        break;
    3.53 +    case DSPF_LUT8:
    3.54 +        *fmt = SDL_PIXELFORMAT_INDEX8;
    3.55 +        break;
    3.56 +    case DSPF_RGB332:
    3.57 +        *fmt = SDL_PIXELFORMAT_RGB332;
    3.58 +        break;
    3.59 +    case DSPF_ARGB4444:
    3.60 +        *fmt = SDL_PIXELFORMAT_ARGB4444;
    3.61 +        break;
    3.62 +    case SDL_PIXELFORMAT_ARGB1555:
    3.63 +        *fmt = SDL_PIXELFORMAT_ARGB1555;
    3.64 +        break;
    3.65 +    case DSPF_RGB16:
    3.66 +        *fmt = SDL_PIXELFORMAT_RGB565;
    3.67 +        break;
    3.68 +    case DSPF_RGB24:
    3.69 +        *fmt = SDL_PIXELFORMAT_RGB24;
    3.70 +        break;
    3.71 +    case DSPF_RGB32:
    3.72 +        *fmt = SDL_PIXELFORMAT_RGB888;
    3.73 +        break;
    3.74 +    case DSPF_ARGB:
    3.75 +        *fmt = SDL_PIXELFORMAT_ARGB8888;
    3.76 +        break;
    3.77 +    case DSPF_YV12:
    3.78 +        *fmt = SDL_PIXELFORMAT_YV12;
    3.79 +        break;                  /* Planar mode: Y + V + U  (3 planes) */
    3.80 +    case DSPF_I420:
    3.81 +        *fmt = SDL_PIXELFORMAT_IYUV;
    3.82 +        break;                  /* Planar mode: Y + U + V  (3 planes) */
    3.83 +    case DSPF_YUY2:
    3.84 +        *fmt = SDL_PIXELFORMAT_YUY2;
    3.85 +        break;                  /* Packed mode: Y0+U0+Y1+V0 (1 plane) */
    3.86 +    case DSPF_UYVY:
    3.87 +        *fmt = SDL_PIXELFORMAT_UYVY;
    3.88 +        break;                  /* Packed mode: U0+Y0+V0+Y1 (1 plane) */
    3.89 +    default:
    3.90 +        return -1;
    3.91 +    }
    3.92 +    return 0;
    3.93 +}
    3.94 +
    3.95 +static DFBSurfacePixelFormat
    3.96 +SDLToDFBPixelFormat(Uint32 format)
    3.97 +{
    3.98 +    switch (format) {
    3.99 +    case SDL_PIXELFORMAT_INDEX4LSB:
   3.100 +        return DSPF_ALUT44;
   3.101 +    case SDL_PIXELFORMAT_INDEX8:
   3.102 +        return DSPF_LUT8;
   3.103 +    case SDL_PIXELFORMAT_RGB332:
   3.104 +        return DSPF_RGB332;
   3.105 +    case SDL_PIXELFORMAT_RGB555:
   3.106 +        return DSPF_ARGB1555;
   3.107 +    case SDL_PIXELFORMAT_ARGB4444:
   3.108 +        return DSPF_ARGB4444;
   3.109 +    case SDL_PIXELFORMAT_ARGB1555:
   3.110 +        return DSPF_ARGB1555;
   3.111 +    case SDL_PIXELFORMAT_RGB565:
   3.112 +        return DSPF_RGB16;
   3.113 +    case SDL_PIXELFORMAT_RGB24:
   3.114 +        return DSPF_RGB24;
   3.115 +    case SDL_PIXELFORMAT_RGB888:
   3.116 +        return DSPF_RGB32;
   3.117 +    case SDL_PIXELFORMAT_ARGB8888:
   3.118 +        return DSPF_ARGB;
   3.119 +    case SDL_PIXELFORMAT_YV12:
   3.120 +        return DSPF_YV12;       /* Planar mode: Y + V + U  (3 planes) */
   3.121 +    case SDL_PIXELFORMAT_IYUV:
   3.122 +        return DSPF_I420;       /* Planar mode: Y + U + V  (3 planes) */
   3.123 +    case SDL_PIXELFORMAT_YUY2:
   3.124 +        return DSPF_YUY2;       /* Packed mode: Y0+U0+Y1+V0 (1 plane) */
   3.125 +    case SDL_PIXELFORMAT_UYVY:
   3.126 +        return DSPF_UYVY;       /* Packed mode: U0+Y0+V0+Y1 (1 plane) */
   3.127 +    case SDL_PIXELFORMAT_YVYU:
   3.128 +        return DSPF_UNKNOWN;    /* Packed mode: Y0+V0+Y1+U0 (1 plane) */
   3.129 +    case SDL_PIXELFORMAT_INDEX1LSB:
   3.130 +        return DSPF_UNKNOWN;
   3.131 +    case SDL_PIXELFORMAT_INDEX1MSB:
   3.132 +        return DSPF_UNKNOWN;
   3.133 +    case SDL_PIXELFORMAT_INDEX4MSB:
   3.134 +        return DSPF_UNKNOWN;
   3.135 +    case SDL_PIXELFORMAT_RGB444:
   3.136 +        return DSPF_UNKNOWN;
   3.137 +    case SDL_PIXELFORMAT_BGR24:
   3.138 +        return DSPF_UNKNOWN;
   3.139 +    case SDL_PIXELFORMAT_BGR888:
   3.140 +        return DSPF_UNKNOWN;
   3.141 +    case SDL_PIXELFORMAT_RGBA8888:
   3.142 +        return DSPF_UNKNOWN;
   3.143 +    case SDL_PIXELFORMAT_ABGR8888:
   3.144 +        return DSPF_UNKNOWN;
   3.145 +    case SDL_PIXELFORMAT_BGRA8888:
   3.146 +        return DSPF_UNKNOWN;
   3.147 +    case SDL_PIXELFORMAT_ARGB2101010:
   3.148 +        return DSPF_UNKNOWN;
   3.149 +    default:
   3.150 +        return DSPF_UNKNOWN;
   3.151 +    }
   3.152 +}
   3.153 +
   3.154 +static DFBEnumerationResult
   3.155 +EnumModesCallback(int width, int height, int bpp, void *data)
   3.156 +{
   3.157 +    struct modes_callback_t *modedata = (struct modes_callback_t *) data;
   3.158 +    SDL_DisplayMode mode;
   3.159 +
   3.160 +    mode.w = width;
   3.161 +    mode.h = height;
   3.162 +    mode.refresh_rate = 0;
   3.163 +    mode.driverdata = NULL;
   3.164 +    mode.format = SDL_PIXELFORMAT_UNKNOWN;
   3.165 +
   3.166 +    if (modedata->nummodes < DFB_MAX_MODES) {
   3.167 +        modedata->modelist[modedata->nummodes++] = mode;
   3.168 +    }
   3.169 +
   3.170 +    SDL_DFB_DEBUG("w %d h %d bpp %d\n", width, height, bpp);
   3.171 +    return DFENUM_OK;
   3.172 +}
   3.173 +
   3.174 +static DFBEnumerationResult
   3.175 +cbScreens(DFBScreenID screen_id, DFBScreenDescription desc,
   3.176 +          void *callbackdata)
   3.177 +{
   3.178 +    struct scn_callback_t *devdata = (struct scn_callback_t *) callbackdata;
   3.179 +
   3.180 +    devdata->screenid[devdata->numscreens++] = screen_id;
   3.181 +    return DFENUM_OK;
   3.182 +}
   3.183 +
   3.184 +DFBEnumerationResult
   3.185 +cbLayers(DFBDisplayLayerID layer_id, DFBDisplayLayerDescription desc,
   3.186 +         void *callbackdata)
   3.187 +{
   3.188 +    struct scn_callback_t *devdata = (struct scn_callback_t *) callbackdata;
   3.189 +
   3.190 +    if (desc.caps & DLCAPS_SURFACE) {
   3.191 +        if ((desc.type & DLTF_GRAPHICS) && (desc.type & DLTF_VIDEO)) {
   3.192 +            if (devdata->vidlayer[devdata->aux] == -1)
   3.193 +                devdata->vidlayer[devdata->aux] = layer_id;
   3.194 +        } else if (desc.type & DLTF_GRAPHICS) {
   3.195 +            if (devdata->gralayer[devdata->aux] == -1)
   3.196 +                devdata->gralayer[devdata->aux] = layer_id;
   3.197 +        }
   3.198 +    }
   3.199 +    return DFENUM_OK;
   3.200 +}
   3.201 +
   3.202 +static void
   3.203 +CheckSetDisplayMode(_THIS, DFB_DisplayData * data, SDL_DisplayMode * mode)
   3.204 +{
   3.205 +    SDL_DFB_DEVICEDATA(_this);
   3.206 +    DFBDisplayLayerConfig config;
   3.207 +    DFBDisplayLayerConfigFlags failed;
   3.208 +    int ret;
   3.209 +
   3.210 +    SDL_DFB_CHECKERR(data->layer->
   3.211 +                     SetCooperativeLevel(data->layer, DLSCL_ADMINISTRATIVE));
   3.212 +    config.width = mode->w;
   3.213 +    config.height = mode->h;
   3.214 +    config.pixelformat = SDLToDFBPixelFormat(mode->format);
   3.215 +    config.flags = DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT;
   3.216 +    if (devdata->use_yuv_underlays) {
   3.217 +        config.flags |= DLCONF_OPTIONS;
   3.218 +        config.options = DLOP_ALPHACHANNEL;
   3.219 +    }
   3.220 +    failed = 0;
   3.221 +    data->layer->TestConfiguration(data->layer, &config, &failed);
   3.222 +    SDL_DFB_CHECKERR(data->layer->
   3.223 +                     SetCooperativeLevel(data->layer, DLSCL_SHARED));
   3.224 +    if (failed == 0)
   3.225 +        SDL_AddDisplayMode(_this->current_display, mode);
   3.226 +    else
   3.227 +        SDL_DFB_DEBUG("Mode %d x %d not available: %x\n", mode->w, mode->h,
   3.228 +                      failed);
   3.229 +
   3.230 +    return;
   3.231 +  error:
   3.232 +    return;
   3.233 +}
   3.234 +
   3.235 +void
   3.236 +DirectFB_InitModes(_THIS)
   3.237 +{
   3.238 +    SDL_DFB_DEVICEDATA(_this);
   3.239 +    IDirectFBDisplayLayer *layer = NULL;
   3.240 +    SDL_VideoDisplay display;
   3.241 +    DFB_DisplayData *dispdata;
   3.242 +    SDL_DisplayMode mode;
   3.243 +#if (DIRECTFB_MAJOR_VERSION == 0) && (DIRECTFB_MINOR_VERSION == 9) && (DIRECTFB_MICRO_VERSION < 23)
   3.244 +    DFBCardCapabilities caps;
   3.245 +#else
   3.246 +    DFBGraphicsDeviceDescription caps;
   3.247 +#endif
   3.248 +    DFBDisplayLayerConfig dlc;
   3.249 +    struct scn_callback_t *screencbdata;
   3.250 +
   3.251 +    int tcw[DFB_MAX_SCREENS];
   3.252 +    int tch[DFB_MAX_SCREENS];
   3.253 +    int i;
   3.254 +    DFBResult ret;
   3.255 +
   3.256 +    SDL_DFB_CALLOC(screencbdata, 1, sizeof(*screencbdata));
   3.257 +
   3.258 +    screencbdata->numscreens = 0;
   3.259 +
   3.260 +    for (i = 0; i < DFB_MAX_SCREENS; i++) {
   3.261 +        screencbdata->gralayer[i] = -1;
   3.262 +        screencbdata->vidlayer[i] = -1;
   3.263 +    }
   3.264 +
   3.265 +    SDL_DFB_CHECKERR(devdata->dfb->
   3.266 +                     EnumScreens(devdata->dfb, &cbScreens, screencbdata));
   3.267 +
   3.268 +    for (i = 0; i < screencbdata->numscreens; i++) {
   3.269 +        IDirectFBScreen *screen;
   3.270 +
   3.271 +        SDL_DFB_CHECKERR(devdata->dfb->
   3.272 +                         GetScreen(devdata->dfb, screencbdata->screenid[i],
   3.273 +                                   &screen));
   3.274 +
   3.275 +        screencbdata->aux = i;
   3.276 +        SDL_DFB_CHECKERR(screen->
   3.277 +                         EnumDisplayLayers(screen, &cbLayers, screencbdata));
   3.278 +#if (DIRECTFB_MAJOR_VERSION >= 1)
   3.279 +        screen->GetSize(screen, &tcw[i], &tch[i]);
   3.280 +#else
   3.281 +        /* FIXME: this is only used to center windows
   3.282 +         *        Should be done otherwise, e.g. get surface from layer
   3.283 +         */
   3.284 +        tcw[i] = 800;
   3.285 +        tch[i] = 600;
   3.286 +#endif
   3.287 +        screen->Release(screen);
   3.288 +    }
   3.289 +
   3.290 +    /* Query card capabilities */
   3.291 +
   3.292 +    devdata->dfb->GetDeviceDescription(devdata->dfb, &caps);
   3.293 +
   3.294 +    SDL_DFB_DEBUG("SDL directfb video driver - %s %s\n", __DATE__, __TIME__);
   3.295 +    SDL_DFB_DEBUG("Using %s (%s) driver.\n", caps.name, caps.vendor);
   3.296 +    SDL_DFB_DEBUG("Found %d screens\n", devdata->numscreens);
   3.297 +
   3.298 +    for (i = 0; i < screencbdata->numscreens; i++) {
   3.299 +        SDL_DFB_CHECKERR(devdata->dfb->
   3.300 +                         GetDisplayLayer(devdata->dfb,
   3.301 +                                         screencbdata->gralayer[i], &layer));
   3.302 +
   3.303 +        SDL_DFB_CHECKERR(layer->
   3.304 +                         SetCooperativeLevel(layer, DLSCL_ADMINISTRATIVE));
   3.305 +        layer->EnableCursor(layer, 1);
   3.306 +        SDL_DFB_CHECKERR(layer->SetCursorOpacity(layer, 0xC0));
   3.307 +
   3.308 +        if (devdata->use_yuv_underlays) {
   3.309 +            dlc.flags = DLCONF_PIXELFORMAT | DLCONF_OPTIONS;
   3.310 +            dlc.pixelformat = DSPF_ARGB;
   3.311 +            dlc.options = DLOP_ALPHACHANNEL;
   3.312 +
   3.313 +            ret = layer->SetConfiguration(layer, &dlc);
   3.314 +            if (ret) {
   3.315 +                /* try AiRGB if the previous failed */
   3.316 +                dlc.pixelformat = DSPF_AiRGB;
   3.317 +                ret = layer->SetConfiguration(layer, &dlc);
   3.318 +            }
   3.319 +        }
   3.320 +
   3.321 +        SDL_DFB_CHECKERR(layer->SetCooperativeLevel(layer, DLSCL_SHARED));
   3.322 +
   3.323 +        /* Query layer configuration to determine the current mode and pixelformat */
   3.324 +        layer->GetConfiguration(layer, &dlc);
   3.325 +
   3.326 +        if (DFBToSDLPixelFormat(dlc.pixelformat, &mode.format) != 0) {
   3.327 +            SDL_DFB_ERR("Unknown dfb pixelformat %x !\n", dlc.pixelformat);
   3.328 +            goto error;
   3.329 +        }
   3.330 +
   3.331 +        mode.w = dlc.width;
   3.332 +        mode.h = dlc.height;
   3.333 +        mode.refresh_rate = 0;
   3.334 +        mode.driverdata = NULL;
   3.335 +
   3.336 +        SDL_DFB_CALLOC(dispdata, 1, sizeof(*dispdata));
   3.337 +
   3.338 +        dispdata->layer = layer;
   3.339 +        dispdata->pixelformat = dlc.pixelformat;
   3.340 +        dispdata->cw = tcw[i];
   3.341 +        dispdata->ch = tch[i];
   3.342 +
   3.343 +        /* YUV - Video layer */
   3.344 +
   3.345 +        dispdata->vidID = screencbdata->vidlayer[i];
   3.346 +        dispdata->vidIDinuse = 0;
   3.347 +
   3.348 +        SDL_zero(display);
   3.349 +
   3.350 +        display.desktop_mode = mode;
   3.351 +        display.current_mode = mode;
   3.352 +        display.driverdata = dispdata;
   3.353 +
   3.354 +        SDL_AddVideoDisplay(&display);
   3.355 +    }
   3.356 +    SDL_DFB_FREE(screencbdata);
   3.357 +    return;
   3.358 +  error:
   3.359 +    /* FIXME: Cleanup not complete, Free existing displays */
   3.360 +    SDL_DFB_FREE(dispdata);
   3.361 +    SDL_DFB_RELEASE(layer);
   3.362 +    return;
   3.363 +}
   3.364 +
   3.365 +void
   3.366 +DirectFB_GetDisplayModes(_THIS)
   3.367 +{
   3.368 +    SDL_DFB_DEVICEDATA(_this);
   3.369 +    DFB_DisplayData *dispdata =
   3.370 +        (DFB_DisplayData *) SDL_CurrentDisplay.driverdata;
   3.371 +    SDL_DisplayMode mode;
   3.372 +    struct modes_callback_t data;
   3.373 +    int i;
   3.374 +    int ret;
   3.375 +
   3.376 +    data.nummodes = 0;
   3.377 +    /* Enumerate the available fullscreen modes */
   3.378 +    SDL_DFB_CALLOC(data.modelist, DFB_MAX_MODES, sizeof(SDL_DisplayMode));
   3.379 +    SDL_DFB_CHECKERR(devdata->dfb->
   3.380 +                     EnumVideoModes(devdata->dfb, EnumModesCallback, &data));
   3.381 +
   3.382 +    for (i = 0; i < data.nummodes; ++i) {
   3.383 +        mode = data.modelist[i];
   3.384 +
   3.385 +        mode.format = SDL_PIXELFORMAT_ARGB8888;
   3.386 +        CheckSetDisplayMode(_this, dispdata, &mode);
   3.387 +        mode.format = SDL_PIXELFORMAT_RGB888;
   3.388 +        CheckSetDisplayMode(_this, dispdata, &mode);
   3.389 +        mode.format = SDL_PIXELFORMAT_RGB24;
   3.390 +        CheckSetDisplayMode(_this, dispdata, &mode);
   3.391 +        mode.format = SDL_PIXELFORMAT_RGB565;
   3.392 +        CheckSetDisplayMode(_this, dispdata, &mode);
   3.393 +        mode.format = SDL_PIXELFORMAT_INDEX8;
   3.394 +        CheckSetDisplayMode(_this, dispdata, &mode);
   3.395 +    }
   3.396 +    SDL_DFB_FREE(data.modelist);
   3.397 +    return;
   3.398 +  error:
   3.399 +    SDL_DFB_FREE(data.modelist);
   3.400 +    return;
   3.401 +}
   3.402 +
   3.403 +int
   3.404 +DirectFB_SetDisplayMode(_THIS, SDL_DisplayMode * mode)
   3.405 +{
   3.406 +    /*
   3.407 +     * FIXME: video mode switch is currently broken for 1.2.0
   3.408 +     * 
   3.409 +     */
   3.410 +
   3.411 +    SDL_DFB_DEVICEDATA(_this);
   3.412 +    DFB_DisplayData *data = (DFB_DisplayData *) SDL_CurrentDisplay.driverdata;
   3.413 +    DFBDisplayLayerConfig config, rconfig;
   3.414 +    DFBDisplayLayerConfigFlags fail = 0;
   3.415 +    DFBResult ret;
   3.416 +
   3.417 +    SDL_DFB_CHECKERR(data->layer->
   3.418 +                     SetCooperativeLevel(data->layer, DLSCL_ADMINISTRATIVE));
   3.419 +
   3.420 +    SDL_DFB_CHECKERR(data->layer->GetConfiguration(data->layer, &config));
   3.421 +    config.flags = DLCONF_WIDTH | DLCONF_HEIGHT;
   3.422 +    if (mode->format != SDL_PIXELFORMAT_UNKNOWN) {
   3.423 +        config.flags |= DLCONF_PIXELFORMAT;
   3.424 +        config.pixelformat = SDLToDFBPixelFormat(mode->format);
   3.425 +        data->pixelformat = config.pixelformat;
   3.426 +    }
   3.427 +    config.width = mode->w;
   3.428 +    config.height = mode->h;
   3.429 +
   3.430 +    if (devdata->use_yuv_underlays) {
   3.431 +        config.flags |= DLCONF_OPTIONS;
   3.432 +        config.options = DLOP_ALPHACHANNEL;
   3.433 +    }
   3.434 +
   3.435 +    data->layer->TestConfiguration(data->layer, &config, &fail);
   3.436 +
   3.437 +    if (fail &
   3.438 +        (DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT | DLCONF_OPTIONS))
   3.439 +    {
   3.440 +        SDL_DFB_ERR("Error setting mode %dx%d-%x\n", mode->w, mode->h,
   3.441 +                    mode->format);
   3.442 +        return -1;
   3.443 +    }
   3.444 +
   3.445 +    SDL_DFB_DEBUG("Trace\n");
   3.446 +    config.flags &= ~fail;
   3.447 +    SDL_DFB_CHECKERR(data->layer->SetConfiguration(data->layer, &config));
   3.448 +
   3.449 +    /* Double check */
   3.450 +    SDL_DFB_CHECKERR(data->layer->GetConfiguration(data->layer, &rconfig));
   3.451 +    SDL_DFB_CHECKERR(data->layer->
   3.452 +                     SetCooperativeLevel(data->layer, DLSCL_SHARED));
   3.453 +
   3.454 +    if ((config.width != rconfig.width) ||
   3.455 +        (config.height != rconfig.height) ||
   3.456 +        ((mode->format != SDL_PIXELFORMAT_UNKNOWN)
   3.457 +         && (config.pixelformat != rconfig.pixelformat))) {
   3.458 +        SDL_DFB_ERR("Error setting mode %dx%d-%x\n", mode->w, mode->h,
   3.459 +                    mode->format);
   3.460 +        return -1;
   3.461 +    }
   3.462 +
   3.463 +    data->pixelformat = rconfig.pixelformat;
   3.464 +    data->cw = config.width;
   3.465 +    data->ch = config.height;
   3.466 +    SDL_CurrentDisplay.current_mode = *mode;
   3.467 +
   3.468 +    return 0;
   3.469 +  error:
   3.470 +    return -1;
   3.471 +}
   3.472 +
   3.473 +void
   3.474 +DirectFB_QuitModes(_THIS)
   3.475 +{
   3.476 +    DFB_DeviceData *devdata = (DFB_DeviceData *) _this->driverdata;
   3.477 +    SDL_DisplayMode tmode;
   3.478 +    DFBResult ret;
   3.479 +    int i;
   3.480 +
   3.481 +    SDL_SelectVideoDisplay(0);
   3.482 +
   3.483 +    SDL_GetDesktopDisplayMode(&tmode);
   3.484 +    tmode.format = SDL_PIXELFORMAT_UNKNOWN;
   3.485 +    DirectFB_SetDisplayMode(_this, &tmode);
   3.486 +
   3.487 +    SDL_GetDesktopDisplayMode(&tmode);
   3.488 +    DirectFB_SetDisplayMode(_this, &tmode);
   3.489 +
   3.490 +    for (i = 0; i < SDL_GetNumVideoDisplays(); i++) {
   3.491 +        DFB_DisplayData *dispdata =
   3.492 +            (DFB_DisplayData *) _this->displays[i].driverdata;
   3.493 +
   3.494 +        if (dispdata->layer) {
   3.495 +            SDL_DFB_CHECK(dispdata->layer->
   3.496 +                          SetCooperativeLevel(dispdata->layer,
   3.497 +                                              DLSCL_ADMINISTRATIVE));
   3.498 +            SDL_DFB_CHECK(dispdata->layer->
   3.499 +                          SetCursorOpacity(dispdata->layer, 0x00));
   3.500 +            SDL_DFB_CHECK(dispdata->layer->
   3.501 +                          SetCooperativeLevel(dispdata->layer, DLSCL_SHARED));
   3.502 +        }
   3.503 +
   3.504 +        SDL_DFB_RELEASE(dispdata->layer);
   3.505 +        SDL_DFB_RELEASE(dispdata->vidlayer);
   3.506 +
   3.507 +    }
   3.508 +}
   3.509 +
   3.510 +/* vi: set ts=4 sw=4 expandtab: */
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/video/directfb/SDL_DirectFB_modes.h	Sun Aug 31 16:04:32 2008 +0000
     4.3 @@ -0,0 +1,57 @@
     4.4 +/*
     4.5 +    SDL - Simple DirectMedia Layer
     4.6 +    Copyright (C) 1997-2006 Sam Lantinga
     4.7 +
     4.8 +    This library is free software; you can redistribute it and/or
     4.9 +    modify it under the terms of the GNU Lesser General Public
    4.10 +    License as published by the Free Software Foundation; either
    4.11 +    version 2.1 of the License, or (at your option) any later version.
    4.12 +
    4.13 +    This library is distributed in the hope that it will be useful,
    4.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    4.16 +    Lesser General Public License for more details.
    4.17 +
    4.18 +    You should have received a copy of the GNU Lesser General Public
    4.19 +    License along with this library; if not, write to the Free Software
    4.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    4.21 +
    4.22 +    Sam Lantinga
    4.23 +    slouken@libsdl.org
    4.24 +*/
    4.25 +#include "SDL_config.h"
    4.26 +
    4.27 +#ifndef _SDL_directfb_modes_h
    4.28 +#define _SDL_directfb_modes_h
    4.29 +
    4.30 +#include "SDL_DirectFB_video.h"
    4.31 +
    4.32 +#define SDL_DFB_DISPLAYDATA(dev, win)  DFB_DisplayData *dispdata = ((win && dev) ? (DFB_DisplayData *) (dev)->displays[(win)->display].driverdata : NULL)
    4.33 +
    4.34 +typedef struct _DFB_DisplayData DFB_DisplayData;
    4.35 +struct _DFB_DisplayData
    4.36 +{
    4.37 +    IDirectFBDisplayLayer *layer;
    4.38 +    DFBSurfacePixelFormat pixelformat;
    4.39 +    /* FIXME: support for multiple video layer. 
    4.40 +     * However, I do not know any card supporting 
    4.41 +     * more than one
    4.42 +     */
    4.43 +    DFBDisplayLayerID vidID;
    4.44 +    IDirectFBDisplayLayer *vidlayer;
    4.45 +
    4.46 +    int vidIDinuse;
    4.47 +
    4.48 +    int cw;
    4.49 +    int ch;
    4.50 +};
    4.51 +
    4.52 +
    4.53 +extern void DirectFB_InitModes(_THIS);
    4.54 +extern void DirectFB_GetDisplayModes(_THIS);
    4.55 +extern int DirectFB_SetDisplayMode(_THIS, SDL_DisplayMode * mode);
    4.56 +extern void DirectFB_QuitModes(_THIS);
    4.57 +
    4.58 +#endif /* _SDL_directfb_modes_h */
    4.59 +
    4.60 +/* vi: set ts=4 sw=4 expandtab: */
     5.1 --- a/src/video/directfb/SDL_DirectFB_mouse.c	Sun Aug 31 16:03:55 2008 +0000
     5.2 +++ b/src/video/directfb/SDL_DirectFB_mouse.c	Sun Aug 31 16:04:32 2008 +0000
     5.3 @@ -22,7 +22,6 @@
     5.4  #include "SDL_config.h"
     5.5  
     5.6  #include "SDL_DirectFB_video.h"
     5.7 -#include "SDL_DirectFB_mouse.h"
     5.8  
     5.9  #include "../SDL_sysvideo.h"
    5.10  #include "../../events/SDL_mouse_c.h"
    5.11 @@ -49,7 +48,8 @@
    5.12      mouse.FreeCursor = DirectFB_FreeCursor;
    5.13      mouse.WarpMouse = DirectFB_WarpMouse;
    5.14      mouse.FreeMouse = DirectFB_FreeMouse;
    5.15 -    devdata->mouse = SDL_AddMouse(&mouse, -1);
    5.16 +    mouse.cursor_shown = 1;
    5.17 +    devdata->mouse = SDL_AddMouse(&mouse, -1, "Mouse", 0, 0, 1);
    5.18  }
    5.19  
    5.20  void
    5.21 @@ -85,23 +85,21 @@
    5.22      dsc.height = surface->h;
    5.23      dsc.pixelformat = DSPF_ARGB;
    5.24  
    5.25 -    SDL_DFB_CHECKERR(devdata->
    5.26 -                     dfb->CreateSurface(devdata->dfb, &dsc, &curdata->surf));
    5.27 +    SDL_DFB_CHECKERR(devdata->dfb->
    5.28 +                     CreateSurface(devdata->dfb, &dsc, &curdata->surf));
    5.29      curdata->hotx = hot_x;
    5.30      curdata->hoty = hot_y;
    5.31      cursor->driverdata = curdata;
    5.32  
    5.33 -    SDL_DFB_CHECKERR(curdata->
    5.34 -                     surf->Lock(curdata->surf, DSLF_WRITE, (void *) &dest,
    5.35 -                                &pitch));
    5.36 +    SDL_DFB_CHECKERR(curdata->surf->
    5.37 +                     Lock(curdata->surf, DSLF_WRITE, (void *) &dest, &pitch));
    5.38  
    5.39 -    //FIXME: Implies a lot of things, e.g. rgba format for SDL_SURFACE ....
    5.40 +    /* Relies on the fact that this is only called with ARGB surface. */
    5.41      p = surface->pixels;
    5.42 -    for (i = 0; i < surface->w * surface->h; i++)
    5.43 -        if (p[i] == 0x00000000)
    5.44 -            dest[i] = 0x00000000;
    5.45 -        else
    5.46 -            dest[i] = p[i];
    5.47 +    for (i = 0; i < surface->h; i++)
    5.48 +        memcpy((char *) dest + i * pitch, (char *) p + i * surface->pitch,
    5.49 +               4 * surface->w);
    5.50 +
    5.51      curdata->surf->Unlock(curdata->surf);
    5.52      return cursor;
    5.53    error:
    5.54 @@ -113,37 +111,38 @@
    5.55  DirectFB_ShowCursor(SDL_Cursor * cursor)
    5.56  {
    5.57      SDL_DFB_CURSORDATA(cursor);
    5.58 -    SDL_VideoDevice *dev = SDL_GetVideoDevice();
    5.59 -    SDL_DFB_DEVICEDATA(dev);
    5.60 -#if 0
    5.61 -    DFB_DisplayData *dispdata =
    5.62 -        (DFB_DisplayData *) dev->displays[dev->current_display].driverdata;
    5.63 -#endif
    5.64      DFBResult ret;
    5.65      SDL_WindowID wid;
    5.66  
    5.67      wid = SDL_GetFocusWindow();
    5.68 -    if (!wid)
    5.69 +    if (wid < 0)
    5.70          return -1;
    5.71      else {
    5.72          SDL_Window *window = SDL_GetWindowFromID(wid);
    5.73          SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
    5.74 -        DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
    5.75 -        DFB_WindowData *windata = (DFB_WindowData *) window->driverdata;
    5.76  
    5.77 -        if (cursor)
    5.78 -            SDL_DFB_CHECKERR(windata->window->SetCursorShape(windata->window,
    5.79 -                                                             curdata->surf,
    5.80 -                                                             curdata->hotx,
    5.81 -                                                             curdata->hoty));
    5.82 -        //TODO: Check administrative 
    5.83 -        SDL_DFB_CHECKERR(dispdata->layer->SetCooperativeLevel(dispdata->layer,
    5.84 -                                                              DLSCL_ADMINISTRATIVE));
    5.85 -        SDL_DFB_CHECKERR(dispdata->layer->SetCursorOpacity(dispdata->layer,
    5.86 -                                                           cursor ? 0xC0 :
    5.87 -                                                           0x00));
    5.88 -        SDL_DFB_CHECKERR(dispdata->layer->SetCooperativeLevel(dispdata->layer,
    5.89 -                                                              DLSCL_SHARED));
    5.90 +        if (display) {
    5.91 +            DFB_DisplayData *dispdata =
    5.92 +                (DFB_DisplayData *) display->driverdata;
    5.93 +            DFB_WindowData *windata = (DFB_WindowData *) window->driverdata;
    5.94 +
    5.95 +            if (cursor)
    5.96 +                SDL_DFB_CHECKERR(windata->window->
    5.97 +                                 SetCursorShape(windata->window,
    5.98 +                                                curdata->surf, curdata->hotx,
    5.99 +                                                curdata->hoty));
   5.100 +
   5.101 +            /* fprintf(stdout, "Cursor is %s\n", cursor ? "on" : "off"); */
   5.102 +            SDL_DFB_CHECKERR(dispdata->layer->
   5.103 +                             SetCooperativeLevel(dispdata->layer,
   5.104 +                                                 DLSCL_ADMINISTRATIVE));
   5.105 +            SDL_DFB_CHECKERR(dispdata->layer->
   5.106 +                             SetCursorOpacity(dispdata->layer,
   5.107 +                                              cursor ? 0xC0 : 0x00));
   5.108 +            SDL_DFB_CHECKERR(dispdata->layer->
   5.109 +                             SetCooperativeLevel(dispdata->layer,
   5.110 +                                                 DLSCL_SHARED));
   5.111 +        }
   5.112      }
   5.113  
   5.114      return 0;
   5.115 @@ -155,8 +154,7 @@
   5.116  static void
   5.117  DirectFB_MoveCursor(SDL_Cursor * cursor)
   5.118  {
   5.119 -    SDL_DFB_CURSORDATA(cursor);
   5.120 -    /* Do we need to do something here ? */
   5.121 +
   5.122  }
   5.123  
   5.124  /* Free a window manager cursor */
   5.125 @@ -182,8 +180,8 @@
   5.126      int cx, cy;
   5.127  
   5.128      SDL_DFB_CHECKERR(windata->window->GetPosition(windata->window, &cx, &cy));
   5.129 -    SDL_DFB_CHECKERR(dispdata->
   5.130 -                     layer->WarpCursor(dispdata->layer, cx + x, cy + y));
   5.131 +    SDL_DFB_CHECKERR(dispdata->layer->
   5.132 +                     WarpCursor(dispdata->layer, cx + x, cy + y));
   5.133  
   5.134    error:
   5.135      return;
   5.136 @@ -193,8 +191,7 @@
   5.137  static void
   5.138  DirectFB_FreeMouse(SDL_Mouse * mouse)
   5.139  {
   5.140 -    // nothing yet  
   5.141 -
   5.142 +    /* nothing yet */
   5.143  }
   5.144  
   5.145  /* 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_opengl.c	Sun Aug 31 16:04:32 2008 +0000
     6.3 @@ -0,0 +1,299 @@
     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 +
    6.29 +#if SDL_DIRECTFB_OPENGL
    6.30 +
    6.31 +struct SDL_GLDriverData
    6.32 +{
    6.33 +    int gl_active;              /* to stop switching drivers while we have a valid context */
    6.34 +    int initialized;
    6.35 +    DirectFB_GLContext *firstgl;        /* linked list */
    6.36 +};
    6.37 +
    6.38 +#define OPENGL_REQUIRS_DLOPEN
    6.39 +#if defined(OPENGL_REQUIRS_DLOPEN) && defined(SDL_LOADSO_DLOPEN)
    6.40 +#include <dlfcn.h>
    6.41 +#define GL_LoadObject(X)	dlopen(X, (RTLD_NOW|RTLD_GLOBAL))
    6.42 +#define GL_LoadFunction		dlsym
    6.43 +#define GL_UnloadObject		dlclose
    6.44 +#else
    6.45 +#define GL_LoadObject	SDL_LoadObject
    6.46 +#define GL_LoadFunction	SDL_LoadFunction
    6.47 +#define GL_UnloadObject	SDL_UnloadObject
    6.48 +#endif
    6.49 +
    6.50 +static void DirectFB_GL_UnloadLibrary(_THIS);
    6.51 +
    6.52 +int
    6.53 +DirectFB_GL_Initialize(_THIS)
    6.54 +{
    6.55 +    if (_this->gl_data) {
    6.56 +        return 0;
    6.57 +    }
    6.58 +
    6.59 +    _this->gl_data =
    6.60 +        (struct SDL_GLDriverData *) SDL_calloc(1,
    6.61 +                                               sizeof(struct
    6.62 +                                                      SDL_GLDriverData));
    6.63 +    if (!_this->gl_data) {
    6.64 +        SDL_OutOfMemory();
    6.65 +        return -1;
    6.66 +    }
    6.67 +    _this->gl_data->initialized = 0;
    6.68 +
    6.69 +    ++_this->gl_data->initialized;
    6.70 +    _this->gl_data->firstgl = NULL;
    6.71 +
    6.72 +    if (DirectFB_GL_LoadLibrary(_this, NULL) < 0) {
    6.73 +        return -1;
    6.74 +    }
    6.75 +
    6.76 +    /* Initialize extensions */
    6.77 +    /* FIXME needed?
    6.78 +     * X11_GL_InitExtensions(_this);
    6.79 +     */
    6.80 +
    6.81 +    return 0;
    6.82 +}
    6.83 +
    6.84 +void
    6.85 +DirectFB_GL_Shutdown(_THIS)
    6.86 +{
    6.87 +    if (!_this->gl_data || (--_this->gl_data->initialized > 0)) {
    6.88 +        return;
    6.89 +    }
    6.90 +
    6.91 +    DirectFB_GL_UnloadLibrary(_this);
    6.92 +
    6.93 +    SDL_free(_this->gl_data);
    6.94 +    _this->gl_data = NULL;
    6.95 +}
    6.96 +
    6.97 +int
    6.98 +DirectFB_GL_LoadLibrary(_THIS, const char *path)
    6.99 +{
   6.100 +    SDL_DFB_DEVICEDATA(_this);
   6.101 +
   6.102 +    void *handle = NULL;
   6.103 +
   6.104 +    SDL_DFB_DEBUG("Loadlibrary : %s\n", path);
   6.105 +
   6.106 +    if (_this->gl_data->gl_active) {
   6.107 +        SDL_SetError("OpenGL context already created");
   6.108 +        return -1;
   6.109 +    }
   6.110 +
   6.111 +
   6.112 +    if (path == NULL) {
   6.113 +        path = SDL_getenv("SDL_VIDEO_GL_DRIVER");
   6.114 +        if (path == NULL) {
   6.115 +            path = "libGL.so";
   6.116 +        }
   6.117 +    }
   6.118 +
   6.119 +    handle = GL_LoadObject(path);
   6.120 +    if (handle == NULL) {
   6.121 +        SDL_DFB_ERR("Library not found: %s\n", path);
   6.122 +        /* SDL_LoadObject() will call SDL_SetError() for us. */
   6.123 +        return -1;
   6.124 +    }
   6.125 +
   6.126 +    SDL_DFB_DEBUG("Loaded library: %s\n", path);
   6.127 +
   6.128 +    /* Unload the old driver and reset the pointers */
   6.129 +    DirectFB_GL_UnloadLibrary(_this);
   6.130 +
   6.131 +    _this->gl_config.dll_handle = handle;
   6.132 +    _this->gl_config.driver_loaded = 1;
   6.133 +    if (path) {
   6.134 +        SDL_strlcpy(_this->gl_config.driver_path, path,
   6.135 +                    SDL_arraysize(_this->gl_config.driver_path));
   6.136 +    } else {
   6.137 +        *_this->gl_config.driver_path = '\0';
   6.138 +    }
   6.139 +
   6.140 +    devdata->glFinish = DirectFB_GL_GetProcAddress(_this, "glFinish");
   6.141 +    devdata->glFlush = DirectFB_GL_GetProcAddress(_this, "glFlush");
   6.142 +
   6.143 +    return 0;
   6.144 +}
   6.145 +
   6.146 +static void
   6.147 +DirectFB_GL_UnloadLibrary(_THIS)
   6.148 +{
   6.149 +    int ret;
   6.150 +
   6.151 +    if (_this->gl_config.driver_loaded) {
   6.152 +
   6.153 +        ret = GL_UnloadObject(_this->gl_config.dll_handle);
   6.154 +        if (ret)
   6.155 +            SDL_DFB_ERR("Error #%d trying to unload library.\n", ret);
   6.156 +        _this->gl_config.dll_handle = NULL;
   6.157 +        _this->gl_config.driver_loaded = 0;
   6.158 +    }
   6.159 +}
   6.160 +
   6.161 +void *
   6.162 +DirectFB_GL_GetProcAddress(_THIS, const char *proc)
   6.163 +{
   6.164 +    void *handle;
   6.165 +
   6.166 +    handle = _this->gl_config.dll_handle;
   6.167 +    return GL_LoadFunction(handle, proc);
   6.168 +}
   6.169 +
   6.170 +SDL_GLContext
   6.171 +DirectFB_GL_CreateContext(_THIS, SDL_Window * window)
   6.172 +{
   6.173 +    SDL_DFB_WINDOWDATA(window);
   6.174 +    DirectFB_GLContext *context;
   6.175 +    int ret;
   6.176 +
   6.177 +    SDL_DFB_CALLOC(context, 1, sizeof(*context));
   6.178 +
   6.179 +    SDL_DFB_CHECKERR(windata->surface->
   6.180 +                     GetGL(windata->surface, &context->context));
   6.181 +    SDL_DFB_CHECKERR(context->context->Unlock(context->context));
   6.182 +
   6.183 +    context->next = _this->gl_data->firstgl;
   6.184 +    _this->gl_data->firstgl = context;
   6.185 +
   6.186 +    if (DirectFB_GL_MakeCurrent(_this, window, context) < 0) {
   6.187 +        DirectFB_GL_DeleteContext(_this, context);
   6.188 +        return NULL;
   6.189 +    }
   6.190 +
   6.191 +    return context;
   6.192 +
   6.193 +  error:
   6.194 +    return NULL;
   6.195 +}
   6.196 +
   6.197 +int
   6.198 +DirectFB_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
   6.199 +{
   6.200 +    SDL_DFB_WINDOWDATA(window);
   6.201 +    DirectFB_GLContext *ctx = (DirectFB_GLContext *) context;
   6.202 +    DirectFB_GLContext *p;
   6.203 +
   6.204 +    int ret;
   6.205 +
   6.206 +    for (p = _this->gl_data->firstgl; p; p = p->next)
   6.207 +        p->context->Unlock(p->context);
   6.208 +
   6.209 +    if (windata) {
   6.210 +        int cw, ch;
   6.211 +
   6.212 +        windata->gl_context = NULL;
   6.213 +        /* Everything is unlocked, check for a resize */
   6.214 +        SDL_DFB_CHECKERR(windata->surface->
   6.215 +                         GetSize(windata->surface, &cw, &ch));
   6.216 +        if (cw != window->w || ch != window->h)
   6.217 +            SDL_DFB_CHECKERR(windata->window->
   6.218 +                             ResizeSurface(windata->window, window->w,
   6.219 +                                           window->h));
   6.220 +    }
   6.221 +
   6.222 +    if (ctx != NULL) {
   6.223 +        SDL_DFB_CHECKERR(ctx->context->Lock(ctx->context));
   6.224 +    }
   6.225 +
   6.226 +    if (windata)
   6.227 +        windata->gl_context = ctx;
   6.228 +
   6.229 +    return 0;
   6.230 +  error:
   6.231 +    return -1;
   6.232 +}
   6.233 +
   6.234 +int
   6.235 +DirectFB_GL_SetSwapInterval(_THIS, int interval)
   6.236 +{
   6.237 +    SDL_Unsupported();
   6.238 +    return -1;
   6.239 +}
   6.240 +
   6.241 +int
   6.242 +DirectFB_GL_GetSwapInterval(_THIS)
   6.243 +{
   6.244 +    SDL_Unsupported();
   6.245 +    return -1;
   6.246 +}
   6.247 +
   6.248 +void
   6.249 +DirectFB_GL_SwapWindow(_THIS, SDL_Window * window)
   6.250 +{
   6.251 +    SDL_DFB_DEVICEDATA(_this);
   6.252 +    SDL_DFB_WINDOWDATA(window);
   6.253 +    int ret;
   6.254 +    DFBRegion region;
   6.255 +
   6.256 +    region.x1 = 0;
   6.257 +    region.y1 = 0;
   6.258 +    region.x2 = window->w;
   6.259 +    region.y2 = window->h;
   6.260 +
   6.261 +    if (devdata->glFinish)
   6.262 +        devdata->glFinish();
   6.263 +    else if (devdata->glFlush)
   6.264 +        devdata->glFlush();
   6.265 +
   6.266 +    if (1 || windata->gl_context) {
   6.267 +        /* SDL_DFB_CHECKERR(windata->gl_context->context->Unlock(windata->gl_context->context)); */
   6.268 +        SDL_DFB_CHECKERR(windata->surface->
   6.269 +                         Flip(windata->surface, &region, DSFLIP_ONSYNC));
   6.270 +        /* SDL_DFB_CHECKERR(windata->gl_context->context->Lock(windata->gl_context->context)); */
   6.271 +
   6.272 +    }
   6.273 +
   6.274 +    return;
   6.275 +  error:
   6.276 +    return;
   6.277 +}
   6.278 +
   6.279 +void
   6.280 +DirectFB_GL_DeleteContext(_THIS, SDL_GLContext context)
   6.281 +{
   6.282 +    DirectFB_GLContext *ctx = (DirectFB_GLContext *) context;
   6.283 +    DirectFB_GLContext *p;
   6.284 +
   6.285 +    ctx->context->Unlock(ctx->context);
   6.286 +    ctx->context->Release(ctx->context);
   6.287 +
   6.288 +    p = _this->gl_data->firstgl;
   6.289 +    while (p && p->next != ctx)
   6.290 +        p = p->next;
   6.291 +    if (p)
   6.292 +        p->next = ctx->next;
   6.293 +    else
   6.294 +        _this->gl_data->firstgl = ctx->next;
   6.295 +
   6.296 +    SDL_DFB_FREE(ctx);
   6.297 +
   6.298 +}
   6.299 +
   6.300 +#endif
   6.301 +
   6.302 +/* 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_opengl.h	Sun Aug 31 16:04:32 2008 +0000
     7.3 @@ -0,0 +1,55 @@
     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_opengl_h
    7.28 +#define _SDL_directfb_opengl_h
    7.29 +
    7.30 +#if SDL_DIRECTFB_OPENGL
    7.31 +#include "SDL_opengl.h"
    7.32 +
    7.33 +typedef struct _DirectFB_GLContext DirectFB_GLContext;
    7.34 +struct _DirectFB_GLContext
    7.35 +{
    7.36 +    IDirectFBGL *context;
    7.37 +    DirectFB_GLContext *next;
    7.38 +};
    7.39 +
    7.40 +/* OpenGL functions */
    7.41 +extern int DirectFB_GL_Initialize(_THIS);
    7.42 +extern void DirectFB_GL_Shutdown(_THIS);
    7.43 +
    7.44 +extern int DirectFB_GL_LoadLibrary(_THIS, const char *path);
    7.45 +extern void *DirectFB_GL_GetProcAddress(_THIS, const char *proc);
    7.46 +extern SDL_GLContext DirectFB_GL_CreateContext(_THIS, SDL_Window * window);
    7.47 +extern int DirectFB_GL_MakeCurrent(_THIS, SDL_Window * window,
    7.48 +                                   SDL_GLContext context);
    7.49 +extern int DirectFB_GL_SetSwapInterval(_THIS, int interval);
    7.50 +extern int DirectFB_GL_GetSwapInterval(_THIS);
    7.51 +extern void DirectFB_GL_SwapWindow(_THIS, SDL_Window * window);
    7.52 +extern void DirectFB_GL_DeleteContext(_THIS, SDL_GLContext context);
    7.53 +
    7.54 +#endif /* SDL_DIRECTFB_OPENGL */
    7.55 +
    7.56 +#endif /* _SDL_directfb_opengl_h */
    7.57 +
    7.58 +/* vi: set ts=4 sw=4 expandtab: */
     8.1 --- a/src/video/directfb/SDL_DirectFB_render.c	Sun Aug 31 16:03:55 2008 +0000
     8.2 +++ b/src/video/directfb/SDL_DirectFB_render.c	Sun Aug 31 16:04:32 2008 +0000
     8.3 @@ -29,11 +29,15 @@
     8.4  #include "../SDL_rect_c.h"
     8.5  #include "../SDL_yuv_sw_c.h"
     8.6  
     8.7 +/* the following is not yet tested ... */
     8.8 +#define USE_DISPLAY_PALETTE			(0)
     8.9 +
    8.10  /* GDI renderer implementation */
    8.11  
    8.12  static SDL_Renderer *DirectFB_CreateRenderer(SDL_Window * window,
    8.13                                               Uint32 flags);
    8.14  static int DirectFB_DisplayModeChanged(SDL_Renderer * renderer);
    8.15 +static int DirectFB_ActivateRenderer(SDL_Renderer * renderer);
    8.16  static int DirectFB_CreateTexture(SDL_Renderer * renderer,
    8.17                                    SDL_Texture * texture);
    8.18  static int DirectFB_QueryTexturePixels(SDL_Renderer * renderer,
    8.19 @@ -89,11 +93,12 @@
    8.20       (SDL_TEXTUREBLENDMODE_NONE | SDL_TEXTUREBLENDMODE_MASK |
    8.21        SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD |
    8.22        SDL_TEXTUREBLENDMODE_MOD),
    8.23 -     (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST),
    8.24 +     (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST |
    8.25 +      SDL_TEXTURESCALEMODE_SLOW | SDL_TEXTURESCALEMODE_BEST),
    8.26       14,
    8.27       {
    8.28 +      SDL_PIXELFORMAT_INDEX4LSB,
    8.29        SDL_PIXELFORMAT_INDEX8,
    8.30 -      SDL_PIXELFORMAT_INDEX4LSB,
    8.31        SDL_PIXELFORMAT_RGB332,
    8.32        SDL_PIXELFORMAT_RGB555,
    8.33        SDL_PIXELFORMAT_RGB565,
    8.34 @@ -115,19 +120,32 @@
    8.35      IDirectFBSurface *surface;
    8.36      DFBSurfaceFlipFlags flipflags;
    8.37      int isyuvdirect;
    8.38 +    int size_changed;
    8.39  } DirectFB_RenderData;
    8.40  
    8.41  typedef struct
    8.42  {
    8.43 -    IDirectFBDisplayLayer *vidlayer;
    8.44      IDirectFBSurface *surface;
    8.45      Uint32 format;
    8.46      void *pixels;
    8.47      int pitch;
    8.48      IDirectFBPalette *palette;
    8.49 -    DFB_DisplayData *display;
    8.50 +    SDL_VideoDisplay *display;
    8.51 +    SDL_DirtyRectList dirty;
    8.52 +#if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 2)
    8.53 +    DFBSurfaceRenderOptions render_options;
    8.54 +#endif
    8.55  } DirectFB_TextureData;
    8.56  
    8.57 +static __inline__ void
    8.58 +SDLtoDFBRect(const SDL_Rect * sr, DFBRectangle * dr)
    8.59 +{
    8.60 +    dr->x = sr->x;
    8.61 +    dr->y = sr->y;
    8.62 +    dr->h = sr->h;
    8.63 +    dr->w = sr->w;
    8.64 +}
    8.65 +
    8.66  void
    8.67  DirectFB_AddRenderDriver(_THIS)
    8.68  {
    8.69 @@ -136,24 +154,53 @@
    8.70          SDL_AddRenderDriver(i, &DirectFB_RenderDriver);
    8.71  }
    8.72  
    8.73 +static int
    8.74 +DisplayPaletteChanged(void *userdata, SDL_Palette * palette)
    8.75 +{
    8.76 +#if USE_DISPLAY_PALETTE
    8.77 +    DirectFB_RenderData *data = (DirectFB_RenderData *) userdata;
    8.78 +    IDirectFBPalette *surfpal;
    8.79 +
    8.80 +    int ret;
    8.81 +    int i;
    8.82 +    int ncolors;
    8.83 +    DFBColor entries[256];
    8.84 +
    8.85 +    SDL_DFB_CHECKERR(data->surface->GetPalette(data->surface, &surfpal));
    8.86 +
    8.87 +    /* FIXME: number of colors */
    8.88 +    ncolors = (palette->ncolors < 256 ? palette->ncolors : 256);
    8.89 +
    8.90 +    for (i = 0; i < ncolors; ++i) {
    8.91 +        entries[i].r = palette->colors[i].r;
    8.92 +        entries[i].g = palette->colors[i].g;
    8.93 +        entries[i].b = palette->colors[i].b;
    8.94 +        entries[i].a = palette->colors[i].unused;
    8.95 +    }
    8.96 +    SDL_DFB_CHECKERR(surfpal->SetEntries(surfpal, entries, ncolors, 0));
    8.97 +    return 0;
    8.98 +  error:
    8.99 +#endif
   8.100 +    return -1;
   8.101 +}
   8.102 +
   8.103 +
   8.104  SDL_Renderer *
   8.105  DirectFB_CreateRenderer(SDL_Window * window, Uint32 flags)
   8.106  {
   8.107      SDL_DFB_WINDOWDATA(window);
   8.108      SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   8.109 -    SDL_DFB_DEVICEDATA(display->device);
   8.110      SDL_Renderer *renderer = NULL;
   8.111      DirectFB_RenderData *data = NULL;
   8.112      DFBResult ret;
   8.113 -    DFBSurfaceDescription dsc;
   8.114      DFBSurfaceCapabilities scaps;
   8.115      char *p;
   8.116 -    int i, n;
   8.117  
   8.118      SDL_DFB_CALLOC(renderer, 1, sizeof(*renderer));
   8.119      SDL_DFB_CALLOC(data, 1, sizeof(*data));
   8.120  
   8.121      renderer->DisplayModeChanged = DirectFB_DisplayModeChanged;
   8.122 +    renderer->ActivateRenderer = DirectFB_ActivateRenderer;
   8.123      renderer->CreateTexture = DirectFB_CreateTexture;
   8.124      renderer->QueryTexturePixels = DirectFB_QueryTexturePixels;
   8.125      renderer->SetTexturePalette = DirectFB_SetTexturePalette;
   8.126 @@ -179,14 +226,16 @@
   8.127          SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTDISCARD;
   8.128  
   8.129      data->surface = windata->surface;
   8.130 -    data->flipflags = 0;
   8.131 +    data->surface->AddRef(data->surface);
   8.132 +
   8.133 +    data->flipflags = DSFLIP_PIPELINE | DSFLIP_BLIT;
   8.134  
   8.135      if (flags & SDL_RENDERER_PRESENTVSYNC) {
   8.136          data->flipflags = DSFLIP_ONSYNC;
   8.137          renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
   8.138      }
   8.139  
   8.140 -    data->surface->GetCapabilities(data->surface, &scaps);
   8.141 +    SDL_DFB_CHECKERR(data->surface->GetCapabilities(data->surface, &scaps));
   8.142      if (scaps & DSCAPS_DOUBLE)
   8.143          renderer->info.flags |= SDL_RENDERER_PRESENTFLIP2;
   8.144      else if (scaps & DSCAPS_TRIPLE)
   8.145 @@ -194,11 +243,16 @@
   8.146      else
   8.147          renderer->info.flags |= SDL_RENDERER_SINGLEBUFFER;
   8.148  
   8.149 -    data->isyuvdirect = 1;      /* default is on! */
   8.150 -    p = getenv("SDL_DIRECTFB_YUV_DIRECT");
   8.151 +    data->isyuvdirect = 0;      /* default is off! */
   8.152 +    p = getenv(DFBENV_USE_YUV_DIRECT);
   8.153      if (p)
   8.154          data->isyuvdirect = atoi(p);
   8.155  
   8.156 +    /* Set up a palette watch on the display palette */
   8.157 +    if (display->palette) {
   8.158 +        SDL_AddPaletteWatch(display->palette, DisplayPaletteChanged, data);
   8.159 +    }
   8.160 +
   8.161      return renderer;
   8.162  
   8.163    error:
   8.164 @@ -267,26 +321,38 @@
   8.165  }
   8.166  
   8.167  static int
   8.168 -DirectFB_DisplayModeChanged(SDL_Renderer * renderer)
   8.169 +DirectFB_ActivateRenderer(SDL_Renderer * renderer)
   8.170  {
   8.171      SDL_DFB_RENDERERDATA(renderer);
   8.172      SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   8.173      SDL_DFB_WINDOWDATA(window);
   8.174 -    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   8.175 -    SDL_DFB_DEVICEDATA(display->device);
   8.176 -    DFBResult ret;
   8.177 -    DFBSurfaceDescription dsc;
   8.178 -    int i, n;
   8.179  
   8.180 -    /*
   8.181 -     * Nothing to do here
   8.182 -     */
   8.183 +    if (renddata->size_changed) {
   8.184 +        int cw, ch;
   8.185 +        int ret;
   8.186 +
   8.187 +        SDL_DFB_CHECKERR(windata->surface->
   8.188 +                         GetSize(windata->surface, &cw, &ch));
   8.189 +        if (cw != window->w || ch != window->h)
   8.190 +            SDL_DFB_CHECKERR(windata->window->
   8.191 +                             ResizeSurface(windata->window, window->w,
   8.192 +                                           window->h));
   8.193 +    }
   8.194      return 0;
   8.195    error:
   8.196      return -1;
   8.197  }
   8.198  
   8.199  static int
   8.200 +DirectFB_DisplayModeChanged(SDL_Renderer * renderer)
   8.201 +{
   8.202 +    SDL_DFB_RENDERERDATA(renderer);
   8.203 +
   8.204 +    renddata->size_changed = SDL_TRUE;
   8.205 +    return 0;
   8.206 +}
   8.207 +
   8.208 +static int
   8.209  DirectFB_AcquireVidLayer(SDL_Renderer * renderer, SDL_Texture * texture)
   8.210  {
   8.211      SDL_DFB_RENDERERDATA(renderer);
   8.212 @@ -301,36 +367,42 @@
   8.213      if (renddata->isyuvdirect && (dispdata->vidID >= 0)
   8.214          && (!dispdata->vidIDinuse)
   8.215          && SDL_ISPIXELFORMAT_FOURCC(data->format)) {
   8.216 -        layconf.flags = DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT;
   8.217 +        layconf.flags =
   8.218 +            DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT |
   8.219 +            DLCONF_SURFACE_CAPS;
   8.220          layconf.width = texture->w;
   8.221          layconf.height = texture->h;
   8.222          layconf.pixelformat = SDLToDFBPixelFormat(data->format);
   8.223 +        layconf.surface_caps = DSCAPS_VIDEOONLY | DSCAPS_DOUBLE;
   8.224  
   8.225          SDL_DFB_CHECKERR(devdata->dfb->
   8.226                           GetDisplayLayer(devdata->dfb, dispdata->vidID,
   8.227 -                                         &data->vidlayer));
   8.228 -        SDL_DFB_CHECKERR(data->vidlayer->
   8.229 -                         SetCooperativeLevel(data->vidlayer,
   8.230 +                                         &dispdata->vidlayer));
   8.231 +        SDL_DFB_CHECKERR(dispdata->vidlayer->
   8.232 +                         SetCooperativeLevel(dispdata->vidlayer,
   8.233                                               DLSCL_EXCLUSIVE));
   8.234 -        SDL_DFB_CHECKERR(data->vidlayer->
   8.235 -                         SetConfiguration(data->vidlayer, &layconf));
   8.236 -        SDL_DFB_CHECKERR(data->vidlayer->
   8.237 -                         GetSurface(data->vidlayer, &data->surface));
   8.238 -        //SDL_DFB_CHECKERR(data->vidlayer->GetDescription(data->vidlayer, laydsc));
   8.239 +
   8.240 +        if (devdata->use_yuv_underlays) {
   8.241 +            ret = dispdata->vidlayer->SetLevel(dispdata->vidlayer, -1);
   8.242 +            if (ret != DFB_OK)
   8.243 +                SDL_DFB_DEBUG("Underlay Setlevel not supported\n");
   8.244 +        }
   8.245 +        SDL_DFB_CHECKERR(dispdata->vidlayer->
   8.246 +                         SetConfiguration(dispdata->vidlayer, &layconf));
   8.247 +        SDL_DFB_CHECKERR(dispdata->vidlayer->
   8.248 +                         GetSurface(dispdata->vidlayer, &data->surface));
   8.249          dispdata->vidIDinuse = 1;
   8.250 -        data->display = dispdata;
   8.251 -        SDL_DFB_DEBUG("Created HW YUV surface\n");
   8.252 -
   8.253 +        data->display = display;
   8.254          return 0;
   8.255      }
   8.256      return 1;
   8.257    error:
   8.258 -    if (data->vidlayer) {
   8.259 +    if (dispdata->vidlayer) {
   8.260          SDL_DFB_RELEASE(data->surface);
   8.261 -        SDL_DFB_CHECKERR(data->vidlayer->
   8.262 -                         SetCooperativeLevel(data->vidlayer,
   8.263 +        SDL_DFB_CHECKERR(dispdata->vidlayer->
   8.264 +                         SetCooperativeLevel(dispdata->vidlayer,
   8.265                                               DLSCL_ADMINISTRATIVE));
   8.266 -        SDL_DFB_RELEASE(data->vidlayer);
   8.267 +        SDL_DFB_RELEASE(dispdata->vidlayer);
   8.268      }
   8.269      return 1;
   8.270  }
   8.271 @@ -338,23 +410,18 @@
   8.272  static int
   8.273  DirectFB_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   8.274  {
   8.275 -    SDL_DFB_RENDERERDATA(renderer);
   8.276      SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   8.277 -    SDL_DFB_WINDOWDATA(window);
   8.278      SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   8.279      SDL_DFB_DEVICEDATA(display->device);
   8.280      DirectFB_TextureData *data;
   8.281      DFBResult ret;
   8.282      DFBSurfaceDescription dsc;
   8.283 -    DFBDisplayLayerDescription laydsc;
   8.284 -    DFBDisplayLayerConfig layconf;
   8.285  
   8.286      SDL_DFB_CALLOC(data, 1, sizeof(*data));
   8.287      texture->driverdata = data;
   8.288  
   8.289      data->format = texture->format;
   8.290      data->pitch = (texture->w * SDL_BYTESPERPIXEL(data->format));
   8.291 -    data->vidlayer = NULL;
   8.292  
   8.293      if (DirectFB_AcquireVidLayer(renderer, texture) != 0) {
   8.294          /* fill surface description */
   8.295 @@ -365,13 +432,15 @@
   8.296          /* <1.2 Never use DSCAPS_VIDEOONLY here. It kills performance
   8.297           * No DSCAPS_SYSTEMONLY either - let dfb decide
   8.298           * 1.2: DSCAPS_SYSTEMONLY boosts performance by factor ~8
   8.299 +         * Depends on other settings as well. Let dfb decide.
   8.300           */
   8.301          dsc.caps = DSCAPS_PREMULTIPLIED;
   8.302 -
   8.303 +#if 0
   8.304          if (texture->access == SDL_TEXTUREACCESS_STREAMING)
   8.305              dsc.caps |= DSCAPS_SYSTEMONLY;
   8.306          else
   8.307              dsc.caps |= DSCAPS_VIDEOONLY;
   8.308 +#endif
   8.309  
   8.310          /* find the right pixelformat */
   8.311  
   8.312 @@ -393,6 +462,15 @@
   8.313          }
   8.314  
   8.315      }
   8.316 +#if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 2)
   8.317 +    data->render_options = DSRO_NONE;
   8.318 +#endif
   8.319 +
   8.320 +    if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
   8.321 +        data->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format);
   8.322 +        SDL_DFB_CALLOC(data->pixels, 1, texture->h * data->pitch);
   8.323 +    }
   8.324 +
   8.325      return 0;
   8.326  
   8.327    error:
   8.328 @@ -406,13 +484,16 @@
   8.329  DirectFB_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
   8.330                              void **pixels, int *pitch)
   8.331  {
   8.332 -    DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
   8.333 +    DirectFB_TextureData *texturedata =
   8.334 +        (DirectFB_TextureData *) texture->driverdata;
   8.335  
   8.336 -    /*
   8.337 -     * Always fail here so in compat mode SDL_HWSURFACE is set !
   8.338 -     */
   8.339 -
   8.340 -    return -1;
   8.341 +    if (texturedata->display) {
   8.342 +        return -1;
   8.343 +    } else {
   8.344 +        *pixels = texturedata->pixels;
   8.345 +        *pitch = texturedata->pitch;
   8.346 +    }
   8.347 +    return 0;
   8.348  }
   8.349  
   8.350  static int
   8.351 @@ -420,8 +501,6 @@
   8.352                             const SDL_Color * colors, int firstcolor,
   8.353                             int ncolors)
   8.354  {
   8.355 -    DirectFB_RenderData *renderdata =
   8.356 -        (DirectFB_RenderData *) renderer->driverdata;
   8.357      DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
   8.358      DFBResult ret;
   8.359  
   8.360 @@ -468,6 +547,7 @@
   8.361              colors[i].r = entries[i].r;
   8.362              colors[i].g = entries[i].g;
   8.363              colors[i].b = entries[i].b;
   8.364 +            colors->unused = SDL_ALPHA_OPAQUE;
   8.365          }
   8.366          return 0;
   8.367      } else {
   8.368 @@ -510,20 +590,29 @@
   8.369  static int
   8.370  DirectFB_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
   8.371  {
   8.372 +#if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 2)
   8.373 +
   8.374 +    DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
   8.375 +
   8.376      switch (texture->scaleMode) {
   8.377      case SDL_TEXTURESCALEMODE_NONE:
   8.378      case SDL_TEXTURESCALEMODE_FAST:
   8.379 -        return 0;
   8.380 +        data->render_options = DSRO_NONE;
   8.381 +        break;
   8.382      case SDL_TEXTURESCALEMODE_SLOW:
   8.383 +        data->render_options = DSRO_SMOOTH_UPSCALE | DSRO_SMOOTH_DOWNSCALE;
   8.384 +        break;
   8.385      case SDL_TEXTURESCALEMODE_BEST:
   8.386 -        SDL_Unsupported();
   8.387 -        texture->scaleMode = SDL_TEXTURESCALEMODE_FAST;
   8.388 -        return -1;
   8.389 +        data->render_options =
   8.390 +            DSRO_SMOOTH_UPSCALE | DSRO_SMOOTH_DOWNSCALE | DSRO_ANTIALIAS;
   8.391 +        break;
   8.392      default:
   8.393          SDL_Unsupported();
   8.394 +        data->render_options = DSRO_NONE;
   8.395          texture->scaleMode = SDL_TEXTURESCALEMODE_NONE;
   8.396          return -1;
   8.397      }
   8.398 +#endif
   8.399      return 0;
   8.400  }
   8.401  
   8.402 @@ -532,8 +621,6 @@
   8.403                         const SDL_Rect * rect, const void *pixels, int pitch)
   8.404  {
   8.405      DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
   8.406 -    DirectFB_RenderData *renderdata =
   8.407 -        (DirectFB_RenderData *) renderer->driverdata;
   8.408      DFBResult ret;
   8.409      Uint8 *dpixels;
   8.410      int dpitch;
   8.411 @@ -566,37 +653,32 @@
   8.412                       const SDL_Rect * rect, int markDirty, void **pixels,
   8.413                       int *pitch)
   8.414  {
   8.415 -    DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
   8.416 +    DirectFB_TextureData *texturedata =
   8.417 +        (DirectFB_TextureData *) texture->driverdata;
   8.418      DFBResult ret;
   8.419 -    void *fdata;
   8.420 -    int fpitch;
   8.421  
   8.422 -    SDL_DFB_CHECKERR(data->surface->Lock(data->surface,
   8.423 -                                         DSLF_WRITE | DSLF_READ, &fdata,
   8.424 -                                         &fpitch));
   8.425 -    data->pixels = fdata;
   8.426 -    data->pitch = fpitch;
   8.427 -
   8.428 -    switch (texture->format) {
   8.429 -    case SDL_PIXELFORMAT_YV12:
   8.430 -    case SDL_PIXELFORMAT_IYUV:
   8.431 -        if (rect
   8.432 -            && (rect->x != 0 || rect->y != 0 || rect->w != texture->w
   8.433 -                || rect->h != texture->h)) {
   8.434 -            SDL_SetError
   8.435 -                ("YV12 and IYUV textures only support full surface locks");
   8.436 -            return -1;
   8.437 -        }
   8.438 -        break;
   8.439 -    default:
   8.440 -        /* Only one plane, no worries */
   8.441 -        break;
   8.442 +    if (markDirty) {
   8.443 +        SDL_AddDirtyRect(&texturedata->dirty, rect);
   8.444      }
   8.445  
   8.446 -    *pitch = data->pitch;
   8.447 -    *pixels = data->pixels;
   8.448 +    if (texturedata->display) {
   8.449 +        void *fdata;
   8.450 +        int fpitch;
   8.451  
   8.452 +        SDL_DFB_CHECKERR(texturedata->surface->Lock(texturedata->surface,
   8.453 +                                                    DSLF_WRITE | DSLF_READ,
   8.454 +                                                    &fdata, &fpitch));
   8.455 +        *pitch = fpitch;
   8.456 +        *pixels = fdata;
   8.457 +    } else {
   8.458 +        *pixels =
   8.459 +            (void *) ((Uint8 *) texturedata->pixels +
   8.460 +                      rect->y * texturedata->pitch +
   8.461 +                      rect->x * SDL_BYTESPERPIXEL(texture->format));
   8.462 +        *pitch = texturedata->pitch;
   8.463 +    }
   8.464      return 0;
   8.465 +
   8.466    error:
   8.467      return -1;
   8.468  }
   8.469 @@ -604,17 +686,25 @@
   8.470  static void
   8.471  DirectFB_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   8.472  {
   8.473 -    DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
   8.474 +    DirectFB_TextureData *texturedata =
   8.475 +        (DirectFB_TextureData *) texture->driverdata;
   8.476  
   8.477 -    data->surface->Unlock(data->surface);
   8.478 -    data->pixels = NULL;
   8.479 +    if (texturedata->display) {
   8.480 +        texturedata->surface->Unlock(texturedata->surface);
   8.481 +        texturedata->pixels = NULL;
   8.482 +    }
   8.483  }
   8.484  
   8.485  static void
   8.486  DirectFB_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   8.487                        int numrects, const SDL_Rect * rects)
   8.488  {
   8.489 -    //TODO: DirtyTexture
   8.490 +    DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
   8.491 +    int i;
   8.492 +
   8.493 +    for (i = 0; i < numrects; ++i) {
   8.494 +        SDL_AddDirtyRect(&data->dirty, &rects[i]);
   8.495 +    }
   8.496  }
   8.497  
   8.498  static int
   8.499 @@ -643,36 +733,51 @@
   8.500          (DirectFB_TextureData *) texture->driverdata;
   8.501      DFBResult ret;
   8.502  
   8.503 -    if (texturedata->vidlayer) {
   8.504 +    if (texturedata->display) {
   8.505          int px, py;
   8.506          SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   8.507 -        SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   8.508 -        SDL_DFB_DEVICEDATA(display->device);
   8.509 +        SDL_DFB_WINDOWDATA(window);
   8.510 +        SDL_VideoDisplay *display = texturedata->display;
   8.511          DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
   8.512 -        SDL_DFB_WINDOWDATA(window);
   8.513  
   8.514 -        SDL_DFB_CHECKERR(texturedata->vidlayer->
   8.515 -                         SetSourceRectangle(texturedata->vidlayer, srcrect->x,
   8.516 +        SDL_DFB_CHECKERR(dispdata->vidlayer->
   8.517 +                         SetSourceRectangle(dispdata->vidlayer, srcrect->x,
   8.518                                              srcrect->y, srcrect->w,
   8.519                                              srcrect->h));
   8.520          windata->window->GetPosition(windata->window, &px, &py);
   8.521 -        SDL_DFB_CHECKERR(texturedata->vidlayer->
   8.522 -                         SetScreenRectangle(texturedata->vidlayer,
   8.523 +        SDL_DFB_CHECKERR(dispdata->vidlayer->
   8.524 +                         SetScreenRectangle(dispdata->vidlayer,
   8.525                                              px + dstrect->x, py + dstrect->y,
   8.526                                              dstrect->w, dstrect->h));
   8.527      } else {
   8.528          DFBRectangle sr, dr;
   8.529          DFBSurfaceBlittingFlags flags = 0;
   8.530  
   8.531 -        sr.x = srcrect->x;
   8.532 -        sr.y = srcrect->y;
   8.533 -        sr.w = srcrect->w;
   8.534 -        sr.h = srcrect->h;
   8.535 +        if (texturedata->dirty.list) {
   8.536 +            SDL_DirtyRect *dirty;
   8.537 +            void *pixels;
   8.538 +            int bpp = SDL_BYTESPERPIXEL(texture->format);
   8.539 +            int pitch = texturedata->pitch;
   8.540  
   8.541 -        dr.x = dstrect->x;
   8.542 -        dr.y = dstrect->y;
   8.543 -        dr.w = dstrect->w;
   8.544 -        dr.h = dstrect->h;
   8.545 +            for (dirty = texturedata->dirty.list; dirty; dirty = dirty->next) {
   8.546 +                SDL_Rect *rect = &dirty->rect;
   8.547 +                pixels =
   8.548 +                    (void *) ((Uint8 *) texturedata->pixels +
   8.549 +                              rect->y * pitch + rect->x * bpp);
   8.550 +                DirectFB_UpdateTexture(renderer, texture, rect,
   8.551 +                                       texturedata->pixels,
   8.552 +                                       texturedata->pitch);
   8.553 +            }
   8.554 +            SDL_ClearDirtyRects(&texturedata->dirty);
   8.555 +        }
   8.556 +#if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 2)
   8.557 +        SDL_DFB_CHECKERR(data->surface->SetRenderOptions(data->surface,
   8.558 +                                                         texturedata->
   8.559 +                                                         render_options));
   8.560 +#endif
   8.561 +
   8.562 +        SDLtoDFBRect(srcrect, &sr);
   8.563 +        SDLtoDFBRect(dstrect, &dr);
   8.564  
   8.565          if (texture->
   8.566              modMode & (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA))
   8.567 @@ -695,6 +800,7 @@
   8.568  
   8.569          switch (texture->blendMode) {
   8.570          case SDL_TEXTUREBLENDMODE_NONE:
   8.571 +                                       /**< No blending */
   8.572              flags |= DSBLIT_NOFX;
   8.573              data->surface->SetSrcBlendFunction(data->surface, DSBF_ONE);
   8.574              data->surface->SetDstBlendFunction(data->surface, DSBF_ZERO);
   8.575 @@ -725,10 +831,11 @@
   8.576  
   8.577          SDL_DFB_CHECKERR(data->surface->
   8.578                           SetBlittingFlags(data->surface, flags));
   8.579 +
   8.580          if (srcrect->w == dstrect->w && srcrect->h == dstrect->h) {
   8.581              SDL_DFB_CHECKERR(data->surface->
   8.582 -                             Blit(data->surface, texturedata->surface, &sr,
   8.583 -                                  dr.x, dr.y));
   8.584 +                             Blit(data->surface, texturedata->surface,
   8.585 +                                  &sr, dr.x, dr.y));
   8.586          } else {
   8.587              SDL_DFB_CHECKERR(data->surface->
   8.588                               StretchBlit(data->surface, texturedata->surface,
   8.589 @@ -746,7 +853,6 @@
   8.590      DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
   8.591      SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   8.592  
   8.593 -    SDL_DirtyRect *dirty;
   8.594      DFBRectangle sr;
   8.595      DFBResult ret;
   8.596  
   8.597 @@ -757,7 +863,7 @@
   8.598  
   8.599      /* Send the data to the display */
   8.600      SDL_DFB_CHECKERR(data->surface->
   8.601 -                     Flip(data->surface, NULL, data->flipflags));
   8.602 +                     Flip(data->surface, NULL, 0 * data->flipflags));
   8.603  
   8.604      return;
   8.605    error:
   8.606 @@ -775,11 +881,15 @@
   8.607      SDL_DFB_RELEASE(data->palette);
   8.608      SDL_DFB_RELEASE(data->surface);
   8.609      if (data->display) {
   8.610 -        data->display->vidIDinuse = 0;
   8.611 -        data->vidlayer->SetCooperativeLevel(data->vidlayer,
   8.612 -                                            DLSCL_ADMINISTRATIVE);
   8.613 +        DFB_DisplayData *dispdata =
   8.614 +            (DFB_DisplayData *) data->display->driverdata;
   8.615 +        dispdata->vidIDinuse = 0;
   8.616 +        dispdata->vidlayer->SetCooperativeLevel(dispdata->vidlayer,
   8.617 +                                                DLSCL_ADMINISTRATIVE);
   8.618 +        SDL_DFB_RELEASE(dispdata->vidlayer);
   8.619      }
   8.620 -    SDL_DFB_RELEASE(data->vidlayer);
   8.621 +    SDL_FreeDirtyRects(&data->dirty);
   8.622 +    SDL_DFB_FREE(data->pixels);
   8.623      SDL_free(data);
   8.624      texture->driverdata = NULL;
   8.625  }
   8.626 @@ -788,10 +898,9 @@
   8.627  DirectFB_DestroyRenderer(SDL_Renderer * renderer)
   8.628  {
   8.629      DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
   8.630 -    int i;
   8.631  
   8.632      if (data) {
   8.633 -        data->surface = NULL;
   8.634 +        SDL_DFB_RELEASE(data->surface);
   8.635          SDL_free(data);
   8.636      }
   8.637      SDL_free(renderer);
     9.1 --- a/src/video/directfb/SDL_DirectFB_video.c	Sun Aug 31 16:03:55 2008 +0000
     9.2 +++ b/src/video/directfb/SDL_DirectFB_video.c	Sun Aug 31 16:04:32 2008 +0000
     9.3 @@ -43,59 +43,23 @@
     9.4  #include "../../events/SDL_events_c.h"
     9.5  #include "SDL_DirectFB_video.h"
     9.6  #include "SDL_DirectFB_events.h"
     9.7 -
     9.8 -/* This is the rect EnumModes2 uses */
     9.9 -struct DirectFBEnumRect
    9.10 -{
    9.11 -    SDL_Rect r;
    9.12 -    struct DirectFBEnumRect *next;
    9.13 -};
    9.14 -
    9.15 -struct DirectFB_GLContext
    9.16 -{
    9.17 -    IDirectFBGL *context;
    9.18 -};
    9.19 +#include "SDL_DirectFB_render.h"
    9.20 +#include "SDL_DirectFB_mouse.h"
    9.21  
    9.22  /* Initialization/Query functions */
    9.23  static int DirectFB_VideoInit(_THIS);
    9.24  static void DirectFB_VideoQuit(_THIS);
    9.25  
    9.26 -static int DirectFB_CreateWindow(_THIS, SDL_Window * window);
    9.27 -static int DirectFB_CreateWindowFrom(_THIS, SDL_Window * window,
    9.28 -                                     const void *data);
    9.29 -static void DirectFB_SetWindowTitle(_THIS, SDL_Window * window);
    9.30 -static void DirectFB_SetWindowPosition(_THIS, SDL_Window * window);
    9.31 -static void DirectFB_SetWindowSize(_THIS, SDL_Window * window);
    9.32 -static void DirectFB_ShowWindow(_THIS, SDL_Window * window);
    9.33 -static void DirectFB_HideWindow(_THIS, SDL_Window * window);
    9.34 -static void DirectFB_RaiseWindow(_THIS, SDL_Window * window);
    9.35 -static void DirectFB_MaximizeWindow(_THIS, SDL_Window * window);
    9.36 -static void DirectFB_MinimizeWindow(_THIS, SDL_Window * window);
    9.37 -static void DirectFB_RestoreWindow(_THIS, SDL_Window * window);
    9.38 -static void DirectFB_SetWindowGrab(_THIS, SDL_Window * window);
    9.39 -static void DirectFB_DestroyWindow(_THIS, SDL_Window * window);
    9.40 -static SDL_bool DirectFB_GetWindowWMInfo(_THIS, SDL_Window * window,
    9.41 -                                         struct SDL_SysWMinfo *info);
    9.42 -
    9.43 -static void DirectFB_GetDisplayModes(_THIS);
    9.44 -static int DirectFB_SetDisplayMode(_THIS, SDL_DisplayMode * mode);
    9.45 +static int DirectFB_Available(void);
    9.46 +static SDL_VideoDevice *DirectFB_CreateDevice(int devindex);
    9.47  
    9.48  static int DirectFB_SetDisplayGammaRamp(_THIS, Uint16 * ramp);
    9.49  static int DirectFB_GetDisplayGammaRamp(_THIS, Uint16 * ramp);
    9.50  
    9.51 -#if SDL_DIRECTFB_OPENGL
    9.52 -static int DirectFB_GL_LoadLibrary(_THIS, const char *path);
    9.53 -static void DirectFB_GL_UnloadLibrary(_THIS);
    9.54 -static void *DirectFB_GL_GetProcAddress(_THIS, const char *proc);
    9.55 -static SDL_GLContext DirectFB_GL_CreateContext(_THIS, SDL_Window * window);
    9.56 -static int DirectFB_GL_MakeCurrent(_THIS, SDL_Window * window,
    9.57 -                                   SDL_GLContext context);
    9.58 -static int DirectFB_GL_SetSwapInterval(_THIS, int interval);
    9.59 -static int DirectFB_GL_GetSwapInterval(_THIS);
    9.60 -static void DirectFB_GL_SwapWindow(_THIS, SDL_Window * window);
    9.61 -static void DirectFB_GL_DeleteContext(_THIS, SDL_GLContext context);
    9.62 -
    9.63 -#endif
    9.64 +VideoBootStrap DirectFB_bootstrap = {
    9.65 +    "directfb", "DirectFB",
    9.66 +    DirectFB_Available, DirectFB_CreateDevice
    9.67 +};
    9.68  
    9.69  /* DirectFB driver bootstrap functions */
    9.70  
    9.71 @@ -119,7 +83,6 @@
    9.72  
    9.73      /* Initialize all variables that we clean on shutdown */
    9.74      SDL_DFB_CALLOC(device, 1, sizeof(SDL_VideoDevice));
    9.75 -    SDL_DFB_CALLOC(device->gl_data, 1, sizeof(*device->gl_data));
    9.76  
    9.77      /* Set the function pointers */
    9.78  
    9.79 @@ -173,217 +136,28 @@
    9.80      return (0);
    9.81  }
    9.82  
    9.83 -VideoBootStrap DirectFB_bootstrap = {
    9.84 -    "directfb", "DirectFB",
    9.85 -    DirectFB_Available, DirectFB_CreateDevice
    9.86 -};
    9.87 -
    9.88 -static DFBEnumerationResult
    9.89 -EnumModesCallback(int width, int height, int bpp, void *data)
    9.90 -{
    9.91 -    SDL_VideoDisplay *this = (SDL_VideoDisplay *) data;
    9.92 -    DFB_DisplayData *dispdata = (DFB_DisplayData *) this->driverdata;
    9.93 -    SDL_DisplayMode mode;
    9.94 -
    9.95 -    mode.w = width;
    9.96 -    mode.h = height;
    9.97 -    mode.refresh_rate = 0;
    9.98 -    mode.driverdata = NULL;
    9.99 -    mode.format = 0;
   9.100 -
   9.101 -    if (dispdata->nummodes < DFB_MAX_MODES) {
   9.102 -        dispdata->modelist[dispdata->nummodes++] = mode;
   9.103 -    }
   9.104 -
   9.105 -    SDL_DFB_DEBUG("w %d h %d bpp %d\n", width, height, bpp);
   9.106 -    return DFENUM_OK;
   9.107 -}
   9.108 -
   9.109 -static int
   9.110 -DFBToSDLPixelFormat(DFBSurfacePixelFormat pixelformat, Uint32 * fmt)
   9.111 -{
   9.112 -    switch (pixelformat) {
   9.113 -    case DSPF_ALUT44:
   9.114 -        *fmt = SDL_PIXELFORMAT_INDEX4LSB;
   9.115 -        break;
   9.116 -    case DSPF_LUT8:
   9.117 -        *fmt = SDL_PIXELFORMAT_INDEX8;
   9.118 -        break;
   9.119 -    case DSPF_RGB332:
   9.120 -        *fmt = SDL_PIXELFORMAT_RGB332;
   9.121 -        break;
   9.122 -    case DSPF_ARGB4444:
   9.123 -        *fmt = SDL_PIXELFORMAT_ARGB4444;
   9.124 -        break;
   9.125 -    case SDL_PIXELFORMAT_ARGB1555:
   9.126 -        *fmt = SDL_PIXELFORMAT_ARGB1555;
   9.127 -        break;
   9.128 -    case DSPF_RGB16:
   9.129 -        *fmt = SDL_PIXELFORMAT_RGB565;
   9.130 -        break;
   9.131 -    case DSPF_RGB24:
   9.132 -        *fmt = SDL_PIXELFORMAT_RGB24;
   9.133 -        break;
   9.134 -    case DSPF_RGB32:
   9.135 -        *fmt = SDL_PIXELFORMAT_RGB888;
   9.136 -        break;
   9.137 -    case DSPF_ARGB:
   9.138 -        *fmt = SDL_PIXELFORMAT_ARGB8888;
   9.139 -        break;
   9.140 -    case DSPF_YV12:
   9.141 -        *fmt = SDL_PIXELFORMAT_YV12;
   9.142 -        break;                  /* Planar mode: Y + V + U  (3 planes) */
   9.143 -    case DSPF_I420:
   9.144 -        *fmt = SDL_PIXELFORMAT_IYUV;
   9.145 -        break;                  /* Planar mode: Y + U + V  (3 planes) */
   9.146 -    case DSPF_YUY2:
   9.147 -        *fmt = SDL_PIXELFORMAT_YUY2;
   9.148 -        break;                  /* Packed mode: Y0+U0+Y1+V0 (1 plane) */
   9.149 -    case DSPF_UYVY:
   9.150 -        *fmt = SDL_PIXELFORMAT_UYVY;
   9.151 -        break;                  /* Packed mode: U0+Y0+V0+Y1 (1 plane) */
   9.152 -    default:
   9.153 -        return -1;
   9.154 -    }
   9.155 -    return 0;
   9.156 -}
   9.157 -
   9.158 -static DFBEnumerationResult
   9.159 -cbScreens(DFBScreenID screen_id, DFBScreenDescription desc,
   9.160 -          void *callbackdata)
   9.161 -{
   9.162 -    DFB_DeviceData *devdata = (DFB_DeviceData *) callbackdata;
   9.163 -
   9.164 -    devdata->screenid[devdata->numscreens++] = screen_id;
   9.165 -    return DFENUM_OK;
   9.166 -}
   9.167 -
   9.168 -DFBEnumerationResult
   9.169 -cbLayers(DFBDisplayLayerID layer_id, DFBDisplayLayerDescription desc,
   9.170 -         void *callbackdata)
   9.171 -{
   9.172 -    DFB_DeviceData *devdata = (DFB_DeviceData *) callbackdata;
   9.173 -
   9.174 -    if (desc.caps & DLCAPS_SURFACE) {
   9.175 -        if ((desc.type & DLTF_GRAPHICS) && (desc.type & DLTF_VIDEO)) {
   9.176 -            if (devdata->vidlayer[devdata->aux] == -1)
   9.177 -                devdata->vidlayer[devdata->aux] = layer_id;
   9.178 -        } else if (desc.type & DLTF_GRAPHICS) {
   9.179 -            if (devdata->gralayer[devdata->aux] == -1)
   9.180 -                devdata->gralayer[devdata->aux] = layer_id;
   9.181 -        }
   9.182 -    }
   9.183 -    return DFENUM_OK;
   9.184 -}
   9.185 -
   9.186  static int
   9.187  DirectFB_VideoInit(_THIS)
   9.188  {
   9.189 -#if (DIRECTFB_MAJOR_VERSION == 0) && (DIRECTFB_MINOR_VERSION == 9) && (DIRECTFB_MICRO_VERSION < 23)
   9.190 -    DFBCardCapabilities caps;
   9.191 -#else
   9.192 -    DFBGraphicsDeviceDescription caps;
   9.193 -#endif
   9.194 -    DFBDisplayLayerConfig dlc;
   9.195 -    struct DirectFBEnumRect *rect;
   9.196      IDirectFB *dfb = NULL;
   9.197 -    IDirectFBDisplayLayer *layer = NULL;
   9.198 -
   9.199 -    SDL_VideoDisplay display;
   9.200 -    DFB_DisplayData *dispdata;
   9.201      DFB_DeviceData *devdata;
   9.202 -    SDL_DisplayMode mode;
   9.203 -    int i;
   9.204 +    char *stemp;
   9.205      DFBResult ret;
   9.206 -    int tcw[DFB_MAX_SCREENS];
   9.207 -    int tch[DFB_MAX_SCREENS];
   9.208  
   9.209      SDL_DFB_CHECKERR(DirectFBInit(NULL, NULL));
   9.210      SDL_DFB_CHECKERR(DirectFBCreate(&dfb));
   9.211  
   9.212      SDL_DFB_CALLOC(devdata, 1, sizeof(*devdata));
   9.213 -    devdata->numscreens = 0;
   9.214 -    for (i = 0; i < DFB_MAX_SCREENS; i++) {
   9.215 -        devdata->gralayer[i] = -1;
   9.216 -        devdata->vidlayer[i] = -1;
   9.217 -    }
   9.218 -    SDL_DFB_CHECKERR(dfb->EnumScreens(dfb, &cbScreens, devdata));
   9.219 -    for (i = 0; i < devdata->numscreens; i++) {
   9.220 -        IDirectFBScreen *screen;
   9.221  
   9.222 -        SDL_DFB_CHECKERR(dfb->GetScreen(dfb, devdata->screenid[i], &screen));
   9.223 +    devdata->use_yuv_underlays = 0;     /* default: off */
   9.224 +    stemp = getenv(DFBENV_USE_YUV_UNDERLAY);
   9.225 +    if (stemp)
   9.226 +        devdata->use_yuv_underlays = atoi(stemp);
   9.227  
   9.228 -        devdata->aux = i;
   9.229 -        SDL_DFB_CHECKERR(screen->EnumDisplayLayers
   9.230 -                         (screen, &cbLayers, devdata));
   9.231 -#if (DIRECTFB_MAJOR_VERSION >= 1)
   9.232 -        screen->GetSize(screen, &tcw[i], &tch[i]);
   9.233 -#else
   9.234 -        /* FIXME: this is only used to center windows
   9.235 -         *        Should be done otherwise, e.g. get surface from layer
   9.236 -         */
   9.237 -        tcw[i] = 800;
   9.238 -        tch[i] = 600;
   9.239 -#endif
   9.240 -        screen->Release(screen);
   9.241 -    }
   9.242 -
   9.243 -    /* Query card capabilities */
   9.244 -
   9.245 -    dfb->GetDeviceDescription(dfb, &caps);
   9.246 -
   9.247 -    SDL_DFB_DEBUG("SDL directfb video driver - %s %s\n", __DATE__, __TIME__);
   9.248 -    SDL_DFB_DEBUG("Using %s (%s) driver.\n", caps.name, caps.vendor);
   9.249 -    SDL_DFB_DEBUG("Found %d screens\n", devdata->numscreens);
   9.250 -
   9.251 -    for (i = 0; i < devdata->numscreens; i++) {
   9.252 -        //SDL_DFB_CHECKERR( dfb->GetDisplayLayer (dfb, DLID_PRIMARY, &layer) );
   9.253 -        SDL_DFB_CHECKERR(dfb->GetDisplayLayer
   9.254 -                         (dfb, devdata->gralayer[i], &layer));
   9.255 -        //SDL_DFB_CHECKERR( dfb->CreateInputEventBuffer (dfb, DICAPS_ALL, DFB_FALSE, &events) );
   9.256 -
   9.257 -        SDL_DFB_CHECKERR(layer->SetCooperativeLevel
   9.258 -                         (layer, DLSCL_ADMINISTRATIVE));
   9.259 -        layer->EnableCursor(layer, 1);
   9.260 -        SDL_DFB_CHECKERR(layer->SetCursorOpacity(layer, 0xC0));
   9.261 -        SDL_DFB_CHECKERR(layer->SetCooperativeLevel(layer, DLSCL_SHARED));
   9.262 -
   9.263 -        /* Query layer configuration to determine the current mode and pixelformat */
   9.264 -        layer->GetConfiguration(layer, &dlc);
   9.265 -
   9.266 -        DFBToSDLPixelFormat(dlc.pixelformat, &mode.format);
   9.267 -
   9.268 -        mode.w = dlc.width;
   9.269 -        mode.h = dlc.height;
   9.270 -        mode.refresh_rate = 0;
   9.271 -        mode.driverdata = NULL;
   9.272 -
   9.273 -        SDL_DFB_CALLOC(dispdata, 1, sizeof(*dispdata));
   9.274 -
   9.275 -        dispdata->layer = layer;
   9.276 -        dispdata->pixelformat = dlc.pixelformat;
   9.277 -        dispdata->cw = tcw[i];
   9.278 -        dispdata->ch = tch[i];
   9.279 -
   9.280 -        /* YUV - Video layer */
   9.281 -
   9.282 -        dispdata->vidID = devdata->vidlayer[i];
   9.283 -        dispdata->vidIDinuse = 0;
   9.284 -
   9.285 -        SDL_zero(display);
   9.286 -
   9.287 -        display.desktop_mode = mode;
   9.288 -        display.current_mode = mode;
   9.289 -        display.driverdata = dispdata;
   9.290 -
   9.291 -        /* Enumerate the available fullscreen modes */
   9.292 -        SDL_DFB_CALLOC(dispdata->modelist, DFB_MAX_MODES,
   9.293 -                       sizeof(SDL_DisplayMode));
   9.294 -        SDL_DFB_CHECKERR(dfb->EnumVideoModes
   9.295 -                         (dfb, EnumModesCallback, &display));
   9.296 -
   9.297 -        SDL_AddVideoDisplay(&display);
   9.298 -    }
   9.299 +    /* Create global Eventbuffer for axis events */
   9.300 +    SDL_DFB_CHECKERR(dfb->
   9.301 +                     CreateInputEventBuffer(dfb, DICAPS_AXES /*DICAPS_ALL */ ,
   9.302 +                                            DFB_TRUE, &devdata->events));
   9.303  
   9.304      devdata->initialized = 1;
   9.305      devdata->dfb = dfb;
   9.306 @@ -391,26 +165,21 @@
   9.307  
   9.308      _this->driverdata = devdata;
   9.309  
   9.310 +    DirectFB_InitModes(_this);
   9.311  
   9.312  #if SDL_DIRECTFB_OPENGL
   9.313 -    /* Opengl */
   9.314 -    _this->gl_data->gl_active = 0;
   9.315 -    _this->gl_data->gl_context = NULL;
   9.316 +    DirectFB_GL_Initialize(_this);
   9.317  #endif
   9.318  
   9.319      DirectFB_AddRenderDriver(_this);
   9.320      DirectFB_InitMouse(_this);
   9.321      DirectFB_InitKeyboard(_this);
   9.322 -    //devdata->mouse = SDL_AddMouse(&mouse, -1);
   9.323 +
   9.324  
   9.325      return 0;
   9.326  
   9.327  
   9.328    error:
   9.329 -    //FIXME: Cleanup not complete, Free existing displays
   9.330 -    SDL_DFB_FREE(dispdata);
   9.331 -    SDL_DFB_FREE(dispdata->modelist);
   9.332 -    SDL_DFB_RELEASE(layer);
   9.333      SDL_DFB_RELEASE(dfb);
   9.334      return -1;
   9.335  }
   9.336 @@ -419,234 +188,22 @@
   9.337  DirectFB_VideoQuit(_THIS)
   9.338  {
   9.339      DFB_DeviceData *devdata = (DFB_DeviceData *) _this->driverdata;
   9.340 -    SDL_DisplayMode tmode;
   9.341 -    DFBResult ret;
   9.342 -    int i;
   9.343  
   9.344 -    tmode = _this->displays[0].desktop_mode;
   9.345 -    tmode.format = SDL_PIXELFORMAT_UNKNOWN;
   9.346 -    DirectFB_SetDisplayMode(_this, &tmode);
   9.347 -    tmode = _this->displays[0].desktop_mode;
   9.348 -    DirectFB_SetDisplayMode(_this, &tmode);
   9.349 +    DirectFB_QuitModes(_this);
   9.350 +    DirectFB_QuitKeyboard(_this);
   9.351 +    DirectFB_QuitMouse(_this);
   9.352  
   9.353 -    for (i = 0; i < devdata->numscreens; i++) {
   9.354 -        DFB_DisplayData *dispdata =
   9.355 -            (DFB_DisplayData *) _this->displays[i].driverdata;
   9.356 -        if (dispdata->layer) {
   9.357 -            SDL_DFB_CHECK(dispdata->
   9.358 -                          layer->SetCooperativeLevel(dispdata->layer,
   9.359 -                                                     DLSCL_ADMINISTRATIVE));
   9.360 -            SDL_DFB_CHECK(dispdata->
   9.361 -                          layer->SetCursorOpacity(dispdata->layer, 0x00));
   9.362 -            SDL_DFB_CHECK(dispdata->
   9.363 -                          layer->SetCooperativeLevel(dispdata->layer,
   9.364 -                                                     DLSCL_SHARED));
   9.365 -        }
   9.366 -        SDL_DFB_RELEASE(dispdata->layer);
   9.367 -
   9.368 -        /* Free video mode list */
   9.369 -        if (dispdata->modelist) {
   9.370 -            SDL_free(dispdata->modelist);
   9.371 -            dispdata->modelist = NULL;
   9.372 -        }
   9.373 -        // Done by core
   9.374 -        //SDL_free(dispdata);
   9.375 -    }
   9.376 -
   9.377 +    SDL_DFB_RELEASE(devdata->events);
   9.378      SDL_DFB_RELEASE(devdata->dfb);
   9.379 -
   9.380 -    SDL_DelMouse(devdata->mouse);
   9.381 -    SDL_DelKeyboard(devdata->keyboard);
   9.382 +    SDL_DFB_FREE(_this->driverdata);
   9.383  
   9.384  #if SDL_DIRECTFB_OPENGL
   9.385 -    DirectFB_GL_UnloadLibrary(_this);
   9.386 +    DirectFB_GL_Shutdown(_this);
   9.387  #endif
   9.388  
   9.389      devdata->initialized = 0;
   9.390  }
   9.391  
   9.392 -
   9.393 -static DFBSurfacePixelFormat
   9.394 -SDLToDFBPixelFormat(Uint32 format)
   9.395 -{
   9.396 -    switch (format) {
   9.397 -    case SDL_PIXELFORMAT_INDEX4LSB:
   9.398 -        return DSPF_ALUT44;
   9.399 -    case SDL_PIXELFORMAT_INDEX8:
   9.400 -        return DSPF_LUT8;
   9.401 -    case SDL_PIXELFORMAT_RGB332:
   9.402 -        return DSPF_RGB332;
   9.403 -    case SDL_PIXELFORMAT_RGB555:
   9.404 -        return DSPF_ARGB1555;
   9.405 -    case SDL_PIXELFORMAT_ARGB4444:
   9.406 -        return DSPF_ARGB4444;
   9.407 -    case SDL_PIXELFORMAT_ARGB1555:
   9.408 -        return DSPF_ARGB1555;
   9.409 -    case SDL_PIXELFORMAT_RGB565:
   9.410 -        return DSPF_RGB16;
   9.411 -    case SDL_PIXELFORMAT_RGB24:
   9.412 -        return DSPF_RGB24;
   9.413 -    case SDL_PIXELFORMAT_RGB888:
   9.414 -        return DSPF_RGB32;
   9.415 -    case SDL_PIXELFORMAT_ARGB8888:
   9.416 -        return DSPF_ARGB;
   9.417 -    case SDL_PIXELFORMAT_YV12:
   9.418 -        return DSPF_YV12;       /* Planar mode: Y + V + U  (3 planes) */
   9.419 -    case SDL_PIXELFORMAT_IYUV:
   9.420 -        return DSPF_I420;       /* Planar mode: Y + U + V  (3 planes) */
   9.421 -    case SDL_PIXELFORMAT_YUY2:
   9.422 -        return DSPF_YUY2;       /* Packed mode: Y0+U0+Y1+V0 (1 plane) */
   9.423 -    case SDL_PIXELFORMAT_UYVY:
   9.424 -        return DSPF_UYVY;       /* Packed mode: U0+Y0+V0+Y1 (1 plane) */
   9.425 -    case SDL_PIXELFORMAT_YVYU:
   9.426 -        return DSPF_UNKNOWN;    /* Packed mode: Y0+V0+Y1+U0 (1 plane) */
   9.427 -    case SDL_PIXELFORMAT_INDEX1LSB:
   9.428 -        return DSPF_UNKNOWN;
   9.429 -    case SDL_PIXELFORMAT_INDEX1MSB:
   9.430 -        return DSPF_UNKNOWN;
   9.431 -    case SDL_PIXELFORMAT_INDEX4MSB:
   9.432 -        return DSPF_UNKNOWN;
   9.433 -    case SDL_PIXELFORMAT_RGB444:
   9.434 -        return DSPF_UNKNOWN;
   9.435 -    case SDL_PIXELFORMAT_BGR24:
   9.436 -        return DSPF_UNKNOWN;
   9.437 -    case SDL_PIXELFORMAT_BGR888:
   9.438 -        return DSPF_UNKNOWN;
   9.439 -    case SDL_PIXELFORMAT_RGBA8888:
   9.440 -        return DSPF_UNKNOWN;
   9.441 -    case SDL_PIXELFORMAT_ABGR8888:
   9.442 -        return DSPF_UNKNOWN;
   9.443 -    case SDL_PIXELFORMAT_BGRA8888:
   9.444 -        return DSPF_UNKNOWN;
   9.445 -    case SDL_PIXELFORMAT_ARGB2101010:
   9.446 -        return DSPF_UNKNOWN;
   9.447 -    default:
   9.448 -        return DSPF_UNKNOWN;
   9.449 -    }
   9.450 -}
   9.451 -
   9.452 -static void
   9.453 -CheckSetDisplayMode(_THIS, DFB_DisplayData * data, SDL_DisplayMode * mode)
   9.454 -{
   9.455 -    DFBDisplayLayerConfig config;
   9.456 -    DFBDisplayLayerConfigFlags failed;
   9.457 -
   9.458 -    config.width = mode->w;
   9.459 -    config.height = mode->h;
   9.460 -    config.pixelformat = SDLToDFBPixelFormat(mode->format);
   9.461 -    config.flags = DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT;
   9.462 -    failed = 0;
   9.463 -    data->layer->TestConfiguration(data->layer, &config, &failed);
   9.464 -    if (failed == 0)
   9.465 -        SDL_AddDisplayMode(_this->current_display, mode);
   9.466 -
   9.467 -}
   9.468 -
   9.469 -static void
   9.470 -DirectFB_GetDisplayModes(_THIS)
   9.471 -{
   9.472 -    //SDL_DisplayData *data = (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
   9.473 -    //SDL_DisplayMode mode;
   9.474 -    //SDL_AddDisplayMode(_this->current_display, &mode);
   9.475 -
   9.476 -    SDL_DFB_DEVICEDATA(_this);
   9.477 -    DFB_DisplayData *data = (DFB_DisplayData *) SDL_CurrentDisplay.driverdata;
   9.478 -    int i;
   9.479 -    SDL_DisplayMode mode;
   9.480 -
   9.481 -    for (i = 0; i < data->nummodes; ++i) {
   9.482 -        mode = data->modelist[i];
   9.483 -        //mode.format = SDL_PIXELFORMAT_UNKNOWN;
   9.484 -
   9.485 -        mode.format = SDL_PIXELFORMAT_INDEX8;
   9.486 -        CheckSetDisplayMode(_this, data, &mode);
   9.487 -        mode.format = SDL_PIXELFORMAT_RGB565;
   9.488 -        CheckSetDisplayMode(_this, data, &mode);
   9.489 -        mode.format = SDL_PIXELFORMAT_RGB24;
   9.490 -        CheckSetDisplayMode(_this, data, &mode);
   9.491 -        mode.format = SDL_PIXELFORMAT_RGB888;
   9.492 -        CheckSetDisplayMode(_this, data, &mode);
   9.493 -    }
   9.494 -}
   9.495 -
   9.496 -int
   9.497 -DirectFB_SetDisplayMode(_THIS, SDL_DisplayMode * mode)
   9.498 -{
   9.499 -    SDL_DFB_DEVICEDATA(_this);
   9.500 -    DFB_DisplayData *data = (DFB_DisplayData *) SDL_CurrentDisplay.driverdata;
   9.501 -    DFBDisplayLayerConfig config, rconfig;
   9.502 -    DFBDisplayLayerConfigFlags fail = 0;
   9.503 -    DFBResult ret;
   9.504 -    DFB_WindowData *win;
   9.505 -
   9.506 -    SDL_DFB_CHECKERR(data->layer->SetCooperativeLevel(data->layer,
   9.507 -                                                      DLSCL_ADMINISTRATIVE));
   9.508 -
   9.509 -    SDL_DFB_CHECKERR(data->layer->GetConfiguration(data->layer, &config));
   9.510 -    config.flags = DLCONF_WIDTH | DLCONF_HEIGHT;        // | DLCONF_BUFFERMODE;
   9.511 -    if (mode->format != SDL_PIXELFORMAT_UNKNOWN) {
   9.512 -        config.flags |= DLCONF_PIXELFORMAT;
   9.513 -        config.pixelformat = SDLToDFBPixelFormat(mode->format);
   9.514 -        data->pixelformat = config.pixelformat;
   9.515 -    }
   9.516 -    config.width = mode->w;
   9.517 -    config.height = mode->h;
   9.518 -
   9.519 -    //config.buffermode = DLBM_BACKVIDEO;
   9.520 -
   9.521 -    //config.pixelformat = GetFormatForBpp (bpp, HIDDEN->layer);
   9.522 -
   9.523 -    data->layer->TestConfiguration(data->layer, &config, &fail);
   9.524 -    if (fail & (DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT)) {
   9.525 -        SDL_DFB_DEBUG("Error setting mode %dx%d-%x\n", mode->w, mode->h,
   9.526 -                      mode->format);
   9.527 -        return -1;
   9.528 -    }
   9.529 -    SDL_DFB_DEBUG("Trace\n");
   9.530 -    config.flags &= ~fail;
   9.531 -    SDL_DFB_CHECKERR(data->layer->SetConfiguration(data->layer, &config));
   9.532 -    SDL_DFB_CHECKERR(data->layer->SetCooperativeLevel(data->layer,
   9.533 -                                                      DLSCL_ADMINISTRATIVE));
   9.534 -
   9.535 -    /* Double check */
   9.536 -    SDL_DFB_CHECKERR(data->layer->GetConfiguration(data->layer, &rconfig));
   9.537 -
   9.538 -    if ((config.width != rconfig.width) ||
   9.539 -        (config.height != rconfig.height) ||
   9.540 -        ((mode->format != SDL_PIXELFORMAT_UNKNOWN)
   9.541 -         && (config.pixelformat != rconfig.pixelformat))) {
   9.542 -        SDL_DFB_DEBUG("Error setting mode %dx%d-%x\n", mode->w, mode->h,
   9.543 -                      mode->format);
   9.544 -        return -1;
   9.545 -    }
   9.546 -
   9.547 -    data->pixelformat = rconfig.pixelformat;
   9.548 -    data->cw = config.width;
   9.549 -    data->ch = config.height;
   9.550 -    SDL_CurrentDisplay.current_mode = *mode;
   9.551 -
   9.552 -    /*
   9.553 -     * FIXME: video mode switch is currently broken
   9.554 -     * 
   9.555 -     * DirectFB 1.2.0-rc1 even has a broken cursor after a switch
   9.556 -     * The following code needs to be revisited whether it is still 
   9.557 -     * needed once the switch works again.
   9.558 -     */
   9.559 -
   9.560 -    win = devdata->firstwin;
   9.561 -
   9.562 -    while (win) {
   9.563 -        SDL_DFB_RELEASE(win->surface);
   9.564 -        SDL_DFB_CHECKERR(win->window->GetSurface(win->window, &win->surface));
   9.565 -        win = win->next;
   9.566 -    }
   9.567 -
   9.568 -
   9.569 -    return 0;
   9.570 -  error:
   9.571 -    return -1;
   9.572 -}
   9.573 -
   9.574  static int
   9.575  DirectFB_SetDisplayGammaRamp(_THIS, Uint16 * ramp)
   9.576  {
   9.577 @@ -658,527 +215,3 @@
   9.578  {
   9.579      return -1;
   9.580  }
   9.581 -
   9.582 -static int
   9.583 -DirectFB_CreateWindow(_THIS, SDL_Window * window)
   9.584 -{
   9.585 -    SDL_DFB_DEVICEDATA(_this);
   9.586 -    SDL_DFB_DISPLAYDATA(_this, window);
   9.587 -    DFB_WindowData *windata;
   9.588 -    DFBWindowOptions wopts;
   9.589 -    DFBWindowDescription desc;
   9.590 -    int ret, x, y;
   9.591 -
   9.592 -    SDL_DFB_DEBUG("Trace x %d y %d w %d h %d\n", window->x, window->y,
   9.593 -                  window->w, window->h);
   9.594 -    window->driverdata = NULL;
   9.595 -    SDL_DFB_CALLOC(window->driverdata, 1, sizeof(DFB_WindowData));
   9.596 -    windata = (DFB_WindowData *) window->driverdata;
   9.597 -
   9.598 -    SDL_DFB_CHECKERR(devdata->
   9.599 -                     dfb->SetCooperativeLevel(devdata->dfb, DFSCL_NORMAL));
   9.600 -    SDL_DFB_CHECKERR(dispdata->
   9.601 -                     layer->SetCooperativeLevel(dispdata->layer,
   9.602 -                                                DLSCL_ADMINISTRATIVE));
   9.603 -
   9.604 -    /* Fill the window description. */
   9.605 -    if (window->x == SDL_WINDOWPOS_CENTERED) {
   9.606 -        x = (dispdata->cw - window->w) / 2;
   9.607 -    } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
   9.608 -        x = 0;
   9.609 -    } else {
   9.610 -        x = window->x;
   9.611 -    }
   9.612 -    if (window->y == SDL_WINDOWPOS_CENTERED) {
   9.613 -        y = (dispdata->ch - window->h) / 2;
   9.614 -    } else if (window->y == SDL_WINDOWPOS_UNDEFINED) {
   9.615 -        y = 0;
   9.616 -    } else {
   9.617 -        y = window->y;
   9.618 -    }
   9.619 -    if (window->flags & SDL_WINDOW_FULLSCREEN) {
   9.620 -        x = 0;
   9.621 -        y = 0;
   9.622 -    }
   9.623 -
   9.624 -    desc.flags = DWDESC_WIDTH | DWDESC_HEIGHT /*| DWDESC_CAPS */  | DWDESC_PIXELFORMAT
   9.625 -        | DWDESC_SURFACE_CAPS;
   9.626 -
   9.627 -#if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 0)
   9.628 -    /* Needed for 1.2 */
   9.629 -    desc.flags |= DWDESC_POSX | DWDESC_POSY;
   9.630 -    desc.posx = x;
   9.631 -    desc.posy = y;
   9.632 -#else
   9.633 -    if (!(window->flags & SDL_WINDOW_FULLSCREEN)
   9.634 -        && window->x != SDL_WINDOWPOS_UNDEFINED
   9.635 -        && window->y != SDL_WINDOWPOS_UNDEFINED) {
   9.636 -        desc.flags |= DWDESC_POSX | DWDESC_POSY;
   9.637 -        desc.posx = x;
   9.638 -        desc.posy = y;
   9.639 -    }
   9.640 -#endif
   9.641 -
   9.642 -    desc.width = window->w;
   9.643 -    desc.height = window->h;
   9.644 -    desc.pixelformat = dispdata->pixelformat;
   9.645 -    desc.caps = 0;              // DWCAPS_DOUBLEBUFFER;
   9.646 -    desc.surface_caps = DSCAPS_DOUBLE | DSCAPS_TRIPLE / DSCAPS_PREMULTIPLIED;
   9.647 -
   9.648 -    /* Create the window. */
   9.649 -    SDL_DFB_CHECKERR(dispdata->layer->CreateWindow(dispdata->layer, &desc,
   9.650 -                                                   &windata->window));
   9.651 -
   9.652 -    windata->window->GetOptions(windata->window, &wopts);
   9.653 -#if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 0)
   9.654 -
   9.655 -    if (window->flags & SDL_WINDOW_RESIZABLE)
   9.656 -        wopts |= DWOP_SCALE;
   9.657 -    else
   9.658 -        wopts |= DWOP_KEEP_SIZE;
   9.659 -#else
   9.660 -    wopts |= DWOP_KEEP_SIZE;    // if not we will crash ...
   9.661 -#endif
   9.662 -
   9.663 -    if (window->flags & SDL_WINDOW_FULLSCREEN)
   9.664 -        wopts |= DWOP_KEEP_POSITION | DWOP_KEEP_STACKING | DWOP_KEEP_SIZE;
   9.665 -
   9.666 -    windata->window->SetOptions(windata->window, wopts);
   9.667 -    /* Get the window's surface. */
   9.668 -    SDL_DFB_CHECKERR(windata->
   9.669 -                     window->GetSurface(windata->window, &windata->surface));
   9.670 -    windata->window->SetOpacity(windata->window, 0xFF);
   9.671 -    SDL_DFB_CHECKERR(windata->window->CreateEventBuffer(windata->window,
   9.672 -                                                        &
   9.673 -                                                        (windata->
   9.674 -                                                         eventbuffer)));
   9.675 -    SDL_DFB_CHECKERR(windata->window->
   9.676 -                     EnableEvents(windata->window,
   9.677 -                                  DWET_POSITION | DWET_SIZE | DWET_CLOSE |
   9.678 -                                  DWET_ALL));
   9.679 -
   9.680 -    if (window->flags & SDL_WINDOW_FULLSCREEN)
   9.681 -        windata->window->SetStackingClass(windata->window, DWSC_UPPER);
   9.682 -    /* Make it the top most window. */
   9.683 -    windata->window->RaiseToTop(windata->window);
   9.684 -
   9.685 -    windata->window->GetID(windata->window, &windata->windowID);
   9.686 -    windata->id = window->id;
   9.687 -
   9.688 -#if SDL_DIRECTFB_OPENGL
   9.689 -    if (window->flags & SDL_WINDOW_OPENGL) {
   9.690 -        if (!_this->gl_config.driver_loaded) {
   9.691 -            /* no driver has been loaded, use default (ourselves) */
   9.692 -            if (DirectFB_GL_LoadLibrary(_this, NULL) < 0) {
   9.693 -                goto error;
   9.694 -            }
   9.695 -        }
   9.696 -        _this->gl_data->gl_active = 1;
   9.697 -    }
   9.698 -#endif
   9.699 -
   9.700 -    /* Add to list ... */
   9.701 -
   9.702 -    windata->next = devdata->firstwin;
   9.703 -    windata->opacity = 0xFF;
   9.704 -    devdata->firstwin = windata;
   9.705 -
   9.706 -    //SDL_DFB_CHECKERR( windata->surface->GetPalette(windata->surface, &windata->palette) );
   9.707 -
   9.708 -    return 0;
   9.709 -  error:
   9.710 -    SDL_DFB_RELEASE(windata->window);
   9.711 -    SDL_DFB_RELEASE(windata->surface);
   9.712 -    return -1;
   9.713 -}
   9.714 -
   9.715 -static int
   9.716 -DirectFB_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
   9.717 -{
   9.718 -    SDL_DFB_DEVICEDATA(_this);
   9.719 -    SDL_DFB_WINDOWDATA(window);
   9.720 -    SDL_DFB_DISPLAYDATA(_this, window);
   9.721 -
   9.722 -    SDL_Unsupported();
   9.723 -    return -1;
   9.724 -}
   9.725 -
   9.726 -static void
   9.727 -DirectFB_SetWindowTitle(_THIS, SDL_Window * window)
   9.728 -{
   9.729 -    SDL_DFB_DEVICEDATA(_this);
   9.730 -    SDL_DFB_WINDOWDATA(window);
   9.731 -    SDL_DFB_DISPLAYDATA(_this, window);
   9.732 -
   9.733 -    SDL_Unsupported();
   9.734 -    //return -1;
   9.735 -
   9.736 -}
   9.737 -
   9.738 -static void
   9.739 -DirectFB_SetWindowPosition(_THIS, SDL_Window * window)
   9.740 -{
   9.741 -    SDL_DFB_DEVICEDATA(_this);
   9.742 -    SDL_DFB_WINDOWDATA(window);
   9.743 -    SDL_DFB_DISPLAYDATA(_this, window);
   9.744 -    int x, y;
   9.745 -
   9.746 -    if (window->y == SDL_WINDOWPOS_UNDEFINED)
   9.747 -        y = 0;
   9.748 -    else
   9.749 -        y = window->y;
   9.750 -
   9.751 -    if (window->x == SDL_WINDOWPOS_UNDEFINED)
   9.752 -        x = 0;
   9.753 -    else
   9.754 -        x = window->x;
   9.755 -
   9.756 -    if (window->flags & SDL_WINDOW_FULLSCREEN) {
   9.757 -        x = 0;
   9.758 -        y = 0;
   9.759 -    }
   9.760 -    //if (!(window->flags & SDL_WINDOW_FULLSCREEN))
   9.761 -    windata->window->MoveTo(windata->window, x, y);
   9.762 -}
   9.763 -
   9.764 -static void
   9.765 -DirectFB_SetWindowSize(_THIS, SDL_Window * window)
   9.766 -{
   9.767 -    int ret;
   9.768 -    SDL_DFB_DEVICEDATA(_this);
   9.769 -    SDL_DFB_WINDOWDATA(window);
   9.770 -    SDL_DFB_DISPLAYDATA(_this, window);
   9.771 -
   9.772 -    if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
   9.773 -        int ch, cw;
   9.774 -
   9.775 -        //      SDL_DFB_DEBUG("Resize %d %d %d %d\n", cw, ch, window->w, window->h);
   9.776 -#if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 0)
   9.777 -        SDL_DFB_CHECKERR(windata->window->
   9.778 -                         ResizeSurface(windata->window, window->w,
   9.779 -                                       window->h));
   9.780 -#else
   9.781 -        SDL_DFB_CHECKERR(windata->window->
   9.782 -                         Resize(windata->window, window->w, window->h));
   9.783 -#endif
   9.784 -        SDL_DFB_CHECKERR(windata->window->GetSize(windata->window, &window->w, &window->h));    /* if a window manager should have decided otherwise */
   9.785 -    }
   9.786 -  error:
   9.787 -    return;
   9.788 -}
   9.789 -
   9.790 -static void
   9.791 -DirectFB_ShowWindow(_THIS, SDL_Window * window)
   9.792 -{
   9.793 -    SDL_DFB_DEVICEDATA(_this);
   9.794 -    SDL_DFB_WINDOWDATA(window);
   9.795 -    SDL_DFB_DISPLAYDATA(_this, window);
   9.796 -
   9.797 -    windata->window->SetOpacity(windata->window, windata->opacity);
   9.798 -
   9.799 -}
   9.800 -
   9.801 -static void
   9.802 -DirectFB_HideWindow(_THIS, SDL_Window * window)
   9.803 -{
   9.804 -    SDL_DFB_DEVICEDATA(_this);
   9.805 -    SDL_DFB_WINDOWDATA(window);
   9.806 -    SDL_DFB_DISPLAYDATA(_this, window);
   9.807 -
   9.808 -    windata->window->GetOpacity(windata->window, &windata->opacity);
   9.809 -    windata->window->SetOpacity(windata->window, 0);
   9.810 -
   9.811 -}
   9.812 -
   9.813 -static void
   9.814 -DirectFB_RaiseWindow(_THIS, SDL_Window * window)
   9.815 -{
   9.816 -    SDL_DFB_DEVICEDATA(_this);
   9.817 -    SDL_DFB_WINDOWDATA(window);
   9.818 -    SDL_DFB_DISPLAYDATA(_this, window);
   9.819 -
   9.820 -    windata->window->Raise(windata->window);
   9.821 -
   9.822 -}
   9.823 -
   9.824 -static void
   9.825 -DirectFB_MaximizeWindow(_THIS, SDL_Window * window)
   9.826 -{
   9.827 -    SDL_DFB_DEVICEDATA(_this);
   9.828 -    SDL_DFB_WINDOWDATA(window);
   9.829 -    SDL_DFB_DISPLAYDATA(_this, window);
   9.830 -
   9.831 -    SDL_Unsupported();
   9.832 -
   9.833 -}
   9.834 -
   9.835 -static void
   9.836 -DirectFB_MinimizeWindow(_THIS, SDL_Window * window)
   9.837 -{
   9.838 -    SDL_DFB_DEVICEDATA(_this);
   9.839 -    SDL_DFB_WINDOWDATA(window);
   9.840 -    SDL_DFB_DISPLAYDATA(_this, window);
   9.841 -
   9.842 -    SDL_Unsupported();
   9.843 -
   9.844 -}
   9.845 -
   9.846 -static void
   9.847 -DirectFB_RestoreWindow(_THIS, SDL_Window * window)
   9.848 -{
   9.849 -    SDL_DFB_DEVICEDATA(_this);
   9.850 -    SDL_DFB_WINDOWDATA(window);
   9.851 -    SDL_DFB_DISPLAYDATA(_this, window);
   9.852 -
   9.853 -    SDL_Unsupported();
   9.854 -
   9.855 -}
   9.856 -
   9.857 -static void
   9.858 -DirectFB_SetWindowGrab(_THIS, SDL_Window * window)
   9.859 -{
   9.860 -    SDL_DFB_DEVICEDATA(_this);
   9.861 -    SDL_DFB_WINDOWDATA(window);
   9.862 -    SDL_DFB_DISPLAYDATA(_this, window);
   9.863 -
   9.864 -    SDL_Unsupported();
   9.865 -
   9.866 -}
   9.867 -
   9.868 -static void
   9.869 -DirectFB_DestroyWindow(_THIS, SDL_Window * window)
   9.870 -{
   9.871 -    SDL_DFB_DEVICEDATA(_this);
   9.872 -    SDL_DFB_WINDOWDATA(window);
   9.873 -    SDL_DFB_DISPLAYDATA(_this, window);
   9.874 -    DFB_WindowData *p;
   9.875 -
   9.876 -    SDL_DFB_DEBUG("Trace\n");
   9.877 -
   9.878 -    SDL_DFB_RELEASE(windata->palette);
   9.879 -    SDL_DFB_RELEASE(windata->eventbuffer);
   9.880 -    SDL_DFB_RELEASE(windata->surface);
   9.881 -    SDL_DFB_RELEASE(windata->window);
   9.882 -
   9.883 -    /* Remove from list ... */
   9.884 -
   9.885 -    p = devdata->firstwin;
   9.886 -    while (p && p->next != windata)
   9.887 -        p = p->next;
   9.888 -    if (p)
   9.889 -        p->next = windata->next;
   9.890 -    else
   9.891 -        devdata->firstwin = windata->next;
   9.892 -    SDL_free(windata);
   9.893 -}
   9.894 -
   9.895 -static SDL_bool
   9.896 -DirectFB_GetWindowWMInfo(_THIS, SDL_Window * window,
   9.897 -                         struct SDL_SysWMinfo *info)
   9.898 -{
   9.899 -    SDL_DFB_DEVICEDATA(_this);
   9.900 -    SDL_DFB_WINDOWDATA(window);
   9.901 -    SDL_DFB_DISPLAYDATA(_this, window);
   9.902 -
   9.903 -    SDL_Unsupported();
   9.904 -    return SDL_FALSE;
   9.905 -}
   9.906 -
   9.907 -#if SDL_DIRECTFB_OPENGL
   9.908 -
   9.909 -#define OPENGL_REQUIRS_DLOPEN
   9.910 -#if defined(OPENGL_REQUIRS_DLOPEN) && defined(SDL_LOADSO_DLOPEN)
   9.911 -#include <dlfcn.h>
   9.912 -#define GL_LoadObject(X)	dlopen(X, (RTLD_NOW|RTLD_GLOBAL))
   9.913 -#define GL_LoadFunction		dlsym
   9.914 -#define GL_UnloadObject		dlclose
   9.915 -#else
   9.916 -#define GL_LoadObject	SDL_LoadObject
   9.917 -#define GL_LoadFunction	SDL_LoadFunction
   9.918 -#define GL_UnloadObject	SDL_UnloadObject
   9.919 -#endif
   9.920 -
   9.921 -static int
   9.922 -DirectFB_GL_LoadLibrary(_THIS, const char *path)
   9.923 -{
   9.924 -    SDL_DFB_DEVICEDATA(_this);
   9.925 -#
   9.926 -    void *handle = NULL;
   9.927 -
   9.928 -    SDL_DFB_DEBUG("Loadlibrary : %s\n", path);
   9.929 -
   9.930 -    if (_this->gl_data->gl_active) {
   9.931 -        SDL_SetError("OpenGL context already created");
   9.932 -        return -1;
   9.933 -    }
   9.934 -
   9.935 -
   9.936 -    if (path == NULL) {
   9.937 -        path = SDL_getenv("SDL_VIDEO_GL_DRIVER");
   9.938 -        if (path == NULL) {
   9.939 -            path = "libGL.so";
   9.940 -        }
   9.941 -    }
   9.942 -
   9.943 -    handle = GL_LoadObject(path);
   9.944 -    if (handle == NULL) {
   9.945 -        SDL_DFB_ERR("Library not found: %s\n", path);
   9.946 -        /* SDL_LoadObject() will call SDL_SetError() for us. */
   9.947 -        return -1;
   9.948 -    }
   9.949 -
   9.950 -    SDL_DFB_DEBUG("Loaded library: %s\n", path);
   9.951 -
   9.952 -    /* Unload the old driver and reset the pointers */
   9.953 -    DirectFB_GL_UnloadLibrary(_this);
   9.954 -
   9.955 -    _this->gl_config.dll_handle = handle;
   9.956 -    _this->gl_config.driver_loaded = 1;
   9.957 -    if (path) {
   9.958 -        SDL_strlcpy(_this->gl_config.driver_path, path,
   9.959 -                    SDL_arraysize(_this->gl_config.driver_path));
   9.960 -    } else {
   9.961 -        *_this->gl_config.driver_path = '\0';
   9.962 -    }
   9.963 -
   9.964 -    devdata->glFinish = DirectFB_GL_GetProcAddress(_this, "glFinish");
   9.965 -    devdata->glFlush = DirectFB_GL_GetProcAddress(_this, "glFlush");
   9.966 -    return 0;
   9.967 -}
   9.968 -
   9.969 -static void
   9.970 -DirectFB_GL_UnloadLibrary(_THIS)
   9.971 -{
   9.972 -    SDL_DFB_DEVICEDATA(_this);
   9.973 -
   9.974 -    int ret;
   9.975 -
   9.976 -    if (_this->gl_config.driver_loaded) {
   9.977 -
   9.978 -        ret = GL_UnloadObject(_this->gl_config.dll_handle);
   9.979 -        if (ret)
   9.980 -            SDL_DFB_ERR("Error #%d trying to unload library.\n", ret);
   9.981 -        _this->gl_config.dll_handle = NULL;
   9.982 -        _this->gl_config.driver_loaded = 0;
   9.983 -    }
   9.984 -}
   9.985 -
   9.986 -static void *
   9.987 -DirectFB_GL_GetProcAddress(_THIS, const char *proc)
   9.988 -{
   9.989 -    SDL_DFB_DEVICEDATA(_this);
   9.990 -    int ret;
   9.991 -    void *handle;
   9.992 -
   9.993 -    SDL_DFB_DEBUG("Trace %s\n", proc);
   9.994 -    handle = _this->gl_config.dll_handle;
   9.995 -    return GL_LoadFunction(handle, proc);
   9.996 -}
   9.997 -
   9.998 -static SDL_GLContext
   9.999 -DirectFB_GL_CreateContext(_THIS, SDL_Window * window)
  9.1000 -{
  9.1001 -    SDL_DFB_DEVICEDATA(_this);
  9.1002 -    SDL_DFB_WINDOWDATA(window);
  9.1003 -    SDL_DFB_DISPLAYDATA(_this, window);
  9.1004 -    int ret;
  9.1005 -    IDirectFBGL *context = NULL;
  9.1006 -
  9.1007 -    SDL_DFB_DEBUG("Trace\n");
  9.1008 -    SDL_DFB_CHECKERR(windata->surface->GetGL(windata->surface, &context));
  9.1009 -    SDL_DFB_CHECKERR(context->Unlock(context));
  9.1010 -
  9.1011 -    if (DirectFB_GL_MakeCurrent(_this, window, context) < 0) {
  9.1012 -        DirectFB_GL_DeleteContext(_this, context);
  9.1013 -        return NULL;
  9.1014 -    }
  9.1015 -
  9.1016 -    return context;
  9.1017 -
  9.1018 -  error:
  9.1019 -    return NULL;
  9.1020 -}
  9.1021 -
  9.1022 -static int
  9.1023 -DirectFB_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
  9.1024 -{
  9.1025 -    SDL_DFB_DEVICEDATA(_this);
  9.1026 -    SDL_DFB_WINDOWDATA(window);
  9.1027 -    SDL_DFB_DISPLAYDATA(_this, window);
  9.1028 -    IDirectFBGL *dfb_context = (IDirectFBGL *) context;
  9.1029 -    int ret;
  9.1030 -
  9.1031 -    if (dfb_context) {
  9.1032 -        dfb_context->Unlock(dfb_context);
  9.1033 -        SDL_DFB_CHECKERR(dfb_context->Lock(dfb_context));
  9.1034 -    }
  9.1035 -    if (windata)
  9.1036 -        windata->gl_context = dfb_context;
  9.1037 -
  9.1038 -    return 0;
  9.1039 -  error:
  9.1040 -    return -1;
  9.1041 -}
  9.1042 -
  9.1043 -static int
  9.1044 -DirectFB_GL_SetSwapInterval(_THIS, int interval)
  9.1045 -{
  9.1046 -    SDL_DFB_DEVICEDATA(_this);
  9.1047 -
  9.1048 -    SDL_Unsupported();
  9.1049 -    return -1;
  9.1050 -
  9.1051 -}
  9.1052 -
  9.1053 -static int
  9.1054 -DirectFB_GL_GetSwapInterval(_THIS)
  9.1055 -{
  9.1056 -    SDL_DFB_DEVICEDATA(_this);
  9.1057 -
  9.1058 -    SDL_Unsupported();
  9.1059 -    return -1;
  9.1060 -
  9.1061 -}
  9.1062 -
  9.1063 -static void
  9.1064 -DirectFB_GL_SwapWindow(_THIS, SDL_Window * window)
  9.1065 -{
  9.1066 -    SDL_DFB_DEVICEDATA(_this);
  9.1067 -    SDL_DFB_WINDOWDATA(window);
  9.1068 -    SDL_DFB_DISPLAYDATA(_this, window);
  9.1069 -    int ret;
  9.1070 -    void *p;
  9.1071 -    int pitch;
  9.1072 -    DFBRegion region;
  9.1073 -
  9.1074 -    region.x1 = 0;
  9.1075 -    region.y1 = 0;
  9.1076 -    region.x2 = window->w;
  9.1077 -    region.y2 = window->h;
  9.1078 -
  9.1079 -    if (devdata->glFinish)
  9.1080 -        devdata->glFinish();
  9.1081 -    else if (devdata->glFlush)
  9.1082 -        devdata->glFlush();
  9.1083 -
  9.1084 -    SDL_DFB_CHECKERR(windata->gl_context->Unlock(windata->gl_context));
  9.1085 -    SDL_DFB_CHECKERR(windata->
  9.1086 -                     surface->Flip(windata->surface, &region, DSFLIP_ONSYNC));
  9.1087 -    SDL_DFB_CHECKERR(windata->gl_context->Lock(windata->gl_context));
  9.1088 -
  9.1089 -    return;
  9.1090 -  error:
  9.1091 -    return;
  9.1092 -}
  9.1093 -
  9.1094 -static void
  9.1095 -DirectFB_GL_DeleteContext(_THIS, SDL_GLContext context)
  9.1096 -{
  9.1097 -    IDirectFBGL *dfb_context = (IDirectFBGL *) context;
  9.1098 -    SDL_DFB_DEVICEDATA(_this);
  9.1099 -
  9.1100 -    dfb_context->Unlock(dfb_context);
  9.1101 -    dfb_context->Release(dfb_context);
  9.1102 -}
  9.1103 -
  9.1104 -#endif
    10.1 --- a/src/video/directfb/SDL_DirectFB_video.h	Sun Aug 31 16:03:55 2008 +0000
    10.2 +++ b/src/video/directfb/SDL_DirectFB_video.h	Sun Aug 31 16:04:32 2008 +0000
    10.3 @@ -24,9 +24,14 @@
    10.4  #ifndef _SDL_DirectFB_video_h
    10.5  #define _SDL_DirectFB_video_h
    10.6  
    10.7 +#include "../SDL_sysvideo.h"
    10.8 +
    10.9  #include <directfb.h>
   10.10  #include <directfb_version.h>
   10.11  
   10.12 +#include "SDL_mouse.h"
   10.13 +
   10.14 +#define DEBUG 0
   10.15  #define LOG_CHANNEL 	stdout
   10.16  
   10.17  #if (DIRECTFB_MAJOR_VERSION == 0) && (DIRECTFB_MINOR_VERSION == 9) && (DIRECTFB_MICRO_VERSION < 23)
   10.18 @@ -42,10 +47,18 @@
   10.19  #include "SDL_loadso.h"
   10.20  #endif
   10.21  
   10.22 -#include "SDL_mouse.h"
   10.23 -#include "../SDL_sysvideo.h"
   10.24 +#include "SDL_DirectFB_events.h"
   10.25 +/*
   10.26 + * #include "SDL_DirectFB_gamma.h"
   10.27 + * #include "SDL_DirectFB_keyboard.h"
   10.28 + */
   10.29 +#include "SDL_DirectFB_modes.h"
   10.30 +#include "SDL_DirectFB_mouse.h"
   10.31 +#include "SDL_DirectFB_opengl.h"
   10.32 +#include "SDL_DirectFB_window.h"
   10.33  
   10.34 -#define DEBUG 1
   10.35 +#define DFBENV_USE_YUV_UNDERLAY "SDL_DIRECTFB_YUV_UNDERLAY"
   10.36 +#define DFBENV_USE_YUV_DIRECT   "SDL_DIRECTFB_YUV_DIRECT"
   10.37  
   10.38  #define SDL_DFB_RELEASE(x) do { if ( x ) { x->Release(x); x = NULL; } } while (0)
   10.39  #define SDL_DFB_FREE(x) do { if ( x ) { SDL_free(x); x = NULL; } } while (0)
   10.40 @@ -102,50 +115,8 @@
   10.41  /* Private display data */
   10.42  
   10.43  #define SDL_DFB_DEVICEDATA(dev)  DFB_DeviceData *devdata = (DFB_DeviceData *) ((dev)->driverdata)
   10.44 -#define SDL_DFB_WINDOWDATA(win)  DFB_WindowData *windata = ((win) ? (DFB_WindowData *) ((win)->driverdata) : NULL)
   10.45 -#define SDL_DFB_DISPLAYDATA(dev, win)  DFB_DisplayData *dispdata = ((win && dev) ? (DFB_DisplayData *) (dev)->displays[(win)->display].driverdata : NULL)
   10.46 -
   10.47 -typedef struct _DFB_DisplayData DFB_DisplayData;
   10.48  
   10.49  #define DFB_MAX_SCREENS 10
   10.50 -#define DFB_MAX_MODES 50
   10.51 -
   10.52 -struct _DFB_DisplayData
   10.53 -{
   10.54 -    IDirectFBDisplayLayer *layer;
   10.55 -    DFBSurfacePixelFormat pixelformat;
   10.56 -    //FIXME: support for multiple layer ...
   10.57 -    DFBDisplayLayerID vidID;
   10.58 -
   10.59 -    int vidIDinuse;
   10.60 -
   10.61 -    int cw;
   10.62 -    int ch;
   10.63 -
   10.64 -    int nummodes;
   10.65 -    SDL_DisplayMode *modelist;
   10.66 -
   10.67 -#if 0
   10.68 -    WMcursor *last_cursor;
   10.69 -    WMcursor *blank_cursor;
   10.70 -    WMcursor *default_cursor;
   10.71 -#endif
   10.72 -};
   10.73 -
   10.74 -
   10.75 -typedef struct _DFB_WindowData DFB_WindowData;
   10.76 -struct _DFB_WindowData
   10.77 -{
   10.78 -    IDirectFBSurface *surface;
   10.79 -    IDirectFBPalette *palette;
   10.80 -    IDirectFBWindow *window;
   10.81 -    IDirectFBGL *gl_context;
   10.82 -    IDirectFBEventBuffer *eventbuffer;
   10.83 -    DFBWindowID windowID;
   10.84 -    int id;                     /* SDL window id */
   10.85 -    DFB_WindowData *next;
   10.86 -    Uint8 opacity;
   10.87 -};
   10.88  
   10.89  typedef struct _DFB_DeviceData DFB_DeviceData;
   10.90  struct _DFB_DeviceData
   10.91 @@ -158,25 +129,14 @@
   10.92      int kbdgeneric;
   10.93      DFB_WindowData *firstwin;
   10.94  
   10.95 -    int numscreens;
   10.96 -    DFBScreenID screenid[DFB_MAX_SCREENS];
   10.97 -    DFBDisplayLayerID gralayer[DFB_MAX_SCREENS];
   10.98 -    DFBDisplayLayerID vidlayer[DFB_MAX_SCREENS];
   10.99 -
  10.100 -    int aux;                    /* auxiliary integer for callbacks */
  10.101 +    int use_yuv_underlays;
  10.102  
  10.103      /* OpenGL */
  10.104      void (*glFinish) (void);
  10.105      void (*glFlush) (void);
  10.106 -};
  10.107  
  10.108 -struct SDL_GLDriverData
  10.109 -{
  10.110 -    int gl_active;              /* to stop switching drivers while we have a valid context */
  10.111 -
  10.112 -#if SDL_DIRECTFB_OPENGL
  10.113 -    IDirectFBGL *gl_context;
  10.114 -#endif                          /* SDL_DIRECTFB_OPENGL */
  10.115 +    /* global events */
  10.116 +    IDirectFBEventBuffer *events;
  10.117  };
  10.118  
  10.119  #endif /* _SDL_DirectFB_video_h */
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/src/video/directfb/SDL_DirectFB_window.c	Sun Aug 31 16:04:32 2008 +0000
    11.3 @@ -0,0 +1,325 @@
    11.4 +/*
    11.5 +    SDL - Simple DirectMedia Layer
    11.6 +    Copyright (C) 1997-2006 Sam Lantinga
    11.7 +
    11.8 +    This library is free software; you can redistribute it and/or
    11.9 +    modify it under the terms of the GNU Lesser General Public
   11.10 +    License as published by the Free Software Foundation; either
   11.11 +    version 2.1 of the License, or (at your option) any later version.
   11.12 +
   11.13 +    This library is distributed in the hope that it will be useful,
   11.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   11.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   11.16 +    Lesser General Public License for more details.
   11.17 +
   11.18 +    You should have received a copy of the GNU Lesser General Public
   11.19 +    License along with this library; if not, write to the Free Software
   11.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   11.21 +
   11.22 +    Sam Lantinga
   11.23 +    slouken@libsdl.org
   11.24 +*/
   11.25 +#include "SDL_config.h"
   11.26 +
   11.27 +#include "SDL_syswm.h"
   11.28 +#include "../SDL_sysvideo.h"
   11.29 +#include "../../events/SDL_keyboard_c.h"
   11.30 +
   11.31 +#include "SDL_DirectFB_video.h"
   11.32 +
   11.33 +int
   11.34 +DirectFB_CreateWindow(_THIS, SDL_Window * window)
   11.35 +{
   11.36 +    SDL_DFB_DEVICEDATA(_this);
   11.37 +    SDL_DFB_DISPLAYDATA(_this, window);
   11.38 +    DFB_WindowData *windata;
   11.39 +    DFBWindowOptions wopts;
   11.40 +    DFBWindowDescription desc;
   11.41 +    int ret, x, y;
   11.42 +
   11.43 +    SDL_DFB_DEBUG("Trace x %d y %d w %d h %d\n", window->x, window->y,
   11.44 +                  window->w, window->h);
   11.45 +    window->driverdata = NULL;
   11.46 +    SDL_DFB_CALLOC(window->driverdata, 1, sizeof(DFB_WindowData));
   11.47 +    windata = (DFB_WindowData *) window->driverdata;
   11.48 +
   11.49 +    SDL_DFB_CHECKERR(devdata->dfb->
   11.50 +                     SetCooperativeLevel(devdata->dfb, DFSCL_NORMAL));
   11.51 +    SDL_DFB_CHECKERR(dispdata->layer->
   11.52 +                     SetCooperativeLevel(dispdata->layer,
   11.53 +                                         DLSCL_ADMINISTRATIVE));
   11.54 +
   11.55 +    /* Fill the window description. */
   11.56 +    if (window->x == SDL_WINDOWPOS_CENTERED) {
   11.57 +        x = (dispdata->cw - window->w) / 2;
   11.58 +    } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
   11.59 +        x = 0;
   11.60 +    } else {
   11.61 +        x = window->x;
   11.62 +    }
   11.63 +    if (window->y == SDL_WINDOWPOS_CENTERED) {
   11.64 +        y = (dispdata->ch - window->h) / 2;
   11.65 +    } else if (window->y == SDL_WINDOWPOS_UNDEFINED) {
   11.66 +        y = 0;
   11.67 +    } else {
   11.68 +        y = window->y;
   11.69 +    }
   11.70 +    if (window->flags & SDL_WINDOW_FULLSCREEN) {
   11.71 +        x = 0;
   11.72 +        y = 0;
   11.73 +    }
   11.74 +
   11.75 +    desc.flags = DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_PIXELFORMAT;
   11.76 +    /*| DWDESC_CAPS | DWDESC_SURFACE_CAPS */
   11.77 +
   11.78 +#if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 0)
   11.79 +    /* Needed for 1.2 */
   11.80 +    desc.flags |= DWDESC_POSX | DWDESC_POSY | DWDESC_SURFACE_CAPS;
   11.81 +    desc.posx = x;
   11.82 +    desc.posy = y;
   11.83 +#else
   11.84 +    if (!(window->flags & SDL_WINDOW_FULLSCREEN)
   11.85 +        && window->x != SDL_WINDOWPOS_UNDEFINED
   11.86 +        && window->y != SDL_WINDOWPOS_UNDEFINED) {
   11.87 +        desc.flags |= DWDESC_POSX | DWDESC_POSY;
   11.88 +        desc.posx = x;
   11.89 +        desc.posy = y;
   11.90 +    }
   11.91 +#endif
   11.92 +
   11.93 +    desc.width = window->w;
   11.94 +    desc.height = window->h;
   11.95 +    desc.pixelformat = dispdata->pixelformat;
   11.96 +#if 0
   11.97 +    desc.caps = 0;
   11.98 +    desc.surface_caps =
   11.99 +        DSCAPS_DOUBLE | DSCAPS_TRIPLE | DSCAPS_PREMULTIPLIED |
  11.100 +        DSCAPS_VIDEOONLY;
  11.101 +#endif
  11.102 +    desc.surface_caps = DSCAPS_PREMULTIPLIED;
  11.103 +    /* DSCAPS_VIDEOONLY has negative impact on performance */
  11.104 +
  11.105 +    /* Create the window. */
  11.106 +    SDL_DFB_CHECKERR(dispdata->layer->
  11.107 +                     CreateWindow(dispdata->layer, &desc, &windata->window));
  11.108 +
  11.109 +    windata->window->GetOptions(windata->window, &wopts);
  11.110 +#if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 0)
  11.111 +
  11.112 +    if (window->flags & SDL_WINDOW_RESIZABLE)
  11.113 +        wopts |= DWOP_SCALE;
  11.114 +    else
  11.115 +        wopts |= DWOP_KEEP_SIZE;
  11.116 +#else
  11.117 +    wopts |= DWOP_KEEP_SIZE;    /* if not we will crash ... */
  11.118 +#endif
  11.119 +
  11.120 +    if (window->flags & SDL_WINDOW_FULLSCREEN)
  11.121 +        wopts |= DWOP_KEEP_POSITION | DWOP_KEEP_STACKING | DWOP_KEEP_SIZE;
  11.122 +
  11.123 +    windata->window->SetOptions(windata->window, wopts);
  11.124 +    /* Get the window's surface. */
  11.125 +    SDL_DFB_CHECKERR(windata->window->
  11.126 +                     GetSurface(windata->window, &windata->surface));
  11.127 +    windata->window->SetOpacity(windata->window, 0xFF);
  11.128 +    SDL_DFB_CHECKERR(windata->window->
  11.129 +                     CreateEventBuffer(windata->window,
  11.130 +                                       &(windata->eventbuffer)));
  11.131 +    SDL_DFB_CHECKERR(windata->window->
  11.132 +                     EnableEvents(windata->window, DWET_ALL));
  11.133 +
  11.134 +    if (window->flags & SDL_WINDOW_FULLSCREEN)
  11.135 +        windata->window->SetStackingClass(windata->window, DWSC_UPPER);
  11.136 +    /* Make it the top most window. */
  11.137 +    windata->window->RaiseToTop(windata->window);
  11.138 +
  11.139 +    windata->window->GetID(windata->window, &windata->windowID);
  11.140 +
  11.141 +    windata->window->GetSize(windata->window, &window->w, &window->h);
  11.142 +
  11.143 +    /* remember parent */
  11.144 +    windata->id = window->id;
  11.145 +
  11.146 +    /* Add to list ... */
  11.147 +
  11.148 +    windata->next = devdata->firstwin;
  11.149 +    windata->opacity = 0xFF;
  11.150 +    devdata->firstwin = windata;
  11.151 +
  11.152 +    return 0;
  11.153 +  error:
  11.154 +    SDL_DFB_RELEASE(windata->window);
  11.155 +    SDL_DFB_RELEASE(windata->surface);
  11.156 +    return -1;
  11.157 +}
  11.158 +
  11.159 +int
  11.160 +DirectFB_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
  11.161 +{
  11.162 +    SDL_Unsupported();
  11.163 +    return -1;
  11.164 +}
  11.165 +
  11.166 +void
  11.167 +DirectFB_SetWindowTitle(_THIS, SDL_Window * window)
  11.168 +{
  11.169 +    SDL_Unsupported();
  11.170 +}
  11.171 +
  11.172 +void
  11.173 +DirectFB_SetWindowPosition(_THIS, SDL_Window * window)
  11.174 +{
  11.175 +    SDL_DFB_WINDOWDATA(window);
  11.176 +    int x, y;
  11.177 +
  11.178 +    if (window->y == SDL_WINDOWPOS_UNDEFINED)
  11.179 +        y = 0;
  11.180 +    else
  11.181 +        y = window->y;
  11.182 +
  11.183 +    if (window->x == SDL_WINDOWPOS_UNDEFINED)
  11.184 +        x = 0;
  11.185 +    else
  11.186 +        x = window->x;
  11.187 +
  11.188 +    if (window->flags & SDL_WINDOW_FULLSCREEN) {
  11.189 +        x = 0;
  11.190 +        y = 0;
  11.191 +    }
  11.192 +
  11.193 +    windata->window->MoveTo(windata->window, x, y);
  11.194 +}
  11.195 +
  11.196 +void
  11.197 +DirectFB_SetWindowSize(_THIS, SDL_Window * window)
  11.198 +{
  11.199 +    int ret;
  11.200 +    SDL_DFB_WINDOWDATA(window);
  11.201 +
  11.202 +    if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
  11.203 +#if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 0)
  11.204 +        int cw;
  11.205 +        int ch;
  11.206 +
  11.207 +        /* Make sure all events are disabled for this operation ! */
  11.208 +        SDL_DFB_CHECKERR(windata->window->
  11.209 +                         DisableEvents(windata->window, DWET_ALL));
  11.210 +
  11.211 +        SDL_DFB_CHECKERR(windata->window->GetSize(windata->window, &cw, &ch));
  11.212 +        if (cw != window->w || ch != window->h)
  11.213 +            SDL_DFB_CHECKERR(windata->window->
  11.214 +                             Resize(windata->window, window->w, window->h));
  11.215 +        SDL_DFB_CHECKERR(windata->window->
  11.216 +                         EnableEvents(windata->window, DWET_ALL));
  11.217 +
  11.218 +#else
  11.219 +        SDL_DFB_CHECKERR(windata->window->
  11.220 +                         Resize(windata->window, window->w, window->h));
  11.221 +#endif
  11.222 +        SDL_DFB_CHECKERR(windata->window->GetSize(windata->window, &window->w, &window->h));    /* if a window manager should have decided otherwise */
  11.223 +
  11.224 +        SDL_OnWindowResized(window);
  11.225 +    }
  11.226 +    return;
  11.227 +  error:
  11.228 +    windata->window->EnableEvents(windata->window, DWET_ALL);
  11.229 +    return;
  11.230 +}
  11.231 +
  11.232 +void
  11.233 +DirectFB_ShowWindow(_THIS, SDL_Window * window)
  11.234 +{
  11.235 +    SDL_DFB_WINDOWDATA(window);
  11.236 +
  11.237 +    windata->window->SetOpacity(windata->window, windata->opacity);
  11.238 +
  11.239 +}
  11.240 +
  11.241 +void
  11.242 +DirectFB_HideWindow(_THIS, SDL_Window * window)
  11.243 +{
  11.244 +    SDL_DFB_WINDOWDATA(window);
  11.245 +
  11.246 +    windata->window->GetOpacity(windata->window, &windata->opacity);
  11.247 +    windata->window->SetOpacity(windata->window, 0);
  11.248 +}
  11.249 +
  11.250 +void
  11.251 +DirectFB_RaiseWindow(_THIS, SDL_Window * window)
  11.252 +{
  11.253 +    SDL_DFB_WINDOWDATA(window);
  11.254 +
  11.255 +    windata->window->RaiseToTop(windata->window);
  11.256 +    windata->window->RequestFocus(windata->window);
  11.257 +}
  11.258 +
  11.259 +void
  11.260 +DirectFB_MaximizeWindow(_THIS, SDL_Window * window)
  11.261 +{
  11.262 +    /* FIXME: Size to Desktop ? */
  11.263 +
  11.264 +    SDL_Unsupported();
  11.265 +}
  11.266 +
  11.267 +void
  11.268 +DirectFB_MinimizeWindow(_THIS, SDL_Window * window)
  11.269 +{
  11.270 +    /* FIXME: Size to 32x32 ? */
  11.271 +
  11.272 +    SDL_Unsupported();
  11.273 +}
  11.274 +
  11.275 +void
  11.276 +DirectFB_RestoreWindow(_THIS, SDL_Window * window)
  11.277 +{
  11.278 +    SDL_Unsupported();
  11.279 +}
  11.280 +
  11.281 +void
  11.282 +DirectFB_SetWindowGrab(_THIS, SDL_Window * window)
  11.283 +{
  11.284 +    SDL_DFB_WINDOWDATA(window);
  11.285 +
  11.286 +    if ((window->flags & SDL_WINDOW_INPUT_GRABBED) &&
  11.287 +        (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
  11.288 +        windata->window->GrabPointer(windata->window);
  11.289 +        windata->window->GrabKeyboard(windata->window);
  11.290 +    } else {
  11.291 +        windata->window->UngrabPointer(windata->window);
  11.292 +        windata->window->UngrabKeyboard(windata->window);
  11.293 +    }
  11.294 +}
  11.295 +
  11.296 +void
  11.297 +DirectFB_DestroyWindow(_THIS, SDL_Window * window)
  11.298 +{
  11.299 +    SDL_DFB_DEVICEDATA(_this);
  11.300 +    SDL_DFB_WINDOWDATA(window);
  11.301 +    DFB_WindowData *p;
  11.302 +
  11.303 +    SDL_DFB_DEBUG("Trace\n");
  11.304 +
  11.305 +    SDL_DFB_RELEASE(windata->eventbuffer);
  11.306 +    SDL_DFB_RELEASE(windata->surface);
  11.307 +    SDL_DFB_RELEASE(windata->window);
  11.308 +
  11.309 +    /* Remove from list ... */
  11.310 +
  11.311 +    p = devdata->firstwin;
  11.312 +    while (p && p->next != windata)
  11.313 +        p = p->next;
  11.314 +    if (p)
  11.315 +        p->next = windata->next;
  11.316 +    else
  11.317 +        devdata->firstwin = windata->next;
  11.318 +    SDL_free(windata);
  11.319 +    return;
  11.320 +}
  11.321 +
  11.322 +SDL_bool
  11.323 +DirectFB_GetWindowWMInfo(_THIS, SDL_Window * window,
  11.324 +                         struct SDL_SysWMinfo * info)
  11.325 +{
  11.326 +    SDL_Unsupported();
  11.327 +    return SDL_FALSE;
  11.328 +}
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/src/video/directfb/SDL_DirectFB_window.h	Sun Aug 31 16:04:32 2008 +0000
    12.3 @@ -0,0 +1,61 @@
    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 +#ifndef _SDL_directfb_window_h
   12.28 +#define _SDL_directfb_window_h
   12.29 +
   12.30 +#define SDL_DFB_WINDOWDATA(win)  DFB_WindowData *windata = ((win) ? (DFB_WindowData *) ((win)->driverdata) : NULL)
   12.31 +
   12.32 +typedef struct _DFB_WindowData DFB_WindowData;
   12.33 +struct _DFB_WindowData
   12.34 +{
   12.35 +    IDirectFBSurface *surface;
   12.36 +    IDirectFBWindow *window;
   12.37 +    DirectFB_GLContext *gl_context;
   12.38 +    IDirectFBEventBuffer *eventbuffer;
   12.39 +    DFBWindowID windowID;
   12.40 +    DFB_WindowData *next;
   12.41 +    Uint8 opacity;
   12.42 +    SDL_WindowID id;
   12.43 +};
   12.44 +
   12.45 +extern int DirectFB_CreateWindow(_THIS, SDL_Window * window);
   12.46 +extern int DirectFB_CreateWindowFrom(_THIS, SDL_Window * window,
   12.47 +                                     const void *data);
   12.48 +extern void DirectFB_SetWindowTitle(_THIS, SDL_Window * window);
   12.49 +extern void DirectFB_SetWindowPosition(_THIS, SDL_Window * window);
   12.50 +extern void DirectFB_SetWindowSize(_THIS, SDL_Window * window);
   12.51 +extern void DirectFB_ShowWindow(_THIS, SDL_Window * window);
   12.52 +extern void DirectFB_HideWindow(_THIS, SDL_Window * window);
   12.53 +extern void DirectFB_RaiseWindow(_THIS, SDL_Window * window);
   12.54 +extern void DirectFB_MaximizeWindow(_THIS, SDL_Window * window);
   12.55 +extern void DirectFB_MinimizeWindow(_THIS, SDL_Window * window);
   12.56 +extern void DirectFB_RestoreWindow(_THIS, SDL_Window * window);
   12.57 +extern void DirectFB_SetWindowGrab(_THIS, SDL_Window * window);
   12.58 +extern void DirectFB_DestroyWindow(_THIS, SDL_Window * window);
   12.59 +extern SDL_bool DirectFB_GetWindowWMInfo(_THIS, SDL_Window * window,
   12.60 +                                         struct SDL_SysWMinfo *info);
   12.61 +
   12.62 +#endif /* _SDL_directfb_window_h */
   12.63 +
   12.64 +/* vi: set ts=4 sw=4 expandtab: */