Couriersud to Sam
authorSam Lantinga <slouken@libsdl.org>
Mon, 16 Aug 2010 09:04:55 -0700
changeset 4636b196d2758026
parent 4635 0a07d002f10b
child 4637 8c229370ddba
Couriersud to Sam

Hi Sam,

20100815_1.diff contains updates for the directfb driver:

- more documentation, mainly on software OpenGL in README.directfb
- Revised error handling leading to leaner code
- Improved/fixed OpenGL handling of multiple contexts.
- Made the built-in simple window manager handle OpenGL windows.
- Rewrote pixelformat mapping - this was quite ugly before.

Well, all software GL, but working :-)
README.DirectFB
src/video/directfb/SDL_DirectFB_WM.c
src/video/directfb/SDL_DirectFB_WM.h
src/video/directfb/SDL_DirectFB_dyn.c
src/video/directfb/SDL_DirectFB_events.c
src/video/directfb/SDL_DirectFB_modes.c
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/README.DirectFB	Sat Aug 14 12:28:43 2010 -0700
     1.2 +++ b/README.DirectFB	Mon Aug 16 09:04:55 2010 -0700
     1.3 @@ -65,10 +65,26 @@
     1.4  OPENGL Support
     1.5  ==============
     1.6  
     1.7 -As of this writing 20070810 you need to pull Mesa from git and do the following:
     1.8 +The following instructions will give you *software* opengl. However this
     1.9 +works at least on all directfb supported platforms.
    1.10 +
    1.11 +As of this writing 20100802 you need to pull Mesa from git and do the following:
    1.12  
    1.13  ------------------------
    1.14 +git checkout 2c9fdaf7292423c157fc79b5ce43f0f199dd753a
    1.15  cd mesa 
    1.16 +git clone git://anongit.freedesktop.org/git/mesa/mesa
    1.17 +------------------------
    1.18 +
    1.19 +Edit configs/linux-directfb so that the Directories-section looks like
    1.20 +------------------------
    1.21 +# Directories
    1.22 +SRC_DIRS     = mesa glu 
    1.23 +GLU_DIRS     = sgi
    1.24 +DRIVER_DIRS  = directfb
    1.25 +PROGRAM_DIRS = 
    1.26 +------------------------
    1.27 +
    1.28  make linux-directfb
    1.29  make
    1.30  
    1.31 @@ -87,3 +103,4 @@
    1.32  export LD_PRELOAD=/usr/local/dfb_GL/libGL.so.7
    1.33  
    1.34  ./testgl
    1.35 +
     2.1 --- a/src/video/directfb/SDL_DirectFB_WM.c	Sat Aug 14 12:28:43 2010 -0700
     2.2 +++ b/src/video/directfb/SDL_DirectFB_WM.c	Mon Aug 16 09:04:55 2010 -0700
     2.3 @@ -27,6 +27,8 @@
     2.4  
     2.5  #include "SDL_DirectFB_video.h"
     2.6  
     2.7 +#include "../../events/SDL_windowevents_c.h"
     2.8 +
     2.9  #define COLOR_EXPAND(col) col.r, col.g, col.b, col.a
    2.10  
    2.11  static DFB_Theme theme_std = {
    2.12 @@ -52,7 +54,7 @@
    2.13  };
    2.14  
    2.15  static void
    2.16 -DrTriangle(IDirectFBSurface * s, int down, int x, int y, int w)
    2.17 +DrawTriangle(IDirectFBSurface * s, int down, int x, int y, int w)
    2.18  {
    2.19      int x1, x2, x3;
    2.20      int y1, y2, y3;
    2.21 @@ -76,7 +78,33 @@
    2.22  }
    2.23  
    2.24  static void
    2.25 -DrCaption(IDirectFBSurface * s, int x, int y, char *text)
    2.26 +LoadFont(_THIS, SDL_Window * window)
    2.27 +{
    2.28 +    SDL_DFB_DEVICEDATA(_this);
    2.29 +    SDL_DFB_WINDOWDATA(window);
    2.30 +
    2.31 +	if (windata->font != NULL) {
    2.32 +		SDL_DFB_RELEASE(windata->font);
    2.33 +	    windata->font = NULL;
    2.34 +	    SDL_DFB_CHECK(windata->window_surface->SetFont(windata->window_surface, windata->font));
    2.35 +	}
    2.36 +	
    2.37 +	if (windata->theme.font != NULL)
    2.38 +	{
    2.39 +        DFBFontDescription fdesc;
    2.40 +
    2.41 +		SDL_zero(fdesc);
    2.42 +	    fdesc.flags = DFDESC_HEIGHT;
    2.43 +	    fdesc.height = windata->theme.font_size;
    2.44 +	    SDL_DFB_CHECK(devdata->
    2.45 +	                  dfb->CreateFont(devdata->dfb, windata->theme.font,
    2.46 +	                                  &fdesc, &windata->font));
    2.47 +	    SDL_DFB_CHECK(windata->window_surface->SetFont(windata->window_surface, windata->font));
    2.48 +	}
    2.49 +}
    2.50 +
    2.51 +static void
    2.52 +DrawCraption(_THIS, IDirectFBSurface * s, int x, int y, char *text)
    2.53  {
    2.54      DFBSurfaceTextFlags flags;
    2.55  
    2.56 @@ -86,7 +114,7 @@
    2.57  }
    2.58  
    2.59  void
    2.60 -DirectFB_WM_RedrawLayout(SDL_Window * window)
    2.61 +DirectFB_WM_RedrawLayout(_THIS, SDL_Window * window)
    2.62  {
    2.63      SDL_DFB_WINDOWDATA(window);
    2.64      IDirectFBSurface *s = windata->window_surface;
    2.65 @@ -99,6 +127,7 @@
    2.66      if (!windata->is_managed || (window->flags & SDL_WINDOW_FULLSCREEN))
    2.67          return;
    2.68  
    2.69 +	LoadFont(_this, window);
    2.70      //s->SetDrawingFlags(s, DSDRAW_BLEND);
    2.71      s->SetColor(s, COLOR_EXPAND(t->frame_color));
    2.72      /* top */
    2.73 @@ -122,16 +151,16 @@
    2.74      x = windata->size.w - t->right_size - w + d;
    2.75      y = t->top_size + d;
    2.76      s->SetColor(s, COLOR_EXPAND(t->close_color));
    2.77 -    DrTriangle(s, 1, x, y, w - 2 * d);
    2.78 +    DrawTriangle(s, 1, x, y, w - 2 * d);
    2.79      /* Max Button */
    2.80      s->SetColor(s, COLOR_EXPAND(t->max_color));
    2.81 -    DrTriangle(s, window->flags & SDL_WINDOW_MAXIMIZED ? 1 : 0, x - w,
    2.82 +    DrawTriangle(s, window->flags & SDL_WINDOW_MAXIMIZED ? 1 : 0, x - w,
    2.83                 y, w - 2 * d);
    2.84  
    2.85      /* Caption */
    2.86      if (window->title) {
    2.87 -        s->SetColor(s, COLOR_EXPAND(t->font_color));
    2.88 -        DrCaption(s, (x - w) / 2, t->top_size + d, window->title);
    2.89 +	    s->SetColor(s, COLOR_EXPAND(t->font_color));
    2.90 +        DrawCraption(_this, s, (x - w) / 2, t->top_size + d, window->title);
    2.91      }
    2.92      /* Icon */
    2.93      if (windata->icon) {
    2.94 @@ -152,26 +181,25 @@
    2.95  DirectFB_WM_GetClientSize(_THIS, SDL_Window * window, int *cw, int *ch)
    2.96  {
    2.97      SDL_DFB_WINDOWDATA(window);
    2.98 -    DFBResult ret;
    2.99  
   2.100 -    ret = windata->window->GetSize(windata->window, cw, ch);
   2.101 +    SDL_DFB_CHECK(windata->window->GetSize(windata->window, cw, ch));
   2.102      *cw -= windata->theme.left_size + windata->theme.right_size;
   2.103      *ch -=
   2.104          windata->theme.top_size + windata->theme.caption_size +
   2.105          windata->theme.bottom_size;
   2.106 -    return ret;
   2.107 +    return DFB_OK;
   2.108  }
   2.109  
   2.110  void
   2.111 -DirectFB_WM_AdjustWindowLayout(SDL_Window * window)
   2.112 +DirectFB_WM_AdjustWindowLayout(SDL_Window * window, int flags, int w, int h)
   2.113  {
   2.114      SDL_DFB_WINDOWDATA(window);
   2.115  
   2.116      if (!windata->is_managed)
   2.117          windata->theme = theme_none;
   2.118 -    else if (window->flags & SDL_WINDOW_FULLSCREEN) {
   2.119 +    else if (flags & SDL_WINDOW_FULLSCREEN) {
   2.120          windata->theme = theme_none;
   2.121 -    } else if (window->flags & SDL_WINDOW_MAXIMIZED) {
   2.122 +    } else if (flags & SDL_WINDOW_MAXIMIZED) {
   2.123          windata->theme = theme_std;
   2.124          windata->theme.left_size = 0;
   2.125          windata->theme.right_size = 0;
   2.126 @@ -183,12 +211,12 @@
   2.127  
   2.128      windata->client.x = windata->theme.left_size;
   2.129      windata->client.y = windata->theme.top_size + windata->theme.caption_size;
   2.130 -    windata->client.w = window->w;
   2.131 -    windata->client.h = window->h;
   2.132 +    windata->client.w = w;
   2.133 +    windata->client.h = h;
   2.134      windata->size.w =
   2.135 -        window->w + windata->theme.left_size + windata->theme.right_size;
   2.136 +        w + windata->theme.left_size + windata->theme.right_size;
   2.137      windata->size.h =
   2.138 -        window->h + windata->theme.top_size +
   2.139 +        h + windata->theme.top_size +
   2.140          windata->theme.caption_size + windata->theme.bottom_size;
   2.141  }
   2.142  
   2.143 @@ -198,19 +226,16 @@
   2.144      SDL_DFB_WINDOWDATA(window);
   2.145      SDL_VideoDisplay *display = window->display;
   2.146  
   2.147 -    windata->window->GetPosition(windata->window,
   2.148 -                                 &windata->restore.x, &windata->restore.y);
   2.149 -    windata->window->GetSize(windata->window, &windata->restore.w,
   2.150 -                             &windata->restore.h);
   2.151 +    SDL_DFB_CHECK(windata->window->GetPosition(windata->window,
   2.152 +                                 &windata->restore.x, &windata->restore.y));
   2.153 +    SDL_DFB_CHECK(windata->window->GetSize(windata->window, &windata->restore.w,
   2.154 +                             &windata->restore.h));
   2.155  
   2.156 -    /* Do this already here */
   2.157 -    window->flags |= SDL_WINDOW_MAXIMIZED;
   2.158 -    DirectFB_WM_AdjustWindowLayout(window);
   2.159 +    DirectFB_WM_AdjustWindowLayout(window, window->flags | SDL_WINDOW_MAXIMIZED, display->current_mode.w, display->current_mode.h) ;
   2.160  
   2.161 -    windata->window->MoveTo(windata->window, 0, 0);
   2.162 -    windata->window->Resize(windata->window,
   2.163 -                            display->current_mode.w, display->current_mode.h);
   2.164 -    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
   2.165 +    SDL_DFB_CHECK(windata->window->MoveTo(windata->window, 0, 0));
   2.166 +    SDL_DFB_CHECK(windata->window->Resize(windata->window,
   2.167 +                            display->current_mode.w, display->current_mode.h));
   2.168  }
   2.169  
   2.170  void
   2.171 @@ -218,15 +243,13 @@
   2.172  {
   2.173      SDL_DFB_WINDOWDATA(window);
   2.174  
   2.175 -    /* Do this already here */
   2.176 -    //window->flags &= ~(SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED);
   2.177 +    DirectFB_WM_AdjustWindowLayout(window, window->flags & ~(SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED), 
   2.178 +    	windata->restore.w, windata->restore.h);
   2.179  
   2.180 -    DirectFB_WM_AdjustWindowLayout(window);
   2.181 -    windata->window->MoveTo(windata->window, windata->restore.x,
   2.182 -                            windata->restore.y);
   2.183 -    windata->window->Resize(windata->window, windata->restore.w,
   2.184 -                            windata->restore.h);
   2.185 -    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0);
   2.186 +    SDL_DFB_CHECK(windata->window->Resize(windata->window, windata->restore.w,
   2.187 +                            windata->restore.h));
   2.188 +    SDL_DFB_CHECK(windata->window->MoveTo(windata->window, windata->restore.x,
   2.189 +                            windata->restore.y));
   2.190  }
   2.191  
   2.192  enum
   2.193 @@ -291,7 +314,9 @@
   2.194  int
   2.195  DirectFB_WM_ProcessEvent(_THIS, SDL_Window * window, DFBWindowEvent * evt)
   2.196  {
   2.197 +    SDL_DFB_DEVICEDATA(_this);
   2.198      SDL_DFB_WINDOWDATA(window);
   2.199 +	DFB_WindowData *gwindata = ((devdata->grabbed_window) ? (DFB_WindowData *) ((devdata->grabbed_window)->driverdata) : NULL);
   2.200  
   2.201      if (!windata->is_managed)
   2.202          return 0;
   2.203 @@ -304,19 +329,26 @@
   2.204              case WM_POS_NONE:
   2.205                  return 0;
   2.206              case WM_POS_CLOSE:
   2.207 +		        wm_grab = WM_POS_NONE;
   2.208                  SDL_SendWindowEvent(window, SDL_WINDOWEVENT_CLOSE, 0,
   2.209                                      0);
   2.210                  return 1;
   2.211              case WM_POS_MAX:
   2.212 +		        wm_grab = WM_POS_NONE;
   2.213                  if (window->flags & SDL_WINDOW_MAXIMIZED) {
   2.214 -                    DirectFB_WM_RestoreWindow(_this, window);
   2.215 +                	SDL_RestoreWindow(window);
   2.216                  } else {
   2.217 -                    DirectFB_WM_MaximizeWindow(_this, window);
   2.218 +                    SDL_MaximizeWindow(window);
   2.219                  }
   2.220                  return 1;
   2.221 +            case WM_POS_CAPTION:
   2.222 +                DirectFB_RaiseWindow(_this, window);
   2.223 +                /* fall through */
   2.224              default:
   2.225                  wm_grab = pos;
   2.226 -                windata->window->GrabPointer(windata->window);
   2.227 +                if (gwindata != NULL)
   2.228 +	                SDL_DFB_CHECK(gwindata->window->UngrabPointer(gwindata->window));
   2.229 +                SDL_DFB_CHECK(windata->window->GrabPointer(windata->window));
   2.230                  wm_lastx = evt->cx;
   2.231                  wm_lasty = evt->cy;
   2.232              }
   2.233 @@ -333,20 +365,22 @@
   2.234              int cw, ch;
   2.235  
   2.236              if (wm_grab & WM_POS_CAPTION)
   2.237 -                windata->window->Move(windata->window, dx, dy);
   2.238 -            if (wm_grab & WM_POS_RIGHT) {
   2.239 -                windata->window->GetSize(windata->window, &cw, &ch);
   2.240 -                windata->window->Resize(windata->window, cw + dx, ch);
   2.241 -            }
   2.242 -            if (wm_grab & WM_POS_BOTTOM) {
   2.243 -                windata->window->GetSize(windata->window, &cw, &ch);
   2.244 -                windata->window->Resize(windata->window, cw, ch + dy);
   2.245 +                SDL_DFB_CHECK(windata->window->Move(windata->window, dx, dy));
   2.246 +	        if (wm_grab & (WM_POS_RIGHT | WM_POS_BOTTOM)) {
   2.247 +	            if ((wm_grab & (WM_POS_BOTTOM | WM_POS_RIGHT)) == WM_POS_BOTTOM)
   2.248 +	            	dx = 0;
   2.249 +	            else if ((wm_grab & (WM_POS_BOTTOM | WM_POS_RIGHT)) == WM_POS_RIGHT)
   2.250 +	            	dy = 0;
   2.251 +                SDL_DFB_CHECK(windata->window->GetSize(windata->window, &cw, &ch));
   2.252 +                SDL_DFB_CHECK(windata->window->Resize(windata->window, cw + dx, ch + dy));
   2.253              }
   2.254              wm_lastx = evt->cx;
   2.255              wm_lasty = evt->cy;
   2.256              return 1;
   2.257          }
   2.258 -        windata->window->UngrabPointer(windata->window);
   2.259 +        SDL_DFB_CHECK(windata->window->UngrabPointer(windata->window));
   2.260 +        if (gwindata != NULL)
   2.261 +            SDL_DFB_CHECK(gwindata->window->GrabPointer(gwindata->window));
   2.262          wm_grab = WM_POS_NONE;
   2.263          break;
   2.264      case DWET_KEYDOWN:
     3.1 --- a/src/video/directfb/SDL_DirectFB_WM.h	Sat Aug 14 12:28:43 2010 -0700
     3.2 +++ b/src/video/directfb/SDL_DirectFB_WM.h	Mon Aug 16 09:04:55 2010 -0700
     3.3 @@ -41,10 +41,10 @@
     3.4      DFBColor max_color;
     3.5  };
     3.6  
     3.7 -extern void DirectFB_WM_AdjustWindowLayout(SDL_Window * window);
     3.8 +extern void DirectFB_WM_AdjustWindowLayout(SDL_Window * window, int flags, int w, int h);
     3.9  extern void DirectFB_WM_MaximizeWindow(_THIS, SDL_Window * window);
    3.10  extern void DirectFB_WM_RestoreWindow(_THIS, SDL_Window * window);
    3.11 -extern void DirectFB_WM_RedrawLayout(SDL_Window * window);
    3.12 +extern void DirectFB_WM_RedrawLayout(_THIS, SDL_Window * window);
    3.13  
    3.14  extern int DirectFB_WM_ProcessEvent(_THIS, SDL_Window * window,
    3.15                                      DFBWindowEvent * evt);
     4.1 --- a/src/video/directfb/SDL_DirectFB_dyn.c	Sat Aug 14 12:28:43 2010 -0700
     4.2 +++ b/src/video/directfb/SDL_DirectFB_dyn.c	Mon Aug 16 09:04:55 2010 -0700
     4.3 @@ -31,7 +31,8 @@
     4.4  #define DFB_SYM(ret, name, args, al, func) ret (*name) args;
     4.5  static struct _SDL_DirectFB_Symbols
     4.6  {
     4.7 -    DFB_SYMS const unsigned int *directfb_major_version;
     4.8 +    DFB_SYMS 
     4.9 +    const unsigned int *directfb_major_version;
    4.10      const unsigned int *directfb_minor_version;
    4.11      const unsigned int *directfb_micro_version;
    4.12  } SDL_DirectFB_Symbols;
     5.1 --- a/src/video/directfb/SDL_DirectFB_events.c	Sat Aug 14 12:28:43 2010 -0700
     5.2 +++ b/src/video/directfb/SDL_DirectFB_events.c	Mon Aug 16 09:04:55 2010 -0700
     5.3 @@ -33,21 +33,28 @@
     5.4  #include "SDL_DirectFB_events.h"
     5.5  
     5.6  #if USE_MULTI_API
     5.7 -#define SDL_SendMouseMotion_ex(id, relative, x, y, p) SDL_SendMouseMotion(id, relative, x, y, p)
     5.8 -#define SDL_SendMouseButton_ex(id, state, button) SDL_SendMouseButton(id, state, button)
     5.9 +#define SDL_SendMouseMotion_ex(w, id, relative, x, y, p) SDL_SendMouseMotion(id, relative, x, y, p)
    5.10 +#define SDL_SendMouseButton_ex(w, id, state, button) SDL_SendMouseButton(id, state, button)
    5.11  #define SDL_SendKeyboardKey_ex(id, state, scancode) SDL_SendKeyboardKey(id, state, scancode)
    5.12  #define SDL_SendKeyboardText_ex(id, text) SDL_SendKeyboardText(id, text)
    5.13  #else
    5.14 -#define SDL_SendMouseMotion_ex(id, relative, x, y, p) SDL_SendMouseMotion(relative, x, y)
    5.15 -#define SDL_SendMouseButton_ex(id, state, button) SDL_SendMouseButton(state, button)
    5.16 +#define SDL_SendMouseMotion_ex(w, id, relative, x, y, p) SDL_SendMouseMotion(w, relative, x, y)
    5.17 +#define SDL_SendMouseButton_ex(w, id, state, button) SDL_SendMouseButton(w, state, button)
    5.18  #define SDL_SendKeyboardKey_ex(id, state, scancode) SDL_SendKeyboardKey(state, scancode)
    5.19  #define SDL_SendKeyboardText_ex(id, text) SDL_SendKeyboardText(text)
    5.20  #endif
    5.21  
    5.22 +typedef struct _cb_data cb_data;
    5.23 +struct _cb_data 
    5.24 +{
    5.25 +	DFB_DeviceData *devdata;	
    5.26 +	int sys_ids;
    5.27 +	int sys_kbd;
    5.28 +};
    5.29  
    5.30  /* The translation tables from a DirectFB keycode to a SDL keysym */
    5.31  static SDLKey oskeymap[256];
    5.32 -static int sys_ids;
    5.33 +
    5.34  
    5.35  static SDL_keysym *DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt,
    5.36                                           SDL_keysym * keysym);
    5.37 @@ -69,14 +76,11 @@
    5.38  
    5.39      SDL_VideoDisplay *display = window->display;
    5.40      DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
    5.41 -    int ret;
    5.42  
    5.43 +	/* FIXME: should we handle the error */
    5.44      if (dispdata->vidIDinuse)
    5.45 -        SDL_DFB_CHECKERR(dispdata->vidlayer->SwitchContext(dispdata->vidlayer,
    5.46 +        SDL_DFB_CHECK(dispdata->vidlayer->SwitchContext(dispdata->vidlayer,
    5.47                                                             DFB_TRUE));
    5.48 -
    5.49 -  error:
    5.50 -    return;
    5.51  #endif
    5.52  
    5.53  }
    5.54 @@ -172,9 +176,9 @@
    5.55          case DWET_BUTTONDOWN:
    5.56              if (ClientXY(p, &evt->x, &evt->y)) {
    5.57                  if (!devdata->use_linux_input) {
    5.58 -                    SDL_SendMouseMotion_ex(devdata->mouse_id[0], 0, evt->x,
    5.59 +                    SDL_SendMouseMotion_ex(p->sdl_window, devdata->mouse_id[0], 0, evt->x,
    5.60                                          evt->y, 0);
    5.61 -                    SDL_SendMouseButton_ex(devdata->mouse_id[0],
    5.62 +                    SDL_SendMouseButton_ex(p->sdl_window, devdata->mouse_id[0],
    5.63                                          SDL_PRESSED,
    5.64                                          DirectFB_TranslateButton
    5.65                                          (evt->button));
    5.66 @@ -186,9 +190,9 @@
    5.67          case DWET_BUTTONUP:
    5.68              if (ClientXY(p, &evt->x, &evt->y)) {
    5.69                  if (!devdata->use_linux_input) {
    5.70 -                    SDL_SendMouseMotion_ex(devdata->mouse_id[0], 0, evt->x,
    5.71 +                    SDL_SendMouseMotion_ex(p->sdl_window, devdata->mouse_id[0], 0, evt->x,
    5.72                                          evt->y, 0);
    5.73 -                    SDL_SendMouseButton_ex(devdata->mouse_id[0],
    5.74 +                    SDL_SendMouseButton_ex(p->sdl_window, devdata->mouse_id[0],
    5.75                                          SDL_RELEASED,
    5.76                                          DirectFB_TranslateButton
    5.77                                          (evt->button));
    5.78 @@ -202,7 +206,7 @@
    5.79                  SDL_Window *window = p->sdl_window;
    5.80                  if (!devdata->use_linux_input) {
    5.81                      if (!(flags & SDL_WINDOW_INPUT_GRABBED))
    5.82 -                        SDL_SendMouseMotion_ex(devdata->mouse_id[0], 0,
    5.83 +                        SDL_SendMouseMotion_ex(p->sdl_window, devdata->mouse_id[0], 0,
    5.84                                              evt->x, evt->y, 0);
    5.85                  } else {
    5.86                      /* relative movements are not exact! 
    5.87 @@ -215,7 +219,7 @@
    5.88                      }
    5.89                  }
    5.90                  if (!(window->flags & SDL_WINDOW_MOUSE_FOCUS))
    5.91 -                    SDL_SendWindowEvent(p->window, SDL_WINDOWEVENT_ENTER, 0,
    5.92 +                    SDL_SendWindowEvent(p->sdl_window, SDL_WINDOWEVENT_ENTER, 0,
    5.93                                          0);
    5.94              }
    5.95              break;
    5.96 @@ -293,7 +297,7 @@
    5.97  }
    5.98  
    5.99  static void
   5.100 -ProcessInputEvent(_THIS, SDL_Window *grabbed_window, DFBInputEvent * ievt)
   5.101 +ProcessInputEvent(_THIS, DFBInputEvent * ievt)
   5.102  {
   5.103      SDL_DFB_DEVICEDATA(_this);
   5.104      SDL_keysym keysym;
   5.105 @@ -302,17 +306,16 @@
   5.106  
   5.107      if (!devdata->use_linux_input) {
   5.108          if (ievt->type == DIET_AXISMOTION) {
   5.109 -            if ((grabbed_window != NULL) && (ievt->flags & DIEF_AXISREL)) {
   5.110 +            if ((devdata->grabbed_window != NULL) && (ievt->flags & DIEF_AXISREL)) {
   5.111                  if (ievt->axis == DIAI_X)
   5.112 -                    SDL_SendMouseMotion_ex(ievt->device_id, 1,
   5.113 +                    SDL_SendMouseMotion_ex(devdata->grabbed_window, ievt->device_id, 1,
   5.114                                          ievt->axisrel, 0, 0);
   5.115                  else if (ievt->axis == DIAI_Y)
   5.116 -                    SDL_SendMouseMotion_ex(ievt->device_id, 1, 0,
   5.117 +                    SDL_SendMouseMotion_ex(devdata->grabbed_window, ievt->device_id, 1, 0,
   5.118                                          ievt->axisrel, 0);
   5.119              }
   5.120          }
   5.121      } else {
   5.122 -#if USE_MULTI_API
   5.123          static int last_x, last_y;
   5.124  
   5.125          switch (ievt->type) {
   5.126 @@ -323,30 +326,34 @@
   5.127                  else if (ievt->axis == DIAI_Y)
   5.128                      last_y = ievt->axisabs;
   5.129                  if (!(ievt->flags & DIEF_FOLLOW)) {
   5.130 +#if USE_MULTI_API
   5.131                      SDL_Mouse *mouse = SDL_GetMouse(ievt->device_id);
   5.132                      SDL_Window *window = SDL_GetWindowFromID(mouse->focus);
   5.133 +#else
   5.134 +                    SDL_Window *window = devdata->grabbed_window;
   5.135 +#endif
   5.136                      if (window) {
   5.137                          DFB_WindowData *windata =
   5.138                              (DFB_WindowData *) window->driverdata;
   5.139                          int x, y;
   5.140  
   5.141                          windata->window->GetPosition(windata->window, &x, &y);
   5.142 -                        SDL_SendMouseMotion_ex(ievt->device_id, 0,
   5.143 +                        SDL_SendMouseMotion_ex(window, ievt->device_id, 0,
   5.144                                              last_x - (x +
   5.145                                                        windata->client.x),
   5.146                                              last_y - (y +
   5.147                                                        windata->client.y), 0);
   5.148                      } else {
   5.149 -                        SDL_SendMouseMotion_ex(ievt->device_id, 0, last_x,
   5.150 +                        SDL_SendMouseMotion_ex(window, ievt->device_id, 0, last_x,
   5.151                                              last_y, 0);
   5.152                      }
   5.153                  }
   5.154              } else if (ievt->flags & DIEF_AXISREL) {
   5.155                  if (ievt->axis == DIAI_X)
   5.156 -                    SDL_SendMouseMotion_ex(ievt->device_id, 1,
   5.157 +                    SDL_SendMouseMotion_ex(devdata->grabbed_window, ievt->device_id, 1,
   5.158                                          ievt->axisrel, 0, 0);
   5.159                  else if (ievt->axis == DIAI_Y)
   5.160 -                    SDL_SendMouseMotion_ex(ievt->device_id, 1, 0,
   5.161 +                    SDL_SendMouseMotion_ex(devdata->grabbed_window, ievt->device_id, 1, 0,
   5.162                                          ievt->axisrel, 0);
   5.163              }
   5.164              break;
   5.165 @@ -365,28 +372,27 @@
   5.166          case DIET_KEYRELEASE:
   5.167              kbd_idx = KbdIndex(_this, ievt->device_id);
   5.168              DirectFB_TranslateKeyInputEvent(_this, kbd_idx, ievt, &keysym);
   5.169 -            SDL_SendKeyboardKey(kbd_idx, SDL_RELEASED, keysym.scancode);
   5.170 +            SDL_SendKeyboardKey_ex(kbd_idx, SDL_RELEASED, keysym.scancode);
   5.171              break;
   5.172          case DIET_BUTTONPRESS:
   5.173              if (ievt->buttons & DIBM_LEFT)
   5.174 -                SDL_SendMouseButton(ievt->device_id, SDL_PRESSED, 1);
   5.175 +                SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_PRESSED, 1);
   5.176              if (ievt->buttons & DIBM_MIDDLE)
   5.177 -                SDL_SendMouseButton(ievt->device_id, SDL_PRESSED, 2);
   5.178 +                SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_PRESSED, 2);
   5.179              if (ievt->buttons & DIBM_RIGHT)
   5.180 -                SDL_SendMouseButton(ievt->device_id, SDL_PRESSED, 3);
   5.181 +                SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_PRESSED, 3);
   5.182              break;
   5.183          case DIET_BUTTONRELEASE:
   5.184              if (!(ievt->buttons & DIBM_LEFT))
   5.185 -                SDL_SendMouseButton(ievt->device_id, SDL_RELEASED, 1);
   5.186 +                SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_RELEASED, 1);
   5.187              if (!(ievt->buttons & DIBM_MIDDLE))
   5.188 -                SDL_SendMouseButton(ievt->device_id, SDL_RELEASED, 2);
   5.189 +                SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_RELEASED, 2);
   5.190              if (!(ievt->buttons & DIBM_RIGHT))
   5.191 -                SDL_SendMouseButton(ievt->device_id, SDL_RELEASED, 3);
   5.192 +                SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_RELEASED, 3);
   5.193              break;
   5.194          default:
   5.195              break;              /* please gcc */
   5.196          }
   5.197 -#endif
   5.198      }
   5.199  }
   5.200  
   5.201 @@ -396,18 +402,11 @@
   5.202      SDL_DFB_DEVICEDATA(_this);
   5.203      DFB_WindowData *p;
   5.204      DFBInputEvent ievt;
   5.205 -    SDL_Window *grabbed_window;
   5.206 -
   5.207 -    grabbed_window = NULL;
   5.208  
   5.209      for (p = devdata->firstwin; p != NULL; p = p->next) {
   5.210          DFBWindowEvent evt;
   5.211          SDL_Window *w = p->sdl_window;
   5.212  
   5.213 -        if (w->flags & SDL_WINDOW_INPUT_GRABBED) {
   5.214 -            grabbed_window = w;
   5.215 -        }
   5.216 -
   5.217          while (p->eventbuffer->GetEvent(p->eventbuffer,
   5.218                                          DFB_EVENT(&evt)) == DFB_OK) {
   5.219              if (!DirectFB_WM_ProcessEvent(_this, w, &evt))
   5.220 @@ -418,7 +417,7 @@
   5.221      /* Now get relative events in case we need them */
   5.222      while (devdata->events->GetEvent(devdata->events,
   5.223                                       DFB_EVENT(&ievt)) == DFB_OK) {
   5.224 -        ProcessInputEvent(_this, grabbed_window, &ievt);
   5.225 +        ProcessInputEvent(_this, &ievt);
   5.226      }
   5.227  }
   5.228  
   5.229 @@ -623,105 +622,87 @@
   5.230  }
   5.231  
   5.232  static DFBEnumerationResult
   5.233 -input_device_cb(DFBInputDeviceID device_id,
   5.234 +EnumKeyboards(DFBInputDeviceID device_id,
   5.235                  DFBInputDeviceDescription desc, void *callbackdata)
   5.236  {
   5.237 -    DFB_DeviceData *devdata = callbackdata;
   5.238 +	cb_data *cb = callbackdata;
   5.239 +    DFB_DeviceData *devdata = cb->devdata;
   5.240  #if USE_MULTI_API
   5.241      SDL_Keyboard keyboard;
   5.242  #endif
   5.243      SDLKey keymap[SDL_NUM_SCANCODES];
   5.244  
   5.245 -    if ((desc.caps & DIDTF_KEYBOARD) && device_id == DIDID_KEYBOARD) {
   5.246 +	if (!cb->sys_kbd) {
   5.247 +		if (cb->sys_ids) {
   5.248 +		    if (device_id >= 0x10)
   5.249 +		        return DFENUM_OK;
   5.250 +		} else {
   5.251 +		    if (device_id < 0x10)
   5.252 +		        return DFENUM_OK;
   5.253 +		}
   5.254 +	} else {
   5.255 +		if (device_id != DIDID_KEYBOARD)
   5.256 +		    return DFENUM_OK;
   5.257 +	}
   5.258 +	
   5.259 +    if ((desc.caps & DIDTF_KEYBOARD)) {
   5.260  #if USE_MULTI_API
   5.261          SDL_zero(keyboard);
   5.262 -        SDL_AddKeyboard(&keyboard, 0);
   5.263 +        SDL_AddKeyboard(&keyboard, devdata->num_keyboard);
   5.264  #endif
   5.265 -        devdata->keyboard[0].id = device_id;
   5.266 -        devdata->keyboard[0].is_generic = 0;
   5.267 -        if (!strncmp("X11", desc.name, 3))
   5.268 -            devdata->keyboard[0].is_generic = 1;
   5.269 -
   5.270 -        SDL_GetDefaultKeymap(keymap);
   5.271 -#if USE_MULTI_API
   5.272 -        SDL_SetKeymap(0, 0, keymap, SDL_NUM_SCANCODES);
   5.273 -#else
   5.274 -        SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES);
   5.275 -#endif
   5.276 -        devdata->num_keyboard++;
   5.277 -
   5.278 -        return DFENUM_CANCEL;
   5.279 -    }
   5.280 -    return DFENUM_OK;
   5.281 -}
   5.282 -
   5.283 -#if USE_MULTI_API
   5.284 -static DFBEnumerationResult
   5.285 -EnumKeyboards(DFBInputDeviceID device_id,
   5.286 -              DFBInputDeviceDescription desc, void *callbackdata)
   5.287 -{
   5.288 -    DFB_DeviceData *devdata = callbackdata;
   5.289 -    SDL_Keyboard keyboard;
   5.290 -    SDLKey keymap[SDL_NUM_SCANCODES];
   5.291 -
   5.292 -    if (sys_ids) {
   5.293 -        if (device_id >= 0x10)
   5.294 -            return DFENUM_OK;
   5.295 -    } else {
   5.296 -        if (device_id < 0x10)
   5.297 -            return DFENUM_OK;
   5.298 -    }
   5.299 -    if ((desc.caps & DIDTF_KEYBOARD)) {
   5.300 -        SDL_zero(keyboard);
   5.301 -        SDL_AddKeyboard(&keyboard, devdata->num_keyboard);
   5.302          devdata->keyboard[devdata->num_keyboard].id = device_id;
   5.303          devdata->keyboard[devdata->num_keyboard].is_generic = 0;
   5.304          if (!strncmp("X11", desc.name, 3))
   5.305              devdata->keyboard[devdata->num_keyboard].is_generic = 1;
   5.306  
   5.307          SDL_GetDefaultKeymap(keymap);
   5.308 +#if USE_MULTI_API
   5.309          SDL_SetKeymap(devdata->num_keyboard, 0, keymap, SDL_NUM_SCANCODES);
   5.310 +#else
   5.311 +        SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES);
   5.312 +#endif
   5.313          devdata->num_keyboard++;
   5.314 +
   5.315 +		if (cb->sys_kbd)
   5.316 +	        return DFENUM_CANCEL;
   5.317      }
   5.318      return DFENUM_OK;
   5.319  }
   5.320 -#endif
   5.321  
   5.322  void
   5.323  DirectFB_InitKeyboard(_THIS)
   5.324  {
   5.325      SDL_DFB_DEVICEDATA(_this);
   5.326 -    int ret;
   5.327 -
   5.328 +	cb_data cb;    
   5.329 +	
   5.330      DirectFB_InitOSKeymap(_this, &oskeymap[0], SDL_arraysize(oskeymap));
   5.331  
   5.332      devdata->num_keyboard = 0;
   5.333 -#if USE_MULTI_API
   5.334 +    cb.devdata = devdata;
   5.335 +    
   5.336      if (devdata->use_linux_input) {
   5.337 -        sys_ids = 0;
   5.338 +    	cb.sys_kbd = 0;
   5.339 +        cb.sys_ids = 0;
   5.340          SDL_DFB_CHECK(devdata->dfb->
   5.341 -                      EnumInputDevices(devdata->dfb, EnumKeyboards, devdata));
   5.342 +                      EnumInputDevices(devdata->dfb, EnumKeyboards, &cb));
   5.343          if (devdata->num_keyboard == 0) {
   5.344 -            sys_ids = 1;
   5.345 +            cb.sys_ids = 1;
   5.346              SDL_DFB_CHECK(devdata->dfb->EnumInputDevices(devdata->dfb,
   5.347                                                           EnumKeyboards,
   5.348 -                                                         devdata));
   5.349 +                                                         &cb));
   5.350          }
   5.351 -    } else
   5.352 -#else
   5.353 -    {
   5.354 +    } else {
   5.355 +    	cb.sys_kbd = 1;
   5.356          SDL_DFB_CHECK(devdata->dfb->EnumInputDevices(devdata->dfb,
   5.357 -                                                     input_device_cb,
   5.358 -                                                     devdata));
   5.359 +                                                     EnumKeyboards,
   5.360 +                                                     &cb));
   5.361      }
   5.362 -#endif
   5.363  }
   5.364  
   5.365  void
   5.366  DirectFB_QuitKeyboard(_THIS)
   5.367  {
   5.368 -    SDL_DFB_DEVICEDATA(_this);
   5.369 -    int ret;
   5.370 +    //SDL_DFB_DEVICEDATA(_this);
   5.371  
   5.372      SDL_KeyboardQuit();
   5.373  
     6.1 --- a/src/video/directfb/SDL_DirectFB_modes.c	Sat Aug 14 12:28:43 2010 -0700
     6.2 +++ b/src/video/directfb/SDL_DirectFB_modes.c	Mon Aug 16 09:04:55 2010 -0700
     6.3 @@ -40,112 +40,101 @@
     6.4      SDL_DisplayMode *modelist;
     6.5  };
     6.6  
     6.7 -static int
     6.8 -DFBToSDLPixelFormat(DFBSurfacePixelFormat pixelformat, Uint32 * fmt)
     6.9 +static const struct {
    6.10 +    DFBSurfacePixelFormat dfb;
    6.11 +    Uint32 sdl;
    6.12 +} pixelformat_tab[] = 
    6.13  {
    6.14 -    switch (pixelformat) {
    6.15 -    case DSPF_ALUT44:
    6.16 -        *fmt = SDL_PIXELFORMAT_INDEX4LSB;
    6.17 -        break;
    6.18 -    case DSPF_LUT8:
    6.19 -        *fmt = SDL_PIXELFORMAT_INDEX8;
    6.20 -        break;
    6.21 -    case DSPF_RGB332:
    6.22 -        *fmt = SDL_PIXELFORMAT_RGB332;
    6.23 -        break;
    6.24 -    case DSPF_ARGB4444:
    6.25 -        *fmt = SDL_PIXELFORMAT_ARGB4444;
    6.26 -        break;
    6.27 -    case SDL_PIXELFORMAT_ARGB1555:
    6.28 -        *fmt = SDL_PIXELFORMAT_ARGB1555;
    6.29 -        break;
    6.30 -    case DSPF_RGB16:
    6.31 -        *fmt = SDL_PIXELFORMAT_RGB565;
    6.32 -        break;
    6.33 -    case DSPF_RGB24:
    6.34 -        *fmt = SDL_PIXELFORMAT_RGB24;
    6.35 -        break;
    6.36 -    case DSPF_RGB32:
    6.37 -        *fmt = SDL_PIXELFORMAT_RGB888;
    6.38 -        break;
    6.39 -    case DSPF_ARGB:
    6.40 -        *fmt = SDL_PIXELFORMAT_ARGB8888;
    6.41 -        break;
    6.42 -    case DSPF_YV12:
    6.43 -        *fmt = SDL_PIXELFORMAT_YV12;
    6.44 -        break;                  /* Planar mode: Y + V + U  (3 planes) */
    6.45 -    case DSPF_I420:
    6.46 -        *fmt = SDL_PIXELFORMAT_IYUV;
    6.47 -        break;                  /* Planar mode: Y + U + V  (3 planes) */
    6.48 -    case DSPF_YUY2:
    6.49 -        *fmt = SDL_PIXELFORMAT_YUY2;
    6.50 -        break;                  /* Packed mode: Y0+U0+Y1+V0 (1 plane) */
    6.51 -    case DSPF_UYVY:
    6.52 -        *fmt = SDL_PIXELFORMAT_UYVY;
    6.53 -        break;                  /* Packed mode: U0+Y0+V0+Y1 (1 plane) */
    6.54 -    default:
    6.55 -        return -1;
    6.56 -    }
    6.57 -    return 0;
    6.58 +    { DSPF_LUT8, SDL_PIXELFORMAT_INDEX8 },              /* 8 bit LUT (8 bit color and alpha lookup from palette) */
    6.59 +    { DSPF_RGB332, SDL_PIXELFORMAT_RGB332 },            /* 8 bit RGB (1 byte, red 3@5, green 3@2, blue 2@0) */
    6.60 +    { DSPF_ARGB4444, SDL_PIXELFORMAT_ARGB4444 },        /* 16 bit ARGB (2 byte, alpha 4@12, red 4@8, green 4@4, blue 4@0) */
    6.61 +    { DSPF_ARGB1555, SDL_PIXELFORMAT_ARGB1555 },        /* 16 bit ARGB (2 byte, alpha 1@15, red 5@10, green 5@5, blue 5@0) */
    6.62 +    { DSPF_RGB16, SDL_PIXELFORMAT_RGB565 },             /* 16 bit RGB (2 byte, red 5@11, green 6@5, blue 5@0) */
    6.63 +    { DSPF_RGB24, SDL_PIXELFORMAT_RGB24 },              /* 24 bit RGB (3 byte, red 8@16, green 8@8, blue 8@0) */
    6.64 +    { DSPF_RGB32, SDL_PIXELFORMAT_RGB888 },             /* 24 bit RGB (4 byte, nothing@24, red 8@16, green 8@8, blue 8@0) */
    6.65 +    { DSPF_ARGB, SDL_PIXELFORMAT_ARGB8888 },            /* 32 bit ARGB (4 byte, alpha 8@24, red 8@16, green 8@8, blue 8@0) */
    6.66 +    { DSPF_RGB444, SDL_PIXELFORMAT_RGB444 },            /* 16 bit RGB (2 byte, nothing @12, red 4@8, green 4@4, blue 4@0) */
    6.67 +    { DSPF_YV12, SDL_PIXELFORMAT_YV12 },                /* 12 bit YUV (8 bit Y plane followed by 8 bit quarter size V/U planes) */
    6.68 +    { DSPF_I420,SDL_PIXELFORMAT_IYUV },                 /* 12 bit YUV (8 bit Y plane followed by 8 bit quarter size U/V planes) */
    6.69 +    { DSPF_YUY2, SDL_PIXELFORMAT_YUY2 },                /* 16 bit YUV (4 byte/ 2 pixel, macropixel contains CbYCrY [31:0]) */
    6.70 +    { DSPF_UYVY, SDL_PIXELFORMAT_UYVY },                /* 16 bit YUV (4 byte/ 2 pixel, macropixel contains YCbYCr [31:0]) */
    6.71 +    { DSPF_RGB555, SDL_PIXELFORMAT_RGB555 },            /* 16 bit RGB (2 byte, nothing @15, red 5@10, green 5@5, blue 5@0) */
    6.72 +
    6.73 +#if (DFB_VERSION_ATLEAST(1,2,0))
    6.74 +    { DSPF_BGR555, SDL_PIXELFORMAT_BGR555 },            /* 16 bit BGR (2 byte, nothing @15, blue 5@10, green 5@5, red 5@0) */
    6.75 +#else
    6.76 +    { DSPF_UNKNOWN, SDL_PIXELFORMAT_BGR555 },
    6.77 +#endif
    6.78 +
    6.79 +    /* Pfff ... nonmatching formats follow */    
    6.80 +    
    6.81 +    { DSPF_ALUT44, SDL_PIXELFORMAT_UNKNOWN },           /* 8 bit ALUT (1 byte, alpha 4@4, color lookup 4@0) */
    6.82 + 	{ DSPF_A8, SDL_PIXELFORMAT_UNKNOWN },               /* 	8 bit alpha (1 byte, alpha 8@0), e.g. anti-aliased glyphs */
    6.83 + 	{ DSPF_AiRGB, SDL_PIXELFORMAT_UNKNOWN },            /* 	32 bit ARGB (4 byte, inv. alpha 8@24, red 8@16, green 8@8, blue 8@0) */
    6.84 + 	{ DSPF_A1, SDL_PIXELFORMAT_UNKNOWN },               /* 	1 bit alpha (1 byte/ 8 pixel, most significant bit used first) */
    6.85 + 	{ DSPF_NV12, SDL_PIXELFORMAT_UNKNOWN },             /* 	12 bit YUV (8 bit Y plane followed by one 16 bit quarter size CbCr [15:0] plane) */
    6.86 + 	{ DSPF_NV16, SDL_PIXELFORMAT_UNKNOWN },             /* 	16 bit YUV (8 bit Y plane followed by one 16 bit half width CbCr [15:0] plane) */
    6.87 + 	{ DSPF_ARGB2554, SDL_PIXELFORMAT_UNKNOWN },         /* 	16 bit ARGB (2 byte, alpha 2@14, red 5@9, green 5@4, blue 4@0) */
    6.88 + 	{ DSPF_NV21, SDL_PIXELFORMAT_UNKNOWN },             /* 	12 bit YUV (8 bit Y plane followed by one 16 bit quarter size CrCb [15:0] plane) */
    6.89 + 	{ DSPF_AYUV, SDL_PIXELFORMAT_UNKNOWN },             /* 	32 bit AYUV (4 byte, alpha 8@24, Y 8@16, Cb 8@8, Cr 8@0) */
    6.90 + 	{ DSPF_A4, SDL_PIXELFORMAT_UNKNOWN },               /* 	4 bit alpha (1 byte/ 2 pixel, more significant nibble used first) */
    6.91 + 	{ DSPF_ARGB1666, SDL_PIXELFORMAT_UNKNOWN },         /* 	1 bit alpha (3 byte/ alpha 1@18, red 6@16, green 6@6, blue 6@0) */
    6.92 + 	{ DSPF_ARGB6666, SDL_PIXELFORMAT_UNKNOWN },         /* 	6 bit alpha (3 byte/ alpha 6@18, red 6@16, green 6@6, blue 6@0) */
    6.93 + 	{ DSPF_RGB18, SDL_PIXELFORMAT_UNKNOWN },            /* 	6 bit RGB (3 byte/ red 6@16, green 6@6, blue 6@0) */
    6.94 + 	{ DSPF_LUT2, SDL_PIXELFORMAT_UNKNOWN },             /* 	2 bit LUT (1 byte/ 4 pixel, 2 bit color and alpha lookup from palette) */
    6.95 +
    6.96 +#if (DFB_VERSION_ATLEAST(1,3,0))
    6.97 + 	{ DSPF_RGBA4444, SDL_PIXELFORMAT_UNKNOWN },         /* 16 bit RGBA (2 byte, red 4@12, green 4@8, blue 4@4, alpha 4@0) */
    6.98 +#endif
    6.99 +
   6.100 +#if (DFB_VERSION_ATLEAST(1,4,0))
   6.101 + 	{ DSPF_RGBA5551, SDL_PIXELFORMAT_UNKNOWN },         /* 	16 bit RGBA (2 byte, red 5@11, green 5@6, blue 5@1, alpha 1@0) */
   6.102 + 	{ DSPF_YUV444P, SDL_PIXELFORMAT_UNKNOWN },          /* 	24 bit full YUV planar (8 bit Y plane followed by an 8 bit Cb and an 8 bit Cr plane) */
   6.103 + 	{ DSPF_ARGB8565, SDL_PIXELFORMAT_UNKNOWN },         /* 	24 bit ARGB (3 byte, alpha 8@16, red 5@11, green 6@5, blue 5@0) */
   6.104 + 	{ DSPF_AVYU, SDL_PIXELFORMAT_UNKNOWN },             /* 	32 bit AVYU 4:4:4 (4 byte, alpha 8@24, Cr 8@16, Y 8@8, Cb 8@0) */
   6.105 + 	{ DSPF_VYU, SDL_PIXELFORMAT_UNKNOWN },              /* 	24 bit VYU 4:4:4 (3 byte, Cr 8@16, Y 8@8, Cb 8@0)  */
   6.106 +#endif
   6.107 + 	
   6.108 +    { DSPF_UNKNOWN, SDL_PIXELFORMAT_INDEX1LSB },
   6.109 +    { DSPF_UNKNOWN, SDL_PIXELFORMAT_INDEX1MSB },
   6.110 +    { DSPF_UNKNOWN, SDL_PIXELFORMAT_INDEX4LSB }, 
   6.111 +    { DSPF_UNKNOWN, SDL_PIXELFORMAT_INDEX4MSB },
   6.112 +    { DSPF_UNKNOWN, SDL_PIXELFORMAT_BGR24 },
   6.113 +    { DSPF_UNKNOWN, SDL_PIXELFORMAT_BGR888 },
   6.114 +    { DSPF_UNKNOWN, SDL_PIXELFORMAT_RGBA8888 },
   6.115 +    { DSPF_UNKNOWN, SDL_PIXELFORMAT_ABGR8888 },
   6.116 +    { DSPF_UNKNOWN, SDL_PIXELFORMAT_BGRA8888 },
   6.117 +    { DSPF_UNKNOWN, SDL_PIXELFORMAT_ARGB2101010 },
   6.118 +    { DSPF_UNKNOWN, SDL_PIXELFORMAT_ABGR4444 },
   6.119 +    { DSPF_UNKNOWN, SDL_PIXELFORMAT_ABGR1555 },
   6.120 +    { DSPF_UNKNOWN, SDL_PIXELFORMAT_BGR565 },
   6.121 +    { DSPF_UNKNOWN, SDL_PIXELFORMAT_YVYU },                        /**< Packed mode: Y0+V0+Y1+U0 (1 pla	*/
   6.122 +};
   6.123 +
   6.124 +static Uint32
   6.125 +DFBToSDLPixelFormat(DFBSurfacePixelFormat pixelformat)
   6.126 +{
   6.127 +    int i;
   6.128 +    
   6.129 +    for (i=0; pixelformat_tab[i].dfb != DSPF_UNKNOWN; i++)
   6.130 +        if (pixelformat_tab[i].dfb == pixelformat)
   6.131 +        {
   6.132 +            return pixelformat_tab[i].sdl;
   6.133 +        }
   6.134 +    return SDL_PIXELFORMAT_UNKNOWN;
   6.135  }
   6.136  
   6.137  static DFBSurfacePixelFormat
   6.138  SDLToDFBPixelFormat(Uint32 format)
   6.139  {
   6.140 -    switch (format) {
   6.141 -    case SDL_PIXELFORMAT_INDEX4LSB:
   6.142 -        return DSPF_ALUT44;
   6.143 -    case SDL_PIXELFORMAT_INDEX8:
   6.144 -        return DSPF_LUT8;
   6.145 -    case SDL_PIXELFORMAT_RGB332:
   6.146 -        return DSPF_RGB332;
   6.147 -    case SDL_PIXELFORMAT_RGB555:
   6.148 -        return DSPF_ARGB1555;
   6.149 -    case SDL_PIXELFORMAT_ARGB4444:
   6.150 -        return DSPF_ARGB4444;
   6.151 -    case SDL_PIXELFORMAT_ARGB1555:
   6.152 -        return DSPF_ARGB1555;
   6.153 -    case SDL_PIXELFORMAT_RGB565:
   6.154 -        return DSPF_RGB16;
   6.155 -    case SDL_PIXELFORMAT_RGB24:
   6.156 -        return DSPF_RGB24;
   6.157 -    case SDL_PIXELFORMAT_RGB888:
   6.158 -        return DSPF_RGB32;
   6.159 -    case SDL_PIXELFORMAT_ARGB8888:
   6.160 -        return DSPF_ARGB;
   6.161 -    case SDL_PIXELFORMAT_YV12:
   6.162 -        return DSPF_YV12;       /* Planar mode: Y + V + U  (3 planes) */
   6.163 -    case SDL_PIXELFORMAT_IYUV:
   6.164 -        return DSPF_I420;       /* Planar mode: Y + U + V  (3 planes) */
   6.165 -    case SDL_PIXELFORMAT_YUY2:
   6.166 -        return DSPF_YUY2;       /* Packed mode: Y0+U0+Y1+V0 (1 plane) */
   6.167 -    case SDL_PIXELFORMAT_UYVY:
   6.168 -        return DSPF_UYVY;       /* Packed mode: U0+Y0+V0+Y1 (1 plane) */
   6.169 -    case SDL_PIXELFORMAT_YVYU:
   6.170 -        return DSPF_UNKNOWN;    /* Packed mode: Y0+V0+Y1+U0 (1 plane) */
   6.171 -    case SDL_PIXELFORMAT_INDEX1LSB:
   6.172 -        return DSPF_UNKNOWN;
   6.173 -    case SDL_PIXELFORMAT_INDEX1MSB:
   6.174 -        return DSPF_UNKNOWN;
   6.175 -    case SDL_PIXELFORMAT_INDEX4MSB:
   6.176 -        return DSPF_UNKNOWN;
   6.177 -    case SDL_PIXELFORMAT_RGB444:
   6.178 -        return DSPF_UNKNOWN;
   6.179 -    case SDL_PIXELFORMAT_BGR24:
   6.180 -        return DSPF_UNKNOWN;
   6.181 -    case SDL_PIXELFORMAT_BGR888:
   6.182 -        return DSPF_UNKNOWN;
   6.183 -    case SDL_PIXELFORMAT_RGBA8888:
   6.184 -        return DSPF_UNKNOWN;
   6.185 -    case SDL_PIXELFORMAT_ABGR8888:
   6.186 -        return DSPF_UNKNOWN;
   6.187 -    case SDL_PIXELFORMAT_BGRA8888:
   6.188 -        return DSPF_UNKNOWN;
   6.189 -    case SDL_PIXELFORMAT_ARGB2101010:
   6.190 -        return DSPF_UNKNOWN;
   6.191 -    default:
   6.192 -        return DSPF_UNKNOWN;
   6.193 -    }
   6.194 +    int i;
   6.195 +    
   6.196 +    for (i=0; pixelformat_tab[i].dfb != DSPF_UNKNOWN; i++)
   6.197 +        if (pixelformat_tab[i].sdl == format)
   6.198 +        {
   6.199 +            return pixelformat_tab[i].dfb;
   6.200 +        }
   6.201 +    return  DSPF_UNKNOWN;
   6.202  }
   6.203  
   6.204  static DFBEnumerationResult
   6.205 @@ -164,7 +153,6 @@
   6.206          modedata->modelist[modedata->nummodes++] = mode;
   6.207      }
   6.208  
   6.209 -    SDL_DFB_DEBUG("w %d h %d bpp %d\n", width, height, bpp);
   6.210      return DFENUM_OK;
   6.211  }
   6.212  
   6.213 @@ -202,7 +190,6 @@
   6.214      SDL_DFB_DEVICEDATA(_this);
   6.215      DFBDisplayLayerConfig config;
   6.216      DFBDisplayLayerConfigFlags failed;
   6.217 -    int ret;
   6.218  
   6.219      SDL_DFB_CHECKERR(data->layer->SetCooperativeLevel(data->layer,
   6.220                                                        DLSCL_ADMINISTRATIVE));
   6.221 @@ -221,7 +208,7 @@
   6.222      if (failed == 0)
   6.223          SDL_AddDisplayMode(display, mode);
   6.224      else
   6.225 -        SDL_DFB_DEBUG("Mode %d x %d not available: %x\n", mode->w,
   6.226 +        SDL_DFB_ERR("Mode %d x %d not available: %x\n", mode->w,
   6.227                        mode->h, failed);
   6.228  
   6.229      return;
   6.230 @@ -295,19 +282,21 @@
   6.231              dlc.pixelformat = DSPF_ARGB;
   6.232              dlc.options = DLOP_ALPHACHANNEL;
   6.233  
   6.234 -            ret = layer->SetConfiguration(layer, &dlc);
   6.235 -            if (ret) {
   6.236 +            ret = SDL_DFB_CHECK(layer->SetConfiguration(layer, &dlc));
   6.237 +            if (ret != DFB_OK) {
   6.238                  /* try AiRGB if the previous failed */
   6.239                  dlc.pixelformat = DSPF_AiRGB;
   6.240 -                ret = layer->SetConfiguration(layer, &dlc);
   6.241 +                SDL_DFB_CHECKERR(layer->SetConfiguration(layer, &dlc));
   6.242              }
   6.243          }
   6.244  
   6.245          /* Query layer configuration to determine the current mode and pixelformat */
   6.246          dlc.flags = DLCONF_ALL;
   6.247 -        layer->GetConfiguration(layer, &dlc);
   6.248 +        SDL_DFB_CHECKERR(layer->GetConfiguration(layer, &dlc));
   6.249  
   6.250 -        if (DFBToSDLPixelFormat(dlc.pixelformat, &mode.format) != 0) {
   6.251 +        mode.format = DFBToSDLPixelFormat(dlc.pixelformat);
   6.252 +        
   6.253 +        if (mode.format == SDL_PIXELFORMAT_UNKNOWN) {
   6.254              SDL_DFB_ERR("Unknown dfb pixelformat %x !\n", dlc.pixelformat);
   6.255              goto error;
   6.256          }
   6.257 @@ -363,7 +352,6 @@
   6.258      SDL_DisplayMode mode;
   6.259      struct modes_callback_t data;
   6.260      int i;
   6.261 -    int ret;
   6.262  
   6.263      data.nummodes = 0;
   6.264      /* Enumerate the available fullscreen modes */
   6.265 @@ -403,7 +391,6 @@
   6.266      DFB_DisplayData *data = (DFB_DisplayData *) display->driverdata;
   6.267      DFBDisplayLayerConfig config, rconfig;
   6.268      DFBDisplayLayerConfigFlags fail = 0;
   6.269 -    DFBResult ret;
   6.270  
   6.271      SDL_DFB_CHECKERR(data->layer->SetCooperativeLevel(data->layer,
   6.272                                                        DLSCL_ADMINISTRATIVE));
   6.273 @@ -469,7 +456,6 @@
   6.274  {
   6.275      //DFB_DeviceData *devdata = (DFB_DeviceData *) _this->driverdata;
   6.276      SDL_DisplayMode tmode;
   6.277 -    DFBResult ret;
   6.278      int i;
   6.279  
   6.280      for (i = 0; i < _this->num_displays; ++i) {
     7.1 --- a/src/video/directfb/SDL_DirectFB_mouse.c	Sat Aug 14 12:28:43 2010 -0700
     7.2 +++ b/src/video/directfb/SDL_DirectFB_mouse.c	Mon Aug 16 09:04:55 2010 -0700
     7.3 @@ -253,7 +253,7 @@
     7.4  void
     7.5  DirectFB_QuitMouse(_THIS)
     7.6  {
     7.7 -    SDL_DFB_DEVICEDATA(_this);
     7.8 +    //SDL_DFB_DEVICEDATA(_this);
     7.9  }
    7.10  
    7.11  
     8.1 --- a/src/video/directfb/SDL_DirectFB_opengl.c	Sat Aug 14 12:28:43 2010 -0700
     8.2 +++ b/src/video/directfb/SDL_DirectFB_opengl.c	Mon Aug 16 09:04:55 2010 -0700
     8.3 @@ -30,6 +30,10 @@
     8.4      int gl_active;              /* to stop switching drivers while we have a valid context */
     8.5      int initialized;
     8.6      DirectFB_GLContext *firstgl;        /* linked list */
     8.7 +    
     8.8 +    /* OpenGL */
     8.9 +    void (*glFinish) (void);
    8.10 +    void (*glFlush) (void);
    8.11  };
    8.12  
    8.13  #define OPENGL_REQUIRS_DLOPEN
    8.14 @@ -94,7 +98,7 @@
    8.15  int
    8.16  DirectFB_GL_LoadLibrary(_THIS, const char *path)
    8.17  {
    8.18 -    SDL_DFB_DEVICEDATA(_this);
    8.19 +    //SDL_DFB_DEVICEDATA(_this);
    8.20  
    8.21      void *handle = NULL;
    8.22  
    8.23 @@ -122,9 +126,6 @@
    8.24  
    8.25      SDL_DFB_DEBUG("Loaded library: %s\n", path);
    8.26  
    8.27 -    /* Unload the old driver and reset the pointers */
    8.28 -    DirectFB_GL_UnloadLibrary(_this);
    8.29 -
    8.30      _this->gl_config.dll_handle = handle;
    8.31      _this->gl_config.driver_loaded = 1;
    8.32      if (path) {
    8.33 @@ -134,8 +135,8 @@
    8.34          *_this->gl_config.driver_path = '\0';
    8.35      }
    8.36  
    8.37 -    devdata->glFinish = DirectFB_GL_GetProcAddress(_this, "glFinish");
    8.38 -    devdata->glFlush = DirectFB_GL_GetProcAddress(_this, "glFlush");
    8.39 +    _this->gl_data->glFinish = DirectFB_GL_GetProcAddress(_this, "glFinish");
    8.40 +    _this->gl_data->glFlush = DirectFB_GL_GetProcAddress(_this, "glFlush");
    8.41  
    8.42      return 0;
    8.43  }
    8.44 @@ -143,6 +144,7 @@
    8.45  static void
    8.46  DirectFB_GL_UnloadLibrary(_THIS)
    8.47  {
    8.48 + #if 0
    8.49      int ret;
    8.50  
    8.51      if (_this->gl_config.driver_loaded) {
    8.52 @@ -153,6 +155,10 @@
    8.53          _this->gl_config.dll_handle = NULL;
    8.54          _this->gl_config.driver_loaded = 0;
    8.55      }
    8.56 +#endif
    8.57 +    /* Free OpenGL memory */
    8.58 +    SDL_free(_this->gl_data);
    8.59 +    _this->gl_data = NULL;
    8.60  }
    8.61  
    8.62  void *
    8.63 @@ -167,11 +173,11 @@
    8.64  SDL_GLContext
    8.65  DirectFB_GL_CreateContext(_THIS, SDL_Window * window)
    8.66  {
    8.67 +    //SDL_DFB_DEVICEDATA(_this);
    8.68      SDL_DFB_WINDOWDATA(window);
    8.69      DirectFB_GLContext *context;
    8.70 -    int ret;
    8.71  
    8.72 -    SDL_DFB_CALLOC(context, 1, sizeof(*context));
    8.73 +    SDL_DFB_CALLOC(context, 1, sizeof(DirectFB_GLContext));
    8.74  
    8.75      SDL_DFB_CHECKERR(windata->surface->GetGL(windata->surface,
    8.76                                               &context->context));
    8.77 @@ -179,11 +185,14 @@
    8.78      if (!context->context)
    8.79          return NULL;
    8.80  
    8.81 -    SDL_DFB_CHECKERR(context->context->Unlock(context->context));
    8.82 -
    8.83 +    context->is_locked = 0;
    8.84 +    context->sdl_window = window;
    8.85 +    
    8.86      context->next = _this->gl_data->firstgl;
    8.87      _this->gl_data->firstgl = context;
    8.88  
    8.89 +    SDL_DFB_CHECK(context->context->Unlock(context->context));
    8.90 +
    8.91      if (DirectFB_GL_MakeCurrent(_this, window, context) < 0) {
    8.92          DirectFB_GL_DeleteContext(_this, context);
    8.93          return NULL;
    8.94 @@ -198,28 +207,24 @@
    8.95  int
    8.96  DirectFB_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
    8.97  {
    8.98 -    SDL_DFB_WINDOWDATA(window);
    8.99 +    //SDL_DFB_WINDOWDATA(window);
   8.100      DirectFB_GLContext *ctx = (DirectFB_GLContext *) context;
   8.101      DirectFB_GLContext *p;
   8.102  
   8.103 -    int ret;
   8.104 -
   8.105      for (p = _this->gl_data->firstgl; p; p = p->next)
   8.106 -        p->context->Unlock(p->context);
   8.107 -
   8.108 -    if (windata) {
   8.109 -        windata->gl_context = NULL;
   8.110 -        /* Everything is unlocked, check for a resize */
   8.111 -        DirectFB_AdjustWindowSurface(window);
   8.112 +    {
   8.113 +       if (p->is_locked) {
   8.114 +         SDL_DFB_CHECKERR(p->context->Unlock(p->context));
   8.115 +         p->is_locked = 0;
   8.116 +       }
   8.117 +        
   8.118      }
   8.119  
   8.120      if (ctx != NULL) {
   8.121          SDL_DFB_CHECKERR(ctx->context->Lock(ctx->context));
   8.122 +        ctx->is_locked = 1;
   8.123      }
   8.124  
   8.125 -    if (windata)
   8.126 -        windata->gl_context = ctx;
   8.127 -
   8.128      return 0;
   8.129    error:
   8.130      return -1;
   8.131 @@ -242,28 +247,36 @@
   8.132  void
   8.133  DirectFB_GL_SwapWindow(_THIS, SDL_Window * window)
   8.134  {
   8.135 -    SDL_DFB_DEVICEDATA(_this);
   8.136 +    //SDL_DFB_DEVICEDATA(_this);
   8.137      SDL_DFB_WINDOWDATA(window);
   8.138 -    int ret;
   8.139      DFBRegion region;
   8.140 +    DirectFB_GLContext *p;
   8.141  
   8.142      region.x1 = 0;
   8.143      region.y1 = 0;
   8.144      region.x2 = window->w;
   8.145      region.y2 = window->h;
   8.146  
   8.147 +#if 0
   8.148      if (devdata->glFinish)
   8.149          devdata->glFinish();
   8.150      else if (devdata->glFlush)
   8.151          devdata->glFlush();
   8.152 +#endif
   8.153  
   8.154 -    if (1 || windata->gl_context) {
   8.155 -        /* SDL_DFB_CHECKERR(windata->gl_context->context->Unlock(windata->gl_context->context)); */
   8.156 -        SDL_DFB_CHECKERR(windata->surface->Flip(windata->surface, &region,
   8.157 -                                                DSFLIP_ONSYNC));
   8.158 -        /* SDL_DFB_CHECKERR(windata->gl_context->context->Lock(windata->gl_context->context)); */
   8.159 +  	for (p = _this->gl_data->firstgl; p != NULL; p = p->next)
   8.160 +        if (p->sdl_window == window && p->is_locked)
   8.161 +        {
   8.162 +            SDL_DFB_CHECKERR(p->context->Unlock(p->context));
   8.163 +            p->is_locked = 0;
   8.164 +        }            
   8.165  
   8.166 -    }
   8.167 +    SDL_DFB_CHECKERR(windata->window_surface->Flip(windata->window_surface,NULL,  DSFLIP_PIPELINE |DSFLIP_BLIT | DSFLIP_ONSYNC ));
   8.168 +
   8.169 +    //if (windata->gl_context) {
   8.170 +        //SDL_DFB_CHECKERR(windata->surface->Flip(windata->surface,NULL, DSFLIP_ONSYNC)); 
   8.171 +        //SDL_DFB_CHECKERR(windata->gl_context->context->Lock(windata->gl_context->context));
   8.172 +    //}
   8.173  
   8.174      return;
   8.175    error:
   8.176 @@ -276,19 +289,58 @@
   8.177      DirectFB_GLContext *ctx = (DirectFB_GLContext *) context;
   8.178      DirectFB_GLContext *p;
   8.179  
   8.180 -    ctx->context->Unlock(ctx->context);
   8.181 -    ctx->context->Release(ctx->context);
   8.182 +    if (ctx->is_locked)
   8.183 +        SDL_DFB_CHECK(ctx->context->Unlock(ctx->context));
   8.184 +    SDL_DFB_RELEASE(ctx->context);
   8.185  
   8.186 -    p = _this->gl_data->firstgl;
   8.187 -    while (p && p->next != ctx)
   8.188 -        p = p->next;
   8.189 +    for (p = _this->gl_data->firstgl; p && p->next != ctx; p = p->next)
   8.190 +        ;
   8.191      if (p)
   8.192          p->next = ctx->next;
   8.193      else
   8.194          _this->gl_data->firstgl = ctx->next;
   8.195  
   8.196      SDL_DFB_FREE(ctx);
   8.197 +}
   8.198  
   8.199 +void
   8.200 +DirectFB_GL_FreeWindowContexts(_THIS, SDL_Window * window)
   8.201 +{
   8.202 +    DirectFB_GLContext *p;
   8.203 +    
   8.204 +	for (p = _this->gl_data->firstgl; p != NULL; p = p->next)
   8.205 +	    if (p->sdl_window == window)
   8.206 +	    {
   8.207 +	    	if (p->is_locked)
   8.208 +	        	SDL_DFB_CHECK(p->context->Unlock(p->context));
   8.209 +	        SDL_DFB_RELEASE(p->context);
   8.210 +	    }
   8.211 +}
   8.212 +
   8.213 +void
   8.214 +DirectFB_GL_ReAllocWindowContexts(_THIS, SDL_Window * window)
   8.215 +{
   8.216 +    DirectFB_GLContext *p;
   8.217 +
   8.218 +	for (p = _this->gl_data->firstgl; p != NULL; p = p->next)
   8.219 +	    if (p->sdl_window == window)
   8.220 +	    {
   8.221 +            SDL_DFB_WINDOWDATA(window);
   8.222 +			SDL_DFB_CHECK(windata->surface->GetGL(windata->surface,
   8.223 +	                                         &p->context));
   8.224 +    		if (p->is_locked)
   8.225 +            	SDL_DFB_CHECK(p->context->Lock(p->context));
   8.226 +	        }
   8.227 +}
   8.228 +
   8.229 +void
   8.230 +DirectFB_GL_DestroyWindowContexts(_THIS, SDL_Window * window)
   8.231 +{
   8.232 +    DirectFB_GLContext *p;
   8.233 +
   8.234 +	for (p = _this->gl_data->firstgl; p != NULL; p = p->next)
   8.235 +		if (p->sdl_window == window)
   8.236 +			DirectFB_GL_DeleteContext(_this, p);
   8.237  }
   8.238  
   8.239  #endif
     9.1 --- a/src/video/directfb/SDL_DirectFB_opengl.h	Sat Aug 14 12:28:43 2010 -0700
     9.2 +++ b/src/video/directfb/SDL_DirectFB_opengl.h	Mon Aug 16 09:04:55 2010 -0700
     9.3 @@ -32,6 +32,9 @@
     9.4  {
     9.5      IDirectFBGL *context;
     9.6      DirectFB_GLContext *next;
     9.7 +    
     9.8 +    SDL_Window *sdl_window;
     9.9 +    int is_locked;
    9.10  };
    9.11  
    9.12  /* OpenGL functions */
    9.13 @@ -48,6 +51,10 @@
    9.14  extern void DirectFB_GL_SwapWindow(_THIS, SDL_Window * window);
    9.15  extern void DirectFB_GL_DeleteContext(_THIS, SDL_GLContext context);
    9.16  
    9.17 +extern void DirectFB_GL_FreeWindowContexts(_THIS, SDL_Window * window);
    9.18 +extern void DirectFB_GL_ReAllocWindowContexts(_THIS, SDL_Window * window);
    9.19 +extern void DirectFB_GL_DestroyWindowContexts(_THIS, SDL_Window * window);
    9.20 +
    9.21  #endif /* SDL_DIRECTFB_OPENGL */
    9.22  
    9.23  #endif /* _SDL_directfb_opengl_h */
    10.1 --- a/src/video/directfb/SDL_DirectFB_render.c	Sat Aug 14 12:28:43 2010 -0700
    10.2 +++ b/src/video/directfb/SDL_DirectFB_render.c	Mon Aug 16 09:04:55 2010 -0700
    10.3 @@ -72,6 +72,7 @@
    10.4  static void DirectFB_DirtyTexture(SDL_Renderer * renderer,
    10.5                                    SDL_Texture * texture, int numrects,
    10.6                                    const SDL_Rect * rects);
    10.7 +static int DirectFB_SetDrawBlendMode(SDL_Renderer * renderer);
    10.8  static int DirectFB_RenderDrawPoints(SDL_Renderer * renderer,
    10.9                                  const SDL_Point * points, int count);
   10.10  static int DirectFB_RenderDrawLines(SDL_Renderer * renderer,
   10.11 @@ -194,20 +195,20 @@
   10.12                                             /**< No blending */
   10.13              data->blitFlags = DSBLIT_NOFX;
   10.14              data->drawFlags = DSDRAW_NOFX;
   10.15 -            destsurf->SetSrcBlendFunction(destsurf, DSBF_ONE);
   10.16 -            destsurf->SetDstBlendFunction(destsurf, DSBF_ZERO);
   10.17 +            SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_ONE));
   10.18 +            SDL_DFB_CHECK(destsurf->SetDstBlendFunction(destsurf, DSBF_ZERO));
   10.19              break;
   10.20          case SDL_BLENDMODE_MASK:
   10.21              data->blitFlags = DSBLIT_BLEND_ALPHACHANNEL;
   10.22              data->drawFlags = DSDRAW_BLEND;
   10.23 -            destsurf->SetSrcBlendFunction(destsurf, DSBF_SRCALPHA);
   10.24 -            destsurf->SetDstBlendFunction(destsurf, DSBF_INVSRCALPHA);
   10.25 +            SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_SRCALPHA));
   10.26 +            SDL_DFB_CHECK(destsurf->SetDstBlendFunction(destsurf, DSBF_INVSRCALPHA));
   10.27              break;
   10.28          case SDL_BLENDMODE_BLEND:
   10.29              data->blitFlags = DSBLIT_BLEND_ALPHACHANNEL;
   10.30              data->drawFlags = DSDRAW_BLEND;
   10.31 -            destsurf->SetSrcBlendFunction(destsurf, DSBF_SRCALPHA);
   10.32 -            destsurf->SetDstBlendFunction(destsurf, DSBF_INVSRCALPHA);
   10.33 +            SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_SRCALPHA));
   10.34 +            SDL_DFB_CHECK(destsurf->SetDstBlendFunction(destsurf, DSBF_INVSRCALPHA));
   10.35              break;
   10.36          case SDL_BLENDMODE_ADD:
   10.37              data->blitFlags = DSBLIT_BLEND_ALPHACHANNEL;
   10.38 @@ -216,16 +217,16 @@
   10.39              // It will be cheaper to copy the surface to
   10.40              // a temporay surface and premultiply 
   10.41              if (source && TextureHasAlpha(source))
   10.42 -                destsurf->SetSrcBlendFunction(destsurf, DSBF_SRCALPHA);
   10.43 +                SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_SRCALPHA));
   10.44              else
   10.45 -                destsurf->SetSrcBlendFunction(destsurf, DSBF_ONE);
   10.46 -            destsurf->SetDstBlendFunction(destsurf, DSBF_ONE);
   10.47 +                SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_ONE));
   10.48 +            SDL_DFB_CHECK(destsurf->SetDstBlendFunction(destsurf, DSBF_ONE));
   10.49              break;
   10.50          case SDL_BLENDMODE_MOD:
   10.51              data->blitFlags = DSBLIT_BLEND_ALPHACHANNEL;
   10.52              data->drawFlags = DSDRAW_BLEND;
   10.53 -            destsurf->SetSrcBlendFunction(destsurf, DSBF_DESTCOLOR);
   10.54 -            destsurf->SetDstBlendFunction(destsurf, DSBF_ZERO);
   10.55 +            SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_DESTCOLOR));
   10.56 +            SDL_DFB_CHECK(destsurf->SetDstBlendFunction(destsurf, DSBF_ZERO));
   10.57              break;
   10.58          }
   10.59          data->lastBlendMode = blendMode;
   10.60 @@ -250,7 +251,6 @@
   10.61      SDL_DFB_WINDOWSURFACE(data->window);
   10.62      IDirectFBPalette *surfpal;
   10.63  
   10.64 -    int ret;
   10.65      int i;
   10.66      int ncolors;
   10.67      DFBColor entries[256];
   10.68 @@ -283,7 +283,6 @@
   10.69      SDL_VideoDisplay *display = window->display;
   10.70      SDL_Renderer *renderer = NULL;
   10.71      DirectFB_RenderData *data = NULL;
   10.72 -    DFBResult ret;
   10.73      DFBSurfaceCapabilities scaps;
   10.74      char *p;
   10.75  
   10.76 @@ -306,10 +305,16 @@
   10.77      renderer->DirtyTexture = DirectFB_DirtyTexture;
   10.78      renderer->RenderDrawPoints = DirectFB_RenderDrawPoints;
   10.79      renderer->RenderDrawLines = DirectFB_RenderDrawLines;
   10.80 +    /* SetDrawColor - no needed */
   10.81 +    renderer->SetDrawBlendMode = DirectFB_SetDrawBlendMode;
   10.82      renderer->RenderFillRects = DirectFB_RenderFillRects;
   10.83      renderer->RenderDrawRects = DirectFB_RenderDrawRects;
   10.84 +    /* RenderDrawEllipse - no reference implementation yet */
   10.85 +    /* RenderFillEllipse - no reference implementation yet */
   10.86      renderer->RenderCopy = DirectFB_RenderCopy;
   10.87      renderer->RenderPresent = DirectFB_RenderPresent;
   10.88 +    /* RenderReadPixels is difficult to implement */
   10.89 +    /* RenderWritePixels is difficult to implement */
   10.90      renderer->DestroyTexture = DirectFB_DestroyTexture;
   10.91      renderer->DestroyRenderer = DirectFB_DestroyRenderer;
   10.92      renderer->info = DirectFB_RenderDriver.info;
   10.93 @@ -324,7 +329,7 @@
   10.94      data->flipflags = DSFLIP_PIPELINE | DSFLIP_BLIT;
   10.95  
   10.96      if (flags & SDL_RENDERER_PRESENTVSYNC) {
   10.97 -        data->flipflags |= DSFLIP_WAITFORSYNC;
   10.98 +        data->flipflags |= DSFLIP_WAITFORSYNC | DSFLIP_ONSYNC;
   10.99          renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
  10.100      } else
  10.101          data->flipflags |= DSFLIP_ONSYNC;
  10.102 @@ -396,11 +401,9 @@
  10.103          return DSPF_UNKNOWN;
  10.104      case SDL_PIXELFORMAT_INDEX4MSB:
  10.105          return DSPF_UNKNOWN;
  10.106 +#if (DFB_VERSION_ATLEAST(1,2,0))
  10.107      case SDL_PIXELFORMAT_RGB444:
  10.108 -#if (DFB_VERSION_ATLEAST(1,2,0))
  10.109          return DSPF_RGB444;
  10.110 -#else
  10.111 -        return DSPF_UNKNOWN;
  10.112  #endif
  10.113      case SDL_PIXELFORMAT_BGR24:
  10.114          return DSPF_UNKNOWN;
  10.115 @@ -427,7 +430,7 @@
  10.116      SDL_DFB_WINDOWDATA(window);
  10.117  
  10.118      if (renddata->size_changed || windata->wm_needs_redraw) {
  10.119 -        DirectFB_AdjustWindowSurface(window);
  10.120 +//        DirectFB_AdjustWindowSurface(window);
  10.121      }
  10.122      return 0;
  10.123  }
  10.124 @@ -451,7 +454,7 @@
  10.125      DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
  10.126      DirectFB_TextureData *data = texture->driverdata;
  10.127      DFBDisplayLayerConfig layconf;
  10.128 -    int ret;
  10.129 +    DFBResult ret;
  10.130  
  10.131      if (renddata->isyuvdirect && (dispdata->vidID >= 0)
  10.132          && (!dispdata->vidIDinuse)
  10.133 @@ -472,7 +475,7 @@
  10.134                                                         DLSCL_EXCLUSIVE));
  10.135  
  10.136          if (devdata->use_yuv_underlays) {
  10.137 -            ret = dispdata->vidlayer->SetLevel(dispdata->vidlayer, -1);
  10.138 +            ret = SDL_DFB_CHECK(dispdata->vidlayer->SetLevel(dispdata->vidlayer, -1));
  10.139              if (ret != DFB_OK)
  10.140                  SDL_DFB_DEBUG("Underlay Setlevel not supported\n");
  10.141          }
  10.142 @@ -505,7 +508,6 @@
  10.143      SDL_VideoDisplay *display = window->display;
  10.144      SDL_DFB_DEVICEDATA(display->device);
  10.145      DirectFB_TextureData *data;
  10.146 -    DFBResult ret;
  10.147      DFBSurfaceDescription dsc;
  10.148      DFBSurfacePixelFormat pixelformat;
  10.149  
  10.150 @@ -600,8 +602,7 @@
  10.151                             int ncolors)
  10.152  {
  10.153      DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
  10.154 -    DFBResult ret;
  10.155 -
  10.156 + 
  10.157      if (SDL_ISPIXELFORMAT_INDEXED(data->format)
  10.158          && !SDL_ISPIXELFORMAT_FOURCC(data->format)) {
  10.159          DFBColor entries[256];
  10.160 @@ -631,7 +632,6 @@
  10.161                             int firstcolor, int ncolors)
  10.162  {
  10.163      DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
  10.164 -    DFBResult ret;
  10.165  
  10.166      if (SDL_ISPIXELFORMAT_INDEXED(data->format)
  10.167          && !SDL_ISPIXELFORMAT_FOURCC(data->format)) {
  10.168 @@ -687,6 +687,23 @@
  10.169  }
  10.170  
  10.171  static int
  10.172 +DirectFB_SetDrawBlendMode(SDL_Renderer * renderer)
  10.173 +{
  10.174 +    switch (renderer->blendMode) {
  10.175 +    case SDL_BLENDMODE_NONE:
  10.176 +    case SDL_BLENDMODE_MASK:
  10.177 +    case SDL_BLENDMODE_BLEND:
  10.178 +    case SDL_BLENDMODE_ADD:
  10.179 +    case SDL_BLENDMODE_MOD:
  10.180 +        return 0;
  10.181 +    default:
  10.182 +        SDL_Unsupported();
  10.183 +        renderer->blendMode = SDL_BLENDMODE_NONE;
  10.184 +        return -1;
  10.185 +    }
  10.186 +}
  10.187 +
  10.188 +static int
  10.189  DirectFB_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
  10.190  {
  10.191  #if (DFB_VERSION_ATLEAST(1,2,0))
  10.192 @@ -720,7 +737,6 @@
  10.193                         const SDL_Rect * rect, const void *pixels, int pitch)
  10.194  {
  10.195      DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
  10.196 -    DFBResult ret;
  10.197      Uint8 *dpixels;
  10.198      int dpitch;
  10.199      Uint8 *src, *dst;
  10.200 @@ -772,7 +788,6 @@
  10.201  {
  10.202      DirectFB_TextureData *texturedata =
  10.203          (DirectFB_TextureData *) texture->driverdata;
  10.204 -    DFBResult ret;
  10.205  
  10.206      if (markDirty) {
  10.207          SDL_AddDirtyRect(&texturedata->dirty, rect);
  10.208 @@ -807,7 +822,7 @@
  10.209          (DirectFB_TextureData *) texture->driverdata;
  10.210  
  10.211      if (texturedata->display) {
  10.212 -        texturedata->surface->Unlock(texturedata->surface);
  10.213 +        SDL_DFB_CHECK(texturedata->surface->Unlock(texturedata->surface));
  10.214          texturedata->pixels = NULL;
  10.215      }
  10.216  }
  10.217 @@ -830,7 +845,6 @@
  10.218      DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
  10.219      SDL_DFB_WINDOWSURFACE(data->window);
  10.220  
  10.221 -    DFBResult ret;
  10.222      Uint8 r, g, b, a;
  10.223  
  10.224      r = renderer->r;
  10.225 @@ -866,7 +880,6 @@
  10.226  {
  10.227      DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
  10.228      SDL_DFB_WINDOWSURFACE(data->window);
  10.229 -    DFBResult ret;
  10.230      int i;
  10.231  
  10.232      PrepareDraw(renderer);
  10.233 @@ -882,7 +895,6 @@
  10.234  {
  10.235      DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
  10.236      SDL_DFB_WINDOWSURFACE(data->window);
  10.237 -    DFBResult ret;
  10.238      int i;
  10.239  
  10.240      PrepareDraw(renderer);
  10.241 @@ -904,7 +916,6 @@
  10.242  {
  10.243      DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
  10.244      SDL_DFB_WINDOWSURFACE(data->window);
  10.245 -    DFBResult ret;
  10.246      int i;
  10.247  
  10.248      PrepareDraw(renderer);
  10.249 @@ -923,7 +934,6 @@
  10.250  {
  10.251      DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
  10.252      SDL_DFB_WINDOWSURFACE(data->window);
  10.253 -    DFBResult ret;
  10.254      int i;
  10.255  
  10.256      PrepareDraw(renderer);
  10.257 @@ -946,7 +956,6 @@
  10.258      DirectFB_TextureData *texturedata =
  10.259          (DirectFB_TextureData *) texture->driverdata;
  10.260      Uint8 alpha = 0xFF;
  10.261 -    DFBResult ret;
  10.262  
  10.263      if (texturedata->display) {
  10.264          int px, py;
  10.265 @@ -960,7 +969,7 @@
  10.266                                                        srcrect->x, srcrect->y,
  10.267                                                        srcrect->w,
  10.268                                                        srcrect->h));
  10.269 -        windata->window->GetPosition(windata->window, &px, &py);
  10.270 +        SDL_DFB_CHECK(windata->window->GetPosition(windata->window, &px, &py));
  10.271          px += windata->client.x;
  10.272          py += windata->client.y;
  10.273          SDL_DFB_CHECKERR(dispdata->
  10.274 @@ -1052,7 +1061,6 @@
  10.275      SDL_DFB_WINDOWDATA(window);
  10.276  
  10.277      DFBRectangle sr;
  10.278 -    DFBResult ret;
  10.279  
  10.280      sr.x = 0;
  10.281      sr.y = 0;
  10.282 @@ -1078,8 +1086,9 @@
  10.283          DFB_DisplayData *dispdata =
  10.284              (DFB_DisplayData *) data->display->driverdata;
  10.285          dispdata->vidIDinuse = 0;
  10.286 -        dispdata->vidlayer->SetCooperativeLevel(dispdata->vidlayer,
  10.287 -                                                DLSCL_ADMINISTRATIVE);
  10.288 +        /* FIXME: Shouldn't we reset the cooperative level */
  10.289 +        SDL_DFB_CHECK(dispdata->vidlayer->SetCooperativeLevel(dispdata->vidlayer,
  10.290 +                                                DLSCL_ADMINISTRATIVE));
  10.291          SDL_DFB_RELEASE(dispdata->vidlayer);
  10.292      }
  10.293      SDL_FreeDirtyRects(&data->dirty);
    11.1 --- a/src/video/directfb/SDL_DirectFB_video.c	Sat Aug 14 12:28:43 2010 -0700
    11.2 +++ b/src/video/directfb/SDL_DirectFB_video.c	Mon Aug 16 09:04:55 2010 -0700
    11.3 @@ -209,14 +209,11 @@
    11.4              DirectFBSetOption("disable-module", "x11input");
    11.5      }
    11.6  
    11.7 -#if USE_MULTI_API
    11.8 -	devdata->use_linux_input = 1;       /* default: on */
    11.9 +	/* FIXME: Reenable as default once multi kbd/mouse interface is sorted out */
   11.10 +	devdata->use_linux_input = 0;       /* default: on */
   11.11      stemp = SDL_getenv(DFBENV_USE_LINUX_INPUT);
   11.12      if (stemp)
   11.13          devdata->use_linux_input = atoi(stemp);
   11.14 -#else
   11.15 -	devdata->use_linux_input = 0;       /* no way to support this ... */
   11.16 -#endif
   11.17  
   11.18      if (!devdata->use_linux_input)
   11.19          DirectFBSetOption("disable-module", "linux_input");
   11.20 @@ -253,6 +250,7 @@
   11.21  
   11.22      devdata->dfb = dfb;
   11.23      devdata->firstwin = NULL;
   11.24 +    devdata->grabbed_window = NULL;
   11.25  
   11.26      _this->driverdata = devdata;
   11.27  
    12.1 --- a/src/video/directfb/SDL_DirectFB_video.h	Sat Aug 14 12:28:43 2010 -0700
    12.2 +++ b/src/video/directfb/SDL_DirectFB_video.h	Mon Aug 16 09:04:55 2010 -0700
    12.3 @@ -78,49 +78,38 @@
    12.4  #define DFBENV_USE_LINUX_INPUT		"SDL_DIRECTFB_LINUX_INPUT"      /* Default: on  */
    12.5  #define DFBENV_USE_WM				"SDL_DIRECTFB_WM"       /* Default: off  */
    12.6  
    12.7 -#define SDL_DFB_RELEASE(x) do { if ( (x) != NULL ) { x->Release(x); x = NULL; } } while (0)
    12.8 +#define SDL_DFB_RELEASE(x) do { if ( (x) != NULL ) { SDL_DFB_CHECK(x->Release(x)); x = NULL; } } while (0)
    12.9  #define SDL_DFB_FREE(x) do { if ( (x) != NULL ) { SDL_free(x); x = NULL; } } while (0)
   12.10  #define SDL_DFB_UNLOCK(x) do { if ( (x) != NULL ) { x->Unlock(x); } } while (0)
   12.11  
   12.12  #if DEBUG
   12.13 -#define SDL_DFB_DEBUG(x...) do { fprintf(LOG_CHANNEL, "%s:", __FUNCTION__); fprintf(LOG_CHANNEL, x); } while (0)
   12.14 -#define SDL_DFB_DEBUGC(x...) do { fprintf(LOG_CHANNEL, x); } while (0)
   12.15 -#else
   12.16 -#define SDL_DFB_DEBUG(x...) do { } while (0)
   12.17 -#define SDL_DFB_DEBUGC(x...) do { } while (0)
   12.18 +/* FIXME: do something with DEBUG */
   12.19  #endif
   12.20  
   12.21  #define SDL_DFB_CONTEXT "SDL_DirectFB"
   12.22  
   12.23 -#define SDL_DFB_ERR(x...) 							\
   12.24 +static inline DFBResult sdl_dfb_check(DFBResult ret, const char *src_file, int src_line, const char *src_code) {
   12.25 +	if (ret != DFB_OK) {
   12.26 +		fprintf(LOG_CHANNEL, "%s <%d>:\n\t", src_file, src_line );
   12.27 +		fprintf(LOG_CHANNEL, "\t%s\n", src_code );
   12.28 +		fprintf(LOG_CHANNEL, "\t%s\n", DirectFBErrorString (ret) );
   12.29 +		SDL_SetError( src_code, DirectFBErrorString (ret) );
   12.30 +	}
   12.31 +	return ret;
   12.32 +}
   12.33 +
   12.34 +#define SDL_DFB_CHECK(x...) sdl_dfb_check( x, __FILE__, __LINE__, #x )
   12.35 +
   12.36 +#define SDL_DFB_CHECKERR(x...) if ( sdl_dfb_check( x, __FILE__, __LINE__, #x ) != DFB_OK ) goto error
   12.37 +
   12.38 +#define SDL_DFB_DEBUG(x...) 							\
   12.39  	do {											\
   12.40  		fprintf(LOG_CHANNEL, "%s: %s <%d>:\n\t",			\
   12.41  			SDL_DFB_CONTEXT, __FILE__, __LINE__ );	\
   12.42 -		fprintf(LOG_CHANNEL, x );						\
   12.43 +        fprintf(LOG_CHANNEL, x ); \
   12.44  	} while (0)
   12.45  
   12.46 -#define SDL_DFB_CHECK(x...) \
   12.47 -     do {                                                                \
   12.48 -          ret = x;                                                    \
   12.49 -          if (ret != DFB_OK) {                                        \
   12.50 -               fprintf(LOG_CHANNEL, "%s <%d>:\n\t", __FILE__, __LINE__ ); 	      \
   12.51 -               fprintf(LOG_CHANNEL, "\t%s\n", #x ); \
   12.52 -               fprintf(LOG_CHANNEL, "\t%s\n", DirectFBErrorString (ret) ); \
   12.53 -               SDL_SetError( #x, DirectFBErrorString (ret) );         \
   12.54 -          }                                                           \
   12.55 -     } while (0)
   12.56 -
   12.57 -#define SDL_DFB_CHECKERR(x...) \
   12.58 -     do {                                                                \
   12.59 -          ret = x;                                                    \
   12.60 -          if (ret != DFB_OK) {                                        \
   12.61 -               fprintf(LOG_CHANNEL, "%s <%d>:\n", __FILE__, __LINE__ ); \
   12.62 -               fprintf(LOG_CHANNEL, "\t%s\n", #x ); \
   12.63 -               fprintf(LOG_CHANNEL, "\t%s\n", DirectFBErrorString (ret) ); \
   12.64 -               SDL_SetError( #x, DirectFBErrorString (ret) );         \
   12.65 -               goto error; 					      \
   12.66 -          }                                                           \
   12.67 -     } while (0)
   12.68 +#define SDL_DFB_ERR(x...) SDL_DFB_DEBUG( x )
   12.69  
   12.70  #define SDL_DFB_CALLOC(r, n, s) \
   12.71       do {                                                                \
   12.72 @@ -158,9 +147,8 @@
   12.73      int use_linux_input;
   12.74      int has_own_wm;
   12.75  
   12.76 -    /* OpenGL */
   12.77 -    void (*glFinish) (void);
   12.78 -    void (*glFlush) (void);
   12.79 +	/* window grab */
   12.80 +	SDL_Window *grabbed_window;
   12.81  
   12.82      /* global events */
   12.83      IDirectFBEventBuffer *events;
    13.1 --- a/src/video/directfb/SDL_DirectFB_window.c	Sat Aug 14 12:28:43 2010 -0700
    13.2 +++ b/src/video/directfb/SDL_DirectFB_window.c	Mon Aug 16 09:04:55 2010 -0700
    13.3 @@ -24,9 +24,14 @@
    13.4  #include "SDL_syswm.h"
    13.5  #include "../SDL_sysvideo.h"
    13.6  #include "../../events/SDL_keyboard_c.h"
    13.7 +#include "../../video/SDL_pixels_c.h"
    13.8  
    13.9  #include "SDL_DirectFB_video.h"
   13.10 +#if SDL_DIRECTFB_OPENGL
   13.11 +#include "SDL_DirectFB_opengl.h"
   13.12 +#endif
   13.13  
   13.14 +static void DirectFB_AdjustWindowSurface(_THIS, SDL_Window * window);
   13.15  
   13.16  int
   13.17  DirectFB_CreateWindow(_THIS, SDL_Window * window)
   13.18 @@ -36,8 +41,7 @@
   13.19      DFB_WindowData *windata = NULL;
   13.20      DFBWindowOptions wopts;
   13.21      DFBWindowDescription desc;
   13.22 -    IDirectFBFont *font;
   13.23 -    int ret, x, y;
   13.24 +    int x, y;
   13.25  
   13.26      SDL_DFB_CALLOC(window->driverdata, 1, sizeof(DFB_WindowData));
   13.27      windata = (DFB_WindowData *) window->driverdata;
   13.28 @@ -69,7 +73,7 @@
   13.29          y = 0;
   13.30      }
   13.31  
   13.32 -    DirectFB_WM_AdjustWindowLayout(window);
   13.33 +    DirectFB_WM_AdjustWindowLayout(window, window->flags, window->w, window->h);
   13.34  
   13.35      /* Create Window */
   13.36      desc.flags =
   13.37 @@ -87,7 +91,7 @@
   13.38                                                     &windata->window));
   13.39  
   13.40      /* Set Options */
   13.41 -    windata->window->GetOptions(windata->window, &wopts);
   13.42 +    SDL_DFB_CHECK(windata->window->GetOptions(windata->window, &wopts));
   13.43  
   13.44      if (window->flags & SDL_WINDOW_RESIZABLE)
   13.45          wopts |= DWOP_SCALE;
   13.46 @@ -96,9 +100,9 @@
   13.47  
   13.48      if (window->flags & SDL_WINDOW_FULLSCREEN) {
   13.49          wopts |= DWOP_KEEP_POSITION | DWOP_KEEP_STACKING | DWOP_KEEP_SIZE;
   13.50 -        windata->window->SetStackingClass(windata->window, DWSC_UPPER);
   13.51 +        SDL_DFB_CHECK(windata->window->SetStackingClass(windata->window, DWSC_UPPER));
   13.52      }
   13.53 -    windata->window->SetOptions(windata->window, wopts);
   13.54 +    SDL_DFB_CHECK(windata->window->SetOptions(windata->window, wopts));
   13.55  
   13.56      /* See what we got */
   13.57      SDL_DFB_CHECKERR(DirectFB_WM_GetClientSize
   13.58 @@ -112,7 +116,7 @@
   13.59                       GetSubSurface(windata->window_surface, &windata->client,
   13.60                                     &windata->surface));
   13.61  
   13.62 -    windata->window->SetOpacity(windata->window, 0xFF);
   13.63 +    SDL_DFB_CHECK(windata->window->SetOpacity(windata->window, 0xFF));
   13.64  
   13.65      /* Create Eventbuffer */
   13.66      SDL_DFB_CHECKERR(windata->window->CreateEventBuffer(windata->window,
   13.67 @@ -123,21 +127,10 @@
   13.68  
   13.69      /* Create a font */
   13.70      /* FIXME: once during Video_Init */
   13.71 -    if (windata->is_managed) {
   13.72 -        DFBFontDescription fdesc;
   13.73 -
   13.74 -        fdesc.flags = DFDESC_HEIGHT;
   13.75 -        fdesc.height = windata->theme.font_size;
   13.76 -        font = NULL;
   13.77 -        SDL_DFB_CHECK(devdata->
   13.78 -                      dfb->CreateFont(devdata->dfb, windata->theme.font,
   13.79 -                                      &fdesc, &font));
   13.80 -        windata->window_surface->SetFont(windata->window_surface, font);
   13.81 -        SDL_DFB_RELEASE(font);
   13.82 -    }
   13.83 +    windata->font = NULL;
   13.84  
   13.85      /* Make it the top most window. */
   13.86 -    windata->window->RaiseToTop(windata->window);
   13.87 +    SDL_DFB_CHECK(windata->window->RaiseToTop(windata->window));
   13.88  
   13.89      /* remember parent */
   13.90      windata->sdl_window = window;
   13.91 @@ -149,7 +142,7 @@
   13.92      devdata->firstwin = windata;
   13.93  
   13.94      /* Draw Frame */
   13.95 -    DirectFB_WM_RedrawLayout(window);
   13.96 +    DirectFB_WM_RedrawLayout(_this, window);
   13.97  
   13.98      return 0;
   13.99    error:
  13.100 @@ -172,6 +165,7 @@
  13.101  
  13.102      if (windata->is_managed) {
  13.103          windata->wm_needs_redraw = 1;
  13.104 +        DirectFB_WM_RedrawLayout(_this, window);
  13.105      } else
  13.106          SDL_Unsupported();
  13.107  }
  13.108 @@ -182,7 +176,6 @@
  13.109      SDL_DFB_DEVICEDATA(_this);
  13.110      SDL_DFB_WINDOWDATA(window);
  13.111      SDL_Surface *surface = NULL;
  13.112 -    DFBResult ret;
  13.113  
  13.114      if (icon) {
  13.115          SDL_PixelFormat format;
  13.116 @@ -216,7 +209,7 @@
  13.117              memcpy((char *) dest + i * pitch,
  13.118                     (char *) p + i * surface->pitch, 4 * surface->w);
  13.119  
  13.120 -        windata->icon->Unlock(windata->icon);
  13.121 +        SDL_DFB_CHECK(windata->icon->Unlock(windata->icon));
  13.122          SDL_FreeSurface(surface);
  13.123      } else {
  13.124          SDL_DFB_RELEASE(windata->icon);
  13.125 @@ -249,16 +242,15 @@
  13.126          x = 0;
  13.127          y = 0;
  13.128      }
  13.129 -    DirectFB_WM_AdjustWindowLayout(window);
  13.130 -    windata->window->MoveTo(windata->window, x, y);
  13.131 +    DirectFB_WM_AdjustWindowLayout(window, window->flags, window->w, window->h);
  13.132 +    SDL_DFB_CHECK(windata->window->MoveTo(windata->window, x, y));
  13.133  }
  13.134  
  13.135  void
  13.136  DirectFB_SetWindowSize(_THIS, SDL_Window * window)
  13.137  {
  13.138 -    SDL_DFB_DEVICEDATA(_this);
  13.139 +    //SDL_DFB_DEVICEDATA(_this);
  13.140      SDL_DFB_WINDOWDATA(window);
  13.141 -    int ret;
  13.142  
  13.143      if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
  13.144          int cw;
  13.145 @@ -272,23 +264,23 @@
  13.146  
  13.147          if (cw != window->w || ch != window->h) {
  13.148  
  13.149 -            DirectFB_WM_AdjustWindowLayout(window);
  13.150 +		    DirectFB_WM_AdjustWindowLayout(window, window->flags, window->w, window->h);
  13.151              SDL_DFB_CHECKERR(windata->window->Resize(windata->window,
  13.152                                                       windata->size.w,
  13.153                                                       windata->size.h));
  13.154          }
  13.155  
  13.156 +        SDL_DFB_CHECKERR(DirectFB_WM_GetClientSize
  13.157 +                     (_this, window, &window->w, &window->h));
  13.158 +        DirectFB_AdjustWindowSurface(_this, window);
  13.159 +
  13.160          SDL_DFB_CHECKERR(windata->window->EnableEvents(windata->window,
  13.161                                                         DWET_ALL));
  13.162  
  13.163 -        SDL_DFB_CHECKERR(DirectFB_WM_GetClientSize
  13.164 -                         (_this, window, &window->w, &window->h));
  13.165 -
  13.166 -        SDL_OnWindowResized(window);
  13.167      }
  13.168      return;
  13.169    error:
  13.170 -    windata->window->EnableEvents(windata->window, DWET_ALL);
  13.171 +    SDL_DFB_CHECK(windata->window->EnableEvents(windata->window, DWET_ALL));
  13.172      return;
  13.173  }
  13.174  
  13.175 @@ -297,7 +289,7 @@
  13.176  {
  13.177      SDL_DFB_WINDOWDATA(window);
  13.178  
  13.179 -    windata->window->SetOpacity(windata->window, windata->opacity);
  13.180 +    SDL_DFB_CHECK(windata->window->SetOpacity(windata->window, windata->opacity));
  13.181  
  13.182  }
  13.183  
  13.184 @@ -306,8 +298,8 @@
  13.185  {
  13.186      SDL_DFB_WINDOWDATA(window);
  13.187  
  13.188 -    windata->window->GetOpacity(windata->window, &windata->opacity);
  13.189 -    windata->window->SetOpacity(windata->window, 0);
  13.190 +    SDL_DFB_CHECK(windata->window->GetOpacity(windata->window, &windata->opacity));
  13.191 +    SDL_DFB_CHECK(windata->window->SetOpacity(windata->window, 0));
  13.192  }
  13.193  
  13.194  void
  13.195 @@ -315,8 +307,8 @@
  13.196  {
  13.197      SDL_DFB_WINDOWDATA(window);
  13.198  
  13.199 -    windata->window->RaiseToTop(windata->window);
  13.200 -    windata->window->RequestFocus(windata->window);
  13.201 +    SDL_DFB_CHECK(windata->window->RaiseToTop(windata->window));
  13.202 +    SDL_DFB_CHECK(windata->window->RequestFocus(windata->window));
  13.203  }
  13.204  
  13.205  void
  13.206 @@ -352,14 +344,23 @@
  13.207  void
  13.208  DirectFB_SetWindowGrab(_THIS, SDL_Window * window)
  13.209  {
  13.210 +    SDL_DFB_DEVICEDATA(_this);
  13.211      SDL_DFB_WINDOWDATA(window);
  13.212 +    DFB_WindowData *gwindata = ((devdata->grabbed_window) ? (DFB_WindowData *) ((devdata->grabbed_window)->driverdata) : NULL);
  13.213  
  13.214      if ((window->flags & SDL_WINDOW_INPUT_GRABBED)) {
  13.215 -        windata->window->GrabPointer(windata->window);
  13.216 -        windata->window->GrabKeyboard(windata->window);
  13.217 +        if (gwindata != NULL)
  13.218 +        {
  13.219 +		    SDL_DFB_CHECK(gwindata->window->UngrabPointer(gwindata->window));
  13.220 +		    SDL_DFB_CHECK(gwindata->window->UngrabKeyboard(gwindata->window));
  13.221 +        }
  13.222 +        SDL_DFB_CHECK(windata->window->GrabPointer(windata->window));
  13.223 +        SDL_DFB_CHECK(windata->window->GrabKeyboard(windata->window));
  13.224 +        devdata->grabbed_window = window;
  13.225      } else {
  13.226 -        windata->window->UngrabPointer(windata->window);
  13.227 -        windata->window->UngrabKeyboard(windata->window);
  13.228 +        SDL_DFB_CHECK(windata->window->UngrabPointer(windata->window));
  13.229 +        SDL_DFB_CHECK(windata->window->UngrabKeyboard(windata->window));
  13.230 +        devdata->grabbed_window = NULL;
  13.231      }
  13.232  }
  13.233  
  13.234 @@ -370,14 +371,19 @@
  13.235      SDL_DFB_WINDOWDATA(window);
  13.236      DFB_WindowData *p;
  13.237  
  13.238 -    SDL_DFB_DEBUG("Trace\n");
  13.239 +    /* Some cleanups */
  13.240 +    SDL_DFB_CHECK(windata->window->UngrabPointer(windata->window));
  13.241 +    SDL_DFB_CHECK(windata->window->UngrabKeyboard(windata->window));
  13.242  
  13.243 -    /* Some cleanups */
  13.244 -    windata->window->UngrabPointer(windata->window);
  13.245 -    windata->window->UngrabKeyboard(windata->window);
  13.246 +#if SDL_DIRECTFB_OPENGL
  13.247 +	DirectFB_GL_DestroyWindowContexts(_this, window);
  13.248 +#endif
  13.249  
  13.250 -    windata->window_surface->SetFont(windata->window_surface, NULL);
  13.251 -    SDL_DFB_RELEASE(windata->icon);
  13.252 +    SDL_DFB_CHECK(windata->window_surface->SetFont(windata->window_surface, NULL));
  13.253 +    SDL_DFB_CHECK(windata->surface->ReleaseSource(windata->surface));
  13.254 +    SDL_DFB_CHECK(windata->window_surface->ReleaseSource(windata->window_surface));
  13.255 +  	SDL_DFB_RELEASE(windata->icon);
  13.256 +    SDL_DFB_RELEASE(windata->font);
  13.257      SDL_DFB_RELEASE(windata->eventbuffer);
  13.258      SDL_DFB_RELEASE(windata->surface);
  13.259      SDL_DFB_RELEASE(windata->window_surface);
  13.260 @@ -405,15 +411,14 @@
  13.261      return SDL_FALSE;
  13.262  }
  13.263  
  13.264 -void
  13.265 -DirectFB_AdjustWindowSurface(SDL_Window * window)
  13.266 +static void
  13.267 +DirectFB_AdjustWindowSurface(_THIS, SDL_Window * window)
  13.268  {
  13.269      SDL_DFB_WINDOWDATA(window);
  13.270      int adjust = windata->wm_needs_redraw;
  13.271      int cw, ch;
  13.272 -    int ret;
  13.273  
  13.274 -    DirectFB_WM_AdjustWindowLayout(window);
  13.275 +    DirectFB_WM_AdjustWindowLayout(window, window->flags, window->w, window->h);
  13.276  
  13.277      SDL_DFB_CHECKERR(windata->
  13.278                       window_surface->GetSize(windata->window_surface, &cw,
  13.279 @@ -423,6 +428,10 @@
  13.280      }
  13.281  
  13.282      if (adjust) {
  13.283 +#if SDL_DIRECTFB_OPENGL
  13.284 +		DirectFB_GL_FreeWindowContexts(_this, window);
  13.285 +#endif
  13.286 +
  13.287  #if DFB_VERSION_ATLEAST(1,2,1)
  13.288          SDL_DFB_CHECKERR(windata->window->ResizeSurface(windata->window,
  13.289                                                          windata->size.w,
  13.290 @@ -446,8 +455,12 @@
  13.291                           GetSubSurface(windata->window_surface,
  13.292                                         &windata->client, &windata->surface));
  13.293  #endif
  13.294 -        DirectFB_WM_RedrawLayout(window);
  13.295 -    }
  13.296 +        DirectFB_WM_RedrawLayout(_this, window);
  13.297 +        
  13.298 +#if SDL_DIRECTFB_OPENGL
  13.299 +		DirectFB_GL_ReAllocWindowContexts(_this, window);
  13.300 +#endif
  13.301 +   }
  13.302    error:
  13.303      return;
  13.304  }
    14.1 --- a/src/video/directfb/SDL_DirectFB_window.h	Sat Aug 14 12:28:43 2010 -0700
    14.2 +++ b/src/video/directfb/SDL_DirectFB_window.h	Mon Aug 16 09:04:55 2010 -0700
    14.3 @@ -34,7 +34,6 @@
    14.4      IDirectFBSurface *surface;
    14.5      IDirectFBSurface *window_surface;   /* only used with has_own_wm */
    14.6      IDirectFBWindow *window;
    14.7 -    DirectFB_GLContext *gl_context;
    14.8      IDirectFBEventBuffer *eventbuffer;
    14.9      SDL_Window *sdl_window;
   14.10      DFB_WindowData *next;
   14.11 @@ -46,6 +45,7 @@
   14.12      int is_managed;
   14.13      int wm_needs_redraw;
   14.14      IDirectFBSurface *icon;
   14.15 +    IDirectFBFont *font;
   14.16      DFB_Theme theme;
   14.17  };
   14.18  
   14.19 @@ -69,7 +69,7 @@
   14.20  extern SDL_bool DirectFB_GetWindowWMInfo(_THIS, SDL_Window * window,
   14.21                                           struct SDL_SysWMinfo *info);
   14.22  
   14.23 -extern void DirectFB_AdjustWindowSurface(SDL_Window * window);
   14.24 +//extern void DirectFB_AdjustWindowSurface(_THIS, SDL_Window * window);
   14.25  
   14.26  #endif /* _SDL_directfb_window_h */
   14.27