Updated the DirectFB support, from Couriersud
authorSam Lantinga <slouken@libsdl.org>
Sat, 05 Feb 2011 16:07:10 -0800
changeset 5199164f20ba08eb
parent 5198 7c3422025c35
child 5200 01bced9a4cc1
Updated the DirectFB support, from Couriersud

attached is a working directfb driver diff which works with the current
changes. There are a number of changes around it as well, e.g.
configure.in.

The directfb renderdriver right now still depends on a some "includes"
from src/video/directfb. That's why it is not yet moved to the new
render folder.
README.DirectFB
configure.in
include/SDL_config.h.in
include/SDL_syswm.h
src/render/SDL_render.c
src/render/SDL_sysrender.h
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_dyn.h
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_mouse.h
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_render.h
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 Feb 05 16:02:30 2011 -0800
     1.2 +++ b/README.DirectFB	Sat Feb 05 16:07:10 2011 -0800
     1.3 @@ -71,9 +71,9 @@
     1.4  As of this writing 20100802 you need to pull Mesa from git and do the following:
     1.5  
     1.6  ------------------------
     1.7 +git clone git://anongit.freedesktop.org/git/mesa/mesa
     1.8 +cd mesa 
     1.9  git checkout 2c9fdaf7292423c157fc79b5ce43f0f199dd753a
    1.10 -cd mesa 
    1.11 -git clone git://anongit.freedesktop.org/git/mesa/mesa
    1.12  ------------------------
    1.13  
    1.14  Edit configs/linux-directfb so that the Directories-section looks like
     2.1 --- a/configure.in	Sat Feb 05 16:02:30 2011 -0800
     2.2 +++ b/configure.in	Sat Feb 05 16:07:10 2011 -0800
     2.3 @@ -1312,8 +1312,7 @@
     2.4          video_directfb=no
     2.5  
     2.6          DIRECTFB_REQUIRED_VERSION=1.0.0
     2.7 -
     2.8 -        AC_PATH_PROG(DIRECTFBCONFIG, directfb-config, no)
     2.9 +        AC_PATH_PROGS(DIRECTFBCONFIG, directfb-config, no, [$prefix/bin:$PATH])
    2.10          if test x$DIRECTFBCONFIG = xno; then
    2.11              AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
    2.12              if test x$PKG_CONFIG != xno; then
    2.13 @@ -1353,13 +1352,15 @@
    2.14                                , enable_directfb_shared=yes)
    2.15  
    2.16              AC_DEFINE(SDL_VIDEO_DRIVER_DIRECTFB)
    2.17 +            AC_DEFINE(SDL_VIDEO_RENDER_DIRECTFB)
    2.18              SOURCES="$SOURCES $srcdir/src/video/directfb/*.c"
    2.19              EXTRA_CFLAGS="$EXTRA_CFLAGS $DIRECTFB_CFLAGS"
    2.20  
    2.21              AC_MSG_CHECKING(for directfb dynamic loading support)
    2.22              directfb_shared=no
    2.23 -            directfb_lib=[`find_lib "libdirectfb.so.*" "$DIRECTFB_LIBS" | sed 's/.*\/\(.*\)/\1/; q'`]
    2.24 -
    2.25 +            directfb_lib=[`find_lib "libdirectfb.so.*" "$DIRECTFB_LIBS"`]
    2.26 +            # | sed 's/.*\/\(.*\)/\1/; q'`]
    2.27 +AC_MSG_WARN("directfb $directfb_lib")
    2.28              if test x$have_loadso != xyes && \
    2.29                 test x$enable_directfb_shared = xyes; then
    2.30                  AC_MSG_WARN([You must have SDL_LoadObject() support for dynamic directfb loading])
     3.1 --- a/include/SDL_config.h.in	Sat Feb 05 16:02:30 2011 -0800
     3.2 +++ b/include/SDL_config.h.in	Sat Feb 05 16:07:10 2011 -0800
     3.3 @@ -279,6 +279,7 @@
     3.4  #undef SDL_VIDEO_RENDER_D3D
     3.5  #undef SDL_VIDEO_RENDER_OGL
     3.6  #undef SDL_VIDEO_RENDER_OGL_ES
     3.7 +#undef SDL_VIDEO_RENDER_DIRECTFB
     3.8  
     3.9  /* Enable OpenGL support */
    3.10  #undef SDL_VIDEO_OPENGL
     4.1 --- a/include/SDL_syswm.h	Sat Feb 05 16:02:30 2011 -0800
     4.2 +++ b/include/SDL_syswm.h	Sat Feb 05 16:07:10 2011 -0800
     4.3 @@ -77,7 +77,7 @@
     4.4  #endif /* defined(SDL_VIDEO_DRIVER_X11) */
     4.5  
     4.6  #if defined(SDL_VIDEO_DRIVER_DIRECTFB)
     4.7 -#include <directfb/directfb.h>
     4.8 +#include <directfb.h>
     4.9  #endif
    4.10  
    4.11  #if defined(SDL_VIDEO_DRIVER_COCOA)
     5.1 --- a/src/render/SDL_render.c	Sat Feb 05 16:02:30 2011 -0800
     5.2 +++ b/src/render/SDL_render.c	Sat Feb 05 16:07:10 2011 -0800
     5.3 @@ -53,6 +53,9 @@
     5.4  #if SDL_VIDEO_RENDER_OGL_ES
     5.5      &GL_ES_RenderDriver,
     5.6  #endif
     5.7 +#if SDL_VIDEO_RENDER_DIRECTFB
     5.8 +    &DirectFB_RenderDriver,
     5.9 +#endif
    5.10      &SW_RenderDriver
    5.11  };
    5.12  static char renderer_magic;
     6.1 --- a/src/render/SDL_sysrender.h	Sat Feb 05 16:02:30 2011 -0800
     6.2 +++ b/src/render/SDL_sysrender.h	Sat Feb 05 16:07:10 2011 -0800
     6.3 @@ -127,6 +127,9 @@
     6.4  #if SDL_VIDEO_RENDER_OGL_ES
     6.5  extern SDL_RenderDriver GL_ES_RenderDriver;
     6.6  #endif
     6.7 +#if SDL_VIDEO_RENDER_DIRECTFB
     6.8 +extern SDL_RenderDriver DirectFB_RenderDriver;
     6.9 +#endif
    6.10  extern SDL_RenderDriver SW_RenderDriver;
    6.11  
    6.12  #endif /* _SDL_sysrender_h */
     7.1 --- a/src/video/directfb/SDL_DirectFB_WM.c	Sat Feb 05 16:02:30 2011 -0800
     7.2 +++ b/src/video/directfb/SDL_DirectFB_WM.c	Sat Feb 05 16:07:10 2011 -0800
     7.3 @@ -18,14 +18,13 @@
     7.4  
     7.5      Sam Lantinga
     7.6      slouken@libsdl.org
     7.7 +
     7.8 +    SDL1.3 DirectFB driver by couriersud@arcor.de
     7.9 +	
    7.10  */
    7.11 -#include "SDL_config.h"
    7.12 -
    7.13 -//#include "SDL_syswm.h"
    7.14 -//#include "../SDL_sysvideo.h"
    7.15 -//#include "../../events/SDL_keyboard_c.h"
    7.16  
    7.17  #include "SDL_DirectFB_video.h"
    7.18 +#include "SDL_DirectFB_window.h"
    7.19  
    7.20  #include "../../events/SDL_windowevents_c.h"
    7.21  
    7.22 @@ -127,6 +126,11 @@
    7.23      if (!windata->is_managed || (window->flags & SDL_WINDOW_FULLSCREEN))
    7.24          return;
    7.25  
    7.26 +    SDL_DFB_CHECK(s->SetSrcBlendFunction(s, DSBF_ONE));
    7.27 +    SDL_DFB_CHECK(s->SetDstBlendFunction(s, DSBF_ZERO));
    7.28 +    SDL_DFB_CHECK(s->SetDrawingFlags(s, DSDRAW_NOFX));
    7.29 +    SDL_DFB_CHECK(s->SetBlittingFlags(s, DSBLIT_NOFX));
    7.30 +
    7.31  	LoadFont(_this, window);
    7.32      //s->SetDrawingFlags(s, DSDRAW_BLEND);
    7.33      s->SetColor(s, COLOR_EXPAND(t->frame_color));
    7.34 @@ -181,8 +185,10 @@
    7.35  DirectFB_WM_GetClientSize(_THIS, SDL_Window * window, int *cw, int *ch)
    7.36  {
    7.37      SDL_DFB_WINDOWDATA(window);
    7.38 +	IDirectFBWindow *dfbwin = windata->dfbwin;
    7.39  
    7.40 -    SDL_DFB_CHECK(windata->window->GetSize(windata->window, cw, ch));
    7.41 +    SDL_DFB_CHECK(dfbwin->GetSize(dfbwin, cw, ch));
    7.42 +    dfbwin->GetSize(dfbwin, cw, ch);
    7.43      *cw -= windata->theme.left_size + windata->theme.right_size;
    7.44      *ch -=
    7.45          windata->theme.top_size + windata->theme.caption_size +
    7.46 @@ -197,6 +203,9 @@
    7.47  
    7.48      if (!windata->is_managed)
    7.49          windata->theme = theme_none;
    7.50 +    else if (flags & SDL_WINDOW_BORDERLESS)
    7.51 +    	//desc.caps |= DWCAPS_NODECORATION;)
    7.52 +    	windata->theme = theme_none;
    7.53      else if (flags & SDL_WINDOW_FULLSCREEN) {
    7.54          windata->theme = theme_none;
    7.55      } else if (flags & SDL_WINDOW_MAXIMIZED) {
    7.56 @@ -220,37 +229,6 @@
    7.57          windata->theme.caption_size + windata->theme.bottom_size;
    7.58  }
    7.59  
    7.60 -void
    7.61 -DirectFB_WM_MaximizeWindow(_THIS, SDL_Window * window)
    7.62 -{
    7.63 -    SDL_DFB_WINDOWDATA(window);
    7.64 -    SDL_VideoDisplay *display = window->display;
    7.65 -
    7.66 -    SDL_DFB_CHECK(windata->window->GetPosition(windata->window,
    7.67 -                                 &windata->restore.x, &windata->restore.y));
    7.68 -    SDL_DFB_CHECK(windata->window->GetSize(windata->window, &windata->restore.w,
    7.69 -                             &windata->restore.h));
    7.70 -
    7.71 -    DirectFB_WM_AdjustWindowLayout(window, window->flags | SDL_WINDOW_MAXIMIZED, display->current_mode.w, display->current_mode.h) ;
    7.72 -
    7.73 -    SDL_DFB_CHECK(windata->window->MoveTo(windata->window, 0, 0));
    7.74 -    SDL_DFB_CHECK(windata->window->Resize(windata->window,
    7.75 -                            display->current_mode.w, display->current_mode.h));
    7.76 -}
    7.77 -
    7.78 -void
    7.79 -DirectFB_WM_RestoreWindow(_THIS, SDL_Window * window)
    7.80 -{
    7.81 -    SDL_DFB_WINDOWDATA(window);
    7.82 -
    7.83 -    DirectFB_WM_AdjustWindowLayout(window, window->flags & ~(SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED), 
    7.84 -    	windata->restore.w, windata->restore.h);
    7.85 -
    7.86 -    SDL_DFB_CHECK(windata->window->Resize(windata->window, windata->restore.w,
    7.87 -                            windata->restore.h));
    7.88 -    SDL_DFB_CHECK(windata->window->MoveTo(windata->window, windata->restore.x,
    7.89 -                            windata->restore.y));
    7.90 -}
    7.91  
    7.92  enum
    7.93  {
    7.94 @@ -307,20 +285,20 @@
    7.95      return pos;
    7.96  }
    7.97  
    7.98 -static int wm_grab;
    7.99 -static int wm_lastx;
   7.100 -static int wm_lasty;
   7.101 -
   7.102  int
   7.103  DirectFB_WM_ProcessEvent(_THIS, SDL_Window * window, DFBWindowEvent * evt)
   7.104  {
   7.105      SDL_DFB_DEVICEDATA(_this);
   7.106      SDL_DFB_WINDOWDATA(window);
   7.107  	DFB_WindowData *gwindata = ((devdata->grabbed_window) ? (DFB_WindowData *) ((devdata->grabbed_window)->driverdata) : NULL);
   7.108 +	IDirectFBWindow *dfbwin = windata->dfbwin;
   7.109 +    DFBWindowOptions wopts;
   7.110  
   7.111      if (!windata->is_managed)
   7.112          return 0;
   7.113  
   7.114 +    SDL_DFB_CHECK(dfbwin->GetOptions(dfbwin, &wopts));
   7.115 +
   7.116      switch (evt->type) {
   7.117      case DWET_BUTTONDOWN:
   7.118          if (evt->buttons & DIBM_LEFT) {
   7.119 @@ -329,59 +307,99 @@
   7.120              case WM_POS_NONE:
   7.121                  return 0;
   7.122              case WM_POS_CLOSE:
   7.123 -		        wm_grab = WM_POS_NONE;
   7.124 +		        windata->wm_grab = WM_POS_NONE;
   7.125                  SDL_SendWindowEvent(window, SDL_WINDOWEVENT_CLOSE, 0,
   7.126                                      0);
   7.127                  return 1;
   7.128              case WM_POS_MAX:
   7.129 -		        wm_grab = WM_POS_NONE;
   7.130 -                if (window->flags & SDL_WINDOW_MAXIMIZED) {
   7.131 -                	SDL_RestoreWindow(window);
   7.132 -                } else {
   7.133 -                    SDL_MaximizeWindow(window);
   7.134 -                }
   7.135 +		        windata->wm_grab = WM_POS_NONE;
   7.136 +				if (window->flags & SDL_WINDOW_MAXIMIZED) {
   7.137 +					SDL_RestoreWindow(window);
   7.138 +				} else {
   7.139 +					SDL_MaximizeWindow(window);
   7.140 +				}
   7.141                  return 1;
   7.142              case WM_POS_CAPTION:
   7.143 -                DirectFB_RaiseWindow(_this, window);
   7.144 +            	if (!(wopts & DWOP_KEEP_STACKING)) {
   7.145 +	                DirectFB_RaiseWindow(_this, window);
   7.146 +	            }
   7.147 +            	if (window->flags & SDL_WINDOW_MAXIMIZED)
   7.148 +            		return 1;
   7.149                  /* fall through */
   7.150              default:
   7.151 -                wm_grab = pos;
   7.152 +                windata->wm_grab = pos;
   7.153                  if (gwindata != NULL)
   7.154 -	                SDL_DFB_CHECK(gwindata->window->UngrabPointer(gwindata->window));
   7.155 -                SDL_DFB_CHECK(windata->window->GrabPointer(windata->window));
   7.156 -                wm_lastx = evt->cx;
   7.157 -                wm_lasty = evt->cy;
   7.158 +	                SDL_DFB_CHECK(gwindata->dfbwin->UngrabPointer(gwindata->dfbwin));
   7.159 +                SDL_DFB_CHECK(dfbwin->GrabPointer(dfbwin));
   7.160 +                windata->wm_lastx = evt->cx;
   7.161 +                windata->wm_lasty = evt->cy;
   7.162              }
   7.163          }
   7.164          return 1;
   7.165      case DWET_BUTTONUP:
   7.166 +        if (!windata->wm_grab)
   7.167 +            return 0;
   7.168 +        if (!(evt->buttons & DIBM_LEFT)) {
   7.169 +            if (windata->wm_grab & (WM_POS_RIGHT | WM_POS_BOTTOM)) {
   7.170 +                int dx = evt->cx - windata->wm_lastx;
   7.171 +                int dy = evt->cy - windata->wm_lasty;
   7.172 +
   7.173 +            	if (!(wopts & DWOP_KEEP_SIZE)) {
   7.174 +                    int cw, ch;
   7.175 +			        if ((windata->wm_grab & (WM_POS_BOTTOM | WM_POS_RIGHT)) == WM_POS_BOTTOM)
   7.176 +			        	dx = 0;
   7.177 +			        else if ((windata->wm_grab & (WM_POS_BOTTOM | WM_POS_RIGHT)) == WM_POS_RIGHT)
   7.178 +			        	dy = 0;
   7.179 +		            SDL_DFB_CHECK(dfbwin->GetSize(dfbwin, &cw, &ch));
   7.180 +
   7.181 +		            /* necessary to trigger an event - ugly*/
   7.182 +					SDL_DFB_CHECK(dfbwin->DisableEvents(dfbwin, DWET_ALL));
   7.183 +		            SDL_DFB_CHECK(dfbwin->Resize(dfbwin, cw + dx + 1, ch + dy));
   7.184 +					SDL_DFB_CHECK(dfbwin->EnableEvents(dfbwin, DWET_ALL));
   7.185 +
   7.186 +		            SDL_DFB_CHECK(dfbwin->Resize(dfbwin, cw + dx, ch + dy));
   7.187 +            	}
   7.188 +            }
   7.189 +            SDL_DFB_CHECK(dfbwin->UngrabPointer(dfbwin));
   7.190 +            if (gwindata != NULL)
   7.191 +                SDL_DFB_CHECK(gwindata->dfbwin->GrabPointer(gwindata->dfbwin));
   7.192 +            windata->wm_grab = WM_POS_NONE;
   7.193 +            return 1;
   7.194 +        }
   7.195          break;
   7.196      case DWET_MOTION:
   7.197 -        if (!wm_grab)
   7.198 +        if (!windata->wm_grab)
   7.199              return 0;
   7.200          if (evt->buttons & DIBM_LEFT) {
   7.201 -            int dx = evt->cx - wm_lastx;
   7.202 -            int dy = evt->cy - wm_lasty;
   7.203 -            int cw, ch;
   7.204 +        	int dx = evt->cx - windata->wm_lastx;
   7.205 +            int dy = evt->cy - windata->wm_lasty;
   7.206  
   7.207 -            if (wm_grab & WM_POS_CAPTION)
   7.208 -                SDL_DFB_CHECK(windata->window->Move(windata->window, dx, dy));
   7.209 -	        if (wm_grab & (WM_POS_RIGHT | WM_POS_BOTTOM)) {
   7.210 -	            if ((wm_grab & (WM_POS_BOTTOM | WM_POS_RIGHT)) == WM_POS_BOTTOM)
   7.211 -	            	dx = 0;
   7.212 -	            else if ((wm_grab & (WM_POS_BOTTOM | WM_POS_RIGHT)) == WM_POS_RIGHT)
   7.213 -	            	dy = 0;
   7.214 -                SDL_DFB_CHECK(windata->window->GetSize(windata->window, &cw, &ch));
   7.215 -                SDL_DFB_CHECK(windata->window->Resize(windata->window, cw + dx, ch + dy));
   7.216 +            if (windata->wm_grab & WM_POS_CAPTION) {
   7.217 +            	if (!(wopts & DWOP_KEEP_POSITION))
   7.218 +	                SDL_DFB_CHECK(dfbwin->Move(dfbwin, dx, dy));
   7.219              }
   7.220 -            wm_lastx = evt->cx;
   7.221 -            wm_lasty = evt->cy;
   7.222 -            return 1;
   7.223 +            if (windata->wm_grab & (WM_POS_RIGHT | WM_POS_BOTTOM)) {
   7.224 +				if (!(wopts & DWOP_KEEP_SIZE)) {
   7.225 +					int cw, ch;
   7.226 +
   7.227 +					/* Make sure all events are disabled for this operation ! */
   7.228 +					SDL_DFB_CHECK(dfbwin->DisableEvents(dfbwin, DWET_ALL));
   7.229 +
   7.230 +					if ((windata->wm_grab & (WM_POS_BOTTOM | WM_POS_RIGHT)) == WM_POS_BOTTOM)
   7.231 +						dx = 0;
   7.232 +					else if ((windata->wm_grab & (WM_POS_BOTTOM | WM_POS_RIGHT)) == WM_POS_RIGHT)
   7.233 +						dy = 0;
   7.234 +
   7.235 +					SDL_DFB_CHECK(dfbwin->GetSize(dfbwin, &cw, &ch));
   7.236 +					SDL_DFB_CHECK(dfbwin->Resize(dfbwin, cw + dx, ch + dy));
   7.237 +
   7.238 +					SDL_DFB_CHECK(dfbwin->EnableEvents(dfbwin, DWET_ALL));
   7.239 +				}
   7.240 +            }
   7.241 +			windata->wm_lastx = evt->cx;
   7.242 +			windata->wm_lasty = evt->cy;
   7.243 +			return 1;
   7.244          }
   7.245 -        SDL_DFB_CHECK(windata->window->UngrabPointer(windata->window));
   7.246 -        if (gwindata != NULL)
   7.247 -            SDL_DFB_CHECK(gwindata->window->GrabPointer(gwindata->window));
   7.248 -        wm_grab = WM_POS_NONE;
   7.249          break;
   7.250      case DWET_KEYDOWN:
   7.251          break;
   7.252 @@ -392,3 +410,4 @@
   7.253      }
   7.254      return 0;
   7.255  }
   7.256 +
     8.1 --- a/src/video/directfb/SDL_DirectFB_WM.h	Sat Feb 05 16:02:30 2011 -0800
     8.2 +++ b/src/video/directfb/SDL_DirectFB_WM.h	Sat Feb 05 16:07:10 2011 -0800
     8.3 @@ -18,12 +18,16 @@
     8.4  
     8.5      Sam Lantinga
     8.6      slouken@libsdl.org
     8.7 +
     8.8 +    SDL1.3 DirectFB driver by couriersud@arcor.de
     8.9 +	
    8.10  */
    8.11 -#include "SDL_config.h"
    8.12  
    8.13  #ifndef _SDL_directfb_wm_h
    8.14  #define _SDL_directfb_wm_h
    8.15  
    8.16 +#include "SDL_DirectFB_video.h"
    8.17 +
    8.18  typedef struct _DFB_Theme DFB_Theme;
    8.19  struct _DFB_Theme
    8.20  {
    8.21 @@ -42,8 +46,6 @@
    8.22  };
    8.23  
    8.24  extern void DirectFB_WM_AdjustWindowLayout(SDL_Window * window, int flags, int w, int h);
    8.25 -extern void DirectFB_WM_MaximizeWindow(_THIS, SDL_Window * window);
    8.26 -extern void DirectFB_WM_RestoreWindow(_THIS, SDL_Window * window);
    8.27  extern void DirectFB_WM_RedrawLayout(_THIS, SDL_Window * window);
    8.28  
    8.29  extern int DirectFB_WM_ProcessEvent(_THIS, SDL_Window * window,
     9.1 --- a/src/video/directfb/SDL_DirectFB_dyn.c	Sat Feb 05 16:02:30 2011 -0800
     9.2 +++ b/src/video/directfb/SDL_DirectFB_dyn.c	Sat Feb 05 16:07:10 2011 -0800
     9.3 @@ -18,7 +18,11 @@
     9.4  
     9.5      Sam Lantinga
     9.6      slouken@libsdl.org
     9.7 +
     9.8 +    SDL1.3 DirectFB driver by couriersud@arcor.de
     9.9 +	
    9.10  */
    9.11 +
    9.12  #include "SDL_config.h"
    9.13  
    9.14  #include "SDL_DirectFB_video.h"
    9.15 @@ -41,6 +45,7 @@
    9.16  #define DFB_SYM(ret, name, args, al, func) ret name args { func SDL_DirectFB_Symbols.name al  ; }
    9.17  DFB_SYMS
    9.18  #undef DFB_SYM
    9.19 +
    9.20  static void *handle = NULL;
    9.21  
    9.22  int
    9.23 @@ -55,7 +60,7 @@
    9.24  #define DFB_SYM(ret, name, args, al, func) if (!(SDL_DirectFB_Symbols.name = SDL_LoadFunction(handle, # name))) retval = 0;
    9.25              DFB_SYMS
    9.26  #undef DFB_SYM
    9.27 -                if (!
    9.28 +            if (!
    9.29                      (SDL_DirectFB_Symbols.directfb_major_version =
    9.30                       SDL_LoadFunction(handle, "directfb_major_version")))
    9.31                  retval = 0;
    10.1 --- a/src/video/directfb/SDL_DirectFB_dyn.h	Sat Feb 05 16:02:30 2011 -0800
    10.2 +++ b/src/video/directfb/SDL_DirectFB_dyn.h	Sat Feb 05 16:07:10 2011 -0800
    10.3 @@ -18,6 +18,9 @@
    10.4  
    10.5      Sam Lantinga
    10.6      slouken@libsdl.org
    10.7 +
    10.8 +    SDL1.3 DirectFB driver by couriersud@arcor.de
    10.9 +	
   10.10  */
   10.11  
   10.12  #ifndef _SDL_DirectFB_dyn_h
   10.13 @@ -33,7 +36,6 @@
   10.14  	DFB_SYM(DFBResult, DirectFBCreate, (IDirectFB **interface), (interface), return) \
   10.15  	DFB_SYM(const char *, DirectFBCheckVersion, (unsigned int required_major, unsigned int required_minor, unsigned int required_micro), \
   10.16  				(required_major, required_minor, required_micro), return)
   10.17 -// #define SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC "/usr/lib/libdirectfb-1.2.so.0"
   10.18  
   10.19  int SDL_DirectFB_LoadLibrary(void);
   10.20  void SDL_DirectFB_UnLoadLibrary(void);
    11.1 --- a/src/video/directfb/SDL_DirectFB_events.c	Sat Feb 05 16:02:30 2011 -0800
    11.2 +++ b/src/video/directfb/SDL_DirectFB_events.c	Sat Feb 05 16:07:10 2011 -0800
    11.3 @@ -18,17 +18,26 @@
    11.4  
    11.5      Sam Lantinga
    11.6      slouken@libsdl.org
    11.7 +
    11.8 +    SDL1.3 DirectFB driver by couriersud@arcor.de
    11.9 +	
   11.10  */
   11.11 -#include "SDL_config.h"
   11.12  
   11.13  /* Handle the event stream, converting DirectFB input events into SDL events */
   11.14  
   11.15 -#include <directfb.h>
   11.16 +#include "SDL_DirectFB_video.h"
   11.17 +#include "SDL_DirectFB_window.h"
   11.18 +#include "SDL_DirectFB_modes.h"
   11.19  
   11.20 -#include "../SDL_sysvideo.h"
   11.21 +#include "SDL_syswm.h"
   11.22 +
   11.23 +#include "../../events/SDL_mouse_c.h"
   11.24 +#include "../../events/SDL_keyboard_c.h"
   11.25 +#include "../../events/SDL_windowevents_c.h"
   11.26  #include "../../events/SDL_events_c.h"
   11.27 -#include "../../events/SDL_keyboard_c.h"
   11.28  #include "../../events/scancodes_linux.h"
   11.29 +#include "../../events/scancodes_xfree86.h"
   11.30 +
   11.31  #include "SDL_DirectFB_events.h"
   11.32  
   11.33  #if USE_MULTI_API
   11.34 @@ -52,36 +61,36 @@
   11.35  };
   11.36  
   11.37  /* The translation tables from a DirectFB keycode to a SDL keysym */
   11.38 -static SDLKey oskeymap[256];
   11.39 +static SDL_ScanCode oskeymap[256];
   11.40  
   11.41  
   11.42  static SDL_KeySym *DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt,
   11.43                                           SDL_KeySym * keysym);
   11.44 -static SDL_KeySym *DirectFB_TranslateKeyInputEvent(_THIS, int index,
   11.45 -                                                   DFBInputEvent * evt,
   11.46 +static SDL_KeySym *DirectFB_TranslateKeyInputEvent(_THIS, DFBInputEvent * evt,
   11.47                                                     SDL_KeySym * keysym);
   11.48  
   11.49 -static void DirectFB_InitOSKeymap(_THIS, SDLKey * keypmap, int numkeys);
   11.50 +static void DirectFB_InitOSKeymap(_THIS, SDL_ScanCode * keypmap, int numkeys);
   11.51  static int DirectFB_TranslateButton(DFBInputDeviceButtonIdentifier button);
   11.52  
   11.53 -static void
   11.54 -DirectFB_SetContext(_THIS, SDL_Window *window)
   11.55 +static void UnicodeToUtf8( Uint16 w , char *utf8buf)
   11.56  {
   11.57 -#if (DFB_VERSION_ATLEAST(1,0,0))
   11.58 -    /* FIXME: does not work on 1.0/1.2 with radeon driver
   11.59 -     *        the approach did work with the matrox driver
   11.60 -     *        This has simply no effect.
   11.61 -     */
   11.62 -
   11.63 -    SDL_VideoDisplay *display = window->display;
   11.64 -    DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
   11.65 -
   11.66 -	/* FIXME: should we handle the error */
   11.67 -    if (dispdata->vidIDinuse)
   11.68 -        SDL_DFB_CHECK(dispdata->vidlayer->SwitchContext(dispdata->vidlayer,
   11.69 -                                                           DFB_TRUE));
   11.70 -#endif
   11.71 -
   11.72 +        unsigned char *utf8s = (unsigned char *) utf8buf;
   11.73 +        
   11.74 +    if ( w < 0x0080 ) {
   11.75 +        utf8s[0] = ( unsigned char ) w;
   11.76 +        utf8s[1] = 0;
   11.77 +    }
   11.78 +    else if ( w < 0x0800 ) {
   11.79 +        utf8s[0] = 0xc0 | (( w ) >> 6 );
   11.80 +        utf8s[1] = 0x80 | (( w ) & 0x3f );
   11.81 +        utf8s[2] = 0;  
   11.82 +    }
   11.83 +    else {
   11.84 +        utf8s[0] = 0xe0 | (( w ) >> 12 );
   11.85 +        utf8s[1] = 0x80 | (( ( w ) >> 6 ) & 0x3f );
   11.86 +        utf8s[2] = 0x80 | (( w ) & 0x3f );
   11.87 +        utf8s[3] = 0;
   11.88 +    }    
   11.89  }
   11.90  
   11.91  static void
   11.92 @@ -163,21 +172,21 @@
   11.93  }
   11.94  
   11.95  static void
   11.96 -ProcessWindowEvent(_THIS, DFB_WindowData * p, Uint32 flags,
   11.97 -                   DFBWindowEvent * evt)
   11.98 +ProcessWindowEvent(_THIS, SDL_Window *sdlwin, DFBWindowEvent * evt)
   11.99  {
  11.100      SDL_DFB_DEVICEDATA(_this);
  11.101 +    SDL_DFB_WINDOWDATA(sdlwin);
  11.102      SDL_KeySym keysym;
  11.103 -    char text[5];
  11.104 +    char text[SDL_TEXTINPUTEVENT_TEXT_SIZE];
  11.105  
  11.106      if (evt->clazz == DFEC_WINDOW) {
  11.107          switch (evt->type) {
  11.108          case DWET_BUTTONDOWN:
  11.109 -            if (ClientXY(p, &evt->x, &evt->y)) {
  11.110 +            if (ClientXY(windata, &evt->x, &evt->y)) {
  11.111                  if (!devdata->use_linux_input) {
  11.112 -                    SDL_SendMouseMotion_ex(p->sdl_window, devdata->mouse_id[0], 0, evt->x,
  11.113 +                    SDL_SendMouseMotion_ex(sdlwin, devdata->mouse_id[0], 0, evt->x,
  11.114                                          evt->y, 0);
  11.115 -                    SDL_SendMouseButton_ex(p->sdl_window, devdata->mouse_id[0],
  11.116 +                    SDL_SendMouseButton_ex(sdlwin, devdata->mouse_id[0],
  11.117                                          SDL_PRESSED,
  11.118                                          DirectFB_TranslateButton
  11.119                                          (evt->button));
  11.120 @@ -187,11 +196,11 @@
  11.121              }
  11.122              break;
  11.123          case DWET_BUTTONUP:
  11.124 -            if (ClientXY(p, &evt->x, &evt->y)) {
  11.125 +            if (ClientXY(windata, &evt->x, &evt->y)) {
  11.126                  if (!devdata->use_linux_input) {
  11.127 -                    SDL_SendMouseMotion_ex(p->sdl_window, devdata->mouse_id[0], 0, evt->x,
  11.128 +                    SDL_SendMouseMotion_ex(sdlwin, devdata->mouse_id[0], 0, evt->x,
  11.129                                          evt->y, 0);
  11.130 -                    SDL_SendMouseButton_ex(p->sdl_window, devdata->mouse_id[0],
  11.131 +                    SDL_SendMouseButton_ex(sdlwin, devdata->mouse_id[0],
  11.132                                          SDL_RELEASED,
  11.133                                          DirectFB_TranslateButton
  11.134                                          (evt->button));
  11.135 @@ -201,11 +210,10 @@
  11.136              }
  11.137              break;
  11.138          case DWET_MOTION:
  11.139 -            if (ClientXY(p, &evt->x, &evt->y)) {
  11.140 -                SDL_Window *window = p->sdl_window;
  11.141 +            if (ClientXY(windata, &evt->x, &evt->y)) {
  11.142                  if (!devdata->use_linux_input) {
  11.143 -                    if (!(flags & SDL_WINDOW_INPUT_GRABBED))
  11.144 -                        SDL_SendMouseMotion_ex(p->sdl_window, devdata->mouse_id[0], 0,
  11.145 +                    if (!(sdlwin->flags & SDL_WINDOW_INPUT_GRABBED))
  11.146 +                        SDL_SendMouseMotion_ex(sdlwin, devdata->mouse_id[0], 0,
  11.147                                              evt->x, evt->y, 0);
  11.148                  } else {
  11.149                      /* relative movements are not exact! 
  11.150 @@ -217,18 +225,19 @@
  11.151                          cnt = 0;
  11.152                      }
  11.153                  }
  11.154 -                if (!(window->flags & SDL_WINDOW_MOUSE_FOCUS))
  11.155 -                    SDL_SendWindowEvent(p->sdl_window, SDL_WINDOWEVENT_ENTER, 0,
  11.156 +                if (!(sdlwin->flags & SDL_WINDOW_MOUSE_FOCUS))
  11.157 +                    SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_ENTER, 0,
  11.158                                          0);
  11.159              }
  11.160              break;
  11.161          case DWET_KEYDOWN:
  11.162              if (!devdata->use_linux_input) {
  11.163                  DirectFB_TranslateKey(_this, evt, &keysym);
  11.164 +                //printf("Scancode %d  %d %d\n", keysym.scancode, evt->key_code, evt->key_id);
  11.165                  SDL_SendKeyboardKey_ex(0, SDL_PRESSED, keysym.scancode);
  11.166                  if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
  11.167 -                    SDL_memcpy(text, &keysym.unicode, 4);
  11.168 -                    text[4] = 0;
  11.169 +	                SDL_zero(text);
  11.170 +                    UnicodeToUtf8(keysym.unicode, text);
  11.171                      if (*text) {
  11.172                          SDL_SendKeyboardText_ex(0, text);
  11.173                      }
  11.174 @@ -242,49 +251,49 @@
  11.175              }
  11.176              break;
  11.177          case DWET_POSITION:
  11.178 -            if (ClientXY(p, &evt->x, &evt->y)) {
  11.179 -                SDL_SendWindowEvent(p->sdl_window, SDL_WINDOWEVENT_MOVED,
  11.180 +            if (ClientXY(windata, &evt->x, &evt->y)) {
  11.181 +                SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_MOVED,
  11.182                                      evt->x, evt->y);
  11.183              }
  11.184              break;
  11.185          case DWET_POSITION_SIZE:
  11.186 -            if (ClientXY(p, &evt->x, &evt->y)) {
  11.187 -                SDL_SendWindowEvent(p->sdl_window, SDL_WINDOWEVENT_MOVED,
  11.188 +            if (ClientXY(windata, &evt->x, &evt->y)) {
  11.189 +                SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_MOVED,
  11.190                                      evt->x, evt->y);
  11.191              }
  11.192              /* fall throught */
  11.193          case DWET_SIZE:
  11.194              // FIXME: what about < 0
  11.195 -            evt->w -= (p->theme.right_size + p->theme.left_size);
  11.196 +            evt->w -= (windata->theme.right_size + windata->theme.left_size);
  11.197              evt->h -=
  11.198 -                (p->theme.top_size + p->theme.bottom_size +
  11.199 -                 p->theme.caption_size);
  11.200 -            SDL_SendWindowEvent(p->sdl_window, SDL_WINDOWEVENT_RESIZED,
  11.201 +                (windata->theme.top_size + windata->theme.bottom_size +
  11.202 +                 windata->theme.caption_size);
  11.203 +            SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_RESIZED,
  11.204                                  evt->w, evt->h);
  11.205              break;
  11.206          case DWET_CLOSE:
  11.207 -            SDL_SendWindowEvent(p->sdl_window, SDL_WINDOWEVENT_CLOSE, 0, 0);
  11.208 +            SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_CLOSE, 0, 0);
  11.209              break;
  11.210          case DWET_GOTFOCUS:
  11.211 -            DirectFB_SetContext(_this, p->sdl_window);
  11.212 -            FocusAllKeyboards(_this, p->sdl_window);
  11.213 -            SDL_SendWindowEvent(p->sdl_window, SDL_WINDOWEVENT_FOCUS_GAINED,
  11.214 +            DirectFB_SetContext(_this, sdlwin);
  11.215 +            FocusAllKeyboards(_this, sdlwin);
  11.216 +            SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_FOCUS_GAINED,
  11.217                                  0, 0);
  11.218              break;
  11.219          case DWET_LOSTFOCUS:
  11.220 -            SDL_SendWindowEvent(p->sdl_window, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
  11.221 +            SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
  11.222              FocusAllKeyboards(_this, 0);
  11.223              break;
  11.224          case DWET_ENTER:
  11.225              /* SDL_DirectFB_ReshowCursor(_this, 0); */
  11.226 -            FocusAllMice(_this, p->sdl_window);
  11.227 +            FocusAllMice(_this, sdlwin);
  11.228              // FIXME: when do we really enter ?
  11.229 -            if (ClientXY(p, &evt->x, &evt->y))
  11.230 +            if (ClientXY(windata, &evt->x, &evt->y))
  11.231                  MotionAllMice(_this, evt->x, evt->y);
  11.232 -            SDL_SendWindowEvent(p->sdl_window, SDL_WINDOWEVENT_ENTER, 0, 0);
  11.233 +            SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_ENTER, 0, 0);
  11.234              break;
  11.235          case DWET_LEAVE:
  11.236 -            SDL_SendWindowEvent(p->sdl_window, SDL_WINDOWEVENT_LEAVE, 0, 0);
  11.237 +            SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_LEAVE, 0, 0);
  11.238              FocusAllMice(_this, 0);
  11.239              /* SDL_DirectFB_ReshowCursor(_this, 1); */
  11.240              break;
  11.241 @@ -301,7 +310,7 @@
  11.242      SDL_DFB_DEVICEDATA(_this);
  11.243      SDL_KeySym keysym;
  11.244      int kbd_idx;
  11.245 -    char text[5];
  11.246 +    char text[SDL_TEXTINPUTEVENT_TEXT_SIZE];
  11.247  
  11.248      if (!devdata->use_linux_input) {
  11.249          if (ievt->type == DIET_AXISMOTION) {
  11.250 @@ -336,7 +345,7 @@
  11.251                              (DFB_WindowData *) window->driverdata;
  11.252                          int x, y;
  11.253  
  11.254 -                        windata->window->GetPosition(windata->window, &x, &y);
  11.255 +                        windata->dfbwin->GetPosition(windata->dfbwin, &x, &y);
  11.256                          SDL_SendMouseMotion_ex(window, ievt->device_id, 0,
  11.257                                              last_x - (x +
  11.258                                                        windata->client.x),
  11.259 @@ -358,11 +367,12 @@
  11.260              break;
  11.261          case DIET_KEYPRESS:
  11.262              kbd_idx = KbdIndex(_this, ievt->device_id);
  11.263 -            DirectFB_TranslateKeyInputEvent(_this, kbd_idx, ievt, &keysym);
  11.264 +            DirectFB_TranslateKeyInputEvent(_this, ievt, &keysym);
  11.265 +            //printf("Scancode %d  %d %d\n", keysym.scancode, evt->key_code, evt->key_id);
  11.266              SDL_SendKeyboardKey_ex(kbd_idx, SDL_PRESSED, keysym.scancode);
  11.267              if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
  11.268 -                SDL_memcpy(text, &keysym.unicode, 4);
  11.269 -                text[4] = 0;
  11.270 +                SDL_zero(text);
  11.271 +                UnicodeToUtf8(keysym.unicode, text);
  11.272                  if (*text) {
  11.273                      SDL_SendKeyboardText_ex(kbd_idx, text);
  11.274                  }
  11.275 @@ -370,7 +380,7 @@
  11.276              break;
  11.277          case DIET_KEYRELEASE:
  11.278              kbd_idx = KbdIndex(_this, ievt->device_id);
  11.279 -            DirectFB_TranslateKeyInputEvent(_this, kbd_idx, ievt, &keysym);
  11.280 +            DirectFB_TranslateKeyInputEvent(_this, ievt, &keysym);
  11.281              SDL_SendKeyboardKey_ex(kbd_idx, SDL_RELEASED, keysym.scancode);
  11.282              break;
  11.283          case DIET_BUTTONPRESS:
  11.284 @@ -399,29 +409,46 @@
  11.285  DirectFB_PumpEventsWindow(_THIS)
  11.286  {
  11.287      SDL_DFB_DEVICEDATA(_this);
  11.288 -    DFB_WindowData *p;
  11.289      DFBInputEvent ievt;
  11.290 +    SDL_Window *w;
  11.291  
  11.292 -    for (p = devdata->firstwin; p != NULL; p = p->next) {
  11.293 +    for (w = devdata->firstwin; w != NULL; w = w->next) {
  11.294 +        SDL_DFB_WINDOWDATA(w);
  11.295          DFBWindowEvent evt;
  11.296 -        SDL_Window *w = p->sdl_window;
  11.297  
  11.298 -        while (p->eventbuffer->GetEvent(p->eventbuffer,
  11.299 +        while (windata->eventbuffer->GetEvent(windata->eventbuffer,
  11.300                                          DFB_EVENT(&evt)) == DFB_OK) {
  11.301 -            if (!DirectFB_WM_ProcessEvent(_this, w, &evt))
  11.302 -                ProcessWindowEvent(_this, p, w->flags, &evt);
  11.303 +            if (!DirectFB_WM_ProcessEvent(_this, w, &evt)) {
  11.304 +                /* Send a SDL_SYSWMEVENT if the application wants them */
  11.305 +                if (SDL_GetEventState(SDL_SYSWMEVENT) == SDL_ENABLE) {
  11.306 +                    SDL_SysWMmsg wmmsg;
  11.307 +                    SDL_VERSION(&wmmsg.version);
  11.308 +                    wmmsg.subsystem = SDL_SYSWM_DIRECTFB;
  11.309 +                    wmmsg.msg.dfb.event.window = evt;
  11.310 +                    SDL_SendSysWMEvent(&wmmsg);
  11.311 +                }
  11.312 +                ProcessWindowEvent(_this, w, &evt);
  11.313 +            }
  11.314          }
  11.315      }
  11.316  
  11.317      /* Now get relative events in case we need them */
  11.318      while (devdata->events->GetEvent(devdata->events,
  11.319                                       DFB_EVENT(&ievt)) == DFB_OK) {
  11.320 +
  11.321 +    	if (SDL_GetEventState(SDL_SYSWMEVENT) == SDL_ENABLE) {
  11.322 +            SDL_SysWMmsg wmmsg;
  11.323 +            SDL_VERSION(&wmmsg.version);
  11.324 +            wmmsg.subsystem = SDL_SYSWM_DIRECTFB;
  11.325 +            wmmsg.msg.dfb.event.input = ievt;
  11.326 +            SDL_SendSysWMEvent(&wmmsg);
  11.327 +        }
  11.328          ProcessInputEvent(_this, &ievt);
  11.329      }
  11.330  }
  11.331  
  11.332  void
  11.333 -DirectFB_InitOSKeymap(_THIS, SDLKey * keymap, int numkeys)
  11.334 +DirectFB_InitOSKeymap(_THIS, SDL_ScanCode * keymap, int numkeys)
  11.335  {
  11.336      int i;
  11.337  
  11.338 @@ -552,15 +579,17 @@
  11.339  DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt, SDL_KeySym * keysym)
  11.340  {
  11.341      SDL_DFB_DEVICEDATA(_this);
  11.342 +    int kbd_idx = 0; /* Window events lag the device source KbdIndex(_this, evt->device_id); */
  11.343 +    DFB_KeyboardData *kbd = &devdata->keyboard[kbd_idx];
  11.344  
  11.345 -    if (evt->key_code >= 0 &&
  11.346 -        evt->key_code < SDL_arraysize(linux_scancode_table))
  11.347 -        keysym->scancode = linux_scancode_table[evt->key_code];
  11.348 -    else
  11.349 -        keysym->scancode = SDL_SCANCODE_UNKNOWN;
  11.350 +    keysym->scancode = SDL_SCANCODE_UNKNOWN;
  11.351 +
  11.352 +    if (kbd->map && evt->key_code >= kbd->map_adjust &&
  11.353 +	    evt->key_code < kbd->map_size + kbd->map_adjust)
  11.354 +	    keysym->scancode = kbd->map[evt->key_code - kbd->map_adjust];
  11.355  
  11.356      if (keysym->scancode == SDL_SCANCODE_UNKNOWN ||
  11.357 -        devdata->keyboard[0].is_generic) {
  11.358 +        devdata->keyboard[kbd_idx].is_generic) {
  11.359          if (evt->key_id - DIKI_UNKNOWN < SDL_arraysize(oskeymap))
  11.360              keysym->scancode = oskeymap[evt->key_id - DIKI_UNKNOWN];
  11.361          else
  11.362 @@ -577,19 +606,20 @@
  11.363  }
  11.364  
  11.365  static SDL_KeySym *
  11.366 -DirectFB_TranslateKeyInputEvent(_THIS, int index, DFBInputEvent * evt,
  11.367 +DirectFB_TranslateKeyInputEvent(_THIS, DFBInputEvent * evt,
  11.368                                  SDL_KeySym * keysym)
  11.369  {
  11.370      SDL_DFB_DEVICEDATA(_this);
  11.371 +    int kbd_idx = KbdIndex(_this, evt->device_id);
  11.372 +    DFB_KeyboardData *kbd = &devdata->keyboard[kbd_idx];
  11.373  
  11.374 -    if (evt->key_code >= 0 &&
  11.375 -        evt->key_code < SDL_arraysize(linux_scancode_table))
  11.376 -        keysym->scancode = linux_scancode_table[evt->key_code];
  11.377 -    else
  11.378 -        keysym->scancode = SDL_SCANCODE_UNKNOWN;
  11.379 +    keysym->scancode = SDL_SCANCODE_UNKNOWN;
  11.380  
  11.381 -    if (keysym->scancode == SDL_SCANCODE_UNKNOWN ||
  11.382 -        devdata->keyboard[index].is_generic) {
  11.383 +    if (kbd->map && evt->key_code >= kbd->map_adjust &&
  11.384 +	    evt->key_code < kbd->map_size + kbd->map_adjust)
  11.385 +	    keysym->scancode = kbd->map[evt->key_code - kbd->map_adjust];
  11.386 +
  11.387 +    if (keysym->scancode == SDL_SCANCODE_UNKNOWN || devdata->keyboard[kbd_idx].is_generic) {
  11.388          if (evt->key_id - DIKI_UNKNOWN < SDL_arraysize(oskeymap))
  11.389              keysym->scancode = oskeymap[evt->key_id - DIKI_UNKNOWN];
  11.390          else
  11.391 @@ -652,8 +682,18 @@
  11.392          devdata->keyboard[devdata->num_keyboard].id = device_id;
  11.393          devdata->keyboard[devdata->num_keyboard].is_generic = 0;
  11.394          if (!strncmp("X11", desc.name, 3))
  11.395 -            devdata->keyboard[devdata->num_keyboard].is_generic = 1;
  11.396 +        {
  11.397 +        	devdata->keyboard[devdata->num_keyboard].map = xfree86_scancode_table2;
  11.398 +        	devdata->keyboard[devdata->num_keyboard].map_size = SDL_arraysize(xfree86_scancode_table2);
  11.399 +			devdata->keyboard[devdata->num_keyboard].map_adjust = 8;
  11.400 +        } else {
  11.401 +        	devdata->keyboard[devdata->num_keyboard].map = linux_scancode_table;
  11.402 +        	devdata->keyboard[devdata->num_keyboard].map_size = SDL_arraysize(linux_scancode_table);
  11.403 +			devdata->keyboard[devdata->num_keyboard].map_adjust = 0;
  11.404 +        }
  11.405  
  11.406 +		SDL_DFB_LOG("Keyboard %d - %s\n", device_id, desc.name);
  11.407 +		
  11.408          SDL_GetDefaultKeymap(keymap);
  11.409  #if USE_MULTI_API
  11.410          SDL_SetKeymap(devdata->num_keyboard, 0, keymap, SDL_NUM_SCANCODES);
  11.411 @@ -707,74 +747,3 @@
  11.412  
  11.413  }
  11.414  
  11.415 -#if 0
  11.416 -/* FIXME: Remove once determined this is not needed in fullscreen mode */
  11.417 -void
  11.418 -DirectFB_PumpEvents(_THIS)
  11.419 -{
  11.420 -    SDL_DFB_DEVICEDATA(_this);
  11.421 -    DFBInputEvent evt;
  11.422 -    static last_x = 0, last_y = 0;
  11.423 -
  11.424 -    while (devdata->eventbuffer->GetEvent(devdata->eventbuffer,
  11.425 -                                          DFB_EVENT(&evt)) == DFB_OK) {
  11.426 -        SDL_KeySym keysym;
  11.427 -        DFBInputDeviceModifierMask mod;
  11.428 -
  11.429 -        if (evt.clazz = DFEC_INPUT) {
  11.430 -            if (evt.flags & DIEF_MODIFIERS)
  11.431 -                mod = evt.modifiers;
  11.432 -            else
  11.433 -                mod = 0;
  11.434 -
  11.435 -            switch (evt.type) {
  11.436 -            case DIET_BUTTONPRESS:
  11.437 -                posted +=
  11.438 -                    SDL_PrivateMouseButton(SDL_PRESSED,
  11.439 -                                           DirectFB_TranslateButton
  11.440 -                                           (evt.button), 0, 0);
  11.441 -                break;
  11.442 -            case DIET_BUTTONRELEASE:
  11.443 -                posted +=
  11.444 -                    SDL_PrivateMouseButton(SDL_RELEASED,
  11.445 -                                           DirectFB_TranslateButton
  11.446 -                                           (evt.button), 0, 0);
  11.447 -                break;
  11.448 -            case DIET_KEYPRESS:
  11.449 -                posted +=
  11.450 -                    SDL_PrivateKeyboard(SDL_PRESSED,
  11.451 -                                        DirectFB_TranslateKey
  11.452 -                                        (evt.key_id, evt.key_symbol,
  11.453 -                                         mod, &keysym));
  11.454 -                break;
  11.455 -            case DIET_KEYRELEASE:
  11.456 -                posted +=
  11.457 -                    SDL_PrivateKeyboard(SDL_RELEASED,
  11.458 -                                        DirectFB_TranslateKey
  11.459 -                                        (evt.key_id, evt.key_symbol,
  11.460 -                                         mod, &keysym));
  11.461 -                break;
  11.462 -            case DIET_AXISMOTION:
  11.463 -                if (evt.flags & DIEF_AXISREL) {
  11.464 -                    if (evt.axis == DIAI_X)
  11.465 -                        posted +=
  11.466 -                            SDL_PrivateMouseMotion(0, 1, evt.axisrel, 0);
  11.467 -                    else if (evt.axis == DIAI_Y)
  11.468 -                        posted +=
  11.469 -                            SDL_PrivateMouseMotion(0, 1, 0, evt.axisrel);
  11.470 -                } else if (evt.flags & DIEF_AXISABS) {
  11.471 -                    if (evt.axis == DIAI_X)
  11.472 -                        last_x = evt.axisabs;
  11.473 -                    else if (evt.axis == DIAI_Y)
  11.474 -                        last_y = evt.axisabs;
  11.475 -                    posted += SDL_PrivateMouseMotion(0, 0, last_x, last_y);
  11.476 -                }
  11.477 -                break;
  11.478 -            default:
  11.479 -                ;
  11.480 -            }
  11.481 -        }
  11.482 -    }
  11.483 -}
  11.484 -#endif
  11.485 -
    12.1 --- a/src/video/directfb/SDL_DirectFB_events.h	Sat Feb 05 16:02:30 2011 -0800
    12.2 +++ b/src/video/directfb/SDL_DirectFB_events.h	Sat Feb 05 16:07:10 2011 -0800
    12.3 @@ -18,13 +18,19 @@
    12.4  
    12.5      Sam Lantinga
    12.6      slouken@libsdl.org
    12.7 +
    12.8 +    SDL1.3 DirectFB driver by couriersud@arcor.de
    12.9 +	
   12.10  */
   12.11 -#include "SDL_config.h"
   12.12  
   12.13 -#include "SDL_DirectFB_video.h"
   12.14 +#ifndef _SDL_DirectFB_events_h
   12.15 +#define _SDL_DirectFB_events_h
   12.16 +
   12.17 +#include "../SDL_sysvideo.h"
   12.18  
   12.19  /* Functions to be exported */
   12.20  extern void DirectFB_InitKeyboard(_THIS);
   12.21  extern void DirectFB_QuitKeyboard(_THIS);
   12.22  extern void DirectFB_PumpEventsWindow(_THIS);
   12.23 -extern SDLKey DirectFB_GetLayoutKey(_THIS, SDLKey physicalKey);
   12.24 +
   12.25 +#endif
    13.1 --- a/src/video/directfb/SDL_DirectFB_modes.c	Sat Feb 05 16:02:30 2011 -0800
    13.2 +++ b/src/video/directfb/SDL_DirectFB_modes.c	Sat Feb 05 16:07:10 2011 -0800
    13.3 @@ -18,14 +18,17 @@
    13.4  
    13.5      Sam Lantinga
    13.6      slouken@libsdl.org
    13.7 +
    13.8 +    SDL1.3 DirectFB driver by couriersud@arcor.de
    13.9 +	
   13.10  */
   13.11 -#include "SDL_config.h"
   13.12  
   13.13  #include "SDL_DirectFB_video.h"
   13.14 +#include "SDL_DirectFB_modes.h"
   13.15  
   13.16  #define DFB_MAX_MODES 200
   13.17  
   13.18 -struct scn_callback_t
   13.19 +struct screen_callback_t
   13.20  {
   13.21      int numscreens;
   13.22      DFBScreenID screenid[DFB_MAX_SCREENS];
   13.23 @@ -40,103 +43,6 @@
   13.24      SDL_DisplayMode *modelist;
   13.25  };
   13.26  
   13.27 -static const struct {
   13.28 -    DFBSurfacePixelFormat dfb;
   13.29 -    Uint32 sdl;
   13.30 -} pixelformat_tab[] = 
   13.31 -{
   13.32 -    { DSPF_LUT8, SDL_PIXELFORMAT_INDEX8 },              /* 8 bit LUT (8 bit color and alpha lookup from palette) */
   13.33 -    { DSPF_RGB332, SDL_PIXELFORMAT_RGB332 },            /* 8 bit RGB (1 byte, red 3@5, green 3@2, blue 2@0) */
   13.34 -    { DSPF_ARGB4444, SDL_PIXELFORMAT_ARGB4444 },        /* 16 bit ARGB (2 byte, alpha 4@12, red 4@8, green 4@4, blue 4@0) */
   13.35 -    { DSPF_ARGB1555, SDL_PIXELFORMAT_ARGB1555 },        /* 16 bit ARGB (2 byte, alpha 1@15, red 5@10, green 5@5, blue 5@0) */
   13.36 -    { DSPF_RGB16, SDL_PIXELFORMAT_RGB565 },             /* 16 bit RGB (2 byte, red 5@11, green 6@5, blue 5@0) */
   13.37 -    { DSPF_RGB24, SDL_PIXELFORMAT_RGB24 },              /* 24 bit RGB (3 byte, red 8@16, green 8@8, blue 8@0) */
   13.38 -    { DSPF_RGB32, SDL_PIXELFORMAT_RGB888 },             /* 24 bit RGB (4 byte, nothing@24, red 8@16, green 8@8, blue 8@0) */
   13.39 -    { DSPF_ARGB, SDL_PIXELFORMAT_ARGB8888 },            /* 32 bit ARGB (4 byte, alpha 8@24, red 8@16, green 8@8, blue 8@0) */
   13.40 -    { DSPF_RGB444, SDL_PIXELFORMAT_RGB444 },            /* 16 bit RGB (2 byte, nothing @12, red 4@8, green 4@4, blue 4@0) */
   13.41 -    { DSPF_YV12, SDL_PIXELFORMAT_YV12 },                /* 12 bit YUV (8 bit Y plane followed by 8 bit quarter size V/U planes) */
   13.42 -    { DSPF_I420,SDL_PIXELFORMAT_IYUV },                 /* 12 bit YUV (8 bit Y plane followed by 8 bit quarter size U/V planes) */
   13.43 -    { DSPF_YUY2, SDL_PIXELFORMAT_YUY2 },                /* 16 bit YUV (4 byte/ 2 pixel, macropixel contains CbYCrY [31:0]) */
   13.44 -    { DSPF_UYVY, SDL_PIXELFORMAT_UYVY },                /* 16 bit YUV (4 byte/ 2 pixel, macropixel contains YCbYCr [31:0]) */
   13.45 -    { DSPF_RGB555, SDL_PIXELFORMAT_RGB555 },            /* 16 bit RGB (2 byte, nothing @15, red 5@10, green 5@5, blue 5@0) */
   13.46 -
   13.47 -#if (DFB_VERSION_ATLEAST(1,2,0))
   13.48 -    { DSPF_BGR555, SDL_PIXELFORMAT_BGR555 },            /* 16 bit BGR (2 byte, nothing @15, blue 5@10, green 5@5, red 5@0) */
   13.49 -#else
   13.50 -    { DSPF_UNKNOWN, SDL_PIXELFORMAT_BGR555 },
   13.51 -#endif
   13.52 -
   13.53 -    /* Pfff ... nonmatching formats follow */    
   13.54 -    
   13.55 -    { DSPF_ALUT44, SDL_PIXELFORMAT_UNKNOWN },           /* 8 bit ALUT (1 byte, alpha 4@4, color lookup 4@0) */
   13.56 - 	{ DSPF_A8, SDL_PIXELFORMAT_UNKNOWN },               /* 	8 bit alpha (1 byte, alpha 8@0), e.g. anti-aliased glyphs */
   13.57 - 	{ DSPF_AiRGB, SDL_PIXELFORMAT_UNKNOWN },            /* 	32 bit ARGB (4 byte, inv. alpha 8@24, red 8@16, green 8@8, blue 8@0) */
   13.58 - 	{ DSPF_A1, SDL_PIXELFORMAT_UNKNOWN },               /* 	1 bit alpha (1 byte/ 8 pixel, most significant bit used first) */
   13.59 - 	{ DSPF_NV12, SDL_PIXELFORMAT_UNKNOWN },             /* 	12 bit YUV (8 bit Y plane followed by one 16 bit quarter size CbCr [15:0] plane) */
   13.60 - 	{ DSPF_NV16, SDL_PIXELFORMAT_UNKNOWN },             /* 	16 bit YUV (8 bit Y plane followed by one 16 bit half width CbCr [15:0] plane) */
   13.61 - 	{ DSPF_ARGB2554, SDL_PIXELFORMAT_UNKNOWN },         /* 	16 bit ARGB (2 byte, alpha 2@14, red 5@9, green 5@4, blue 4@0) */
   13.62 - 	{ DSPF_NV21, SDL_PIXELFORMAT_UNKNOWN },             /* 	12 bit YUV (8 bit Y plane followed by one 16 bit quarter size CrCb [15:0] plane) */
   13.63 - 	{ DSPF_AYUV, SDL_PIXELFORMAT_UNKNOWN },             /* 	32 bit AYUV (4 byte, alpha 8@24, Y 8@16, Cb 8@8, Cr 8@0) */
   13.64 - 	{ DSPF_A4, SDL_PIXELFORMAT_UNKNOWN },               /* 	4 bit alpha (1 byte/ 2 pixel, more significant nibble used first) */
   13.65 - 	{ DSPF_ARGB1666, SDL_PIXELFORMAT_UNKNOWN },         /* 	1 bit alpha (3 byte/ alpha 1@18, red 6@16, green 6@6, blue 6@0) */
   13.66 - 	{ DSPF_ARGB6666, SDL_PIXELFORMAT_UNKNOWN },         /* 	6 bit alpha (3 byte/ alpha 6@18, red 6@16, green 6@6, blue 6@0) */
   13.67 - 	{ DSPF_RGB18, SDL_PIXELFORMAT_UNKNOWN },            /* 	6 bit RGB (3 byte/ red 6@16, green 6@6, blue 6@0) */
   13.68 - 	{ DSPF_LUT2, SDL_PIXELFORMAT_UNKNOWN },             /* 	2 bit LUT (1 byte/ 4 pixel, 2 bit color and alpha lookup from palette) */
   13.69 -
   13.70 -#if (DFB_VERSION_ATLEAST(1,3,0))
   13.71 - 	{ DSPF_RGBA4444, SDL_PIXELFORMAT_UNKNOWN },         /* 16 bit RGBA (2 byte, red 4@12, green 4@8, blue 4@4, alpha 4@0) */
   13.72 -#endif
   13.73 -
   13.74 -#if (DFB_VERSION_ATLEAST(1,4,0))
   13.75 - 	{ DSPF_RGBA5551, SDL_PIXELFORMAT_UNKNOWN },         /* 	16 bit RGBA (2 byte, red 5@11, green 5@6, blue 5@1, alpha 1@0) */
   13.76 - 	{ 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) */
   13.77 - 	{ DSPF_ARGB8565, SDL_PIXELFORMAT_UNKNOWN },         /* 	24 bit ARGB (3 byte, alpha 8@16, red 5@11, green 6@5, blue 5@0) */
   13.78 - 	{ 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) */
   13.79 - 	{ DSPF_VYU, SDL_PIXELFORMAT_UNKNOWN },              /* 	24 bit VYU 4:4:4 (3 byte, Cr 8@16, Y 8@8, Cb 8@0)  */
   13.80 -#endif
   13.81 - 	
   13.82 -    { DSPF_UNKNOWN, SDL_PIXELFORMAT_INDEX1LSB },
   13.83 -    { DSPF_UNKNOWN, SDL_PIXELFORMAT_INDEX1MSB },
   13.84 -    { DSPF_UNKNOWN, SDL_PIXELFORMAT_INDEX4LSB }, 
   13.85 -    { DSPF_UNKNOWN, SDL_PIXELFORMAT_INDEX4MSB },
   13.86 -    { DSPF_UNKNOWN, SDL_PIXELFORMAT_BGR24 },
   13.87 -    { DSPF_UNKNOWN, SDL_PIXELFORMAT_BGR888 },
   13.88 -    { DSPF_UNKNOWN, SDL_PIXELFORMAT_RGBA8888 },
   13.89 -    { DSPF_UNKNOWN, SDL_PIXELFORMAT_ABGR8888 },
   13.90 -    { DSPF_UNKNOWN, SDL_PIXELFORMAT_BGRA8888 },
   13.91 -    { DSPF_UNKNOWN, SDL_PIXELFORMAT_ARGB2101010 },
   13.92 -    { DSPF_UNKNOWN, SDL_PIXELFORMAT_ABGR4444 },
   13.93 -    { DSPF_UNKNOWN, SDL_PIXELFORMAT_ABGR1555 },
   13.94 -    { DSPF_UNKNOWN, SDL_PIXELFORMAT_BGR565 },
   13.95 -    { DSPF_UNKNOWN, SDL_PIXELFORMAT_YVYU },                        /**< Packed mode: Y0+V0+Y1+U0 (1 pla	*/
   13.96 -};
   13.97 -
   13.98 -static Uint32
   13.99 -DFBToSDLPixelFormat(DFBSurfacePixelFormat pixelformat)
  13.100 -{
  13.101 -    int i;
  13.102 -    
  13.103 -    for (i=0; pixelformat_tab[i].dfb != DSPF_UNKNOWN; i++)
  13.104 -        if (pixelformat_tab[i].dfb == pixelformat)
  13.105 -        {
  13.106 -            return pixelformat_tab[i].sdl;
  13.107 -        }
  13.108 -    return SDL_PIXELFORMAT_UNKNOWN;
  13.109 -}
  13.110 -
  13.111 -static DFBSurfacePixelFormat
  13.112 -SDLToDFBPixelFormat(Uint32 format)
  13.113 -{
  13.114 -    int i;
  13.115 -    
  13.116 -    for (i=0; pixelformat_tab[i].dfb != DSPF_UNKNOWN; i++)
  13.117 -        if (pixelformat_tab[i].sdl == format)
  13.118 -        {
  13.119 -            return pixelformat_tab[i].dfb;
  13.120 -        }
  13.121 -    return  DSPF_UNKNOWN;
  13.122 -}
  13.123 -
  13.124  static DFBEnumerationResult
  13.125  EnumModesCallback(int width, int height, int bpp, void *data)
  13.126  {
  13.127 @@ -157,20 +63,20 @@
  13.128  }
  13.129  
  13.130  static DFBEnumerationResult
  13.131 -cbScreens(DFBScreenID screen_id, DFBScreenDescription desc,
  13.132 +EnumScreensCallback(DFBScreenID screen_id, DFBScreenDescription desc,
  13.133            void *callbackdata)
  13.134  {
  13.135 -    struct scn_callback_t *devdata = (struct scn_callback_t *) callbackdata;
  13.136 +    struct screen_callback_t *devdata = (struct screen_callback_t *) callbackdata;
  13.137  
  13.138      devdata->screenid[devdata->numscreens++] = screen_id;
  13.139      return DFENUM_OK;
  13.140  }
  13.141  
  13.142 -DFBEnumerationResult
  13.143 -cbLayers(DFBDisplayLayerID layer_id, DFBDisplayLayerDescription desc,
  13.144 +static DFBEnumerationResult
  13.145 +EnumLayersCallback(DFBDisplayLayerID layer_id, DFBDisplayLayerDescription desc,
  13.146           void *callbackdata)
  13.147  {
  13.148 -    struct scn_callback_t *devdata = (struct scn_callback_t *) callbackdata;
  13.149 +    struct screen_callback_t *devdata = (struct screen_callback_t *) callbackdata;
  13.150  
  13.151      if (desc.caps & DLCAPS_SURFACE) {
  13.152          if ((desc.type & DLTF_GRAPHICS) && (desc.type & DLTF_VIDEO)) {
  13.153 @@ -195,7 +101,7 @@
  13.154                                                        DLSCL_ADMINISTRATIVE));
  13.155      config.width = mode->w;
  13.156      config.height = mode->h;
  13.157 -    config.pixelformat = SDLToDFBPixelFormat(mode->format);
  13.158 +    config.pixelformat = DirectFB_SDLToDFBPixelFormat(mode->format);
  13.159      config.flags = DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT;
  13.160      if (devdata->use_yuv_underlays) {
  13.161          config.flags |= DLCONF_OPTIONS;
  13.162 @@ -206,7 +112,10 @@
  13.163      SDL_DFB_CHECKERR(data->layer->SetCooperativeLevel(data->layer,
  13.164                                                        DLSCL_SHARED));
  13.165      if (failed == 0)
  13.166 +    {
  13.167          SDL_AddDisplayMode(display, mode);
  13.168 +        SDL_DFB_LOG("Mode %d x %d Added\n", mode->w, mode->h);
  13.169 +    }
  13.170      else
  13.171          SDL_DFB_ERR("Mode %d x %d not available: %x\n", mode->w,
  13.172                        mode->h, failed);
  13.173 @@ -216,6 +125,26 @@
  13.174      return;
  13.175  }
  13.176  
  13.177 +
  13.178 +void
  13.179 +DirectFB_SetContext(_THIS, SDL_Window *window)
  13.180 +{
  13.181 +#if (DFB_VERSION_ATLEAST(1,0,0))
  13.182 +    /* FIXME: does not work on 1.0/1.2 with radeon driver
  13.183 +     *        the approach did work with the matrox driver
  13.184 +     *        This has simply no effect.
  13.185 +     */
  13.186 +
  13.187 +    SDL_VideoDisplay *display = window->display;
  13.188 +    DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
  13.189 +
  13.190 +	/* FIXME: should we handle the error */
  13.191 +    if (dispdata->vidIDinuse)
  13.192 +        SDL_DFB_CHECK(dispdata->vidlayer->SwitchContext(dispdata->vidlayer,
  13.193 +                                                           DFB_TRUE));
  13.194 +#endif
  13.195 +}
  13.196 +
  13.197  void
  13.198  DirectFB_InitModes(_THIS)
  13.199  {
  13.200 @@ -226,14 +155,14 @@
  13.201      SDL_DisplayMode mode;
  13.202      DFBGraphicsDeviceDescription caps;
  13.203      DFBDisplayLayerConfig dlc;
  13.204 -    struct scn_callback_t *screencbdata;
  13.205 +    struct screen_callback_t *screencbdata;
  13.206  
  13.207      int tcw[DFB_MAX_SCREENS];
  13.208      int tch[DFB_MAX_SCREENS];
  13.209      int i;
  13.210      DFBResult ret;
  13.211  
  13.212 -    SDL_DFB_CALLOC(screencbdata, 1, sizeof(*screencbdata));
  13.213 +    SDL_DFB_ALLOC_CLEAR(screencbdata, sizeof(*screencbdata));
  13.214  
  13.215      screencbdata->numscreens = 0;
  13.216  
  13.217 @@ -242,7 +171,7 @@
  13.218          screencbdata->vidlayer[i] = -1;
  13.219      }
  13.220  
  13.221 -    SDL_DFB_CHECKERR(devdata->dfb->EnumScreens(devdata->dfb, &cbScreens,
  13.222 +    SDL_DFB_CHECKERR(devdata->dfb->EnumScreens(devdata->dfb, &EnumScreensCallback,
  13.223                                                 screencbdata));
  13.224  
  13.225      for (i = 0; i < screencbdata->numscreens; i++) {
  13.226 @@ -253,9 +182,10 @@
  13.227                                                   [i], &screen));
  13.228  
  13.229          screencbdata->aux = i;
  13.230 -        SDL_DFB_CHECKERR(screen->EnumDisplayLayers(screen, &cbLayers,
  13.231 +        SDL_DFB_CHECKERR(screen->EnumDisplayLayers(screen, &EnumLayersCallback,
  13.232                                                     screencbdata));
  13.233          screen->GetSize(screen, &tcw[i], &tch[i]);
  13.234 +
  13.235          screen->Release(screen);
  13.236      }
  13.237  
  13.238 @@ -263,10 +193,6 @@
  13.239  
  13.240      devdata->dfb->GetDeviceDescription(devdata->dfb, &caps);
  13.241  
  13.242 -    SDL_DFB_DEBUG("SDL directfb video driver - %s %s\n", __DATE__, __TIME__);
  13.243 -    SDL_DFB_DEBUG("Using %s (%s) driver.\n", caps.name, caps.vendor);
  13.244 -    SDL_DFB_DEBUG("Found %d screens\n", screencbdata->numscreens);
  13.245 -
  13.246      for (i = 0; i < screencbdata->numscreens; i++) {
  13.247          SDL_DFB_CHECKERR(devdata->dfb->GetDisplayLayer(devdata->dfb,
  13.248                                                         screencbdata->gralayer
  13.249 @@ -282,7 +208,7 @@
  13.250              dlc.pixelformat = DSPF_ARGB;
  13.251              dlc.options = DLOP_ALPHACHANNEL;
  13.252  
  13.253 -            ret = SDL_DFB_CHECK(layer->SetConfiguration(layer, &dlc));
  13.254 +            ret = layer->SetConfiguration(layer, &dlc);
  13.255              if (ret != DFB_OK) {
  13.256                  /* try AiRGB if the previous failed */
  13.257                  dlc.pixelformat = DSPF_AiRGB;
  13.258 @@ -294,7 +220,7 @@
  13.259          dlc.flags = DLCONF_ALL;
  13.260          SDL_DFB_CHECKERR(layer->GetConfiguration(layer, &dlc));
  13.261  
  13.262 -        mode.format = DFBToSDLPixelFormat(dlc.pixelformat);
  13.263 +        mode.format = DirectFB_DFBToSDLPixelFormat(dlc.pixelformat);
  13.264          
  13.265          if (mode.format == SDL_PIXELFORMAT_UNKNOWN) {
  13.266              SDL_DFB_ERR("Unknown dfb pixelformat %x !\n", dlc.pixelformat);
  13.267 @@ -306,7 +232,7 @@
  13.268          mode.refresh_rate = 0;
  13.269          mode.driverdata = NULL;
  13.270  
  13.271 -        SDL_DFB_CALLOC(dispdata, 1, sizeof(*dispdata));
  13.272 +        SDL_DFB_ALLOC_CLEAR(dispdata, sizeof(*dispdata));
  13.273  
  13.274          dispdata->layer = layer;
  13.275          dispdata->pixelformat = dlc.pixelformat;
  13.276 @@ -399,7 +325,7 @@
  13.277      config.flags = DLCONF_WIDTH | DLCONF_HEIGHT;
  13.278      if (mode->format != SDL_PIXELFORMAT_UNKNOWN) {
  13.279          config.flags |= DLCONF_PIXELFORMAT;
  13.280 -        config.pixelformat = SDLToDFBPixelFormat(mode->format);
  13.281 +        config.pixelformat = DirectFB_SDLToDFBPixelFormat(mode->format);
  13.282          data->pixelformat = config.pixelformat;
  13.283      }
  13.284      config.width = mode->w;
  13.285 @@ -420,7 +346,6 @@
  13.286          return -1;
  13.287      }
  13.288  
  13.289 -    SDL_DFB_DEBUG("Trace\n");
  13.290      config.flags &= ~fail;
  13.291      SDL_DFB_CHECKERR(data->layer->SetConfiguration(data->layer, &config));
  13.292  #if (DFB_VERSION_ATLEAST(1,2,0))
  13.293 @@ -454,7 +379,6 @@
  13.294  void
  13.295  DirectFB_QuitModes(_THIS)
  13.296  {
  13.297 -    //DFB_DeviceData *devdata = (DFB_DeviceData *) _this->driverdata;
  13.298      SDL_DisplayMode tmode;
  13.299      int i;
  13.300  
    14.1 --- a/src/video/directfb/SDL_DirectFB_modes.h	Sat Feb 05 16:02:30 2011 -0800
    14.2 +++ b/src/video/directfb/SDL_DirectFB_modes.h	Sat Feb 05 16:07:10 2011 -0800
    14.3 @@ -18,32 +18,36 @@
    14.4  
    14.5      Sam Lantinga
    14.6      slouken@libsdl.org
    14.7 +
    14.8 +    SDL1.3 DirectFB driver by couriersud@arcor.de
    14.9 +	
   14.10  */
   14.11 -#include "SDL_config.h"
   14.12  
   14.13  #ifndef _SDL_directfb_modes_h
   14.14  #define _SDL_directfb_modes_h
   14.15  
   14.16 -#include "SDL_DirectFB_video.h"
   14.17 +#include <directfb.h>
   14.18  
   14.19 -#define SDL_DFB_DISPLAYDATA(dev, win)  DFB_DisplayData *dispdata = ((win && dev) ? (DFB_DisplayData *) (win)->display->driverdata : NULL)
   14.20 +#include "../SDL_sysvideo.h"
   14.21 +
   14.22 +#define SDL_DFB_DISPLAYDATA(win)  DFB_DisplayData *dispdata = ((win) ? (DFB_DisplayData *) (win)->display->driverdata : NULL)
   14.23  
   14.24  typedef struct _DFB_DisplayData DFB_DisplayData;
   14.25  struct _DFB_DisplayData
   14.26  {
   14.27 -    IDirectFBDisplayLayer *layer;
   14.28 -    DFBSurfacePixelFormat pixelformat;
   14.29 +    IDirectFBDisplayLayer 	*layer;
   14.30 +    DFBSurfacePixelFormat 	pixelformat;
   14.31      /* FIXME: support for multiple video layer. 
   14.32       * However, I do not know any card supporting 
   14.33       * more than one
   14.34       */
   14.35 -    DFBDisplayLayerID vidID;
   14.36 -    IDirectFBDisplayLayer *vidlayer;
   14.37 +    DFBDisplayLayerID 		vidID;
   14.38 +    IDirectFBDisplayLayer 	*vidlayer;
   14.39  
   14.40 -    int vidIDinuse;
   14.41 +    int 					vidIDinuse;
   14.42  
   14.43 -    int cw;
   14.44 -    int ch;
   14.45 +    int 					cw;
   14.46 +    int 					ch;
   14.47  };
   14.48  
   14.49  
   14.50 @@ -52,6 +56,8 @@
   14.51  extern int DirectFB_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
   14.52  extern void DirectFB_QuitModes(_THIS);
   14.53  
   14.54 +extern void DirectFB_SetContext(_THIS, SDL_Window *window);
   14.55 +
   14.56  #endif /* _SDL_directfb_modes_h */
   14.57  
   14.58  /* vi: set ts=4 sw=4 expandtab: */
    15.1 --- a/src/video/directfb/SDL_DirectFB_mouse.c	Sat Feb 05 16:02:30 2011 -0800
    15.2 +++ b/src/video/directfb/SDL_DirectFB_mouse.c	Sat Feb 05 16:07:10 2011 -0800
    15.3 @@ -18,7 +18,11 @@
    15.4  
    15.5      Sam Lantinga
    15.6      slouken@libsdl.org
    15.7 +
    15.8 +    SDL1.3 DirectFB driver by couriersud@arcor.de
    15.9 +	
   15.10  */
   15.11 +
   15.12  #include "SDL_config.h"
   15.13  
   15.14  #include "SDL_DirectFB_video.h"
   15.15 @@ -123,8 +127,8 @@
   15.16      Uint32 *p;
   15.17      int pitch, i;
   15.18  
   15.19 -    SDL_DFB_CALLOC(cursor, 1, sizeof(*cursor));
   15.20 -    SDL_DFB_CALLOC(curdata, 1, sizeof(*curdata));
   15.21 +    SDL_DFB_ALLOC_CLEAR(cursor, 1, sizeof(*cursor));
   15.22 +    SDL_DFB_ALLOC_CLEAR(curdata, 1, sizeof(*curdata));
   15.23  
   15.24      dsc.flags =
   15.25          DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS;
   15.26 @@ -175,7 +179,7 @@
   15.27  
   15.28              if (cursor)
   15.29                  SDL_DFB_CHECKERR(windata->window->
   15.30 -                                 SetCursorShape(windata->window,
   15.31 +                                 SetCursorShape(windata->dfbwin,
   15.32                                                  curdata->surf, curdata->hotx,
   15.33                                                  curdata->hoty));
   15.34  
   15.35 @@ -224,7 +228,7 @@
   15.36      DFBResult ret;
   15.37      int cx, cy;
   15.38  
   15.39 -    SDL_DFB_CHECKERR(windata->window->GetPosition(windata->window, &cx, &cy));
   15.40 +    SDL_DFB_CHECKERR(windata->dfbwin->GetPosition(windata->dfbwin, &cx, &cy));
   15.41      SDL_DFB_CHECKERR(dispdata->layer->WarpCursor(dispdata->layer,
   15.42                                                   cx + x + windata->client.x,
   15.43                                                   cy + y + windata->client.y));
   15.44 @@ -253,7 +257,6 @@
   15.45  void
   15.46  DirectFB_QuitMouse(_THIS)
   15.47  {
   15.48 -    //SDL_DFB_DEVICEDATA(_this);
   15.49  }
   15.50  
   15.51  
    16.1 --- a/src/video/directfb/SDL_DirectFB_mouse.h	Sat Feb 05 16:02:30 2011 -0800
    16.2 +++ b/src/video/directfb/SDL_DirectFB_mouse.h	Sat Feb 05 16:07:10 2011 -0800
    16.3 @@ -18,19 +18,24 @@
    16.4  
    16.5      Sam Lantinga
    16.6      slouken@libsdl.org
    16.7 +
    16.8 +    SDL1.3 DirectFB driver by couriersud@arcor.de
    16.9 +	
   16.10  */
   16.11 -#include "SDL_config.h"
   16.12  
   16.13  #ifndef _SDL_DirectFB_mouse_h
   16.14  #define _SDL_DirectFB_mouse_h
   16.15  
   16.16 +#include <directfb.h>
   16.17 +
   16.18 +#include "../SDL_sysvideo.h"
   16.19 +
   16.20  typedef struct _DFB_CursorData DFB_CursorData;
   16.21 -
   16.22  struct _DFB_CursorData
   16.23  {
   16.24      IDirectFBSurface *surf;
   16.25 -    int hotx;
   16.26 -    int hoty;
   16.27 +    int 			hotx;
   16.28 +    int 			hoty;
   16.29  };
   16.30  
   16.31  #define SDL_DFB_CURSORDATA(curs)  DFB_CursorData *curdata = (DFB_CursorData *) ((curs) ? (curs)->driverdata : NULL)
    17.1 --- a/src/video/directfb/SDL_DirectFB_opengl.c	Sat Feb 05 16:02:30 2011 -0800
    17.2 +++ b/src/video/directfb/SDL_DirectFB_opengl.c	Sat Feb 05 16:07:10 2011 -0800
    17.3 @@ -13,17 +13,27 @@
    17.4      Lesser General Public License for more details.
    17.5  
    17.6      You should have received a copy of the GNU Lesser General Public
    17.7 -    License along with _this library; if not, write to the Free Software
    17.8 +    License along with this library; if not, write to the Free Software
    17.9      Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   17.10  
   17.11      Sam Lantinga
   17.12      slouken@libsdl.org
   17.13 +
   17.14 +    SDL1.3 DirectFB driver by couriersud@arcor.de
   17.15 +	
   17.16  */
   17.17 -#include "SDL_config.h"
   17.18  
   17.19  #include "SDL_DirectFB_video.h"
   17.20  
   17.21  #if SDL_DIRECTFB_OPENGL
   17.22 +#include "SDL_DirectFB_opengl.h"
   17.23 +#include "SDL_DirectFB_window.h"
   17.24 +
   17.25 +#include <directfbgl.h>
   17.26 +#include "SDL_loadso.h"
   17.27 +#endif
   17.28 +
   17.29 +#if SDL_DIRECTFB_OPENGL
   17.30  
   17.31  struct SDL_GLDriverData
   17.32  {
   17.33 @@ -177,7 +187,7 @@
   17.34      SDL_DFB_WINDOWDATA(window);
   17.35      DirectFB_GLContext *context;
   17.36  
   17.37 -    SDL_DFB_CALLOC(context, 1, sizeof(DirectFB_GLContext));
   17.38 +    SDL_DFB_ALLOC_CLEAR(context, sizeof(DirectFB_GLContext));
   17.39  
   17.40      SDL_DFB_CHECKERR(windata->surface->GetGL(windata->surface,
   17.41                                               &context->context));
    18.1 --- a/src/video/directfb/SDL_DirectFB_opengl.h	Sat Feb 05 16:02:30 2011 -0800
    18.2 +++ b/src/video/directfb/SDL_DirectFB_opengl.h	Sat Feb 05 16:07:10 2011 -0800
    18.3 @@ -18,23 +18,29 @@
    18.4  
    18.5      Sam Lantinga
    18.6      slouken@libsdl.org
    18.7 +
    18.8 +    SDL1.3 DirectFB driver by couriersud@arcor.de
    18.9 +	
   18.10  */
   18.11 -#include "SDL_config.h"
   18.12 +
   18.13  
   18.14  #ifndef _SDL_directfb_opengl_h
   18.15  #define _SDL_directfb_opengl_h
   18.16  
   18.17 +#include "SDL_DirectFB_video.h"
   18.18 +
   18.19  #if SDL_DIRECTFB_OPENGL
   18.20 +
   18.21  #include "SDL_opengl.h"
   18.22  
   18.23  typedef struct _DirectFB_GLContext DirectFB_GLContext;
   18.24  struct _DirectFB_GLContext
   18.25  {
   18.26 -    IDirectFBGL *context;
   18.27 -    DirectFB_GLContext *next;
   18.28 +    IDirectFBGL 		*context;
   18.29 +    DirectFB_GLContext 	*next;
   18.30      
   18.31 -    SDL_Window *sdl_window;
   18.32 -    int is_locked;
   18.33 +    SDL_Window 			*sdl_window;
   18.34 +    int 				is_locked;
   18.35  };
   18.36  
   18.37  /* OpenGL functions */
    19.1 --- a/src/video/directfb/SDL_DirectFB_render.c	Sat Feb 05 16:02:30 2011 -0800
    19.2 +++ b/src/video/directfb/SDL_DirectFB_render.c	Sat Feb 05 16:07:10 2011 -0800
    19.3 @@ -18,47 +18,74 @@
    19.4  
    19.5      Sam Lantinga
    19.6      slouken@libsdl.org
    19.7 -    
    19.8 -    SDL1.3 implementation by couriersud@arcor.de
    19.9 -    
   19.10 +
   19.11 +    SDL1.3 DirectFB driver by couriersud@arcor.de
   19.12 +	
   19.13  */
   19.14 -#include "SDL_config.h"
   19.15 +#include "SDL_DirectFB_video.h"
   19.16 +#include "SDL_DirectFB_window.h"
   19.17 +#include "SDL_DirectFB_modes.h"
   19.18  
   19.19 -#include "SDL_DirectFB_video.h"
   19.20 -#include "SDL_DirectFB_render.h"
   19.21 -#include "../SDL_yuv_sw_c.h"
   19.22 +#include "SDL_DirectFB_shape.h"
   19.23 +
   19.24 +#include "../SDL_sysvideo.h"
   19.25 +#include "../../render/SDL_sysrender.h"
   19.26 +//#include "../SDL_rect_c.h"
   19.27 +//#include "../SDL_yuv_sw_c.h"
   19.28  
   19.29  /* the following is not yet tested ... */
   19.30  #define USE_DISPLAY_PALETTE			(0)
   19.31  
   19.32 +
   19.33 +#define SDL_DFB_RENDERERDATA(rend) DirectFB_RenderData *renddata = ((rend) ? (DirectFB_RenderData *) (rend)->driverdata : NULL)
   19.34 +
   19.35 +
   19.36  /* GDI renderer implementation */
   19.37  
   19.38  static SDL_Renderer *DirectFB_CreateRenderer(SDL_Window * window,
   19.39                                               Uint32 flags);
   19.40 -static int DirectFB_DisplayModeChanged(SDL_Renderer * renderer);
   19.41 -static int DirectFB_ActivateRenderer(SDL_Renderer * renderer);
   19.42 +static void DirectFB_ActivateRenderer(SDL_Renderer * renderer);
   19.43  static int DirectFB_CreateTexture(SDL_Renderer * renderer,
   19.44                                    SDL_Texture * texture);
   19.45  static int DirectFB_QueryTexturePixels(SDL_Renderer * renderer,
   19.46                                         SDL_Texture * texture,
   19.47                                         void **pixels, int *pitch);
   19.48 +static int DirectFB_SetTexturePalette(SDL_Renderer * renderer,
   19.49 +                                      SDL_Texture * texture,
   19.50 +                                      const SDL_Color * colors,
   19.51 +                                      int firstcolor, int ncolors);
   19.52 +static int DirectFB_GetTexturePalette(SDL_Renderer * renderer,
   19.53 +                                      SDL_Texture * texture,
   19.54 +                                      SDL_Color * colors,
   19.55 +                                      int firstcolor, int ncolors);
   19.56 +static int DirectFB_SetTextureAlphaMod(SDL_Renderer * renderer,
   19.57 +                                       SDL_Texture * texture);
   19.58 +static int DirectFB_SetTextureColorMod(SDL_Renderer * renderer,
   19.59 +                                       SDL_Texture * texture);
   19.60 +static int DirectFB_SetTextureBlendMode(SDL_Renderer * renderer,
   19.61 +                                        SDL_Texture * texture);
   19.62 +static int DirectFB_SetTextureScaleMode(SDL_Renderer * renderer,
   19.63 +                                        SDL_Texture * texture);
   19.64  static int DirectFB_UpdateTexture(SDL_Renderer * renderer,
   19.65                                    SDL_Texture * texture,
   19.66                                    const SDL_Rect * rect,
   19.67                                    const void *pixels, int pitch);
   19.68  static int DirectFB_LockTexture(SDL_Renderer * renderer,
   19.69                                  SDL_Texture * texture,
   19.70 -                                const SDL_Rect * rect, int markDirty,
   19.71 +                                const SDL_Rect * rect,
   19.72                                  void **pixels, int *pitch);
   19.73  static void DirectFB_UnlockTexture(SDL_Renderer * renderer,
   19.74                                     SDL_Texture * texture);
   19.75  static void DirectFB_DirtyTexture(SDL_Renderer * renderer,
   19.76                                    SDL_Texture * texture, int numrects,
   19.77                                    const SDL_Rect * rects);
   19.78 +static int DirectFB_SetDrawBlendMode(SDL_Renderer * renderer);
   19.79  static int DirectFB_RenderDrawPoints(SDL_Renderer * renderer,
   19.80                                  const SDL_Point * points, int count);
   19.81  static int DirectFB_RenderDrawLines(SDL_Renderer * renderer,
   19.82                                 const SDL_Point * points, int count);
   19.83 +static int DirectFB_RenderDrawRects(SDL_Renderer * renderer,
   19.84 +		const SDL_Rect ** rects, int count);
   19.85  static int DirectFB_RenderFillRects(SDL_Renderer * renderer,
   19.86  		const SDL_Rect ** rects, int count);
   19.87  static int DirectFB_RenderCopy(SDL_Renderer * renderer,
   19.88 @@ -69,6 +96,11 @@
   19.89  static void DirectFB_DestroyTexture(SDL_Renderer * renderer,
   19.90                                      SDL_Texture * texture);
   19.91  static void DirectFB_DestroyRenderer(SDL_Renderer * renderer);
   19.92 +static int DirectFB_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
   19.93 +                     Uint32 format, void * pixels, int pitch);
   19.94 +static int DirectFB_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
   19.95 +                      Uint32 format, const void * pixels, int pitch);
   19.96 +
   19.97  
   19.98  #define SDL_DFB_WINDOWSURFACE(win)  IDirectFBSurface *destsurf = ((DFB_WindowData *) ((win)->driverdata))->surface;
   19.99  
  19.100 @@ -77,20 +109,16 @@
  19.101      {
  19.102       "directfb",
  19.103       (SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED),
  19.104 -     12,
  19.105 +     /* (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR |
  19.106 +      SDL_TEXTUREMODULATE_ALPHA),
  19.107 +      (SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK | SDL_BLENDMODE_BLEND |
  19.108 +      SDL_BLENDMODE_ADD | SDL_BLENDMODE_MOD),
  19.109 +     (SDL_SCALEMODE_NONE | SDL_SCALEMODE_FAST |
  19.110 +      SDL_SCALEMODE_SLOW | SDL_SCALEMODE_BEST),*/
  19.111 +     0,
  19.112       {
  19.113 -      SDL_PIXELFORMAT_RGB332,
  19.114 -      SDL_PIXELFORMAT_RGB555,
  19.115 -      SDL_PIXELFORMAT_RGB565,
  19.116 -      SDL_PIXELFORMAT_RGB888,
  19.117 -      SDL_PIXELFORMAT_ARGB8888,
  19.118 -      SDL_PIXELFORMAT_ARGB4444,
  19.119 -      SDL_PIXELFORMAT_ARGB1555,
  19.120 -      SDL_PIXELFORMAT_RGB24,
  19.121 -      SDL_PIXELFORMAT_YV12,
  19.122 -      SDL_PIXELFORMAT_IYUV,
  19.123 -      SDL_PIXELFORMAT_YUY2,
  19.124 -      SDL_PIXELFORMAT_UYVY},
  19.125 +    		 /* formats filled in later */
  19.126 +     },
  19.127       0,
  19.128       0}
  19.129  };
  19.130 @@ -99,7 +127,6 @@
  19.131  {
  19.132      SDL_Window *window;
  19.133      DFBSurfaceFlipFlags flipflags;
  19.134 -    int isyuvdirect;
  19.135      int size_changed;
  19.136      int lastBlendMode;
  19.137      DFBSurfaceBlittingFlags blitFlags;
  19.138 @@ -112,8 +139,11 @@
  19.139      Uint32 format;
  19.140      void *pixels;
  19.141      int pitch;
  19.142 -    SDL_VideoDisplay *display;
  19.143 -    SDL_DirtyRectList dirty;
  19.144 +    IDirectFBPalette *palette;
  19.145 +    int isDirty;
  19.146 +
  19.147 +    SDL_VideoDisplay *display;      /* only for yuv textures */
  19.148 +
  19.149  #if (DFB_VERSION_ATLEAST(1,2,0))
  19.150      DFBSurfaceRenderOptions render_options;
  19.151  #endif
  19.152 @@ -135,7 +165,12 @@
  19.153      /* Drawing primitive ? */
  19.154      if (!data)
  19.155          return 0;
  19.156 +        
  19.157 +    return (DFB_PIXELFORMAT_HAS_ALPHA(DirectFB_SDLToDFBPixelFormat(data->format)) ? 1 : 0);
  19.158 +#if 0
  19.159      switch (data->format) {
  19.160 +    case SDL_PIXELFORMAT_INDEX4LSB:
  19.161 +    case SDL_PIXELFORMAT_INDEX4MSB:
  19.162      case SDL_PIXELFORMAT_ARGB4444:
  19.163      case SDL_PIXELFORMAT_ARGB1555:
  19.164      case SDL_PIXELFORMAT_ARGB8888:
  19.165 @@ -143,10 +178,11 @@
  19.166      case SDL_PIXELFORMAT_ABGR8888:
  19.167      case SDL_PIXELFORMAT_BGRA8888:
  19.168      case SDL_PIXELFORMAT_ARGB2101010:
  19.169 -        return 1;
  19.170 +       return 1;
  19.171      default:
  19.172          return 0;
  19.173      }
  19.174 +#endif
  19.175  }
  19.176  
  19.177  static void
  19.178 @@ -165,6 +201,14 @@
  19.179              SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_ONE));
  19.180              SDL_DFB_CHECK(destsurf->SetDstBlendFunction(destsurf, DSBF_ZERO));
  19.181              break;
  19.182 +#if 0
  19.183 +        case SDL_BLENDMODE_MASK:
  19.184 +            data->blitFlags =  DSBLIT_BLEND_ALPHACHANNEL;
  19.185 +            data->drawFlags = DSDRAW_BLEND;
  19.186 +            SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_SRCALPHA));
  19.187 +            SDL_DFB_CHECK(destsurf->SetDstBlendFunction(destsurf, DSBF_INVSRCALPHA));
  19.188 +            break;
  19.189 +#endif
  19.190          case SDL_BLENDMODE_BLEND:
  19.191              data->blitFlags = DSBLIT_BLEND_ALPHACHANNEL;
  19.192              data->drawFlags = DSDRAW_BLEND;
  19.193 @@ -183,19 +227,74 @@
  19.194                  SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_ONE));
  19.195              SDL_DFB_CHECK(destsurf->SetDstBlendFunction(destsurf, DSBF_ONE));
  19.196              break;
  19.197 +        case SDL_BLENDMODE_MOD:
  19.198 +            data->blitFlags = DSBLIT_BLEND_ALPHACHANNEL;
  19.199 +            data->drawFlags = DSDRAW_BLEND;
  19.200 +            //SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_DESTCOLOR));
  19.201 +            //SDL_DFB_CHECK(destsurf->SetDstBlendFunction(destsurf, DSBF_ZERO));
  19.202 +            //data->glBlendFunc(GL_ZERO, GL_SRC_COLOR);
  19.203 +            SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_ZERO));
  19.204 +            SDL_DFB_CHECK(destsurf->SetDstBlendFunction(destsurf, DSBF_SRCCOLOR));
  19.205 +
  19.206 +            break;
  19.207          }
  19.208          data->lastBlendMode = blendMode;
  19.209      }
  19.210  }
  19.211  
  19.212 -void
  19.213 -DirectFB_AddRenderDriver(_THIS)
  19.214 +static int
  19.215 +DisplayPaletteChanged(void *userdata, SDL_Palette * palette)
  19.216  {
  19.217 +#if USE_DISPLAY_PALETTE
  19.218 +    DirectFB_RenderData *data = (DirectFB_RenderData *) userdata;
  19.219 +    SDL_DFB_WINDOWSURFACE(data->window);
  19.220 +    IDirectFBPalette *surfpal;
  19.221 +
  19.222      int i;
  19.223 +    int ncolors;
  19.224 +    DFBColor entries[256];
  19.225  
  19.226 -    for (i = 0; i < _this->num_displays; ++i) {
  19.227 -        SDL_AddRenderDriver(&_this->displays[i], &DirectFB_RenderDriver);
  19.228 +    SDL_DFB_CHECKERR(destsurf->GetPalette(destsurf, &surfpal));
  19.229 +
  19.230 +    /* FIXME: number of colors */
  19.231 +    ncolors = (palette->ncolors < 256 ? palette->ncolors : 256);
  19.232 +
  19.233 +    for (i = 0; i < ncolors; ++i) {
  19.234 +        entries[i].r = palette->colors[i].r;
  19.235 +        entries[i].g = palette->colors[i].g;
  19.236 +        entries[i].b = palette->colors[i].b;
  19.237 +        entries[i].a = palette->colors[i].unused;
  19.238      }
  19.239 +    SDL_DFB_CHECKERR(surfpal->SetEntries(surfpal, entries, ncolors, 0));
  19.240 +    return 0;
  19.241 +  error:
  19.242 +#else
  19.243 +    SDL_Unsupported();
  19.244 +#endif
  19.245 +    return -1;
  19.246 +}
  19.247 +
  19.248 +static void
  19.249 +DirectFB_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
  19.250 +{
  19.251 +    SDL_DFB_RENDERERDATA(renderer);
  19.252 +
  19.253 +    if (event->event == SDL_WINDOWEVENT_RESIZED) {
  19.254 +        /* Rebind the context to the window area and update matrices */
  19.255 +        //SDL_CurrentContext = NULL;
  19.256 +        //data->updateSize = SDL_TRUE;
  19.257 +        renddata->size_changed = SDL_TRUE;
  19.258 +   }
  19.259 +}
  19.260 +
  19.261 +int
  19.262 +DirectFB_RenderClear(SDL_Renderer * renderer)
  19.263 +{
  19.264 +    SDL_DFB_RENDERERDATA(renderer);
  19.265 +
  19.266 +    DirectFB_ActivateRenderer(renderer);
  19.267 +
  19.268 +    return 0;
  19.269  }
  19.270  
  19.271  SDL_Renderer *
  19.272 @@ -205,35 +304,53 @@
  19.273      SDL_VideoDisplay *display = window->display;
  19.274      SDL_Renderer *renderer = NULL;
  19.275      DirectFB_RenderData *data = NULL;
  19.276 -    char *p;
  19.277 +    DFBSurfaceCapabilities scaps;
  19.278 +    //char *p;
  19.279  
  19.280 -    SDL_DFB_CALLOC(renderer, 1, sizeof(*renderer));
  19.281 -    SDL_DFB_CALLOC(data, 1, sizeof(*data));
  19.282 +    SDL_DFB_ALLOC_CLEAR(renderer, sizeof(*renderer));
  19.283 +    SDL_DFB_ALLOC_CLEAR(data, sizeof(*data));
  19.284  
  19.285 -    renderer->DisplayModeChanged = DirectFB_DisplayModeChanged;
  19.286 -    renderer->ActivateRenderer = DirectFB_ActivateRenderer;
  19.287 +    renderer->WindowEvent = DirectFB_WindowEvent;
  19.288      renderer->CreateTexture = DirectFB_CreateTexture;
  19.289 -    renderer->QueryTexturePixels = DirectFB_QueryTexturePixels;
  19.290 +    renderer->SetTextureAlphaMod = DirectFB_SetTextureAlphaMod;
  19.291 +    renderer->SetTextureColorMod = DirectFB_SetTextureColorMod;
  19.292 +    renderer->SetTextureBlendMode = DirectFB_SetTextureBlendMode;
  19.293      renderer->UpdateTexture = DirectFB_UpdateTexture;
  19.294      renderer->LockTexture = DirectFB_LockTexture;
  19.295 +    renderer->RenderClear = DirectFB_RenderClear;
  19.296      renderer->UnlockTexture = DirectFB_UnlockTexture;
  19.297 -    renderer->DirtyTexture = DirectFB_DirtyTexture;
  19.298      renderer->RenderDrawPoints = DirectFB_RenderDrawPoints;
  19.299      renderer->RenderDrawLines = DirectFB_RenderDrawLines;
  19.300 +    /* SetDrawColor - no needed */
  19.301      renderer->RenderFillRects = DirectFB_RenderFillRects;
  19.302      /* RenderDrawEllipse - no reference implementation yet */
  19.303      /* RenderFillEllipse - no reference implementation yet */
  19.304      renderer->RenderCopy = DirectFB_RenderCopy;
  19.305      renderer->RenderPresent = DirectFB_RenderPresent;
  19.306 -    /* RenderReadPixels is difficult to implement */
  19.307 -    /* RenderWritePixels is difficult to implement */
  19.308 +    
  19.309 +    /* FIXME: Yet to be tested */
  19.310 +    renderer->RenderReadPixels = DirectFB_RenderReadPixels;
  19.311 +    //renderer->RenderWritePixels = DirectFB_RenderWritePixels;
  19.312 +    
  19.313      renderer->DestroyTexture = DirectFB_DestroyTexture;
  19.314      renderer->DestroyRenderer = DirectFB_DestroyRenderer;
  19.315 +
  19.316 +#if 0
  19.317 +    renderer->QueryTexturePixels = DirectFB_QueryTexturePixels;
  19.318 +    renderer->SetTexturePalette = DirectFB_SetTexturePalette;
  19.319 +    renderer->GetTexturePalette = DirectFB_GetTexturePalette;
  19.320 +    renderer->SetTextureScaleMode = DirectFB_SetTextureScaleMode;
  19.321 +    renderer->DirtyTexture = DirectFB_DirtyTexture;
  19.322 +    renderer->SetDrawBlendMode = DirectFB_SetDrawBlendMode;
  19.323 +    renderer->RenderDrawRects = DirectFB_RenderDrawRects;
  19.324 +#endif
  19.325 +
  19.326      renderer->info = DirectFB_RenderDriver.info;
  19.327      renderer->window = window;      /* SDL window */
  19.328      renderer->driverdata = data;
  19.329  
  19.330 -    renderer->info.flags = SDL_RENDERER_ACCELERATED;
  19.331 +    renderer->info.flags =
  19.332 +        SDL_RENDERER_ACCELERATED;
  19.333  
  19.334      data->window = window;
  19.335  
  19.336 @@ -245,10 +362,26 @@
  19.337      } else
  19.338          data->flipflags |= DSFLIP_ONSYNC;
  19.339  
  19.340 -    data->isyuvdirect = 0;      /* default is off! */
  19.341 -    p = SDL_getenv(DFBENV_USE_YUV_DIRECT);
  19.342 -    if (p)
  19.343 -        data->isyuvdirect = atoi(p);
  19.344 +    SDL_DFB_CHECKERR(windata->surface->
  19.345 +                     GetCapabilities(windata->surface, &scaps));
  19.346 +
  19.347 +#if 0
  19.348 +    if (scaps & DSCAPS_DOUBLE)
  19.349 +        renderer->info.flags |= SDL_RENDERER_PRESENTFLIP2;
  19.350 +    else if (scaps & DSCAPS_TRIPLE)
  19.351 +        renderer->info.flags |= SDL_RENDERER_PRESENTFLIP3;
  19.352 +    else
  19.353 +        renderer->info.flags |= SDL_RENDERER_SINGLEBUFFER;
  19.354 +#endif
  19.355 +
  19.356 +    DirectFB_SetSupportedPixelFormats(&renderer->info);
  19.357 +
  19.358 +#if 0
  19.359 +    /* Set up a palette watch on the display palette */
  19.360 +    if (display->palette) {
  19.361 +        SDL_AddPaletteWatch(display->palette, DisplayPaletteChanged, data);
  19.362 +    }
  19.363 +#endif
  19.364  
  19.365      return renderer;
  19.366  
  19.367 @@ -258,58 +391,7 @@
  19.368      return NULL;
  19.369  }
  19.370  
  19.371 -static DFBSurfacePixelFormat
  19.372 -SDLToDFBPixelFormat(Uint32 format)
  19.373 -{
  19.374 -    switch (format) {
  19.375 -    case SDL_PIXELFORMAT_RGB332:
  19.376 -        return DSPF_RGB332;
  19.377 -    case SDL_PIXELFORMAT_RGB555:
  19.378 -        return DSPF_ARGB1555;
  19.379 -    case SDL_PIXELFORMAT_ARGB4444:
  19.380 -        return DSPF_ARGB4444;
  19.381 -    case SDL_PIXELFORMAT_ARGB1555:
  19.382 -        return DSPF_ARGB1555;
  19.383 -    case SDL_PIXELFORMAT_RGB565:
  19.384 -        return DSPF_RGB16;
  19.385 -    case SDL_PIXELFORMAT_RGB24:
  19.386 -        return DSPF_RGB24;
  19.387 -    case SDL_PIXELFORMAT_RGB888:
  19.388 -        return DSPF_RGB32;
  19.389 -    case SDL_PIXELFORMAT_ARGB8888:
  19.390 -        return DSPF_ARGB;
  19.391 -    case SDL_PIXELFORMAT_YV12:
  19.392 -        return DSPF_YV12;       /* Planar mode: Y + V + U  (3 planes) */
  19.393 -    case SDL_PIXELFORMAT_IYUV:
  19.394 -        return DSPF_I420;       /* Planar mode: Y + U + V  (3 planes) */
  19.395 -    case SDL_PIXELFORMAT_YUY2:
  19.396 -        return DSPF_YUY2;       /* Packed mode: Y0+U0+Y1+V0 (1 plane) */
  19.397 -    case SDL_PIXELFORMAT_UYVY:
  19.398 -        return DSPF_UYVY;       /* Packed mode: U0+Y0+V0+Y1 (1 plane) */
  19.399 -    case SDL_PIXELFORMAT_YVYU:
  19.400 -        return DSPF_UNKNOWN;    /* Packed mode: Y0+V0+Y1+U0 (1 plane) */
  19.401 -#if (DFB_VERSION_ATLEAST(1,2,0))
  19.402 -    case SDL_PIXELFORMAT_RGB444:
  19.403 -        return DSPF_RGB444;
  19.404 -#endif
  19.405 -    case SDL_PIXELFORMAT_BGR24:
  19.406 -        return DSPF_UNKNOWN;
  19.407 -    case SDL_PIXELFORMAT_BGR888:
  19.408 -        return DSPF_UNKNOWN;
  19.409 -    case SDL_PIXELFORMAT_RGBA8888:
  19.410 -        return DSPF_UNKNOWN;
  19.411 -    case SDL_PIXELFORMAT_ABGR8888:
  19.412 -        return DSPF_UNKNOWN;
  19.413 -    case SDL_PIXELFORMAT_BGRA8888:
  19.414 -        return DSPF_UNKNOWN;
  19.415 -    case SDL_PIXELFORMAT_ARGB2101010:
  19.416 -        return DSPF_UNKNOWN;
  19.417 -    default:
  19.418 -        return DSPF_UNKNOWN;
  19.419 -    }
  19.420 -}
  19.421 -
  19.422 -static int
  19.423 +static void
  19.424  DirectFB_ActivateRenderer(SDL_Renderer * renderer)
  19.425  {
  19.426      SDL_DFB_RENDERERDATA(renderer);
  19.427 @@ -317,24 +399,15 @@
  19.428      SDL_DFB_WINDOWDATA(window);
  19.429  
  19.430      if (renddata->size_changed || windata->wm_needs_redraw) {
  19.431 -//        DirectFB_AdjustWindowSurface(window);
  19.432 +        DirectFB_AdjustWindowSurface(window);
  19.433      }
  19.434 -    return 0;
  19.435  }
  19.436  
  19.437 -static int
  19.438 -DirectFB_DisplayModeChanged(SDL_Renderer * renderer)
  19.439 -{
  19.440 -    SDL_DFB_RENDERERDATA(renderer);
  19.441 -
  19.442 -    renddata->size_changed = SDL_TRUE;
  19.443 -    return 0;
  19.444 -}
  19.445  
  19.446  static int
  19.447  DirectFB_AcquireVidLayer(SDL_Renderer * renderer, SDL_Texture * texture)
  19.448  {
  19.449 -    SDL_DFB_RENDERERDATA(renderer);
  19.450 +    //SDL_DFB_RENDERERDATA(renderer);
  19.451      SDL_Window *window = renderer->window;
  19.452      SDL_VideoDisplay *display = window->display;
  19.453      SDL_DFB_DEVICEDATA(display->device);
  19.454 @@ -343,7 +416,7 @@
  19.455      DFBDisplayLayerConfig layconf;
  19.456      DFBResult ret;
  19.457  
  19.458 -    if (renddata->isyuvdirect && (dispdata->vidID >= 0)
  19.459 +    if (devdata->use_yuv_direct && (dispdata->vidID >= 0)
  19.460          && (!dispdata->vidIDinuse)
  19.461          && SDL_ISPIXELFORMAT_FOURCC(data->format)) {
  19.462          layconf.flags =
  19.463 @@ -351,7 +424,7 @@
  19.464              DLCONF_SURFACE_CAPS;
  19.465          layconf.width = texture->w;
  19.466          layconf.height = texture->h;
  19.467 -        layconf.pixelformat = SDLToDFBPixelFormat(data->format);
  19.468 +        layconf.pixelformat = DirectFB_SDLToDFBPixelFormat(data->format);
  19.469          layconf.surface_caps = DSCAPS_VIDEOONLY | DSCAPS_DOUBLE;
  19.470  
  19.471          SDL_DFB_CHECKERR(devdata->dfb->GetDisplayLayer(devdata->dfb,
  19.472 @@ -362,7 +435,7 @@
  19.473                                                         DLSCL_EXCLUSIVE));
  19.474  
  19.475          if (devdata->use_yuv_underlays) {
  19.476 -            ret = SDL_DFB_CHECK(dispdata->vidlayer->SetLevel(dispdata->vidlayer, -1));
  19.477 +            ret = dispdata->vidlayer->SetLevel(dispdata->vidlayer, -1);
  19.478              if (ret != DFB_OK)
  19.479                  SDL_DFB_DEBUG("Underlay Setlevel not supported\n");
  19.480          }
  19.481 @@ -398,11 +471,13 @@
  19.482      DFBSurfaceDescription dsc;
  19.483      DFBSurfacePixelFormat pixelformat;
  19.484  
  19.485 -    SDL_DFB_CALLOC(data, 1, sizeof(*data));
  19.486 +    DirectFB_ActivateRenderer(renderer);
  19.487 +
  19.488 +    SDL_DFB_ALLOC_CLEAR(data, sizeof(*data));
  19.489      texture->driverdata = data;
  19.490  
  19.491      /* find the right pixelformat */
  19.492 -    pixelformat = SDLToDFBPixelFormat(texture->format);
  19.493 +    pixelformat = DirectFB_SDLToDFBPixelFormat(texture->format);
  19.494      if (pixelformat == DSPF_UNKNOWN) {
  19.495          SDL_SetError("Unknown pixel format %d\n", data->format);
  19.496          goto error;
  19.497 @@ -417,6 +492,12 @@
  19.498              DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS;
  19.499          dsc.width = texture->w;
  19.500          dsc.height = texture->h;
  19.501 +        if(texture->format == SDL_PIXELFORMAT_YV12 ||
  19.502 +           texture->format == SDL_PIXELFORMAT_IYUV) {
  19.503 +           /* dfb has problems with odd sizes -make them even internally */
  19.504 +           dsc.width += (dsc.width % 2);
  19.505 +           dsc.height += (dsc.height % 2);
  19.506 +        }
  19.507          /* <1.2 Never use DSCAPS_VIDEOONLY here. It kills performance
  19.508           * No DSCAPS_SYSTEMONLY either - let dfb decide
  19.509           * 1.2: DSCAPS_SYSTEMONLY boosts performance by factor ~8
  19.510 @@ -436,18 +517,33 @@
  19.511          /* Create the surface */
  19.512          SDL_DFB_CHECKERR(devdata->dfb->CreateSurface(devdata->dfb, &dsc,
  19.513                                                       &data->surface));
  19.514 +        if (SDL_ISPIXELFORMAT_INDEXED(data->format)
  19.515 +            && !SDL_ISPIXELFORMAT_FOURCC(data->format)) {
  19.516 +#if 1
  19.517 +            SDL_DFB_CHECKERR(data->surface->GetPalette(data->surface, &data->palette));
  19.518 +#else
  19.519 +            /* DFB has issues with blitting LUT8 surfaces.
  19.520 +			 * Creating a new palette does not help.
  19.521 +			 */
  19.522 +        	DFBPaletteDescription pal_desc;
  19.523 +        	pal_desc.flags = DPDESC_SIZE; // | DPDESC_ENTRIES
  19.524 +        	pal_desc.size = 256;
  19.525 +        	SDL_DFB_CHECKERR(devdata->dfb->CreatePalette(devdata->dfb, &pal_desc,&data->palette));
  19.526 +        	SDL_DFB_CHECKERR(data->surface->SetPalette(data->surface, data->palette));
  19.527 +#endif
  19.528 +        }
  19.529 +
  19.530      }
  19.531  #if (DFB_VERSION_ATLEAST(1,2,0))
  19.532      data->render_options = DSRO_NONE;
  19.533  #endif
  19.534 -
  19.535      if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
  19.536          /* 3 plane YUVs return 1 bpp, but we need more space for other planes */
  19.537          if(texture->format == SDL_PIXELFORMAT_YV12 ||
  19.538             texture->format == SDL_PIXELFORMAT_IYUV) {
  19.539 -            SDL_DFB_CALLOC(data->pixels, 1, (texture->h * data->pitch * 3 + texture->h * data->pitch * 3 % 2) / 2);
  19.540 +            SDL_DFB_ALLOC_CLEAR(data->pixels, (texture->h * data->pitch  + ((texture->h + texture->h % 2) * (data->pitch + data->pitch % 2) * 2) / 4));
  19.541          } else {
  19.542 -            SDL_DFB_CALLOC(data->pixels, 1, texture->h * data->pitch);
  19.543 +            SDL_DFB_ALLOC_CLEAR(data->pixels, texture->h * data->pitch);
  19.544          }
  19.545      }
  19.546  
  19.547 @@ -477,6 +573,116 @@
  19.548  }
  19.549  
  19.550  static int
  19.551 +DirectFB_SetTexturePalette(SDL_Renderer * renderer,
  19.552 +                           SDL_Texture * texture,
  19.553 +                           const SDL_Color * colors, int firstcolor,
  19.554 +                           int ncolors)
  19.555 +{
  19.556 +    DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
  19.557 +    if (SDL_ISPIXELFORMAT_INDEXED(data->format)
  19.558 +        && !SDL_ISPIXELFORMAT_FOURCC(data->format)) {
  19.559 +        DFBColor entries[256];
  19.560 +        int i;
  19.561 +
  19.562 +        if (ncolors > 256)
  19.563 +        	ncolors = 256;
  19.564 +
  19.565 +        for (i = 0; i < ncolors; ++i) {
  19.566 +            entries[i].r = colors[i].r;
  19.567 +            entries[i].g = colors[i].g;
  19.568 +            entries[i].b = colors[i].b;
  19.569 +            entries[i].a = 0xff;
  19.570 +        }
  19.571 +        SDL_DFB_CHECKERR(data->
  19.572 +                         palette->SetEntries(data->palette, entries, ncolors, firstcolor));
  19.573 +        return 0;
  19.574 +    } else {
  19.575 +        SDL_SetError("YUV textures don't have a palette");
  19.576 +        return -1;
  19.577 +    }
  19.578 +  error:
  19.579 +    return -1;
  19.580 +}
  19.581 +
  19.582 +static int
  19.583 +DirectFB_GetTexturePalette(SDL_Renderer * renderer,
  19.584 +                           SDL_Texture * texture, SDL_Color * colors,
  19.585 +                           int firstcolor, int ncolors)
  19.586 +{
  19.587 +    DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
  19.588 +
  19.589 +    if (SDL_ISPIXELFORMAT_INDEXED(data->format)
  19.590 +        && !SDL_ISPIXELFORMAT_FOURCC(data->format)) {
  19.591 +        DFBColor entries[256];
  19.592 +        int i;
  19.593 +
  19.594 +        SDL_DFB_CHECKERR(data->
  19.595 +                         palette->GetEntries(data->palette, entries, ncolors,
  19.596 +                                             firstcolor));
  19.597 +
  19.598 +        for (i = 0; i < ncolors; ++i) {
  19.599 +            colors[i].r = entries[i].r;
  19.600 +            colors[i].g = entries[i].g;
  19.601 +            colors[i].b = entries[i].b;
  19.602 +            colors->unused = SDL_ALPHA_OPAQUE;
  19.603 +        }
  19.604 +        return 0;
  19.605 +    } else {
  19.606 +        SDL_SetError("YUV textures don't have a palette");
  19.607 +        return -1;
  19.608 +    }
  19.609 +  error:
  19.610 +    return -1;
  19.611 +}
  19.612 +
  19.613 +static int
  19.614 +DirectFB_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture)
  19.615 +{
  19.616 +    return 0;
  19.617 +}
  19.618 +
  19.619 +static int
  19.620 +DirectFB_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture)
  19.621 +{
  19.622 +    return 0;
  19.623 +}
  19.624 +
  19.625 +static int
  19.626 +DirectFB_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
  19.627 +{
  19.628 +    switch (texture->blendMode) {
  19.629 +    case SDL_BLENDMODE_NONE:
  19.630 +    //case SDL_BLENDMODE_MASK:
  19.631 +    case SDL_BLENDMODE_BLEND:
  19.632 +    case SDL_BLENDMODE_ADD:
  19.633 +    case SDL_BLENDMODE_MOD:
  19.634 +        return 0;
  19.635 +    default:
  19.636 +        SDL_Unsupported();
  19.637 +        texture->blendMode = SDL_BLENDMODE_NONE;
  19.638 +        return -1;
  19.639 +    }
  19.640 +}
  19.641 +
  19.642 +static int
  19.643 +DirectFB_SetDrawBlendMode(SDL_Renderer * renderer)
  19.644 +{
  19.645 +    switch (renderer->blendMode) {
  19.646 +    case SDL_BLENDMODE_NONE:
  19.647 +    //case SDL_BLENDMODE_MASK:
  19.648 +    case SDL_BLENDMODE_BLEND:
  19.649 +    case SDL_BLENDMODE_ADD:
  19.650 +    case SDL_BLENDMODE_MOD:
  19.651 +        return 0;
  19.652 +    default:
  19.653 +        SDL_Unsupported();
  19.654 +        renderer->blendMode = SDL_BLENDMODE_NONE;
  19.655 +        return -1;
  19.656 +    }
  19.657 +}
  19.658 +
  19.659 +#if 0
  19.660 +static int
  19.661  DirectFB_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
  19.662  {
  19.663  #if (DFB_VERSION_ATLEAST(1,2,0))
  19.664 @@ -504,6 +710,7 @@
  19.665  #endif
  19.666      return 0;
  19.667  }
  19.668 +#endif
  19.669  
  19.670  static int
  19.671  DirectFB_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
  19.672 @@ -515,9 +722,16 @@
  19.673      Uint8 *src, *dst;
  19.674      int row;
  19.675      size_t length;
  19.676 -    int bpp = DFB_BYTES_PER_PIXEL(SDLToDFBPixelFormat(texture->format));
  19.677 +    int bpp = DFB_BYTES_PER_PIXEL(DirectFB_SDLToDFBPixelFormat(texture->format));
  19.678      // FIXME: SDL_BYTESPERPIXEL(texture->format) broken for yuv yv12 3 planes
  19.679  
  19.680 +    DirectFB_ActivateRenderer(renderer);
  19.681 +
  19.682 +    if ((texture->format == SDL_PIXELFORMAT_YV12) ||
  19.683 +        (texture->format == SDL_PIXELFORMAT_IYUV)) {
  19.684 +        bpp = 1;
  19.685 +    }
  19.686 +    
  19.687      SDL_DFB_CHECKERR(data->surface->Lock(data->surface,
  19.688                                           DSLF_WRITE | DSLF_READ,
  19.689                                           ((void **) &dpixels), &dpitch));
  19.690 @@ -530,24 +744,25 @@
  19.691          dst += dpitch;
  19.692      }
  19.693      /* copy other planes for 3 plane formats */
  19.694 -    if (texture->format == SDL_PIXELFORMAT_YV12 ||
  19.695 -        texture->format == SDL_PIXELFORMAT_IYUV) {
  19.696 +    if ((texture->format == SDL_PIXELFORMAT_YV12) ||
  19.697 +        (texture->format == SDL_PIXELFORMAT_IYUV)) {
  19.698          src = (Uint8 *) pixels + texture->h * pitch;
  19.699          dst = (Uint8 *) dpixels + texture->h * dpitch + rect->y * dpitch / 4 + rect->x * bpp / 2;
  19.700 -        for (row = 0; row < rect->h / 2; ++row) {
  19.701 +        for (row = 0; row < rect->h / 2 + (rect->h & 1); ++row) {
  19.702              SDL_memcpy(dst, src, length / 2);
  19.703              src += pitch / 2;
  19.704              dst += dpitch / 2;
  19.705          }
  19.706          src = (Uint8 *) pixels + texture->h * pitch + texture->h * pitch / 4;
  19.707          dst = (Uint8 *) dpixels + texture->h * dpitch + texture->h * dpitch / 4 + rect->y * dpitch / 4 + rect->x * bpp / 2;
  19.708 -        for (row = 0; row < rect->h / 2; ++row) {
  19.709 +        for (row = 0; row < rect->h / 2 + (rect->h & 1); ++row) {
  19.710              SDL_memcpy(dst, src, length / 2);
  19.711              src += pitch / 2;
  19.712              dst += dpitch / 2;
  19.713          }
  19.714      }
  19.715      SDL_DFB_CHECKERR(data->surface->Unlock(data->surface));
  19.716 +    data->isDirty = 0;
  19.717      return 0;
  19.718    error:
  19.719      return 1;
  19.720 @@ -556,15 +771,18 @@
  19.721  
  19.722  static int
  19.723  DirectFB_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
  19.724 -                     const SDL_Rect * rect, int markDirty,
  19.725 -                     void **pixels, int *pitch)
  19.726 +                     const SDL_Rect * rect, void **pixels, int *pitch)
  19.727  {
  19.728      DirectFB_TextureData *texturedata =
  19.729          (DirectFB_TextureData *) texture->driverdata;
  19.730  
  19.731 +    DirectFB_ActivateRenderer(renderer);
  19.732 +
  19.733 +#if 0
  19.734      if (markDirty) {
  19.735          SDL_AddDirtyRect(&texturedata->dirty, rect);
  19.736      }
  19.737 +#endif
  19.738  
  19.739      if (texturedata->display) {
  19.740          void *fdata;
  19.741 @@ -579,8 +797,9 @@
  19.742          *pixels =
  19.743              (void *) ((Uint8 *) texturedata->pixels +
  19.744                        rect->y * texturedata->pitch +
  19.745 -                      rect->x * DFB_BYTES_PER_PIXEL(SDLToDFBPixelFormat(texture->format)));
  19.746 +                      rect->x * DFB_BYTES_PER_PIXEL(DirectFB_SDLToDFBPixelFormat(texture->format)));
  19.747          *pitch = texturedata->pitch;
  19.748 +        texturedata->isDirty = 1;
  19.749      }
  19.750      return 0;
  19.751  
  19.752 @@ -594,12 +813,15 @@
  19.753      DirectFB_TextureData *texturedata =
  19.754          (DirectFB_TextureData *) texture->driverdata;
  19.755  
  19.756 +    DirectFB_ActivateRenderer(renderer);
  19.757 +
  19.758      if (texturedata->display) {
  19.759          SDL_DFB_CHECK(texturedata->surface->Unlock(texturedata->surface));
  19.760          texturedata->pixels = NULL;
  19.761      }
  19.762  }
  19.763  
  19.764 +#if 0
  19.765  static void
  19.766  DirectFB_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
  19.767                        int numrects, const SDL_Rect * rects)
  19.768 @@ -611,6 +833,7 @@
  19.769          SDL_AddDirtyRect(&data->dirty, &rects[i]);
  19.770      }
  19.771  }
  19.772 +#endif
  19.773  
  19.774  static int
  19.775  PrepareDraw(SDL_Renderer * renderer)
  19.776 @@ -630,9 +853,11 @@
  19.777  
  19.778      switch (renderer->blendMode) {
  19.779      case SDL_BLENDMODE_NONE:
  19.780 +    //case SDL_BLENDMODE_MASK:
  19.781      case SDL_BLENDMODE_BLEND:
  19.782          break;
  19.783      case SDL_BLENDMODE_ADD:
  19.784 +    case SDL_BLENDMODE_MOD:
  19.785          r = ((int) r * (int) a) / 255;
  19.786          g = ((int) g * (int) a) / 255;
  19.787          b = ((int) b * (int) a) / 255;
  19.788 @@ -653,6 +878,8 @@
  19.789      SDL_DFB_WINDOWSURFACE(data->window);
  19.790      int i;
  19.791  
  19.792 +    DirectFB_ActivateRenderer(renderer);
  19.793 +
  19.794      PrepareDraw(renderer);
  19.795      for (i=0; i < count; i++)
  19.796      	SDL_DFB_CHECKERR(destsurf->DrawLine(destsurf, points[i].x, points[i].y, points[i].x, points[i].y));
  19.797 @@ -668,6 +895,8 @@
  19.798      SDL_DFB_WINDOWSURFACE(data->window);
  19.799      int i;
  19.800  
  19.801 +    DirectFB_ActivateRenderer(renderer);
  19.802 +
  19.803      PrepareDraw(renderer);
  19.804      /* Use antialiasing when available */
  19.805  #if (DFB_VERSION_ATLEAST(1,2,0))
  19.806 @@ -683,12 +912,34 @@
  19.807  }
  19.808  
  19.809  static int
  19.810 +DirectFB_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
  19.811 +{
  19.812 +    DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
  19.813 +    SDL_DFB_WINDOWSURFACE(data->window);
  19.814 +    int i;
  19.815 +
  19.816 +    DirectFB_ActivateRenderer(renderer);
  19.817 +
  19.818 +    PrepareDraw(renderer);
  19.819 +
  19.820 +    for (i=0; i<count; i++)
  19.821 +    	SDL_DFB_CHECKERR(destsurf->DrawRectangle(destsurf, rects[i]->x, rects[i]->y,
  19.822 +    			rects[i]->w, rects[i]->h));
  19.823 +
  19.824 +    return 0;
  19.825 +  error:
  19.826 +    return -1;
  19.827 +}
  19.828 +
  19.829 +static int
  19.830  DirectFB_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
  19.831  {
  19.832      DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
  19.833      SDL_DFB_WINDOWSURFACE(data->window);
  19.834      int i;
  19.835  
  19.836 +    DirectFB_ActivateRenderer(renderer);
  19.837 +
  19.838      PrepareDraw(renderer);
  19.839  
  19.840      for (i=0; i<count; i++)
  19.841 @@ -708,7 +959,9 @@
  19.842      SDL_DFB_WINDOWSURFACE(data->window);
  19.843      DirectFB_TextureData *texturedata =
  19.844          (DirectFB_TextureData *) texture->driverdata;
  19.845 -    Uint8 alpha = 0xFF;
  19.846 +    Uint8 alpha, r, g, b;
  19.847 +
  19.848 +    DirectFB_ActivateRenderer(renderer);
  19.849  
  19.850      if (texturedata->display) {
  19.851          int px, py;
  19.852 @@ -722,7 +975,7 @@
  19.853                                                        srcrect->x, srcrect->y,
  19.854                                                        srcrect->w,
  19.855                                                        srcrect->h));
  19.856 -        SDL_DFB_CHECK(windata->window->GetPosition(windata->window, &px, &py));
  19.857 +        SDL_DFB_CHECK(windata->dfbwin->GetPosition(windata->dfbwin, &px, &py));
  19.858          px += windata->client.x;
  19.859          py += windata->client.y;
  19.860          SDL_DFB_CHECKERR(dispdata->
  19.861 @@ -735,10 +988,11 @@
  19.862          DFBRectangle sr, dr;
  19.863          DFBSurfaceBlittingFlags flags = 0;
  19.864  
  19.865 +#if 0
  19.866          if (texturedata->dirty.list) {
  19.867              SDL_DirtyRect *dirty;
  19.868              void *pixels;
  19.869 -            int bpp = DFB_BYTES_PER_PIXEL(SDLToDFBPixelFormat(texture->format));
  19.870 +            int bpp = DFB_BYTES_PER_PIXEL(DirectFB_SDLToDFBPixelFormat(texture->format));
  19.871              int pitch = texturedata->pitch;
  19.872  
  19.873              for (dirty = texturedata->dirty.list; dirty; dirty = dirty->next) {
  19.874 @@ -747,38 +1001,43 @@
  19.875                      (void *) ((Uint8 *) texturedata->pixels +
  19.876                                rect->y * pitch + rect->x * bpp);
  19.877                  DirectFB_UpdateTexture(renderer, texture, rect,
  19.878 -                                       texturedata->pixels,
  19.879 +                                       pixels,
  19.880                                         texturedata->pitch);
  19.881              }
  19.882              SDL_ClearDirtyRects(&texturedata->dirty);
  19.883          }
  19.884 +#endif
  19.885 +        if (texturedata->isDirty)
  19.886 +        {
  19.887 +            SDL_Rect rect;
  19.888 +
  19.889 +            rect.x = 0;
  19.890 +            rect.y = 0;
  19.891 +            rect.w = texture->w;
  19.892 +            rect.h = texture->h;
  19.893 +
  19.894 +            DirectFB_UpdateTexture(renderer, texture, &rect, texturedata->pixels, texturedata->pitch);
  19.895 +        }
  19.896  
  19.897          SDLtoDFBRect(srcrect, &sr);
  19.898          SDLtoDFBRect(dstrect, &dr);
  19.899  
  19.900 +        alpha = r = g = b = 0xff;
  19.901 +		if (texture->modMode & SDL_TEXTUREMODULATE_ALPHA){
  19.902 +			alpha = texture->a;
  19.903 +        	flags |= DSBLIT_BLEND_COLORALPHA;
  19.904 +		}
  19.905 +
  19.906 +        if (texture->modMode & SDL_TEXTUREMODULATE_COLOR) {
  19.907 +            r = texture->r;
  19.908 +            g = texture->g;
  19.909 +            b = texture->b;
  19.910 +            flags |= DSBLIT_COLORIZE;
  19.911 +        }
  19.912          SDL_DFB_CHECKERR(destsurf->
  19.913 -                         SetColor(destsurf, 0xFF, 0xFF, 0xFF, 0xFF));
  19.914 -        if (texture->
  19.915 -            modMode & (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA))
  19.916 -        {
  19.917 -            if (texture->modMode & SDL_TEXTUREMODULATE_ALPHA) {
  19.918 -                alpha = texture->a;
  19.919 -                SDL_DFB_CHECKERR(destsurf->SetColor(destsurf, 0xFF, 0xFF,
  19.920 -                                                    0xFF, alpha));
  19.921 -            }
  19.922 -            if (texture->modMode & SDL_TEXTUREMODULATE_COLOR) {
  19.923 +                         SetColor(destsurf, r, g, b, alpha));
  19.924  
  19.925 -                SDL_DFB_CHECKERR(destsurf->SetColor(destsurf,
  19.926 -                                                    texture->r,
  19.927 -                                                    texture->g,
  19.928 -                                                    texture->b, alpha));
  19.929 -                flags |= DSBLIT_COLORIZE;
  19.930 -            }
  19.931 -            if (alpha < 0xFF)
  19.932 -                flags |= DSBLIT_SRC_PREMULTCOLOR;
  19.933 -        } else
  19.934 -            SDL_DFB_CHECKERR(destsurf->SetColor(destsurf, 0xFF, 0xFF,
  19.935 -                                                0xFF, 0xFF));
  19.936 +        // ???? flags |= DSBLIT_SRC_PREMULTCOLOR;
  19.937  
  19.938          SetBlendMode(data, texture->blendMode, texturedata);
  19.939  
  19.940 @@ -812,13 +1071,27 @@
  19.941      DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
  19.942      SDL_Window *window = renderer->window;
  19.943      SDL_DFB_WINDOWDATA(window);
  19.944 +    SDL_ShapeData *shape_data = (window->shaper ? window->shaper->driverdata : NULL);
  19.945  
  19.946 -    DFBRectangle sr;
  19.947 +    DirectFB_ActivateRenderer(renderer);
  19.948  
  19.949 -    sr.x = 0;
  19.950 -    sr.y = 0;
  19.951 -    sr.w = window->w;
  19.952 -    sr.h = window->h;
  19.953 +    if (shape_data && shape_data->surface) {
  19.954 +        /* saturate the window surface alpha channel */
  19.955 +        SDL_DFB_CHECK(windata->window_surface->SetSrcBlendFunction(windata->window_surface, DSBF_ONE));
  19.956 +        SDL_DFB_CHECK(windata->window_surface->SetDstBlendFunction(windata->window_surface, DSBF_ONE));
  19.957 +        SDL_DFB_CHECK(windata->window_surface->SetDrawingFlags(windata->window_surface, DSDRAW_BLEND));
  19.958 +        SDL_DFB_CHECK(windata->window_surface->SetColor(windata->window_surface, 0, 0, 0, 0xff));
  19.959 +        SDL_DFB_CHECK(windata->window_surface->FillRectangle(windata->window_surface, 0,0, windata->size.w, windata->size.h));
  19.960 +
  19.961 +        /* blit the mask */
  19.962 +        SDL_DFB_CHECK(windata->surface->SetSrcBlendFunction(windata->surface, DSBF_DESTCOLOR));
  19.963 +        SDL_DFB_CHECK(windata->surface->SetDstBlendFunction(windata->surface, DSBF_ZERO));
  19.964 +        SDL_DFB_CHECK(windata->surface->SetBlittingFlags(windata->surface, DSBLIT_BLEND_ALPHACHANNEL));
  19.965 +#if (DFB_VERSION_ATLEAST(1,2,0))
  19.966 +        SDL_DFB_CHECK(windata->surface->SetRenderOptions(windata->surface, DSRO_NONE));
  19.967 +#endif
  19.968 +        SDL_DFB_CHECK(windata->surface->Blit(windata->surface, shape_data->surface, NULL, 0, 0));
  19.969 +    }
  19.970  
  19.971      /* Send the data to the display */
  19.972      SDL_DFB_CHECK(windata->window_surface->Flip(windata->window_surface, NULL,
  19.973 @@ -830,9 +1103,12 @@
  19.974  {
  19.975      DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
  19.976  
  19.977 +    DirectFB_ActivateRenderer(renderer);
  19.978 +
  19.979      if (!data) {
  19.980          return;
  19.981      }
  19.982 +    //SDL_FreeDirtyRects(&data->dirty);
  19.983      SDL_DFB_RELEASE(data->palette);
  19.984      SDL_DFB_RELEASE(data->surface);
  19.985      if (data->display) {
  19.986 @@ -844,7 +1120,6 @@
  19.987                                                  DLSCL_ADMINISTRATIVE));
  19.988          SDL_DFB_RELEASE(dispdata->vidlayer);
  19.989      }
  19.990 -    SDL_FreeDirtyRects(&data->dirty);
  19.991      SDL_DFB_FREE(data->pixels);
  19.992      SDL_free(data);
  19.993      texture->driverdata = NULL;
  19.994 @@ -854,6 +1129,13 @@
  19.995  DirectFB_DestroyRenderer(SDL_Renderer * renderer)
  19.996  {
  19.997      DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
  19.998 +    SDL_VideoDisplay *display = renderer->window->display;
  19.999 +
 19.1000 +#if 0
 19.1001 +    if (display->palette) {
 19.1002 +        SDL_DelPaletteWatch(display->palette, DisplayPaletteChanged, data);
 19.1003 +    }
 19.1004 +#endif
 19.1005  
 19.1006      if (data) {
 19.1007          SDL_free(data);
 19.1008 @@ -861,4 +1143,58 @@
 19.1009      SDL_free(renderer);
 19.1010  }
 19.1011  
 19.1012 +static int
 19.1013 +DirectFB_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
 19.1014 +                     Uint32 format, void * pixels, int pitch)
 19.1015 +{
 19.1016 +    SDL_Window *window = renderer->window;
 19.1017 +    SDL_DFB_WINDOWDATA(window);
 19.1018 +    Uint32 sdl_format;
 19.1019 +   	void * laypixels;
 19.1020 +   	int laypitch;
 19.1021 +  	DFBSurfacePixelFormat dfb_format;
 19.1022 +
 19.1023 +    DirectFB_ActivateRenderer(renderer);
 19.1024 +
 19.1025 +    SDL_DFB_CHECK(windata->surface->GetPixelFormat(windata->surface, &dfb_format));
 19.1026 +    sdl_format = DirectFB_DFBToSDLPixelFormat(dfb_format);
 19.1027 +    SDL_DFB_CHECK(windata->surface->Lock(windata->surface, DSLF_READ, (void **) &laypixels, &laypitch));
 19.1028 +    
 19.1029 +    laypixels += (rect->y * laypitch + rect->x * SDL_BYTESPERPIXEL(sdl_format) );
 19.1030 +    SDL_ConvertPixels(rect->w, rect->h,
 19.1031 +                      sdl_format, laypixels, laypitch,
 19.1032 +                      format, pixels, pitch);
 19.1033 +
 19.1034 +    SDL_DFB_CHECK(windata->surface->Unlock(windata->surface));
 19.1035 +    
 19.1036 +    return 0;
 19.1037 +}
 19.1038 +
 19.1039 +static int
 19.1040 +DirectFB_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
 19.1041 +                      Uint32 format, const void * pixels, int pitch)
 19.1042 +{
 19.1043 +    SDL_Window *window = renderer->window;
 19.1044 +    SDL_DFB_WINDOWDATA(window);
 19.1045 +    Uint32 sdl_format;
 19.1046 +   	void * laypixels;
 19.1047 +   	int laypitch;
 19.1048 +  	DFBSurfacePixelFormat dfb_format;
 19.1049 +
 19.1050 +    SDL_DFB_CHECK(windata->surface->GetPixelFormat(windata->surface, &dfb_format));
 19.1051 +    sdl_format = DirectFB_DFBToSDLPixelFormat(dfb_format);
 19.1052 +
 19.1053 +    SDL_DFB_CHECK(windata->surface->Lock(windata->surface, DSLF_WRITE, (void **) &laypixels, &laypitch));
 19.1054 +      
 19.1055 +    laypixels += (rect->y * laypitch + rect->x * SDL_BYTESPERPIXEL(sdl_format) );
 19.1056 +    SDL_ConvertPixels(rect->w, rect->h,
 19.1057 +                      format, pixels, pitch,
 19.1058 +                      sdl_format, laypixels, laypitch);
 19.1059 +
 19.1060 +    SDL_DFB_CHECK(windata->surface->Unlock(windata->surface));
 19.1061 +
 19.1062 +    return 0;
 19.1063 +}
 19.1064 +
 19.1065 +
 19.1066  /* vi: set ts=4 sw=4 expandtab: */
    20.1 --- a/src/video/directfb/SDL_DirectFB_render.h	Sat Feb 05 16:02:30 2011 -0800
    20.2 +++ b/src/video/directfb/SDL_DirectFB_render.h	Sat Feb 05 16:07:10 2011 -0800
    20.3 @@ -18,13 +18,12 @@
    20.4  
    20.5      Sam Lantinga
    20.6      slouken@libsdl.org
    20.7 +
    20.8 +    SDL1.3 DirectFB driver by couriersud@arcor.de
    20.9 +	
   20.10  */
   20.11 -#include "SDL_config.h"
   20.12 +
   20.13  
   20.14  /* SDL surface based renderer implementation */
   20.15  
   20.16 -#define SDL_DFB_RENDERERDATA(rend) DirectFB_RenderData *renddata = ((rend) ? (DirectFB_RenderData *) (rend)->driverdata : NULL)
   20.17 -
   20.18 -extern void DirectFB_AddRenderDriver(_THIS);
   20.19 -
   20.20  /* vi: set ts=4 sw=4 expandtab: */
    21.1 --- a/src/video/directfb/SDL_DirectFB_video.c	Sat Feb 05 16:02:30 2011 -0800
    21.2 +++ b/src/video/directfb/SDL_DirectFB_video.c	Sat Feb 05 16:07:10 2011 -0800
    21.3 @@ -19,10 +19,23 @@
    21.4      Sam Lantinga
    21.5      slouken@libsdl.org
    21.6  
    21.7 -    SDL1.3 implementation by couriersud@arcor.de
    21.8 +    SDL1.3 DirectFB driver by couriersud@arcor.de
    21.9  	
   21.10  */
   21.11  
   21.12 +#include "SDL_DirectFB_video.h"
   21.13 +
   21.14 +#include "SDL_DirectFB_events.h"
   21.15 +/*
   21.16 + * #include "SDL_DirectFB_gamma.h"
   21.17 + * #include "SDL_DirectFB_keyboard.h"
   21.18 + */
   21.19 +#include "SDL_DirectFB_modes.h"
   21.20 +#include "SDL_DirectFB_mouse.h"
   21.21 +#include "SDL_DirectFB_opengl.h"
   21.22 +#include "SDL_DirectFB_window.h"
   21.23 +#include "SDL_DirectFB_WM.h"
   21.24 +
   21.25  
   21.26  #include "SDL_config.h"
   21.27  
   21.28 @@ -46,6 +59,8 @@
   21.29  #include "SDL_DirectFB_events.h"
   21.30  #include "SDL_DirectFB_render.h"
   21.31  #include "SDL_DirectFB_mouse.h"
   21.32 +#include "SDL_DirectFB_shape.h"
   21.33 +
   21.34  
   21.35  #include "SDL_DirectFB_dyn.h"
   21.36  
   21.37 @@ -61,6 +76,10 @@
   21.38      DirectFB_Available, DirectFB_CreateDevice
   21.39  };
   21.40  
   21.41 +static const DirectFBSurfaceDrawingFlagsNames(drawing_flags);
   21.42 +static const DirectFBSurfaceBlittingFlagsNames(blitting_flags);
   21.43 +static const DirectFBAccelerationMaskNames(acceleration_mask);
   21.44 +
   21.45  /* DirectFB driver bootstrap functions */
   21.46  
   21.47  static int
   21.48 @@ -89,7 +108,7 @@
   21.49          return NULL;
   21.50  
   21.51      /* Initialize all variables that we clean on shutdown */
   21.52 -    SDL_DFB_CALLOC(device, 1, sizeof(SDL_VideoDevice));
   21.53 +    SDL_DFB_ALLOC_CLEAR(device, sizeof(SDL_VideoDevice));
   21.54  
   21.55      /* Set the function pointers */
   21.56  
   21.57 @@ -128,8 +147,13 @@
   21.58  
   21.59  #endif
   21.60  
   21.61 +	/* Shaped window support */
   21.62 +	device->shape_driver.CreateShaper = DirectFB_CreateShaper;
   21.63 +	device->shape_driver.SetWindowShape = DirectFB_SetWindowShape;
   21.64 +	device->shape_driver.ResizeWindowShape = DirectFB_ResizeWindowShape;
   21.65 +	
   21.66      device->free = DirectFB_DeleteDevice;
   21.67 -	fprintf(LOG_CHANNEL, "Device setup %p!!\n", device->ShowWindow);
   21.68 +    
   21.69      return device;
   21.70    error:
   21.71      if (device)
   21.72 @@ -137,10 +161,6 @@
   21.73      return (0);
   21.74  }
   21.75  
   21.76 -static const DirectFBSurfaceDrawingFlagsNames(drawing_flags);
   21.77 -static const DirectFBSurfaceBlittingFlagsNames(blitting_flags);
   21.78 -static const DirectFBAccelerationMaskNames(acceleration_mask);
   21.79 -
   21.80  static void
   21.81  DirectFB_DeviceInformation(IDirectFB * dfb)
   21.82  {
   21.83 @@ -149,59 +169,64 @@
   21.84  
   21.85      dfb->GetDeviceDescription(dfb, &desc);
   21.86  
   21.87 -    fprintf(LOG_CHANNEL, "DirectFB Device Information\n");
   21.88 -    fprintf(LOG_CHANNEL, "===========================\n");
   21.89 -    fprintf(LOG_CHANNEL, "Name:           %s\n", desc.name);
   21.90 -    fprintf(LOG_CHANNEL, "Vendor:         %s\n", desc.vendor);
   21.91 -    fprintf(LOG_CHANNEL, "Driver Name:    %s\n", desc.driver.name);
   21.92 -    fprintf(LOG_CHANNEL, "Driver Vendor:  %s\n", desc.driver.vendor);
   21.93 -    fprintf(LOG_CHANNEL, "Driver Version: %d.%d\n", desc.driver.major,
   21.94 +    SDL_DFB_LOG( "DirectFB Device Information\n");
   21.95 +    SDL_DFB_LOG( "===========================\n");
   21.96 +    SDL_DFB_LOG( "Name:           %s\n", desc.name);
   21.97 +    SDL_DFB_LOG( "Vendor:         %s\n", desc.vendor);
   21.98 +    SDL_DFB_LOG( "Driver Name:    %s\n", desc.driver.name);
   21.99 +    SDL_DFB_LOG( "Driver Vendor:  %s\n", desc.driver.vendor);
  21.100 +    SDL_DFB_LOG( "Driver Version: %d.%d\n", desc.driver.major,
  21.101              desc.driver.minor);
  21.102  
  21.103 -    fprintf(LOG_CHANNEL, "\nVideo memoory:  %d\n", desc.video_memory);
  21.104 +    SDL_DFB_LOG( "\nVideo memoory:  %d\n", desc.video_memory);
  21.105  
  21.106 -    fprintf(LOG_CHANNEL, "\nBlitting flags:\n");
  21.107 +    SDL_DFB_LOG( "\nBlitting flags:\n");
  21.108      for (n = 0; blitting_flags[n].flag; n++) {
  21.109          if (desc.blitting_flags & blitting_flags[n].flag)
  21.110 -            fprintf(LOG_CHANNEL, "    %s\n", blitting_flags[n].name);
  21.111 +            SDL_DFB_LOG( "    %s\n", blitting_flags[n].name);
  21.112      }
  21.113  
  21.114 -    fprintf(LOG_CHANNEL, "\nDrawing flags:\n");
  21.115 +    SDL_DFB_LOG( "\nDrawing flags:\n");
  21.116      for (n = 0; drawing_flags[n].flag; n++) {
  21.117          if (desc.drawing_flags & drawing_flags[n].flag)
  21.118 -            fprintf(LOG_CHANNEL, "    %s\n", drawing_flags[n].name);
  21.119 +            SDL_DFB_LOG( "    %s\n", drawing_flags[n].name);
  21.120      }
  21.121  
  21.122  
  21.123 -    fprintf(LOG_CHANNEL, "\nAcceleration flags:\n");
  21.124 +    SDL_DFB_LOG( "\nAcceleration flags:\n");
  21.125      for (n = 0; acceleration_mask[n].mask; n++) {
  21.126          if (desc.acceleration_mask & acceleration_mask[n].mask)
  21.127 -            fprintf(LOG_CHANNEL, "    %s\n", acceleration_mask[n].name);
  21.128 +            SDL_DFB_LOG( "    %s\n", acceleration_mask[n].name);
  21.129      }
  21.130  
  21.131  
  21.132  }
  21.133  
  21.134 +static int readBoolEnv(const char *env_name, int def_val)
  21.135 +{
  21.136 +    char *stemp;
  21.137 +
  21.138 +    stemp = SDL_getenv(env_name);
  21.139 +    if (stemp)
  21.140 +        return atoi(stemp);
  21.141 +    else
  21.142 +        return def_val;
  21.143 +}
  21.144 +
  21.145  static int
  21.146  DirectFB_VideoInit(_THIS)
  21.147  {
  21.148      IDirectFB *dfb = NULL;
  21.149      DFB_DeviceData *devdata = NULL;
  21.150 -    char *stemp;
  21.151      DFBResult ret;
  21.152  
  21.153 -    SDL_DFB_CALLOC(devdata, 1, sizeof(*devdata));
  21.154 +    SDL_DFB_ALLOC_CLEAR(devdata, sizeof(*devdata));
  21.155  
  21.156      SDL_DFB_CHECKERR(DirectFBInit(NULL, NULL));
  21.157  
  21.158      /* avoid switching to the framebuffer when we
  21.159       * are running X11 */
  21.160 -    stemp = SDL_getenv(DFBENV_USE_X11_CHECK);
  21.161 -    if (stemp)
  21.162 -        ret = atoi(stemp);
  21.163 -    else
  21.164 -        ret = 1;
  21.165 -
  21.166 +    ret = readBoolEnv(DFBENV_USE_X11_CHECK , 1);
  21.167      if (ret) {
  21.168          if (SDL_getenv("DISPLAY"))
  21.169              DirectFBSetOption("system", "x11");
  21.170 @@ -210,22 +235,20 @@
  21.171      }
  21.172  
  21.173  	/* FIXME: Reenable as default once multi kbd/mouse interface is sorted out */
  21.174 -	devdata->use_linux_input = 0;       /* default: on */
  21.175 -    stemp = SDL_getenv(DFBENV_USE_LINUX_INPUT);
  21.176 -    if (stemp)
  21.177 -        devdata->use_linux_input = atoi(stemp);
  21.178 +	devdata->use_linux_input = readBoolEnv(DFBENV_USE_LINUX_INPUT, 0);       /* default: on */
  21.179  
  21.180      if (!devdata->use_linux_input)
  21.181 +    {
  21.182 +		SDL_DFB_LOG("Disabling linxu input\n");    
  21.183          DirectFBSetOption("disable-module", "linux_input");
  21.184 -
  21.185 +    }
  21.186 +    
  21.187      SDL_DFB_CHECKERR(DirectFBCreate(&dfb));
  21.188  
  21.189      DirectFB_DeviceInformation(dfb);
  21.190 -    devdata->use_yuv_underlays = 0;     /* default: off */
  21.191 -    stemp = SDL_getenv(DFBENV_USE_YUV_UNDERLAY);
  21.192 -    if (stemp)
  21.193 -        devdata->use_yuv_underlays = atoi(stemp);
  21.194 -
  21.195 +    
  21.196 +    devdata->use_yuv_underlays = readBoolEnv(DFBENV_USE_YUV_UNDERLAY, 0);     /* default: off */
  21.197 +    devdata->use_yuv_direct = readBoolEnv(DFBENV_USE_YUV_DIRECT, 0);      /* default is off! */
  21.198  
  21.199      /* Create global Eventbuffer for axis events */
  21.200      if (devdata->use_linux_input) {
  21.201 @@ -239,15 +262,11 @@
  21.202                                                       &devdata->events));
  21.203      }
  21.204  
  21.205 +    /* simple window manager support */
  21.206 +    devdata->has_own_wm = readBoolEnv(DFBENV_USE_WM, 0);
  21.207 +
  21.208      devdata->initialized = 1;
  21.209  
  21.210 -    /* simple window manager support */
  21.211 -    stemp = SDL_getenv(DFBENV_USE_WM);
  21.212 -    if (stemp)
  21.213 -        devdata->has_own_wm = atoi(stemp);
  21.214 -    else
  21.215 -        devdata->has_own_wm = 0;
  21.216 -
  21.217      devdata->dfb = dfb;
  21.218      devdata->firstwin = NULL;
  21.219      devdata->grabbed_window = NULL;
  21.220 @@ -260,7 +279,6 @@
  21.221      DirectFB_GL_Initialize(_this);
  21.222  #endif
  21.223  
  21.224 -    DirectFB_AddRenderDriver(_this);
  21.225      DirectFB_InitMouse(_this);
  21.226      DirectFB_InitKeyboard(_this);
  21.227  
  21.228 @@ -282,6 +300,7 @@
  21.229      DirectFB_QuitKeyboard(_this);
  21.230      DirectFB_QuitMouse(_this);
  21.231  
  21.232 +    devdata->events->Reset(devdata->events);
  21.233      SDL_DFB_RELEASE(devdata->events);
  21.234      SDL_DFB_RELEASE(devdata->dfb);
  21.235  
  21.236 @@ -291,3 +310,114 @@
  21.237  
  21.238      devdata->initialized = 0;
  21.239  }
  21.240 +
  21.241 +/* DirectFB driver general support functions */
  21.242 +
  21.243 +static const struct {
  21.244 +    DFBSurfacePixelFormat dfb;
  21.245 +    Uint32 sdl;
  21.246 +} pixelformat_tab[] = 
  21.247 +{
  21.248 +    { DSPF_RGB32, SDL_PIXELFORMAT_RGB888 },             /* 24 bit RGB (4 byte, nothing@24, red 8@16, green 8@8, blue 8@0) */
  21.249 +    { DSPF_ARGB, SDL_PIXELFORMAT_ARGB8888 },            /* 32 bit ARGB (4 byte, alpha 8@24, red 8@16, green 8@8, blue 8@0) */
  21.250 +    { DSPF_RGB16, SDL_PIXELFORMAT_RGB565 },             /* 16 bit RGB (2 byte, red 5@11, green 6@5, blue 5@0) */
  21.251 +    { DSPF_RGB332, SDL_PIXELFORMAT_RGB332 },            /* 8 bit RGB (1 byte, red 3@5, green 3@2, blue 2@0) */
  21.252 +    { DSPF_ARGB4444, SDL_PIXELFORMAT_ARGB4444 },        /* 16 bit ARGB (2 byte, alpha 4@12, red 4@8, green 4@4, blue 4@0) */
  21.253 +    { DSPF_ARGB1555, SDL_PIXELFORMAT_ARGB1555 },        /* 16 bit ARGB (2 byte, alpha 1@15, red 5@10, green 5@5, blue 5@0) */
  21.254 +    { DSPF_RGB24, SDL_PIXELFORMAT_RGB24 },              /* 24 bit RGB (3 byte, red 8@16, green 8@8, blue 8@0) */
  21.255 +    { DSPF_RGB444, SDL_PIXELFORMAT_RGB444 },            /* 16 bit RGB (2 byte, nothing @12, red 4@8, green 4@4, blue 4@0) */
  21.256 +    { DSPF_YV12, SDL_PIXELFORMAT_YV12 },                /* 12 bit YUV (8 bit Y plane followed by 8 bit quarter size V/U planes) */
  21.257 +    { DSPF_I420,SDL_PIXELFORMAT_IYUV },                 /* 12 bit YUV (8 bit Y plane followed by 8 bit quarter size U/V planes) */
  21.258 +    { DSPF_YUY2, SDL_PIXELFORMAT_YUY2 },                /* 16 bit YUV (4 byte/ 2 pixel, macropixel contains CbYCrY [31:0]) */
  21.259 +    { DSPF_UYVY, SDL_PIXELFORMAT_UYVY },                /* 16 bit YUV (4 byte/ 2 pixel, macropixel contains YCbYCr [31:0]) */
  21.260 +    { DSPF_RGB555, SDL_PIXELFORMAT_RGB555 },            /* 16 bit RGB (2 byte, nothing @15, red 5@10, green 5@5, blue 5@0) */
  21.261 +#if (ENABLE_LUT8)
  21.262 +    { DSPF_LUT8, SDL_PIXELFORMAT_INDEX8 },              /* 8 bit LUT (8 bit color and alpha lookup from palette) */
  21.263 +#endif
  21.264 +
  21.265 +#if (DFB_VERSION_ATLEAST(1,2,0))
  21.266 +    { DSPF_BGR555, SDL_PIXELFORMAT_BGR555 },            /* 16 bit BGR (2 byte, nothing @15, blue 5@10, green 5@5, red 5@0) */
  21.267 +#else
  21.268 +    { DSPF_UNKNOWN, SDL_PIXELFORMAT_BGR555 },
  21.269 +#endif
  21.270 +
  21.271 +    /* Pfff ... nonmatching formats follow */    
  21.272 +    
  21.273 +    { DSPF_ALUT44, SDL_PIXELFORMAT_UNKNOWN },           /* 8 bit ALUT (1 byte, alpha 4@4, color lookup 4@0) */
  21.274 + 	{ DSPF_A8, SDL_PIXELFORMAT_UNKNOWN },               /* 	8 bit alpha (1 byte, alpha 8@0), e.g. anti-aliased glyphs */
  21.275 + 	{ DSPF_AiRGB, SDL_PIXELFORMAT_UNKNOWN },            /* 	32 bit ARGB (4 byte, inv. alpha 8@24, red 8@16, green 8@8, blue 8@0) */
  21.276 + 	{ DSPF_A1, SDL_PIXELFORMAT_UNKNOWN },               /* 	1 bit alpha (1 byte/ 8 pixel, most significant bit used first) */
  21.277 + 	{ DSPF_NV12, SDL_PIXELFORMAT_UNKNOWN },             /* 	12 bit YUV (8 bit Y plane followed by one 16 bit quarter size CbCr [15:0] plane) */
  21.278 + 	{ DSPF_NV16, SDL_PIXELFORMAT_UNKNOWN },             /* 	16 bit YUV (8 bit Y plane followed by one 16 bit half width CbCr [15:0] plane) */
  21.279 + 	{ DSPF_ARGB2554, SDL_PIXELFORMAT_UNKNOWN },         /* 	16 bit ARGB (2 byte, alpha 2@14, red 5@9, green 5@4, blue 4@0) */
  21.280 + 	{ DSPF_NV21, SDL_PIXELFORMAT_UNKNOWN },             /* 	12 bit YUV (8 bit Y plane followed by one 16 bit quarter size CrCb [15:0] plane) */
  21.281 + 	{ DSPF_AYUV, SDL_PIXELFORMAT_UNKNOWN },             /* 	32 bit AYUV (4 byte, alpha 8@24, Y 8@16, Cb 8@8, Cr 8@0) */
  21.282 + 	{ DSPF_A4, SDL_PIXELFORMAT_UNKNOWN },               /* 	4 bit alpha (1 byte/ 2 pixel, more significant nibble used first) */
  21.283 + 	{ DSPF_ARGB1666, SDL_PIXELFORMAT_UNKNOWN },         /* 	1 bit alpha (3 byte/ alpha 1@18, red 6@16, green 6@6, blue 6@0) */
  21.284 + 	{ DSPF_ARGB6666, SDL_PIXELFORMAT_UNKNOWN },         /* 	6 bit alpha (3 byte/ alpha 6@18, red 6@16, green 6@6, blue 6@0) */
  21.285 + 	{ DSPF_RGB18, SDL_PIXELFORMAT_UNKNOWN },            /* 	6 bit RGB (3 byte/ red 6@16, green 6@6, blue 6@0) */
  21.286 + 	{ DSPF_LUT2, SDL_PIXELFORMAT_UNKNOWN },             /* 	2 bit LUT (1 byte/ 4 pixel, 2 bit color and alpha lookup from palette) */
  21.287 +
  21.288 +#if (DFB_VERSION_ATLEAST(1,3,0))
  21.289 + 	{ DSPF_RGBA4444, SDL_PIXELFORMAT_UNKNOWN },         /* 16 bit RGBA (2 byte, red 4@12, green 4@8, blue 4@4, alpha 4@0) */
  21.290 +#endif
  21.291 +
  21.292 +#if (DFB_VERSION_ATLEAST(1,4,3))
  21.293 + 	{ DSPF_RGBA5551, SDL_PIXELFORMAT_UNKNOWN },         /* 	16 bit RGBA (2 byte, red 5@11, green 5@6, blue 5@1, alpha 1@0) */
  21.294 + 	{ 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) */
  21.295 + 	{ DSPF_ARGB8565, SDL_PIXELFORMAT_UNKNOWN },         /* 	24 bit ARGB (3 byte, alpha 8@16, red 5@11, green 6@5, blue 5@0) */
  21.296 + 	{ 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) */
  21.297 + 	{ DSPF_VYU, SDL_PIXELFORMAT_UNKNOWN },              /* 	24 bit VYU 4:4:4 (3 byte, Cr 8@16, Y 8@8, Cb 8@0)  */
  21.298 +#endif
  21.299 + 	
  21.300 +    { DSPF_UNKNOWN, SDL_PIXELFORMAT_INDEX1LSB },
  21.301 +    { DSPF_UNKNOWN, SDL_PIXELFORMAT_INDEX1MSB },
  21.302 +    { DSPF_UNKNOWN, SDL_PIXELFORMAT_INDEX4LSB }, 
  21.303 +    { DSPF_UNKNOWN, SDL_PIXELFORMAT_INDEX4MSB },
  21.304 +    { DSPF_UNKNOWN, SDL_PIXELFORMAT_BGR24 },
  21.305 +    { DSPF_UNKNOWN, SDL_PIXELFORMAT_BGR888 },
  21.306 +    { DSPF_UNKNOWN, SDL_PIXELFORMAT_RGBA8888 },
  21.307 +    { DSPF_UNKNOWN, SDL_PIXELFORMAT_ABGR8888 },
  21.308 +    { DSPF_UNKNOWN, SDL_PIXELFORMAT_BGRA8888 },
  21.309 +    { DSPF_UNKNOWN, SDL_PIXELFORMAT_ARGB2101010 },
  21.310 +    { DSPF_UNKNOWN, SDL_PIXELFORMAT_ABGR4444 },
  21.311 +    { DSPF_UNKNOWN, SDL_PIXELFORMAT_ABGR1555 },
  21.312 +    { DSPF_UNKNOWN, SDL_PIXELFORMAT_BGR565 },
  21.313 +    { DSPF_UNKNOWN, SDL_PIXELFORMAT_YVYU },                        /**< Packed mode: Y0+V0+Y1+U0 (1 pla	*/
  21.314 +};
  21.315 +
  21.316 +Uint32
  21.317 +DirectFB_DFBToSDLPixelFormat(DFBSurfacePixelFormat pixelformat)
  21.318 +{
  21.319 +    int i;
  21.320 +    
  21.321 +    for (i=0; pixelformat_tab[i].dfb != DSPF_UNKNOWN; i++)
  21.322 +        if (pixelformat_tab[i].dfb == pixelformat)
  21.323 +        {
  21.324 +            return pixelformat_tab[i].sdl;
  21.325 +        }
  21.326 +    return SDL_PIXELFORMAT_UNKNOWN;
  21.327 +}
  21.328 +
  21.329 +DFBSurfacePixelFormat
  21.330 +DirectFB_SDLToDFBPixelFormat(Uint32 format)
  21.331 +{
  21.332 +    int i;
  21.333 +    
  21.334 +    for (i=0; pixelformat_tab[i].dfb != DSPF_UNKNOWN; i++)
  21.335 +        if (pixelformat_tab[i].sdl == format)
  21.336 +        {
  21.337 +            return pixelformat_tab[i].dfb;
  21.338 +        }
  21.339 +    return DSPF_UNKNOWN;
  21.340 +}
  21.341 +
  21.342 +void DirectFB_SetSupportedPixelFormats(SDL_RendererInfo* ri)
  21.343 +{
  21.344 +	int i, j;
  21.345 +
  21.346 +    for (i=0, j=0; pixelformat_tab[i].dfb != DSPF_UNKNOWN; i++)
  21.347 +    	if (pixelformat_tab[i].sdl != SDL_PIXELFORMAT_UNKNOWN)
  21.348 +    		ri->texture_formats[j++] = pixelformat_tab[i].sdl;
  21.349 +    ri->num_texture_formats = j;
  21.350 +}
    22.1 --- a/src/video/directfb/SDL_DirectFB_video.h	Sat Feb 05 16:02:30 2011 -0800
    22.2 +++ b/src/video/directfb/SDL_DirectFB_video.h	Sat Feb 05 16:07:10 2011 -0800
    22.3 @@ -18,28 +18,22 @@
    22.4  
    22.5      Sam Lantinga
    22.6      slouken@libsdl.org
    22.7 +
    22.8 +    SDL1.3 DirectFB driver by couriersud@arcor.de
    22.9 +	
   22.10  */
   22.11 +
   22.12  #include "SDL_config.h"
   22.13  
   22.14  #ifndef _SDL_DirectFB_video_h
   22.15  #define _SDL_DirectFB_video_h
   22.16  
   22.17 -#include "../SDL_sysvideo.h"
   22.18 -
   22.19  #include <directfb.h>
   22.20  #include <directfb_version.h>
   22.21  
   22.22 -#include "SDL_mouse.h"
   22.23 -
   22.24 -
   22.25 -/* Set below to 1 to compile with (old) multi mice/keyboard api. Code left in
   22.26 - * in case we see this again ... 
   22.27 - */
   22.28 -
   22.29 -#define USE_MULTI_API	(0)
   22.30 -
   22.31 -#define DEBUG 1
   22.32 -#define LOG_CHANNEL 	stdout
   22.33 +#include "../SDL_sysvideo.h"
   22.34 +#include "SDL_scancode.h"
   22.35 +#include "SDL_render.h"
   22.36  
   22.37  #define DFB_VERSIONNUM(X, Y, Z)						\
   22.38  	((X)*1000 + (Y)*100 + (Z))
   22.39 @@ -52,25 +46,29 @@
   22.40  
   22.41  #if (DFB_VERSION_ATLEAST(1,0,0))
   22.42  #define SDL_DIRECTFB_OPENGL 1
   22.43 -#include <directfbgl.h>
   22.44  #else
   22.45  #error "SDL_DIRECTFB: Please compile against libdirectfb version >= 1.0.0"
   22.46  #endif
   22.47  
   22.48 -#if SDL_DIRECTFB_OPENGL
   22.49 -#include "SDL_loadso.h"
   22.50 +/* Set below to 1 to compile with (old) multi mice/keyboard api. Code left in
   22.51 + * in case we see this again ... 
   22.52 + */
   22.53 +
   22.54 +#define USE_MULTI_API	(0)
   22.55 +
   22.56 +/* Support for LUT8/INDEX8 pixel format.
   22.57 + * This is broken in DirectFB 1.4.3. It works in 1.4.0 and 1.4.5
   22.58 + * occurred.
   22.59 + */
   22.60 +
   22.61 +#if (DFB_COMPILEDVERSION == DFB_VERSIONNUM(1, 4, 3))
   22.62 +#define ENABLE_LUT8		(0)
   22.63 +#else
   22.64 +#define ENABLE_LUT8		(1)
   22.65  #endif
   22.66  
   22.67 -#include "SDL_DirectFB_events.h"
   22.68 -/*
   22.69 - * #include "SDL_DirectFB_gamma.h"
   22.70 - * #include "SDL_DirectFB_keyboard.h"
   22.71 - */
   22.72 -#include "SDL_DirectFB_modes.h"
   22.73 -#include "SDL_DirectFB_mouse.h"
   22.74 -#include "SDL_DirectFB_opengl.h"
   22.75 -#include "SDL_DirectFB_window.h"
   22.76 -#include "SDL_DirectFB_WM.h"
   22.77 +#define DIRECTFB_DEBUG 1
   22.78 +#define LOG_CHANNEL 	stdout
   22.79  
   22.80  #define DFBENV_USE_YUV_UNDERLAY 	"SDL_DIRECTFB_YUV_UNDERLAY"     /* Default: off */
   22.81  #define DFBENV_USE_YUV_DIRECT   	"SDL_DIRECTFB_YUV_DIRECT"       /* Default: off */
   22.82 @@ -82,76 +80,103 @@
   22.83  #define SDL_DFB_FREE(x) do { if ( (x) != NULL ) { SDL_free(x); x = NULL; } } while (0)
   22.84  #define SDL_DFB_UNLOCK(x) do { if ( (x) != NULL ) { x->Unlock(x); } } while (0)
   22.85  
   22.86 -#if DEBUG
   22.87 -/* FIXME: do something with DEBUG */
   22.88 -#endif
   22.89 -
   22.90  #define SDL_DFB_CONTEXT "SDL_DirectFB"
   22.91  
   22.92 -static inline DFBResult sdl_dfb_check(DFBResult ret, const char *src_file, int src_line, const char *src_code) {
   22.93 +#define SDL_DFB_ERR(x...) 							\
   22.94 +	do {											\
   22.95 +		fprintf(LOG_CHANNEL, "%s: %s <%d>:\n\t",	\
   22.96 +			SDL_DFB_CONTEXT, __FILE__, __LINE__ );	\
   22.97 +        fprintf(LOG_CHANNEL, x ); 					\
   22.98 +	} while (0)
   22.99 +
  22.100 +#if (DIRECTFB_DEBUG)
  22.101 +
  22.102 +#define SDL_DFB_LOG(x...) 							\
  22.103 +	do {											\
  22.104 +		fprintf(LOG_CHANNEL, SDL_DFB_CONTEXT);		\
  22.105 +        fprintf(LOG_CHANNEL, x ); 					\
  22.106 +		fprintf(LOG_CHANNEL, "\n");					\
  22.107 +	} while (0)
  22.108 +
  22.109 +#define SDL_DFB_DEBUG(x...) SDL_DFB_ERR( x )
  22.110 +
  22.111 +static inline DFBResult sdl_dfb_check(DFBResult ret, const char *src_file, int src_line) {
  22.112  	if (ret != DFB_OK) {
  22.113 -		fprintf(LOG_CHANNEL, "%s <%d>:\n\t", src_file, src_line );
  22.114 -		fprintf(LOG_CHANNEL, "\t%s\n", src_code );
  22.115 -		fprintf(LOG_CHANNEL, "\t%s\n", DirectFBErrorString (ret) );
  22.116 -		SDL_SetError( src_code, DirectFBErrorString (ret) );
  22.117 +		SDL_DFB_LOG("%s (%d):%s", src_file, src_line, DirectFBErrorString (ret) );
  22.118 +		SDL_SetError("%s:%s", SDL_DFB_CONTEXT, DirectFBErrorString (ret) );
  22.119  	}
  22.120  	return ret;
  22.121  }
  22.122  
  22.123 -#define SDL_DFB_CHECK(x...) sdl_dfb_check( x, __FILE__, __LINE__, #x )
  22.124 +#define SDL_DFB_CHECK(x...) do { sdl_dfb_check( x, __FILE__, __LINE__); } while (0)
  22.125 +#define SDL_DFB_CHECKERR(x...) do { if ( sdl_dfb_check( x, __FILE__, __LINE__) != DFB_OK ) goto error; } while (0)
  22.126  
  22.127 -#define SDL_DFB_CHECKERR(x...) if ( sdl_dfb_check( x, __FILE__, __LINE__, #x ) != DFB_OK ) goto error
  22.128 +#else
  22.129  
  22.130 -#define SDL_DFB_DEBUG(x...) 							\
  22.131 -	do {											\
  22.132 -		fprintf(LOG_CHANNEL, "%s: %s <%d>:\n\t",			\
  22.133 -			SDL_DFB_CONTEXT, __FILE__, __LINE__ );	\
  22.134 -        fprintf(LOG_CHANNEL, x ); \
  22.135 -	} while (0)
  22.136 +#define SDL_DFB_CHECK(x...) x
  22.137 +#define SDL_DFB_CHECKERR(x...) do { if (x != DFB_OK ) goto error; } while (0)
  22.138 +#define SDL_DFB_LOG(x...) do {} while (0)
  22.139 +#define SDL_DFB_DEBUG(x...) do {} while (0)
  22.140  
  22.141 -#define SDL_DFB_ERR(x...) SDL_DFB_DEBUG( x )
  22.142 +#endif
  22.143 +
  22.144  
  22.145  #define SDL_DFB_CALLOC(r, n, s) \
  22.146 -     do {                                                                \
  22.147 -          r = SDL_calloc (n, s);                                      \
  22.148 -          if (!(r)) {                                                 \
  22.149 -               fprintf( LOG_CHANNEL, "%s <%d>:\n\t", __FILE__, __LINE__ ); \
  22.150 -               SDL_OutOfMemory();                                     \
  22.151 -               goto error; 					      \
  22.152 -          }                                                           \
  22.153 +     do {                                           \
  22.154 +          r = SDL_calloc (n, s);                    \
  22.155 +          if (!(r)) {                               \
  22.156 +               SDL_DFB_ERR("Out of memory"); 		\
  22.157 +               SDL_OutOfMemory();                   \
  22.158 +               goto error; 					      	\
  22.159 +          }                                         \
  22.160       } while (0)
  22.161  
  22.162 +#define SDL_DFB_ALLOC_CLEAR(r, s) SDL_DFB_CALLOC(r, 1, s)
  22.163 +
  22.164  /* Private display data */
  22.165  
  22.166  #define SDL_DFB_DEVICEDATA(dev)  DFB_DeviceData *devdata = (dev ? (DFB_DeviceData *) ((dev)->driverdata) : NULL)
  22.167  
  22.168  #define DFB_MAX_SCREENS 10
  22.169  
  22.170 +typedef struct _DFB_KeyboardData DFB_KeyboardData;
  22.171 +struct _DFB_KeyboardData
  22.172 +{
  22.173 +	const SDL_ScanCode	*map;		/* keyboard scancode map */
  22.174 +	int				map_size;	/* size of map */
  22.175 +	int				map_adjust; /* index adjust */
  22.176 +    int 			is_generic; /* generic keyboard */
  22.177 +    int id;
  22.178 +};
  22.179 +
  22.180  typedef struct _DFB_DeviceData DFB_DeviceData;
  22.181  struct _DFB_DeviceData
  22.182  {
  22.183      int initialized;
  22.184  
  22.185 -    IDirectFB *dfb;
  22.186 -    int num_mice;
  22.187 -    int mouse_id[0x100];
  22.188 -    int num_keyboard;
  22.189 -    struct
  22.190 -    {
  22.191 -        int is_generic;
  22.192 -        int id;
  22.193 -    } keyboard[10];
  22.194 -    DFB_WindowData *firstwin;
  22.195 +    IDirectFB 			*dfb;
  22.196 +    int 				num_mice;
  22.197 +    int 				mouse_id[0x100];
  22.198 +    int 				num_keyboard;
  22.199 +    DFB_KeyboardData 	keyboard[10];
  22.200 +    SDL_Window	 		*firstwin;
  22.201  
  22.202 -    int use_yuv_underlays;
  22.203 -    int use_linux_input;
  22.204 -    int has_own_wm;
  22.205 +    int 				use_yuv_underlays;
  22.206 +    int 				use_yuv_direct;
  22.207 +    int 				use_linux_input;
  22.208 +    int 				has_own_wm;
  22.209 +
  22.210  
  22.211  	/* window grab */
  22.212 -	SDL_Window *grabbed_window;
  22.213 +	SDL_Window 			*grabbed_window;
  22.214  
  22.215      /* global events */
  22.216      IDirectFBEventBuffer *events;
  22.217  };
  22.218  
  22.219 +Uint32 DirectFB_DFBToSDLPixelFormat(DFBSurfacePixelFormat pixelformat);
  22.220 +DFBSurfacePixelFormat DirectFB_SDLToDFBPixelFormat(Uint32 format);
  22.221 +void DirectFB_SetSupportedPixelFormats(SDL_RendererInfo *ri);
  22.222 +
  22.223 +
  22.224  #endif /* _SDL_DirectFB_video_h */
    23.1 --- a/src/video/directfb/SDL_DirectFB_window.c	Sat Feb 05 16:02:30 2011 -0800
    23.2 +++ b/src/video/directfb/SDL_DirectFB_window.c	Sat Feb 05 16:07:10 2011 -0800
    23.3 @@ -18,41 +18,49 @@
    23.4  
    23.5      Sam Lantinga
    23.6      slouken@libsdl.org
    23.7 +
    23.8 +    SDL1.3 DirectFB driver by couriersud@arcor.de
    23.9 +	
   23.10  */
   23.11 -#include "SDL_config.h"
   23.12 -
   23.13 -#include "SDL_syswm.h"
   23.14 -#include "../SDL_sysvideo.h"
   23.15 -#include "../../events/SDL_keyboard_c.h"
   23.16 -#include "../../video/SDL_pixels_c.h"
   23.17  
   23.18  #include "SDL_DirectFB_video.h"
   23.19 +#include "SDL_DirectFB_modes.h"
   23.20 +#include "SDL_DirectFB_window.h"
   23.21 +#include "SDL_DirectFB_shape.h"
   23.22 +
   23.23  #if SDL_DIRECTFB_OPENGL
   23.24  #include "SDL_DirectFB_opengl.h"
   23.25  #endif
   23.26  
   23.27 -static void DirectFB_AdjustWindowSurface(_THIS, SDL_Window * window);
   23.28 +#include "SDL_syswm.h"
   23.29 +
   23.30 +#include "../SDL_pixels_c.h"
   23.31  
   23.32  int
   23.33  DirectFB_CreateWindow(_THIS, SDL_Window * window)
   23.34  {
   23.35      SDL_DFB_DEVICEDATA(_this);
   23.36 -    SDL_DFB_DISPLAYDATA(_this, window);
   23.37 +    SDL_DFB_DISPLAYDATA(window);
   23.38      DFB_WindowData *windata = NULL;
   23.39      DFBWindowOptions wopts;
   23.40      DFBWindowDescription desc;
   23.41      int x, y;
   23.42 +    int bshaped = 0;
   23.43  
   23.44 -    SDL_DFB_CALLOC(window->driverdata, 1, sizeof(DFB_WindowData));
   23.45 +    SDL_DFB_ALLOC_CLEAR(window->driverdata, sizeof(DFB_WindowData));
   23.46      windata = (DFB_WindowData *) window->driverdata;
   23.47  
   23.48      windata->is_managed = devdata->has_own_wm;
   23.49 -
   23.50 +#if 1
   23.51      SDL_DFB_CHECKERR(devdata->dfb->SetCooperativeLevel(devdata->dfb,
   23.52                                                         DFSCL_NORMAL));
   23.53      SDL_DFB_CHECKERR(dispdata->layer->SetCooperativeLevel(dispdata->layer,
   23.54                                                            DLSCL_ADMINISTRATIVE));
   23.55 -
   23.56 +#endif
   23.57 +	/* FIXME ... ughh, ugly */
   23.58 +	if (window->x == -1000 && window->y == -1000)
   23.59 +		bshaped = 1;
   23.60 +	
   23.61      /* Fill the window description. */
   23.62      if (window->x == SDL_WINDOWPOS_CENTERED) {
   23.63          x = (dispdata->cw - window->w) / 2;
   23.64 @@ -61,6 +69,7 @@
   23.65      } else {
   23.66          x = window->x;
   23.67      }
   23.68 +    
   23.69      if (window->y == SDL_WINDOWPOS_CENTERED) {
   23.70          y = (dispdata->ch - window->h) / 2;
   23.71      } else if (window->y == SDL_WINDOWPOS_UNDEFINED) {
   23.72 @@ -68,6 +77,7 @@
   23.73      } else {
   23.74          y = window->y;
   23.75      }
   23.76 +    
   23.77      if (window->flags & SDL_WINDOW_FULLSCREEN) {
   23.78          x = 0;
   23.79          y = 0;
   23.80 @@ -76,78 +86,103 @@
   23.81      DirectFB_WM_AdjustWindowLayout(window, window->flags, window->w, window->h);
   23.82  
   23.83      /* Create Window */
   23.84 +	desc.caps = 0;
   23.85      desc.flags =
   23.86 -        DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_PIXELFORMAT | DWDESC_POSX
   23.87 -        | DWDESC_POSY | DWDESC_SURFACE_CAPS;
   23.88 +        DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_POSX | DWDESC_POSY | DWDESC_SURFACE_CAPS;
   23.89 +
   23.90 +    if (bshaped) {
   23.91 +    	desc.flags |= DWDESC_CAPS;
   23.92 +    	desc.caps |= DWCAPS_ALPHACHANNEL;
   23.93 +    }
   23.94 +    else
   23.95 +    {
   23.96 +    	desc.flags |= DWDESC_PIXELFORMAT;
   23.97 +    }
   23.98 +
   23.99 +    if (!(window->flags & SDL_WINDOW_BORDERLESS))
  23.100 +		desc.caps |= DWCAPS_NODECORATION;
  23.101 +
  23.102      desc.posx = x;
  23.103      desc.posy = y;
  23.104      desc.width = windata->size.w;
  23.105      desc.height = windata->size.h;
  23.106      desc.pixelformat = dispdata->pixelformat;
  23.107      desc.surface_caps = DSCAPS_PREMULTIPLIED;
  23.108 -
  23.109 +    
  23.110      /* Create the window. */
  23.111      SDL_DFB_CHECKERR(dispdata->layer->CreateWindow(dispdata->layer, &desc,
  23.112 -                                                   &windata->window));
  23.113 +                                                   &windata->dfbwin));
  23.114  
  23.115      /* Set Options */
  23.116 -    SDL_DFB_CHECK(windata->window->GetOptions(windata->window, &wopts));
  23.117 +    SDL_DFB_CHECK(windata->dfbwin->GetOptions(windata->dfbwin, &wopts));
  23.118  
  23.119 -    if (window->flags & SDL_WINDOW_RESIZABLE)
  23.120 -        wopts |= DWOP_SCALE;
  23.121 -    else
  23.122 +    /* explicit rescaling of surface */
  23.123 +    wopts |= DWOP_SCALE;
  23.124 +    if (window->flags & SDL_WINDOW_RESIZABLE) {
  23.125 +        wopts &= ~DWOP_KEEP_SIZE;
  23.126 +    }
  23.127 +    else {
  23.128          wopts |= DWOP_KEEP_SIZE;
  23.129 +    }
  23.130  
  23.131      if (window->flags & SDL_WINDOW_FULLSCREEN) {
  23.132          wopts |= DWOP_KEEP_POSITION | DWOP_KEEP_STACKING | DWOP_KEEP_SIZE;
  23.133 -        SDL_DFB_CHECK(windata->window->SetStackingClass(windata->window, DWSC_UPPER));
  23.134 +        SDL_DFB_CHECK(windata->dfbwin->SetStackingClass(windata->dfbwin, DWSC_UPPER));
  23.135      }
  23.136 -    SDL_DFB_CHECK(windata->window->SetOptions(windata->window, wopts));
  23.137 +    
  23.138 +    if (bshaped) {
  23.139 +        wopts |= DWOP_SHAPED | DWOP_ALPHACHANNEL;
  23.140 +        wopts &= ~DWOP_OPAQUE_REGION;
  23.141 +    }
  23.142 +
  23.143 +    SDL_DFB_CHECK(windata->dfbwin->SetOptions(windata->dfbwin, wopts));
  23.144  
  23.145      /* See what we got */
  23.146 -    SDL_DFB_CHECKERR(DirectFB_WM_GetClientSize
  23.147 +    SDL_DFB_CHECK(DirectFB_WM_GetClientSize
  23.148                       (_this, window, &window->w, &window->h));
  23.149  
  23.150      /* Get the window's surface. */
  23.151 -    SDL_DFB_CHECKERR(windata->window->GetSurface(windata->window,
  23.152 +    SDL_DFB_CHECKERR(windata->dfbwin->GetSurface(windata->dfbwin,
  23.153                                                   &windata->window_surface));
  23.154 +
  23.155      /* And get a subsurface for rendering */
  23.156      SDL_DFB_CHECKERR(windata->window_surface->
  23.157                       GetSubSurface(windata->window_surface, &windata->client,
  23.158                                     &windata->surface));
  23.159  
  23.160 -    SDL_DFB_CHECK(windata->window->SetOpacity(windata->window, 0xFF));
  23.161 +    SDL_DFB_CHECK(windata->dfbwin->SetOpacity(windata->dfbwin, 0xFF));
  23.162  
  23.163      /* Create Eventbuffer */
  23.164 -    SDL_DFB_CHECKERR(windata->window->CreateEventBuffer(windata->window,
  23.165 +
  23.166 +    SDL_DFB_CHECKERR(windata->dfbwin->CreateEventBuffer(windata->dfbwin,
  23.167                                                          &windata->
  23.168                                                          eventbuffer));
  23.169 -    SDL_DFB_CHECKERR(windata->window->
  23.170 -                     EnableEvents(windata->window, DWET_ALL));
  23.171 +    SDL_DFB_CHECKERR(windata->dfbwin->
  23.172 +                     EnableEvents(windata->dfbwin, DWET_ALL));
  23.173  
  23.174      /* Create a font */
  23.175      /* FIXME: once during Video_Init */
  23.176      windata->font = NULL;
  23.177  
  23.178      /* Make it the top most window. */
  23.179 -    SDL_DFB_CHECK(windata->window->RaiseToTop(windata->window));
  23.180 +    SDL_DFB_CHECK(windata->dfbwin->RaiseToTop(windata->dfbwin));
  23.181  
  23.182      /* remember parent */
  23.183 -    windata->sdl_window = window;
  23.184 +    //windata->sdlwin = window;
  23.185  
  23.186      /* Add to list ... */
  23.187  
  23.188      windata->next = devdata->firstwin;
  23.189      windata->opacity = 0xFF;
  23.190 -    devdata->firstwin = windata;
  23.191 +    devdata->firstwin = window;
  23.192  
  23.193      /* Draw Frame */
  23.194      DirectFB_WM_RedrawLayout(_this, window);
  23.195  
  23.196      return 0;
  23.197    error:
  23.198 -    SDL_DFB_RELEASE(windata->window);
  23.199 -    SDL_DFB_RELEASE(windata->surface);
  23.200 +	SDL_DFB_RELEASE(windata->surface);
  23.201 +    SDL_DFB_RELEASE(windata->dfbwin);
  23.202      return -1;
  23.203  }
  23.204  
  23.205 @@ -226,61 +261,69 @@
  23.206  DirectFB_SetWindowPosition(_THIS, SDL_Window * window)
  23.207  {
  23.208      SDL_DFB_WINDOWDATA(window);
  23.209 +    SDL_DFB_DISPLAYDATA(window);
  23.210      int x, y;
  23.211  
  23.212 -    if (window->y == SDL_WINDOWPOS_UNDEFINED)
  23.213 +    if (window->x == SDL_WINDOWPOS_CENTERED) {
  23.214 +        x = (dispdata->cw - window->w) / 2;
  23.215 +    } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
  23.216 +        x = 0;
  23.217 +    } else {
  23.218 +        x = window->x;
  23.219 +    }
  23.220 +    
  23.221 +    if (window->y == SDL_WINDOWPOS_CENTERED) {
  23.222 +        y = (dispdata->ch - window->h) / 2;
  23.223 +    } else if (window->y == SDL_WINDOWPOS_UNDEFINED) {
  23.224          y = 0;
  23.225 -    else
  23.226 +    } else {
  23.227          y = window->y;
  23.228 -
  23.229 -    if (window->x == SDL_WINDOWPOS_UNDEFINED)
  23.230 -        x = 0;
  23.231 -    else
  23.232 -        x = window->x;
  23.233 +    }
  23.234  
  23.235      if (window->flags & SDL_WINDOW_FULLSCREEN) {
  23.236          x = 0;
  23.237          y = 0;
  23.238      }
  23.239      DirectFB_WM_AdjustWindowLayout(window, window->flags, window->w, window->h);
  23.240 -    SDL_DFB_CHECK(windata->window->MoveTo(windata->window, x, y));
  23.241 +    SDL_DFB_CHECK(windata->dfbwin->MoveTo(windata->dfbwin, x, y));
  23.242  }
  23.243  
  23.244  void
  23.245  DirectFB_SetWindowSize(_THIS, SDL_Window * window)
  23.246  {
  23.247 -    //SDL_DFB_DEVICEDATA(_this);
  23.248      SDL_DFB_WINDOWDATA(window);
  23.249  
  23.250 +    if(SDL_IsShapedWindow(window))
  23.251 +        DirectFB_ResizeWindowShape(window);
  23.252 +
  23.253      if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
  23.254          int cw;
  23.255          int ch;
  23.256  
  23.257          /* Make sure all events are disabled for this operation ! */
  23.258 -        SDL_DFB_CHECKERR(windata->window->DisableEvents(windata->window,
  23.259 +        SDL_DFB_CHECKERR(windata->dfbwin->DisableEvents(windata->dfbwin,
  23.260                                                          DWET_ALL));
  23.261 -
  23.262          SDL_DFB_CHECKERR(DirectFB_WM_GetClientSize(_this, window, &cw, &ch));
  23.263  
  23.264          if (cw != window->w || ch != window->h) {
  23.265  
  23.266  		    DirectFB_WM_AdjustWindowLayout(window, window->flags, window->w, window->h);
  23.267 -            SDL_DFB_CHECKERR(windata->window->Resize(windata->window,
  23.268 +            SDL_DFB_CHECKERR(windata->dfbwin->Resize(windata->dfbwin,
  23.269                                                       windata->size.w,
  23.270                                                       windata->size.h));
  23.271          }
  23.272  
  23.273          SDL_DFB_CHECKERR(DirectFB_WM_GetClientSize
  23.274                       (_this, window, &window->w, &window->h));
  23.275 -        DirectFB_AdjustWindowSurface(_this, window);
  23.276 +        DirectFB_AdjustWindowSurface(window);
  23.277  
  23.278 -        SDL_DFB_CHECKERR(windata->window->EnableEvents(windata->window,
  23.279 +        SDL_DFB_CHECKERR(windata->dfbwin->EnableEvents(windata->dfbwin,
  23.280                                                         DWET_ALL));
  23.281  
  23.282      }
  23.283      return;
  23.284    error:
  23.285 -    SDL_DFB_CHECK(windata->window->EnableEvents(windata->window, DWET_ALL));
  23.286 +    SDL_DFB_CHECK(windata->dfbwin->EnableEvents(windata->dfbwin, DWET_ALL));
  23.287      return;
  23.288  }
  23.289  
  23.290 @@ -289,7 +332,7 @@
  23.291  {
  23.292      SDL_DFB_WINDOWDATA(window);
  23.293  
  23.294 -    SDL_DFB_CHECK(windata->window->SetOpacity(windata->window, windata->opacity));
  23.295 +    SDL_DFB_CHECK(windata->dfbwin->SetOpacity(windata->dfbwin, windata->opacity));
  23.296  
  23.297  }
  23.298  
  23.299 @@ -298,8 +341,8 @@
  23.300  {
  23.301      SDL_DFB_WINDOWDATA(window);
  23.302  
  23.303 -    SDL_DFB_CHECK(windata->window->GetOpacity(windata->window, &windata->opacity));
  23.304 -    SDL_DFB_CHECK(windata->window->SetOpacity(windata->window, 0));
  23.305 +    SDL_DFB_CHECK(windata->dfbwin->GetOpacity(windata->dfbwin, &windata->opacity));
  23.306 +    SDL_DFB_CHECK(windata->dfbwin->SetOpacity(windata->dfbwin, 0));
  23.307  }
  23.308  
  23.309  void
  23.310 @@ -307,19 +350,32 @@
  23.311  {
  23.312      SDL_DFB_WINDOWDATA(window);
  23.313  
  23.314 -    SDL_DFB_CHECK(windata->window->RaiseToTop(windata->window));
  23.315 -    SDL_DFB_CHECK(windata->window->RequestFocus(windata->window));
  23.316 +    SDL_DFB_CHECK(windata->dfbwin->RaiseToTop(windata->dfbwin));
  23.317 +    SDL_DFB_CHECK(windata->dfbwin->RequestFocus(windata->dfbwin));
  23.318  }
  23.319  
  23.320  void
  23.321  DirectFB_MaximizeWindow(_THIS, SDL_Window * window)
  23.322  {
  23.323      SDL_DFB_WINDOWDATA(window);
  23.324 +    SDL_VideoDisplay *display = window->display;
  23.325 +    DFBWindowOptions wopts;
  23.326  
  23.327 -    if (windata->is_managed) {
  23.328 -        DirectFB_WM_MaximizeWindow(_this, window);
  23.329 -    } else
  23.330 -        SDL_Unsupported();
  23.331 +    SDL_DFB_CHECK(windata->dfbwin->GetPosition(windata->dfbwin,
  23.332 +                                 &windata->restore.x, &windata->restore.y));
  23.333 +    SDL_DFB_CHECK(windata->dfbwin->GetSize(windata->dfbwin, &windata->restore.w,
  23.334 +                             &windata->restore.h));
  23.335 +
  23.336 +    DirectFB_WM_AdjustWindowLayout(window, window->flags | SDL_WINDOW_MAXIMIZED, display->current_mode.w, display->current_mode.h) ;
  23.337 +
  23.338 +    SDL_DFB_CHECK(windata->dfbwin->MoveTo(windata->dfbwin, 0, 0));
  23.339 +    SDL_DFB_CHECK(windata->dfbwin->Resize(windata->dfbwin,
  23.340 +                            display->current_mode.w, display->current_mode.h));
  23.341 +
  23.342 +    /* Set Options */
  23.343 +    SDL_DFB_CHECK(windata->dfbwin->GetOptions(windata->dfbwin, &wopts));
  23.344 +    wopts |= DWOP_KEEP_SIZE | DWOP_KEEP_POSITION;
  23.345 +    SDL_DFB_CHECK(windata->dfbwin->SetOptions(windata->dfbwin, wopts));
  23.346  }
  23.347  
  23.348  void
  23.349 @@ -334,11 +390,29 @@
  23.350  DirectFB_RestoreWindow(_THIS, SDL_Window * window)
  23.351  {
  23.352      SDL_DFB_WINDOWDATA(window);
  23.353 +    DFBWindowOptions wopts;
  23.354  
  23.355 -    if (windata->is_managed) {
  23.356 -        DirectFB_WM_RestoreWindow(_this, window);
  23.357 -    } else
  23.358 -        SDL_Unsupported();
  23.359 +    /* Set Options */
  23.360 +    SDL_DFB_CHECK(windata->dfbwin->GetOptions(windata->dfbwin, &wopts));
  23.361 +    wopts &= ~(DWOP_KEEP_SIZE | DWOP_KEEP_POSITION);
  23.362 +    SDL_DFB_CHECK(windata->dfbwin->SetOptions(windata->dfbwin, wopts));
  23.363 +
  23.364 +    /* Window layout */
  23.365 +    DirectFB_WM_AdjustWindowLayout(window, window->flags & ~(SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED),
  23.366 +    	windata->restore.w, windata->restore.h);
  23.367 +    SDL_DFB_CHECK(windata->dfbwin->Resize(windata->dfbwin, windata->restore.w,
  23.368 +                            windata->restore.h));
  23.369 +    SDL_DFB_CHECK(windata->dfbwin->MoveTo(windata->dfbwin, windata->restore.x,
  23.370 +                            windata->restore.y));
  23.371 +
  23.372 +    if (!(window->flags & SDL_WINDOW_RESIZABLE))
  23.373 +        wopts |= DWOP_KEEP_SIZE;
  23.374 +
  23.375 +    if (window->flags & SDL_WINDOW_FULLSCREEN)
  23.376 +        wopts |= DWOP_KEEP_POSITION | DWOP_KEEP_SIZE;
  23.377 +    SDL_DFB_CHECK(windata->dfbwin->SetOptions(windata->dfbwin, wopts));
  23.378 +
  23.379 +
  23.380  }
  23.381  
  23.382  void
  23.383 @@ -351,15 +425,15 @@
  23.384      if ((window->flags & SDL_WINDOW_INPUT_GRABBED)) {
  23.385          if (gwindata != NULL)
  23.386          {
  23.387 -		    SDL_DFB_CHECK(gwindata->window->UngrabPointer(gwindata->window));
  23.388 -		    SDL_DFB_CHECK(gwindata->window->UngrabKeyboard(gwindata->window));
  23.389 +		    SDL_DFB_CHECK(gwindata->dfbwin->UngrabPointer(gwindata->dfbwin));
  23.390 +		    SDL_DFB_CHECK(gwindata->dfbwin->UngrabKeyboard(gwindata->dfbwin));
  23.391          }
  23.392 -        SDL_DFB_CHECK(windata->window->GrabPointer(windata->window));
  23.393 -        SDL_DFB_CHECK(windata->window->GrabKeyboard(windata->window));
  23.394 +        SDL_DFB_CHECK(windata->dfbwin->GrabPointer(windata->dfbwin));
  23.395 +        SDL_DFB_CHECK(windata->dfbwin->GrabKeyboard(windata->dfbwin));
  23.396          devdata->grabbed_window = window;
  23.397      } else {
  23.398 -        SDL_DFB_CHECK(windata->window->UngrabPointer(windata->window));
  23.399 -        SDL_DFB_CHECK(windata->window->UngrabKeyboard(windata->window));
  23.400 +        SDL_DFB_CHECK(windata->dfbwin->UngrabPointer(windata->dfbwin));
  23.401 +        SDL_DFB_CHECK(windata->dfbwin->UngrabKeyboard(windata->dfbwin));
  23.402          devdata->grabbed_window = NULL;
  23.403      }
  23.404  }
  23.405 @@ -372,13 +446,22 @@
  23.406      DFB_WindowData *p;
  23.407  
  23.408      /* Some cleanups */
  23.409 -    SDL_DFB_CHECK(windata->window->UngrabPointer(windata->window));
  23.410 -    SDL_DFB_CHECK(windata->window->UngrabKeyboard(windata->window));
  23.411 +    SDL_DFB_CHECK(windata->dfbwin->UngrabPointer(windata->dfbwin));
  23.412 +    SDL_DFB_CHECK(windata->dfbwin->UngrabKeyboard(windata->dfbwin));
  23.413  
  23.414  #if SDL_DIRECTFB_OPENGL
  23.415  	DirectFB_GL_DestroyWindowContexts(_this, window);
  23.416  #endif
  23.417  
  23.418 +	if (window->shaper)
  23.419 +	{
  23.420 +	    SDL_ShapeData *data = window->shaper->driverdata;
  23.421 +	    SDL_DFB_CHECK(data->surface->ReleaseSource(data->surface));
  23.422 +    	SDL_DFB_RELEASE(data->surface);
  23.423 +    	SDL_DFB_FREE(data);
  23.424 +    	SDL_DFB_FREE(window->shaper);
  23.425 +	}
  23.426 +
  23.427      SDL_DFB_CHECK(windata->window_surface->SetFont(windata->window_surface, NULL));
  23.428      SDL_DFB_CHECK(windata->surface->ReleaseSource(windata->surface));
  23.429      SDL_DFB_CHECK(windata->window_surface->ReleaseSource(windata->window_surface));
  23.430 @@ -388,13 +471,14 @@
  23.431      SDL_DFB_RELEASE(windata->surface);
  23.432      SDL_DFB_RELEASE(windata->window_surface);
  23.433  
  23.434 -    SDL_DFB_RELEASE(windata->window);
  23.435 +    SDL_DFB_RELEASE(windata->dfbwin);
  23.436  
  23.437      /* Remove from list ... */
  23.438  
  23.439 -    p = devdata->firstwin;
  23.440 -    while (p && p->next != windata)
  23.441 -        p = p->next;
  23.442 +    p = devdata->firstwin->driverdata;
  23.443 +
  23.444 +    while (p && p->next != window)
  23.445 +        p = (p->next ? p->next->driverdata : NULL);
  23.446      if (p)
  23.447          p->next = windata->next;
  23.448      else
  23.449 @@ -407,12 +491,25 @@
  23.450  DirectFB_GetWindowWMInfo(_THIS, SDL_Window * window,
  23.451                           struct SDL_SysWMinfo * info)
  23.452  {
  23.453 -    SDL_Unsupported();
  23.454 -    return SDL_FALSE;
  23.455 +    SDL_DFB_DEVICEDATA(_this);
  23.456 +    SDL_DFB_WINDOWDATA(window);
  23.457 +
  23.458 +    if (info->version.major == SDL_MAJOR_VERSION &&
  23.459 +        info->version.minor == SDL_MINOR_VERSION) {
  23.460 +        info->subsystem = SDL_SYSWM_DIRECTFB;
  23.461 +        info->info.dfb.dfb = devdata->dfb;
  23.462 +        info->info.dfb.window = windata->dfbwin;
  23.463 +        info->info.dfb.surface = windata->surface;
  23.464 +        return SDL_TRUE;
  23.465 +    } else {
  23.466 +        SDL_SetError("Application not compiled with SDL %d.%d\n",
  23.467 +                     SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
  23.468 +        return SDL_FALSE;
  23.469 +    }
  23.470  }
  23.471  
  23.472 -static void
  23.473 -DirectFB_AdjustWindowSurface(_THIS, SDL_Window * window)
  23.474 +void
  23.475 +DirectFB_AdjustWindowSurface(SDL_Window * window)
  23.476  {
  23.477      SDL_DFB_WINDOWDATA(window);
  23.478      int adjust = windata->wm_needs_redraw;
  23.479 @@ -429,11 +526,11 @@
  23.480  
  23.481      if (adjust) {
  23.482  #if SDL_DIRECTFB_OPENGL
  23.483 -		DirectFB_GL_FreeWindowContexts(_this, window);
  23.484 +		DirectFB_GL_FreeWindowContexts(window->display->device, window);
  23.485  #endif
  23.486  
  23.487 -#if DFB_VERSION_ATLEAST(1,2,1)
  23.488 -        SDL_DFB_CHECKERR(windata->window->ResizeSurface(windata->window,
  23.489 +#if (DFB_VERSION_ATLEAST(1,2,1))
  23.490 +        SDL_DFB_CHECKERR(windata->dfbwin->ResizeSurface(windata->dfbwin,
  23.491                                                          windata->size.w,
  23.492                                                          windata->size.h));
  23.493          SDL_DFB_CHECKERR(windata->surface->MakeSubSurface(windata->surface,
  23.494 @@ -443,22 +540,22 @@
  23.495  #else
  23.496          DFBWindowOptions opts;
  23.497  
  23.498 -        SDL_DFB_CHECKERR(windata->window->GetOptions(windata->window, &opts));
  23.499 +        SDL_DFB_CHECKERR(windata->dfbwin->GetOptions(windata->dfbwin, &opts));
  23.500          /* recreate subsurface */
  23.501          SDL_DFB_RELEASE(windata->surface);
  23.502  
  23.503          if (opts & DWOP_SCALE)
  23.504 -            SDL_DFB_CHECKERR(windata->window->ResizeSurface(windata->window,
  23.505 +            SDL_DFB_CHECKERR(windata->dfbwin->ResizeSurface(windata->dfbwin,
  23.506                                                              windata->size.w,
  23.507                                                              windata->size.h));
  23.508          SDL_DFB_CHECKERR(windata->window_surface->
  23.509                           GetSubSurface(windata->window_surface,
  23.510                                         &windata->client, &windata->surface));
  23.511  #endif
  23.512 -        DirectFB_WM_RedrawLayout(_this, window);
  23.513 +        DirectFB_WM_RedrawLayout(window->display->device, window);
  23.514          
  23.515  #if SDL_DIRECTFB_OPENGL
  23.516 -		DirectFB_GL_ReAllocWindowContexts(_this, window);
  23.517 +		DirectFB_GL_ReAllocWindowContexts(window->display->device, window);
  23.518  #endif
  23.519     }
  23.520    error:
    24.1 --- a/src/video/directfb/SDL_DirectFB_window.h	Sat Feb 05 16:02:30 2011 -0800
    24.2 +++ b/src/video/directfb/SDL_DirectFB_window.h	Sat Feb 05 16:07:10 2011 -0800
    24.3 @@ -18,12 +18,15 @@
    24.4  
    24.5      Sam Lantinga
    24.6      slouken@libsdl.org
    24.7 +
    24.8 +    SDL1.3 DirectFB driver by couriersud@arcor.de
    24.9 +	
   24.10  */
   24.11 -#include "SDL_config.h"
   24.12  
   24.13  #ifndef _SDL_directfb_window_h
   24.14  #define _SDL_directfb_window_h
   24.15  
   24.16 +#include "SDL_DirectFB_video.h"
   24.17  #include "SDL_DirectFB_WM.h"
   24.18  
   24.19  #define SDL_DFB_WINDOWDATA(win)  DFB_WindowData *windata = ((win) ? (DFB_WindowData *) ((win)->driverdata) : NULL)
   24.20 @@ -31,22 +34,28 @@
   24.21  typedef struct _DFB_WindowData DFB_WindowData;
   24.22  struct _DFB_WindowData
   24.23  {
   24.24 -    IDirectFBSurface *surface;
   24.25 -    IDirectFBSurface *window_surface;   /* only used with has_own_wm */
   24.26 -    IDirectFBWindow *window;
   24.27 -    IDirectFBEventBuffer *eventbuffer;
   24.28 -    SDL_Window *sdl_window;
   24.29 -    DFB_WindowData *next;
   24.30 -    Uint8 opacity;
   24.31 -    DFBRectangle client;
   24.32 -    DFBDimension size;
   24.33 +    IDirectFBSurface 		*window_surface;	/* window surface */
   24.34 +    IDirectFBSurface 		*surface;			/* client drawing surface */
   24.35 +    IDirectFBWindow 		*dfbwin;
   24.36 +    IDirectFBEventBuffer 	*eventbuffer;
   24.37 +    //SDL_Window 				*sdlwin;
   24.38 +    SDL_Window	 			*next;
   24.39 +    Uint8 					opacity;
   24.40 +    DFBRectangle 			client;
   24.41 +    DFBDimension 			size;
   24.42 +    DFBRectangle 			restore;
   24.43 +
   24.44      /* WM extras */
   24.45 -    DFBRectangle restore;
   24.46 -    int is_managed;
   24.47 -    int wm_needs_redraw;
   24.48 -    IDirectFBSurface *icon;
   24.49 -    IDirectFBFont *font;
   24.50 -    DFB_Theme theme;
   24.51 +    int 					is_managed;
   24.52 +    int 					wm_needs_redraw;
   24.53 +    IDirectFBSurface 		*icon;
   24.54 +    IDirectFBFont 			*font;
   24.55 +    DFB_Theme 				theme;
   24.56 +
   24.57 +    /* WM moving and sizing */
   24.58 +    int 					wm_grab;
   24.59 +    int 					wm_lastx;
   24.60 +    int 					wm_lasty;
   24.61  };
   24.62  
   24.63  extern int DirectFB_CreateWindow(_THIS, SDL_Window * window);
   24.64 @@ -69,7 +78,7 @@
   24.65  extern SDL_bool DirectFB_GetWindowWMInfo(_THIS, SDL_Window * window,
   24.66                                           struct SDL_SysWMinfo *info);
   24.67  
   24.68 -//extern void DirectFB_AdjustWindowSurface(_THIS, SDL_Window * window);
   24.69 +extern void DirectFB_AdjustWindowSurface(SDL_Window * window);
   24.70  
   24.71  #endif /* _SDL_directfb_window_h */
   24.72