Added support for DirectFB video on Linux (thanks Denis!)
authorSam Lantinga <slouken@libsdl.org>
Tue, 04 Sep 2001 22:53:46 +0000
changeset 167cb384ef627f6
parent 166 39877400bd1e
child 168 e92aa316c517
Added support for DirectFB video on Linux (thanks Denis!)
configure.in
docs.html
src/video/Makefile.am
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/directfb/.cvsignore
src/video/directfb/Makefile.am
src/video/directfb/SDL_DirectFB_events.c
src/video/directfb/SDL_DirectFB_events.h
src/video/directfb/SDL_DirectFB_keys.h
src/video/directfb/SDL_DirectFB_video.c
src/video/directfb/SDL_DirectFB_video.h
     1.1 --- a/configure.in	Tue Sep 04 22:48:09 2001 +0000
     1.2 +++ b/configure.in	Tue Sep 04 22:53:46 2001 +0000
     1.3 @@ -695,6 +695,46 @@
     1.4      fi
     1.5  }
     1.6  
     1.7 +dnl Find DirectFB
     1.8 +CheckDirectFB()
     1.9 +{
    1.10 +    AC_ARG_ENABLE(video-directfb,
    1.11 +[  --enable-video-directfb    use DirectFB video driver [default=yes]],
    1.12 +                  , enable_video_directfb=yes)
    1.13 +    if test x$enable_video = xyes -a x$enable_video_directfb = xyes; then
    1.14 +        video_directfb=no
    1.15 +
    1.16 +        AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
    1.17 +        if test x$PKG_CONFIG = xno ; then
    1.18 +            AC_MSG_WARN([*** pkg-config is required to build the DirectFB video driver.])
    1.19 +        else
    1.20 +            AC_MSG_CHECKING(for DirectFB support)
    1.21 +
    1.22 +            if ! pkg-config --atleast-pkgconfig-version 0.5 ; then
    1.23 +                AC_MSG_ERROR([*** pkg-config too old; version 0.5 or better required.])
    1.24 +            fi
    1.25 +
    1.26 +            DIRECTFB_REQUIRED_VERSION=0.9.5
    1.27 +
    1.28 +            if $PKG_CONFIG --atleast-version $DIRECTFB_REQUIRED_VERSION directfb ; then
    1.29 +                DIRECTFB_CFLAGS=`$PKG_CONFIG --cflags directfb`
    1.30 +                DIRECTFB_LIBS=`$PKG_CONFIG --libs directfb`
    1.31 +                video_directfb=yes
    1.32 +            fi
    1.33 +        fi
    1.34 +
    1.35 +        AC_MSG_RESULT($video_directfb)
    1.36 +        if test x$video_directfb = xyes; then
    1.37 +            CFLAGS="$CFLAGS -DENABLE_DIRECTFB"
    1.38 +            VIDEO_SUBDIRS="$VIDEO_SUBDIRS directfb"
    1.39 +            VIDEO_DRIVERS="$VIDEO_DRIVERS directfb/libvideo_directfb.la"
    1.40 +
    1.41 +            AC_SUBST(DIRECTFB_CFLAGS)
    1.42 +            AC_SUBST(DIRECTFB_LIBS)
    1.43 +        fi
    1.44 +    fi
    1.45 +}
    1.46 +
    1.47  dnl See if we're running on PlayStation 2 hardware
    1.48  CheckPS2GS()
    1.49  {
    1.50 @@ -1219,6 +1259,7 @@
    1.51          CheckNANOX
    1.52          CheckDGA
    1.53          CheckFBCON
    1.54 +        CheckDirectFB
    1.55          CheckPS2GS
    1.56          CheckGGI
    1.57          CheckSVGA
    1.58 @@ -2174,6 +2215,7 @@
    1.59  src/video/dga/Makefile
    1.60  src/video/nanox/Makefile
    1.61  src/video/fbcon/Makefile
    1.62 +src/video/directfb/Makefile
    1.63  src/video/ps2gs/Makefile
    1.64  src/video/ggi/Makefile
    1.65  src/video/maccommon/Makefile
     2.1 --- a/docs.html	Tue Sep 04 22:48:09 2001 +0000
     2.2 +++ b/docs.html	Tue Sep 04 22:53:46 2001 +0000
     2.3 @@ -16,6 +16,7 @@
     2.4  Major changes since SDL 1.0.0:
     2.5  </H2>
     2.6  <UL>
     2.7 +	<LI> 1.2.3: Added support for DirectFB video on Linux (thanks Denis!)
     2.8  	<LI> 1.2.3: Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
     2.9  	<LI> 1.2.3: Fixed the system dependent SDL_WINDOWID hack on Windows
    2.10  	<LI> 1.2.3: Added 640x480 as a scaled resolution for NTSC/PAL output 
     3.1 --- a/src/video/Makefile.am	Tue Sep 04 22:48:09 2001 +0000
     3.2 +++ b/src/video/Makefile.am	Tue Sep 04 22:53:46 2001 +0000
     3.3 @@ -5,7 +5,7 @@
     3.4  
     3.5  # Define which subdirectories need to be built
     3.6  SUBDIRS = @VIDEO_SUBDIRS@
     3.7 -DIST_SUBDIRS = dummy x11 dga nanox fbcon vgl svga ggi aalib \
     3.8 +DIST_SUBDIRS = dummy x11 dga nanox fbcon directfb vgl svga ggi aalib \
     3.9                 wincommon windib windx5 \
    3.10                 maccommon macdsp macrom quartz \
    3.11                 bwindow ps2gs photon cybergfx
     4.1 --- a/src/video/SDL_sysvideo.h	Tue Sep 04 22:48:09 2001 +0000
     4.2 +++ b/src/video/SDL_sysvideo.h	Tue Sep 04 22:53:46 2001 +0000
     4.3 @@ -337,6 +337,9 @@
     4.4  #ifdef ENABLE_FBCON
     4.5  extern VideoBootStrap FBCON_bootstrap;
     4.6  #endif
     4.7 +#ifdef ENABLE_DIRECTFB
     4.8 +extern VideoBootStrap DirectFB_bootstrap;
     4.9 +#endif
    4.10  #ifdef ENABLE_PS2GS
    4.11  extern VideoBootStrap PS2GS_bootstrap;
    4.12  #endif
     5.1 --- a/src/video/SDL_video.c	Tue Sep 04 22:48:09 2001 +0000
     5.2 +++ b/src/video/SDL_video.c	Tue Sep 04 22:53:46 2001 +0000
     5.3 @@ -57,6 +57,9 @@
     5.4  #ifdef ENABLE_FBCON
     5.5  	&FBCON_bootstrap,
     5.6  #endif
     5.7 +#ifdef ENABLE_DIRECTFB
     5.8 +	&DirectFB_bootstrap,
     5.9 +#endif
    5.10  #ifdef ENABLE_PS2GS
    5.11  	&PS2GS_bootstrap,
    5.12  #endif
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/video/directfb/.cvsignore	Tue Sep 04 22:53:46 2001 +0000
     6.3 @@ -0,0 +1,6 @@
     6.4 +Makefile.in
     6.5 +Makefile
     6.6 +.libs
     6.7 +*.o
     6.8 +*.lo
     6.9 +*.la
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/video/directfb/Makefile.am	Tue Sep 04 22:53:46 2001 +0000
     7.3 @@ -0,0 +1,15 @@
     7.4 +
     7.5 +## Makefile.am for SDL using the DirectFB video driver
     7.6 +
     7.7 +CFLAGS = @CFLAGS@ $(DIRECTFB_CFLAGS)
     7.8 +
     7.9 +noinst_LTLIBRARIES = libvideo_directfb.la
    7.10 +libvideo_directfb_la_SOURCES = $(DIRECTFB_SRCS)
    7.11 +libvideo_directfb_la_LIBADD  = $(DIRECTFB_LIBS)
    7.12 +
    7.13 +# The SDL DirectFB video driver sources
    7.14 +DIRECTFB_SRCS = 		\
    7.15 +	SDL_DirectFB_events.c	\
    7.16 +	SDL_DirectFB_events.h	\
    7.17 +	SDL_DirectFB_video.c	\
    7.18 +	SDL_DirectFB_video.h
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/video/directfb/SDL_DirectFB_events.c	Tue Sep 04 22:53:46 2001 +0000
     8.3 @@ -0,0 +1,222 @@
     8.4 +/*
     8.5 +	SDL - Simple DirectMedia Layer
     8.6 +	Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
     8.7 +
     8.8 +	This library is free software; you can redistribute it and/or
     8.9 +	modify it under the terms of the GNU Library General Public
    8.10 +	License as published by the Free Software Foundation; either
    8.11 +	version 2 of the License, or (at your option) any later version.
    8.12 +
    8.13 +	This library is distributed in the hope that it will be useful,
    8.14 +	but WITHOUT ANY WARRANTY; without even the implied warranty of
    8.15 +	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    8.16 +	Library General Public License for more details.
    8.17 +
    8.18 +	You should have received a copy of the GNU Library General Public
    8.19 +	License along with this library; if not, write to the Free
    8.20 +	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    8.21 +
    8.22 +	Sam Lantinga
    8.23 +	slouken@devolution.com
    8.24 +*/
    8.25 +
    8.26 +#ifdef SAVE_RCSID
    8.27 +static char rcsid =
    8.28 + "@(#) $Id$";
    8.29 +#endif
    8.30 +
    8.31 +/* Handle the event stream, converting DirectFB input events into SDL events */
    8.32 +
    8.33 +#include <sys/types.h>
    8.34 +#include <sys/time.h>
    8.35 +#include <stdlib.h>
    8.36 +#include <stdio.h>
    8.37 +#include <unistd.h>
    8.38 +#include <fcntl.h>
    8.39 +#include <termios.h>
    8.40 +
    8.41 +#include <directfb.h>
    8.42 +
    8.43 +#include "SDL.h"
    8.44 +#include "SDL_sysevents.h"
    8.45 +#include "SDL_sysvideo.h"
    8.46 +#include "SDL_events_c.h"
    8.47 +#include "SDL_DirectFB_video.h"
    8.48 +#include "SDL_DirectFB_events.h"
    8.49 +
    8.50 +/* The translation tables from a DirectFB keycode to a SDL keysym */
    8.51 +static SDLKey keymap[256];
    8.52 +static SDL_keysym *DirectFB_TranslateKey (DFBInputEvent *ev, SDL_keysym *keysym);
    8.53 +static int DirectFB_TranslateButton (DFBInputEvent *ev);
    8.54 +
    8.55 +static int posted = 0;
    8.56 +
    8.57 +
    8.58 +void DirectFB_PumpEvents (_THIS)
    8.59 +{
    8.60 +  DFBInputEvent evt;
    8.61 +
    8.62 +  while (HIDDEN->inputbuffer->GetEvent (HIDDEN->inputbuffer, &evt) == DFB_OK)
    8.63 +    {
    8.64 +      SDL_keysym keysym;
    8.65 +
    8.66 +      switch (evt.type)
    8.67 +        {
    8.68 +        case DIET_BUTTONPRESS:
    8.69 +          posted += SDL_PrivateMouseButton(SDL_PRESSED,
    8.70 +                                           DirectFB_TranslateButton (&evt), 0, 0);
    8.71 +          break;
    8.72 +        case DIET_BUTTONRELEASE:
    8.73 +          posted += SDL_PrivateMouseButton(SDL_RELEASED,
    8.74 +                                           DirectFB_TranslateButton (&evt), 0, 0);
    8.75 +          break;
    8.76 +        case DIET_KEYPRESS:
    8.77 +          posted += SDL_PrivateKeyboard(SDL_PRESSED, DirectFB_TranslateKey(&evt, &keysym));
    8.78 +          break;
    8.79 +        case DIET_KEYRELEASE:
    8.80 +          posted += SDL_PrivateKeyboard(SDL_RELEASED, DirectFB_TranslateKey(&evt, &keysym));
    8.81 +          break;
    8.82 +        case DIET_AXISMOTION:
    8.83 +          if (evt.flags & DIEF_AXISREL)
    8.84 +            {
    8.85 +              if (evt.axis == DIAI_X)
    8.86 +                posted += SDL_PrivateMouseMotion(0, 1, evt.axisrel, 0);
    8.87 +              else if (evt.axis == DIAI_Y)
    8.88 +                posted += SDL_PrivateMouseMotion(0, 1, 0, evt.axisrel);
    8.89 +            }
    8.90 +          break;
    8.91 +        default:
    8.92 +          ;
    8.93 +        }
    8.94 +    }
    8.95 +}
    8.96 +
    8.97 +void DirectFB_InitOSKeymap (_THIS)
    8.98 +{
    8.99 +  int i;
   8.100 +	
   8.101 +  /* Initialize the DirectFB key translation table */
   8.102 +  for (i=0; i<SDL_TABLESIZE(keymap); ++i)
   8.103 +    keymap[i] = SDLK_UNKNOWN;
   8.104 +
   8.105 +  keymap[DIKC_A] = SDLK_a;
   8.106 +  keymap[DIKC_B] = SDLK_b;
   8.107 +  keymap[DIKC_C] = SDLK_c;
   8.108 +  keymap[DIKC_D] = SDLK_d;
   8.109 +  keymap[DIKC_E] = SDLK_e;
   8.110 +  keymap[DIKC_F] = SDLK_f;
   8.111 +  keymap[DIKC_G] = SDLK_g;
   8.112 +  keymap[DIKC_H] = SDLK_h;
   8.113 +  keymap[DIKC_I] = SDLK_i;
   8.114 +  keymap[DIKC_J] = SDLK_j;
   8.115 +  keymap[DIKC_K] = SDLK_k;
   8.116 +  keymap[DIKC_L] = SDLK_l;
   8.117 +  keymap[DIKC_M] = SDLK_m;
   8.118 +  keymap[DIKC_N] = SDLK_n;
   8.119 +  keymap[DIKC_O] = SDLK_o;
   8.120 +  keymap[DIKC_P] = SDLK_p;
   8.121 +  keymap[DIKC_Q] = SDLK_q;
   8.122 +  keymap[DIKC_R] = SDLK_r;
   8.123 +  keymap[DIKC_S] = SDLK_s;
   8.124 +  keymap[DIKC_T] = SDLK_t;
   8.125 +  keymap[DIKC_U] = SDLK_u;
   8.126 +  keymap[DIKC_V] = SDLK_v;
   8.127 +  keymap[DIKC_W] = SDLK_w;
   8.128 +  keymap[DIKC_X] = SDLK_x;
   8.129 +  keymap[DIKC_Y] = SDLK_y;
   8.130 +  keymap[DIKC_Z] = SDLK_z;
   8.131 +  
   8.132 +  keymap[DIKC_0] = SDLK_0;
   8.133 +  keymap[DIKC_1] = SDLK_1;
   8.134 +  keymap[DIKC_2] = SDLK_2;
   8.135 +  keymap[DIKC_3] = SDLK_3;
   8.136 +  keymap[DIKC_4] = SDLK_4;
   8.137 +  keymap[DIKC_5] = SDLK_5;
   8.138 +  keymap[DIKC_6] = SDLK_6;
   8.139 +  keymap[DIKC_7] = SDLK_7;
   8.140 +  keymap[DIKC_8] = SDLK_8;
   8.141 +  keymap[DIKC_9] = SDLK_9;
   8.142 +  
   8.143 +  keymap[DIKC_F1] = SDLK_F1;
   8.144 +  keymap[DIKC_F2] = SDLK_F2;
   8.145 +  keymap[DIKC_F3] = SDLK_F3;
   8.146 +  keymap[DIKC_F4] = SDLK_F4;
   8.147 +  keymap[DIKC_F5] = SDLK_F5;
   8.148 +  keymap[DIKC_F6] = SDLK_F6;
   8.149 +  keymap[DIKC_F7] = SDLK_F7;
   8.150 +  keymap[DIKC_F8] = SDLK_F8;
   8.151 +  keymap[DIKC_F9] = SDLK_F9;
   8.152 +  keymap[DIKC_F10] = SDLK_F10;
   8.153 +  keymap[DIKC_F11] = SDLK_F11;
   8.154 +  keymap[DIKC_F12] = SDLK_F12;
   8.155 +  
   8.156 +  keymap[DIKC_ESCAPE] = SDLK_ESCAPE;
   8.157 +  keymap[DIKC_LEFT] = SDLK_LEFT;
   8.158 +  keymap[DIKC_RIGHT] = SDLK_RIGHT;
   8.159 +  keymap[DIKC_UP] = SDLK_UP;
   8.160 +  keymap[DIKC_DOWN] = SDLK_DOWN;
   8.161 +  keymap[DIKC_CTRL] = SDLK_LCTRL;
   8.162 +  keymap[DIKC_SHIFT] = SDLK_LSHIFT;
   8.163 +  keymap[DIKC_ALT] = SDLK_LALT;
   8.164 +  keymap[DIKC_ALTGR] = SDLK_RALT;
   8.165 +  keymap[DIKC_TAB] = SDLK_TAB;
   8.166 +  keymap[DIKC_ENTER] = SDLK_RETURN;
   8.167 +  keymap[DIKC_SPACE] = SDLK_SPACE;
   8.168 +  keymap[DIKC_BACKSPACE] = SDLK_BACKSPACE;
   8.169 +  keymap[DIKC_INSERT] = SDLK_INSERT;
   8.170 +  keymap[DIKC_DELETE] = SDLK_DELETE;
   8.171 +  keymap[DIKC_HOME] = SDLK_HOME;
   8.172 +  keymap[DIKC_END] = SDLK_END;
   8.173 +  keymap[DIKC_PAGEUP] = SDLK_PAGEUP;
   8.174 +  keymap[DIKC_PAGEDOWN] = SDLK_PAGEDOWN;
   8.175 +  keymap[DIKC_CAPSLOCK] = SDLK_CAPSLOCK;
   8.176 +  keymap[DIKC_NUMLOCK] = SDLK_NUMLOCK;
   8.177 +  keymap[DIKC_SCRLOCK] = SDLK_SCROLLOCK;
   8.178 +  keymap[DIKC_PRINT] = SDLK_PRINT;
   8.179 +  keymap[DIKC_PAUSE] = SDLK_PAUSE;
   8.180 +  keymap[DIKC_KP_DIV] = SDLK_KP_DIVIDE;
   8.181 +  keymap[DIKC_KP_MULT] = SDLK_KP_MULTIPLY;
   8.182 +  keymap[DIKC_KP_MINUS] = SDLK_KP_MINUS;
   8.183 +  keymap[DIKC_KP_PLUS] = SDLK_KP_PLUS;
   8.184 +  keymap[DIKC_KP_ENTER] = SDLK_KP_ENTER;
   8.185 +  
   8.186 +  keymap[DIKC_OK] = SDLK_RETURN;
   8.187 +  keymap[DIKC_CANCEL] = SDLK_BREAK;
   8.188 +  keymap[DIKC_CLEAR] = SDLK_DELETE;
   8.189 +  keymap[DIKC_POWER] = SDLK_POWER;
   8.190 +  keymap[DIKC_POWER2] = SDLK_POWER;
   8.191 +  keymap[DIKC_MENU] = SDLK_MENU;
   8.192 +  keymap[DIKC_HELP] = SDLK_HELP;
   8.193 +  keymap[DIKC_BACK] = SDLK_ESCAPE;
   8.194 +}
   8.195 +
   8.196 +
   8.197 +static SDL_keysym *DirectFB_TranslateKey (DFBInputEvent *ev, SDL_keysym *keysym)
   8.198 +{
   8.199 +  /* Set the keysym information */
   8.200 +  keysym->scancode = ev->keycode;
   8.201 +  keysym->mod = KMOD_NONE;
   8.202 +  keysym->unicode = 0;
   8.203 +
   8.204 +  if (ev->key_ascii > 0 && ev->key_ascii < 128)
   8.205 +    keysym->sym = ev->key_ascii;
   8.206 +  else
   8.207 +    keysym->sym = keymap[ev->keycode];
   8.208 +
   8.209 +  return keysym;
   8.210 +}
   8.211 +
   8.212 +static int DirectFB_TranslateButton (DFBInputEvent *ev)
   8.213 +{
   8.214 +  switch (ev->button)
   8.215 +    {
   8.216 +    case DIBI_LEFT:
   8.217 +      return 1;
   8.218 +    case DIBI_MIDDLE:
   8.219 +      return 2;
   8.220 +    case DIBI_RIGHT:
   8.221 +      return 3;
   8.222 +    default:
   8.223 +      return 0;
   8.224 +    }
   8.225 +}
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/src/video/directfb/SDL_DirectFB_events.h	Tue Sep 04 22:53:46 2001 +0000
     9.3 @@ -0,0 +1,33 @@
     9.4 +/*
     9.5 +    SDL - Simple DirectMedia Layer
     9.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
     9.7 +
     9.8 +    This library is free software; you can redistribute it and/or
     9.9 +    modify it under the terms of the GNU Library General Public
    9.10 +    License as published by the Free Software Foundation; either
    9.11 +    version 2 of the License, or (at your option) any later version.
    9.12 +
    9.13 +    This library is distributed in the hope that it will be useful,
    9.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    9.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    9.16 +    Library General Public License for more details.
    9.17 +
    9.18 +    You should have received a copy of the GNU Library General Public
    9.19 +    License along with this library; if not, write to the Free
    9.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    9.21 +
    9.22 +    Sam Lantinga
    9.23 +    slouken@devolution.com
    9.24 +*/
    9.25 +
    9.26 +#ifdef SAVE_RCSID
    9.27 +static char rcsid =
    9.28 + "@(#) $Id$";
    9.29 +#endif
    9.30 +
    9.31 +#include "SDL_DirectFB_video.h"
    9.32 +
    9.33 +/* Functions to be exported */
    9.34 +extern void DirectFB_InitOSKeymap(_THIS);
    9.35 +extern void DirectFB_PumpEvents(_THIS);
    9.36 +
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/src/video/directfb/SDL_DirectFB_keys.h	Tue Sep 04 22:53:46 2001 +0000
    10.3 @@ -0,0 +1,135 @@
    10.4 +
    10.5 +#define SCANCODE_ESCAPE			1
    10.6 +
    10.7 +#define SCANCODE_1			2
    10.8 +#define SCANCODE_2			3
    10.9 +#define SCANCODE_3			4
   10.10 +#define SCANCODE_4			5
   10.11 +#define SCANCODE_5			6
   10.12 +#define SCANCODE_6			7
   10.13 +#define SCANCODE_7			8
   10.14 +#define SCANCODE_8			9
   10.15 +#define SCANCODE_9			10
   10.16 +#define SCANCODE_0			11
   10.17 +
   10.18 +#define SCANCODE_MINUS			12
   10.19 +#define SCANCODE_EQUAL			13
   10.20 +
   10.21 +#define SCANCODE_BACKSPACE		14
   10.22 +#define SCANCODE_TAB			15
   10.23 +
   10.24 +#define SCANCODE_Q			16
   10.25 +#define SCANCODE_W			17
   10.26 +#define SCANCODE_E			18
   10.27 +#define SCANCODE_R			19
   10.28 +#define SCANCODE_T			20
   10.29 +#define SCANCODE_Y			21
   10.30 +#define SCANCODE_U			22
   10.31 +#define SCANCODE_I			23
   10.32 +#define SCANCODE_O			24
   10.33 +#define SCANCODE_P			25
   10.34 +#define SCANCODE_BRACKET_LEFT		26
   10.35 +#define SCANCODE_BRACKET_RIGHT		27
   10.36 +
   10.37 +#define SCANCODE_ENTER			28
   10.38 +
   10.39 +#define SCANCODE_LEFTCONTROL		29
   10.40 +
   10.41 +#define SCANCODE_A			30
   10.42 +#define SCANCODE_S			31
   10.43 +#define SCANCODE_D			32
   10.44 +#define SCANCODE_F			33
   10.45 +#define SCANCODE_G			34
   10.46 +#define SCANCODE_H			35
   10.47 +#define SCANCODE_J			36
   10.48 +#define SCANCODE_K			37
   10.49 +#define SCANCODE_L			38
   10.50 +#define SCANCODE_SEMICOLON		39
   10.51 +#define SCANCODE_APOSTROPHE		40
   10.52 +#define SCANCODE_GRAVE			41
   10.53 +
   10.54 +#define SCANCODE_LEFTSHIFT		42
   10.55 +#define SCANCODE_BACKSLASH		43
   10.56 +
   10.57 +#define SCANCODE_Z			44
   10.58 +#define SCANCODE_X			45
   10.59 +#define SCANCODE_C			46
   10.60 +#define SCANCODE_V			47
   10.61 +#define SCANCODE_B			48
   10.62 +#define SCANCODE_N			49
   10.63 +#define SCANCODE_M			50
   10.64 +#define SCANCODE_COMMA			51
   10.65 +#define SCANCODE_PERIOD			52
   10.66 +#define SCANCODE_SLASH			53
   10.67 +
   10.68 +#define SCANCODE_RIGHTSHIFT		54
   10.69 +#define SCANCODE_KEYPADMULTIPLY		55
   10.70 +
   10.71 +#define SCANCODE_LEFTALT		56
   10.72 +#define SCANCODE_SPACE			57
   10.73 +#define SCANCODE_CAPSLOCK		58
   10.74 +
   10.75 +#define SCANCODE_F1			59
   10.76 +#define SCANCODE_F2			60
   10.77 +#define SCANCODE_F3			61
   10.78 +#define SCANCODE_F4			62
   10.79 +#define SCANCODE_F5			63
   10.80 +#define SCANCODE_F6			64
   10.81 +#define SCANCODE_F7			65
   10.82 +#define SCANCODE_F8			66
   10.83 +#define SCANCODE_F9			67
   10.84 +#define SCANCODE_F10			68
   10.85 +
   10.86 +#define SCANCODE_NUMLOCK		69
   10.87 +#define SCANCODE_SCROLLLOCK		70
   10.88 +
   10.89 +#define SCANCODE_KEYPAD7		71
   10.90 +#define SCANCODE_CURSORUPLEFT		71
   10.91 +#define SCANCODE_KEYPAD8		72
   10.92 +#define SCANCODE_CURSORUP		72
   10.93 +#define SCANCODE_KEYPAD9		73
   10.94 +#define SCANCODE_CURSORUPRIGHT		73
   10.95 +#define SCANCODE_KEYPADMINUS		74
   10.96 +#define SCANCODE_KEYPAD4		75
   10.97 +#define SCANCODE_CURSORLEFT		75
   10.98 +#define SCANCODE_KEYPAD5		76
   10.99 +#define SCANCODE_KEYPAD6		77
  10.100 +#define SCANCODE_CURSORRIGHT		77
  10.101 +#define SCANCODE_KEYPADPLUS		78
  10.102 +#define SCANCODE_KEYPAD1		79
  10.103 +#define SCANCODE_CURSORDOWNLEFT		79
  10.104 +#define SCANCODE_KEYPAD2		80
  10.105 +#define SCANCODE_CURSORDOWN		80
  10.106 +#define SCANCODE_KEYPAD3		81
  10.107 +#define SCANCODE_CURSORDOWNRIGHT	81
  10.108 +#define SCANCODE_KEYPAD0		82
  10.109 +#define SCANCODE_KEYPADPERIOD		83
  10.110 +
  10.111 +#define SCANCODE_LESS			86
  10.112 +
  10.113 +#define SCANCODE_F11			87
  10.114 +#define SCANCODE_F12			88
  10.115 +
  10.116 +#define SCANCODE_KEYPADENTER		96
  10.117 +#define SCANCODE_RIGHTCONTROL		97
  10.118 +#define SCANCODE_CONTROL		97
  10.119 +#define SCANCODE_KEYPADDIVIDE		98
  10.120 +#define SCANCODE_PRINTSCREEN		99
  10.121 +#define SCANCODE_RIGHTALT		100
  10.122 +#define SCANCODE_BREAK			101	/* Beware: is 119     */
  10.123 +#define SCANCODE_BREAK_ALTERNATIVE	119	/* on some keyboards! */
  10.124 +
  10.125 +#define SCANCODE_HOME			102
  10.126 +#define SCANCODE_CURSORBLOCKUP		90	/* Cursor key block */
  10.127 +#define SCANCODE_PAGEUP			104
  10.128 +#define SCANCODE_CURSORBLOCKLEFT	92	/* Cursor key block */
  10.129 +#define SCANCODE_CURSORBLOCKRIGHT	94	/* Cursor key block */
  10.130 +#define SCANCODE_END			107
  10.131 +#define SCANCODE_CURSORBLOCKDOWN	108	/* Cursor key block */
  10.132 +#define SCANCODE_PAGEDOWN		109
  10.133 +#define SCANCODE_INSERT			110
  10.134 +#define SCANCODE_REMOVE			111
  10.135 +
  10.136 +#define SCANCODE_RIGHTWIN		126
  10.137 +#define SCANCODE_LEFTWIN		125
  10.138 +
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/src/video/directfb/SDL_DirectFB_video.c	Tue Sep 04 22:53:46 2001 +0000
    11.3 @@ -0,0 +1,746 @@
    11.4 +/*
    11.5 +	SDL - Simple DirectMedia Layer
    11.6 +	Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    11.7 +
    11.8 +	This library is free software; you can redistribute it and/or
    11.9 +	modify it under the terms of the GNU Library General Public
   11.10 +	License as published by the Free Software Foundation; either
   11.11 +	version 2 of the License, or (at your option) any later version.
   11.12 +
   11.13 +	This library is distributed in the hope that it will be useful,
   11.14 +	but WITHOUT ANY WARRANTY; without even the implied warranty of
   11.15 +	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   11.16 +	Library General Public License for more details.
   11.17 +
   11.18 +	You should have received a copy of the GNU Library General Public
   11.19 +	License along with this library; if not, write to the Free
   11.20 +	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   11.21 +
   11.22 +	Sam Lantinga
   11.23 +	slouken@devolution.com
   11.24 +*/
   11.25 +
   11.26 +#ifdef SAVE_RCSID
   11.27 +static char rcsid =
   11.28 + "@(#) $Id$";
   11.29 +#endif
   11.30 +
   11.31 +/* DirectFB video driver implementation.
   11.32 +*/
   11.33 +
   11.34 +#include <stdlib.h>
   11.35 +#include <stdio.h>
   11.36 +#include <fcntl.h>
   11.37 +#include <unistd.h>
   11.38 +#include <sys/mman.h>
   11.39 +
   11.40 +#include <directfb.h>
   11.41 +
   11.42 +#include "SDL.h"
   11.43 +#include "SDL_error.h"
   11.44 +#include "SDL_video.h"
   11.45 +#include "SDL_mouse.h"
   11.46 +#include "SDL_sysvideo.h"
   11.47 +#include "SDL_pixels_c.h"
   11.48 +#include "SDL_events_c.h"
   11.49 +#include "SDL_DirectFB_video.h"
   11.50 +#include "SDL_DirectFB_events.h"
   11.51 +
   11.52 +
   11.53 +/* Initialization/Query functions */
   11.54 +static int DirectFB_VideoInit(_THIS, SDL_PixelFormat *vformat);
   11.55 +static SDL_Rect **DirectFB_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
   11.56 +static SDL_Surface *DirectFB_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
   11.57 +static int DirectFB_SetColors(_THIS, int firstcolor, int ncolors,
   11.58 +			 SDL_Color *colors);
   11.59 +static void DirectFB_VideoQuit(_THIS);
   11.60 +
   11.61 +/* Hardware surface functions */
   11.62 +static int DirectFB_AllocHWSurface(_THIS, SDL_Surface *surface);
   11.63 +static int DirectFB_FillHWRect(_THIS, SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color);
   11.64 +static int DirectFB_LockHWSurface(_THIS, SDL_Surface *surface);
   11.65 +static void DirectFB_UnlockHWSurface(_THIS, SDL_Surface *surface);
   11.66 +static void DirectFB_FreeHWSurface(_THIS, SDL_Surface *surface);
   11.67 +static int DirectFB_CheckHWBlit(_THIS, SDL_Surface *src, SDL_Surface *dst);
   11.68 +static int DirectFB_HWAccelBlit(SDL_Surface *src, SDL_Rect *srcrect,
   11.69 +                                SDL_Surface *dst, SDL_Rect *dstrect);
   11.70 +static int DirectFB_SetHWColorKey(_THIS, SDL_Surface *surface, Uint32 key);
   11.71 +static int DirectFB_SetHWAlpha(_THIS, SDL_Surface *surface, Uint8 alpha);
   11.72 +static int DirectFB_FlipHWSurface(_THIS, SDL_Surface *surface);
   11.73 +
   11.74 +/* Various screen update functions available */
   11.75 +static void DirectFB_DirectUpdate(_THIS, int numrects, SDL_Rect *rects);
   11.76 +static void DirectFB_WindowedUpdate(_THIS, int numrects, SDL_Rect *rects);
   11.77 +
   11.78 +/* This is the rect EnumModes2 uses */
   11.79 +struct DirectFBEnumRect {
   11.80 +	SDL_Rect r;
   11.81 +	struct DirectFBEnumRect* next;
   11.82 +};
   11.83 +
   11.84 +static struct DirectFBEnumRect *enumlists[NUM_MODELISTS];
   11.85 +
   11.86 +
   11.87 +/* DirectFB driver bootstrap functions */
   11.88 +
   11.89 +static int DirectFB_Available(void)
   11.90 +{
   11.91 +  return 1;
   11.92 +}
   11.93 +
   11.94 +static void DirectFB_DeleteDevice(SDL_VideoDevice *device)
   11.95 +{
   11.96 +  free(device->hidden);
   11.97 +  free(device);
   11.98 +}
   11.99 +
  11.100 +static SDL_VideoDevice *DirectFB_CreateDevice(int devindex)
  11.101 +{
  11.102 +  SDL_VideoDevice *device;
  11.103 +
  11.104 +  /* Initialize all variables that we clean on shutdown */
  11.105 +  device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
  11.106 +  if (device)
  11.107 +    {
  11.108 +      memset (device, 0, (sizeof *device));
  11.109 +      device->hidden = (struct SDL_PrivateVideoData *) malloc (sizeof (*device->hidden));
  11.110 +    }
  11.111 +  if (device == NULL  ||  device->hidden == NULL)
  11.112 +    {
  11.113 +      SDL_OutOfMemory();
  11.114 +      if (device)
  11.115 +        {
  11.116 +          free (device);
  11.117 +        }
  11.118 +      return(0);
  11.119 +    }
  11.120 +  memset (device->hidden, 0, sizeof (*device->hidden));
  11.121 +
  11.122 +  /* Set the function pointers */
  11.123 +  device->VideoInit = DirectFB_VideoInit;
  11.124 +  device->ListModes = DirectFB_ListModes;
  11.125 +  device->SetVideoMode = DirectFB_SetVideoMode;
  11.126 +  device->SetColors = DirectFB_SetColors;
  11.127 +  device->UpdateRects = NULL;
  11.128 +  device->VideoQuit = DirectFB_VideoQuit;
  11.129 +  device->AllocHWSurface = DirectFB_AllocHWSurface;
  11.130 +  device->CheckHWBlit = DirectFB_CheckHWBlit;
  11.131 +  device->FillHWRect = DirectFB_FillHWRect;
  11.132 +  device->SetHWColorKey = DirectFB_SetHWColorKey;
  11.133 +  device->SetHWAlpha = DirectFB_SetHWAlpha;
  11.134 +  device->LockHWSurface = DirectFB_LockHWSurface;
  11.135 +  device->UnlockHWSurface = DirectFB_UnlockHWSurface;
  11.136 +  device->FlipHWSurface = DirectFB_FlipHWSurface;
  11.137 +  device->FreeHWSurface = DirectFB_FreeHWSurface;
  11.138 +  device->SetCaption = NULL;
  11.139 +  device->SetIcon = NULL;
  11.140 +  device->IconifyWindow = NULL;
  11.141 +  device->GrabInput = NULL;
  11.142 +  device->GetWMInfo = NULL;
  11.143 +  device->InitOSKeymap = DirectFB_InitOSKeymap;
  11.144 +  device->PumpEvents = DirectFB_PumpEvents;
  11.145 +
  11.146 +  device->free = DirectFB_DeleteDevice;
  11.147 +
  11.148 +  return device;
  11.149 +}
  11.150 +
  11.151 +VideoBootStrap DirectFB_bootstrap = {
  11.152 +  "directfb", "DirectFB",
  11.153 +  DirectFB_Available, DirectFB_CreateDevice
  11.154 +};
  11.155 +
  11.156 +static DFBEnumerationResult EnumModesCallback (unsigned int  width,
  11.157 +                                               unsigned int  height,
  11.158 +                                               unsigned int  bpp,
  11.159 +                                               void         *data)
  11.160 +{
  11.161 +  SDL_VideoDevice *this = (SDL_VideoDevice *)data;
  11.162 +  struct DirectFBEnumRect *enumrect;
  11.163 +
  11.164 +  switch (bpp)
  11.165 +    {
  11.166 +    case 8:
  11.167 +    case 15:
  11.168 +    case 16:
  11.169 +    case 24:
  11.170 +    case 32:
  11.171 +      bpp /= 8; --bpp;
  11.172 +      ++HIDDEN->SDL_nummodes[bpp];
  11.173 +      enumrect = (struct DirectFBEnumRect*)malloc(sizeof(struct DirectFBEnumRect));
  11.174 +      if ( !enumrect )
  11.175 +        {
  11.176 +          SDL_OutOfMemory();
  11.177 +          return DFENUM_CANCEL;
  11.178 +        }
  11.179 +      enumrect->r.x = 0;
  11.180 +      enumrect->r.y = 0;
  11.181 +      enumrect->r.w = width;
  11.182 +      enumrect->r.h = height;
  11.183 +      enumrect->next = enumlists[bpp];
  11.184 +      enumlists[bpp] = enumrect;
  11.185 +      break;
  11.186 +    }
  11.187 +
  11.188 +  return DFENUM_OK;
  11.189 +}
  11.190 +
  11.191 +struct private_hwdata {
  11.192 +  IDirectFBSurface *surface;
  11.193 +};
  11.194 +
  11.195 +void SetDirectFBerror (const char *function, DFBResult code)
  11.196 +{
  11.197 +  const char *error = DirectFBErrorString (code);
  11.198 +
  11.199 +  if (error)
  11.200 +    SDL_SetError("%s: %s", function, error);
  11.201 +  else
  11.202 +    SDL_SetError("Unknown error code from %s", function);
  11.203 +}
  11.204 +
  11.205 +static DFBSurfacePixelFormat SDLToDFBPixelFormat (SDL_PixelFormat *format)
  11.206 +{
  11.207 +  if (format->Rmask && format->Gmask && format->Bmask)
  11.208 +    {
  11.209 +      switch (format->BitsPerPixel)
  11.210 +        {
  11.211 +        case 16:
  11.212 +          if (format->Rmask == 0xF800 &&
  11.213 +              format->Gmask == 0x07E0 &&
  11.214 +              format->Bmask == 0x001F)
  11.215 +            return DSPF_RGB16;
  11.216 +          /* fall through */
  11.217 +          
  11.218 +        case 15:
  11.219 +          if (format->Rmask == 0x7C00 &&
  11.220 +              format->Gmask == 0x03E0 &&
  11.221 +              format->Bmask == 0x001F)
  11.222 +            return DSPF_RGB15;
  11.223 +          break;
  11.224 +          
  11.225 +        case 24:
  11.226 +          if (format->Rmask == 0xFF0000 &&
  11.227 +              format->Gmask == 0x00FF00 &&
  11.228 +              format->Bmask == 0x0000FF)
  11.229 +            return DSPF_RGB24;
  11.230 +          break;
  11.231 +          
  11.232 +        case 32:
  11.233 +          if (format->Rmask == 0xFF0000 &&
  11.234 +              format->Gmask == 0x00FF00 &&
  11.235 +              format->Bmask == 0x0000FF)
  11.236 +            {
  11.237 +              if (format->Amask == 0xFF000000)
  11.238 +                return DSPF_ARGB;
  11.239 +              else
  11.240 +                return DSPF_RGB32;
  11.241 +            }
  11.242 +          break;
  11.243 +        }
  11.244 +    }
  11.245 +  else
  11.246 +    {
  11.247 +      switch (format->BitsPerPixel)
  11.248 +	{
  11.249 +	case 15:
  11.250 +	  return DSPF_RGB15;
  11.251 +	case 16:
  11.252 +	  return DSPF_RGB16;
  11.253 +	case 24:
  11.254 +	  return DSPF_RGB24;
  11.255 +	case 32:
  11.256 +	  return DSPF_RGB32;
  11.257 +	}
  11.258 +    }
  11.259 +
  11.260 +  return DSPF_UNKNOWN;
  11.261 +}
  11.262 +
  11.263 +static int DFBToSDLPixelFormat (DFBSurfacePixelFormat pixelformat, SDL_PixelFormat *format)
  11.264 +{
  11.265 +  format->BitsPerPixel = 0;
  11.266 +  format->Amask = format->Rmask = format->Gmask = format->Bmask = 0;
  11.267 +
  11.268 +  switch (pixelformat)
  11.269 +    {
  11.270 +    case DSPF_A8:
  11.271 +      format->Amask = 0x000000FF;
  11.272 +      break;
  11.273 +    case DSPF_RGB15:
  11.274 +      format->Rmask = 0x00007C00;
  11.275 +      format->Gmask = 0x000003E0;
  11.276 +      format->Bmask = 0x0000001F;
  11.277 +      break;
  11.278 +    case DSPF_RGB16:
  11.279 +      format->Rmask = 0x0000F800;
  11.280 +      format->Gmask = 0x000007E0;
  11.281 +      format->Bmask = 0x0000001F;
  11.282 +      break;
  11.283 +    case DSPF_ARGB:
  11.284 +      format->Amask = 0xFF000000;
  11.285 +      /* fall through */
  11.286 +    case DSPF_RGB24:
  11.287 +    case DSPF_RGB32:
  11.288 +      format->Rmask = 0x00FF0000;
  11.289 +      format->Gmask = 0x0000FF00;
  11.290 +      format->Bmask = 0x000000FF;
  11.291 +      break;
  11.292 +    default:
  11.293 +      return -1;
  11.294 +    }
  11.295 +
  11.296 +  format->BitsPerPixel = BITS_PER_PIXEL(pixelformat);
  11.297 +
  11.298 +  return 0;
  11.299 +}
  11.300 +
  11.301 +
  11.302 +int DirectFB_VideoInit(_THIS, SDL_PixelFormat *vformat)
  11.303 +{
  11.304 +  int                    i, j;
  11.305 +  DFBResult              ret;
  11.306 +  IDirectFB             *dfb;
  11.307 +  DFBCardCapabilities    caps;
  11.308 +  IDirectFBDisplayLayer *layer;
  11.309 +  DFBDisplayLayerConfig  dlc;
  11.310 +  IDirectFBInputBuffer  *inputbuffer;
  11.311 +
  11.312 +
  11.313 +  ret = DirectFBInit (NULL, NULL);
  11.314 +  if (ret)
  11.315 +    {
  11.316 +      SetDirectFBerror ("DirectFBInit", ret);
  11.317 +      return -1;
  11.318 +    }
  11.319 +
  11.320 +  ret = DirectFBCreate (&dfb);
  11.321 +  if (ret)
  11.322 +    {
  11.323 +      SetDirectFBerror ("DirectFBCreate", ret);
  11.324 +      return -1;
  11.325 +    }
  11.326 +
  11.327 +  ret = dfb->GetDisplayLayer (dfb, DLID_PRIMARY, &layer);
  11.328 +  if (ret)
  11.329 +    {
  11.330 +      SetDirectFBerror ("dfb->GetDisplayLayer", ret);
  11.331 +      dfb->Release (dfb);
  11.332 +      return -1;
  11.333 +    }
  11.334 +
  11.335 +  ret = dfb->CreateInputBuffer (dfb, DICAPS_BUTTONS | DICAPS_AXIS | DICAPS_KEYS,
  11.336 +                                &inputbuffer);
  11.337 +  if (ret)
  11.338 +    {
  11.339 +      SetDirectFBerror ("dfb->CreateInputBuffer", ret);
  11.340 +      layer->Release (layer);
  11.341 +      dfb->Release (dfb);
  11.342 +      return -1;
  11.343 +    }
  11.344 +  
  11.345 +  layer->EnableCursor (layer, 1);
  11.346 +
  11.347 +  /* Query layer configuration to determine the current mode and pixelformat */
  11.348 +  layer->GetConfiguration (layer, &dlc);
  11.349 +
  11.350 +  if (DFBToSDLPixelFormat (dlc.pixelformat, vformat))
  11.351 +    {
  11.352 +      SDL_SetError ("Unsupported pixelformat");
  11.353 +      layer->Release (layer);
  11.354 +      dfb->Release (dfb);
  11.355 +      return -1;
  11.356 +    }
  11.357 +
  11.358 +  /* Enumerate the available fullscreen modes */
  11.359 +  for ( i=0; i<NUM_MODELISTS; ++i )
  11.360 +    enumlists[i] = NULL;
  11.361 +
  11.362 +  ret = dfb->EnumVideoModes (dfb, EnumModesCallback, this);
  11.363 +  if (ret)
  11.364 +    {
  11.365 +      SetDirectFBerror ("dfb->EnumVideoModes", ret);
  11.366 +      layer->Release (layer);
  11.367 +      dfb->Release (dfb);
  11.368 +      return(-1);
  11.369 +    }
  11.370 +  for ( i=0; i<NUM_MODELISTS; ++i )
  11.371 +    {
  11.372 +      struct DirectFBEnumRect *rect;
  11.373 +      HIDDEN->SDL_modelist[i] = (SDL_Rect **) malloc
  11.374 +        ((HIDDEN->SDL_nummodes[i]+1)*sizeof(SDL_Rect *));
  11.375 +      if ( HIDDEN->SDL_modelist[i] == NULL )
  11.376 +        {
  11.377 +          SDL_OutOfMemory();
  11.378 +          return(-1);
  11.379 +        }
  11.380 +      for ( j = 0, rect = enumlists[i]; rect; ++j, rect = rect->next )
  11.381 +        {
  11.382 +          HIDDEN->SDL_modelist[i][j]=(SDL_Rect *)rect;
  11.383 +        }
  11.384 +      HIDDEN->SDL_modelist[i][j] = NULL;
  11.385 +    }
  11.386 +
  11.387 +  /* Query card capabilities to get the video memory size */
  11.388 +  dfb->GetCardCapabilities (dfb, &caps);
  11.389 +
  11.390 +  this->info.wm_available = 1;
  11.391 +  this->info.hw_available = 1;
  11.392 +  this->info.blit_hw      = 1;
  11.393 +  this->info.blit_hw_CC   = 1;
  11.394 +  this->info.blit_hw_A    = 1;
  11.395 +  this->info.blit_fill    = 1;
  11.396 +  this->info.video_mem    = caps.video_memory / 1024;
  11.397 +
  11.398 +  HIDDEN->initialized = 1;
  11.399 +  HIDDEN->dfb         = dfb;
  11.400 +  HIDDEN->layer       = layer;
  11.401 +  HIDDEN->inputbuffer = inputbuffer;
  11.402 +
  11.403 +  return 0;
  11.404 +}
  11.405 +
  11.406 +static SDL_Rect **DirectFB_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
  11.407 +{
  11.408 +  if (flags & SDL_FULLSCREEN)
  11.409 +    return HIDDEN->SDL_modelist[((format->BitsPerPixel + 7) / 8) - 1];
  11.410 +  else
  11.411 +    if (SDLToDFBPixelFormat (format) != DSPF_UNKNOWN)
  11.412 +      return (SDL_Rect**) -1;
  11.413 +
  11.414 +  return NULL;
  11.415 +}
  11.416 +
  11.417 +SDL_Surface *DirectFB_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags)
  11.418 +{
  11.419 +  DFBResult             ret;
  11.420 +  DFBSurfaceDescription dsc;
  11.421 +  DFBSurfacePixelFormat pixelformat;
  11.422 +
  11.423 +  fprintf (stderr, "SDL DirectFB_SetVideoMode: %dx%d@%d, flags: 0x%08x\n",
  11.424 +           width, height, bpp, flags);
  11.425 +
  11.426 +  flags |= SDL_FULLSCREEN;
  11.427 +
  11.428 +  /* Release previous primary surface */
  11.429 +  if (current->hwdata && current->hwdata->surface)
  11.430 +    {
  11.431 +      current->hwdata->surface->Release (current->hwdata->surface);
  11.432 +      current->hwdata->surface = NULL;
  11.433 +    }
  11.434 +  else if (!current->hwdata)
  11.435 +    {
  11.436 +      /* Allocate the hardware acceleration data */
  11.437 +      current->hwdata = (struct private_hwdata *) malloc (sizeof(*current->hwdata));
  11.438 +      if (!current->hwdata)
  11.439 +        {
  11.440 +          SDL_OutOfMemory();
  11.441 +          return NULL;
  11.442 +	}
  11.443 +      memset (current->hwdata, 0, sizeof(*current->hwdata));
  11.444 +    }
  11.445 +
  11.446 +  /* Set cooperative level depending on flag SDL_FULLSCREEN */
  11.447 +  if (flags & SDL_FULLSCREEN)
  11.448 +    {
  11.449 +      ret = HIDDEN->dfb->SetCooperativeLevel (HIDDEN->dfb, DFSCL_FULLSCREEN);
  11.450 +      if (ret)
  11.451 +        {
  11.452 +          DirectFBError ("dfb->SetCooperativeLevel", ret);
  11.453 +          flags &= ~SDL_FULLSCREEN;
  11.454 +        }
  11.455 +    }
  11.456 +  else
  11.457 +    HIDDEN->dfb->SetCooperativeLevel (HIDDEN->dfb, DFSCL_NORMAL);
  11.458 +
  11.459 +  /* Set video mode */
  11.460 +  ret = HIDDEN->dfb->SetVideoMode (HIDDEN->dfb, width, height, bpp);
  11.461 +  if (ret)
  11.462 +    {
  11.463 +      if (flags & SDL_FULLSCREEN)
  11.464 +        {
  11.465 +          flags &= ~SDL_FULLSCREEN;
  11.466 +          HIDDEN->dfb->SetCooperativeLevel (HIDDEN->dfb, DFSCL_NORMAL);
  11.467 +          ret = HIDDEN->dfb->SetVideoMode (HIDDEN->dfb, width, height, bpp);
  11.468 +        }
  11.469 +
  11.470 +      if (ret)
  11.471 +        {
  11.472 +          SetDirectFBerror ("dfb->SetVideoMode", ret);
  11.473 +          return NULL;
  11.474 +        }
  11.475 +    }
  11.476 +
  11.477 +  /* Create primary surface */
  11.478 +  dsc.flags = DSDESC_CAPS;
  11.479 +  dsc.caps  = DSCAPS_PRIMARY | ((flags & SDL_DOUBLEBUF) ? DSCAPS_FLIPPING : 0);
  11.480 +
  11.481 +  ret = HIDDEN->dfb->CreateSurface (HIDDEN->dfb, &dsc, &current->hwdata->surface);
  11.482 +  if (ret && (flags & SDL_DOUBLEBUF))
  11.483 +    {
  11.484 +      /* Try without double buffering */
  11.485 +      dsc.caps &= ~DSCAPS_FLIPPING;
  11.486 +      ret = HIDDEN->dfb->CreateSurface (HIDDEN->dfb, &dsc, &current->hwdata->surface);
  11.487 +    }
  11.488 +  if (ret)
  11.489 +    {
  11.490 +      SetDirectFBerror ("dfb->CreateSurface", ret);
  11.491 +      current->hwdata->surface = NULL;
  11.492 +      return NULL;
  11.493 +    }
  11.494 +
  11.495 +  current->w     = width;
  11.496 +  current->h     = height;
  11.497 +  current->flags = SDL_HWSURFACE | SDL_PREALLOC;
  11.498 +
  11.499 +  if (flags & SDL_FULLSCREEN)
  11.500 +    {
  11.501 +      current->flags |= SDL_FULLSCREEN;
  11.502 +      this->UpdateRects = DirectFB_DirectUpdate;
  11.503 +    }
  11.504 +  else
  11.505 +    this->UpdateRects = DirectFB_WindowedUpdate;
  11.506 +
  11.507 +  if (dsc.caps & DSCAPS_FLIPPING)
  11.508 +    current->flags |= SDL_DOUBLEBUF;
  11.509 +
  11.510 +  current->hwdata->surface->GetPixelFormat (current->hwdata->surface, &pixelformat);
  11.511 +  DFBToSDLPixelFormat (pixelformat, current->format);
  11.512 +
  11.513 +  return current;
  11.514 +}
  11.515 +
  11.516 +static int DirectFB_AllocHWSurface(_THIS, SDL_Surface *surface)
  11.517 +{
  11.518 +  DFBResult             ret;
  11.519 +  DFBSurfaceDescription dsc;
  11.520 +
  11.521 +  /*  fprintf(stderr, "SDL: DirectFB_AllocHWSurface (%dx%d@%d, flags: 0x%08x)\n",
  11.522 +      surface->w, surface->h, surface->format->BitsPerPixel, surface->flags);*/
  11.523 +
  11.524 +  if (surface->w < 8 || surface->h < 8)
  11.525 +    return -1;
  11.526 +
  11.527 +  /* fill surface description */
  11.528 +  dsc.flags  = DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS;
  11.529 +  dsc.width  = surface->w;
  11.530 +  dsc.height = surface->h;
  11.531 +  dsc.caps   = surface->flags & SDL_DOUBLEBUF ? DSCAPS_FLIPPING : 0;
  11.532 +
  11.533 +  /* find the right pixelformat */
  11.534 +  dsc.pixelformat = SDLToDFBPixelFormat (surface->format);
  11.535 +  if (dsc.pixelformat == DSPF_UNKNOWN)
  11.536 +    return -1;
  11.537 +
  11.538 +  /* Allocate the hardware acceleration data */
  11.539 +  surface->hwdata = (struct private_hwdata *) malloc (sizeof(*surface->hwdata));
  11.540 +  if (surface->hwdata == NULL)
  11.541 +    {
  11.542 +      SDL_OutOfMemory();
  11.543 +      return -1;
  11.544 +    }
  11.545 +
  11.546 +  /* Create the surface */
  11.547 +  ret = HIDDEN->dfb->CreateSurface (HIDDEN->dfb, &dsc, &surface->hwdata->surface);
  11.548 +  if (ret)
  11.549 +    {
  11.550 +      SetDirectFBerror ("dfb->CreateSurface", ret);
  11.551 +      free (surface->hwdata);
  11.552 +      surface->hwdata = NULL;
  11.553 +      return -1;
  11.554 +    }
  11.555 +
  11.556 +  surface->flags |= SDL_HWSURFACE | SDL_PREALLOC;
  11.557 +
  11.558 +  return 0;
  11.559 +}
  11.560 +
  11.561 +static void DirectFB_FreeHWSurface(_THIS, SDL_Surface *surface)
  11.562 +{
  11.563 +  if (surface->hwdata && HIDDEN->initialized)
  11.564 +    {
  11.565 +      surface->hwdata->surface->Release (surface->hwdata->surface);
  11.566 +      free (surface->hwdata);
  11.567 +      surface->hwdata = NULL;
  11.568 +    }
  11.569 +}
  11.570 +
  11.571 +static int DirectFB_CheckHWBlit(_THIS, SDL_Surface *src, SDL_Surface *dst)
  11.572 +{
  11.573 +  /*  fprintf(stderr, "SDL: DirectFB_CheckHWBlit (src->hwdata: %p, dst->hwdata: %p)\n",
  11.574 +      src->hwdata, dst->hwdata);*/
  11.575 +
  11.576 +  if (!src->hwdata || !dst->hwdata)
  11.577 +    return 0;
  11.578 +
  11.579 +  src->flags |= SDL_HWACCEL;
  11.580 +  src->map->hw_blit = DirectFB_HWAccelBlit;
  11.581 +
  11.582 +  return 1;
  11.583 +}
  11.584 +
  11.585 +static int DirectFB_HWAccelBlit(SDL_Surface *src, SDL_Rect *srcrect,
  11.586 +                                SDL_Surface *dst, SDL_Rect *dstrect)
  11.587 +{
  11.588 +  DFBRectangle             sr, dr;
  11.589 +  IDirectFBSurface        *surface;
  11.590 +  DFBSurfaceBlittingFlags  flags = DSBLIT_NOFX;
  11.591 +
  11.592 +  sr.x = srcrect->x;
  11.593 +  sr.y = srcrect->y;
  11.594 +  sr.w = srcrect->w;
  11.595 +  sr.h = srcrect->h;
  11.596 +
  11.597 +  dr.x = dstrect->x;
  11.598 +  dr.y = dstrect->y;
  11.599 +  dr.w = dstrect->w;
  11.600 +  dr.h = dstrect->h;
  11.601 +
  11.602 +  surface = dst->hwdata->surface;
  11.603 +
  11.604 +  if (src->flags & SDL_SRCCOLORKEY)
  11.605 +    {
  11.606 +      flags |= DSBLIT_SRC_COLORKEY;
  11.607 +      surface->SetSrcColorKey (surface, src->format->colorkey);
  11.608 +    }
  11.609 +
  11.610 +  if (src->flags & SDL_SRCALPHA)
  11.611 +    {
  11.612 +      flags |= DSBLIT_BLEND_COLORALPHA;
  11.613 +      surface->SetColor (surface, 0xff, 0xff, 0xff, src->format->alpha);
  11.614 +    }
  11.615 +
  11.616 +  surface->SetBlittingFlags (surface, flags);
  11.617 +
  11.618 +  if (sr.w == dr.w && sr.h == dr.h)
  11.619 +    surface->Blit (surface, src->hwdata->surface, &sr, dr.x, dr.y);
  11.620 +  else
  11.621 +    surface->StretchBlit (surface, src->hwdata->surface, &sr, &dr);
  11.622 +
  11.623 +  return 0;
  11.624 +}
  11.625 +
  11.626 +static int DirectFB_FillHWRect(_THIS, SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color)
  11.627 +{
  11.628 +  SDL_PixelFormat  *fmt     = dst->format;
  11.629 +  IDirectFBSurface *surface = dst->hwdata->surface;
  11.630 +
  11.631 +  /* ugly */
  11.632 +  surface->SetColor (surface,
  11.633 +                     (color & fmt->Rmask) >> (fmt->Rshift - fmt->Rloss),
  11.634 +                     (color & fmt->Gmask) >> (fmt->Gshift - fmt->Gloss),
  11.635 +                     (color & fmt->Bmask) << (fmt->Bloss - fmt->Bshift), 0xFF);
  11.636 +  surface->FillRectangle (surface, dstrect->x, dstrect->y, dstrect->w, dstrect->h);
  11.637 +
  11.638 +  return 0;
  11.639 +}
  11.640 +
  11.641 +static int DirectFB_SetHWColorKey(_THIS, SDL_Surface *surface, Uint32 key)
  11.642 +{
  11.643 +  return 0;
  11.644 +}
  11.645 +
  11.646 +static int DirectFB_SetHWAlpha(_THIS, SDL_Surface *surface, Uint8 alpha)
  11.647 +{
  11.648 +  return 0;
  11.649 +}
  11.650 +
  11.651 +static int DirectFB_FlipHWSurface(_THIS, SDL_Surface *surface)
  11.652 +{
  11.653 +  return surface->hwdata->surface->Flip (surface->hwdata->surface, NULL, DSFLIP_WAITFORSYNC);
  11.654 +}
  11.655 +
  11.656 +static int DirectFB_LockHWSurface(_THIS, SDL_Surface *surface)
  11.657 +{
  11.658 +  DFBResult  ret;
  11.659 +  void      *data;
  11.660 +  int        pitch;
  11.661 +
  11.662 +  ret = surface->hwdata->surface->Lock (surface->hwdata->surface,
  11.663 +                                        DSLF_WRITE, &data, &pitch);
  11.664 +  if (ret)
  11.665 +    {
  11.666 +      SetDirectFBerror ("surface->Lock", ret);
  11.667 +      return -1;
  11.668 +    }
  11.669 +
  11.670 +  surface->pixels = data;
  11.671 +  surface->pitch  = pitch;
  11.672 +
  11.673 +  return 0;
  11.674 +}
  11.675 +
  11.676 +static void DirectFB_UnlockHWSurface(_THIS, SDL_Surface *surface)
  11.677 +{
  11.678 +  surface->hwdata->surface->Unlock (surface->hwdata->surface);
  11.679 +  surface->pixels = NULL;
  11.680 +}
  11.681 +
  11.682 +static void DirectFB_DirectUpdate(_THIS, int numrects, SDL_Rect *rects)
  11.683 +{
  11.684 +}
  11.685 +
  11.686 +static void DirectFB_WindowedUpdate(_THIS, int numrects, SDL_Rect *rects)
  11.687 +{
  11.688 +  IDirectFBSurface *surface = this->screen->hwdata->surface;
  11.689 +  DFBRegion region = { rects->x, rects->y,
  11.690 +                       rects->x + rects->w - 1,
  11.691 +                       rects->y + rects->h - 1 };
  11.692 +
  11.693 +  while (--numrects)
  11.694 +    {
  11.695 +      int x2, y2;
  11.696 +
  11.697 +      rects++;
  11.698 +
  11.699 +      if (rects->x < region.x1)
  11.700 +        region.x1 = rects->x;
  11.701 +
  11.702 +      if (rects->y < region.y1)
  11.703 +        region.y1 = rects->y;
  11.704 +
  11.705 +      x2 = rects->x + rects->w - 1;
  11.706 +      y2 = rects->y + rects->h - 1;
  11.707 +
  11.708 +      if (x2 > region.x2)
  11.709 +        region.x2 = x2;
  11.710 +
  11.711 +      if (y2 > region.y2)
  11.712 +        region.y2 = y2;
  11.713 +    }
  11.714 +
  11.715 +  surface->Flip (surface, &region, DSFLIP_WAITFORSYNC);
  11.716 +}
  11.717 +
  11.718 +int DirectFB_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
  11.719 +{
  11.720 +  fprintf(stderr, "SDL: Unimplemented DirectFB_SetColors!\n");
  11.721 +  return 0;
  11.722 +}
  11.723 +	
  11.724 +void DirectFB_VideoQuit(_THIS)
  11.725 +{
  11.726 +  int i, j;
  11.727 +
  11.728 +  HIDDEN->inputbuffer->Release (HIDDEN->inputbuffer);
  11.729 +  HIDDEN->layer->Release (HIDDEN->layer);
  11.730 +  HIDDEN->dfb->Release (HIDDEN->dfb);
  11.731 +
  11.732 +  /* Free video mode lists */
  11.733 +  for ( i=0; i<NUM_MODELISTS; ++i )
  11.734 +    {
  11.735 +      if ( HIDDEN->SDL_modelist[i] != NULL )
  11.736 +        {
  11.737 +          for ( j=0; HIDDEN->SDL_modelist[i][j]; ++j )
  11.738 +            free(HIDDEN->SDL_modelist[i][j]);
  11.739 +          free(HIDDEN->SDL_modelist[i]);
  11.740 +          HIDDEN->SDL_modelist[i] = NULL;
  11.741 +        }
  11.742 +    }
  11.743 +
  11.744 +  HIDDEN->initialized = 0;
  11.745 +}
  11.746 +
  11.747 +void DirectFB_FinalQuit(void) 
  11.748 +{
  11.749 +}
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/src/video/directfb/SDL_DirectFB_video.h	Tue Sep 04 22:53:46 2001 +0000
    12.3 @@ -0,0 +1,55 @@
    12.4 +/*
    12.5 +    SDL - Simple DirectMedia Layer
    12.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    12.7 +
    12.8 +    This library is free software; you can redistribute it and/or
    12.9 +    modify it under the terms of the GNU Library General Public
   12.10 +    License as published by the Free Software Foundation; either
   12.11 +    version 2 of the License, or (at your option) any later version.
   12.12 +
   12.13 +    This library is distributed in the hope that it will be useful,
   12.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   12.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   12.16 +    Library General Public License for more details.
   12.17 +
   12.18 +    You should have received a copy of the GNU Library General Public
   12.19 +    License along with this library; if not, write to the Free
   12.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   12.21 +
   12.22 +    Sam Lantinga
   12.23 +    slouken@devolution.com
   12.24 +*/
   12.25 +
   12.26 +#ifdef SAVE_RCSID
   12.27 +static char rcsid =
   12.28 + "@(#) $Id$";
   12.29 +#endif
   12.30 +
   12.31 +#ifndef _SDL_DirectFB_video_h
   12.32 +#define _SDL_DirectFB_video_h
   12.33 +
   12.34 +#include <directfb.h>
   12.35 +
   12.36 +#include "SDL_mouse.h"
   12.37 +#include "SDL_sysvideo.h"
   12.38 +
   12.39 +#define _THIS SDL_VideoDevice *this
   12.40 +
   12.41 +/* Private display data */
   12.42 +
   12.43 +struct SDL_PrivateVideoData
   12.44 +{
   12.45 +  int                    initialized;
   12.46 +
   12.47 +  IDirectFB             *dfb;
   12.48 +  IDirectFBDisplayLayer *layer;
   12.49 +  IDirectFBInputBuffer  *inputbuffer;
   12.50 +
   12.51 +#define NUM_MODELISTS	4		/* 8, 16, 24, and 32 bits-per-pixel */
   12.52 +  int SDL_nummodes[NUM_MODELISTS];
   12.53 +  SDL_Rect **SDL_modelist[NUM_MODELISTS];
   12.54 +};
   12.55 +
   12.56 +#define HIDDEN (this->hidden)
   12.57 +
   12.58 +#endif /* _SDL_DirectFB_video_h */