merged with repo
authorApoorv Upreti <apoorvupreti@gmail.com>
Thu, 14 Nov 2013 22:35:28 +0530
changeset 7983eed9fd44234c
parent 7982 1c0c2e078fb7
parent 7981 6d538bc1b395
child 7984 fb7d28e880cc
merged with repo
src/audio/baudio/SDL_beaudio.cc
src/audio/baudio/SDL_beaudio.h
src/filesystem/beos/SDL_sysfilesystem.cc
src/joystick/beos/SDL_bejoystick.cc
src/loadso/beos/SDL_sysloadso.c
src/main/beos/SDL_BApp.h
src/main/beos/SDL_BeApp.cc
src/main/beos/SDL_BeApp.h
src/power/beos/SDL_syspower.c
src/timer/beos/SDL_systimer.c
src/video/bwindow/SDL_BWin.h
src/video/bwindow/SDL_bclipboard.cc
src/video/bwindow/SDL_bclipboard.h
src/video/bwindow/SDL_bevents.cc
src/video/bwindow/SDL_bevents.h
src/video/bwindow/SDL_bframebuffer.cc
src/video/bwindow/SDL_bframebuffer.h
src/video/bwindow/SDL_bkeyboard.cc
src/video/bwindow/SDL_bkeyboard.h
src/video/bwindow/SDL_bmodes.cc
src/video/bwindow/SDL_bmodes.h
src/video/bwindow/SDL_bopengl.cc
src/video/bwindow/SDL_bopengl.h
src/video/bwindow/SDL_bvideo.cc
src/video/bwindow/SDL_bvideo.h
src/video/bwindow/SDL_bwindow.cc
src/video/bwindow/SDL_bwindow.h
     1.1 --- a/CMakeLists.txt	Thu Nov 14 22:19:07 2013 +0530
     1.2 +++ b/CMakeLists.txt	Thu Nov 14 22:35:28 2013 +0530
     1.3 @@ -95,8 +95,10 @@
     1.4      set(MACOSX TRUE)
     1.5    endif()
     1.6    # TODO: iOS?
     1.7 -elseif(CMAKE_SYSTEM_NAME MATCHES "Haiku.*|BeOS.*")
     1.8 -  set(BEOS TRUE)
     1.9 +elseif(CMAKE_SYSTEM_NAME MATCHES "BeOS.*")
    1.10 +  message_error("BeOS support has been removed as of SDL 2.0.2.")
    1.11 +elseif(CMAKE_SYSTEM_NAME MATCHES "Haiku.*")
    1.12 +  set(HAIKU TRUE)
    1.13  endif()
    1.14  
    1.15  # Don't mistake osx for unix
    1.16 @@ -308,9 +310,9 @@
    1.17  
    1.18    check_c_compiler_flag(-Wall HAVE_GCC_WALL)
    1.19    if(HAVE_GCC_WALL)
    1.20 -    if(CMAKE_SYSTEM_NAME MATCHES "Haiku|BeOS")
    1.21 +    if(HAIKU)
    1.22        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-multichar")
    1.23 -    endif(CMAKE_SYSTEM_NAME MATCHES "Haiku|BeOS")
    1.24 +    endif(HAIKU)
    1.25    endif(HAVE_GCC_WALL)
    1.26  endif(USE_GCC)
    1.27  
    1.28 @@ -991,15 +993,15 @@
    1.29    endif(SDL_VIDEO)
    1.30  
    1.31    CheckPTHREAD()
    1.32 -elseif(BEOS)
    1.33 +elseif(HAIKU)
    1.34    if(SDL_VIDEO)
    1.35 -    set(SDL_VIDEO_DRIVER_BWINDOW 1)
    1.36 -    file(GLOB BWINDOW_SOURCES ${SDL2_SOURCE_DIR}/src/video/bwindow/*.c)
    1.37 -    set(SOURCE_FILES ${SOURCE_FILES} ${BWINDOW_SOURCES})
    1.38 +    set(SDL_VIDEO_DRIVER_HAIKU 1)
    1.39 +    file(GLOB HAIKUVIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/haiku/*.c)
    1.40 +    set(SOURCE_FILES ${SOURCE_FILES} ${HAIKUVIDEO_SOURCES})
    1.41      set(HAVE_SDL_VIDEO TRUE)
    1.42  
    1.43 -    set(SDL_FILESYSTEM_BEOS 1)
    1.44 -    file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/beos/*.cc)
    1.45 +    set(SDL_FILESYSTEM_HAIKU 1)
    1.46 +    file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/haiku/*.cc)
    1.47      set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
    1.48      set(HAVE_SDL_FILESYSTEM TRUE)
    1.49  
     2.1 --- a/README-linux.txt	Thu Nov 14 22:19:07 2013 +0530
     2.2 +++ b/README-linux.txt	Thu Nov 14 22:35:28 2013 +0530
     2.3 @@ -30,3 +30,51 @@
     2.4    configure script to include DirectFB support. Send patches.  :)
     2.5  
     2.6  
     2.7 +================================================================================
     2.8 +Joystick does not work
     2.9 +================================================================================
    2.10 +
    2.11 +If you compiled or are using a version of SDL with udev support (and you should!)
    2.12 +there's a few issues that may cause SDL to fail to detect your joystick. To
    2.13 +debug this, start by installing the evtest utility. On Ubuntu/Debian:
    2.14 +
    2.15 +    sudo apt-get install evtest
    2.16 +    
    2.17 +Then run:
    2.18 +    
    2.19 +    sudo evtest
    2.20 +    
    2.21 +You'll hopefully see your joystick listed along with a name like "/dev/input/eventXX"
    2.22 +Now run:
    2.23 +    
    2.24 +    cat /dev/input/event/XX
    2.25 +
    2.26 +If you get a permission error, you need to set a udev rule to change the mode of
    2.27 +your device (see below)    
    2.28 +    
    2.29 +Also, try:
    2.30 +    
    2.31 +    sudo udevadm info --query=all --name=input/eventXX
    2.32 +    
    2.33 +If you see a line stating ID_INPUT_JOYSTICK=1, great, if you don't see it,
    2.34 +you need to set up an udev rule to force this variable.
    2.35 +
    2.36 +A combined rule for the Saitek Pro Flight Rudder Pedals to fix both issues looks 
    2.37 +like:
    2.38 +    
    2.39 +   SUBSYSTEM=="input", ATTRS{idProduct}=="0763", ATTRS{idVendor}=="06a3", MODE="0666", ENV{ID_INPUT_JOYSTICK}="1"
    2.40 +   SUBSYSTEM=="input", ATTRS{idProduct}=="0764", ATTRS{idVendor}=="06a3", MODE="0666", ENV{ID_INPUT_JOYSTICK}="1"
    2.41 +   
    2.42 +You can set up similar rules for your device by changing the values listed in
    2.43 +idProduct and idVendor. To obtain these values, try:
    2.44 +    
    2.45 +    sudo udevadm info -a --name=input/eventXX | grep idVendor
    2.46 +    sudo udevadm info -a --name=input/eventXX | grep idProduct
    2.47 +    
    2.48 +If multiple values come up for each of these, the one you want is the first one of each.    
    2.49 +
    2.50 +On other systems which ship with an older udev (such as CentOS), you may need
    2.51 +to set up a rule such as:
    2.52 +    
    2.53 +    SUBSYSTEM=="input", ENV{ID_CLASS}=="joystick", ENV{ID_INPUT_JOYSTICK}="1"
    2.54 +
     3.1 --- a/cmake/sdlchecks.cmake	Thu Nov 14 22:19:07 2013 +0530
     3.2 +++ b/cmake/sdlchecks.cmake	Thu Nov 14 22:35:28 2013 +0530
     3.3 @@ -638,7 +638,7 @@
     3.4      elseif(HPUX)
     3.5        set(PTHREAD_CFLAGS "-D_REENTRANT")
     3.6        set(PTHREAD_LDFLAGS "-L/usr/lib -pthread")
     3.7 -    elseif(BEOS)
     3.8 +    elseif(HAIKU)
     3.9        set(PTHREAD_CFLAGS "-D_REENTRANT")
    3.10        set(PTHREAD_LDFLAGS "")
    3.11      else()
     4.1 --- a/configure	Thu Nov 14 22:19:07 2013 +0530
     4.2 +++ b/configure	Thu Nov 14 22:35:28 2013 +0530
     4.3 @@ -15950,7 +15950,7 @@
     4.4      fi
     4.5  fi
     4.6  
     4.7 -# Actually this doesn't work on OpenBSD and BeOS
     4.8 +# Actually this doesn't work on OpenBSD
     4.9  #AC_MSG_CHECKING(for linker option --no-undefined)
    4.10  #have_no_undefined=no
    4.11  #save_LDFLAGS="$LDFLAGS"
    4.12 @@ -18598,7 +18598,7 @@
    4.13  $as_echo_n "checking for necessary GCC -Wno-multichar option... " >&6; }
    4.14          need_gcc_Wno_multichar=no
    4.15          case "$host" in
    4.16 -            *-*-beos* | *-*-haiku*)
    4.17 +            *-*-haiku*)
    4.18                  need_gcc_Wno_multichar=yes
    4.19                  ;;
    4.20          esac
    4.21 @@ -20124,13 +20124,13 @@
    4.22      fi
    4.23  }
    4.24  
    4.25 -CheckBWINDOW()
    4.26 +CheckHaikuVideo()
    4.27  {
    4.28      if test x$enable_video = xyes; then
    4.29  
    4.30 -$as_echo "#define SDL_VIDEO_DRIVER_BWINDOW 1" >>confdefs.h
    4.31 -
    4.32 -        SOURCES="$SOURCES $srcdir/src/video/bwindow/*.cc"
    4.33 +$as_echo "#define SDL_VIDEO_DRIVER_HAIKU 1" >>confdefs.h
    4.34 +
    4.35 +        SOURCES="$SOURCES $srcdir/src/video/haiku/*.cc"
    4.36          have_video=yes
    4.37      fi
    4.38  }
    4.39 @@ -20680,14 +20680,14 @@
    4.40      fi
    4.41  }
    4.42  
    4.43 -CheckBeGL()
    4.44 +CheckHaikuGL()
    4.45  {
    4.46      if test x$enable_video = xyes -a x$enable_video_opengl = xyes; then
    4.47  
    4.48  $as_echo "#define SDL_VIDEO_OPENGL 1" >>confdefs.h
    4.49  
    4.50  
    4.51 -$as_echo "#define SDL_VIDEO_OPENGL_BGL 1" >>confdefs.h
    4.52 +$as_echo "#define SDL_VIDEO_OPENGL_HAIKU 1" >>confdefs.h
    4.53  
    4.54  
    4.55  $as_echo "#define SDL_VIDEO_RENDER_OGL 1" >>confdefs.h
    4.56 @@ -22399,66 +22399,72 @@
    4.57          fi
    4.58          ;;
    4.59  
    4.60 +        *-*-beos*)
    4.61 +        as_fn_error $? "
    4.62 +*** BeOS support has been removed as of SDL 2.0.2.
    4.63 +        " "$LINENO" 5
    4.64 +        ;;
    4.65  
    4.66      *-*-haiku*)
    4.67 -        ARCH=beos
    4.68 +        ARCH=haiku
    4.69          ac_default_prefix=/boot/common
    4.70          CheckDummyVideo
    4.71          CheckDiskAudio
    4.72          CheckDummyAudio
    4.73 -        CheckBWINDOW
    4.74 -        CheckBeGL
    4.75 +        CheckHaikuVideo
    4.76 +        CheckHaikuGL
    4.77          CheckPTHREAD
    4.78 +
    4.79          # Set up files for the audio library
    4.80          if test x$enable_audio = xyes; then
    4.81  
    4.82 -$as_echo "#define SDL_AUDIO_DRIVER_BEOSAUDIO 1" >>confdefs.h
    4.83 -
    4.84 -            SOURCES="$SOURCES $srcdir/src/audio/baudio/*.cc"
    4.85 +$as_echo "#define SDL_AUDIO_DRIVER_HAIKU 1" >>confdefs.h
    4.86 +
    4.87 +            SOURCES="$SOURCES $srcdir/src/audio/haiku/*.cc"
    4.88              have_audio=yes
    4.89          fi
    4.90          # Set up files for the joystick library
    4.91          if test x$enable_joystick = xyes; then
    4.92  
    4.93 -$as_echo "#define SDL_JOYSTICK_BEOS 1" >>confdefs.h
    4.94 -
    4.95 -            SOURCES="$SOURCES $srcdir/src/joystick/beos/*.cc"
    4.96 +$as_echo "#define SDL_JOYSTICK_HAIKU 1" >>confdefs.h
    4.97 +
    4.98 +            SOURCES="$SOURCES $srcdir/src/joystick/haiku/*.cc"
    4.99              have_joystick=yes
   4.100          fi
   4.101          # Set up files for the timer library
   4.102          if test x$enable_timers = xyes; then
   4.103  
   4.104 -$as_echo "#define SDL_TIMER_BEOS 1" >>confdefs.h
   4.105 -
   4.106 -            SOURCES="$SOURCES $srcdir/src/timer/beos/*.c"
   4.107 +$as_echo "#define SDL_TIMER_HAIKU 1" >>confdefs.h
   4.108 +
   4.109 +            SOURCES="$SOURCES $srcdir/src/timer/haiku/*.c"
   4.110              have_timers=yes
   4.111          fi
   4.112          # Set up files for the shared object loading library
   4.113          if test x$enable_loadso = xyes; then
   4.114  
   4.115 -$as_echo "#define SDL_LOADSO_BEOS 1" >>confdefs.h
   4.116 -
   4.117 -            SOURCES="$SOURCES $srcdir/src/loadso/beos/*.c"
   4.118 +$as_echo "#define SDL_LOADSO_HAIKU 1" >>confdefs.h
   4.119 +
   4.120 +            SOURCES="$SOURCES $srcdir/src/loadso/haiku/*.c"
   4.121              have_loadso=yes
   4.122          fi
   4.123          # Set up files for the system power library
   4.124          if test x$enable_power = xyes; then
   4.125  
   4.126 -$as_echo "#define SDL_POWER_BEOS 1" >>confdefs.h
   4.127 -
   4.128 -            SOURCES="$SOURCES $srcdir/src/power/beos/*.c"
   4.129 +$as_echo "#define SDL_POWER_HAIKU 1" >>confdefs.h
   4.130 +
   4.131 +            SOURCES="$SOURCES $srcdir/src/power/haiku/*.c"
   4.132              have_power=yes
   4.133          fi
   4.134          # Set up files for the system filesystem library
   4.135          if test x$enable_filesystem = xyes; then
   4.136  
   4.137 -$as_echo "#define SDL_FILESYSTEM_BEOS 1" >>confdefs.h
   4.138 -
   4.139 -            SOURCES="$SOURCES $srcdir/src/filesystem/beos/*.cc"
   4.140 +$as_echo "#define SDL_FILESYSTEM_HAIKU 1" >>confdefs.h
   4.141 +
   4.142 +            SOURCES="$SOURCES $srcdir/src/filesystem/haiku/*.cc"
   4.143              have_filesystem=yes
   4.144          fi
   4.145          # The BeOS platform requires special setup.
   4.146 -        SOURCES="$srcdir/src/main/beos/*.cc $SOURCES"
   4.147 +        SOURCES="$srcdir/src/main/haiku/*.cc $SOURCES"
   4.148          EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lroot -lbe -lmedia -lgame -ldevice -ltextencoding"
   4.149          ;;
   4.150      arm*-apple-darwin*)
     5.1 --- a/configure.in	Thu Nov 14 22:19:07 2013 +0530
     5.2 +++ b/configure.in	Thu Nov 14 22:35:28 2013 +0530
     5.3 @@ -204,7 +204,7 @@
     5.4      fi
     5.5  fi
     5.6  
     5.7 -# Actually this doesn't work on OpenBSD and BeOS
     5.8 +# Actually this doesn't work on OpenBSD
     5.9  #AC_MSG_CHECKING(for linker option --no-undefined)
    5.10  #have_no_undefined=no
    5.11  #save_LDFLAGS="$LDFLAGS"
    5.12 @@ -1097,7 +1097,7 @@
    5.13          AC_MSG_CHECKING(for necessary GCC -Wno-multichar option)
    5.14          need_gcc_Wno_multichar=no
    5.15          case "$host" in
    5.16 -            *-*-beos* | *-*-haiku*)
    5.17 +            *-*-haiku*)
    5.18                  need_gcc_Wno_multichar=yes
    5.19                  ;;
    5.20          esac
    5.21 @@ -1474,12 +1474,12 @@
    5.22      fi
    5.23  }
    5.24  
    5.25 -dnl Set up the BWindow video driver if enabled
    5.26 -CheckBWINDOW()
    5.27 +dnl Set up the Haiku video driver if enabled
    5.28 +CheckHaikuVideo()
    5.29  {
    5.30      if test x$enable_video = xyes; then
    5.31 -        AC_DEFINE(SDL_VIDEO_DRIVER_BWINDOW, 1, [ ])
    5.32 -        SOURCES="$SOURCES $srcdir/src/video/bwindow/*.cc"
    5.33 +        AC_DEFINE(SDL_VIDEO_DRIVER_HAIKU, 1, [ ])
    5.34 +        SOURCES="$SOURCES $srcdir/src/video/haiku/*.cc"
    5.35          have_video=yes
    5.36      fi
    5.37  }
    5.38 @@ -1743,12 +1743,12 @@
    5.39      fi
    5.40  }
    5.41  
    5.42 -dnl Check for BeOS OpenGL
    5.43 -CheckBeGL()
    5.44 +dnl Check for Haiku OpenGL
    5.45 +CheckHaikuGL()
    5.46  {
    5.47      if test x$enable_video = xyes -a x$enable_video_opengl = xyes; then
    5.48          AC_DEFINE(SDL_VIDEO_OPENGL, 1, [ ])
    5.49 -        AC_DEFINE(SDL_VIDEO_OPENGL_BGL, 1, [ ])
    5.50 +        AC_DEFINE(SDL_VIDEO_OPENGL_HAIKU, 1, [ ])
    5.51          AC_DEFINE(SDL_VIDEO_RENDER_OGL, 1, [ ])
    5.52          EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lGL"
    5.53      fi
    5.54 @@ -2619,55 +2619,60 @@
    5.55          ;;
    5.56  
    5.57      dnl BeOS support removed after SDL 2.0.1. Haiku still works.  --ryan.
    5.58 -    dnl *-*-beos*)
    5.59 +    *-*-beos*)
    5.60 +        AC_MSG_ERROR([
    5.61 +*** BeOS support has been removed as of SDL 2.0.2.
    5.62 +        ])
    5.63 +        ;;
    5.64  
    5.65      *-*-haiku*)
    5.66 -        ARCH=beos
    5.67 +        ARCH=haiku
    5.68          ac_default_prefix=/boot/common
    5.69          CheckDummyVideo
    5.70          CheckDiskAudio
    5.71          CheckDummyAudio
    5.72 -        CheckBWINDOW
    5.73 -        CheckBeGL
    5.74 +        CheckHaikuVideo
    5.75 +        CheckHaikuGL
    5.76          CheckPTHREAD
    5.77 +
    5.78          # Set up files for the audio library
    5.79          if test x$enable_audio = xyes; then
    5.80 -            AC_DEFINE(SDL_AUDIO_DRIVER_BEOSAUDIO, 1, [ ])
    5.81 -            SOURCES="$SOURCES $srcdir/src/audio/baudio/*.cc"
    5.82 +            AC_DEFINE(SDL_AUDIO_DRIVER_HAIKU, 1, [ ])
    5.83 +            SOURCES="$SOURCES $srcdir/src/audio/haiku/*.cc"
    5.84              have_audio=yes
    5.85          fi
    5.86          # Set up files for the joystick library
    5.87          if test x$enable_joystick = xyes; then
    5.88 -            AC_DEFINE(SDL_JOYSTICK_BEOS, 1, [ ])
    5.89 -            SOURCES="$SOURCES $srcdir/src/joystick/beos/*.cc"
    5.90 +            AC_DEFINE(SDL_JOYSTICK_HAIKU, 1, [ ])
    5.91 +            SOURCES="$SOURCES $srcdir/src/joystick/haiku/*.cc"
    5.92              have_joystick=yes
    5.93          fi
    5.94          # Set up files for the timer library
    5.95          if test x$enable_timers = xyes; then
    5.96 -            AC_DEFINE(SDL_TIMER_BEOS, 1, [ ])
    5.97 -            SOURCES="$SOURCES $srcdir/src/timer/beos/*.c"
    5.98 +            AC_DEFINE(SDL_TIMER_HAIKU, 1, [ ])
    5.99 +            SOURCES="$SOURCES $srcdir/src/timer/haiku/*.c"
   5.100              have_timers=yes
   5.101          fi
   5.102          # Set up files for the shared object loading library
   5.103          if test x$enable_loadso = xyes; then
   5.104 -            AC_DEFINE(SDL_LOADSO_BEOS, 1, [ ])
   5.105 -            SOURCES="$SOURCES $srcdir/src/loadso/beos/*.c"
   5.106 +            AC_DEFINE(SDL_LOADSO_HAIKU, 1, [ ])
   5.107 +            SOURCES="$SOURCES $srcdir/src/loadso/haiku/*.c"
   5.108              have_loadso=yes
   5.109          fi
   5.110          # Set up files for the system power library
   5.111          if test x$enable_power = xyes; then
   5.112 -            AC_DEFINE(SDL_POWER_BEOS, 1, [ ])
   5.113 -            SOURCES="$SOURCES $srcdir/src/power/beos/*.c"
   5.114 +            AC_DEFINE(SDL_POWER_HAIKU, 1, [ ])
   5.115 +            SOURCES="$SOURCES $srcdir/src/power/haiku/*.c"
   5.116              have_power=yes
   5.117          fi
   5.118          # Set up files for the system filesystem library
   5.119          if test x$enable_filesystem = xyes; then
   5.120 -            AC_DEFINE(SDL_FILESYSTEM_BEOS, 1, [ ])
   5.121 -            SOURCES="$SOURCES $srcdir/src/filesystem/beos/*.cc"
   5.122 +            AC_DEFINE(SDL_FILESYSTEM_HAIKU, 1, [ ])
   5.123 +            SOURCES="$SOURCES $srcdir/src/filesystem/haiku/*.cc"
   5.124              have_filesystem=yes
   5.125          fi
   5.126 -        # The BeOS platform requires special setup.
   5.127 -        SOURCES="$srcdir/src/main/beos/*.cc $SOURCES"
   5.128 +        # The Haiku platform requires special setup.
   5.129 +        SOURCES="$srcdir/src/main/haiku/*.cc $SOURCES"
   5.130          EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lroot -lbe -lmedia -lgame -ldevice -ltextencoding"
   5.131          ;;
   5.132      arm*-apple-darwin*)
     6.1 --- a/include/SDL_config.h.cmake	Thu Nov 14 22:19:07 2013 +0530
     6.2 +++ b/include/SDL_config.h.cmake	Thu Nov 14 22:35:28 2013 +0530
     6.3 @@ -191,7 +191,7 @@
     6.4  #cmakedefine SDL_AUDIO_DRIVER_ARTS_DYNAMIC @SDL_AUDIO_DRIVER_ARTS_DYNAMIC@
     6.5  #cmakedefine SDL_AUDIO_DRIVER_PULSEAUDIO @SDL_AUDIO_DRIVER_PULSEAUDIO@
     6.6  #cmakedefine SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC @SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC@
     6.7 -#cmakedefine SDL_AUDIO_DRIVER_BEOSAUDIO @SDL_AUDIO_DRIVER_BEOSAUDIO@
     6.8 +#cmakedefine SDL_AUDIO_DRIVER_HAIKU @SDL_AUDIO_DRIVER_HAIKU@
     6.9  #cmakedefine SDL_AUDIO_DRIVER_BSD @SDL_AUDIO_DRIVER_BSD@
    6.10  #cmakedefine SDL_AUDIO_DRIVER_COREAUDIO @SDL_AUDIO_DRIVER_COREAUDIO@
    6.11  #cmakedefine SDL_AUDIO_DRIVER_DISK @SDL_AUDIO_DRIVER_DISK@
    6.12 @@ -216,7 +216,7 @@
    6.13  /* Enable various input drivers */
    6.14  #cmakedefine SDL_INPUT_LINUXEV @SDL_INPUT_LINUXEV@
    6.15  #cmakedefine SDL_INPUT_TSLIB @SDL_INPUT_TSLIB@
    6.16 -#cmakedefine SDL_JOYSTICK_BEOS @SDL_JOYSTICK_BEOS@
    6.17 +#cmakedefine SDL_JOYSTICK_HAIKU @SDL_JOYSTICK_HAIKU@
    6.18  #cmakedefine SDL_JOYSTICK_DINPUT @SDL_JOYSTICK_DINPUT@
    6.19  #cmakedefine SDL_JOYSTICK_DUMMY @SDL_JOYSTICK_DUMMY@
    6.20  #cmakedefine SDL_JOYSTICK_IOKIT @SDL_JOYSTICK_IOKIT@
    6.21 @@ -230,7 +230,7 @@
    6.22  #cmakedefine SDL_HAPTIC_DINPUT @SDL_HAPTIC_DINPUT@
    6.23  
    6.24  /* Enable various shared object loading systems */
    6.25 -#cmakedefine SDL_LOADSO_BEOS @SDL_LOADSO_BEOS@
    6.26 +#cmakedefine SDL_LOADSO_HAIKU @SDL_LOADSO_HAIKU@
    6.27  #cmakedefine SDL_LOADSO_DLOPEN @SDL_LOADSO_DLOPEN@
    6.28  #cmakedefine SDL_LOADSO_DUMMY @SDL_LOADSO_DUMMY@
    6.29  #cmakedefine SDL_LOADSO_LDG @SDL_LOADSO_LDG@
    6.30 @@ -243,14 +243,14 @@
    6.31  #cmakedefine SDL_THREAD_WINDOWS @SDL_THREAD_WINDOWS@
    6.32  
    6.33  /* Enable various timer systems */
    6.34 -#cmakedefine SDL_TIMER_BEOS @SDL_TIMER_BEOS@
    6.35 +#cmakedefine SDL_TIMER_HAIKU @SDL_TIMER_HAIKU@
    6.36  #cmakedefine SDL_TIMER_DUMMY @SDL_TIMER_DUMMY@
    6.37  #cmakedefine SDL_TIMER_UNIX @SDL_TIMER_UNIX@
    6.38  #cmakedefine SDL_TIMER_WINDOWS @SDL_TIMER_WINDOWS@
    6.39  #cmakedefine SDL_TIMER_WINCE @SDL_TIMER_WINCE@
    6.40  
    6.41  /* Enable various video drivers */
    6.42 -#cmakedefine SDL_VIDEO_DRIVER_BWINDOW @SDL_VIDEO_DRIVER_BWINDOW@
    6.43 +#cmakedefine SDL_VIDEO_DRIVER_HAIKU @SDL_VIDEO_DRIVER_HAIKU@
    6.44  #cmakedefine SDL_VIDEO_DRIVER_COCOA @SDL_VIDEO_DRIVER_COCOA@
    6.45  #cmakedefine SDL_VIDEO_DRIVER_DIRECTFB @SDL_VIDEO_DRIVER_DIRECTFB@
    6.46  #cmakedefine SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC @SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC@
    6.47 @@ -300,11 +300,11 @@
    6.48  #cmakedefine SDL_POWER_LINUX @SDL_POWER_LINUX@
    6.49  #cmakedefine SDL_POWER_WINDOWS @SDL_POWER_WINDOWS@
    6.50  #cmakedefine SDL_POWER_MACOSX @SDL_POWER_MACOSX@
    6.51 -#cmakedefine SDL_POWER_BEOS @SDL_POWER_BEOS@
    6.52 +#cmakedefine SDL_POWER_HAIKU @SDL_POWER_HAIKU@
    6.53  #cmakedefine SDL_POWER_HARDWIRED @SDL_POWER_HARDWIRED@
    6.54  
    6.55  /* Enable system filesystem support */
    6.56 -#cmakedefine SDL_FILESYSTEM_BEOS @SDL_FILESYSTEM_BEOS@
    6.57 +#cmakedefine SDL_FILESYSTEM_HAIKU @SDL_FILESYSTEM_HAIKU@
    6.58  #cmakedefine SDL_FILESYSTEM_COCOA @SDL_FILESYSTEM_COCOA@
    6.59  #cmakedefine SDL_FILESYSTEM_DUMMY @SDL_FILESYSTEM_DUMMY@
    6.60  #cmakedefine SDL_FILESYSTEM_UNIX @SDL_FILESYSTEM_UNIX@
     7.1 --- a/include/SDL_config.h.in	Thu Nov 14 22:19:07 2013 +0530
     7.2 +++ b/include/SDL_config.h.in	Thu Nov 14 22:35:28 2013 +0530
     7.3 @@ -193,7 +193,7 @@
     7.4  #undef SDL_AUDIO_DRIVER_ARTS_DYNAMIC
     7.5  #undef SDL_AUDIO_DRIVER_PULSEAUDIO
     7.6  #undef SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC
     7.7 -#undef SDL_AUDIO_DRIVER_BEOSAUDIO
     7.8 +#undef SDL_AUDIO_DRIVER_HAIKU
     7.9  #undef SDL_AUDIO_DRIVER_BSD
    7.10  #undef SDL_AUDIO_DRIVER_COREAUDIO
    7.11  #undef SDL_AUDIO_DRIVER_DISK
    7.12 @@ -219,7 +219,7 @@
    7.13  #undef SDL_INPUT_LINUXEV
    7.14  #undef SDL_INPUT_LINUXKD
    7.15  #undef SDL_INPUT_TSLIB
    7.16 -#undef SDL_JOYSTICK_BEOS
    7.17 +#undef SDL_JOYSTICK_HAIKU
    7.18  #undef SDL_JOYSTICK_DINPUT
    7.19  #undef SDL_JOYSTICK_DUMMY
    7.20  #undef SDL_JOYSTICK_IOKIT
    7.21 @@ -233,7 +233,7 @@
    7.22  #undef SDL_HAPTIC_DINPUT
    7.23  
    7.24  /* Enable various shared object loading systems */
    7.25 -#undef SDL_LOADSO_BEOS
    7.26 +#undef SDL_LOADSO_HAIKU
    7.27  #undef SDL_LOADSO_DLOPEN
    7.28  #undef SDL_LOADSO_DUMMY
    7.29  #undef SDL_LOADSO_LDG
    7.30 @@ -246,13 +246,13 @@
    7.31  #undef SDL_THREAD_WINDOWS
    7.32  
    7.33  /* Enable various timer systems */
    7.34 -#undef SDL_TIMER_BEOS
    7.35 +#undef SDL_TIMER_HAIKU
    7.36  #undef SDL_TIMER_DUMMY
    7.37  #undef SDL_TIMER_UNIX
    7.38  #undef SDL_TIMER_WINDOWS
    7.39  
    7.40  /* Enable various video drivers */
    7.41 -#undef SDL_VIDEO_DRIVER_BWINDOW
    7.42 +#undef SDL_VIDEO_DRIVER_HAIKU
    7.43  #undef SDL_VIDEO_DRIVER_COCOA
    7.44  #undef SDL_VIDEO_DRIVER_DIRECTFB
    7.45  #undef SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC
    7.46 @@ -303,11 +303,11 @@
    7.47  #undef SDL_POWER_LINUX
    7.48  #undef SDL_POWER_WINDOWS
    7.49  #undef SDL_POWER_MACOSX
    7.50 -#undef SDL_POWER_BEOS
    7.51 +#undef SDL_POWER_HAIKU
    7.52  #undef SDL_POWER_HARDWIRED
    7.53  
    7.54  /* Enable system filesystem support */
    7.55 -#undef SDL_FILESYSTEM_BEOS
    7.56 +#undef SDL_FILESYSTEM_HAIKU
    7.57  #undef SDL_FILESYSTEM_COCOA
    7.58  #undef SDL_FILESYSTEM_DUMMY
    7.59  #undef SDL_FILESYSTEM_UNIX
     8.1 --- a/include/SDL_platform.h	Thu Nov 14 22:19:07 2013 +0530
     8.2 +++ b/include/SDL_platform.h	Thu Nov 14 22:35:28 2013 +0530
     8.3 @@ -32,10 +32,6 @@
     8.4  #undef __AIX__
     8.5  #define __AIX__     1
     8.6  #endif
     8.7 -#if defined(__BEOS__)
     8.8 -#undef __BEOS__
     8.9 -#define __BEOS__    1
    8.10 -#endif
    8.11  #if defined(__HAIKU__)
    8.12  #undef __HAIKU__
    8.13  #define __HAIKU__   1
     9.1 --- a/include/SDL_thread.h	Thu Nov 14 22:19:07 2013 +0530
     9.2 +++ b/include/SDL_thread.h	Thu Nov 14 22:35:28 2013 +0530
     9.3 @@ -119,7 +119,7 @@
     9.4   *  Create a thread.
     9.5   *
     9.6   *   Thread naming is a little complicated: Most systems have very small
     9.7 - *    limits for the string length (BeOS has 32 bytes, Linux currently has 16,
     9.8 + *    limits for the string length (Haiku has 32 bytes, Linux currently has 16,
     9.9   *    Visual C++ 6.0 has nine!), and possibly other arbitrary rules. You'll
    9.10   *    have to see what happens with your system's debugger. The name should be
    9.11   *    UTF-8 (but using the naming limits of C identifiers is a better bet).
    10.1 --- a/src/SDL.c	Thu Nov 14 22:19:07 2013 +0530
    10.2 +++ b/src/SDL.c	Thu Nov 14 22:35:28 2013 +0530
    10.3 @@ -396,8 +396,6 @@
    10.4      return "AIX";
    10.5  #elif __ANDROID__
    10.6      return "Android";
    10.7 -#elif __BEOS__
    10.8 -    return "BeOS";
    10.9  #elif __BSDI__
   10.10      return "BSDI";
   10.11  #elif __DREAMCAST__
    11.1 --- a/src/audio/SDL_audio.c	Thu Nov 14 22:19:07 2013 +0530
    11.2 +++ b/src/audio/SDL_audio.c	Thu Nov 14 22:35:28 2013 +0530
    11.3 @@ -56,7 +56,7 @@
    11.4  extern AudioBootStrap DSOUND_bootstrap;
    11.5  extern AudioBootStrap WINMM_bootstrap;
    11.6  extern AudioBootStrap PAUDIO_bootstrap;
    11.7 -extern AudioBootStrap BEOSAUDIO_bootstrap;
    11.8 +extern AudioBootStrap HAIKUAUDIO_bootstrap;
    11.9  extern AudioBootStrap COREAUDIO_bootstrap;
   11.10  extern AudioBootStrap SNDMGR_bootstrap;
   11.11  extern AudioBootStrap DISKAUD_bootstrap;
   11.12 @@ -113,8 +113,8 @@
   11.13  #if SDL_AUDIO_DRIVER_PAUDIO
   11.14      &PAUDIO_bootstrap,
   11.15  #endif
   11.16 -#if SDL_AUDIO_DRIVER_BEOSAUDIO
   11.17 -    &BEOSAUDIO_bootstrap,
   11.18 +#if SDL_AUDIO_DRIVER_HAIKU
   11.19 +    &HAIKUAUDIO_bootstrap,
   11.20  #endif
   11.21  #if SDL_AUDIO_DRIVER_COREAUDIO
   11.22      &COREAUDIO_bootstrap,
    12.1 --- a/src/audio/baudio/SDL_beaudio.cc	Thu Nov 14 22:19:07 2013 +0530
    12.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.3 @@ -1,240 +0,0 @@
    12.4 -/*
    12.5 -  Simple DirectMedia Layer
    12.6 -  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    12.7 -
    12.8 -  This software is provided 'as-is', without any express or implied
    12.9 -  warranty.  In no event will the authors be held liable for any damages
   12.10 -  arising from the use of this software.
   12.11 -
   12.12 -  Permission is granted to anyone to use this software for any purpose,
   12.13 -  including commercial applications, and to alter it and redistribute it
   12.14 -  freely, subject to the following restrictions:
   12.15 -
   12.16 -  1. The origin of this software must not be misrepresented; you must not
   12.17 -     claim that you wrote the original software. If you use this software
   12.18 -     in a product, an acknowledgment in the product documentation would be
   12.19 -     appreciated but is not required.
   12.20 -  2. Altered source versions must be plainly marked as such, and must not be
   12.21 -     misrepresented as being the original software.
   12.22 -  3. This notice may not be removed or altered from any source distribution.
   12.23 -*/
   12.24 -#include "SDL_config.h"
   12.25 -
   12.26 -#if SDL_AUDIO_DRIVER_BEOSAUDIO
   12.27 -
   12.28 -/* Allow access to the audio stream on BeOS */
   12.29 -
   12.30 -#include <SoundPlayer.h>
   12.31 -#include <signal.h>
   12.32 -
   12.33 -#include "../../main/beos/SDL_BeApp.h"
   12.34 -
   12.35 -extern "C"
   12.36 -{
   12.37 -
   12.38 -#include "SDL_audio.h"
   12.39 -#include "../SDL_audio_c.h"
   12.40 -#include "../SDL_sysaudio.h"
   12.41 -#include "SDL_beaudio.h"
   12.42 -
   12.43 -}
   12.44 -
   12.45 -
   12.46 -/* !!! FIXME: have the callback call the higher level to avoid code dupe. */
   12.47 -/* The BeOS callback for handling the audio buffer */
   12.48 -static void
   12.49 -FillSound(void *device, void *stream, size_t len,
   12.50 -          const media_raw_audio_format & format)
   12.51 -{
   12.52 -    SDL_AudioDevice *audio = (SDL_AudioDevice *) device;
   12.53 -
   12.54 -    /* Only do soemthing if audio is enabled */
   12.55 -    if (!audio->enabled)
   12.56 -        return;
   12.57 -
   12.58 -    if (!audio->paused) {
   12.59 -        if (audio->convert.needed) {
   12.60 -            SDL_LockMutex(audio->mixer_lock);
   12.61 -            (*audio->spec.callback) (audio->spec.userdata,
   12.62 -                                     (Uint8 *) audio->convert.buf,
   12.63 -                                     audio->convert.len);
   12.64 -            SDL_UnlockMutex(audio->mixer_lock);
   12.65 -            SDL_ConvertAudio(&audio->convert);
   12.66 -            SDL_memcpy(stream, audio->convert.buf, audio->convert.len_cvt);
   12.67 -        } else {
   12.68 -            SDL_LockMutex(audio->mixer_lock);
   12.69 -            (*audio->spec.callback) (audio->spec.userdata,
   12.70 -                                     (Uint8 *) stream, len);
   12.71 -            SDL_UnlockMutex(audio->mixer_lock);
   12.72 -        }
   12.73 -    }
   12.74 -}
   12.75 -
   12.76 -static void
   12.77 -BEOSAUDIO_CloseDevice(_THIS)
   12.78 -{
   12.79 -    if (_this->hidden != NULL) {
   12.80 -        if (_this->hidden->audio_obj) {
   12.81 -            _this->hidden->audio_obj->Stop();
   12.82 -            delete _this->hidden->audio_obj;
   12.83 -            _this->hidden->audio_obj = NULL;
   12.84 -        }
   12.85 -
   12.86 -        delete _this->hidden;
   12.87 -        _this->hidden = NULL;
   12.88 -    }
   12.89 -}
   12.90 -
   12.91 -
   12.92 -static const int sig_list[] = {
   12.93 -    SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGWINCH, 0
   12.94 -};
   12.95 -
   12.96 -static inline void
   12.97 -MaskSignals(sigset_t * omask)
   12.98 -{
   12.99 -    sigset_t mask;
  12.100 -    int i;
  12.101 -
  12.102 -    sigemptyset(&mask);
  12.103 -    for (i = 0; sig_list[i]; ++i) {
  12.104 -        sigaddset(&mask, sig_list[i]);
  12.105 -    }
  12.106 -    sigprocmask(SIG_BLOCK, &mask, omask);
  12.107 -}
  12.108 -
  12.109 -static inline void
  12.110 -UnmaskSignals(sigset_t * omask)
  12.111 -{
  12.112 -    sigprocmask(SIG_SETMASK, omask, NULL);
  12.113 -}
  12.114 -
  12.115 -
  12.116 -static int
  12.117 -BEOSAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
  12.118 -{
  12.119 -    int valid_datatype = 0;
  12.120 -    media_raw_audio_format format;
  12.121 -    SDL_AudioFormat test_format = SDL_FirstAudioFormat(_this->spec.format);
  12.122 -
  12.123 -    /* Initialize all variables that we clean on shutdown */
  12.124 -    _this->hidden = new SDL_PrivateAudioData;
  12.125 -    if (_this->hidden == NULL) {
  12.126 -        return SDL_OutOfMemory();
  12.127 -    }
  12.128 -    SDL_memset(_this->hidden, 0, (sizeof *_this->hidden));
  12.129 -
  12.130 -    /* Parse the audio format and fill the Be raw audio format */
  12.131 -    SDL_memset(&format, '\0', sizeof(media_raw_audio_format));
  12.132 -    format.byte_order = B_MEDIA_LITTLE_ENDIAN;
  12.133 -    format.frame_rate = (float) _this->spec.freq;
  12.134 -    format.channel_count = _this->spec.channels;        /* !!! FIXME: support > 2? */
  12.135 -    while ((!valid_datatype) && (test_format)) {
  12.136 -        valid_datatype = 1;
  12.137 -        _this->spec.format = test_format;
  12.138 -        switch (test_format) {
  12.139 -        case AUDIO_S8:
  12.140 -            format.format = media_raw_audio_format::B_AUDIO_CHAR;
  12.141 -            break;
  12.142 -
  12.143 -        case AUDIO_U8:
  12.144 -            format.format = media_raw_audio_format::B_AUDIO_UCHAR;
  12.145 -            break;
  12.146 -
  12.147 -        case AUDIO_S16LSB:
  12.148 -            format.format = media_raw_audio_format::B_AUDIO_SHORT;
  12.149 -            break;
  12.150 -
  12.151 -        case AUDIO_S16MSB:
  12.152 -            format.format = media_raw_audio_format::B_AUDIO_SHORT;
  12.153 -            format.byte_order = B_MEDIA_BIG_ENDIAN;
  12.154 -            break;
  12.155 -
  12.156 -        case AUDIO_S32LSB:
  12.157 -            format.format = media_raw_audio_format::B_AUDIO_INT;
  12.158 -            break;
  12.159 -
  12.160 -        case AUDIO_S32MSB:
  12.161 -            format.format = media_raw_audio_format::B_AUDIO_INT;
  12.162 -            format.byte_order = B_MEDIA_BIG_ENDIAN;
  12.163 -            break;
  12.164 -
  12.165 -        case AUDIO_F32LSB:
  12.166 -            format.format = media_raw_audio_format::B_AUDIO_FLOAT;
  12.167 -            break;
  12.168 -
  12.169 -        case AUDIO_F32MSB:
  12.170 -            format.format = media_raw_audio_format::B_AUDIO_FLOAT;
  12.171 -            format.byte_order = B_MEDIA_BIG_ENDIAN;
  12.172 -            break;
  12.173 -
  12.174 -        default:
  12.175 -            valid_datatype = 0;
  12.176 -            test_format = SDL_NextAudioFormat();
  12.177 -            break;
  12.178 -        }
  12.179 -    }
  12.180 -
  12.181 -    if (!valid_datatype) {      /* shouldn't happen, but just in case... */
  12.182 -        BEOSAUDIO_CloseDevice(_this);
  12.183 -        return SDL_SetError("Unsupported audio format");
  12.184 -    }
  12.185 -
  12.186 -    /* Calculate the final parameters for this audio specification */
  12.187 -    SDL_CalculateAudioSpec(&_this->spec);
  12.188 -
  12.189 -    format.buffer_size = _this->spec.size;
  12.190 -
  12.191 -    /* Subscribe to the audio stream (creates a new thread) */
  12.192 -    sigset_t omask;
  12.193 -    MaskSignals(&omask);
  12.194 -    _this->hidden->audio_obj = new BSoundPlayer(&format, "SDL Audio",
  12.195 -                                                FillSound, NULL, _this);
  12.196 -    UnmaskSignals(&omask);
  12.197 -
  12.198 -    if (_this->hidden->audio_obj->Start() == B_NO_ERROR) {
  12.199 -        _this->hidden->audio_obj->SetHasData(true);
  12.200 -    } else {
  12.201 -        BEOSAUDIO_CloseDevice(_this);
  12.202 -        return SDL_SetError("Unable to start Be audio");
  12.203 -    }
  12.204 -
  12.205 -    /* We're running! */
  12.206 -    return 0;
  12.207 -}
  12.208 -
  12.209 -static void
  12.210 -BEOSAUDIO_Deinitialize(void)
  12.211 -{
  12.212 -    SDL_QuitBeApp();
  12.213 -}
  12.214 -
  12.215 -static int
  12.216 -BEOSAUDIO_Init(SDL_AudioDriverImpl * impl)
  12.217 -{
  12.218 -    /* Initialize the Be Application, if it's not already started */
  12.219 -    if (SDL_InitBeApp() < 0) {
  12.220 -        return 0;
  12.221 -    }
  12.222 -
  12.223 -    /* Set the function pointers */
  12.224 -    impl->OpenDevice = BEOSAUDIO_OpenDevice;
  12.225 -    impl->CloseDevice = BEOSAUDIO_CloseDevice;
  12.226 -    impl->Deinitialize = BEOSAUDIO_Deinitialize;
  12.227 -    impl->ProvidesOwnCallbackThread = 1;
  12.228 -    impl->OnlyHasDefaultOutputDevice = 1;
  12.229 -
  12.230 -    return 1;   /* this audio target is available. */
  12.231 -}
  12.232 -
  12.233 -extern "C"
  12.234 -{
  12.235 -    extern AudioBootStrap BEOSAUDIO_bootstrap;
  12.236 -}
  12.237 -AudioBootStrap BEOSAUDIO_bootstrap = {
  12.238 -    "baudio", "BeOS BSoundPlayer", BEOSAUDIO_Init, 0
  12.239 -};
  12.240 -
  12.241 -#endif /* SDL_AUDIO_DRIVER_BEOSAUDIO */
  12.242 -
  12.243 -/* vi: set ts=4 sw=4 expandtab: */
    13.1 --- a/src/audio/baudio/SDL_beaudio.h	Thu Nov 14 22:19:07 2013 +0530
    13.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.3 @@ -1,38 +0,0 @@
    13.4 -/*
    13.5 -  Simple DirectMedia Layer
    13.6 -  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    13.7 -
    13.8 -  This software is provided 'as-is', without any express or implied
    13.9 -  warranty.  In no event will the authors be held liable for any damages
   13.10 -  arising from the use of this software.
   13.11 -
   13.12 -  Permission is granted to anyone to use this software for any purpose,
   13.13 -  including commercial applications, and to alter it and redistribute it
   13.14 -  freely, subject to the following restrictions:
   13.15 -
   13.16 -  1. The origin of this software must not be misrepresented; you must not
   13.17 -     claim that you wrote the original software. If you use this software
   13.18 -     in a product, an acknowledgment in the product documentation would be
   13.19 -     appreciated but is not required.
   13.20 -  2. Altered source versions must be plainly marked as such, and must not be
   13.21 -     misrepresented as being the original software.
   13.22 -  3. This notice may not be removed or altered from any source distribution.
   13.23 -*/
   13.24 -#include "SDL_config.h"
   13.25 -
   13.26 -#ifndef _SDL_beaudio_h
   13.27 -#define _SDL_beaudio_h
   13.28 -
   13.29 -#include "../SDL_sysaudio.h"
   13.30 -
   13.31 -/* Hidden "this" pointer for the audio functions */
   13.32 -#define _THIS   SDL_AudioDevice *_this
   13.33 -
   13.34 -struct SDL_PrivateAudioData
   13.35 -{
   13.36 -    BSoundPlayer *audio_obj;
   13.37 -};
   13.38 -
   13.39 -#endif /* _SDL_beaudio_h */
   13.40 -
   13.41 -/* vi: set ts=4 sw=4 expandtab: */
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/src/audio/haiku/SDL_haikuaudio.cc	Thu Nov 14 22:35:28 2013 +0530
    14.3 @@ -0,0 +1,240 @@
    14.4 +/*
    14.5 +  Simple DirectMedia Layer
    14.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    14.7 +
    14.8 +  This software is provided 'as-is', without any express or implied
    14.9 +  warranty.  In no event will the authors be held liable for any damages
   14.10 +  arising from the use of this software.
   14.11 +
   14.12 +  Permission is granted to anyone to use this software for any purpose,
   14.13 +  including commercial applications, and to alter it and redistribute it
   14.14 +  freely, subject to the following restrictions:
   14.15 +
   14.16 +  1. The origin of this software must not be misrepresented; you must not
   14.17 +     claim that you wrote the original software. If you use this software
   14.18 +     in a product, an acknowledgment in the product documentation would be
   14.19 +     appreciated but is not required.
   14.20 +  2. Altered source versions must be plainly marked as such, and must not be
   14.21 +     misrepresented as being the original software.
   14.22 +  3. This notice may not be removed or altered from any source distribution.
   14.23 +*/
   14.24 +#include "SDL_config.h"
   14.25 +
   14.26 +#if SDL_AUDIO_DRIVER_HAIKU
   14.27 +
   14.28 +/* Allow access to the audio stream on Haiku */
   14.29 +
   14.30 +#include <SoundPlayer.h>
   14.31 +#include <signal.h>
   14.32 +
   14.33 +#include "../../main/haiku/SDL_BeApp.h"
   14.34 +
   14.35 +extern "C"
   14.36 +{
   14.37 +
   14.38 +#include "SDL_audio.h"
   14.39 +#include "../SDL_audio_c.h"
   14.40 +#include "../SDL_sysaudio.h"
   14.41 +#include "SDL_haikuaudio.h"
   14.42 +
   14.43 +}
   14.44 +
   14.45 +
   14.46 +/* !!! FIXME: have the callback call the higher level to avoid code dupe. */
   14.47 +/* The Haiku callback for handling the audio buffer */
   14.48 +static void
   14.49 +FillSound(void *device, void *stream, size_t len,
   14.50 +          const media_raw_audio_format & format)
   14.51 +{
   14.52 +    SDL_AudioDevice *audio = (SDL_AudioDevice *) device;
   14.53 +
   14.54 +    /* Only do soemthing if audio is enabled */
   14.55 +    if (!audio->enabled)
   14.56 +        return;
   14.57 +
   14.58 +    if (!audio->paused) {
   14.59 +        if (audio->convert.needed) {
   14.60 +            SDL_LockMutex(audio->mixer_lock);
   14.61 +            (*audio->spec.callback) (audio->spec.userdata,
   14.62 +                                     (Uint8 *) audio->convert.buf,
   14.63 +                                     audio->convert.len);
   14.64 +            SDL_UnlockMutex(audio->mixer_lock);
   14.65 +            SDL_ConvertAudio(&audio->convert);
   14.66 +            SDL_memcpy(stream, audio->convert.buf, audio->convert.len_cvt);
   14.67 +        } else {
   14.68 +            SDL_LockMutex(audio->mixer_lock);
   14.69 +            (*audio->spec.callback) (audio->spec.userdata,
   14.70 +                                     (Uint8 *) stream, len);
   14.71 +            SDL_UnlockMutex(audio->mixer_lock);
   14.72 +        }
   14.73 +    }
   14.74 +}
   14.75 +
   14.76 +static void
   14.77 +HAIKUAUDIO_CloseDevice(_THIS)
   14.78 +{
   14.79 +    if (_this->hidden != NULL) {
   14.80 +        if (_this->hidden->audio_obj) {
   14.81 +            _this->hidden->audio_obj->Stop();
   14.82 +            delete _this->hidden->audio_obj;
   14.83 +            _this->hidden->audio_obj = NULL;
   14.84 +        }
   14.85 +
   14.86 +        delete _this->hidden;
   14.87 +        _this->hidden = NULL;
   14.88 +    }
   14.89 +}
   14.90 +
   14.91 +
   14.92 +static const int sig_list[] = {
   14.93 +    SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGWINCH, 0
   14.94 +};
   14.95 +
   14.96 +static inline void
   14.97 +MaskSignals(sigset_t * omask)
   14.98 +{
   14.99 +    sigset_t mask;
  14.100 +    int i;
  14.101 +
  14.102 +    sigemptyset(&mask);
  14.103 +    for (i = 0; sig_list[i]; ++i) {
  14.104 +        sigaddset(&mask, sig_list[i]);
  14.105 +    }
  14.106 +    sigprocmask(SIG_BLOCK, &mask, omask);
  14.107 +}
  14.108 +
  14.109 +static inline void
  14.110 +UnmaskSignals(sigset_t * omask)
  14.111 +{
  14.112 +    sigprocmask(SIG_SETMASK, omask, NULL);
  14.113 +}
  14.114 +
  14.115 +
  14.116 +static int
  14.117 +HAIKUAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
  14.118 +{
  14.119 +    int valid_datatype = 0;
  14.120 +    media_raw_audio_format format;
  14.121 +    SDL_AudioFormat test_format = SDL_FirstAudioFormat(_this->spec.format);
  14.122 +
  14.123 +    /* Initialize all variables that we clean on shutdown */
  14.124 +    _this->hidden = new SDL_PrivateAudioData;
  14.125 +    if (_this->hidden == NULL) {
  14.126 +        return SDL_OutOfMemory();
  14.127 +    }
  14.128 +    SDL_memset(_this->hidden, 0, (sizeof *_this->hidden));
  14.129 +
  14.130 +    /* Parse the audio format and fill the Be raw audio format */
  14.131 +    SDL_memset(&format, '\0', sizeof(media_raw_audio_format));
  14.132 +    format.byte_order = B_MEDIA_LITTLE_ENDIAN;
  14.133 +    format.frame_rate = (float) _this->spec.freq;
  14.134 +    format.channel_count = _this->spec.channels;        /* !!! FIXME: support > 2? */
  14.135 +    while ((!valid_datatype) && (test_format)) {
  14.136 +        valid_datatype = 1;
  14.137 +        _this->spec.format = test_format;
  14.138 +        switch (test_format) {
  14.139 +        case AUDIO_S8:
  14.140 +            format.format = media_raw_audio_format::B_AUDIO_CHAR;
  14.141 +            break;
  14.142 +
  14.143 +        case AUDIO_U8:
  14.144 +            format.format = media_raw_audio_format::B_AUDIO_UCHAR;
  14.145 +            break;
  14.146 +
  14.147 +        case AUDIO_S16LSB:
  14.148 +            format.format = media_raw_audio_format::B_AUDIO_SHORT;
  14.149 +            break;
  14.150 +
  14.151 +        case AUDIO_S16MSB:
  14.152 +            format.format = media_raw_audio_format::B_AUDIO_SHORT;
  14.153 +            format.byte_order = B_MEDIA_BIG_ENDIAN;
  14.154 +            break;
  14.155 +
  14.156 +        case AUDIO_S32LSB:
  14.157 +            format.format = media_raw_audio_format::B_AUDIO_INT;
  14.158 +            break;
  14.159 +
  14.160 +        case AUDIO_S32MSB:
  14.161 +            format.format = media_raw_audio_format::B_AUDIO_INT;
  14.162 +            format.byte_order = B_MEDIA_BIG_ENDIAN;
  14.163 +            break;
  14.164 +
  14.165 +        case AUDIO_F32LSB:
  14.166 +            format.format = media_raw_audio_format::B_AUDIO_FLOAT;
  14.167 +            break;
  14.168 +
  14.169 +        case AUDIO_F32MSB:
  14.170 +            format.format = media_raw_audio_format::B_AUDIO_FLOAT;
  14.171 +            format.byte_order = B_MEDIA_BIG_ENDIAN;
  14.172 +            break;
  14.173 +
  14.174 +        default:
  14.175 +            valid_datatype = 0;
  14.176 +            test_format = SDL_NextAudioFormat();
  14.177 +            break;
  14.178 +        }
  14.179 +    }
  14.180 +
  14.181 +    if (!valid_datatype) {      /* shouldn't happen, but just in case... */
  14.182 +        HAIKUAUDIO_CloseDevice(_this);
  14.183 +        return SDL_SetError("Unsupported audio format");
  14.184 +    }
  14.185 +
  14.186 +    /* Calculate the final parameters for this audio specification */
  14.187 +    SDL_CalculateAudioSpec(&_this->spec);
  14.188 +
  14.189 +    format.buffer_size = _this->spec.size;
  14.190 +
  14.191 +    /* Subscribe to the audio stream (creates a new thread) */
  14.192 +    sigset_t omask;
  14.193 +    MaskSignals(&omask);
  14.194 +    _this->hidden->audio_obj = new BSoundPlayer(&format, "SDL Audio",
  14.195 +                                                FillSound, NULL, _this);
  14.196 +    UnmaskSignals(&omask);
  14.197 +
  14.198 +    if (_this->hidden->audio_obj->Start() == B_NO_ERROR) {
  14.199 +        _this->hidden->audio_obj->SetHasData(true);
  14.200 +    } else {
  14.201 +        HAIKUAUDIO_CloseDevice(_this);
  14.202 +        return SDL_SetError("Unable to start Be audio");
  14.203 +    }
  14.204 +
  14.205 +    /* We're running! */
  14.206 +    return 0;
  14.207 +}
  14.208 +
  14.209 +static void
  14.210 +HAIKUAUDIO_Deinitialize(void)
  14.211 +{
  14.212 +    SDL_QuitBeApp();
  14.213 +}
  14.214 +
  14.215 +static int
  14.216 +HAIKUAUDIO_Init(SDL_AudioDriverImpl * impl)
  14.217 +{
  14.218 +    /* Initialize the Be Application, if it's not already started */
  14.219 +    if (SDL_InitBeApp() < 0) {
  14.220 +        return 0;
  14.221 +    }
  14.222 +
  14.223 +    /* Set the function pointers */
  14.224 +    impl->OpenDevice = HAIKUAUDIO_OpenDevice;
  14.225 +    impl->CloseDevice = HAIKUAUDIO_CloseDevice;
  14.226 +    impl->Deinitialize = HAIKUAUDIO_Deinitialize;
  14.227 +    impl->ProvidesOwnCallbackThread = 1;
  14.228 +    impl->OnlyHasDefaultOutputDevice = 1;
  14.229 +
  14.230 +    return 1;   /* this audio target is available. */
  14.231 +}
  14.232 +
  14.233 +extern "C"
  14.234 +{
  14.235 +    extern AudioBootStrap HAIKUAUDIO_bootstrap;
  14.236 +}
  14.237 +AudioBootStrap HAIKUAUDIO_bootstrap = {
  14.238 +    "haiku", "Haiku BSoundPlayer", HAIKUAUDIO_Init, 0
  14.239 +};
  14.240 +
  14.241 +#endif /* SDL_AUDIO_DRIVER_HAIKU */
  14.242 +
  14.243 +/* vi: set ts=4 sw=4 expandtab: */
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/src/audio/haiku/SDL_haikuaudio.h	Thu Nov 14 22:35:28 2013 +0530
    15.3 @@ -0,0 +1,38 @@
    15.4 +/*
    15.5 +  Simple DirectMedia Layer
    15.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    15.7 +
    15.8 +  This software is provided 'as-is', without any express or implied
    15.9 +  warranty.  In no event will the authors be held liable for any damages
   15.10 +  arising from the use of this software.
   15.11 +
   15.12 +  Permission is granted to anyone to use this software for any purpose,
   15.13 +  including commercial applications, and to alter it and redistribute it
   15.14 +  freely, subject to the following restrictions:
   15.15 +
   15.16 +  1. The origin of this software must not be misrepresented; you must not
   15.17 +     claim that you wrote the original software. If you use this software
   15.18 +     in a product, an acknowledgment in the product documentation would be
   15.19 +     appreciated but is not required.
   15.20 +  2. Altered source versions must be plainly marked as such, and must not be
   15.21 +     misrepresented as being the original software.
   15.22 +  3. This notice may not be removed or altered from any source distribution.
   15.23 +*/
   15.24 +#include "SDL_config.h"
   15.25 +
   15.26 +#ifndef _SDL_beaudio_h
   15.27 +#define _SDL_beaudio_h
   15.28 +
   15.29 +#include "../SDL_sysaudio.h"
   15.30 +
   15.31 +/* Hidden "this" pointer for the audio functions */
   15.32 +#define _THIS   SDL_AudioDevice *_this
   15.33 +
   15.34 +struct SDL_PrivateAudioData
   15.35 +{
   15.36 +    BSoundPlayer *audio_obj;
   15.37 +};
   15.38 +
   15.39 +#endif /* _SDL_beaudio_h */
   15.40 +
   15.41 +/* vi: set ts=4 sw=4 expandtab: */
    16.1 --- a/src/events/SDL_sysevents.h	Thu Nov 14 22:19:07 2013 +0530
    16.2 +++ b/src/events/SDL_sysevents.h	Thu Nov 14 22:35:28 2013 +0530
    16.3 @@ -24,8 +24,8 @@
    16.4  
    16.5  /* Useful functions and variables from SDL_sysevents.c */
    16.6  
    16.7 -#if defined(__BEOS__) || defined(__HAIKU__) 
    16.8 -/* The Be and Haiku event loops run in a separate thread */
    16.9 +#if defined(__HAIKU__)
   16.10 +/* The Haiku event loops run in a separate thread */
   16.11  #define MUST_THREAD_EVENTS
   16.12  #endif
   16.13  
    17.1 --- a/src/filesystem/beos/SDL_sysfilesystem.cc	Thu Nov 14 22:19:07 2013 +0530
    17.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.3 @@ -1,93 +0,0 @@
    17.4 -/*
    17.5 -  Simple DirectMedia Layer
    17.6 -  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    17.7 -
    17.8 -  This software is provided 'as-is', without any express or implied
    17.9 -  warranty.  In no event will the authors be held liable for any damages
   17.10 -  arising from the use of this software.
   17.11 -
   17.12 -  Permission is granted to anyone to use this software for any purpose,
   17.13 -  including commercial applications, and to alter it and redistribute it
   17.14 -  freely, subject to the following restrictions:
   17.15 -
   17.16 -  1. The origin of this software must not be misrepresented; you must not
   17.17 -     claim that you wrote the original software. If you use this software
   17.18 -     in a product, an acknowledgment in the product documentation would be
   17.19 -     appreciated but is not required.
   17.20 -  2. Altered source versions must be plainly marked as such, and must not be
   17.21 -     misrepresented as being the original software.
   17.22 -  3. This notice may not be removed or altered from any source distribution.
   17.23 -*/
   17.24 -#include "SDL_config.h"
   17.25 -
   17.26 -#ifdef SDL_FILESYSTEM_BEOS
   17.27 -
   17.28 -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
   17.29 -/* System dependent filesystem routines                                */
   17.30 -
   17.31 -#include <os/kernel/image.h>
   17.32 -#include <os/storage/Directory.h>
   17.33 -#include <os/storage/Entry.h>
   17.34 -#include <os/storage/Path.h>
   17.35 -
   17.36 -#include "SDL_error.h"
   17.37 -#include "SDL_stdinc.h"
   17.38 -#include "SDL_assert.h"
   17.39 -#include "SDL_filesystem.h"
   17.40 -
   17.41 -char *
   17.42 -SDL_GetBasePath(void)
   17.43 -{
   17.44 -    image_info info;
   17.45 -    int32 cookie = 0;
   17.46 -
   17.47 -    while (get_next_image_info(0, &cookie, &info) == B_OK) {
   17.48 -        if (info.type == B_APP_IMAGE) {
   17.49 -            break;
   17.50 -        }
   17.51 -    }
   17.52 -
   17.53 -    BEntry entry(info.name, true);
   17.54 -    BPath path;
   17.55 -    status_t rc = entry.GetPath(&path);  /* (path) now has binary's path. */
   17.56 -    SDL_assert(rc == B_OK);
   17.57 -    rc = path.GetParent(&path); /* chop filename, keep directory. */
   17.58 -    SDL_assert(rc == B_OK);
   17.59 -    const char *str = path.Path();
   17.60 -    SDL_assert(str != NULL);
   17.61 -
   17.62 -    const size_t len = SDL_strlen(str);
   17.63 -    char *retval = (char *) SDL_malloc(len + 2);
   17.64 -    if (!retval) {
   17.65 -        SDL_OutOfMemory();
   17.66 -        return NULL;
   17.67 -    }
   17.68 -
   17.69 -    SDL_memcpy(retval, str, len);
   17.70 -    retval[len] = '/';
   17.71 -    retval[len+1] = '\0';
   17.72 -    return retval;
   17.73 -}
   17.74 -
   17.75 -
   17.76 -char *
   17.77 -SDL_GetPrefPath(const char *org, const char *app)
   17.78 -{
   17.79 -    // !!! FIXME: is there a better way to do this?
   17.80 -    const char *home = SDL_getenv("HOME");
   17.81 -    const char *append = "config/settings/";
   17.82 -    const size_t len = SDL_strlen(home) + SDL_strlen(append) + SDL_strlen(org) + SDL_strlen(app) + 3;
   17.83 -    char *retval = (char *) SDL_malloc(len);
   17.84 -    if (!retval) {
   17.85 -        SDL_OutOfMemory();
   17.86 -    } else {
   17.87 -        SDL_snprintf(retval, len, "%s%s%s/%s/", home, append, org, app);
   17.88 -        create_directory(retval, 0700);  // BeOS api: creates missing dirs
   17.89 -    }
   17.90 -
   17.91 -    return retval;
   17.92 -}
   17.93 -
   17.94 -#endif /* SDL_FILESYSTEM_BEOS */
   17.95 -
   17.96 -/* vi: set ts=4 sw=4 expandtab: */
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/src/filesystem/haiku/SDL_sysfilesystem.cc	Thu Nov 14 22:35:28 2013 +0530
    18.3 @@ -0,0 +1,93 @@
    18.4 +/*
    18.5 +  Simple DirectMedia Layer
    18.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    18.7 +
    18.8 +  This software is provided 'as-is', without any express or implied
    18.9 +  warranty.  In no event will the authors be held liable for any damages
   18.10 +  arising from the use of this software.
   18.11 +
   18.12 +  Permission is granted to anyone to use this software for any purpose,
   18.13 +  including commercial applications, and to alter it and redistribute it
   18.14 +  freely, subject to the following restrictions:
   18.15 +
   18.16 +  1. The origin of this software must not be misrepresented; you must not
   18.17 +     claim that you wrote the original software. If you use this software
   18.18 +     in a product, an acknowledgment in the product documentation would be
   18.19 +     appreciated but is not required.
   18.20 +  2. Altered source versions must be plainly marked as such, and must not be
   18.21 +     misrepresented as being the original software.
   18.22 +  3. This notice may not be removed or altered from any source distribution.
   18.23 +*/
   18.24 +#include "SDL_config.h"
   18.25 +
   18.26 +#ifdef SDL_FILESYSTEM_HAIKU
   18.27 +
   18.28 +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
   18.29 +/* System dependent filesystem routines                                */
   18.30 +
   18.31 +#include <os/kernel/image.h>
   18.32 +#include <os/storage/Directory.h>
   18.33 +#include <os/storage/Entry.h>
   18.34 +#include <os/storage/Path.h>
   18.35 +
   18.36 +#include "SDL_error.h"
   18.37 +#include "SDL_stdinc.h"
   18.38 +#include "SDL_assert.h"
   18.39 +#include "SDL_filesystem.h"
   18.40 +
   18.41 +char *
   18.42 +SDL_GetBasePath(void)
   18.43 +{
   18.44 +    image_info info;
   18.45 +    int32 cookie = 0;
   18.46 +
   18.47 +    while (get_next_image_info(0, &cookie, &info) == B_OK) {
   18.48 +        if (info.type == B_APP_IMAGE) {
   18.49 +            break;
   18.50 +        }
   18.51 +    }
   18.52 +
   18.53 +    BEntry entry(info.name, true);
   18.54 +    BPath path;
   18.55 +    status_t rc = entry.GetPath(&path);  /* (path) now has binary's path. */
   18.56 +    SDL_assert(rc == B_OK);
   18.57 +    rc = path.GetParent(&path); /* chop filename, keep directory. */
   18.58 +    SDL_assert(rc == B_OK);
   18.59 +    const char *str = path.Path();
   18.60 +    SDL_assert(str != NULL);
   18.61 +
   18.62 +    const size_t len = SDL_strlen(str);
   18.63 +    char *retval = (char *) SDL_malloc(len + 2);
   18.64 +    if (!retval) {
   18.65 +        SDL_OutOfMemory();
   18.66 +        return NULL;
   18.67 +    }
   18.68 +
   18.69 +    SDL_memcpy(retval, str, len);
   18.70 +    retval[len] = '/';
   18.71 +    retval[len+1] = '\0';
   18.72 +    return retval;
   18.73 +}
   18.74 +
   18.75 +
   18.76 +char *
   18.77 +SDL_GetPrefPath(const char *org, const char *app)
   18.78 +{
   18.79 +    // !!! FIXME: is there a better way to do this?
   18.80 +    const char *home = SDL_getenv("HOME");
   18.81 +    const char *append = "config/settings/";
   18.82 +    const size_t len = SDL_strlen(home) + SDL_strlen(append) + SDL_strlen(org) + SDL_strlen(app) + 3;
   18.83 +    char *retval = (char *) SDL_malloc(len);
   18.84 +    if (!retval) {
   18.85 +        SDL_OutOfMemory();
   18.86 +    } else {
   18.87 +        SDL_snprintf(retval, len, "%s%s%s/%s/", home, append, org, app);
   18.88 +        create_directory(retval, 0700);  // Haiku api: creates missing dirs
   18.89 +    }
   18.90 +
   18.91 +    return retval;
   18.92 +}
   18.93 +
   18.94 +#endif /* SDL_FILESYSTEM_HAIKU */
   18.95 +
   18.96 +/* vi: set ts=4 sw=4 expandtab: */
    19.1 --- a/src/joystick/beos/SDL_bejoystick.cc	Thu Nov 14 22:19:07 2013 +0530
    19.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.3 @@ -1,280 +0,0 @@
    19.4 -/*
    19.5 -  Simple DirectMedia Layer
    19.6 -  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    19.7 -
    19.8 -  This software is provided 'as-is', without any express or implied
    19.9 -  warranty.  In no event will the authors be held liable for any damages
   19.10 -  arising from the use of this software.
   19.11 -
   19.12 -  Permission is granted to anyone to use this software for any purpose,
   19.13 -  including commercial applications, and to alter it and redistribute it
   19.14 -  freely, subject to the following restrictions:
   19.15 -
   19.16 -  1. The origin of this software must not be misrepresented; you must not
   19.17 -     claim that you wrote the original software. If you use this software
   19.18 -     in a product, an acknowledgment in the product documentation would be
   19.19 -     appreciated but is not required.
   19.20 -  2. Altered source versions must be plainly marked as such, and must not be
   19.21 -     misrepresented as being the original software.
   19.22 -  3. This notice may not be removed or altered from any source distribution.
   19.23 -*/
   19.24 -#include "SDL_config.h"
   19.25 -
   19.26 -#ifdef SDL_JOYSTICK_BEOS
   19.27 -
   19.28 -/* This is the system specific header for the SDL joystick API */
   19.29 -
   19.30 -#include <be/support/String.h>
   19.31 -#include <be/device/Joystick.h>
   19.32 -
   19.33 -extern "C"
   19.34 -{
   19.35 -
   19.36 -#include "SDL_joystick.h"
   19.37 -#include "../SDL_sysjoystick.h"
   19.38 -#include "../SDL_joystick_c.h"
   19.39 -
   19.40 -
   19.41 -/* The maximum number of joysticks we'll detect */
   19.42 -#define MAX_JOYSTICKS	16
   19.43 -
   19.44 -/* A list of available joysticks */
   19.45 -    static char *SDL_joyport[MAX_JOYSTICKS];
   19.46 -    static char *SDL_joyname[MAX_JOYSTICKS];
   19.47 -
   19.48 -/* The private structure used to keep track of a joystick */
   19.49 -    struct joystick_hwdata
   19.50 -    {
   19.51 -        BJoystick *stick;
   19.52 -        uint8 *new_hats;
   19.53 -        int16 *new_axes;
   19.54 -    };
   19.55 -
   19.56 -    static int SDL_SYS_numjoysticks = 0;
   19.57 -
   19.58 -/* Function to scan the system for joysticks.
   19.59 - * This function should set SDL_numjoysticks to the number of available
   19.60 - * joysticks.  Joystick 0 should be the system default joystick.
   19.61 - * It should return 0, or -1 on an unrecoverable fatal error.
   19.62 - */
   19.63 -    int SDL_SYS_JoystickInit(void)
   19.64 -    {
   19.65 -        BJoystick joystick;
   19.66 -        int i;
   19.67 -        int32 nports;
   19.68 -        char name[B_OS_NAME_LENGTH];
   19.69 -
   19.70 -        /* Search for attached joysticks */
   19.71 -          nports = joystick.CountDevices();
   19.72 -          SDL_SYS_numjoysticks = 0;
   19.73 -          SDL_memset(SDL_joyport, 0, (sizeof SDL_joyport));
   19.74 -          SDL_memset(SDL_joyname, 0, (sizeof SDL_joyname));
   19.75 -        for (i = 0; (SDL_SYS_numjoysticks < MAX_JOYSTICKS) && (i < nports); ++i)
   19.76 -        {
   19.77 -            if (joystick.GetDeviceName(i, name) == B_OK) {
   19.78 -                if (joystick.Open(name) != B_ERROR) {
   19.79 -                    BString stick_name;
   19.80 -                      joystick.GetControllerName(&stick_name);
   19.81 -                      SDL_joyport[SDL_SYS_numjoysticks] = strdup(name);
   19.82 -                      SDL_joyname[SDL_SYS_numjoysticks] = strdup(stick_name.String());
   19.83 -                      SDL_SYS_numjoysticks++;
   19.84 -                      joystick.Close();
   19.85 -                }
   19.86 -            }
   19.87 -        }
   19.88 -        return (SDL_SYS_numjoysticks);
   19.89 -    }
   19.90 -
   19.91 -    int SDL_SYS_NumJoysticks()
   19.92 -    {
   19.93 -        return SDL_SYS_numjoysticks;
   19.94 -    }
   19.95 -
   19.96 -    void SDL_SYS_JoystickDetect()
   19.97 -    {
   19.98 -    }
   19.99 -
  19.100 -    SDL_bool SDL_SYS_JoystickNeedsPolling()
  19.101 -    {
  19.102 -        return SDL_FALSE;
  19.103 -    }
  19.104 -
  19.105 -/* Function to get the device-dependent name of a joystick */
  19.106 -    const char *SDL_SYS_JoystickNameForDeviceIndex(int device_index)
  19.107 -    {
  19.108 -        return SDL_joyname[device_index];
  19.109 -    }
  19.110 -
  19.111 -/* Function to perform the mapping from device index to the instance id for this index */
  19.112 -    SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
  19.113 -    {
  19.114 -        return device_index;
  19.115 -    }
  19.116 -
  19.117 -/* Function to open a joystick for use.
  19.118 -   The joystick to open is specified by the index field of the joystick.
  19.119 -   This should fill the nbuttons and naxes fields of the joystick structure.
  19.120 -   It returns 0, or -1 if there is an error.
  19.121 - */
  19.122 -    int SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
  19.123 -    {
  19.124 -        BJoystick *stick;
  19.125 -
  19.126 -        /* Create the joystick data structure */
  19.127 -        joystick->instance_id = device_index;
  19.128 -        joystick->hwdata = (struct joystick_hwdata *)
  19.129 -            SDL_malloc(sizeof(*joystick->hwdata));
  19.130 -        if (joystick->hwdata == NULL) {
  19.131 -            return SDL_OutOfMemory();
  19.132 -        }
  19.133 -        SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata));
  19.134 -        stick = new BJoystick;
  19.135 -        joystick->hwdata->stick = stick;
  19.136 -
  19.137 -        /* Open the requested joystick for use */
  19.138 -        if (stick->Open(SDL_joyport[device_index]) == B_ERROR) {
  19.139 -            SDL_SYS_JoystickClose(joystick);
  19.140 -            return SDL_SetError("Unable to open joystick");
  19.141 -        }
  19.142 -
  19.143 -        /* Set the joystick to calibrated mode */
  19.144 -        stick->EnableCalibration();
  19.145 -
  19.146 -        /* Get the number of buttons, hats, and axes on the joystick */
  19.147 -        joystick->nbuttons = stick->CountButtons();
  19.148 -        joystick->naxes = stick->CountAxes();
  19.149 -        joystick->nhats = stick->CountHats();
  19.150 -
  19.151 -        joystick->hwdata->new_axes = (int16 *)
  19.152 -            SDL_malloc(joystick->naxes * sizeof(int16));
  19.153 -        joystick->hwdata->new_hats = (uint8 *)
  19.154 -            SDL_malloc(joystick->nhats * sizeof(uint8));
  19.155 -        if (!joystick->hwdata->new_hats || !joystick->hwdata->new_axes) {
  19.156 -            SDL_SYS_JoystickClose(joystick);
  19.157 -            return SDL_OutOfMemory();
  19.158 -        }
  19.159 -
  19.160 -        /* We're done! */
  19.161 -        return (0);
  19.162 -    }
  19.163 -
  19.164 -/* Function to determine is this joystick is attached to the system right now */
  19.165 -    SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
  19.166 -    {
  19.167 -        return SDL_TRUE;
  19.168 -    }
  19.169 -
  19.170 -/* Function to update the state of a joystick - called as a device poll.
  19.171 - * This function shouldn't update the joystick structure directly,
  19.172 - * but instead should call SDL_PrivateJoystick*() to deliver events
  19.173 - * and update joystick device state.
  19.174 - */
  19.175 -    void SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
  19.176 -    {
  19.177 -        static const Uint8 hat_map[9] = {
  19.178 -            SDL_HAT_CENTERED,
  19.179 -            SDL_HAT_UP,
  19.180 -            SDL_HAT_RIGHTUP,
  19.181 -            SDL_HAT_RIGHT,
  19.182 -            SDL_HAT_RIGHTDOWN,
  19.183 -            SDL_HAT_DOWN,
  19.184 -            SDL_HAT_LEFTDOWN,
  19.185 -            SDL_HAT_LEFT,
  19.186 -            SDL_HAT_LEFTUP
  19.187 -        };
  19.188 -        const int JITTER = (32768 / 10);        /* 10% jitter threshold (ok?) */
  19.189 -
  19.190 -        BJoystick *stick;
  19.191 -        int i, change;
  19.192 -        int16 *axes;
  19.193 -        uint8 *hats;
  19.194 -        uint32 buttons;
  19.195 -
  19.196 -        /* Set up data pointers */
  19.197 -        stick = joystick->hwdata->stick;
  19.198 -        axes = joystick->hwdata->new_axes;
  19.199 -        hats = joystick->hwdata->new_hats;
  19.200 -
  19.201 -        /* Get the new joystick state */
  19.202 -        stick->Update();
  19.203 -        stick->GetAxisValues(axes);
  19.204 -        stick->GetHatValues(hats);
  19.205 -        buttons = stick->ButtonValues();
  19.206 -
  19.207 -        /* Generate axis motion events */
  19.208 -        for (i = 0; i < joystick->naxes; ++i) {
  19.209 -            change = ((int32) axes[i] - joystick->axes[i]);
  19.210 -            if ((change > JITTER) || (change < -JITTER)) {
  19.211 -                SDL_PrivateJoystickAxis(joystick, i, axes[i]);
  19.212 -            }
  19.213 -        }
  19.214 -
  19.215 -        /* Generate hat change events */
  19.216 -        for (i = 0; i < joystick->nhats; ++i) {
  19.217 -            if (hats[i] != joystick->hats[i]) {
  19.218 -                SDL_PrivateJoystickHat(joystick, i, hat_map[hats[i]]);
  19.219 -            }
  19.220 -        }
  19.221 -
  19.222 -        /* Generate button events */
  19.223 -        for (i = 0; i < joystick->nbuttons; ++i) {
  19.224 -            if ((buttons & 0x01) != joystick->buttons[i]) {
  19.225 -                SDL_PrivateJoystickButton(joystick, i, (buttons & 0x01));
  19.226 -            }
  19.227 -            buttons >>= 1;
  19.228 -        }
  19.229 -    }
  19.230 -
  19.231 -/* Function to close a joystick after use */
  19.232 -    void SDL_SYS_JoystickClose(SDL_Joystick * joystick)
  19.233 -    {
  19.234 -        if (joystick->hwdata) {
  19.235 -            joystick->hwdata->stick->Close();
  19.236 -            delete joystick->hwdata->stick;
  19.237 -            SDL_free(joystick->hwdata->new_hats);
  19.238 -            SDL_free(joystick->hwdata->new_axes);
  19.239 -            SDL_free(joystick->hwdata);
  19.240 -            joystick->hwdata = NULL;
  19.241 -        }
  19.242 -    }
  19.243 -
  19.244 -/* Function to perform any system-specific joystick related cleanup */
  19.245 -    void SDL_SYS_JoystickQuit(void)
  19.246 -    {
  19.247 -        int i;
  19.248 -
  19.249 -        for (i = 0; SDL_joyport[i]; ++i) {
  19.250 -            SDL_free(SDL_joyport[i]);
  19.251 -        }
  19.252 -        SDL_joyport[0] = NULL;
  19.253 -
  19.254 -        for (i = 0; SDL_joyname[i]; ++i) {
  19.255 -            SDL_free(SDL_joyname[i]);
  19.256 -        }
  19.257 -        SDL_joyname[0] = NULL;
  19.258 -    }
  19.259 -
  19.260 -    SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
  19.261 -    {
  19.262 -        SDL_JoystickGUID guid;
  19.263 -        /* the GUID is just the first 16 chars of the name for now */
  19.264 -        const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index );
  19.265 -        SDL_zero( guid );
  19.266 -        SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
  19.267 -        return guid;
  19.268 -    }
  19.269 -
  19.270 -    SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
  19.271 -    {
  19.272 -        SDL_JoystickGUID guid;
  19.273 -        /* the GUID is just the first 16 chars of the name for now */
  19.274 -        const char *name = joystick->name;
  19.275 -        SDL_zero( guid );
  19.276 -        SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
  19.277 -        return guid;
  19.278 -    }
  19.279 -
  19.280 -};                              // extern "C"
  19.281 -
  19.282 -#endif /* SDL_JOYSTICK_BEOS */
  19.283 -/* vi: set ts=4 sw=4 expandtab: */
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/src/joystick/haiku/SDL_haikujoystick.cc	Thu Nov 14 22:35:28 2013 +0530
    20.3 @@ -0,0 +1,281 @@
    20.4 +/*
    20.5 +  Simple DirectMedia Layer
    20.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    20.7 +
    20.8 +  This software is provided 'as-is', without any express or implied
    20.9 +  warranty.  In no event will the authors be held liable for any damages
   20.10 +  arising from the use of this software.
   20.11 +
   20.12 +  Permission is granted to anyone to use this software for any purpose,
   20.13 +  including commercial applications, and to alter it and redistribute it
   20.14 +  freely, subject to the following restrictions:
   20.15 +
   20.16 +  1. The origin of this software must not be misrepresented; you must not
   20.17 +     claim that you wrote the original software. If you use this software
   20.18 +     in a product, an acknowledgment in the product documentation would be
   20.19 +     appreciated but is not required.
   20.20 +  2. Altered source versions must be plainly marked as such, and must not be
   20.21 +     misrepresented as being the original software.
   20.22 +  3. This notice may not be removed or altered from any source distribution.
   20.23 +*/
   20.24 +#include "SDL_config.h"
   20.25 +
   20.26 +#ifdef SDL_JOYSTICK_HAIKU
   20.27 +
   20.28 +/* This is the system specific header for the SDL joystick API */
   20.29 +
   20.30 +#include <os/support/String.h>
   20.31 +#include <os/device/Joystick.h>
   20.32 +
   20.33 +extern "C"
   20.34 +{
   20.35 +
   20.36 +#include "SDL_joystick.h"
   20.37 +#include "../SDL_sysjoystick.h"
   20.38 +#include "../SDL_joystick_c.h"
   20.39 +
   20.40 +
   20.41 +/* The maximum number of joysticks we'll detect */
   20.42 +#define MAX_JOYSTICKS	16
   20.43 +
   20.44 +/* A list of available joysticks */
   20.45 +    static char *SDL_joyport[MAX_JOYSTICKS];
   20.46 +    static char *SDL_joyname[MAX_JOYSTICKS];
   20.47 +
   20.48 +/* The private structure used to keep track of a joystick */
   20.49 +    struct joystick_hwdata
   20.50 +    {
   20.51 +        BJoystick *stick;
   20.52 +        uint8 *new_hats;
   20.53 +        int16 *new_axes;
   20.54 +    };
   20.55 +
   20.56 +    static int SDL_SYS_numjoysticks = 0;
   20.57 +
   20.58 +/* Function to scan the system for joysticks.
   20.59 + * This function should set SDL_numjoysticks to the number of available
   20.60 + * joysticks.  Joystick 0 should be the system default joystick.
   20.61 + * It should return 0, or -1 on an unrecoverable fatal error.
   20.62 + */
   20.63 +    int SDL_SYS_JoystickInit(void)
   20.64 +    {
   20.65 +        BJoystick joystick;
   20.66 +        int i;
   20.67 +        int32 nports;
   20.68 +        char name[B_OS_NAME_LENGTH];
   20.69 +
   20.70 +        /* Search for attached joysticks */
   20.71 +          nports = joystick.CountDevices();
   20.72 +          SDL_SYS_numjoysticks = 0;
   20.73 +          SDL_memset(SDL_joyport, 0, (sizeof SDL_joyport));
   20.74 +          SDL_memset(SDL_joyname, 0, (sizeof SDL_joyname));
   20.75 +        for (i = 0; (SDL_SYS_numjoysticks < MAX_JOYSTICKS) && (i < nports); ++i)
   20.76 +        {
   20.77 +            if (joystick.GetDeviceName(i, name) == B_OK) {
   20.78 +                if (joystick.Open(name) != B_ERROR) {
   20.79 +                    BString stick_name;
   20.80 +                      joystick.GetControllerName(&stick_name);
   20.81 +                      SDL_joyport[SDL_SYS_numjoysticks] = strdup(name);
   20.82 +                      SDL_joyname[SDL_SYS_numjoysticks] = strdup(stick_name.String());
   20.83 +                      SDL_SYS_numjoysticks++;
   20.84 +                      joystick.Close();
   20.85 +                }
   20.86 +            }
   20.87 +        }
   20.88 +        return (SDL_SYS_numjoysticks);
   20.89 +    }
   20.90 +
   20.91 +    int SDL_SYS_NumJoysticks()
   20.92 +    {
   20.93 +        return SDL_SYS_numjoysticks;
   20.94 +    }
   20.95 +
   20.96 +    void SDL_SYS_JoystickDetect()
   20.97 +    {
   20.98 +    }
   20.99 +
  20.100 +    SDL_bool SDL_SYS_JoystickNeedsPolling()
  20.101 +    {
  20.102 +        return SDL_FALSE;
  20.103 +    }
  20.104 +
  20.105 +/* Function to get the device-dependent name of a joystick */
  20.106 +    const char *SDL_SYS_JoystickNameForDeviceIndex(int device_index)
  20.107 +    {
  20.108 +        return SDL_joyname[device_index];
  20.109 +    }
  20.110 +
  20.111 +/* Function to perform the mapping from device index to the instance id for this index */
  20.112 +    SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
  20.113 +    {
  20.114 +        return device_index;
  20.115 +    }
  20.116 +
  20.117 +/* Function to open a joystick for use.
  20.118 +   The joystick to open is specified by the index field of the joystick.
  20.119 +   This should fill the nbuttons and naxes fields of the joystick structure.
  20.120 +   It returns 0, or -1 if there is an error.
  20.121 + */
  20.122 +    int SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
  20.123 +    {
  20.124 +        BJoystick *stick;
  20.125 +
  20.126 +        /* Create the joystick data structure */
  20.127 +        joystick->instance_id = device_index;
  20.128 +        joystick->hwdata = (struct joystick_hwdata *)
  20.129 +            SDL_malloc(sizeof(*joystick->hwdata));
  20.130 +        if (joystick->hwdata == NULL) {
  20.131 +            return SDL_OutOfMemory();
  20.132 +        }
  20.133 +        SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata));
  20.134 +        stick = new BJoystick;
  20.135 +        joystick->hwdata->stick = stick;
  20.136 +
  20.137 +        /* Open the requested joystick for use */
  20.138 +        if (stick->Open(SDL_joyport[device_index]) == B_ERROR) {
  20.139 +            SDL_SYS_JoystickClose(joystick);
  20.140 +            return SDL_SetError("Unable to open joystick");
  20.141 +        }
  20.142 +
  20.143 +        /* Set the joystick to calibrated mode */
  20.144 +        stick->EnableCalibration();
  20.145 +
  20.146 +        /* Get the number of buttons, hats, and axes on the joystick */
  20.147 +        joystick->nbuttons = stick->CountButtons();
  20.148 +        joystick->naxes = stick->CountAxes();
  20.149 +        joystick->nhats = stick->CountHats();
  20.150 +
  20.151 +        joystick->hwdata->new_axes = (int16 *)
  20.152 +            SDL_malloc(joystick->naxes * sizeof(int16));
  20.153 +        joystick->hwdata->new_hats = (uint8 *)
  20.154 +            SDL_malloc(joystick->nhats * sizeof(uint8));
  20.155 +        if (!joystick->hwdata->new_hats || !joystick->hwdata->new_axes) {
  20.156 +            SDL_SYS_JoystickClose(joystick);
  20.157 +            return SDL_OutOfMemory();
  20.158 +        }
  20.159 +
  20.160 +        /* We're done! */
  20.161 +        return (0);
  20.162 +    }
  20.163 +
  20.164 +/* Function to determine is this joystick is attached to the system right now */
  20.165 +    SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
  20.166 +    {
  20.167 +        return SDL_TRUE;
  20.168 +    }
  20.169 +
  20.170 +/* Function to update the state of a joystick - called as a device poll.
  20.171 + * This function shouldn't update the joystick structure directly,
  20.172 + * but instead should call SDL_PrivateJoystick*() to deliver events
  20.173 + * and update joystick device state.
  20.174 + */
  20.175 +    void SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
  20.176 +    {
  20.177 +        static const Uint8 hat_map[9] = {
  20.178 +            SDL_HAT_CENTERED,
  20.179 +            SDL_HAT_UP,
  20.180 +            SDL_HAT_RIGHTUP,
  20.181 +            SDL_HAT_RIGHT,
  20.182 +            SDL_HAT_RIGHTDOWN,
  20.183 +            SDL_HAT_DOWN,
  20.184 +            SDL_HAT_LEFTDOWN,
  20.185 +            SDL_HAT_LEFT,
  20.186 +            SDL_HAT_LEFTUP
  20.187 +        };
  20.188 +        const int JITTER = (32768 / 10);        /* 10% jitter threshold (ok?) */
  20.189 +
  20.190 +        BJoystick *stick;
  20.191 +        int i, change;
  20.192 +        int16 *axes;
  20.193 +        uint8 *hats;
  20.194 +        uint32 buttons;
  20.195 +
  20.196 +        /* Set up data pointers */
  20.197 +        stick = joystick->hwdata->stick;
  20.198 +        axes = joystick->hwdata->new_axes;
  20.199 +        hats = joystick->hwdata->new_hats;
  20.200 +
  20.201 +        /* Get the new joystick state */
  20.202 +        stick->Update();
  20.203 +        stick->GetAxisValues(axes);
  20.204 +        stick->GetHatValues(hats);
  20.205 +        buttons = stick->ButtonValues();
  20.206 +
  20.207 +        /* Generate axis motion events */
  20.208 +        for (i = 0; i < joystick->naxes; ++i) {
  20.209 +            change = ((int32) axes[i] - joystick->axes[i]);
  20.210 +            if ((change > JITTER) || (change < -JITTER)) {
  20.211 +                SDL_PrivateJoystickAxis(joystick, i, axes[i]);
  20.212 +            }
  20.213 +        }
  20.214 +
  20.215 +        /* Generate hat change events */
  20.216 +        for (i = 0; i < joystick->nhats; ++i) {
  20.217 +            if (hats[i] != joystick->hats[i]) {
  20.218 +                SDL_PrivateJoystickHat(joystick, i, hat_map[hats[i]]);
  20.219 +            }
  20.220 +        }
  20.221 +
  20.222 +        /* Generate button events */
  20.223 +        for (i = 0; i < joystick->nbuttons; ++i) {
  20.224 +            if ((buttons & 0x01) != joystick->buttons[i]) {
  20.225 +                SDL_PrivateJoystickButton(joystick, i, (buttons & 0x01));
  20.226 +            }
  20.227 +            buttons >>= 1;
  20.228 +        }
  20.229 +    }
  20.230 +
  20.231 +/* Function to close a joystick after use */
  20.232 +    void SDL_SYS_JoystickClose(SDL_Joystick * joystick)
  20.233 +    {
  20.234 +        if (joystick->hwdata) {
  20.235 +            joystick->hwdata->stick->Close();
  20.236 +            delete joystick->hwdata->stick;
  20.237 +            SDL_free(joystick->hwdata->new_hats);
  20.238 +            SDL_free(joystick->hwdata->new_axes);
  20.239 +            SDL_free(joystick->hwdata);
  20.240 +            joystick->hwdata = NULL;
  20.241 +        }
  20.242 +    }
  20.243 +
  20.244 +/* Function to perform any system-specific joystick related cleanup */
  20.245 +    void SDL_SYS_JoystickQuit(void)
  20.246 +    {
  20.247 +        int i;
  20.248 +
  20.249 +        for (i = 0; SDL_joyport[i]; ++i) {
  20.250 +            SDL_free(SDL_joyport[i]);
  20.251 +        }
  20.252 +        SDL_joyport[0] = NULL;
  20.253 +
  20.254 +        for (i = 0; SDL_joyname[i]; ++i) {
  20.255 +            SDL_free(SDL_joyname[i]);
  20.256 +        }
  20.257 +        SDL_joyname[0] = NULL;
  20.258 +    }
  20.259 +
  20.260 +    SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
  20.261 +    {
  20.262 +        SDL_JoystickGUID guid;
  20.263 +        /* the GUID is just the first 16 chars of the name for now */
  20.264 +        const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index );
  20.265 +        SDL_zero( guid );
  20.266 +        SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
  20.267 +        return guid;
  20.268 +    }
  20.269 +
  20.270 +    SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
  20.271 +    {
  20.272 +        SDL_JoystickGUID guid;
  20.273 +        /* the GUID is just the first 16 chars of the name for now */
  20.274 +        const char *name = joystick->name;
  20.275 +        SDL_zero( guid );
  20.276 +        SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
  20.277 +        return guid;
  20.278 +    }
  20.279 +
  20.280 +};                              // extern "C"
  20.281 +
  20.282 +#endif /* SDL_JOYSTICK_HAIKU */
  20.283 +
  20.284 +/* vi: set ts=4 sw=4 expandtab: */
    21.1 --- a/src/loadso/beos/SDL_sysloadso.c	Thu Nov 14 22:19:07 2013 +0530
    21.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.3 @@ -1,71 +0,0 @@
    21.4 -/*
    21.5 -  Simple DirectMedia Layer
    21.6 -  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    21.7 -
    21.8 -  This software is provided 'as-is', without any express or implied
    21.9 -  warranty.  In no event will the authors be held liable for any damages
   21.10 -  arising from the use of this software.
   21.11 -
   21.12 -  Permission is granted to anyone to use this software for any purpose,
   21.13 -  including commercial applications, and to alter it and redistribute it
   21.14 -  freely, subject to the following restrictions:
   21.15 -
   21.16 -  1. The origin of this software must not be misrepresented; you must not
   21.17 -     claim that you wrote the original software. If you use this software
   21.18 -     in a product, an acknowledgment in the product documentation would be
   21.19 -     appreciated but is not required.
   21.20 -  2. Altered source versions must be plainly marked as such, and must not be
   21.21 -     misrepresented as being the original software.
   21.22 -  3. This notice may not be removed or altered from any source distribution.
   21.23 -*/
   21.24 -#include "SDL_config.h"
   21.25 -
   21.26 -#ifdef SDL_LOADSO_BEOS
   21.27 -
   21.28 -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
   21.29 -/* System dependent library loading routines                           */
   21.30 -
   21.31 -#include <stdio.h>
   21.32 -#include <be/kernel/image.h>
   21.33 -
   21.34 -#include "SDL_loadso.h"
   21.35 -
   21.36 -void *
   21.37 -SDL_LoadObject(const char *sofile)
   21.38 -{
   21.39 -    void *handle = NULL;
   21.40 -    image_id library_id = load_add_on(sofile);
   21.41 -    if (library_id < 0) {
   21.42 -        SDL_SetError(strerror((int) library_id));
   21.43 -    } else {
   21.44 -        handle = (void *) (library_id);
   21.45 -    }
   21.46 -    return (handle);
   21.47 -}
   21.48 -
   21.49 -void *
   21.50 -SDL_LoadFunction(void *handle, const char *name)
   21.51 -{
   21.52 -    void *sym = NULL;
   21.53 -    image_id library_id = (image_id) handle;
   21.54 -    status_t rc =
   21.55 -        get_image_symbol(library_id, name, B_SYMBOL_TYPE_TEXT, &sym);
   21.56 -    if (rc != B_NO_ERROR) {
   21.57 -        SDL_SetError(strerror(rc));
   21.58 -    }
   21.59 -    return (sym);
   21.60 -}
   21.61 -
   21.62 -void
   21.63 -SDL_UnloadObject(void *handle)
   21.64 -{
   21.65 -    image_id library_id;
   21.66 -    if (handle != NULL) {
   21.67 -        library_id = (image_id) handle;
   21.68 -        unload_add_on(library_id);
   21.69 -    }
   21.70 -}
   21.71 -
   21.72 -#endif /* SDL_LOADSO_BEOS */
   21.73 -
   21.74 -/* vi: set ts=4 sw=4 expandtab: */
    22.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.2 +++ b/src/loadso/haiku/SDL_sysloadso.c	Thu Nov 14 22:35:28 2013 +0530
    22.3 @@ -0,0 +1,71 @@
    22.4 +/*
    22.5 +  Simple DirectMedia Layer
    22.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    22.7 +
    22.8 +  This software is provided 'as-is', without any express or implied
    22.9 +  warranty.  In no event will the authors be held liable for any damages
   22.10 +  arising from the use of this software.
   22.11 +
   22.12 +  Permission is granted to anyone to use this software for any purpose,
   22.13 +  including commercial applications, and to alter it and redistribute it
   22.14 +  freely, subject to the following restrictions:
   22.15 +
   22.16 +  1. The origin of this software must not be misrepresented; you must not
   22.17 +     claim that you wrote the original software. If you use this software
   22.18 +     in a product, an acknowledgment in the product documentation would be
   22.19 +     appreciated but is not required.
   22.20 +  2. Altered source versions must be plainly marked as such, and must not be
   22.21 +     misrepresented as being the original software.
   22.22 +  3. This notice may not be removed or altered from any source distribution.
   22.23 +*/
   22.24 +#include "SDL_config.h"
   22.25 +
   22.26 +#ifdef SDL_LOADSO_HAIKU
   22.27 +
   22.28 +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
   22.29 +/* System dependent library loading routines                           */
   22.30 +
   22.31 +#include <stdio.h>
   22.32 +#include <os/kernel/image.h>
   22.33 +
   22.34 +#include "SDL_loadso.h"
   22.35 +
   22.36 +void *
   22.37 +SDL_LoadObject(const char *sofile)
   22.38 +{
   22.39 +    void *handle = NULL;
   22.40 +    image_id library_id = load_add_on(sofile);
   22.41 +    if (library_id < 0) {
   22.42 +        SDL_SetError(strerror((int) library_id));
   22.43 +    } else {
   22.44 +        handle = (void *) (library_id);
   22.45 +    }
   22.46 +    return (handle);
   22.47 +}
   22.48 +
   22.49 +void *
   22.50 +SDL_LoadFunction(void *handle, const char *name)
   22.51 +{
   22.52 +    void *sym = NULL;
   22.53 +    image_id library_id = (image_id) handle;
   22.54 +    status_t rc =
   22.55 +        get_image_symbol(library_id, name, B_SYMBOL_TYPE_TEXT, &sym);
   22.56 +    if (rc != B_NO_ERROR) {
   22.57 +        SDL_SetError(strerror(rc));
   22.58 +    }
   22.59 +    return (sym);
   22.60 +}
   22.61 +
   22.62 +void
   22.63 +SDL_UnloadObject(void *handle)
   22.64 +{
   22.65 +    image_id library_id;
   22.66 +    if (handle != NULL) {
   22.67 +        library_id = (image_id) handle;
   22.68 +        unload_add_on(library_id);
   22.69 +    }
   22.70 +}
   22.71 +
   22.72 +#endif /* SDL_LOADSO_HAIKU */
   22.73 +
   22.74 +/* vi: set ts=4 sw=4 expandtab: */
    23.1 --- a/src/main/beos/SDL_BApp.h	Thu Nov 14 22:19:07 2013 +0530
    23.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.3 @@ -1,380 +0,0 @@
    23.4 -/*
    23.5 -  Simple DirectMedia Layer
    23.6 -  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    23.7 -
    23.8 -  This software is provided 'as-is', without any express or implied
    23.9 -  warranty.  In no event will the authors be held liable for any damages
   23.10 -  arising from the use of this software.
   23.11 -
   23.12 -  Permission is granted to anyone to use this software for any purpose,
   23.13 -  including commercial applications, and to alter it and redistribute it
   23.14 -  freely, subject to the following restrictions:
   23.15 -
   23.16 -  1. The origin of this software must not be misrepresented; you must not
   23.17 -     claim that you wrote the original software. If you use this software
   23.18 -     in a product, an acknowledgment in the product documentation would be
   23.19 -     appreciated but is not required.
   23.20 -  2. Altered source versions must be plainly marked as such, and must not be
   23.21 -     misrepresented as being the original software.
   23.22 -  3. This notice may not be removed or altered from any source distribution.
   23.23 -*/
   23.24 -#ifndef SDL_BAPP_H
   23.25 -#define SDL_BAPP_H
   23.26 -
   23.27 -#include <InterfaceKit.h>
   23.28 -#include <OpenGLKit.h>
   23.29 -
   23.30 -#include "../../video/bwindow/SDL_bkeyboard.h"
   23.31 -
   23.32 -
   23.33 -#ifdef __cplusplus
   23.34 -extern "C" {
   23.35 -#endif
   23.36 -
   23.37 -#include "SDL_config.h"
   23.38 -
   23.39 -#include "SDL_video.h"
   23.40 -
   23.41 -/* Local includes */
   23.42 -#include "../../events/SDL_events_c.h"
   23.43 -#include "../../video/bwindow/SDL_bkeyboard.h"
   23.44 -#include "../../video/bwindow/SDL_bframebuffer.h"
   23.45 -
   23.46 -#ifdef __cplusplus
   23.47 -}
   23.48 -#endif
   23.49 -
   23.50 -#include <vector>
   23.51 -
   23.52 -
   23.53 -
   23.54 -
   23.55 -/* Forward declarations */
   23.56 -class SDL_BWin;
   23.57 -
   23.58 -/* Message constants */
   23.59 -enum ToSDL {
   23.60 -    /* Intercepted by BWindow on its way to BView */
   23.61 -    BAPP_MOUSE_MOVED,
   23.62 -    BAPP_MOUSE_BUTTON,
   23.63 -    BAPP_MOUSE_WHEEL,
   23.64 -    BAPP_KEY,
   23.65 -    BAPP_REPAINT,           /* from _UPDATE_ */
   23.66 -    /* From BWindow */
   23.67 -    BAPP_MAXIMIZE,          /* from B_ZOOM */
   23.68 -    BAPP_MINIMIZE,
   23.69 -    BAPP_RESTORE,           /* TODO: IMPLEMENT! */
   23.70 -    BAPP_SHOW,
   23.71 -    BAPP_HIDE,
   23.72 -    BAPP_MOUSE_FOCUS,       /* caused by MOUSE_MOVE */
   23.73 -    BAPP_KEYBOARD_FOCUS,    /* from WINDOW_ACTIVATED */
   23.74 -    BAPP_WINDOW_CLOSE_REQUESTED,
   23.75 -    BAPP_WINDOW_MOVED,
   23.76 -    BAPP_WINDOW_RESIZED,
   23.77 -    BAPP_SCREEN_CHANGED
   23.78 -};
   23.79 -
   23.80 -
   23.81 -
   23.82 -/* Create a descendant of BApplication */
   23.83 -class SDL_BApp : public BApplication {
   23.84 -public:
   23.85 -    SDL_BApp(const char* signature) :
   23.86 -        BApplication(signature) {
   23.87 -        _current_context = NULL;
   23.88 -    }
   23.89 -
   23.90 -
   23.91 -    virtual ~SDL_BApp() {
   23.92 -    }
   23.93 -
   23.94 -
   23.95 -
   23.96 -        /* Event-handling functions */
   23.97 -    virtual void MessageReceived(BMessage* message) {
   23.98 -        /* Sort out SDL-related messages */
   23.99 -        switch ( message->what ) {
  23.100 -        case BAPP_MOUSE_MOVED:
  23.101 -            _HandleMouseMove(message);
  23.102 -            break;
  23.103 -
  23.104 -        case BAPP_MOUSE_BUTTON:
  23.105 -            _HandleMouseButton(message);
  23.106 -            break;
  23.107 -
  23.108 -        case BAPP_MOUSE_WHEEL:
  23.109 -            _HandleMouseWheel(message);
  23.110 -            break;
  23.111 -
  23.112 -        case BAPP_KEY:
  23.113 -            _HandleKey(message);
  23.114 -            break;
  23.115 -
  23.116 -        case BAPP_REPAINT:
  23.117 -            _HandleBasicWindowEvent(message, SDL_WINDOWEVENT_EXPOSED);
  23.118 -            break;
  23.119 -
  23.120 -        case BAPP_MAXIMIZE:
  23.121 -            _HandleBasicWindowEvent(message, SDL_WINDOWEVENT_MAXIMIZED);
  23.122 -            break;
  23.123 -
  23.124 -        case BAPP_MINIMIZE:
  23.125 -            _HandleBasicWindowEvent(message, SDL_WINDOWEVENT_MINIMIZED);
  23.126 -            break;
  23.127 -
  23.128 -        case BAPP_SHOW:
  23.129 -            _HandleBasicWindowEvent(message, SDL_WINDOWEVENT_SHOWN);
  23.130 -            break;
  23.131 -
  23.132 -        case BAPP_HIDE:
  23.133 -            _HandleBasicWindowEvent(message, SDL_WINDOWEVENT_HIDDEN);
  23.134 -            break;
  23.135 -
  23.136 -        case BAPP_MOUSE_FOCUS:
  23.137 -            _HandleMouseFocus(message);
  23.138 -            break;
  23.139 -
  23.140 -        case BAPP_KEYBOARD_FOCUS:
  23.141 -            _HandleKeyboardFocus(message);
  23.142 -            break;
  23.143 -
  23.144 -        case BAPP_WINDOW_CLOSE_REQUESTED:
  23.145 -            _HandleBasicWindowEvent(message, SDL_WINDOWEVENT_CLOSE);
  23.146 -            break;
  23.147 -
  23.148 -        case BAPP_WINDOW_MOVED:
  23.149 -            _HandleWindowMoved(message);
  23.150 -            break;
  23.151 -
  23.152 -        case BAPP_WINDOW_RESIZED:
  23.153 -            _HandleWindowResized(message);
  23.154 -            break;
  23.155 -
  23.156 -        case BAPP_SCREEN_CHANGED:
  23.157 -            /* TODO: Handle screen resize or workspace change */
  23.158 -            break;
  23.159 -
  23.160 -        default:
  23.161 -           BApplication::MessageReceived(message);
  23.162 -           break;
  23.163 -        }
  23.164 -    }
  23.165 -
  23.166 -    /* Window creation/destruction methods */
  23.167 -    int32 GetID(SDL_Window *win) {
  23.168 -        int32 i;
  23.169 -        for(i = 0; i < _GetNumWindowSlots(); ++i) {
  23.170 -            if( GetSDLWindow(i) == NULL ) {
  23.171 -                _SetSDLWindow(win, i);
  23.172 -                return i;
  23.173 -            }
  23.174 -        }
  23.175 -
  23.176 -        /* Expand the vector if all slots are full */
  23.177 -        if( i == _GetNumWindowSlots() ) {
  23.178 -            _PushBackWindow(win);
  23.179 -            return i;
  23.180 -        }
  23.181 -
  23.182 -        /* TODO: error handling */
  23.183 -        return 0;
  23.184 -    }
  23.185 -
  23.186 -    /* FIXME: Bad coding practice, but I can't include SDL_BWin.h here.  Is
  23.187 -       there another way to do this? */
  23.188 -    void ClearID(SDL_BWin *bwin); /* Defined in SDL_BeApp.cc */
  23.189 -
  23.190 -
  23.191 -    SDL_Window *GetSDLWindow(int32 winID) {
  23.192 -        return _window_map[winID];
  23.193 -    }
  23.194 -
  23.195 -    void SetCurrentContext(BGLView *newContext) {
  23.196 -        if(_current_context)
  23.197 -            _current_context->UnlockGL();
  23.198 -        _current_context = newContext;
  23.199 -        _current_context->LockGL();
  23.200 -    }
  23.201 -private:
  23.202 -    /* Event management */
  23.203 -    void _HandleBasicWindowEvent(BMessage *msg, int32 sdlEventType) {
  23.204 -        SDL_Window *win;
  23.205 -        int32 winID;
  23.206 -        if(
  23.207 -            !_GetWinID(msg, &winID)
  23.208 -        ) {
  23.209 -            return;
  23.210 -        }
  23.211 -        win = GetSDLWindow(winID);
  23.212 -        SDL_SendWindowEvent(win, sdlEventType, 0, 0);
  23.213 -    }
  23.214 -
  23.215 -    void _HandleMouseMove(BMessage *msg) {
  23.216 -        SDL_Window *win;
  23.217 -        int32 winID;
  23.218 -        int32 x = 0, y = 0;
  23.219 -        if(
  23.220 -            !_GetWinID(msg, &winID) ||
  23.221 -            msg->FindInt32("x", &x) != B_OK || /* x movement */
  23.222 -            msg->FindInt32("y", &y) != B_OK    /* y movement */
  23.223 -        ) {
  23.224 -            return;
  23.225 -        }
  23.226 -        win = GetSDLWindow(winID);
  23.227 -        SDL_SendMouseMotion(win, 0, 0, x, y);
  23.228 -
  23.229 -        /* Tell the application that the mouse passed over, redraw needed */
  23.230 -        BE_UpdateWindowFramebuffer(NULL,win,NULL,-1);
  23.231 -    }
  23.232 -
  23.233 -    void _HandleMouseButton(BMessage *msg) {
  23.234 -        SDL_Window *win;
  23.235 -        int32 winID;
  23.236 -        int32 button, state;    /* left/middle/right, pressed/released */
  23.237 -        if(
  23.238 -            !_GetWinID(msg, &winID) ||
  23.239 -            msg->FindInt32("button-id", &button) != B_OK ||
  23.240 -            msg->FindInt32("button-state", &state) != B_OK
  23.241 -        ) {
  23.242 -            return;
  23.243 -        }
  23.244 -        win = GetSDLWindow(winID);
  23.245 -        SDL_SendMouseButton(win, 0, state, button);
  23.246 -    }
  23.247 -
  23.248 -    void _HandleMouseWheel(BMessage *msg) {
  23.249 -        SDL_Window *win;
  23.250 -        int32 winID;
  23.251 -        int32 xTicks, yTicks;
  23.252 -        if(
  23.253 -            !_GetWinID(msg, &winID) ||
  23.254 -            msg->FindInt32("xticks", &xTicks) != B_OK ||
  23.255 -            msg->FindInt32("yticks", &yTicks) != B_OK
  23.256 -        ) {
  23.257 -            return;
  23.258 -        }
  23.259 -        win = GetSDLWindow(winID);
  23.260 -        SDL_SendMouseWheel(win, 0, xTicks, yTicks);
  23.261 -    }
  23.262 -
  23.263 -    void _HandleKey(BMessage *msg) {
  23.264 -        int32 scancode, state;  /* scancode, pressed/released */
  23.265 -        if(
  23.266 -            msg->FindInt32("key-state", &state) != B_OK ||
  23.267 -            msg->FindInt32("key-scancode", &scancode) != B_OK
  23.268 -        ) {
  23.269 -            return;
  23.270 -        }
  23.271 -
  23.272 -        /* Make sure this isn't a repeated event (key pressed and held) */
  23.273 -        if(state == SDL_PRESSED && BE_GetKeyState(scancode) == SDL_PRESSED) {
  23.274 -            return;
  23.275 -        }
  23.276 -        BE_SetKeyState(scancode, state);
  23.277 -        SDL_SendKeyboardKey(state, BE_GetScancodeFromBeKey(scancode));
  23.278 -    }
  23.279 -
  23.280 -    void _HandleMouseFocus(BMessage *msg) {
  23.281 -        SDL_Window *win;
  23.282 -        int32 winID;
  23.283 -        bool bSetFocus; /* If false, lose focus */
  23.284 -        if(
  23.285 -            !_GetWinID(msg, &winID) ||
  23.286 -            msg->FindBool("focusGained", &bSetFocus) != B_OK
  23.287 -        ) {
  23.288 -            return;
  23.289 -        }
  23.290 -        win = GetSDLWindow(winID);
  23.291 -        if(bSetFocus) {
  23.292 -            SDL_SetMouseFocus(win);
  23.293 -        } else if(SDL_GetMouseFocus() == win) {
  23.294 -            /* Only lose all focus if this window was the current focus */
  23.295 -            SDL_SetMouseFocus(NULL);
  23.296 -        }
  23.297 -    }
  23.298 -
  23.299 -    void _HandleKeyboardFocus(BMessage *msg) {
  23.300 -        SDL_Window *win;
  23.301 -        int32 winID;
  23.302 -        bool bSetFocus; /* If false, lose focus */
  23.303 -        if(
  23.304 -            !_GetWinID(msg, &winID) ||
  23.305 -            msg->FindBool("focusGained", &bSetFocus) != B_OK
  23.306 -        ) {
  23.307 -            return;
  23.308 -        }
  23.309 -        win = GetSDLWindow(winID);
  23.310 -        if(bSetFocus) {
  23.311 -            SDL_SetKeyboardFocus(win);
  23.312 -        } else if(SDL_GetKeyboardFocus() == win) {
  23.313 -            /* Only lose all focus if this window was the current focus */
  23.314 -            SDL_SetKeyboardFocus(NULL);
  23.315 -        }
  23.316 -    }
  23.317 -
  23.318 -    void _HandleWindowMoved(BMessage *msg) {
  23.319 -        SDL_Window *win;
  23.320 -        int32 winID;
  23.321 -        int32 xPos, yPos;
  23.322 -        /* Get the window id and new x/y position of the window */
  23.323 -        if(
  23.324 -            !_GetWinID(msg, &winID) ||
  23.325 -            msg->FindInt32("window-x", &xPos) != B_OK ||
  23.326 -            msg->FindInt32("window-y", &yPos) != B_OK
  23.327 -        ) {
  23.328 -            return;
  23.329 -        }
  23.330 -        win = GetSDLWindow(winID);
  23.331 -        SDL_SendWindowEvent(win, SDL_WINDOWEVENT_MOVED, xPos, yPos);
  23.332 -    }
  23.333 -
  23.334 -    void _HandleWindowResized(BMessage *msg) {
  23.335 -        SDL_Window *win;
  23.336 -        int32 winID;
  23.337 -        int32 w, h;
  23.338 -        /* Get the window id ]and new x/y position of the window */
  23.339 -        if(
  23.340 -            !_GetWinID(msg, &winID) ||
  23.341 -            msg->FindInt32("window-w", &w) != B_OK ||
  23.342 -            msg->FindInt32("window-h", &h) != B_OK
  23.343 -        ) {
  23.344 -            return;
  23.345 -        }
  23.346 -        win = GetSDLWindow(winID);
  23.347 -        SDL_SendWindowEvent(win, SDL_WINDOWEVENT_RESIZED, w, h);
  23.348 -    }
  23.349 -
  23.350 -    bool _GetWinID(BMessage *msg, int32 *winID) {
  23.351 -        return msg->FindInt32("window-id", winID) == B_OK;
  23.352 -    }
  23.353 -
  23.354 -
  23.355 -
  23.356 -    /* Vector functions: Wraps vector stuff in case we need to change
  23.357 -       implementation */
  23.358 -    void _SetSDLWindow(SDL_Window *win, int32 winID) {
  23.359 -        _window_map[winID] = win;
  23.360 -    }
  23.361 -
  23.362 -    int32 _GetNumWindowSlots() {
  23.363 -        return _window_map.size();
  23.364 -    }
  23.365 -
  23.366 -
  23.367 -    void _PopBackWindow() {
  23.368 -        _window_map.pop_back();
  23.369 -    }
  23.370 -
  23.371 -    void _PushBackWindow(SDL_Window *win) {
  23.372 -        _window_map.push_back(win);
  23.373 -    }
  23.374 -
  23.375 -
  23.376 -    /* Members */
  23.377 -    std::vector<SDL_Window*> _window_map; /* Keeps track of SDL_Windows by index-id */
  23.378 -
  23.379 -    display_mode *_saved_mode;
  23.380 -    BGLView      *_current_context;
  23.381 -};
  23.382 -
  23.383 -#endif
    24.1 --- a/src/main/beos/SDL_BeApp.cc	Thu Nov 14 22:19:07 2013 +0530
    24.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.3 @@ -1,136 +0,0 @@
    24.4 -/*
    24.5 -  Simple DirectMedia Layer
    24.6 -  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    24.7 -
    24.8 -  This software is provided 'as-is', without any express or implied
    24.9 -  warranty.  In no event will the authors be held liable for any damages
   24.10 -  arising from the use of this software.
   24.11 -
   24.12 -  Permission is granted to anyone to use this software for any purpose,
   24.13 -  including commercial applications, and to alter it and redistribute it
   24.14 -  freely, subject to the following restrictions:
   24.15 -
   24.16 -  1. The origin of this software must not be misrepresented; you must not
   24.17 -     claim that you wrote the original software. If you use this software
   24.18 -     in a product, an acknowledgment in the product documentation would be
   24.19 -     appreciated but is not required.
   24.20 -  2. Altered source versions must be plainly marked as such, and must not be
   24.21 -     misrepresented as being the original software.
   24.22 -  3. This notice may not be removed or altered from any source distribution.
   24.23 -*/
   24.24 -#include "SDL_config.h"
   24.25 -
   24.26 -#if defined(__BEOS__) || defined(__HAIKU__)
   24.27 -
   24.28 -/* Handle the BeApp specific portions of the application */
   24.29 -
   24.30 -#include <AppKit.h>
   24.31 -#include <storage/Path.h>
   24.32 -#include <storage/Entry.h>
   24.33 -#include <unistd.h>
   24.34 -
   24.35 -#include "SDL_BApp.h"	/* SDL_BApp class definition */
   24.36 -#include "SDL_BeApp.h"
   24.37 -#include "SDL_thread.h"
   24.38 -#include "SDL_timer.h"
   24.39 -#include "SDL_error.h"
   24.40 -
   24.41 -#include "../../video/bwindow/SDL_BWin.h"
   24.42 -
   24.43 -#ifdef __cplusplus
   24.44 -extern "C" {
   24.45 -#endif
   24.46 -/* Flag to tell whether or not the Be application is active or not */
   24.47 -int SDL_BeAppActive = 0;
   24.48 -static SDL_Thread *SDL_AppThread = NULL;
   24.49 -
   24.50 -static int
   24.51 -StartBeApp(void *unused)
   24.52 -{
   24.53 -    BApplication *App;
   24.54 -
   24.55 -    App = new SDL_BApp("application/x-SDL-executable");
   24.56 -
   24.57 -    App->Run();
   24.58 -    delete App;
   24.59 -    return (0);
   24.60 -}
   24.61 -
   24.62 -/* Initialize the Be Application, if it's not already started */
   24.63 -int
   24.64 -SDL_InitBeApp(void)
   24.65 -{
   24.66 -    /* Create the BApplication that handles appserver interaction */
   24.67 -    if (SDL_BeAppActive <= 0) {
   24.68 -        SDL_AppThread = SDL_CreateThread(StartBeApp, "SDLApplication", NULL);
   24.69 -        if (SDL_AppThread == NULL) {
   24.70 -            return SDL_SetError("Couldn't create BApplication thread");
   24.71 -        }
   24.72 -
   24.73 -        /* Change working to directory to that of executable */
   24.74 -        app_info info;
   24.75 -        if (B_OK == be_app->GetAppInfo(&info)) {
   24.76 -            entry_ref ref = info.ref;
   24.77 -            BEntry entry;
   24.78 -            if (B_OK == entry.SetTo(&ref)) {
   24.79 -                BPath path;
   24.80 -                if (B_OK == path.SetTo(&entry)) {
   24.81 -                    if (B_OK == path.GetParent(&path)) {
   24.82 -                        chdir(path.Path());
   24.83 -                    }
   24.84 -                }
   24.85 -            }
   24.86 -        }
   24.87 -
   24.88 -        do {
   24.89 -            SDL_Delay(10);
   24.90 -        } while ((be_app == NULL) || be_app->IsLaunching());
   24.91 -
   24.92 -        /* Mark the application active */
   24.93 -        SDL_BeAppActive = 0;
   24.94 -    }
   24.95 -
   24.96 -    /* Increment the application reference count */
   24.97 -    ++SDL_BeAppActive;
   24.98 -
   24.99 -    /* The app is running, and we're ready to go */
  24.100 -    return (0);
  24.101 -}
  24.102 -
  24.103 -/* Quit the Be Application, if there's nothing left to do */
  24.104 -void
  24.105 -SDL_QuitBeApp(void)
  24.106 -{
  24.107 -    /* Decrement the application reference count */
  24.108 -    --SDL_BeAppActive;
  24.109 -
  24.110 -    /* If the reference count reached zero, clean up the app */
  24.111 -    if (SDL_BeAppActive == 0) {
  24.112 -        if (SDL_AppThread != NULL) {
  24.113 -            if (be_app != NULL) {       /* Not tested */
  24.114 -                be_app->PostMessage(B_QUIT_REQUESTED);
  24.115 -            }
  24.116 -            SDL_WaitThread(SDL_AppThread, NULL);
  24.117 -            SDL_AppThread = NULL;
  24.118 -        }
  24.119 -        /* be_app should now be NULL since be_app has quit */
  24.120 -    }
  24.121 -}
  24.122 -
  24.123 -#ifdef __cplusplus
  24.124 -}
  24.125 -#endif
  24.126 -
  24.127 -/* SDL_BApp functions */
  24.128 -void SDL_BApp::ClearID(SDL_BWin *bwin) {
  24.129 -	_SetSDLWindow(NULL, bwin->GetID());
  24.130 -	int32 i = _GetNumWindowSlots() - 1;
  24.131 -	while(i >= 0 && GetSDLWindow(i) == NULL) {
  24.132 -		_PopBackWindow();
  24.133 -		--i;
  24.134 -	}
  24.135 -}
  24.136 -
  24.137 -#endif /* __BEOS__ */
  24.138 -
  24.139 -/* vi: set ts=4 sw=4 expandtab: */
    25.1 --- a/src/main/beos/SDL_BeApp.h	Thu Nov 14 22:19:07 2013 +0530
    25.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.3 @@ -1,41 +0,0 @@
    25.4 -/*
    25.5 -  Simple DirectMedia Layer
    25.6 -  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    25.7 -
    25.8 -  This software is provided 'as-is', without any express or implied
    25.9 -  warranty.  In no event will the authors be held liable for any damages
   25.10 -  arising from the use of this software.
   25.11 -
   25.12 -  Permission is granted to anyone to use this software for any purpose,
   25.13 -  including commercial applications, and to alter it and redistribute it
   25.14 -  freely, subject to the following restrictions:
   25.15 -
   25.16 -  1. The origin of this software must not be misrepresented; you must not
   25.17 -     claim that you wrote the original software. If you use this software
   25.18 -     in a product, an acknowledgment in the product documentation would be
   25.19 -     appreciated but is not required.
   25.20 -  2. Altered source versions must be plainly marked as such, and must not be
   25.21 -     misrepresented as being the original software.
   25.22 -  3. This notice may not be removed or altered from any source distribution.
   25.23 -*/
   25.24 -#include "SDL_config.h"
   25.25 -
   25.26 -
   25.27 -#ifdef __cplusplus
   25.28 -extern "C" {
   25.29 -#endif
   25.30 -/* Handle the BeApp specific portions of the application */
   25.31 -
   25.32 -/* Initialize the Be Application, if it's not already started */
   25.33 -extern int SDL_InitBeApp(void);
   25.34 -
   25.35 -/* Quit the Be Application, if there's nothing left to do */
   25.36 -extern void SDL_QuitBeApp(void);
   25.37 -
   25.38 -/* Flag to tell whether the app is active or not */
   25.39 -extern int SDL_BeAppActive;
   25.40 -/* vi: set ts=4 sw=4 expandtab: */
   25.41 -
   25.42 -#ifdef __cplusplus
   25.43 -}
   25.44 -#endif
    26.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.2 +++ b/src/main/haiku/SDL_BApp.h	Thu Nov 14 22:35:28 2013 +0530
    26.3 @@ -0,0 +1,380 @@
    26.4 +/*
    26.5 +  Simple DirectMedia Layer
    26.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    26.7 +
    26.8 +  This software is provided 'as-is', without any express or implied
    26.9 +  warranty.  In no event will the authors be held liable for any damages
   26.10 +  arising from the use of this software.
   26.11 +
   26.12 +  Permission is granted to anyone to use this software for any purpose,
   26.13 +  including commercial applications, and to alter it and redistribute it
   26.14 +  freely, subject to the following restrictions:
   26.15 +
   26.16 +  1. The origin of this software must not be misrepresented; you must not
   26.17 +     claim that you wrote the original software. If you use this software
   26.18 +     in a product, an acknowledgment in the product documentation would be
   26.19 +     appreciated but is not required.
   26.20 +  2. Altered source versions must be plainly marked as such, and must not be
   26.21 +     misrepresented as being the original software.
   26.22 +  3. This notice may not be removed or altered from any source distribution.
   26.23 +*/
   26.24 +#ifndef SDL_BAPP_H
   26.25 +#define SDL_BAPP_H
   26.26 +
   26.27 +#include <InterfaceKit.h>
   26.28 +#include <OpenGLKit.h>
   26.29 +
   26.30 +#include "../../video/haiku/SDL_bkeyboard.h"
   26.31 +
   26.32 +
   26.33 +#ifdef __cplusplus
   26.34 +extern "C" {
   26.35 +#endif
   26.36 +
   26.37 +#include "SDL_config.h"
   26.38 +
   26.39 +#include "SDL_video.h"
   26.40 +
   26.41 +/* Local includes */
   26.42 +#include "../../events/SDL_events_c.h"
   26.43 +#include "../../video/haiku/SDL_bkeyboard.h"
   26.44 +#include "../../video/haiku/SDL_bframebuffer.h"
   26.45 +
   26.46 +#ifdef __cplusplus
   26.47 +}
   26.48 +#endif
   26.49 +
   26.50 +#include <vector>
   26.51 +
   26.52 +
   26.53 +
   26.54 +
   26.55 +/* Forward declarations */
   26.56 +class SDL_BWin;
   26.57 +
   26.58 +/* Message constants */
   26.59 +enum ToSDL {
   26.60 +    /* Intercepted by BWindow on its way to BView */
   26.61 +    BAPP_MOUSE_MOVED,
   26.62 +    BAPP_MOUSE_BUTTON,
   26.63 +    BAPP_MOUSE_WHEEL,
   26.64 +    BAPP_KEY,
   26.65 +    BAPP_REPAINT,           /* from _UPDATE_ */
   26.66 +    /* From BWindow */
   26.67 +    BAPP_MAXIMIZE,          /* from B_ZOOM */
   26.68 +    BAPP_MINIMIZE,
   26.69 +    BAPP_RESTORE,           /* TODO: IMPLEMENT! */
   26.70 +    BAPP_SHOW,
   26.71 +    BAPP_HIDE,
   26.72 +    BAPP_MOUSE_FOCUS,       /* caused by MOUSE_MOVE */
   26.73 +    BAPP_KEYBOARD_FOCUS,    /* from WINDOW_ACTIVATED */
   26.74 +    BAPP_WINDOW_CLOSE_REQUESTED,
   26.75 +    BAPP_WINDOW_MOVED,
   26.76 +    BAPP_WINDOW_RESIZED,
   26.77 +    BAPP_SCREEN_CHANGED
   26.78 +};
   26.79 +
   26.80 +
   26.81 +
   26.82 +/* Create a descendant of BApplication */
   26.83 +class SDL_BApp : public BApplication {
   26.84 +public:
   26.85 +    SDL_BApp(const char* signature) :
   26.86 +        BApplication(signature) {
   26.87 +        _current_context = NULL;
   26.88 +    }
   26.89 +
   26.90 +
   26.91 +    virtual ~SDL_BApp() {
   26.92 +    }
   26.93 +
   26.94 +
   26.95 +
   26.96 +        /* Event-handling functions */
   26.97 +    virtual void MessageReceived(BMessage* message) {
   26.98 +        /* Sort out SDL-related messages */
   26.99 +        switch ( message->what ) {
  26.100 +        case BAPP_MOUSE_MOVED:
  26.101 +            _HandleMouseMove(message);
  26.102 +            break;
  26.103 +
  26.104 +        case BAPP_MOUSE_BUTTON:
  26.105 +            _HandleMouseButton(message);
  26.106 +            break;
  26.107 +
  26.108 +        case BAPP_MOUSE_WHEEL:
  26.109 +            _HandleMouseWheel(message);
  26.110 +            break;
  26.111 +
  26.112 +        case BAPP_KEY:
  26.113 +            _HandleKey(message);
  26.114 +            break;
  26.115 +
  26.116 +        case BAPP_REPAINT:
  26.117 +            _HandleBasicWindowEvent(message, SDL_WINDOWEVENT_EXPOSED);
  26.118 +            break;
  26.119 +
  26.120 +        case BAPP_MAXIMIZE:
  26.121 +            _HandleBasicWindowEvent(message, SDL_WINDOWEVENT_MAXIMIZED);
  26.122 +            break;
  26.123 +
  26.124 +        case BAPP_MINIMIZE:
  26.125 +            _HandleBasicWindowEvent(message, SDL_WINDOWEVENT_MINIMIZED);
  26.126 +            break;
  26.127 +
  26.128 +        case BAPP_SHOW:
  26.129 +            _HandleBasicWindowEvent(message, SDL_WINDOWEVENT_SHOWN);
  26.130 +            break;
  26.131 +
  26.132 +        case BAPP_HIDE:
  26.133 +            _HandleBasicWindowEvent(message, SDL_WINDOWEVENT_HIDDEN);
  26.134 +            break;
  26.135 +
  26.136 +        case BAPP_MOUSE_FOCUS:
  26.137 +            _HandleMouseFocus(message);
  26.138 +            break;
  26.139 +
  26.140 +        case BAPP_KEYBOARD_FOCUS:
  26.141 +            _HandleKeyboardFocus(message);
  26.142 +            break;
  26.143 +
  26.144 +        case BAPP_WINDOW_CLOSE_REQUESTED:
  26.145 +            _HandleBasicWindowEvent(message, SDL_WINDOWEVENT_CLOSE);
  26.146 +            break;
  26.147 +
  26.148 +        case BAPP_WINDOW_MOVED:
  26.149 +            _HandleWindowMoved(message);
  26.150 +            break;
  26.151 +
  26.152 +        case BAPP_WINDOW_RESIZED:
  26.153 +            _HandleWindowResized(message);
  26.154 +            break;
  26.155 +
  26.156 +        case BAPP_SCREEN_CHANGED:
  26.157 +            /* TODO: Handle screen resize or workspace change */
  26.158 +            break;
  26.159 +
  26.160 +        default:
  26.161 +           BApplication::MessageReceived(message);
  26.162 +           break;
  26.163 +        }
  26.164 +    }
  26.165 +
  26.166 +    /* Window creation/destruction methods */
  26.167 +    int32 GetID(SDL_Window *win) {
  26.168 +        int32 i;
  26.169 +        for(i = 0; i < _GetNumWindowSlots(); ++i) {
  26.170 +            if( GetSDLWindow(i) == NULL ) {
  26.171 +                _SetSDLWindow(win, i);
  26.172 +                return i;
  26.173 +            }
  26.174 +        }
  26.175 +
  26.176 +        /* Expand the vector if all slots are full */
  26.177 +        if( i == _GetNumWindowSlots() ) {
  26.178 +            _PushBackWindow(win);
  26.179 +            return i;
  26.180 +        }
  26.181 +
  26.182 +        /* TODO: error handling */
  26.183 +        return 0;
  26.184 +    }
  26.185 +
  26.186 +    /* FIXME: Bad coding practice, but I can't include SDL_BWin.h here.  Is
  26.187 +       there another way to do this? */
  26.188 +    void ClearID(SDL_BWin *bwin); /* Defined in SDL_BeApp.cc */
  26.189 +
  26.190 +
  26.191 +    SDL_Window *GetSDLWindow(int32 winID) {
  26.192 +        return _window_map[winID];
  26.193 +    }
  26.194 +
  26.195 +    void SetCurrentContext(BGLView *newContext) {
  26.196 +        if(_current_context)
  26.197 +            _current_context->UnlockGL();
  26.198 +        _current_context = newContext;
  26.199 +        _current_context->LockGL();
  26.200 +    }
  26.201 +private:
  26.202 +    /* Event management */
  26.203 +    void _HandleBasicWindowEvent(BMessage *msg, int32 sdlEventType) {
  26.204 +        SDL_Window *win;
  26.205 +        int32 winID;
  26.206 +        if(
  26.207 +            !_GetWinID(msg, &winID)
  26.208 +        ) {
  26.209 +            return;
  26.210 +        }
  26.211 +        win = GetSDLWindow(winID);
  26.212 +        SDL_SendWindowEvent(win, sdlEventType, 0, 0);
  26.213 +    }
  26.214 +
  26.215 +    void _HandleMouseMove(BMessage *msg) {
  26.216 +        SDL_Window *win;
  26.217 +        int32 winID;
  26.218 +        int32 x = 0, y = 0;
  26.219 +        if(
  26.220 +            !_GetWinID(msg, &winID) ||
  26.221 +            msg->FindInt32("x", &x) != B_OK || /* x movement */
  26.222 +            msg->FindInt32("y", &y) != B_OK    /* y movement */
  26.223 +        ) {
  26.224 +            return;
  26.225 +        }
  26.226 +        win = GetSDLWindow(winID);
  26.227 +        SDL_SendMouseMotion(win, 0, 0, x, y);
  26.228 +
  26.229 +        /* Tell the application that the mouse passed over, redraw needed */
  26.230 +        BE_UpdateWindowFramebuffer(NULL,win,NULL,-1);
  26.231 +    }
  26.232 +
  26.233 +    void _HandleMouseButton(BMessage *msg) {
  26.234 +        SDL_Window *win;
  26.235 +        int32 winID;
  26.236 +        int32 button, state;    /* left/middle/right, pressed/released */
  26.237 +        if(
  26.238 +            !_GetWinID(msg, &winID) ||
  26.239 +            msg->FindInt32("button-id", &button) != B_OK ||
  26.240 +            msg->FindInt32("button-state", &state) != B_OK
  26.241 +        ) {
  26.242 +            return;
  26.243 +        }
  26.244 +        win = GetSDLWindow(winID);
  26.245 +        SDL_SendMouseButton(win, 0, state, button);
  26.246 +    }
  26.247 +
  26.248 +    void _HandleMouseWheel(BMessage *msg) {
  26.249 +        SDL_Window *win;
  26.250 +        int32 winID;
  26.251 +        int32 xTicks, yTicks;
  26.252 +        if(
  26.253 +            !_GetWinID(msg, &winID) ||
  26.254 +            msg->FindInt32("xticks", &xTicks) != B_OK ||
  26.255 +            msg->FindInt32("yticks", &yTicks) != B_OK
  26.256 +        ) {
  26.257 +            return;
  26.258 +        }
  26.259 +        win = GetSDLWindow(winID);
  26.260 +        SDL_SendMouseWheel(win, 0, xTicks, yTicks);
  26.261 +    }
  26.262 +
  26.263 +    void _HandleKey(BMessage *msg) {
  26.264 +        int32 scancode, state;  /* scancode, pressed/released */
  26.265 +        if(
  26.266 +            msg->FindInt32("key-state", &state) != B_OK ||
  26.267 +            msg->FindInt32("key-scancode", &scancode) != B_OK
  26.268 +        ) {
  26.269 +            return;
  26.270 +        }
  26.271 +
  26.272 +        /* Make sure this isn't a repeated event (key pressed and held) */
  26.273 +        if(state == SDL_PRESSED && BE_GetKeyState(scancode) == SDL_PRESSED) {
  26.274 +            return;
  26.275 +        }
  26.276 +        BE_SetKeyState(scancode, state);
  26.277 +        SDL_SendKeyboardKey(state, BE_GetScancodeFromBeKey(scancode));
  26.278 +    }
  26.279 +
  26.280 +    void _HandleMouseFocus(BMessage *msg) {
  26.281 +        SDL_Window *win;
  26.282 +        int32 winID;
  26.283 +        bool bSetFocus; /* If false, lose focus */
  26.284 +        if(
  26.285 +            !_GetWinID(msg, &winID) ||
  26.286 +            msg->FindBool("focusGained", &bSetFocus) != B_OK
  26.287 +        ) {
  26.288 +            return;
  26.289 +        }
  26.290 +        win = GetSDLWindow(winID);
  26.291 +        if(bSetFocus) {
  26.292 +            SDL_SetMouseFocus(win);
  26.293 +        } else if(SDL_GetMouseFocus() == win) {
  26.294 +            /* Only lose all focus if this window was the current focus */
  26.295 +            SDL_SetMouseFocus(NULL);
  26.296 +        }
  26.297 +    }
  26.298 +
  26.299 +    void _HandleKeyboardFocus(BMessage *msg) {
  26.300 +        SDL_Window *win;
  26.301 +        int32 winID;
  26.302 +        bool bSetFocus; /* If false, lose focus */
  26.303 +        if(
  26.304 +            !_GetWinID(msg, &winID) ||
  26.305 +            msg->FindBool("focusGained", &bSetFocus) != B_OK
  26.306 +        ) {
  26.307 +            return;
  26.308 +        }
  26.309 +        win = GetSDLWindow(winID);
  26.310 +        if(bSetFocus) {
  26.311 +            SDL_SetKeyboardFocus(win);
  26.312 +        } else if(SDL_GetKeyboardFocus() == win) {
  26.313 +            /* Only lose all focus if this window was the current focus */
  26.314 +            SDL_SetKeyboardFocus(NULL);
  26.315 +        }
  26.316 +    }
  26.317 +
  26.318 +    void _HandleWindowMoved(BMessage *msg) {
  26.319 +        SDL_Window *win;
  26.320 +        int32 winID;
  26.321 +        int32 xPos, yPos;
  26.322 +        /* Get the window id and new x/y position of the window */
  26.323 +        if(
  26.324 +            !_GetWinID(msg, &winID) ||
  26.325 +            msg->FindInt32("window-x", &xPos) != B_OK ||
  26.326 +            msg->FindInt32("window-y", &yPos) != B_OK
  26.327 +        ) {
  26.328 +            return;
  26.329 +        }
  26.330 +        win = GetSDLWindow(winID);
  26.331 +        SDL_SendWindowEvent(win, SDL_WINDOWEVENT_MOVED, xPos, yPos);
  26.332 +    }
  26.333 +
  26.334 +    void _HandleWindowResized(BMessage *msg) {
  26.335 +        SDL_Window *win;
  26.336 +        int32 winID;
  26.337 +        int32 w, h;
  26.338 +        /* Get the window id ]and new x/y position of the window */
  26.339 +        if(
  26.340 +            !_GetWinID(msg, &winID) ||
  26.341 +            msg->FindInt32("window-w", &w) != B_OK ||
  26.342 +            msg->FindInt32("window-h", &h) != B_OK
  26.343 +        ) {
  26.344 +            return;
  26.345 +        }
  26.346 +        win = GetSDLWindow(winID);
  26.347 +        SDL_SendWindowEvent(win, SDL_WINDOWEVENT_RESIZED, w, h);
  26.348 +    }
  26.349 +
  26.350 +    bool _GetWinID(BMessage *msg, int32 *winID) {
  26.351 +        return msg->FindInt32("window-id", winID) == B_OK;
  26.352 +    }
  26.353 +
  26.354 +
  26.355 +
  26.356 +    /* Vector functions: Wraps vector stuff in case we need to change
  26.357 +       implementation */
  26.358 +    void _SetSDLWindow(SDL_Window *win, int32 winID) {
  26.359 +        _window_map[winID] = win;
  26.360 +    }
  26.361 +
  26.362 +    int32 _GetNumWindowSlots() {
  26.363 +        return _window_map.size();
  26.364 +    }
  26.365 +
  26.366 +
  26.367 +    void _PopBackWindow() {
  26.368 +        _window_map.pop_back();
  26.369 +    }
  26.370 +
  26.371 +    void _PushBackWindow(SDL_Window *win) {
  26.372 +        _window_map.push_back(win);
  26.373 +    }
  26.374 +
  26.375 +
  26.376 +    /* Members */
  26.377 +    std::vector<SDL_Window*> _window_map; /* Keeps track of SDL_Windows by index-id */
  26.378 +
  26.379 +    display_mode *_saved_mode;
  26.380 +    BGLView      *_current_context;
  26.381 +};
  26.382 +
  26.383 +#endif
    27.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.2 +++ b/src/main/haiku/SDL_BeApp.cc	Thu Nov 14 22:35:28 2013 +0530
    27.3 @@ -0,0 +1,136 @@
    27.4 +/*
    27.5 +  Simple DirectMedia Layer
    27.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    27.7 +
    27.8 +  This software is provided 'as-is', without any express or implied
    27.9 +  warranty.  In no event will the authors be held liable for any damages
   27.10 +  arising from the use of this software.
   27.11 +
   27.12 +  Permission is granted to anyone to use this software for any purpose,
   27.13 +  including commercial applications, and to alter it and redistribute it
   27.14 +  freely, subject to the following restrictions:
   27.15 +
   27.16 +  1. The origin of this software must not be misrepresented; you must not
   27.17 +     claim that you wrote the original software. If you use this software
   27.18 +     in a product, an acknowledgment in the product documentation would be
   27.19 +     appreciated but is not required.
   27.20 +  2. Altered source versions must be plainly marked as such, and must not be
   27.21 +     misrepresented as being the original software.
   27.22 +  3. This notice may not be removed or altered from any source distribution.
   27.23 +*/
   27.24 +#include "SDL_config.h"
   27.25 +
   27.26 +#if defined(__HAIKU__)
   27.27 +
   27.28 +/* Handle the BeApp specific portions of the application */
   27.29 +
   27.30 +#include <AppKit.h>
   27.31 +#include <storage/Path.h>
   27.32 +#include <storage/Entry.h>
   27.33 +#include <unistd.h>
   27.34 +
   27.35 +#include "SDL_BApp.h"	/* SDL_BApp class definition */
   27.36 +#include "SDL_BeApp.h"
   27.37 +#include "SDL_thread.h"
   27.38 +#include "SDL_timer.h"
   27.39 +#include "SDL_error.h"
   27.40 +
   27.41 +#include "../../video/haiku/SDL_BWin.h"
   27.42 +
   27.43 +#ifdef __cplusplus
   27.44 +extern "C" {
   27.45 +#endif
   27.46 +/* Flag to tell whether or not the Be application is active or not */
   27.47 +int SDL_BeAppActive = 0;
   27.48 +static SDL_Thread *SDL_AppThread = NULL;
   27.49 +
   27.50 +static int
   27.51 +StartBeApp(void *unused)
   27.52 +{
   27.53 +    BApplication *App;
   27.54 +
   27.55 +    App = new SDL_BApp("application/x-SDL-executable");
   27.56 +
   27.57 +    App->Run();
   27.58 +    delete App;
   27.59 +    return (0);
   27.60 +}
   27.61 +
   27.62 +/* Initialize the Be Application, if it's not already started */
   27.63 +int
   27.64 +SDL_InitBeApp(void)
   27.65 +{
   27.66 +    /* Create the BApplication that handles appserver interaction */
   27.67 +    if (SDL_BeAppActive <= 0) {
   27.68 +        SDL_AppThread = SDL_CreateThread(StartBeApp, "SDLApplication", NULL);
   27.69 +        if (SDL_AppThread == NULL) {
   27.70 +            return SDL_SetError("Couldn't create BApplication thread");
   27.71 +        }
   27.72 +
   27.73 +        /* Change working to directory to that of executable */
   27.74 +        app_info info;
   27.75 +        if (B_OK == be_app->GetAppInfo(&info)) {
   27.76 +            entry_ref ref = info.ref;
   27.77 +            BEntry entry;
   27.78 +            if (B_OK == entry.SetTo(&ref)) {
   27.79 +                BPath path;
   27.80 +                if (B_OK == path.SetTo(&entry)) {
   27.81 +                    if (B_OK == path.GetParent(&path)) {
   27.82 +                        chdir(path.Path());
   27.83 +                    }
   27.84 +                }
   27.85 +            }
   27.86 +        }
   27.87 +
   27.88 +        do {
   27.89 +            SDL_Delay(10);
   27.90 +        } while ((be_app == NULL) || be_app->IsLaunching());
   27.91 +
   27.92 +        /* Mark the application active */
   27.93 +        SDL_BeAppActive = 0;
   27.94 +    }
   27.95 +
   27.96 +    /* Increment the application reference count */
   27.97 +    ++SDL_BeAppActive;
   27.98 +
   27.99 +    /* The app is running, and we're ready to go */
  27.100 +    return (0);
  27.101 +}
  27.102 +
  27.103 +/* Quit the Be Application, if there's nothing left to do */
  27.104 +void
  27.105 +SDL_QuitBeApp(void)
  27.106 +{
  27.107 +    /* Decrement the application reference count */
  27.108 +    --SDL_BeAppActive;
  27.109 +
  27.110 +    /* If the reference count reached zero, clean up the app */
  27.111 +    if (SDL_BeAppActive == 0) {
  27.112 +        if (SDL_AppThread != NULL) {
  27.113 +            if (be_app != NULL) {       /* Not tested */
  27.114 +                be_app->PostMessage(B_QUIT_REQUESTED);
  27.115 +            }
  27.116 +            SDL_WaitThread(SDL_AppThread, NULL);
  27.117 +            SDL_AppThread = NULL;
  27.118 +        }
  27.119 +        /* be_app should now be NULL since be_app has quit */
  27.120 +    }
  27.121 +}
  27.122 +
  27.123 +#ifdef __cplusplus
  27.124 +}
  27.125 +#endif
  27.126 +
  27.127 +/* SDL_BApp functions */
  27.128 +void SDL_BApp::ClearID(SDL_BWin *bwin) {
  27.129 +	_SetSDLWindow(NULL, bwin->GetID());
  27.130 +	int32 i = _GetNumWindowSlots() - 1;
  27.131 +	while(i >= 0 && GetSDLWindow(i) == NULL) {
  27.132 +		_PopBackWindow();
  27.133 +		--i;
  27.134 +	}
  27.135 +}
  27.136 +
  27.137 +#endif /* __HAIKU__ */
  27.138 +
  27.139 +/* vi: set ts=4 sw=4 expandtab: */
    28.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.2 +++ b/src/main/haiku/SDL_BeApp.h	Thu Nov 14 22:35:28 2013 +0530
    28.3 @@ -0,0 +1,41 @@
    28.4 +/*
    28.5 +  Simple DirectMedia Layer
    28.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    28.7 +
    28.8 +  This software is provided 'as-is', without any express or implied
    28.9 +  warranty.  In no event will the authors be held liable for any damages
   28.10 +  arising from the use of this software.
   28.11 +
   28.12 +  Permission is granted to anyone to use this software for any purpose,
   28.13 +  including commercial applications, and to alter it and redistribute it
   28.14 +  freely, subject to the following restrictions:
   28.15 +
   28.16 +  1. The origin of this software must not be misrepresented; you must not
   28.17 +     claim that you wrote the original software. If you use this software
   28.18 +     in a product, an acknowledgment in the product documentation would be
   28.19 +     appreciated but is not required.
   28.20 +  2. Altered source versions must be plainly marked as such, and must not be
   28.21 +     misrepresented as being the original software.
   28.22 +  3. This notice may not be removed or altered from any source distribution.
   28.23 +*/
   28.24 +#include "SDL_config.h"
   28.25 +
   28.26 +
   28.27 +#ifdef __cplusplus
   28.28 +extern "C" {
   28.29 +#endif
   28.30 +/* Handle the BeApp specific portions of the application */
   28.31 +
   28.32 +/* Initialize the Be Application, if it's not already started */
   28.33 +extern int SDL_InitBeApp(void);
   28.34 +
   28.35 +/* Quit the Be Application, if there's nothing left to do */
   28.36 +extern void SDL_QuitBeApp(void);
   28.37 +
   28.38 +/* Flag to tell whether the app is active or not */
   28.39 +extern int SDL_BeAppActive;
   28.40 +/* vi: set ts=4 sw=4 expandtab: */
   28.41 +
   28.42 +#ifdef __cplusplus
   28.43 +}
   28.44 +#endif
    29.1 --- a/src/power/SDL_power.c	Thu Nov 14 22:19:07 2013 +0530
    29.2 +++ b/src/power/SDL_power.c	Thu Nov 14 22:35:28 2013 +0530
    29.3 @@ -33,7 +33,7 @@
    29.4  SDL_bool SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState *, int *, int *);
    29.5  SDL_bool SDL_GetPowerInfo_Windows(SDL_PowerState *, int *, int *);
    29.6  SDL_bool SDL_GetPowerInfo_MacOSX(SDL_PowerState *, int *, int *);
    29.7 -SDL_bool SDL_GetPowerInfo_BeOS(SDL_PowerState *, int *, int *);
    29.8 +SDL_bool SDL_GetPowerInfo_Haiku(SDL_PowerState *, int *, int *);
    29.9  SDL_bool SDL_GetPowerInfo_UIKit(SDL_PowerState *, int *, int *);
   29.10  SDL_bool SDL_GetPowerInfo_Android(SDL_PowerState *, int *, int *);
   29.11  SDL_bool SDL_GetPowerInfo_PSP(SDL_PowerState *, int *, int *);
   29.12 @@ -68,8 +68,8 @@
   29.13  #ifdef SDL_POWER_MACOSX         /* handles Mac OS X, Darwin. */
   29.14      SDL_GetPowerInfo_MacOSX,
   29.15  #endif
   29.16 -#ifdef SDL_POWER_BEOS           /* handles BeOS, Zeta, with euc.jp apm driver. */
   29.17 -    SDL_GetPowerInfo_BeOS,
   29.18 +#ifdef SDL_POWER_HAIKU          /* with BeOS euc.jp apm driver. Does this work on Haiku? */
   29.19 +    SDL_GetPowerInfo_Haiku,
   29.20  #endif
   29.21  #ifdef SDL_POWER_ANDROID        /* handles Android. */
   29.22      SDL_GetPowerInfo_Android,
    30.1 --- a/src/power/beos/SDL_syspower.c	Thu Nov 14 22:19:07 2013 +0530
    30.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    30.3 @@ -1,125 +0,0 @@
    30.4 -/*
    30.5 -  Simple DirectMedia Layer
    30.6 -  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    30.7 -
    30.8 -  This software is provided 'as-is', without any express or implied
    30.9 -  warranty.  In no event will the authors be held liable for any damages
   30.10 -  arising from the use of this software.
   30.11 -
   30.12 -  Permission is granted to anyone to use this software for any purpose,
   30.13 -  including commercial applications, and to alter it and redistribute it
   30.14 -  freely, subject to the following restrictions:
   30.15 -
   30.16 -  1. The origin of this software must not be misrepresented; you must not
   30.17 -     claim that you wrote the original software. If you use this software
   30.18 -     in a product, an acknowledgment in the product documentation would be
   30.19 -     appreciated but is not required.
   30.20 -  2. Altered source versions must be plainly marked as such, and must not be
   30.21 -     misrepresented as being the original software.
   30.22 -  3. This notice may not be removed or altered from any source distribution.
   30.23 -*/
   30.24 -#include "SDL_config.h"
   30.25 -
   30.26 -#ifndef SDL_POWER_DISABLED
   30.27 -#if SDL_POWER_BEOS
   30.28 -
   30.29 -#include <stdio.h>
   30.30 -#include <stdlib.h>
   30.31 -#include <unistd.h>
   30.32 -#include <fcntl.h>
   30.33 -#include <ctype.h>
   30.34 -#include <drivers/Drivers.h>
   30.35 -
   30.36 -/* These values are from apm.h ... */
   30.37 -#define APM_DEVICE_PATH "/dev/misc/apm"
   30.38 -#define APM_FUNC_OFFSET 0x5300
   30.39 -#define APM_FUNC_GET_POWER_STATUS 10
   30.40 -#define APM_DEVICE_ALL 1
   30.41 -#define APM_BIOS_CALL (B_DEVICE_OP_CODES_END + 3)
   30.42 -
   30.43 -#include "SDL_power.h"
   30.44 -
   30.45 -SDL_bool
   30.46 -SDL_GetPowerInfo_BeOS(SDL_PowerState * state, int *seconds, int *percent)
   30.47 -{
   30.48 -    const int fd = open("/dev/misc/apm", O_RDONLY);
   30.49 -    SDL_bool need_details = SDL_FALSE;
   30.50 -    uint16 regs[6];
   30.51 -    uint8 ac_status;
   30.52 -    uint8 battery_status;
   30.53 -    uint8 battery_flags;
   30.54 -    uint8 battery_life;
   30.55 -    uint32 battery_time;
   30.56 -    int rc;
   30.57 -
   30.58 -    if (fd == -1) {
   30.59 -        return SDL_FALSE;       /* maybe some other method will work? */
   30.60 -    }
   30.61 -
   30.62 -    memset(regs, '\0', sizeof(regs));
   30.63 -    regs[0] = APM_FUNC_OFFSET + APM_FUNC_GET_POWER_STATUS;
   30.64 -    regs[1] = APM_DEVICE_ALL;
   30.65 -    rc = ioctl(fd, APM_BIOS_CALL, regs);
   30.66 -    close(fd);
   30.67 -
   30.68 -    if (rc < 0) {
   30.69 -        return SDL_FALSE;
   30.70 -    }
   30.71 -
   30.72 -    ac_status = regs[1] >> 8;
   30.73 -    battery_status = regs[1] & 0xFF;
   30.74 -    battery_flags = regs[2] >> 8;
   30.75 -    battery_life = regs[2] & 0xFF;
   30.76 -    battery_time = (uint32) regs[3];
   30.77 -
   30.78 -    /* in theory, _something_ should be set in battery_flags, right? */
   30.79 -    if (battery_flags == 0x00) {        /* older APM BIOS? Less fields. */
   30.80 -        battery_time = 0xFFFF;
   30.81 -        if (battery_status == 0xFF) {
   30.82 -            battery_flags = 0xFF;
   30.83 -        } else {
   30.84 -            battery_flags = (1 << battery_status);
   30.85 -        }
   30.86 -    }
   30.87 -
   30.88 -    if ((battery_time != 0xFFFF) && (battery_time & (1 << 15))) {
   30.89 -        /* time is in minutes, not seconds */
   30.90 -        battery_time = (battery_time & 0x7FFF) * 60;
   30.91 -    }
   30.92 -
   30.93 -    if (battery_flags == 0xFF) {        /* unknown state */
   30.94 -        *state = SDL_POWERSTATE_UNKNOWN;
   30.95 -    } else if (battery_flags & (1 << 7)) {      /* no battery */
   30.96 -        *state = SDL_POWERSTATE_NO_BATTERY;
   30.97 -    } else if (battery_flags & (1 << 3)) {      /* charging */
   30.98 -        *state = SDL_POWERSTATE_CHARGING;
   30.99 -        need_details = SDL_TRUE;
  30.100 -    } else if (ac_status == 1) {
  30.101 -        *state = SDL_POWERSTATE_CHARGED;        /* on AC, not charging. */
  30.102 -        need_details = SDL_TRUE;
  30.103 -    } else {
  30.104 -        *state = SDL_POWERSTATE_ON_BATTERY;     /* not on AC. */
  30.105 -        need_details = SDL_TRUE;
  30.106 -    }
  30.107 -
  30.108 -    *percent = -1;
  30.109 -    *seconds = -1;
  30.110 -    if (need_details) {
  30.111 -        const int pct = (int) battery_life;
  30.112 -        const int secs = (int) battery_time;
  30.113 -
  30.114 -        if (pct != 255) {       /* 255 == unknown */
  30.115 -            *percent = (pct > 100) ? 100 : pct; /* clamp between 0%, 100% */
  30.116 -        }
  30.117 -        if (secs != 0xFFFF) {   /* 0xFFFF == unknown */
  30.118 -            *seconds = secs;
  30.119 -        }
  30.120 -    }
  30.121 -
  30.122 -    return SDL_TRUE;            /* the definitive answer if APM driver replied. */
  30.123 -}
  30.124 -
  30.125 -#endif /* SDL_POWER_BEOS */
  30.126 -#endif /* SDL_POWER_DISABLED */
  30.127 -
  30.128 -/* vi: set ts=4 sw=4 expandtab: */
    31.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    31.2 +++ b/src/power/haiku/SDL_syspower.c	Thu Nov 14 22:35:28 2013 +0530
    31.3 @@ -0,0 +1,126 @@
    31.4 +/*
    31.5 +  Simple DirectMedia Layer
    31.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    31.7 +
    31.8 +  This software is provided 'as-is', without any express or implied
    31.9 +  warranty.  In no event will the authors be held liable for any damages
   31.10 +  arising from the use of this software.
   31.11 +
   31.12 +  Permission is granted to anyone to use this software for any purpose,
   31.13 +  including commercial applications, and to alter it and redistribute it
   31.14 +  freely, subject to the following restrictions:
   31.15 +
   31.16 +  1. The origin of this software must not be misrepresented; you must not
   31.17 +     claim that you wrote the original software. If you use this software
   31.18 +     in a product, an acknowledgment in the product documentation would be
   31.19 +     appreciated but is not required.
   31.20 +  2. Altered source versions must be plainly marked as such, and must not be
   31.21 +     misrepresented as being the original software.
   31.22 +  3. This notice may not be removed or altered from any source distribution.
   31.23 +*/
   31.24 +#include "SDL_config.h"
   31.25 +
   31.26 +/* !!! FIXME: does this thing even work on Haiku? */
   31.27 +#ifndef SDL_POWER_DISABLED
   31.28 +#if SDL_POWER_HAIKU
   31.29 +
   31.30 +#include <stdio.h>
   31.31 +#include <stdlib.h>
   31.32 +#include <unistd.h>
   31.33 +#include <fcntl.h>
   31.34 +#include <ctype.h>
   31.35 +#include <drivers/Drivers.h>
   31.36 +
   31.37 +/* These values are from apm.h ... */
   31.38 +#define APM_DEVICE_PATH "/dev/misc/apm"
   31.39 +#define APM_FUNC_OFFSET 0x5300
   31.40 +#define APM_FUNC_GET_POWER_STATUS 10
   31.41 +#define APM_DEVICE_ALL 1
   31.42 +#define APM_BIOS_CALL (B_DEVICE_OP_CODES_END + 3)
   31.43 +
   31.44 +#include "SDL_power.h"
   31.45 +
   31.46 +SDL_bool
   31.47 +SDL_GetPowerInfo_Haiku(SDL_PowerState * state, int *seconds, int *percent)
   31.48 +{
   31.49 +    const int fd = open("/dev/misc/apm", O_RDONLY);
   31.50 +    SDL_bool need_details = SDL_FALSE;
   31.51 +    uint16 regs[6];
   31.52 +    uint8 ac_status;
   31.53 +    uint8 battery_status;
   31.54 +    uint8 battery_flags;
   31.55 +    uint8 battery_life;
   31.56 +    uint32 battery_time;
   31.57 +    int rc;
   31.58 +
   31.59 +    if (fd == -1) {
   31.60 +        return SDL_FALSE;       /* maybe some other method will work? */
   31.61 +    }
   31.62 +
   31.63 +    memset(regs, '\0', sizeof(regs));
   31.64 +    regs[0] = APM_FUNC_OFFSET + APM_FUNC_GET_POWER_STATUS;
   31.65 +    regs[1] = APM_DEVICE_ALL;
   31.66 +    rc = ioctl(fd, APM_BIOS_CALL, regs);
   31.67 +    close(fd);
   31.68 +
   31.69 +    if (rc < 0) {
   31.70 +        return SDL_FALSE;
   31.71 +    }
   31.72 +
   31.73 +    ac_status = regs[1] >> 8;
   31.74 +    battery_status = regs[1] & 0xFF;
   31.75 +    battery_flags = regs[2] >> 8;
   31.76 +    battery_life = regs[2] & 0xFF;
   31.77 +    battery_time = (uint32) regs[3];
   31.78 +
   31.79 +    /* in theory, _something_ should be set in battery_flags, right? */
   31.80 +    if (battery_flags == 0x00) {        /* older APM BIOS? Less fields. */
   31.81 +        battery_time = 0xFFFF;
   31.82 +        if (battery_status == 0xFF) {
   31.83 +            battery_flags = 0xFF;
   31.84 +        } else {
   31.85 +            battery_flags = (1 << battery_status);
   31.86 +        }
   31.87 +    }
   31.88 +
   31.89 +    if ((battery_time != 0xFFFF) && (battery_time & (1 << 15))) {
   31.90 +        /* time is in minutes, not seconds */
   31.91 +        battery_time = (battery_time & 0x7FFF) * 60;
   31.92 +    }
   31.93 +
   31.94 +    if (battery_flags == 0xFF) {        /* unknown state */
   31.95 +        *state = SDL_POWERSTATE_UNKNOWN;
   31.96 +    } else if (battery_flags & (1 << 7)) {      /* no battery */
   31.97 +        *state = SDL_POWERSTATE_NO_BATTERY;
   31.98 +    } else if (battery_flags & (1 << 3)) {      /* charging */
   31.99 +        *state = SDL_POWERSTATE_CHARGING;
  31.100 +        need_details = SDL_TRUE;
  31.101 +    } else if (ac_status == 1) {
  31.102 +        *state = SDL_POWERSTATE_CHARGED;        /* on AC, not charging. */
  31.103 +        need_details = SDL_TRUE;
  31.104 +    } else {
  31.105 +        *state = SDL_POWERSTATE_ON_BATTERY;     /* not on AC. */
  31.106 +        need_details = SDL_TRUE;
  31.107 +    }
  31.108 +
  31.109 +    *percent = -1;
  31.110 +    *seconds = -1;
  31.111 +    if (need_details) {
  31.112 +        const int pct = (int) battery_life;
  31.113 +        const int secs = (int) battery_time;
  31.114 +
  31.115 +        if (pct != 255) {       /* 255 == unknown */
  31.116 +            *percent = (pct > 100) ? 100 : pct; /* clamp between 0%, 100% */
  31.117 +        }
  31.118 +        if (secs != 0xFFFF) {   /* 0xFFFF == unknown */
  31.119 +            *seconds = secs;
  31.120 +        }
  31.121 +    }
  31.122 +
  31.123 +    return SDL_TRUE;            /* the definitive answer if APM driver replied. */
  31.124 +}
  31.125 +
  31.126 +#endif /* SDL_POWER_HAIKU */
  31.127 +#endif /* SDL_POWER_DISABLED */
  31.128 +
  31.129 +/* vi: set ts=4 sw=4 expandtab: */
    32.1 --- a/src/timer/beos/SDL_systimer.c	Thu Nov 14 22:19:07 2013 +0530
    32.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    32.3 @@ -1,74 +0,0 @@
    32.4 -/*
    32.5 -  Simple DirectMedia Layer
    32.6 -  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    32.7 -
    32.8 -  This software is provided 'as-is', without any express or implied
    32.9 -  warranty.  In no event will the authors be held liable for any damages
   32.10 -  arising from the use of this software.
   32.11 -
   32.12 -  Permission is granted to anyone to use this software for any purpose,
   32.13 -  including commercial applications, and to alter it and redistribute it
   32.14 -  freely, subject to the following restrictions:
   32.15 -
   32.16 -  1. The origin of this software must not be misrepresented; you must not
   32.17 -     claim that you wrote the original software. If you use this software
   32.18 -     in a product, an acknowledgment in the product documentation would be
   32.19 -     appreciated but is not required.
   32.20 -  2. Altered source versions must be plainly marked as such, and must not be
   32.21 -     misrepresented as being the original software.
   32.22 -  3. This notice may not be removed or altered from any source distribution.
   32.23 -*/
   32.24 -#include "SDL_config.h"
   32.25 -
   32.26 -#ifdef SDL_TIMER_BEOS
   32.27 -
   32.28 -#include <be/kernel/OS.h>
   32.29 -
   32.30 -#include "SDL_timer.h"
   32.31 -
   32.32 -static bigtime_t start;
   32.33 -static SDL_bool ticks_started = SDL_FALSE;
   32.34 -
   32.35 -void
   32.36 -SDL_InitTicks(void)
   32.37 -{
   32.38 -    if (ticks_started) {
   32.39 -        return;
   32.40 -    }
   32.41 -    ticks_started = SDL_TRUE;
   32.42 -
   32.43 -    /* Set first ticks value */
   32.44 -    start = system_time();
   32.45 -}
   32.46 -
   32.47 -Uint32
   32.48 -SDL_GetTicks(void)
   32.49 -{
   32.50 -    if (!ticks_started) {
   32.51 -        SDL_InitTicks();
   32.52 -    }
   32.53 -
   32.54 -    return ((system_time() - start) / 1000);
   32.55 -}
   32.56 -
   32.57 -Uint64
   32.58 -SDL_GetPerformanceCounter(void)
   32.59 -{
   32.60 -    return system_time();
   32.61 -}
   32.62 -
   32.63 -Uint64
   32.64 -SDL_GetPerformanceFrequency(void)
   32.65 -{
   32.66 -    return 1000000;
   32.67 -}
   32.68 -
   32.69 -void
   32.70 -SDL_Delay(Uint32 ms)
   32.71 -{
   32.72 -    snooze(ms * 1000);
   32.73 -}
   32.74 -
   32.75 -#endif /* SDL_TIMER_BEOS */
   32.76 -
   32.77 -/* vi: set ts=4 sw=4 expandtab: */
    33.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    33.2 +++ b/src/timer/haiku/SDL_systimer.c	Thu Nov 14 22:35:28 2013 +0530
    33.3 @@ -0,0 +1,74 @@
    33.4 +/*
    33.5 +  Simple DirectMedia Layer
    33.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    33.7 +
    33.8 +  This software is provided 'as-is', without any express or implied
    33.9 +  warranty.  In no event will the authors be held liable for any damages
   33.10 +  arising from the use of this software.
   33.11 +
   33.12 +  Permission is granted to anyone to use this software for any purpose,
   33.13 +  including commercial applications, and to alter it and redistribute it
   33.14 +  freely, subject to the following restrictions:
   33.15 +
   33.16 +  1. The origin of this software must not be misrepresented; you must not
   33.17 +     claim that you wrote the original software. If you use this software
   33.18 +     in a product, an acknowledgment in the product documentation would be
   33.19 +     appreciated but is not required.
   33.20 +  2. Altered source versions must be plainly marked as such, and must not be
   33.21 +     misrepresented as being the original software.
   33.22 +  3. This notice may not be removed or altered from any source distribution.
   33.23 +*/
   33.24 +#include "SDL_config.h"
   33.25 +
   33.26 +#ifdef SDL_TIMER_HAIKU
   33.27 +
   33.28 +#include <os/kernel/OS.h>
   33.29 +
   33.30 +#include "SDL_timer.h"
   33.31 +
   33.32 +static bigtime_t start;
   33.33 +static SDL_bool ticks_started = SDL_FALSE;
   33.34 +
   33.35 +void
   33.36 +SDL_InitTicks(void)
   33.37 +{
   33.38 +    if (ticks_started) {
   33.39 +        return;
   33.40 +    }
   33.41 +    ticks_started = SDL_TRUE;
   33.42 +
   33.43 +    /* Set first ticks value */
   33.44 +    start = system_time();
   33.45 +}
   33.46 +
   33.47 +Uint32
   33.48 +SDL_GetTicks(void)
   33.49 +{
   33.50 +    if (!ticks_started) {
   33.51 +        SDL_InitTicks();
   33.52 +    }
   33.53 +
   33.54 +    return ((system_time() - start) / 1000);
   33.55 +}
   33.56 +
   33.57 +Uint64
   33.58 +SDL_GetPerformanceCounter(void)
   33.59 +{
   33.60 +    return system_time();
   33.61 +}
   33.62 +
   33.63 +Uint64
   33.64 +SDL_GetPerformanceFrequency(void)
   33.65 +{
   33.66 +    return 1000000;
   33.67 +}
   33.68 +
   33.69 +void
   33.70 +SDL_Delay(Uint32 ms)
   33.71 +{
   33.72 +    snooze(ms * 1000);
   33.73 +}
   33.74 +
   33.75 +#endif /* SDL_TIMER_HAIKU */
   33.76 +
   33.77 +/* vi: set ts=4 sw=4 expandtab: */
    34.1 --- a/src/video/SDL_sysvideo.h	Thu Nov 14 22:19:07 2013 +0530
    34.2 +++ b/src/video/SDL_sysvideo.h	Thu Nov 14 22:35:28 2013 +0530
    34.3 @@ -348,8 +348,8 @@
    34.4  #if SDL_VIDEO_DRIVER_WINDOWS
    34.5  extern VideoBootStrap WINDOWS_bootstrap;
    34.6  #endif
    34.7 -#if SDL_VIDEO_DRIVER_BWINDOW
    34.8 -extern VideoBootStrap BWINDOW_bootstrap;
    34.9 +#if SDL_VIDEO_DRIVER_HAIKU
   34.10 +extern VideoBootStrap HAIKU_bootstrap;
   34.11  #endif
   34.12  #if SDL_VIDEO_DRIVER_PANDORA
   34.13  extern VideoBootStrap PND_bootstrap;
    35.1 --- a/src/video/SDL_video.c	Thu Nov 14 22:19:07 2013 +0530
    35.2 +++ b/src/video/SDL_video.c	Thu Nov 14 22:35:28 2013 +0530
    35.3 @@ -65,8 +65,8 @@
    35.4  #if SDL_VIDEO_DRIVER_WINDOWS
    35.5      &WINDOWS_bootstrap,
    35.6  #endif
    35.7 -#if SDL_VIDEO_DRIVER_BWINDOW
    35.8 -    &BWINDOW_bootstrap,
    35.9 +#if SDL_VIDEO_DRIVER_HAIKU
   35.10 +    &HAIKU_bootstrap,
   35.11  #endif
   35.12  #if SDL_VIDEO_DRIVER_PANDORA
   35.13      &PND_bootstrap,
    36.1 --- a/src/video/bwindow/SDL_BWin.h	Thu Nov 14 22:19:07 2013 +0530
    36.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    36.3 @@ -1,636 +0,0 @@
    36.4 -/*
    36.5 -  Simple DirectMedia Layer
    36.6 -  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    36.7 -
    36.8 -  This software is provided 'as-is', without any express or implied
    36.9 -  warranty.  In no event will the authors be held liable for any damages
   36.10 -  arising from the use of this software.
   36.11 -
   36.12 -  Permission is granted to anyone to use this software for any purpose,
   36.13 -  including commercial applications, and to alter it and redistribute it
   36.14 -  freely, subject to the following restrictions:
   36.15 -
   36.16 -  1. The origin of this software must not be misrepresented; you must not
   36.17 -     claim that you wrote the original software. If you use this software
   36.18 -     in a product, an acknowledgment in the product documentation would be
   36.19 -     appreciated but is not required.
   36.20 -  2. Altered source versions must be plainly marked as such, and must not be
   36.21 -     misrepresented as being the original software.
   36.22 -  3. This notice may not be removed or altered from any source distribution.
   36.23 -*/
   36.24 -
   36.25 -#ifndef _SDL_BWin_h
   36.26 -#define _SDL_BWin_h
   36.27 -
   36.28 -#ifdef __cplusplus
   36.29 -extern "C" {
   36.30 -#endif
   36.31 -
   36.32 -#include "SDL_config.h"
   36.33 -#include "SDL.h"
   36.34 -#include "SDL_syswm.h"
   36.35 -#include "SDL_bframebuffer.h"
   36.36 -
   36.37 -#ifdef __cplusplus
   36.38 -}
   36.39 -#endif
   36.40 -
   36.41 -#include <stdio.h>
   36.42 -#include <AppKit.h>
   36.43 -#include <InterfaceKit.h>
   36.44 -#include <be/game/DirectWindow.h>
   36.45 -#if SDL_VIDEO_OPENGL
   36.46 -#include <be/opengl/GLView.h>
   36.47 -#endif
   36.48 -#include "SDL_events.h"
   36.49 -#include "../../main/beos/SDL_BApp.h"
   36.50 -
   36.51 -
   36.52 -enum WinCommands {
   36.53 -    BWIN_MOVE_WINDOW,
   36.54 -    BWIN_RESIZE_WINDOW,
   36.55 -    BWIN_SHOW_WINDOW,
   36.56 -    BWIN_HIDE_WINDOW,
   36.57 -    BWIN_MAXIMIZE_WINDOW,
   36.58 -    BWIN_MINIMIZE_WINDOW,
   36.59 -    BWIN_RESTORE_WINDOW,
   36.60 -    BWIN_SET_TITLE,
   36.61 -    BWIN_SET_BORDERED,
   36.62 -    BWIN_FULLSCREEN
   36.63 -};
   36.64 -
   36.65 -
   36.66 -class SDL_BWin:public BDirectWindow
   36.67 -{
   36.68 -  public:
   36.69 -    /* Constructor/Destructor */
   36.70 -    SDL_BWin(BRect bounds, window_look look, uint32 flags)
   36.71 -        : BDirectWindow(bounds, "Untitled", look, B_NORMAL_WINDOW_FEEL, flags)
   36.72 -    {
   36.73 -        _last_buttons = 0;
   36.74 -
   36.75 -#if SDL_VIDEO_OPENGL
   36.76 -        _SDL_GLView = NULL;
   36.77 -#endif
   36.78 -        _shown = false;
   36.79 -        _inhibit_resize = false;
   36.80 -        _mouse_focused = false;
   36.81 -        _prev_frame = NULL;
   36.82 -
   36.83 -        /* Handle framebuffer stuff */
   36.84 -        _connected = _connection_disabled = false;
   36.85 -        _buffer_created = _buffer_dirty = false;
   36.86 -        _trash_window_buffer = false;
   36.87 -        _buffer_locker = new BLocker();
   36.88 -        _bitmap = NULL;
   36.89 -#ifdef DRAWTHREAD
   36.90 -        _draw_thread_id = spawn_thread(BE_DrawThread, "drawing_thread",
   36.91 -                            B_NORMAL_PRIORITY, (void*) this);
   36.92 -        resume_thread(_draw_thread_id);
   36.93 -#endif
   36.94 -    }
   36.95 -
   36.96 -    virtual ~ SDL_BWin()
   36.97 -    {
   36.98 -        Lock();
   36.99 -        _connection_disabled = true;
  36.100 -        int32 result;
  36.101 -
  36.102 -#if SDL_VIDEO_OPENGL
  36.103 -        if (_SDL_GLView) {
  36.104 -            _SDL_GLView->UnlockGL();
  36.105 -            RemoveChild(_SDL_GLView);   /* Why was this outside the if
  36.106 -                                            statement before? */
  36.107 -        }
  36.108 -
  36.109 -#endif
  36.110 -        Unlock();
  36.111 -#if SDL_VIDEO_OPENGL
  36.112 -        if (_SDL_GLView) {
  36.113 -            delete _SDL_GLView;
  36.114 -        }
  36.115 -#endif
  36.116 -
  36.117 -        /* Clean up framebuffer stuff */
  36.118 -        _buffer_locker->Lock();
  36.119 -#ifdef DRAWTHREAD
  36.120 -        wait_for_thread(_draw_thread_id, &result);
  36.121 -#endif
  36.122 -        free(_clips);
  36.123 -        delete _buffer_locker;
  36.124 -    }
  36.125 -
  36.126 -
  36.127 -    /* * * * * OpenGL functionality * * * * */
  36.128 -#if SDL_VIDEO_OPENGL
  36.129 -    virtual BGLView *CreateGLView(Uint32 gl_flags) {
  36.130 -        Lock();
  36.131 -        if (_SDL_GLView == NULL) {
  36.132 -            _SDL_GLView = new BGLView(Bounds(), "SDL GLView",
  36.133 -                                     B_FOLLOW_ALL_SIDES,
  36.134 -                                     (B_WILL_DRAW | B_FRAME_EVENTS),
  36.135 -                                     gl_flags);
  36.136 -        }
  36.137 -        AddChild(_SDL_GLView);
  36.138 -        _SDL_GLView->EnableDirectMode(true);
  36.139 -        _SDL_GLView->LockGL();  /* "New" GLViews are created */
  36.140 -        Unlock();
  36.141 -        return (_SDL_GLView);
  36.142 -    }
  36.143 -
  36.144 -    virtual void RemoveGLView() {
  36.145 -        Lock();
  36.146 -        if(_SDL_GLView) {
  36.147 -            _SDL_GLView->UnlockGL();
  36.148 -            RemoveChild(_SDL_GLView);
  36.149 -        }
  36.150 -        Unlock();
  36.151 -    }
  36.152 -
  36.153 -    virtual void SwapBuffers(void) {
  36.154 -        _SDL_GLView->UnlockGL();
  36.155 -        _SDL_GLView->LockGL();
  36.156 -        _SDL_GLView->SwapBuffers();
  36.157 -    }
  36.158 -#endif
  36.159 -
  36.160 -    /* * * * * Framebuffering* * * * */
  36.161 -    virtual void DirectConnected(direct_buffer_info *info) {
  36.162 -        if(!_connected && _connection_disabled) {
  36.163 -            return;
  36.164 -        }
  36.165 -
  36.166 -        /* Determine if the pixel buffer is usable after this update */
  36.167 -        _trash_window_buffer =      _trash_window_buffer
  36.168 -                                || ((info->buffer_state & B_BUFFER_RESIZED)
  36.169 -                                || (info->buffer_state & B_BUFFER_RESET)
  36.170 -                                || (info->driver_state == B_MODE_CHANGED));
  36.171 -        LockBuffer();
  36.172 -
  36.173 -        switch(info->buffer_state & B_DIRECT_MODE_MASK) {
  36.174 -        case B_DIRECT_START:
  36.175 -            _connected = true;
  36.176 -
  36.177 -        case B_DIRECT_MODIFY:
  36.178 -            if(_clips) {
  36.179 -                free(_clips);
  36.180 -                _clips = NULL;
  36.181 -            }
  36.182 -
  36.183 -            _num_clips = info->clip_list_count;
  36.184 -            _clips = (clipping_rect *)malloc(_num_clips*sizeof(clipping_rect));
  36.185 -            if(_clips) {
  36.186 -                memcpy(_clips, info->clip_list,
  36.187 -                    _num_clips*sizeof(clipping_rect));
  36.188 -
  36.189 -                _bits = (uint8*) info->bits;
  36.190 -                _row_bytes = info->bytes_per_row;
  36.191 -                _bounds = info->window_bounds;
  36.192 -                _bytes_per_px = info->bits_per_pixel / 8;
  36.193 -                _buffer_dirty = true;
  36.194 -            }
  36.195 -            break;
  36.196 -
  36.197 -        case B_DIRECT_STOP:
  36.198 -            _connected = false;
  36.199 -            break;
  36.200 -        }
  36.201 -#if SDL_VIDEO_OPENGL
  36.202 -        if(_SDL_GLView) {
  36.203 -            _SDL_GLView->DirectConnected(info);
  36.204 -        }
  36.205 -#endif
  36.206 -
  36.207 -
  36.208 -        /* Call the base object directconnected */
  36.209 -        BDirectWindow::DirectConnected(info);
  36.210 -
  36.211 -        UnlockBuffer();
  36.212 -
  36.213 -    }
  36.214 -
  36.215 -
  36.216 -
  36.217 -
  36.218 -    /* * * * * Event sending * * * * */
  36.219 -    /* Hook functions */
  36.220 -    virtual void FrameMoved(BPoint origin) {
  36.221 -        /* Post a message to the BApp so that it can handle the window event */
  36.222 -        BMessage msg(BAPP_WINDOW_MOVED);
  36.223 -        msg.AddInt32("window-x", (int)origin.x);
  36.224 -        msg.AddInt32("window-y", (int)origin.y);
  36.225 -        _PostWindowEvent(msg);
  36.226 -
  36.227 -        /* Perform normal hook operations */
  36.228 -        BDirectWindow::FrameMoved(origin);
  36.229 -    }
  36.230 -
  36.231 -    virtual void FrameResized(float width, float height) {
  36.232 -        /* Post a message to the BApp so that it can handle the window event */
  36.233 -        BMessage msg(BAPP_WINDOW_RESIZED);
  36.234 -
  36.235 -        msg.AddInt32("window-w", (int)width + 1);
  36.236 -        msg.AddInt32("window-h", (int)height + 1);
  36.237 -        _PostWindowEvent(msg);
  36.238 -
  36.239 -        /* Perform normal hook operations */
  36.240 -        BDirectWindow::FrameResized(width, height);
  36.241 -    }
  36.242 -
  36.243 -    virtual bool QuitRequested() {
  36.244 -        BMessage msg(BAPP_WINDOW_CLOSE_REQUESTED);
  36.245 -        _PostWindowEvent(msg);
  36.246 -
  36.247 -        /* We won't allow a quit unless asked by DestroyWindow() */
  36.248 -        return false;
  36.249 -    }
  36.250 -
  36.251 -    virtual void WindowActivated(bool active) {
  36.252 -        BMessage msg(BAPP_KEYBOARD_FOCUS);  /* Mouse focus sold separately */
  36.253 -        _PostWindowEvent(msg);
  36.254 -    }
  36.255 -
  36.256 -    virtual void Zoom(BPoint origin,
  36.257 -                float width,
  36.258 -                float height) {
  36.259 -        BMessage msg(BAPP_MAXIMIZE);    /* Closest thing to maximization Haiku has */
  36.260 -        _PostWindowEvent(msg);
  36.261 -
  36.262 -        /* Before the window zooms, record its size */
  36.263 -        if( !_prev_frame )
  36.264 -            _prev_frame = new BRect(Frame());
  36.265 -
  36.266 -        /* Perform normal hook operations */
  36.267 -        BDirectWindow::Zoom(origin, width, height);
  36.268 -    }
  36.269 -
  36.270 -    /* Member functions */
  36.271 -    virtual void Show() {
  36.272 -        while(IsHidden()) {
  36.273 -            BDirectWindow::Show();
  36.274 -        }
  36.275 -        _shown = true;
  36.276 -
  36.277 -        BMessage msg(BAPP_SHOW);
  36.278 -        _PostWindowEvent(msg);
  36.279 -    }
  36.280 -
  36.281 -    virtual void Hide() {
  36.282 -        BDirectWindow::Hide();
  36.283 -        _shown = false;
  36.284 -
  36.285 -        BMessage msg(BAPP_HIDE);
  36.286 -        _PostWindowEvent(msg);
  36.287 -    }
  36.288 -
  36.289 -    virtual void Minimize(bool minimize) {
  36.290 -        BDirectWindow::Minimize(minimize);
  36.291 -        int32 minState = (minimize ? BAPP_MINIMIZE : BAPP_RESTORE);
  36.292 -
  36.293 -        BMessage msg(minState);
  36.294 -        _PostWindowEvent(msg);
  36.295 -    }
  36.296 -
  36.297 -
  36.298 -    /* BView message interruption */
  36.299 -    virtual void DispatchMessage(BMessage * msg, BHandler * target)
  36.300 -    {
  36.301 -        BPoint where;   /* Used by mouse moved */
  36.302 -        int32 buttons;  /* Used for mouse button events */
  36.303 -        int32 key;      /* Used for key events */
  36.304 -
  36.305 -        switch (msg->what) {
  36.306 -        case B_MOUSE_MOVED:
  36.307 -            int32 transit;
  36.308 -            if (msg->FindPoint("where", &where) == B_OK
  36.309 -                && msg->FindInt32("be:transit", &transit) == B_OK) {
  36.310 -                _MouseMotionEvent(where, transit);
  36.311 -            }
  36.312 -
  36.313 -            /* FIXME: Apparently a button press/release event might be dropped
  36.314 -               if made before before a different button is released.  Does
  36.315 -               B_MOUSE_MOVED have the data needed to check if a mouse button
  36.316 -               state has changed? */
  36.317 -            if (msg->FindInt32("buttons", &buttons) == B_OK) {
  36.318 -                _MouseButtonEvent(buttons);
  36.319 -            }
  36.320 -            break;
  36.321 -
  36.322 -        case B_MOUSE_DOWN:
  36.323 -        case B_MOUSE_UP:
  36.324 -            /* _MouseButtonEvent() detects any and all buttons that may have
  36.325 -               changed state, as well as that button's new state */
  36.326 -            if (msg->FindInt32("buttons", &buttons) == B_OK) {
  36.327 -                _MouseButtonEvent(buttons);
  36.328 -            }
  36.329 -            break;
  36.330 -
  36.331 -        case B_MOUSE_WHEEL_CHANGED:
  36.332 -            float x, y;
  36.333 -            if (msg->FindFloat("be:wheel_delta_x", &x) == B_OK
  36.334 -                && msg->FindFloat("be:wheel_delta_y", &y) == B_OK) {
  36.335 -                    _MouseWheelEvent((int)x, (int)y);
  36.336 -            }
  36.337 -            break;
  36.338 -
  36.339 -        case B_KEY_DOWN:
  36.340 -        case B_UNMAPPED_KEY_DOWN:      /* modifier keys are unmapped */
  36.341 -            if (msg->FindInt32("key", &key) == B_OK) {
  36.342 -                _KeyEvent((SDL_Scancode)key, SDL_PRESSED);
  36.343 -            }
  36.344 -            break;
  36.345 -
  36.346 -        case B_KEY_UP:
  36.347 -        case B_UNMAPPED_KEY_UP:        /* modifier keys are unmapped */
  36.348 -            if (msg->FindInt32("key", &key) == B_OK) {
  36.349 -                _KeyEvent(key, SDL_RELEASED);
  36.350 -            }
  36.351 -            break;
  36.352 -
  36.353 -        default:
  36.354 -            /* move it after switch{} so it's always handled
  36.355 -               that way we keep BeOS feautures like:
  36.356 -               - CTRL+Q to close window (and other shortcuts)
  36.357 -               - PrintScreen to make screenshot into /boot/home
  36.358 -               - etc.. */
  36.359 -            /* BDirectWindow::DispatchMessage(msg, target); */
  36.360 -            break;
  36.361 -        }
  36.362 -
  36.363 -        BDirectWindow::DispatchMessage(msg, target);
  36.364 -    }
  36.365 -
  36.366 -    /* Handle command messages */
  36.367 -    virtual void MessageReceived(BMessage* message) {
  36.368 -        switch (message->what) {
  36.369 -            /* Handle commands from SDL */
  36.370 -            case BWIN_SET_TITLE:
  36.371 -                _SetTitle(message);
  36.372 -                break;
  36.373 -            case BWIN_MOVE_WINDOW:
  36.374 -                _MoveTo(message);
  36.375 -                break;
  36.376 -            case BWIN_RESIZE_WINDOW:
  36.377 -                _ResizeTo(message);
  36.378 -                break;
  36.379 -            case BWIN_SET_BORDERED:
  36.380 -                _SetBordered(message);
  36.381 -                break;
  36.382 -            case BWIN_SHOW_WINDOW:
  36.383 -                Show();
  36.384 -                break;
  36.385 -            case BWIN_HIDE_WINDOW:
  36.386 -                Hide();
  36.387 -                break;
  36.388 -            case BWIN_MAXIMIZE_WINDOW:
  36.389 -                BWindow::Zoom();
  36.390 -                break;
  36.391 -            case BWIN_MINIMIZE_WINDOW:
  36.392 -                Minimize(true);
  36.393 -                break;
  36.394 -            case BWIN_RESTORE_WINDOW:
  36.395 -                _Restore();
  36.396 -                break;
  36.397 -            case BWIN_FULLSCREEN:
  36.398 -                _SetFullScreen(message);
  36.399 -                break;
  36.400 -            default:
  36.401 -                /* Perform normal message handling */
  36.402 -                BDirectWindow::MessageReceived(message);
  36.403 -                break;
  36.404 -        }
  36.405 -
  36.406 -    }
  36.407 -
  36.408 -
  36.409 -
  36.410 -    /* Accessor methods */
  36.411 -    bool IsShown() { return _shown; }
  36.412 -    int32 GetID() { return _id; }
  36.413 -    uint32 GetRowBytes() { return _row_bytes; }
  36.414 -    int32 GetFbX() { return _bounds.left; }
  36.415 -    int32 GetFbY() { return _bounds.top; }
  36.416 -    bool ConnectionEnabled() { return !_connection_disabled; }
  36.417 -    bool Connected() { return _connected; }
  36.418 -    clipping_rect *GetClips() { return _clips; }
  36.419 -    int32 GetNumClips() { return _num_clips; }
  36.420 -    uint8* GetBufferPx() { return _bits; }
  36.421 -    int32 GetBytesPerPx() { return _bytes_per_px; }
  36.422 -    bool CanTrashWindowBuffer() { return _trash_window_buffer; }
  36.423 -    bool BufferExists() { return _buffer_created; }
  36.424 -    bool BufferIsDirty() { return _buffer_dirty; }
  36.425 -    BBitmap *GetBitmap() { return _bitmap; }
  36.426 -#if SDL_VIDEO_OPENGL
  36.427 -    BGLView *GetGLView() { return _SDL_GLView; }
  36.428 -#endif
  36.429 -
  36.430 -    /* Setter methods */
  36.431 -    void SetID(int32 id) { _id = id; }
  36.432 -    void SetBufferExists(bool bufferExists) { _buffer_created = bufferExists; }
  36.433 -    void LockBuffer() { _buffer_locker->Lock(); }
  36.434 -    void UnlockBuffer() { _buffer_locker->Unlock(); }
  36.435 -    void SetBufferDirty(bool bufferDirty) { _buffer_dirty = bufferDirty; }
  36.436 -    void SetTrashBuffer(bool trash) { _trash_window_buffer = trash;     }
  36.437 -    void SetBitmap(BBitmap *bitmap) { _bitmap = bitmap; }
  36.438 -
  36.439 -
  36.440 -private:
  36.441 -    /* Event redirection */
  36.442 -    void _MouseMotionEvent(BPoint &where, int32 transit) {
  36.443 -        if(transit == B_EXITED_VIEW) {
  36.444 -            /* Change mouse focus */
  36.445 -            if(_mouse_focused) {
  36.446 -                _MouseFocusEvent(false);
  36.447 -            }
  36.448 -        } else {
  36.449 -            /* Change mouse focus */
  36.450 -            if (!_mouse_focused) {
  36.451 -                _MouseFocusEvent(true);
  36.452 -            }
  36.453 -            BMessage msg(BAPP_MOUSE_MOVED);
  36.454 -            msg.AddInt32("x", (int)where.x);
  36.455 -            msg.AddInt32("y", (int)where.y);
  36.456 -
  36.457 -            _PostWindowEvent(msg);
  36.458 -        }
  36.459 -    }
  36.460 -
  36.461 -    void _MouseFocusEvent(bool focusGained) {
  36.462 -        _mouse_focused = focusGained;
  36.463 -        BMessage msg(BAPP_MOUSE_FOCUS);
  36.464 -        msg.AddBool("focusGained", focusGained);
  36.465 -        _PostWindowEvent(msg);
  36.466 -
  36.467 -/* FIXME: Why were these here?
  36.468 - if false: be_app->SetCursor(B_HAND_CURSOR);
  36.469 - if true:  SDL_SetCursor(NULL); */
  36.470 -    }
  36.471 -
  36.472 -    void _MouseButtonEvent(int32 buttons) {
  36.473 -        int32 buttonStateChange = buttons ^ _last_buttons;
  36.474 -
  36.475 -        /* Make sure at least one button has changed state */
  36.476 -        if( !(buttonStateChange) ) {
  36.477 -            return;
  36.478 -        }
  36.479 -
  36.480 -        /* Add any mouse button events */
  36.481 -        if(buttonStateChange & B_PRIMARY_MOUSE_BUTTON) {
  36.482 -            _SendMouseButton(SDL_BUTTON_LEFT, buttons &
  36.483 -                B_PRIMARY_MOUSE_BUTTON);
  36.484 -        }
  36.485 -        if(buttonStateChange & B_SECONDARY_MOUSE_BUTTON) {
  36.486 -            _SendMouseButton(SDL_BUTTON_RIGHT, buttons &
  36.487 -                B_PRIMARY_MOUSE_BUTTON);
  36.488 -        }
  36.489 -        if(buttonStateChange & B_TERTIARY_MOUSE_BUTTON) {
  36.490 -            _SendMouseButton(SDL_BUTTON_MIDDLE, buttons &
  36.491 -                B_PRIMARY_MOUSE_BUTTON);
  36.492 -        }
  36.493 -
  36.494 -        _last_buttons = buttons;
  36.495 -    }
  36.496 -
  36.497 -    void _SendMouseButton(int32 button, int32 state) {
  36.498 -        BMessage msg(BAPP_MOUSE_BUTTON);
  36.499 -        msg.AddInt32("button-id", button);
  36.500 -        msg.AddInt32("button-state", state);
  36.501 -        _PostWindowEvent(msg);
  36.502 -    }
  36.503 -
  36.504 -    void _MouseWheelEvent(int32 x, int32 y) {
  36.505 -        /* Create a message to pass along to the BeApp thread */
  36.506 -        BMessage msg(BAPP_MOUSE_WHEEL);
  36.507 -        msg.AddInt32("xticks", x);
  36.508 -        msg.AddInt32("yticks", y);
  36.509 -        _PostWindowEvent(msg);
  36.510 -    }
  36.511 -
  36.512 -    void _KeyEvent(int32 keyCode, int32 keyState) {
  36.513 -        /* Create a message to pass along to the BeApp thread */
  36.514 -        BMessage msg(BAPP_KEY);
  36.515 -        msg.AddInt32("key-state", keyState);
  36.516 -        msg.AddInt32("key-scancode", keyCode);
  36.517 -        be_app->PostMessage(&msg);
  36.518 -        /* Apparently SDL only uses the scancode */
  36.519 -    }
  36.520 -
  36.521 -    void _RepaintEvent() {
  36.522 -        /* Force a repaint: Call the SDL exposed event */
  36.523 -        BMessage msg(BAPP_REPAINT);
  36.524 -        _PostWindowEvent(msg);
  36.525 -    }
  36.526 -    void _PostWindowEvent(BMessage &msg) {
  36.527 -        msg.AddInt32("window-id", _id);
  36.528 -        be_app->PostMessage(&msg);
  36.529 -    }
  36.530 -
  36.531 -    /* Command methods (functions called upon by SDL) */
  36.532 -    void _SetTitle(BMessage *msg) {
  36.533 -        const char *title;
  36.534 -        if(
  36.535 -            msg->FindString("window-title", &title) != B_OK
  36.536 -        ) {
  36.537 -            return;
  36.538 -        }
  36.539 -        SetTitle(title);
  36.540 -    }
  36.541 -
  36.542 -    void _MoveTo(BMessage *msg) {
  36.543 -        int32 x, y;
  36.544 -        if(
  36.545 -            msg->FindInt32("window-x", &x) != B_OK ||
  36.546 -            msg->FindInt32("window-y", &y) != B_OK
  36.547 -        ) {
  36.548 -            return;
  36.549 -        }
  36.550 -        MoveTo(x, y);
  36.551 -    }
  36.552 -
  36.553 -    void _ResizeTo(BMessage *msg) {
  36.554 -        int32 w, h;
  36.555 -        if(
  36.556 -            msg->FindInt32("window-w", &w) != B_OK ||
  36.557 -            msg->FindInt32("window-h", &h) != B_OK
  36.558 -        ) {
  36.559 -            return;
  36.560 -        }
  36.561 -        ResizeTo(w, h);
  36.562 -    }
  36.563 -
  36.564 -    void _SetBordered(BMessage *msg) {
  36.565 -        bool bEnabled;
  36.566 -        if(msg->FindBool("window-border", &bEnabled) != B_OK) {
  36.567 -            return;
  36.568 -        }
  36.569 -        SetLook(bEnabled ? B_BORDERED_WINDOW_LOOK : B_NO_BORDER_WINDOW_LOOK);
  36.570 -    }
  36.571 -
  36.572 -    void _Restore() {
  36.573 -        if(IsMinimized()) {
  36.574 -            Minimize(false);
  36.575 -        } else if(IsHidden()) {
  36.576 -            Show();
  36.577 -        } else if(_prev_frame != NULL) {    /* Zoomed */
  36.578 -            MoveTo(_prev_frame->left, _prev_frame->top);
  36.579 -            ResizeTo(_prev_frame->Width(), _prev_frame->Height());
  36.580 -        }
  36.581 -    }
  36.582 -
  36.583 -    void _SetFullScreen(BMessage *msg) {
  36.584 -        bool fullscreen;
  36.585 -        if(
  36.586 -            msg->FindBool("fullscreen", &fullscreen) != B_OK
  36.587 -        ) {
  36.588 -            return;
  36.589 -        }
  36.590 -        SetFullScreen(fullscreen);
  36.591 -    }
  36.592 -
  36.593 -    /* Members */
  36.594 -#if SDL_VIDEO_OPENGL
  36.595 -    BGLView * _SDL_GLView;
  36.596 -#endif
  36.597 -
  36.598 -    int32 _last_buttons;
  36.599 -    int32 _id;  /* Window id used by SDL_BApp */
  36.600 -    bool  _mouse_focused;       /* Does this window have mouse focus? */
  36.601 -    bool  _shown;
  36.602 -    bool  _inhibit_resize;
  36.603 -
  36.604 -    BRect *_prev_frame; /* Previous position and size of the window */
  36.605 -
  36.606 -    /* Framebuffer members */
  36.607 -    bool            _connected,
  36.608 -                    _connection_disabled,
  36.609 -                    _buffer_created,
  36.610 -                    _buffer_dirty,
  36.611 -                    _trash_window_buffer;
  36.612 -    uint8          *_bits;
  36.613 -    uint32          _row_bytes;
  36.614 -    clipping_rect   _bounds;
  36.615 -    BLocker        *_buffer_locker;
  36.616 -    clipping_rect  *_clips;
  36.617 -    int32           _num_clips;
  36.618 -    int32           _bytes_per_px;
  36.619 -    thread_id       _draw_thread_id;
  36.620 -
  36.621 -    BBitmap        *_bitmap;
  36.622 -};
  36.623 -
  36.624 -
  36.625 -/* FIXME:
  36.626 - * An explanation of framebuffer flags.
  36.627 - *
  36.628 - * _connected -           Original variable used to let the drawing thread know
  36.629 - *                         when changes are being made to the other framebuffer
  36.630 - *                         members.
  36.631 - * _connection_disabled - Used to signal to the drawing thread that the window
  36.632 - *                         is closing, and the thread should exit.
  36.633 - * _buffer_created -      True if the current buffer is valid
  36.634 - * _buffer_dirty -        True if the window should be redrawn.
  36.635 - * _trash_window_buffer - True if the window buffer needs to be trashed partway
  36.636 - *                         through a draw cycle.  Occurs when the previous
  36.637 - *                         buffer provided by DirectConnected() is invalidated.
  36.638 - */
  36.639 -#endif
    37.1 --- a/src/video/bwindow/SDL_bclipboard.cc	Thu Nov 14 22:19:07 2013 +0530
    37.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    37.3 @@ -1,95 +0,0 @@
    37.4 -/*
    37.5 -  Simple DirectMedia Layer
    37.6 -  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    37.7 -
    37.8 -  This software is provided 'as-is', without any express or implied
    37.9 -  warranty.  In no event will the authors be held liable for any damages
   37.10 -  arising from the use of this software.
   37.11 -
   37.12 -  Permission is granted to anyone to use this software for any purpose,
   37.13 -  including commercial applications, and to alter it and redistribute it
   37.14 -  freely, subject to the following restrictions:
   37.15 -
   37.16 -  1. The origin of this software must not be misrepresented; you must not
   37.17 -     claim that you wrote the original software. If you use this software
   37.18 -     in a product, an acknowledgment in the product documentation would be
   37.19 -     appreciated but is not required.
   37.20 -  2. Altered source versions must be plainly marked as such, and must not be
   37.21 -     misrepresented as being the original software.
   37.22 -  3. This notice may not be removed or altered from any source distribution.
   37.23 -*/
   37.24 -#include "SDL_config.h"
   37.25 -
   37.26 -#if SDL_VIDEO_DRIVER_BWINDOW
   37.27 -
   37.28 -/* BWindow based framebuffer implementation */
   37.29 -
   37.30 -#include <unistd.h>
   37.31 -#include <TypeConstants.h>
   37.32 -
   37.33 -#include "SDL_BWin.h"
   37.34 -#include "SDL_timer.h"
   37.35 -#include "../SDL_sysvideo.h"
   37.36 -
   37.37 -#ifdef __cplusplus
   37.38 -extern "C" {
   37.39 -#endif
   37.40 -
   37.41 -int BE_SetClipboardText(_THIS, const char *text) {
   37.42 -	BMessage *clip = NULL;
   37.43 -	if(be_clipboard->Lock()) {
   37.44 -		be_clipboard->Clear();
   37.45 -		if((clip = be_clipboard->Data())) {
   37.46 -			/* Presumably the string of characters is ascii-format */
   37.47 -			ssize_t asciiLength = 0;
   37.48 -			for(; text[asciiLength] != 0; ++asciiLength) {}
   37.49 -			clip->AddData("text/plain", B_MIME_TYPE, &text, asciiLength);
   37.50 -			be_clipboard->Commit();
   37.51 -		}
   37.52 -		be_clipboard->Unlock();
   37.53 -	}
   37.54 -	return 0;
   37.55 -}
   37.56 -
   37.57 -char *BE_GetClipboardText(_THIS) {
   37.58 -	BMessage *clip = NULL;
   37.59 -	const char *text = NULL;	
   37.60 -	ssize_t length;
   37.61 -	char *result;
   37.62 -	if(be_clipboard->Lock()) {
   37.63 -		if((clip = be_clipboard->Data())) {
   37.64 -			/* Presumably the string of characters is ascii-format */
   37.65 -			clip->FindData("text/plain", B_MIME_TYPE, (const void**)&text,
   37.66 -				&length);
   37.67 -		} else {
   37.68 -			be_clipboard->Unlock();
   37.69 -		}
   37.70 -		be_clipboard->Unlock();
   37.71 -	} 
   37.72 -	
   37.73 -	if (!text) {
   37.74 -		result = SDL_strdup("");
   37.75 -	} else {
   37.76 -		/* Copy the data and pass on to SDL */
   37.77 -		result = (char*)SDL_calloc(1, sizeof(char*)*length);
   37.78 -		SDL_strlcpy(result, text, length);
   37.79 -	}
   37.80 -	
   37.81 -	return result;
   37.82 -}
   37.83 -
   37.84 -SDL_bool BE_HasClipboardText(_THIS) {
   37.85 -	SDL_bool result = SDL_FALSE;
   37.86 -	char *text = BE_GetClipboardText(_this);
   37.87 -	if (text) {
   37.88 -		result = text[0] != '\0' ? SDL_TRUE : SDL_FALSE;
   37.89 -		SDL_free(text);
   37.90 -	} 
   37.91 -	return result;
   37.92 -}
   37.93 -
   37.94 -#ifdef __cplusplus
   37.95 -}
   37.96 -#endif
   37.97 -
   37.98 -#endif /* SDL_VIDEO_DRIVER_BWINDOW */
    38.1 --- a/src/video/bwindow/SDL_bclipboard.h	Thu Nov 14 22:19:07 2013 +0530
    38.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    38.3 @@ -1,31 +0,0 @@
    38.4 -/*
    38.5 -  Simple DirectMedia Layer
    38.6 -  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    38.7 -
    38.8 -  This software is provided 'as-is', without any express or implied
    38.9 -  warranty.  In no event will the authors be held liable for any damages
   38.10 -  arising from the use of this software.
   38.11 -
   38.12 -  Permission is granted to anyone to use this software for any purpose,
   38.13 -  including commercial applications, and to alter it and redistribute it
   38.14 -  freely, subject to the following restrictions:
   38.15 -
   38.16 -  1. The origin of this software must not be misrepresented; you must not
   38.17 -     claim that you wrote the original software. If you use this software
   38.18 -     in a product, an acknowledgment in the product documentation would be
   38.19 -     appreciated but is not required.
   38.20 -  2. Altered source versions must be plainly marked as such, and must not be
   38.21 -     misrepresented as being the original software.
   38.22 -  3. This notice may not be removed or altered from any source distribution.
   38.23 -*/
   38.24 -
   38.25 -#include "SDL_config.h"
   38.26 -
   38.27 -#ifndef SDL_BCLIPBOARD_H
   38.28 -#define SDL_BCLIPBOARD_H
   38.29 -
   38.30 -extern int BE_SetClipboardText(_THIS, const char *text);
   38.31 -extern char *BE_GetClipboardText(_THIS);
   38.32 -extern SDL_bool BE_HasClipboardText(_THIS);
   38.33 -
   38.34 -#endif
    39.1 --- a/src/video/bwindow/SDL_bevents.cc	Thu Nov 14 22:19:07 2013 +0530
    39.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    39.3 @@ -1,39 +0,0 @@
    39.4 -/*
    39.5 -  Simple DirectMedia Layer
    39.6 -  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    39.7 -
    39.8 -  This software is provided 'as-is', without any express or implied
    39.9 -  warranty.  In no event will the authors be held liable for any damages
   39.10 -  arising from the use of this software.
   39.11 -
   39.12 -  Permission is granted to anyone to use this software for any purpose,
   39.13 -  including commercial applications, and to alter it and redistribute it
   39.14 -  freely, subject to the following restrictions:
   39.15 -
   39.16 -  1. The origin of this software must not be misrepresented; you must not
   39.17 -     claim that you wrote the original software. If you use this software
   39.18 -     in a product, an acknowledgment in the product documentation would be
   39.19 -     appreciated but is not required.
   39.20 -  2. Altered source versions must be plainly marked as such, and must not be
   39.21 -     misrepresented as being the original software.
   39.22 -  3. This notice may not be removed or altered from any source distribution.
   39.23 -*/
   39.24 -#include "SDL_config.h"
   39.25 -
   39.26 -#if SDL_VIDEO_DRIVER_BWINDOW
   39.27 -
   39.28 -#include "SDL_bevents.h"
   39.29 -
   39.30 -#ifdef __cplusplus
   39.31 -extern "C" {
   39.32 -#endif
   39.33 -
   39.34 -void BE_PumpEvents(_THIS) {
   39.35 -	/* Since the event thread is its own thread, this isn't really necessary */
   39.36 -}
   39.37 -
   39.38 -#ifdef __cplusplus
   39.39 -}
   39.40 -#endif
   39.41 -
   39.42 -#endif /* SDL_VIDEO_DRIVER_BWINDOW */
    40.1 --- a/src/video/bwindow/SDL_bevents.h	Thu Nov 14 22:19:07 2013 +0530
    40.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    40.3 @@ -1,37 +0,0 @@
    40.4 -/*
    40.5 -  Simple DirectMedia Layer
    40.6 -  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    40.7 -
    40.8 -  This software is provided 'as-is', without any express or implied
    40.9 -  warranty.  In no event will the authors be held liable for any damages
   40.10 -  arising from the use of this software.
   40.11 -
   40.12 -  Permission is granted to anyone to use this software for any purpose,
   40.13 -  including commercial applications, and to alter it and redistribute it
   40.14 -  freely, subject to the following restrictions:
   40.15 -
   40.16 -  1. The origin of this software must not be misrepresented; you must not
   40.17 -     claim that you wrote the original software. If you use this software
   40.18 -     in a product, an acknowledgment in the product documentation would be
   40.19 -     appreciated but is not required.
   40.20 -  2. Altered source versions must be plainly marked as such, and must not be
   40.21 -     misrepresented as being the original software.
   40.22 -  3. This notice may not be removed or altered from any source distribution.
   40.23 -*/
   40.24 -
   40.25 -#ifndef SDL_BEVENTS_H
   40.26 -#define SDL_BEVENTS_H
   40.27 -
   40.28 -#include "../SDL_sysvideo.h"
   40.29 -
   40.30 -#ifdef __cplusplus
   40.31 -extern "C" {
   40.32 -#endif
   40.33 -
   40.34 -extern void BE_PumpEvents(_THIS);
   40.35 -
   40.36 -#ifdef __cplusplus
   40.37 -}
   40.38 -#endif
   40.39 -
   40.40 -#endif
    41.1 --- a/src/video/bwindow/SDL_bframebuffer.cc	Thu Nov 14 22:19:07 2013 +0530
    41.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    41.3 @@ -1,254 +0,0 @@
    41.4 -/*
    41.5 -  Simple DirectMedia Layer
    41.6 -  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    41.7 -
    41.8 -  This software is provided 'as-is', without any express or implied
    41.9 -  warranty.  In no event will the authors be held liable for any damages
   41.10 -  arising from the use of this software.
   41.11 -
   41.12 -  Permission is granted to anyone to use this software for any purpose,
   41.13 -  including commercial applications, and to alter it and redistribute it
   41.14 -  freely, subject to the following restrictions:
   41.15 -
   41.16 -  1. The origin of this software must not be misrepresented; you must not
   41.17 -     claim that you wrote the original software. If you use this software
   41.18 -     in a product, an acknowledgment in the product documentation would be
   41.19 -     appreciated but is not required.
   41.20 -  2. Altered source versions must be plainly marked as such, and must not be
   41.21 -     misrepresented as being the original software.
   41.22 -  3. This notice may not be removed or altered from any source distribution.
   41.23 -*/
   41.24 -#include "SDL_config.h"
   41.25 -
   41.26 -#if SDL_VIDEO_DRIVER_BWINDOW
   41.27 -
   41.28 -#include "SDL_bframebuffer.h"
   41.29 -
   41.30 -#include <AppKit.h>
   41.31 -#include <InterfaceKit.h>
   41.32 -#include "SDL_bmodes.h"
   41.33 -#include "SDL_BWin.h"
   41.34 -
   41.35 -#include "../../main/beos/SDL_BApp.h"
   41.36 -
   41.37 -#ifdef __cplusplus
   41.38 -extern "C" {
   41.39 -#endif
   41.40 -
   41.41 -int32 BE_UpdateOnce(SDL_Window *window);
   41.42 -
   41.43 -static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) {
   41.44 -	return ((SDL_BWin*)(window->driverdata));
   41.45 -}
   41.46 -
   41.47 -static SDL_INLINE SDL_BApp *_GetBeApp() {
   41.48 -	return ((SDL_BApp*)be_app);
   41.49 -}
   41.50 -
   41.51 -int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window,
   41.52 -                                       Uint32 * format,
   41.53 -                                       void ** pixels, int *pitch) {
   41.54 -	SDL_BWin *bwin = _ToBeWin(window);
   41.55 -	BScreen bscreen;
   41.56 -	if(!bscreen.IsValid()) {
   41.57 -		return -1;
   41.58 -	}
   41.59 -
   41.60 -	while(!bwin->Connected()) { snooze(100); }
   41.61 -	
   41.62 -	/* Make sure we have exclusive access to frame buffer data */
   41.63 -	bwin->LockBuffer();
   41.64 -
   41.65 -	/* format */
   41.66 -	display_mode bmode;
   41.67 -	bscreen.GetMode(&bmode);
   41.68 -	int32 bpp = BE_ColorSpaceToBitsPerPixel(bmode.space);
   41.69 -	*format = BE_BPPToSDLPxFormat(bpp);
   41.70 -
   41.71 -	/* Create the new bitmap object */
   41.72 -	BBitmap *bitmap = bwin->GetBitmap();
   41.73 -
   41.74 -	if(bitmap) {
   41.75 -		delete bitmap;
   41.76 -	}
   41.77 -	bitmap = new BBitmap(bwin->Bounds(), (color_space)bmode.space,
   41.78 -			false,	/* Views not accepted */
   41.79 -			true);	/* Contiguous memory required */
   41.80 -			
   41.81 -	if(bitmap->InitCheck() != B_OK) {
   41.82 -		return SDL_SetError("Could not initialize back buffer!\n");
   41.83 -	}
   41.84 -
   41.85 -
   41.86 -	bwin->SetBitmap(bitmap);
   41.87 -	
   41.88 -	/* Set the pixel pointer */
   41.89 -	*pixels = bitmap->Bits();
   41.90 -
   41.91 -	/* pitch = width of window, in bytes */
   41.92 -	*pitch = bitmap->BytesPerRow();
   41.93 -
   41.94 -	bwin->SetBufferExists(true);
   41.95 -	bwin->SetTrashBuffer(false);
   41.96 -	bwin->UnlockBuffer();
   41.97 -	return 0;
   41.98 -}
   41.99 -
  41.100 -
  41.101 -
  41.102 -int BE_UpdateWindowFramebuffer(_THIS, SDL_Window * window,
  41.103 -                                      const SDL_Rect * rects, int numrects) {
  41.104 -	if(!window)
  41.105 -		return 0;
  41.106 -
  41.107 -	SDL_BWin *bwin = _ToBeWin(window);
  41.108 -
  41.109 -#ifdef DRAWTHREAD	
  41.110 -	bwin->LockBuffer();
  41.111 -	bwin->SetBufferDirty(true);
  41.112 -	bwin->UnlockBuffer();
  41.113 -#else
  41.114 -	bwin->SetBufferDirty(true);
  41.115 -	BE_UpdateOnce(window);
  41.116 -#endif
  41.117 -
  41.118 -	return 0;
  41.119 -}
  41.120 -
  41.121 -int32 BE_DrawThread(void *data) {
  41.122 -	SDL_BWin *bwin = (SDL_BWin*)data;
  41.123 -	
  41.124 -	BScreen bscreen;
  41.125 -	if(!bscreen.IsValid()) {
  41.126 -		return -1;
  41.127 -	}
  41.128 -
  41.129 -	while(bwin->ConnectionEnabled()) {
  41.130 -		if( bwin->Connected() && bwin->BufferExists() && bwin->BufferIsDirty() ) {
  41.131 -			bwin->LockBuffer();
  41.132 -			BBitmap *bitmap = NULL;
  41.133 -			bitmap = bwin->GetBitmap();
  41.134 -			int32 windowPitch = bitmap->BytesPerRow();
  41.135 -			int32 bufferPitch = bwin->GetRowBytes();
  41.136 -			uint8 *windowpx;
  41.137 -			uint8 *bufferpx;
  41.138 -
  41.139 -			int32 BPP = bwin->GetBytesPerPx();
  41.140 -			int32 windowSub = bwin->GetFbX() * BPP +
  41.141 -						  bwin->GetFbY() * windowPitch;
  41.142 -			clipping_rect *clips = bwin->GetClips();
  41.143 -			int32 numClips = bwin->GetNumClips();
  41.144 -			int i, y;
  41.145 -
  41.146 -			/* Blit each clipping rectangle */
  41.147 -			bscreen.WaitForRetrace();
  41.148 -			for(i = 0; i < numClips; ++i) {
  41.149 -				clipping_rect rc = clips[i];
  41.150 -				/* Get addresses of the start of each clipping rectangle */
  41.151 -				int32 width = clips[i].right - clips[i].left + 1;
  41.152 -				int32 height = clips[i].bottom - clips[i].top + 1;
  41.153 -				bufferpx = bwin->GetBufferPx() + 
  41.154 -					clips[i].top * bufferPitch + clips[i].left * BPP;
  41.155 -				windowpx = (uint8*)bitmap->Bits() + 
  41.156 -					clips[i].top * windowPitch + clips[i].left * BPP -
  41.157 -					windowSub;
  41.158 -
  41.159 -				/* Copy each row of pixels from the window buffer into the frame
  41.160 -				   buffer */
  41.161 -				for(y = 0; y < height; ++y)
  41.162 -				{
  41.163 -
  41.164 -					if(bwin->CanTrashWindowBuffer()) {
  41.165 -						goto escape;	/* Break out before the buffer is killed */
  41.166 -					}
  41.167 -
  41.168 -					memcpy(bufferpx, windowpx, width * BPP);
  41.169 -					bufferpx += bufferPitch;
  41.170 -					windowpx += windowPitch;
  41.171 -				}
  41.172 -			}
  41.173 -
  41.174 -			bwin->SetBufferDirty(false);
  41.175 -escape:
  41.176 -			bwin->UnlockBuffer();
  41.177 -		} else {
  41.178 -			snooze(16000);
  41.179 -		}
  41.180 -	}
  41.181 -	
  41.182 -	return B_OK;
  41.183 -}
  41.184 -
  41.185 -void BE_DestroyWindowFramebuffer(_THIS, SDL_Window * window) {
  41.186 -	SDL_BWin *bwin = _ToBeWin(window);
  41.187 -	
  41.188 -	bwin->LockBuffer();
  41.189 -	
  41.190 -	/* Free and clear the window buffer */
  41.191 -	BBitmap *bitmap = bwin->GetBitmap();
  41.192 -	delete bitmap;
  41.193 -	bwin->SetBitmap(NULL);
  41.194 -	bwin->SetBufferExists(false);
  41.195 -	bwin->UnlockBuffer();
  41.196 -}
  41.197 -
  41.198 -
  41.199 -/*
  41.200 - * TODO:
  41.201 - * This was written to test if certain errors were caused by threading issues.
  41.202 - * The specific issues have since become rare enough that they may have been
  41.203 - * solved, but I doubt it- they were pretty sporadic before now.
  41.204 - */
  41.205 -int32 BE_UpdateOnce(SDL_Window *window) {
  41.206 -	SDL_BWin *bwin = _ToBeWin(window);
  41.207 -	BScreen bscreen;
  41.208 -	if(!bscreen.IsValid()) {
  41.209 -		return -1;
  41.210 -	}
  41.211 -
  41.212 -	if(bwin->ConnectionEnabled() && bwin->Connected()) {
  41.213 -		bwin->LockBuffer();
  41.214 -		int32 windowPitch = window->surface->pitch;
  41.215 -		int32 bufferPitch = bwin->GetRowBytes();
  41.216 -		uint8 *windowpx;
  41.217 -		uint8 *bufferpx;
  41.218 -
  41.219 -		int32 BPP = bwin->GetBytesPerPx();
  41.220 -		uint8 *windowBaseAddress = (uint8*)window->surface->pixels;
  41.221 -		int32 windowSub = bwin->GetFbX() * BPP +
  41.222 -						  bwin->GetFbY() * windowPitch;
  41.223 -		clipping_rect *clips = bwin->GetClips();
  41.224 -		int32 numClips = bwin->GetNumClips();
  41.225 -		int i, y;
  41.226 -
  41.227 -		/* Blit each clipping rectangle */
  41.228 -		bscreen.WaitForRetrace();
  41.229 -		for(i = 0; i < numClips; ++i) {
  41.230 -			clipping_rect rc = clips[i];
  41.231 -			/* Get addresses of the start of each clipping rectangle */
  41.232 -			int32 width = clips[i].right - clips[i].left + 1;
  41.233 -			int32 height = clips[i].bottom - clips[i].top + 1;
  41.234 -			bufferpx = bwin->GetBufferPx() + 
  41.235 -				clips[i].top * bufferPitch + clips[i].left * BPP;
  41.236 -			windowpx = windowBaseAddress + 
  41.237 -				clips[i].top * windowPitch + clips[i].left * BPP - windowSub;
  41.238 -
  41.239 -			/* Copy each row of pixels from the window buffer into the frame
  41.240 -			   buffer */
  41.241 -			for(y = 0; y < height; ++y)
  41.242 -			{
  41.243 -				memcpy(bufferpx, windowpx, width * BPP);
  41.244 -				bufferpx += bufferPitch;
  41.245 -				windowpx += windowPitch;
  41.246 -			}
  41.247 -		}
  41.248 -		bwin->UnlockBuffer();
  41.249 -	}
  41.250 -	return 0;
  41.251 -}
  41.252 -
  41.253 -#ifdef __cplusplus
  41.254 -}
  41.255 -#endif
  41.256 -
  41.257 -#endif /* SDL_VIDEO_DRIVER_BWINDOW */
    42.1 --- a/src/video/bwindow/SDL_bframebuffer.h	Thu Nov 14 22:19:07 2013 +0530
    42.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    42.3 @@ -1,45 +0,0 @@
    42.4 -/*
    42.5 -  Simple DirectMedia Layer
    42.6 -  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    42.7 -
    42.8 -  This software is provided 'as-is', without any express or implied
    42.9 -  warranty.  In no event will the authors be held liable for any damages
   42.10 -  arising from the use of this software.
   42.11 -
   42.12 -  Permission is granted to anyone to use this software for any purpose,
   42.13 -  including commercial applications, and to alter it and redistribute it
   42.14 -  freely, subject to the following restrictions:
   42.15 -
   42.16 -  1. The origin of this software must not be misrepresented; you must not
   42.17 -     claim that you wrote the original software. If you use this software
   42.18 -     in a product, an acknowledgment in the product documentation would be
   42.19 -     appreciated but is not required.
   42.20 -  2. Altered source versions must be plainly marked as such, and must not be
   42.21 -     misrepresented as being the original software.
   42.22 -  3. This notice may not be removed or altered from any source distribution.
   42.23 -*/
   42.24 -
   42.25 -#ifndef SDL_BFRAMEBUFFER_H
   42.26 -#define SDL_BFRAMEBUFFER_H
   42.27 -#include <SupportDefs.h>
   42.28 -#ifdef __cplusplus
   42.29 -extern "C" {
   42.30 -#endif
   42.31 -
   42.32 -#define DRAWTHREAD
   42.33 -
   42.34 -#include "../SDL_sysvideo.h"
   42.35 -
   42.36 -extern int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window,
   42.37 -                                       Uint32 * format,
   42.38 -                                       void ** pixels, int *pitch);
   42.39 -extern int BE_UpdateWindowFramebuffer(_THIS, SDL_Window * window,
   42.40 -                                       const SDL_Rect * rects, int numrects);
   42.41 -extern void BE_DestroyWindowFramebuffer(_THIS, SDL_Window * window);
   42.42 -extern int32 BE_DrawThread(void *data);
   42.43 -
   42.44 -#ifdef __cplusplus
   42.45 -}
   42.46 -#endif
   42.47 -
   42.48 -#endif
    43.1 --- a/src/video/bwindow/SDL_bkeyboard.cc	Thu Nov 14 22:19:07 2013 +0530
    43.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    43.3 @@ -1,188 +0,0 @@
    43.4 -/*
    43.5 -  Simple DirectMedia Layer
    43.6 -  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    43.7 -
    43.8 -  This software is provided 'as-is', without any express or implied
    43.9 -  warranty.  In no event will the authors be held liable for any damages
   43.10 -  arising from the use of this software.
   43.11 -
   43.12 -  Permission is granted to anyone to use this software for any purpose,
   43.13 -  including commercial applications, and to alter it and redistribute it
   43.14 -  freely, subject to the following restrictions:
   43.15 -
   43.16 -  1. The origin of this software must not be misrepresented; you must not
   43.17 -     claim that you wrote the original software. If you use this software
   43.18 -     in a product, an acknowledgment in the product documentation would be
   43.19 -     appreciated but is not required.
   43.20 -  2. Altered source versions must be plainly marked as such, and must not be
   43.21 -     misrepresented as being the original software.
   43.22 -  3. This notice may not be removed or altered from any source distribution.
   43.23 -*/
   43.24 -#include "SDL_config.h"
   43.25 -
   43.26 -#if SDL_VIDEO_DRIVER_BWINDOW
   43.27 -
   43.28 -#include <SupportDefs.h>
   43.29 -#include <support/UTF8.h>
   43.30 -
   43.31 -#ifdef __cplusplus
   43.32 -extern "C" {
   43.33 -#endif
   43.34 -
   43.35 -#include "SDL_events.h"
   43.36 -#include "SDL_keycode.h"
   43.37 -
   43.38 -#include "SDL_bkeyboard.h"
   43.39 -
   43.40 -
   43.41 -#define KEYMAP_SIZE 128
   43.42 -
   43.43 -
   43.44 -static SDL_Scancode keymap[KEYMAP_SIZE];
   43.45 -static int8 keystate[KEYMAP_SIZE];
   43.46 -
   43.47 -void BE_InitOSKeymap() {
   43.48 -		for( uint i = 0; i < SDL_TABLESIZE(keymap); ++i ) {
   43.49 -			keymap[i] = SDL_SCANCODE_UNKNOWN;
   43.50 -		}
   43.51 -
   43.52 -		for( uint i = 0; i < KEYMAP_SIZE; ++i ) {
   43.53 -			keystate[i] = SDL_RELEASED;
   43.54 -		}
   43.55 -
   43.56 -		keymap[0x01]		= SDL_GetScancodeFromKey(SDLK_ESCAPE);
   43.57 -		keymap[B_F1_KEY]	= SDL_GetScancodeFromKey(SDLK_F1);
   43.58 -		keymap[B_F2_KEY]	= SDL_GetScancodeFromKey(SDLK_F2);
   43.59 -		keymap[B_F3_KEY]	= SDL_GetScancodeFromKey(SDLK_F3);
   43.60 -		keymap[B_F4_KEY]	= SDL_GetScancodeFromKey(SDLK_F4);
   43.61 -		keymap[B_F5_KEY]	= SDL_GetScancodeFromKey(SDLK_F5);
   43.62 -		keymap[B_F6_KEY]	= SDL_GetScancodeFromKey(SDLK_F6);
   43.63 -		keymap[B_F7_KEY]	= SDL_GetScancodeFromKey(SDLK_F7);
   43.64 -		keymap[B_F8_KEY]	= SDL_GetScancodeFromKey(SDLK_F8);
   43.65 -		keymap[B_F9_KEY]	= SDL_GetScancodeFromKey(SDLK_F9);
   43.66 -		keymap[B_F10_KEY]	= SDL_GetScancodeFromKey(SDLK_F10);
   43.67 -		keymap[B_F11_KEY]	= SDL_GetScancodeFromKey(SDLK_F11);
   43.68 -		keymap[B_F12_KEY]	= SDL_GetScancodeFromKey(SDLK_F12);
   43.69 -		keymap[B_PRINT_KEY]	= SDL_GetScancodeFromKey(SDLK_PRINTSCREEN);
   43.70 -		keymap[B_SCROLL_KEY]	= SDL_GetScancodeFromKey(SDLK_SCROLLLOCK);
   43.71 -		keymap[B_PAUSE_KEY]	= SDL_GetScancodeFromKey(SDLK_PAUSE);
   43.72 -		keymap[0x11]		= SDL_GetScancodeFromKey(SDLK_BACKQUOTE);
   43.73 -		keymap[0x12]		= SDL_GetScancodeFromKey(SDLK_1);
   43.74 -		keymap[0x13]		= SDL_GetScancodeFromKey(SDLK_2);
   43.75 -		keymap[0x14]		= SDL_GetScancodeFromKey(SDLK_3);
   43.76 -		keymap[0x15]		= SDL_GetScancodeFromKey(SDLK_4);
   43.77 -		keymap[0x16]		= SDL_GetScancodeFromKey(SDLK_5);
   43.78 -		keymap[0x17]		= SDL_GetScancodeFromKey(SDLK_6);
   43.79 -		keymap[0x18]		= SDL_GetScancodeFromKey(SDLK_7);
   43.80 -		keymap[0x19]		= SDL_GetScancodeFromKey(SDLK_8);
   43.81 -		keymap[0x1a]		= SDL_GetScancodeFromKey(SDLK_9);
   43.82 -		keymap[0x1b]		= SDL_GetScancodeFromKey(SDLK_0);
   43.83 -		keymap[0x1c]		= SDL_GetScancodeFromKey(SDLK_MINUS);
   43.84 -		keymap[0x1d]		= SDL_GetScancodeFromKey(SDLK_EQUALS);
   43.85 -		keymap[0x1e]		= SDL_GetScancodeFromKey(SDLK_BACKSPACE);
   43.86 -		keymap[0x1f]		= SDL_GetScancodeFromKey(SDLK_INSERT);
   43.87 -		keymap[0x20]		= SDL_GetScancodeFromKey(SDLK_HOME);
   43.88 -		keymap[0x21]		= SDL_GetScancodeFromKey(SDLK_PAGEUP);
   43.89 -		keymap[0x22]		= SDL_GetScancodeFromKey(SDLK_NUMLOCKCLEAR);
   43.90 -		keymap[0x23]		= SDL_GetScancodeFromKey(SDLK_KP_DIVIDE);
   43.91 -		keymap[0x24]		= SDL_GetScancodeFromKey(SDLK_KP_MULTIPLY);
   43.92 -		keymap[0x25]		= SDL_GetScancodeFromKey(SDLK_KP_MINUS);
   43.93 -		keymap[0x26]		= SDL_GetScancodeFromKey(SDLK_TAB);
   43.94 -		keymap[0x27]		= SDL_GetScancodeFromKey(SDLK_q);
   43.95 -		keymap[0x28]		= SDL_GetScancodeFromKey(SDLK_w);
   43.96 -		keymap[0x29]		= SDL_GetScancodeFromKey(SDLK_e);
   43.97 -		keymap[0x2a]		= SDL_GetScancodeFromKey(SDLK_r);
   43.98 -		keymap[0x2b]		= SDL_GetScancodeFromKey(SDLK_t);
   43.99 -		keymap[0x2c]		= SDL_GetScancodeFromKey(SDLK_y);
  43.100 -		keymap[0x2d]		= SDL_GetScancodeFromKey(SDLK_u);
  43.101 -		keymap[0x2e]		= SDL_GetScancodeFromKey(SDLK_i);
  43.102 -		keymap[0x2f]		= SDL_GetScancodeFromKey(SDLK_o);
  43.103 -		keymap[0x30]		= SDL_GetScancodeFromKey(SDLK_p);
  43.104 -		keymap[0x31]		= SDL_GetScancodeFromKey(SDLK_LEFTBRACKET);
  43.105 -		keymap[0x32]		= SDL_GetScancodeFromKey(SDLK_RIGHTBRACKET);
  43.106 -		keymap[0x33]		= SDL_GetScancodeFromKey(SDLK_BACKSLASH);
  43.107 -		keymap[0x34]		= SDL_GetScancodeFromKey(SDLK_DELETE);
  43.108 -		keymap[0x35]		= SDL_GetScancodeFromKey(SDLK_END);
  43.109 -		keymap[0x36]		= SDL_GetScancodeFromKey(SDLK_PAGEDOWN);
  43.110 -		keymap[0x37]		= SDL_GetScancodeFromKey(SDLK_KP_7);
  43.111 -		keymap[0x38]		= SDL_GetScancodeFromKey(SDLK_KP_8);
  43.112 -		keymap[0x39]		= SDL_GetScancodeFromKey(SDLK_KP_9);
  43.113 -		keymap[0x3a]		= SDL_GetScancodeFromKey(SDLK_KP_PLUS);
  43.114 -		keymap[0x3b]		= SDL_GetScancodeFromKey(SDLK_CAPSLOCK);
  43.115 -		keymap[0x3c]		= SDL_GetScancodeFromKey(SDLK_a);
  43.116 -		keymap[0x3d]		= SDL_GetScancodeFromKey(SDLK_s);
  43.117 -		keymap[0x3e]		= SDL_GetScancodeFromKey(SDLK_d);
  43.118 -		keymap[0x3f]		= SDL_GetScancodeFromKey(SDLK_f);
  43.119 -		keymap[0x40]		= SDL_GetScancodeFromKey(SDLK_g);
  43.120 -		keymap[0x41]		= SDL_GetScancodeFromKey(SDLK_h);
  43.121 -		keymap[0x42]		= SDL_GetScancodeFromKey(SDLK_j);
  43.122 -		keymap[0x43]		= SDL_GetScancodeFromKey(SDLK_k);
  43.123 -		keymap[0x44]		= SDL_GetScancodeFromKey(SDLK_l);
  43.124 -		keymap[0x45]		= SDL_GetScancodeFromKey(SDLK_SEMICOLON);
  43.125 -		keymap[0x46]		= SDL_GetScancodeFromKey(SDLK_QUOTE);
  43.126 -		keymap[0x47]		= SDL_GetScancodeFromKey(SDLK_RETURN);
  43.127 -		keymap[0x48]		= SDL_GetScancodeFromKey(SDLK_KP_4);
  43.128 -		keymap[0x49]		= SDL_GetScancodeFromKey(SDLK_KP_5);
  43.129 -		keymap[0x4a]		= SDL_GetScancodeFromKey(SDLK_KP_6);
  43.130 -		keymap[0x4b]		= SDL_GetScancodeFromKey(SDLK_LSHIFT);
  43.131 -		keymap[0x4c]		= SDL_GetScancodeFromKey(SDLK_z);
  43.132 -		keymap[0x4d]		= SDL_GetScancodeFromKey(SDLK_x);
  43.133 -		keymap[0x4e]		= SDL_GetScancodeFromKey(SDLK_c);
  43.134 -		keymap[0x4f]		= SDL_GetScancodeFromKey(SDLK_v);
  43.135 -		keymap[0x50]		= SDL_GetScancodeFromKey(SDLK_b);
  43.136 -		keymap[0x51]		= SDL_GetScancodeFromKey(SDLK_n);
  43.137 -		keymap[0x52]		= SDL_GetScancodeFromKey(SDLK_m);
  43.138 -		keymap[0x53]		= SDL_GetScancodeFromKey(SDLK_COMMA);
  43.139 -		keymap[0x54]		= SDL_GetScancodeFromKey(SDLK_PERIOD);
  43.140 -		keymap[0x55]		= SDL_GetScancodeFromKey(SDLK_SLASH);
  43.141 -		keymap[0x56]		= SDL_GetScancodeFromKey(SDLK_RSHIFT);
  43.142 -		keymap[0x57]		= SDL_GetScancodeFromKey(SDLK_UP);
  43.143 -		keymap[0x58]		= SDL_GetScancodeFromKey(SDLK_KP_1);
  43.144 -		keymap[0x59]		= SDL_GetScancodeFromKey(SDLK_KP_2);
  43.145 -		keymap[0x5a]		= SDL_GetScancodeFromKey(SDLK_KP_3);
  43.146 -		keymap[0x5b]		= SDL_GetScancodeFromKey(SDLK_KP_ENTER);
  43.147 -		keymap[0x5c]		= SDL_GetScancodeFromKey(SDLK_LCTRL);
  43.148 -		keymap[0x5d]		= SDL_GetScancodeFromKey(SDLK_LALT);
  43.149 -		keymap[0x5e]		= SDL_GetScancodeFromKey(SDLK_SPACE);
  43.150 -		keymap[0x5f]		= SDL_GetScancodeFromKey(SDLK_RALT);
  43.151 -		keymap[0x60]		= SDL_GetScancodeFromKey(SDLK_RCTRL);
  43.152 -		keymap[0x61]		= SDL_GetScancodeFromKey(SDLK_LEFT);
  43.153 -		keymap[0x62]		= SDL_GetScancodeFromKey(SDLK_DOWN);
  43.154 -		keymap[0x63]		= SDL_GetScancodeFromKey(SDLK_RIGHT);
  43.155 -		keymap[0x64]		= SDL_GetScancodeFromKey(SDLK_KP_0);
  43.156 -		keymap[0x65]		= SDL_GetScancodeFromKey(SDLK_KP_PERIOD);
  43.157 -		keymap[0x66]		= SDL_GetScancodeFromKey(SDLK_LGUI);
  43.158 -		keymap[0x67]		= SDL_GetScancodeFromKey(SDLK_RGUI);
  43.159 -		keymap[0x68]		= SDL_GetScancodeFromKey(SDLK_MENU);
  43.160 -		keymap[0x69]		= SDL_GetScancodeFromKey(SDLK_2); /* SDLK_EURO */
  43.161 -		keymap[0x6a]		= SDL_GetScancodeFromKey(SDLK_KP_EQUALS);
  43.162 -		keymap[0x6b]		= SDL_GetScancodeFromKey(SDLK_POWER);
  43.163 -}
  43.164 -
  43.165 -SDL_Scancode BE_GetScancodeFromBeKey(int32 bkey) {
  43.166 -	if(bkey > 0 && bkey < (int32)SDL_TABLESIZE(keymap)) {
  43.167 -		return keymap[bkey];
  43.168 -	} else {
  43.169 -		return SDL_SCANCODE_UNKNOWN;
  43.170 -	}
  43.171 -}
  43.172 -
  43.173 -int8 BE_GetKeyState(int32 bkey) {
  43.174 -	if(bkey > 0 && bkey < KEYMAP_SIZE) {
  43.175 -		return keystate[bkey];
  43.176 -	} else {
  43.177 -		return SDL_RELEASED;
  43.178 -	}
  43.179 -}
  43.180 -
  43.181 -void BE_SetKeyState(int32 bkey, int8 state) {
  43.182 -	if(bkey > 0 && bkey < KEYMAP_SIZE) {
  43.183 -		keystate[bkey] = state;
  43.184 -	}
  43.185 -}
  43.186 -
  43.187 -#ifdef __cplusplus
  43.188 -}
  43.189 -#endif
  43.190 -
  43.191 -#endif /* SDL_VIDEO_DRIVER_BWINDOW */
    44.1 --- a/src/video/bwindow/SDL_bkeyboard.h	Thu Nov 14 22:19:07 2013 +0530
    44.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    44.3 @@ -1,42 +0,0 @@
    44.4 -/*
    44.5 -  Simple DirectMedia Layer
    44.6 -  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    44.7 -
    44.8 -  This software is provided 'as-is', without any express or implied
    44.9 -  warranty.  In no event will the authors be held liable for any damages
   44.10 -  arising from the use of this software.
   44.11 -
   44.12 -  Permission is granted to anyone to use this software for any purpose,
   44.13 -  including commercial applications, and to alter it and redistribute it
   44.14 -  freely, subject to the following restrictions:
   44.15 -
   44.16 -  1. The origin of this software must not be misrepresented; you must not
   44.17 -     claim that you wrote the original software. If you use this software
   44.18 -     in a product, an acknowledgment in the product documentation would be
   44.19 -     appreciated but is not required.
   44.20 -  2. Altered source versions must be plainly marked as such, and must not be
   44.21 -     misrepresented as being the original software.
   44.22 -  3. This notice may not be removed or altered from any source distribution.
   44.23 -*/
   44.24 -
   44.25 -#ifndef SDL_BKEYBOARD_H
   44.26 -#define SDL_BKEYBOARD_H
   44.27 -
   44.28 -#include <SupportDefs.h>
   44.29 -
   44.30 -#ifdef __cplusplus
   44.31 -extern "C" {
   44.32 -#endif
   44.33 -
   44.34 -#include "../../../include/SDL_keyboard.h"
   44.35 -
   44.36 -extern void BE_InitOSKeymap();
   44.37 -extern SDL_Scancode BE_GetScancodeFromBeKey(int32 bkey);
   44.38 -extern int8 BE_GetKeyState(int32 bkey);
   44.39 -extern void BE_SetKeyState(int32 bkey, int8 state);
   44.40 -
   44.41 -#ifdef __cplusplus
   44.42 -}
   44.43 -#endif
   44.44 -
   44.45 -#endif
    45.1 --- a/src/video/bwindow/SDL_bmodes.cc	Thu Nov 14 22:19:07 2013 +0530
    45.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    45.3 @@ -1,331 +0,0 @@
    45.4 -/*
    45.5 -  Simple DirectMedia Layer
    45.6 -  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    45.7 -
    45.8 -  This software is provided 'as-is', without any express or implied
    45.9 -  warranty.  In no event will the authors be held liable for any damages
   45.10 -  arising from the use of this software.
   45.11 -
   45.12 -  Permission is granted to anyone to use this software for any purpose,
   45.13 -  including commercial applications, and to alter it and redistribute it
   45.14 -  freely, subject to the following restrictions:
   45.15 -
   45.16 -  1. The origin of this software must not be misrepresented; you must not
   45.17 -     claim that you wrote the original software. If you use this software
   45.18 -     in a product, an acknowledgment in the product documentation would be
   45.19 -     appreciated but is not required.
   45.20 -  2. Altered source versions must be plainly marked as such, and must not be
   45.21 -     misrepresented as being the original software.
   45.22 -  3. This notice may not be removed or altered from any source distribution.
   45.23 -*/
   45.24 -#include "SDL_config.h"
   45.25 -
   45.26 -#if SDL_VIDEO_DRIVER_BWINDOW
   45.27 -
   45.28 -#include <AppKit.h>
   45.29 -#include <InterfaceKit.h>
   45.30 -#include "SDL_bmodes.h"
   45.31 -#include "SDL_BWin.h"
   45.32 -
   45.33 -#if SDL_VIDEO_OPENGL
   45.34 -#include "SDL_bopengl.h"
   45.35 -#endif
   45.36 -
   45.37 -#include "../../main/beos/SDL_BApp.h"
   45.38 -
   45.39 -#ifdef __cplusplus
   45.40 -extern "C" {
   45.41 -#endif
   45.42 -
   45.43 -
   45.44 -#define WRAP_BMODE 1 /* FIXME: Some debate as to whether this is necessary */
   45.45 -
   45.46 -#if WRAP_BMODE
   45.47 -/* This wrapper is here so that the driverdata can be freed without freeing
   45.48 -   the display_mode structure */
   45.49 -typedef struct SDL_DisplayModeData {
   45.50 -	display_mode *bmode;
   45.51 -};
   45.52 -#endif
   45.53 -
   45.54 -static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) {
   45.55 -	return ((SDL_BWin*)(window->driverdata));
   45.56 -}
   45.57 -
   45.58 -static SDL_INLINE SDL_BApp *_GetBeApp() {
   45.59 -	return ((SDL_BApp*)be_app);
   45.60 -}
   45.61 -
   45.62 -static SDL_INLINE display_mode * _ExtractBMode(SDL_DisplayMode *mode) {
   45.63 -#if WRAP_BMODE
   45.64 -	return ((SDL_DisplayModeData*)mode->driverdata)->bmode;
   45.65 -#else
   45.66 -	return (display_mode*)(mode->driverdata);
   45.67 -#endif
   45.68 -}
   45.69 -
   45.70 -/* Copied from haiku/trunk/src/preferences/screen/ScreenMode.cpp */
   45.71 -static float get_refresh_rate(display_mode &mode) {
   45.72 -	return float(mode.timing.pixel_clock * 1000)
   45.73 -		/ float(mode.timing.h_total * mode.timing.v_total);
   45.74 -}
   45.75 -
   45.76 -
   45.77 -#if 0
   45.78 -/* TODO:
   45.79 - * This is a useful debugging tool.  Uncomment and insert into code as needed.
   45.80 - */
   45.81 -void _SpoutModeData(display_mode *bmode) {
   45.82 -	printf("BMode:\n");
   45.83 -	printf("\tw,h = (%i,%i)\n", bmode->virtual_width, bmode->virtual_height);
   45.84 -	printf("\th,v = (%i,%i)\n", bmode->h_display_start, 
   45.85 -			bmode->v_display_start);
   45.86 -	if(bmode->flags) {
   45.87 -		printf("\tFlags:\n");
   45.88 -		if(bmode->flags & B_SCROLL) {
   45.89 -			printf("\t\tB_SCROLL\n");
   45.90 -		}
   45.91 -		if(bmode->flags & B_8_BIT_DAC) {
   45.92 -			printf("\t\tB_8_BIT_DAC\n");
   45.93 -		}
   45.94 -		if(bmode->flags & B_HARDWARE_CURSOR) {
   45.95 -			printf("\t\tB_HARDWARE_CURSOR\n");
   45.96 -		}
   45.97 -		if(bmode->flags & B_PARALLEL_ACCESS) {
   45.98 -			printf("\t\tB_PARALLEL_ACCESS\n");
   45.99 -		}
  45.100 -		if(bmode->flags & B_DPMS) {
  45.101 -			printf("\t\tB_DPMS\n");
  45.102 -		}
  45.103 -		if(bmode->flags & B_IO_FB_NA) {
  45.104 -			printf("\t\tB_IO_FB_NA\n");
  45.105 -		}
  45.106 -	}
  45.107 -	printf("\tTiming:\n");
  45.108 -	printf("\t\tpx clock: %i\n", bmode->timing.pixel_clock);
  45.109 -	printf("\t\th - display: %i sync start: %i sync end: %i total: %i\n",
  45.110 -		bmode->timing.h_display, bmode->timing.h_sync_start,
  45.111 -		bmode->timing.h_sync_end, bmode->timing.h_total);
  45.112 -	printf("\t\tv - display: %i sync start: %i sync end: %i total: %i\n",
  45.113 -		bmode->timing.v_display, bmode->timing.v_sync_start,
  45.114 -		bmode->timing.v_sync_end, bmode->timing.v_total);
  45.115 -	if(bmode->timing.flags) {
  45.116 -		printf("\t\tFlags:\n");
  45.117 -		if(bmode->timing.flags & B_BLANK_PEDESTAL) {
  45.118 -			printf("\t\t\tB_BLANK_PEDESTAL\n");
  45.119 -		}
  45.120 -		if(bmode->timing.flags & B_TIMING_INTERLACED) {
  45.121 -			printf("\t\t\tB_TIMING_INTERLACED\n");
  45.122 -		}
  45.123 -		if(bmode->timing.flags & B_POSITIVE_HSYNC) {
  45.124 -			printf("\t\t\tB_POSITIVE_HSYNC\n");
  45.125 -		}
  45.126 -		if(bmode->timing.flags & B_POSITIVE_VSYNC) {
  45.127 -			printf("\t\t\tB_POSITIVE_VSYNC\n");
  45.128 -		}
  45.129 -		if(bmode->timing.flags & B_SYNC_ON_GREEN) {
  45.130 -			printf("\t\t\tB_SYNC_ON_GREEN\n");
  45.131 -		}
  45.132 -	}
  45.133 -}
  45.134 -#endif
  45.135 -
  45.136 -
  45.137 -
  45.138 -int32 BE_ColorSpaceToBitsPerPixel(uint32 colorspace)
  45.139 -{
  45.140 -	int bitsperpixel;
  45.141 -
  45.142 -	bitsperpixel = 0;
  45.143 -	switch (colorspace) {
  45.144 -	    case B_CMAP8:
  45.145 -		bitsperpixel = 8;
  45.146 -		break;
  45.147 -	    case B_RGB15:
  45.148 -	    case B_RGBA15:
  45.149 -	    case B_RGB15_BIG:
  45.150 -	    case B_RGBA15_BIG:
  45.151 -		bitsperpixel = 15;
  45.152 -		break;
  45.153 -	    case B_RGB16:
  45.154 -	    case B_RGB16_BIG:
  45.155 -		bitsperpixel = 16;
  45.156 -		break;
  45.157 -	    case B_RGB32:
  45.158 -	    case B_RGBA32:
  45.159 -	    case B_RGB32_BIG:
  45.160 -	    case B_RGBA32_BIG:
  45.161 -		bitsperpixel = 32;
  45.162 -		break;
  45.163 -	    default:
  45.164 -		break;
  45.165 -	}
  45.166 -	return(bitsperpixel);
  45.167 -}
  45.168 -
  45.169 -int32 BE_BPPToSDLPxFormat(int32 bpp) {
  45.170 -	/* Translation taken from SDL_windowsmodes.c */
  45.171 -	switch (bpp) {
  45.172 -	case 32:
  45.173 -		return SDL_PIXELFORMAT_RGB888;
  45.174 -		break;
  45.175 -	case 24:	/* May not be supported by Haiku */
  45.176 -		return SDL_PIXELFORMAT_RGB24;
  45.177 -		break;
  45.178 -	case 16:
  45.179 -		return SDL_PIXELFORMAT_RGB565;
  45.180 -		break;
  45.181 -	case 15:
  45.182 -		return SDL_PIXELFORMAT_RGB555;
  45.183 -		break;
  45.184 -	case 8:
  45.185 -		return SDL_PIXELFORMAT_INDEX8;
  45.186 -		break;
  45.187 -	case 4:		/* May not be supported by Haiku */
  45.188 -		return SDL_PIXELFORMAT_INDEX4LSB;
  45.189 -		break;
  45.190 -	}
  45.191 -
  45.192 -	/* May never get here, but safer and needed to shut up compiler */
  45.193 -	SDL_SetError("Invalid bpp value");
  45.194 -	return 0;       
  45.195 -}
  45.196 -
  45.197 -static void _BDisplayModeToSdlDisplayMode(display_mode *bmode,
  45.198 -		SDL_DisplayMode *mode) {
  45.199 -	mode->w = bmode->virtual_width;
  45.200 -	mode->h = bmode->virtual_height;
  45.201 -	mode->refresh_rate = (int)get_refresh_rate(*bmode);
  45.202 -
  45.203 -#if WRAP_BMODE
  45.204 -	SDL_DisplayModeData *data = (SDL_DisplayModeData*)SDL_calloc(1,
  45.205 -		sizeof(SDL_DisplayModeData));
  45.206 -	data->bmode = bmode;
  45.207 -	
  45.208 -	mode->driverdata = data;
  45.209 -
  45.210 -#else
  45.211 -
  45.212 -	mode->driverdata = bmode;
  45.213 -#endif
  45.214 -
  45.215 -	/* Set the format */
  45.216 -	int32 bpp = BE_ColorSpaceToBitsPerPixel(bmode->space);
  45.217 -	mode->format = BE_BPPToSDLPxFormat(bpp);
  45.218 -}
  45.219 -
  45.220 -/* Later, there may be more than one monitor available */
  45.221 -static void _AddDisplay(BScreen *screen) {
  45.222 -	SDL_VideoDisplay display;
  45.223 -	SDL_DisplayMode *mode = (SDL_DisplayMode*)SDL_calloc(1,
  45.224 -		sizeof(SDL_DisplayMode));
  45.225 -	display_mode *bmode = (display_mode*)SDL_calloc(1, sizeof(display_mode));
  45.226 -	screen->GetMode(bmode);
  45.227 -
  45.228 -	_BDisplayModeToSdlDisplayMode(bmode, mode);
  45.229 -	
  45.230 -	SDL_zero(display);
  45.231 -	display.desktop_mode = *mode;
  45.232 -	display.current_mode = *mode;
  45.233 -	
  45.234 -	SDL_AddVideoDisplay(&display);
  45.235 -}
  45.236 -
  45.237 -/*
  45.238 - * Functions called by SDL
  45.239 - */
  45.240 -
  45.241 -int BE_InitModes(_THIS) {
  45.242 -	BScreen screen;
  45.243 -
  45.244 -	/* TODO: When Haiku supports multiple display screens, call
  45.245 -	   _AddDisplayScreen() for each of them. */
  45.246 -	_AddDisplay(&screen);
  45.247 -	return 0;
  45.248 -}
  45.249 -
  45.250 -int BE_QuitModes(_THIS) {
  45.251 -	/* FIXME: Nothing really needs to be done here at the moment? */
  45.252 -	return 0;
  45.253 -}
  45.254 -
  45.255 -
  45.256 -int BE_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect) {
  45.257 -	BScreen bscreen;
  45.258 -	BRect rc = bscreen.Frame();
  45.259 -	rect->x = (int)rc.left;
  45.260 -	rect->y = (int)rc.top;
  45.261 -	rect->w = (int)rc.Width() + 1;
  45.262 -	rect->h = (int)rc.Height() + 1;
  45.263 -	return 0;
  45.264 -}
  45.265 -
  45.266 -void BE_GetDisplayModes(_THIS, SDL_VideoDisplay *display) {
  45.267 -	/* Get the current screen */
  45.268 -	BScreen bscreen;
  45.269 -
  45.270 -	/* Iterate through all of the modes */
  45.271 -	SDL_DisplayMode mode;
  45.272 -	display_mode this_bmode;
  45.273 -	display_mode *bmodes;
  45.274 -	uint32 count, i;
  45.275 -	
  45.276 -	/* Get graphics-hardware supported modes */
  45.277 -	bscreen.GetModeList(&bmodes, &count);
  45.278 -	bscreen.GetMode(&this_bmode);
  45.279 -	
  45.280 -	for(i = 0; i < count; ++i) {
  45.281 -		// FIXME: Apparently there are errors with colorspace changes
  45.282 -		if (bmodes[i].space == this_bmode.space) {
  45.283 -			_BDisplayModeToSdlDisplayMode(&bmodes[i], &mode);
  45.284 -			SDL_AddDisplayMode(display, &mode);
  45.285 -		}
  45.286 -	}
  45.287 -	free(bmodes);
  45.288 -}
  45.289 -
  45.290 -
  45.291 -int BE_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode){
  45.292 -	/* Get the current screen */
  45.293 -	BScreen bscreen;
  45.294 -	if(!bscreen.IsValid()) {
  45.295 -		printf(__FILE__": %d - ERROR: BAD SCREEN\n", __LINE__);
  45.296 -	}
  45.297 -
  45.298 -	/* Set the mode using the driver data */
  45.299 -	display_mode *bmode = _ExtractBMode(mode);
  45.300 -
  45.301 -
  45.302 -	/* FIXME: Is the first option always going to be the right one? */
  45.303 -	uint32 c = 0, i;
  45.304 -	display_mode *bmode_list;
  45.305 -	bscreen.GetModeList(&bmode_list, &c);
  45.306 -	for(i = 0; i < c; ++i) {
  45.307 -		if(	bmode_list[i].space == bmode->space &&
  45.308 -			bmode_list[i].virtual_width == bmode->virtual_width &&
  45.309 -			bmode_list[i].virtual_height == bmode->virtual_height ) {
  45.310 -				bmode = &bmode_list[i];
  45.311 -				break;
  45.312 -		}
  45.313 -	}
  45.314 -
  45.315 -	if(bscreen.SetMode(bmode) != B_OK) {
  45.316 -		return SDL_SetError("Bad video mode\n");
  45.317 -	}
  45.318 -	
  45.319 -	free(bmode_list);
  45.320 -	
  45.321 -#if SDL_VIDEO_OPENGL
  45.322 -	/* FIXME: Is there some way to reboot the OpenGL context?  This doesn't
  45.323 -	   help */
  45.324 -//	BE_GL_RebootContexts(_this);
  45.325 -#endif
  45.326 -
  45.327 -	return 0;
  45.328 -}
  45.329 -
  45.330 -#ifdef __cplusplus
  45.331 -}
  45.332 -#endif
  45.333 -
  45.334 -#endif /* SDL_VIDEO_DRIVER_BWINDOW */
    46.1 --- a/src/video/bwindow/SDL_bmodes.h	Thu Nov 14 22:19:07 2013 +0530
    46.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    46.3 @@ -1,46 +0,0 @@
    46.4 -/*
    46.5 -  Simple DirectMedia Layer
    46.6 -  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    46.7 -
    46.8 -  This software is provided 'as-is', without any express or implied
    46.9 -  warranty.  In no event will the authors be held liable for any damages
   46.10 -  arising from the use of this software.
   46.11 -
   46.12 -  Permission is granted to anyone to use this software for any purpose,
   46.13 -  including commercial applications, and to alter it and redistribute it
   46.14 -  freely, subject to the following restrictions:
   46.15 -
   46.16 -  1. The origin of this software must not be misrepresented; you must not
   46.17 -     claim that you wrote the original software. If you use this software
   46.18 -     in a product, an acknowledgment in the product documentation would be
   46.19 -     appreciated but is not required.
   46.20 -  2. Altered source versions must be plainly marked as such, and must not be
   46.21 -     misrepresented as being the original software.
   46.22 -  3. This notice may not be removed or altered from any source distribution.
   46.23 -*/
   46.24 -
   46.25 -#ifndef SDL_BMODES_H
   46.26 -#define SDL_BMODES_H
   46.27 -
   46.28 -#ifdef __cplusplus
   46.29 -extern "C" {
   46.30 -#endif
   46.31 -
   46.32 -#include "../SDL_sysvideo.h"
   46.33 -
   46.34 -extern int32 BE_ColorSpaceToBitsPerPixel(uint32 colorspace);
   46.35 -extern int32 BE_BPPToSDLPxFormat(int32 bpp);
   46.36 -
   46.37 -extern int BE_InitModes(_THIS);
   46.38 -extern int BE_QuitModes(_THIS);
   46.39 -extern int BE_GetDisplayBounds(_THIS, SDL_VideoDisplay *display,
   46.40 -    SDL_Rect *rect);
   46.41 -extern void BE_GetDisplayModes(_THIS, SDL_VideoDisplay *display);
   46.42 -extern int BE_SetDisplayMode(_THIS, SDL_VideoDisplay *display,
   46.43 -    SDL_DisplayMode *mode);
   46.44 -
   46.45 -#ifdef __cplusplus
   46.46 -}
   46.47 -#endif
   46.48 -
   46.49 -#endif
    47.1 --- a/src/video/bwindow/SDL_bopengl.cc	Thu Nov 14 22:19:07 2013 +0530
    47.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    47.3 @@ -1,219 +0,0 @@
    47.4 -/*
    47.5 -  Simple DirectMedia Layer
    47.6 -  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    47.7 -
    47.8 -  This software is provided 'as-is', without any express or implied
    47.9 -  warranty.  In no event will the authors be held liable for any damages
   47.10 -  arising from the use of this software.
   47.11 -
   47.12 -  Permission is granted to anyone to use this software for any purpose,
   47.13 -  including commercial applications, and to alter it and redistribute it
   47.14 -  freely, subject to the following restrictions:
   47.15 -
   47.16 -  1. The origin of this software must not be misrepresented; you must not
   47.17 -     claim that you wrote the original software. If you use this software
   47.18 -     in a product, an acknowledgment in the product documentation would be
   47.19 -     appreciated but is not required.
   47.20 -  2. Altered source versions must be plainly marked as such, and must not be
   47.21 -     misrepresented as being the original software.
   47.22 -  3. This notice may not be removed or altered from any source distribution.
   47.23 -*/
   47.24 -#include "SDL_config.h"
   47.25 -
   47.26 -#if SDL_VIDEO_DRIVER_BWINDOW
   47.27 -
   47.28 -#include "SDL_bopengl.h"
   47.29 -
   47.30 -#include <unistd.h>
   47.31 -#include <KernelKit.h>
   47.32 -#include <OpenGLKit.h>
   47.33 -#include "SDL_BWin.h"
   47.34 -#include "../../main/beos/SDL_BApp.h"
   47.35 -
   47.36 -#ifdef __cplusplus
   47.37 -extern "C" {
   47.38 -#endif
   47.39 -
   47.40 -
   47.41 -#define BGL_FLAGS BGL_RGB | BGL_DOUBLE
   47.42 -
   47.43 -static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) {
   47.44 -	return ((SDL_BWin*)(window->driverdata));
   47.45 -}
   47.46 -
   47.47 -static SDL_INLINE SDL_BApp *_GetBeApp() {
   47.48 -	return ((SDL_BApp*)be_app);
   47.49 -}
   47.50 -
   47.51 -/* Passing a NULL path means load pointers from the application */
   47.52 -int BE_GL_LoadLibrary(_THIS, const char *path)
   47.53 -{
   47.54 -/* FIXME: Is this working correctly? */
   47.55 -	image_info info;
   47.56 -			int32 cookie = 0;
   47.57 -	while (get_next_image_info(0, &cookie, &info) == B_OK) {
   47.58 -		void *location = NULL;
   47.59 -		if( get_image_symbol(info.id, "glBegin", B_SYMBOL_TYPE_ANY,
   47.60 -				&location) == B_OK) {
   47.61 -
   47.62 -			_this->gl_config.dll_handle = (void *) info.id;
   47.63 -			_this->gl_config.driver_loaded = 1;
   47.64 -			SDL_strlcpy(_this->gl_config.driver_path, "libGL.so",
   47.65 -					SDL_arraysize(_this->gl_config.driver_path));
   47.66 -		}
   47.67 -	}
   47.68 -	return 0;
   47.69 -}
   47.70 -
   47.71 -void *BE_GL_GetProcAddress(_THIS, const char *proc)
   47.72 -{
   47.73 -	if (_this->gl_config.dll_handle != NULL) {
   47.74 -		void *location = NULL;
   47.75 -		status_t err;
   47.76 -		if ((err =
   47.77 -			get_image_symbol((image_id) _this->gl_config.dll_handle,
   47.78 -                              proc, B_SYMBOL_TYPE_ANY,
   47.79 -                              &location)) == B_OK) {
   47.80 -            return location;
   47.81 -        } else {
   47.82 -                SDL_SetError("Couldn't find OpenGL symbol");
   47.83 -                return NULL;
   47.84 -        }
   47.85 -	} else {
   47.86 -		SDL_SetError("OpenGL library not loaded");
   47.87 -		return NULL;
   47.88 -	}
   47.89 -}
   47.90 -
   47.91 -
   47.92 -
   47.93 -
   47.94 -void BE_GL_SwapWindow(_THIS, SDL_Window * window) {
   47.95 -    _ToBeWin(window)->SwapBuffers();
   47.96 -}
   47.97 -
   47.98 -int BE_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) {
   47.99 -	_GetBeApp()->SetCurrentContext(((SDL_BWin*)context)->GetGLView());
  47.100 -	return 0;
  47.101 -}
  47.102 -
  47.103 -
  47.104 -SDL_GLContext BE_GL_CreateContext(_THIS, SDL_Window * window) {
  47.105 -	/* FIXME: Not sure what flags should be included here; may want to have
  47.106 -	   most of them */
  47.107 -	SDL_BWin *bwin = _ToBeWin(window);
  47.108 -	bwin->CreateGLView(BGL_FLAGS);
  47.109 -	return (SDL_GLContext)(bwin);
  47.110 -}
  47.111 -
  47.112 -void BE_GL_DeleteContext(_THIS, SDL_GLContext context) {
  47.113 -	/* Currently, automatically unlocks the view */
  47.114 -	((SDL_BWin*)context)->RemoveGLView();
  47.115 -}
  47.116 -
  47.117 -
  47.118 -int BE_GL_SetSwapInterval(_THIS, int interval) {
  47.119 -	/* TODO: Implement this, if necessary? */
  47.120 -	return 0;
  47.121 -}
  47.122 -
  47.123 -int BE_GL_GetSwapInterval(_THIS) {
  47.124 -	/* TODO: Implement this, if necessary? */
  47.125 -	return 0;
  47.126 -}
  47.127 -
  47.128 -
  47.129 -void BE_GL_UnloadLibrary(_THIS) {
  47.130 -	/* TODO: Implement this, if necessary? */
  47.131 -}
  47.132 -
  47.133 -
  47.134 -/* FIXME: This function is meant to clear the OpenGL context when the video
  47.135 -   mode changes (see SDL_bmodes.cc), but it doesn't seem to help, and is not
  47.136 -   currently in use. */
  47.137 -void BE_GL_RebootContexts(_THIS) {
  47.138 -	SDL_Window *window = _this->windows;
  47.139 -	while(window) {
  47.140 -		SDL_BWin *bwin = _ToBeWin(window);
  47.141 -		if(bwin->GetGLView()) {
  47.142 -			bwin->LockLooper();
  47.143 -			bwin->RemoveGLView();
  47.144 -			bwin->CreateGLView(BGL_FLAGS);
  47.145 -			bwin->UnlockLooper();
  47.146 -		}
  47.147 -		window = window->next;
  47.148 -	}
  47.149 -}
  47.150 -
  47.151 -
  47.152 -#if 0 /* Functions from 1.2 that do not appear to be used in 1.3 */
  47.153 -
  47.154 -    int BE_GL_GetAttribute(_THIS, SDL_GLattr attrib, int *value)
  47.155 -    {
  47.156 -        /*
  47.157 -           FIXME? Right now BE_GL_GetAttribute shouldn't be called between glBegin() and glEnd() - it doesn't use "cached" values
  47.158 -         */
  47.159 -        switch (attrib) {
  47.160 -        case SDL_GL_RED_SIZE:
  47.161 -            glGetIntegerv(GL_RED_BITS, (GLint *) value);
  47.162 -            break;
  47.163 -        case SDL_GL_GREEN_SIZE:
  47.164 -            glGetIntegerv(GL_GREEN_BITS, (GLint *) value);
  47.165 -            break;
  47.166 -        case SDL_GL_BLUE_SIZE:
  47.167 -            glGetIntegerv(GL_BLUE_BITS, (GLint *) value);
  47.168 -            break;
  47.169 -        case SDL_GL_ALPHA_SIZE:
  47.170 -            glGetIntegerv(GL_ALPHA_BITS, (GLint *) value);
  47.171 -            break;
  47.172 -        case SDL_GL_DOUBLEBUFFER:
  47.173 -            glGetBooleanv(GL_DOUBLEBUFFER, (GLboolean *) value);
  47.174 -            break;
  47.175 -        case SDL_GL_BUFFER_SIZE:
  47.176 -            int v;
  47.177 -            glGetIntegerv(GL_RED_BITS, (GLint *) & v);
  47.178 -            *value = v;
  47.179 -            glGetIntegerv(GL_GREEN_BITS, (GLint *) & v);
  47.180 -            *value += v;
  47.181 -            glGetIntegerv(GL_BLUE_BITS, (GLint *) & v);
  47.182 -            *value += v;
  47.183 -            glGetIntegerv(GL_ALPHA_BITS, (GLint *) & v);
  47.184 -            *value += v;
  47.185 -            break;
  47.186 -        case SDL_GL_DEPTH_SIZE:
  47.187 -            glGetIntegerv(GL_DEPTH_BITS, (GLint *) value);      /* Mesa creates 16 only? r5 always 32 */
  47.188 -            break;
  47.189 -        case SDL_GL_STENCIL_SIZE:
  47.190 -            glGetIntegerv(GL_STENCIL_BITS, (GLint *) value);
  47.191 -            break;
  47.192 -        case SDL_GL_ACCUM_RED_SIZE:
  47.193 -            glGetIntegerv(GL_ACCUM_RED_BITS, (GLint *) value);
  47.194 -            break;
  47.195 -        case SDL_GL_ACCUM_GREEN_SIZE:
  47.196 -            glGetIntegerv(GL_ACCUM_GREEN_BITS, (GLint *) value);
  47.197 -            break;
  47.198 -        case SDL_GL_ACCUM_BLUE_SIZE:
  47.199 -            glGetIntegerv(GL_ACCUM_BLUE_BITS, (GLint *) value);
  47.200 -            break;
  47.201 -        case SDL_GL_ACCUM_ALPHA_SIZE:
  47.202 -            glGetIntegerv(GL_ACCUM_ALPHA_BITS, (GLint *) value);
  47.203 -            break;
  47.204 -        case SDL_GL_STEREO:
  47.205 -        case SDL_GL_MULTISAMPLEBUFFERS:
  47.206 -        case SDL_GL_MULTISAMPLESAMPLES:
  47.207 -        default:
  47.208 -            *value = 0;
  47.209 -            return (-1);
  47.210 -        }
  47.211 -        return 0;
  47.212 -    }
  47.213 -
  47.214 -#endif
  47.215 -
  47.216 -
  47.217 -
  47.218 -#ifdef __cplusplus
  47.219 -}
  47.220 -#endif
  47.221 -
  47.222 -#endif /* SDL_VIDEO_DRIVER_BWINDOW */
    48.1 --- a/src/video/bwindow/SDL_bopengl.h	Thu Nov 14 22:19:07 2013 +0530
    48.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    48.3 @@ -1,49 +0,0 @@
    48.4 -/*
    48.5 -  Simple DirectMedia Layer
    48.6 -  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    48.7 -
    48.8 -  This software is provided 'as-is', without any express or implied
    48.9 -  warranty.  In no event will the authors be held liable for any damages
   48.10 -  arising from the use of this software.
   48.11 -
   48.12 -  Permission is granted to anyone to use this software for any purpose,
   48.13 -  including commercial applications, and to alter it and redistribute it
   48.14 -  freely, subject to the following restrictions:
   48.15 -
   48.16 -  1. The origin of this software must not be misrepresented; you must not
   48.17 -     claim that you wrote the original software. If you use this software
   48.18 -     in a product, an acknowledgment in the product documentation would be
   48.19 -     appreciated but is not required.
   48.20 -  2. Altered source versions must be plainly marked as such, and must not be
   48.21 -     misrepresented as being the original software.
   48.22 -  3. This notice may not be removed or altered from any source distribution.
   48.23 -*/
   48.24 -
   48.25 -#ifndef SDL_BOPENGL_H
   48.26 -#define SDL_BOPENGL_H
   48.27 -
   48.28 -#ifdef __cplusplus
   48.29 -extern "C" {
   48.30 -#endif
   48.31 -
   48.32 -#include "../SDL_sysvideo.h"
   48.33 -
   48.34 -
   48.35 -extern int BE_GL_LoadLibrary(_THIS, const char *path);                  /* FIXME */
   48.36 -extern void *BE_GL_GetProcAddress(_THIS, const char *proc);             /* FIXME */
   48.37 -extern void BE_GL_UnloadLibrary(_THIS);                                 /* TODO */
   48.38 -extern int BE_GL_MakeCurrent(_THIS, SDL_Window * window,
   48.39 -                              SDL_GLContext context);
   48.40 -extern int BE_GL_SetSwapInterval(_THIS, int interval);                  /* TODO */
   48.41 -extern int BE_GL_GetSwapInterval(_THIS);                                /* TODO */
   48.42 -extern void BE_GL_SwapWindow(_THIS, SDL_Window * window);
   48.43 -extern SDL_GLContext BE_GL_CreateContext(_THIS, SDL_Window * window);
   48.44 -extern void BE_GL_DeleteContext(_THIS, SDL_GLContext context);
   48.45 -
   48.46 -extern void BE_GL_RebootContexts(_THIS);
   48.47 -
   48.48 -#ifdef __cplusplus
   48.49 -}
   48.50 -#endif
   48.51 -
   48.52 -#endif
    49.1 --- a/src/video/bwindow/SDL_bvideo.cc	Thu Nov 14 22:19:07 2013 +0530
    49.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    49.3 @@ -1,174 +0,0 @@
    49.4 -/*
    49.5 -  Simple DirectMedia Layer
    49.6 -  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    49.7 -
    49.8 -  This software is provided 'as-is', without any express or implied
    49.9 -  warranty.  In no event will the authors be held liable for any damages
   49.10 -  arising from the use of this software.
   49.11 -
   49.12 -  Permission is granted to anyone to use this software for any purpose,
   49.13 -  including commercial applications, and to alter it and redistribute it
   49.14 -  freely, subject to the following restrictions:
   49.15 -
   49.16 -  1. The origin of this software must not be misrepresented; you must not
   49.17 -     claim that you wrote the original software. If you use this software
   49.18 -     in a product, an acknowledgment in the product documentation would be
   49.19 -     appreciated but is not required.
   49.20 -  2. Altered source versions must be plainly marked as such, and must not be
   49.21 -     misrepresented as being the original software.
   49.22 -  3. This notice may not be removed or altered from any source distribution.
   49.23 -*/
   49.24 -#include "SDL_config.h"
   49.25 -
   49.26 -#if SDL_VIDEO_DRIVER_BWINDOW
   49.27 -
   49.28 -
   49.29 -#ifdef __cplusplus
   49.30 -extern "C" {
   49.31 -#endif
   49.32 -
   49.33 -#include "SDL_bkeyboard.h"
   49.34 -#include "SDL_bwindow.h"
   49.35 -#include "SDL_bclipboard.h"
   49.36 -#include "SDL_bvideo.h"
   49.37 -#include "SDL_bopengl.h"
   49.38 -#include "SDL_bmodes.h"
   49.39 -#include "SDL_bframebuffer.h"
   49.40 -#include "SDL_bevents.h"
   49.41 -
   49.42 -/* FIXME: Undefined functions */
   49.43 -//    #define BE_PumpEvents NULL
   49.44 -    #define BE_StartTextInput NULL
   49.45 -    #define BE_StopTextInput NULL
   49.46 -    #define BE_SetTextInputRect NULL
   49.47 -
   49.48 -//    #define BE_DeleteDevice NULL
   49.49 -
   49.50 -/* End undefined functions */
   49.51 -
   49.52 -static SDL_VideoDevice *
   49.53 -BE_CreateDevice(int devindex)
   49.54 -{
   49.55 -    SDL_VideoDevice *device;
   49.56 -    /*SDL_VideoData *data;*/
   49.57 -
   49.58 -    /* Initialize all variables that we clean on shutdown */
   49.59 -    device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
   49.60 -
   49.61 -    device->driverdata = NULL; /* FIXME: Is this the cause of some of the
   49.62 -    							  SDL_Quit() errors? */
   49.63 -
   49.64 -/* TODO: Figure out if any initialization needs to go here */
   49.65 -
   49.66 -    /* Set the function pointers */
   49.67 -    device->VideoInit = BE_VideoInit;
   49.68 -    device->VideoQuit = BE_VideoQuit;
   49.69 -    device->GetDisplayBounds = BE_GetDisplayBounds;
   49.70 -    device->GetDisplayModes = BE_GetDisplayModes;
   49.71 -    device->SetDisplayMode = BE_SetDisplayMode;
   49.72 -    device->PumpEvents = BE_PumpEvents;
   49.73 -
   49.74 -    device->CreateWindow = BE_CreateWindow;
   49.75 -    device->CreateWindowFrom = BE_CreateWindowFrom;
   49.76 -    device->SetWindowTitle = BE_SetWindowTitle;
   49.77 -    device->SetWindowIcon = BE_SetWindowIcon;
   49.78 -    device->SetWindowPosition = BE_SetWindowPosition;
   49.79 -    device->SetWindowSize = BE_SetWindowSize;
   49.80 -    device->ShowWindow = BE_ShowWindow;
   49.81 -    device->HideWindow = BE_HideWindow;
   49.82 -    device->RaiseWindow = BE_RaiseWindow;
   49.83 -    device->MaximizeWindow = BE_MaximizeWindow;
   49.84 -    device->MinimizeWindow = BE_MinimizeWindow;
   49.85 -    device->RestoreWindow = BE_RestoreWindow;
   49.86 -    device->SetWindowBordered = BE_SetWindowBordered;
   49.87 -    device->SetWindowFullscreen = BE_SetWindowFullscreen;
   49.88 -    device->SetWindowGammaRamp = BE_SetWindowGammaRamp;
   49.89 -    device->GetWindowGammaRamp = BE_GetWindowGammaRamp;
   49.90 -    device->SetWindowGrab = BE_SetWindowGrab;
   49.91 -    device->DestroyWindow = BE_DestroyWindow;
   49.92 -    device->GetWindowWMInfo = BE_GetWindowWMInfo;
   49.93 -    device->CreateWindowFramebuffer = BE_CreateWindowFramebuffer;
   49.94 -    device->UpdateWindowFramebuffer = BE_UpdateWindowFramebuffer;
   49.95 -    device->DestroyWindowFramebuffer = BE_DestroyWindowFramebuffer;
   49.96 -    
   49.97 -    device->shape_driver.CreateShaper = NULL;
   49.98 -    device->shape_driver.SetWindowShape = NULL;
   49.99 -    device->shape_driver.ResizeWindowShape = NULL;
  49.100 -
  49.101 -
  49.102 -    device->GL_LoadLibrary = BE_GL_LoadLibrary;
  49.103 -    device->GL_GetProcAddress = BE_GL_GetProcAddress;
  49.104 -    device->GL_UnloadLibrary = BE_GL_UnloadLibrary;
  49.105 -    device->GL_CreateContext = BE_GL_CreateContext;
  49.106 -    device->GL_MakeCurrent = BE_GL_MakeCurrent;
  49.107 -    device->GL_SetSwapInterval = BE_GL_SetSwapInterval;
  49.108 -    device->GL_GetSwapInterval = BE_GL_GetSwapInterval;
  49.109 -    device->GL_SwapWindow = BE_GL_SwapWindow;
  49.110 -    device->GL_DeleteContext = BE_GL_DeleteContext;
  49.111 -
  49.112 -    device->StartTextInput = BE_StartTextInput;
  49.113 -    device->StopTextInput = BE_StopTextInput;
  49.114 -    device->SetTextInputRect = BE_SetTextInputRect;
  49.115 -
  49.116 -    device->SetClipboardText = BE_SetClipboardText;
  49.117 -    device->GetClipboardText = BE_GetClipboardText;
  49.118 -    device->HasClipboardText = BE_HasClipboardText;
  49.119 -
  49.120 -    device->free = BE_DeleteDevice;
  49.121 -
  49.122 -    return device;
  49.123 -}
  49.124 -
  49.125 -VideoBootStrap BWINDOW_bootstrap = {
  49.126 -	"bwindow", "BDirectWindow graphics",
  49.127 -	BE_Available, BE_CreateDevice
  49.128 -};
  49.129 -
  49.130 -void BE_DeleteDevice(SDL_VideoDevice * device)
  49.131 -{
  49.132 -	SDL_free(device->driverdata);
  49.133 -	SDL_free(device);
  49.134 -}
  49.135 -
  49.136 -int BE_VideoInit(_THIS)
  49.137 -{
  49.138 -	/* Initialize the Be Application for appserver interaction */
  49.139 -	if (SDL_InitBeApp() < 0) {
  49.140 -		return -1;
  49.141 -	}
  49.142 -	
  49.143 -	/* Initialize video modes */
  49.144 -	BE_InitModes(_this);
  49.145 -
  49.146 -	/* Init the keymap */
  49.147 -	BE_InitOSKeymap();
  49.148 -	
  49.149 -	
  49.150 -#if SDL_VIDEO_OPENGL
  49.151 -        /* testgl application doesn't load library, just tries to load symbols */
  49.152 -        /* is it correct? if so we have to load library here */
  49.153 -    BE_GL_LoadLibrary(_this, NULL);
  49.154 -#endif
  49.155 -
  49.156 -        /* We're done! */
  49.157 -    return (0);
  49.158 -}
  49.159 -
  49.160 -int BE_Available(void)
  49.161 -{
  49.162 -    return (1);
  49.163 -}
  49.164 -
  49.165 -void BE_VideoQuit(_THIS)
  49.166 -{
  49.167 -
  49.168 -    BE_QuitModes(_this);
  49.169 -
  49.170 -    SDL_QuitBeApp();
  49.171 -}
  49.172 -
  49.173 -#ifdef __cplusplus
  49.174 -}
  49.175 -#endif
  49.176 -
  49.177 -#endif /* SDL_VIDEO_DRIVER_BWINDOW */
    50.1 --- a/src/video/bwindow/SDL_bvideo.h	Thu Nov 14 22:19:07 2013 +0530
    50.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    50.3 @@ -1,42 +0,0 @@
    50.4 -/*
    50.5 -  Simple DirectMedia Layer
    50.6 -  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    50.7 -
    50.8 -  This software is provided 'as-is', without any express or implied
    50.9 -  warranty.  In no event will the authors be held liable for any damages
   50.10 -  arising from the use of this software.
   50.11 -
   50.12 -  Permission is granted to anyone to use this software for any purpose,
   50.13 -  including commercial applications, and to alter it and redistribute it
   50.14 -  freely, subject to the following restrictions:
   50.15 -
   50.16 -  1. The origin of this software must not be misrepresented; you must not
   50.17 -     claim that you wrote the original software. If you use this software
   50.18 -     in a product, an acknowledgment in the product documentation would be
   50.19 -     appreciated but is not required.
   50.20 -  2. Altered source versions must be plainly marked as such, and must not be
   50.21 -     misrepresented as being the original software.
   50.22 -  3. This notice may not be removed or altered from any source distribution.
   50.23 -*/
   50.24 -
   50.25 -#ifndef BVIDEO_H
   50.26 -#define BVIDEO_H
   50.27 -
   50.28 -#ifdef __cplusplus
   50.29 -extern "C" {
   50.30 -#endif
   50.31 -
   50.32 -#include "../../main/beos/SDL_BeApp.h"
   50.33 -#include "../SDL_sysvideo.h"
   50.34 -
   50.35 -
   50.36 -extern void BE_VideoQuit(_THIS);
   50.37 -extern int BE_VideoInit(_THIS);
   50.38 -extern void BE_DeleteDevice(_THIS);
   50.39 -extern int BE_Available(void);
   50.40 -
   50.41 -#ifdef __cplusplus
   50.42 -}
   50.43 -#endif
   50.44 -
   50.45 -#endif
    51.1 --- a/src/video/bwindow/SDL_bwindow.cc	Thu Nov 14 22:19:07 2013 +0530
    51.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    51.3 @@ -1,223 +0,0 @@
    51.4 -/*
    51.5 -  Simple DirectMedia Layer
    51.6 -  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    51.7 -
    51.8 -  This software is provided 'as-is', without any express or implied
    51.9 -  warranty.  In no event will the authors be held liable for any damages
   51.10 -  arising from the use of this software.
   51.11 -
   51.12 -  Permission is granted to anyone to use this software for any purpose,
   51.13 -  including commercial applications, and to alter it and redistribute it
   51.14 -  freely, subject to the following restrictions:
   51.15 -
   51.16 -  1. The origin of this software must not be misrepresented; you must not
   51.17 -     claim that you wrote the original software. If you use this software
   51.18 -     in a product, an acknowledgment in the product documentation would be
   51.19 -     appreciated but is not required.
   51.20 -  2. Altered source versions must be plainly marked as such, and must not be
   51.21 -     misrepresented as being the original software.
   51.22 -  3. This notice may not be removed or altered from any source distribution.
   51.23 -*/
   51.24 -#include "SDL_config.h"
   51.25 -
   51.26 -#if SDL_VIDEO_DRIVER_BWINDOW
   51.27 -#include "../SDL_sysvideo.h"
   51.28 -
   51.29 -#include "SDL_BWin.h"
   51.30 -#include <new>
   51.31 -
   51.32 -/* Define a path to window's BWIN data */
   51.33 -#ifdef __cplusplus
   51.34 -extern "C" {
   51.35 -#endif
   51.36 -
   51.37 -static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) {
   51.38 -	return ((SDL_BWin*)(window->driverdata));
   51.39 -}
   51.40 -
   51.41 -static SDL_INLINE SDL_BApp *_GetBeApp() {
   51.42 -	return ((SDL_BApp*)be_app);
   51.43 -}
   51.44 -
   51.45 -static int _InitWindow(_THIS, SDL_Window *window) {
   51.46 -	uint32 flags = 0;
   51.47 -	window_look look = B_BORDERED_WINDOW_LOOK;
   51.48 -
   51.49 -	BRect bounds(
   51.50 -        window->x,
   51.51 -        window->y,
   51.52 -        window->x + window->w - 1,	//BeWindows have an off-by-one px w/h thing
   51.53 -        window->y + window->h - 1
   51.54 -    );
   51.55 -    
   51.56 -    if(window->flags & SDL_WINDOW_FULLSCREEN) {
   51.57 -    	/* TODO: Add support for this flag */
   51.58 -    	printf(__FILE__": %d!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n",__LINE__);
   51.59 -    }
   51.60 -    if(window->flags & SDL_WINDOW_OPENGL) {
   51.61 -    	/* TODO: Add support for this flag */
   51.62 -    }
   51.63 -    if(!(window->flags & SDL_WINDOW_RESIZABLE)) {
   51.64 -    	flags |= B_NOT_RESIZABLE | B_NOT_ZOOMABLE;
   51.65 -    }
   51.66 -    if(window->flags & SDL_WINDOW_BORDERLESS) {
   51.67 -    	look = B_NO_BORDER_WINDOW_LOOK;
   51.68 -    }
   51.69 -
   51.70 -    SDL_BWin *bwin = new(std::nothrow) SDL_BWin(bounds, look, flags);
   51.71 -    if(bwin == NULL)
   51.72 -    	return ENOMEM;
   51.73 -
   51.74 -    window->driverdata = bwin;
   51.75 -    int32 winID = _GetBeApp()->GetID(window);
   51.76 -    bwin->SetID(winID);
   51.77 -
   51.78 -    return 0;
   51.79 -}
   51.80 -
   51.81 -int BE_CreateWindow(_THIS, SDL_Window *window) {
   51.82 -	if(_InitWindow(_this, window) == ENOMEM)
   51.83 -		return ENOMEM;
   51.84 -	
   51.85 -	/* Start window loop */
   51.86 -    _ToBeWin(window)->Show();
   51.87 -    return 0;
   51.88 -}
   51.89 -
   51.90 -int BE_CreateWindowFrom(_THIS, SDL_Window * window, const void *data) {
   51.91 -
   51.92 -	SDL_BWin *otherBWin = (SDL_BWin*)data;
   51.93 -	if(!otherBWin->LockLooper())
   51.94 -		return -1;
   51.95 -	
   51.96 -	/* Create the new window and initialize its members */
   51.97 -	window->x = (int)otherBWin->Frame().left;
   51.98 -	window->y = (int)otherBWin->Frame().top;
   51.99 -	window->w = (int)otherBWin->Frame().Width();
  51.100 -	window->h = (int)otherBWin->Frame().Height();
  51.101 -	
  51.102 -	/* Set SDL flags */
  51.103 -	if(!(otherBWin->Flags() & B_NOT_RESIZABLE)) {
  51.104 -		window->flags |= SDL_WINDOW_RESIZABLE;
  51.105 -	}
  51.106 -	
  51.107 -	/* If we are out of memory, return the error code */
  51.108 -	if(_InitWindow(_this, window) == ENOMEM)
  51.109 -		return ENOMEM;
  51.110 -	
  51.111 -	/* TODO: Add any other SDL-supported window attributes here */
  51.112 -    _ToBeWin(window)->SetTitle(otherBWin->Title());
  51.113 -    
  51.114 -    /* Start window loop and unlock the other window */
  51.115 -    _ToBeWin(window)->Show();
  51.116 -    
  51.117 -    otherBWin->UnlockLooper();
  51.118 -    return 0;
  51.119 -}
  51.120 -
  51.121 -void BE_SetWindowTitle(_THIS, SDL_Window * window) {
  51.122 -	BMessage msg(BWIN_SET_TITLE);
  51.123 -	msg.AddString("window-title", window->title);
  51.124 -	_ToBeWin(window)->PostMessage(&msg);
  51.125 -}
  51.126 -
  51.127 -void BE_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon) {
  51.128 -	/* FIXME: Icons not supported by BeOs/Haiku */
  51.129 -}
  51.130 -
  51.131 -void BE_SetWindowPosition(_THIS, SDL_Window * window) {
  51.132 -	BMessage msg(BWIN_MOVE_WINDOW);
  51.133 -	msg.AddInt32("window-x", window->x);
  51.134 -	msg.AddInt32("window-y", window->y);
  51.135 -	_ToBeWin(window)->PostMessage(&msg);
  51.136 -}
  51.137 -
  51.138 -void BE_SetWindowSize(_THIS, SDL_Window * window) {
  51.139 -	BMessage msg(BWIN_RESIZE_WINDOW);
  51.140 -	msg.AddInt32("window-w", window->w - 1);
  51.141 -	msg.AddInt32("window-h", window->h - 1);
  51.142 -	_ToBeWin(window)->PostMessage(&msg);
  51.143 -}
  51.144 -
  51.145 -void BE_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered) {
  51.146 -	BMessage msg(BWIN_SET_BORDERED);
  51.147 -	msg.AddBool("window-border", bordered != SDL_FALSE);
  51.148 -	_ToBeWin(window)->PostMessage(&msg);
  51.149 -}
  51.150 -
  51.151 -void BE_ShowWindow(_THIS, SDL_Window * window) {
  51.152 -	BMessage msg(BWIN_SHOW_WINDOW);
  51.153 -	_ToBeWin(window)->PostMessage(&msg);
  51.154 -}
  51.155 -
  51.156 -void BE_HideWindow(_THIS, SDL_Window * window) {
  51.157 -	BMessage msg(BWIN_HIDE_WINDOW);
  51.158 -	_ToBeWin(window)->PostMessage(&msg);
  51.159 -}
  51.160 -
  51.161 -void BE_RaiseWindow(_THIS, SDL_Window * window) {
  51.162 -	BMessage msg(BWIN_SHOW_WINDOW);	/* Activate this window and move to front */
  51.163 -	_ToBeWin(window)->PostMessage(&msg);
  51.164 -}
  51.165 -
  51.166 -void BE_MaximizeWindow(_THIS, SDL_Window * window) {
  51.167 -	BMessage msg(BWIN_MAXIMIZE_WINDOW);
  51.168 -	_ToBeWin(window)->PostMessage(&msg);
  51.169 -}
  51.170 -
  51.171 -void BE_MinimizeWindow(_THIS, SDL_Window * window) {
  51.172 -	BMessage msg(BWIN_MINIMIZE_WINDOW);
  51.173 -	_ToBeWin(window)->PostMessage(&msg);
  51.174 -}
  51.175 -
  51.176 -void BE_RestoreWindow(_THIS, SDL_Window * window) {
  51.177 -	BMessage msg(BWIN_RESTORE_WINDOW);
  51.178 -	_ToBeWin(window)->PostMessage(&msg);
  51.179 -}
  51.180 -
  51.181 -void BE_SetWindowFullscreen(_THIS, SDL_Window * window,
  51.182 -		SDL_VideoDisplay * display, SDL_bool fullscreen) {
  51.183 -	/* Haiku tracks all video display information */
  51.184 -	BMessage msg(BWIN_FULLSCREEN);
  51.185 -	msg.AddBool("fullscreen", fullscreen);
  51.186 -	_ToBeWin(window)->PostMessage(&msg);
  51.187 -	
  51.188 -}
  51.189 -
  51.190 -int BE_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp) {
  51.191 -	/* FIXME: Not BeOs/Haiku supported */
  51.192 -	return -1;
  51.193 -}
  51.194 -
  51.195 -int BE_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp) {
  51.196 -	/* FIXME: Not BeOs/Haiku supported */
  51.197 -	return -1;
  51.198 -}
  51.199 -
  51.200 -
  51.201 -void BE_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed) {
  51.202 -	/* TODO: Implement this! */
  51.203 -}
  51.204 -
  51.205 -void BE_DestroyWindow(_THIS, SDL_Window * window) {
  51.206 -	_ToBeWin(window)->LockLooper();	/* This MUST be locked */
  51.207 -	_GetBeApp()->ClearID(_ToBeWin(window));
  51.208 -	_ToBeWin(window)->Quit();
  51.209 -	window->driverdata = NULL;
  51.210 -}
  51.211 -
  51.212 -SDL_bool BE_GetWindowWMInfo(_THIS, SDL_Window * window,
  51.213 -                                    struct SDL_SysWMinfo *info) {
  51.214 -	/* FIXME: What is the point of this? What information should be included? */
  51.215 -	return SDL_FALSE;
  51.216 -}
  51.217 -
  51.218 -
  51.219 -
  51.220 -
  51.221 - 
  51.222 -#ifdef __cplusplus
  51.223 -}
  51.224 -#endif
  51.225 -
  51.226 -#endif /* SDL_VIDEO_DRIVER_BWINDOW */
    52.1 --- a/src/video/bwindow/SDL_bwindow.h	Thu Nov 14 22:19:07 2013 +0530
    52.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    52.3 @@ -1,53 +0,0 @@
    52.4 -/*
    52.5 -  Simple DirectMedia Layer
    52.6 -  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    52.7 -
    52.8 -  This software is provided 'as-is', without any express or implied
    52.9 -  warranty.  In no event will the authors be held liable for any damages
   52.10 -  arising from the use of this software.
   52.11 -
   52.12 -  Permission is granted to anyone to use this software for any purpose,
   52.13 -  including commercial applications, and to alter it and redistribute it
   52.14 -  freely, subject to the following restrictions:
   52.15 -
   52.16 -  1. The origin of this software must not be misrepresented; you must not
   52.17 -     claim that you wrote the original software. If you use this software
   52.18 -     in a product, an acknowledgment in the product documentation would be
   52.19 -     appreciated but is not required.
   52.20 -  2. Altered source versions must be plainly marked as such, and must not be
   52.21 -     misrepresented as being the original software.
   52.22 -  3. This notice may not be removed or altered from any source distribution.
   52.23 -*/
   52.24 -
   52.25 -#ifndef SDL_BWINDOW_H
   52.26 -#define SDL_BWINDOW_H
   52.27 -
   52.28 -
   52.29 -#include "../SDL_sysvideo.h"
   52.30 -
   52.31 -
   52.32 -extern int BE_CreateWindow(_THIS, SDL_Window *window);
   52.33 -extern int BE_CreateWindowFrom(_THIS, SDL_Window * window, const void *data);
   52.34 -extern void BE_SetWindowTitle(_THIS, SDL_Window * window);
   52.35 -extern void BE_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon);
   52.36 -extern void BE_SetWindowPosition(_THIS, SDL_Window * window);
   52.37 -extern void BE_SetWindowSize(_THIS, SDL_Window * window);
   52.38 -extern void BE_ShowWindow(_THIS, SDL_Window * window);
   52.39 -extern void BE_HideWindow(_THIS, SDL_Window * window);
   52.40 -extern void BE_RaiseWindow(_THIS, SDL_Window * window);
   52.41 -extern void BE_MaximizeWindow(_THIS, SDL_Window * window);
   52.42 -extern void BE_MinimizeWindow(_THIS, SDL_Window * window);
   52.43 -extern void BE_RestoreWindow(_THIS, SDL_Window * window);
   52.44 -extern void BE_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered);
   52.45 -extern void BE_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
   52.46 -extern int BE_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp);
   52.47 -extern int BE_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp);
   52.48 -extern void BE_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed);
   52.49 -extern void BE_DestroyWindow(_THIS, SDL_Window * window);
   52.50 -extern SDL_bool BE_GetWindowWMInfo(_THIS, SDL_Window * window,
   52.51 -                                    struct SDL_SysWMinfo *info);
   52.52 -
   52.53 -
   52.54 -
   52.55 -#endif
   52.56 -
    53.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    53.2 +++ b/src/video/haiku/SDL_BWin.h	Thu Nov 14 22:35:28 2013 +0530
    53.3 @@ -0,0 +1,636 @@
    53.4 +/*
    53.5 +  Simple DirectMedia Layer
    53.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    53.7 +
    53.8 +  This software is provided 'as-is', without any express or implied
    53.9 +  warranty.  In no event will the authors be held liable for any damages
   53.10 +  arising from the use of this software.
   53.11 +
   53.12 +  Permission is granted to anyone to use this software for any purpose,
   53.13 +  including commercial applications, and to alter it and redistribute it
   53.14 +  freely, subject to the following restrictions:
   53.15 +
   53.16 +  1. The origin of this software must not be misrepresented; you must not
   53.17 +     claim that you wrote the original software. If you use this software
   53.18 +     in a product, an acknowledgment in the product documentation would be
   53.19 +     appreciated but is not required.
   53.20 +  2. Altered source versions must be plainly marked as such, and must not be
   53.21 +     misrepresented as being the original software.
   53.22 +  3. This notice may not be removed or altered from any source distribution.
   53.23 +*/
   53.24 +
   53.25 +#ifndef _SDL_BWin_h
   53.26 +#define _SDL_BWin_h
   53.27 +
   53.28 +#ifdef __cplusplus
   53.29 +extern "C" {
   53.30 +#endif
   53.31 +
   53.32 +#include "SDL_config.h"
   53.33 +#include "SDL.h"
   53.34 +#include "SDL_syswm.h"
   53.35 +#include "SDL_bframebuffer.h"
   53.36 +
   53.37 +#ifdef __cplusplus
   53.38 +}
   53.39 +#endif
   53.40 +
   53.41 +#include <stdio.h>
   53.42 +#include <AppKit.h>
   53.43 +#include <InterfaceKit.h>
   53.44 +#include <be/game/DirectWindow.h>
   53.45 +#if SDL_VIDEO_OPENGL
   53.46 +#include <be/opengl/GLView.h>
   53.47 +#endif
   53.48 +#include "SDL_events.h"
   53.49 +#include "../../main/haiku/SDL_BApp.h"
   53.50 +
   53.51 +
   53.52 +enum WinCommands {
   53.53 +    BWIN_MOVE_WINDOW,
   53.54 +    BWIN_RESIZE_WINDOW,
   53.55 +    BWIN_SHOW_WINDOW,
   53.56 +    BWIN_HIDE_WINDOW,
   53.57 +    BWIN_MAXIMIZE_WINDOW,
   53.58 +    BWIN_MINIMIZE_WINDOW,
   53.59 +    BWIN_RESTORE_WINDOW,
   53.60 +    BWIN_SET_TITLE,
   53.61 +    BWIN_SET_BORDERED,
   53.62 +    BWIN_FULLSCREEN
   53.63 +};
   53.64 +
   53.65 +
   53.66 +class SDL_BWin:public BDirectWindow
   53.67 +{
   53.68 +  public:
   53.69 +    /* Constructor/Destructor */
   53.70 +    SDL_BWin(BRect bounds, window_look look, uint32 flags)
   53.71 +        : BDirectWindow(bounds, "Untitled", look, B_NORMAL_WINDOW_FEEL, flags)
   53.72 +    {
   53.73 +        _last_buttons = 0;
   53.74 +
   53.75 +#if SDL_VIDEO_OPENGL
   53.76 +        _SDL_GLView = NULL;
   53.77 +#endif
   53.78 +        _shown = false;
   53.79 +        _inhibit_resize = false;
   53.80 +        _mouse_focused = false;
   53.81 +        _prev_frame = NULL;
   53.82 +
   53.83 +        /* Handle framebuffer stuff */
   53.84 +        _connected = _connection_disabled = false;
   53.85 +        _buffer_created = _buffer_dirty = false;
   53.86 +        _trash_window_buffer = false;
   53.87 +        _buffer_locker = new BLocker();
   53.88 +        _bitmap = NULL;
   53.89 +#ifdef DRAWTHREAD
   53.90 +        _draw_thread_id = spawn_thread(BE_DrawThread, "drawing_thread",
   53.91 +                            B_NORMAL_PRIORITY, (void*) this);
   53.92 +        resume_thread(_draw_thread_id);
   53.93 +#endif
   53.94 +    }
   53.95 +
   53.96 +    virtual ~ SDL_BWin()
   53.97 +    {
   53.98 +        Lock();
   53.99 +        _connection_disabled = true;
  53.100 +        int32 result;
  53.101 +
  53.102 +#if SDL_VIDEO_OPENGL
  53.103 +        if (_SDL_GLView) {
  53.104 +            _SDL_GLView->UnlockGL();
  53.105 +            RemoveChild(_SDL_GLView);   /* Why was this outside the if
  53.106 +                                            statement before? */
  53.107 +        }
  53.108 +
  53.109 +#endif
  53.110 +        Unlock();
  53.111 +#if SDL_VIDEO_OPENGL
  53.112 +        if (_SDL_GLView) {
  53.113 +            delete _SDL_GLView;
  53.114 +        }
  53.115 +#endif
  53.116 +
  53.117 +        /* Clean up framebuffer stuff */
  53.118 +        _buffer_locker->Lock();
  53.119 +#ifdef DRAWTHREAD
  53.120 +        wait_for_thread(_draw_thread_id, &result);
  53.121 +#endif
  53.122 +        free(_clips);
  53.123 +        delete _buffer_locker;
  53.124 +    }
  53.125 +
  53.126 +
  53.127 +    /* * * * * OpenGL functionality * * * * */
  53.128 +#if SDL_VIDEO_OPENGL
  53.129 +    virtual BGLView *CreateGLView(Uint32 gl_flags) {
  53.130 +        Lock();
  53.131 +        if (_SDL_GLView == NULL) {
  53.132 +            _SDL_GLView = new BGLView(Bounds(), "SDL GLView",
  53.133 +                                     B_FOLLOW_ALL_SIDES,
  53.134 +                                     (B_WILL_DRAW | B_FRAME_EVENTS),
  53.135 +                                     gl_flags);
  53.136 +        }
  53.137 +        AddChild(_SDL_GLView);
  53.138 +        _SDL_GLView->EnableDirectMode(true);
  53.139 +        _SDL_GLView->LockGL();  /* "New" GLViews are created */
  53.140 +        Unlock();
  53.141 +        return (_SDL_GLView);
  53.142 +    }
  53.143 +
  53.144 +    virtual void RemoveGLView() {
  53.145 +        Lock();
  53.146 +        if(_SDL_GLView) {
  53.147 +            _SDL_GLView->UnlockGL();
  53.148 +            RemoveChild(_SDL_GLView);
  53.149 +        }
  53.150 +        Unlock();
  53.151 +    }
  53.152 +
  53.153 +    virtual void SwapBuffers(void) {
  53.154 +        _SDL_GLView->UnlockGL();
  53.155 +        _SDL_GLView->LockGL();
  53.156 +        _SDL_GLView->SwapBuffers();
  53.157 +    }
  53.158 +#endif
  53.159 +
  53.160 +    /* * * * * Framebuffering* * * * */
  53.161 +    virtual void DirectConnected(direct_buffer_info *info) {
  53.162 +        if(!_connected && _connection_disabled) {
  53.163 +            return;
  53.164 +        }
  53.165 +
  53.166 +        /* Determine if the pixel buffer is usable after this update */
  53.167 +        _trash_window_buffer =      _trash_window_buffer
  53.168 +                                || ((info->buffer_state & B_BUFFER_RESIZED)
  53.169 +                                || (info->buffer_state & B_BUFFER_RESET)
  53.170 +                                || (info->driver_state == B_MODE_CHANGED));
  53.171 +        LockBuffer();
  53.172 +
  53.173 +        switch(info->buffer_state & B_DIRECT_MODE_MASK) {
  53.174 +        case B_DIRECT_START:
  53.175 +            _connected = true;
  53.176 +
  53.177 +        case B_DIRECT_MODIFY:
  53.178 +            if(_clips) {
  53.179 +                free(_clips);
  53.180 +                _clips = NULL;
  53.181 +            }
  53.182 +
  53.183 +            _num_clips = info->clip_list_count;
  53.184 +            _clips = (clipping_rect *)malloc(_num_clips*sizeof(clipping_rect));
  53.185 +            if(_clips) {
  53.186 +                memcpy(_clips, info->clip_list,
  53.187 +                    _num_clips*sizeof(clipping_rect));
  53.188 +
  53.189 +                _bits = (uint8*) info->bits;
  53.190 +                _row_bytes = info->bytes_per_row;
  53.191 +                _bounds = info->window_bounds;
  53.192 +                _bytes_per_px = info->bits_per_pixel / 8;
  53.193 +                _buffer_dirty = true;
  53.194 +            }
  53.195 +            break;
  53.196 +
  53.197 +        case B_DIRECT_STOP:
  53.198 +            _connected = false;
  53.199 +            break;
  53.200 +        }
  53.201 +#if SDL_VIDEO_OPENGL
  53.202 +        if(_SDL_GLView) {
  53.203 +            _SDL_GLView->DirectConnected(info);
  53.204 +        }
  53.205 +#endif
  53.206 +
  53.207 +
  53.208 +        /* Call the base object directconnected */
  53.209 +        BDirectWindow::DirectConnected(info);
  53.210 +
  53.211 +        UnlockBuffer();
  53.212 +
  53.213 +    }
  53.214 +
  53.215 +
  53.216 +
  53.217 +
  53.218 +    /* * * * * Event sending * * * * */
  53.219 +    /* Hook functions */
  53.220 +    virtual void FrameMoved(BPoint origin) {
  53.221 +        /* Post a message to the BApp so that it can handle the window event */
  53.222 +        BMessage msg(BAPP_WINDOW_MOVED);
  53.223 +        msg.AddInt32("window-x", (int)origin.x);
  53.224 +        msg.AddInt32("window-y", (int)origin.y);
  53.225 +        _PostWindowEvent(msg);
  53.226 +
  53.227 +        /* Perform normal hook operations */
  53.228 +        BDirectWindow::FrameMoved(origin);
  53.229 +    }
  53.230 +
  53.231 +    virtual void FrameResized(float width, float height) {
  53.232 +        /* Post a message to the BApp so that it can handle the window event */
  53.233 +        BMessage msg(BAPP_WINDOW_RESIZED);
  53.234 +
  53.235 +        msg.AddInt32("window-w", (int)width + 1);
  53.236 +        msg.AddInt32("window-h", (int)height + 1);
  53.237 +        _PostWindowEvent(msg);
  53.238 +
  53.239 +        /* Perform normal hook operations */
  53.240 +        BDirectWindow::FrameResized(width, height);
  53.241 +    }
  53.242 +
  53.243 +    virtual bool QuitRequested() {
  53.244 +        BMessage msg(BAPP_WINDOW_CLOSE_REQUESTED);
  53.245 +        _PostWindowEvent(msg);
  53.246 +
  53.247 +        /* We won't allow a quit unless asked by DestroyWindow() */
  53.248 +        return false;
  53.249 +    }
  53.250 +
  53.251 +    virtual void WindowActivated(bool active) {
  53.252 +        BMessage msg(BAPP_KEYBOARD_FOCUS);  /* Mouse focus sold separately */
  53.253 +        _PostWindowEvent(msg);
  53.254 +    }
  53.255 +
  53.256 +    virtual void Zoom(BPoint origin,
  53.257 +                float width,
  53.258 +                float height) {
  53.259 +        BMessage msg(BAPP_MAXIMIZE);    /* Closest thing to maximization Haiku has */
  53.260 +        _PostWindowEvent(msg);
  53.261 +
  53.262 +        /* Before the window zooms, record its size */
  53.263 +        if( !_prev_frame )
  53.264 +            _prev_frame = new BRect(Frame());
  53.265 +
  53.266 +        /* Perform normal hook operations */
  53.267 +        BDirectWindow::Zoom(origin, width, height);
  53.268 +    }
  53.269 +
  53.270 +    /* Member functions */
  53.271 +    virtual void Show() {
  53.272 +        while(IsHidden()) {
  53.273 +            BDirectWindow::Show();
  53.274 +        }
  53.275 +        _shown = true;
  53.276 +
  53.277 +        BMessage msg(BAPP_SHOW);
  53.278 +        _PostWindowEvent(msg);
  53.279 +    }
  53.280 +
  53.281 +    virtual void Hide() {
  53.282 +        BDirectWindow::Hide();
  53.283 +        _shown = false;
  53.284 +
  53.285 +        BMessage msg(BAPP_HIDE);
  53.286 +        _PostWindowEvent(msg);
  53.287 +    }
  53.288 +
  53.289 +    virtual void Minimize(bool minimize) {
  53.290 +        BDirectWindow::Minimize(minimize);
  53.291 +        int32 minState = (minimize ? BAPP_MINIMIZE : BAPP_RESTORE);
  53.292 +
  53.293 +        BMessage msg(minState);
  53.294 +        _PostWindowEvent(msg);
  53.295 +    }
  53.296 +
  53.297 +
  53.298 +    /* BView message interruption */
  53.299 +    virtual void DispatchMessage(BMessage * msg, BHandler * target)
  53.300 +    {
  53.301 +        BPoint where;   /* Used by mouse moved */
  53.302 +        int32 buttons;  /* Used for mouse button events */
  53.303 +        int32 key;      /* Used for key events */
  53.304 +
  53.305 +        switch (msg->what) {
  53.306 +        case B_MOUSE_MOVED:
  53.307 +            int32 transit;
  53.308 +            if (msg->FindPoint("where", &where) == B_OK
  53.309 +                && msg->FindInt32("be:transit", &transit) == B_OK) {
  53.310 +                _MouseMotionEvent(where, transit);
  53.311 +            }
  53.312 +
  53.313 +            /* FIXME: Apparently a button press/release event might be dropped
  53.314 +               if made before before a different button is released.  Does
  53.315 +               B_MOUSE_MOVED have the data needed to check if a mouse button
  53.316 +               state has changed? */
  53.317 +            if (msg->FindInt32("buttons", &buttons) == B_OK) {
  53.318 +                _MouseButtonEvent(buttons);
  53.319 +            }
  53.320 +            break;
  53.321 +
  53.322 +        case B_MOUSE_DOWN:
  53.323 +        case B_MOUSE_UP:
  53.324 +            /* _MouseButtonEvent() detects any and all buttons that may have
  53.325 +               changed state, as well as that button's new state */
  53.326 +            if (msg->FindInt32("buttons", &buttons) == B_OK) {
  53.327 +                _MouseButtonEvent(buttons);
  53.328 +            }
  53.329 +            break;
  53.330 +
  53.331 +        case B_MOUSE_WHEEL_CHANGED:
  53.332 +            float x, y;
  53.333 +            if (msg->FindFloat("be:wheel_delta_x", &x) == B_OK
  53.334 +                && msg->FindFloat("be:wheel_delta_y", &y) == B_OK) {
  53.335 +                    _MouseWheelEvent((int)x, (int)y);
  53.336 +            }
  53.337 +            break;
  53.338 +
  53.339 +        case B_KEY_DOWN:
  53.340 +        case B_UNMAPPED_KEY_DOWN:      /* modifier keys are unmapped */
  53.341 +            if (msg->FindInt32("key", &key) == B_OK) {
  53.342 +                _KeyEvent((SDL_Scancode)key, SDL_PRESSED);
  53.343 +            }
  53.344 +            break;
  53.345 +
  53.346 +        case B_KEY_UP:
  53.347 +        case B_UNMAPPED_KEY_UP:        /* modifier keys are unmapped */
  53.348 +            if (msg->FindInt32("key", &key) == B_OK) {
  53.349 +                _KeyEvent(key, SDL_RELEASED);
  53.350 +            }
  53.351 +            break;
  53.352 +
  53.353 +        default:
  53.354 +            /* move it after switch{} so it's always handled
  53.355 +               that way we keep Haiku features like:
  53.356 +               - CTRL+Q to close window (and other shortcuts)
  53.357 +               - PrintScreen to make screenshot into /boot/home
  53.358 +               - etc.. */
  53.359 +            /* BDirectWindow::DispatchMessage(msg, target); */
  53.360 +            break;
  53.361 +        }
  53.362 +
  53.363 +        BDirectWindow::DispatchMessage(msg, target);
  53.364 +    }
  53.365 +
  53.366 +    /* Handle command messages */
  53.367 +    virtual void MessageReceived(BMessage* message) {
  53.368 +        switch (message->what) {
  53.369 +            /* Handle commands from SDL */
  53.370 +            case BWIN_SET_TITLE:
  53.371 +                _SetTitle(message);
  53.372 +                break;
  53.373 +            case BWIN_MOVE_WINDOW:
  53.374 +                _MoveTo(message);
  53.375 +                break;
  53.376 +            case BWIN_RESIZE_WINDOW:
  53.377 +                _ResizeTo(message);
  53.378 +                break;
  53.379 +            case BWIN_SET_BORDERED:
  53.380 +                _SetBordered(message);
  53.381 +                break;
  53.382 +            case BWIN_SHOW_WINDOW:
  53.383 +                Show();
  53.384 +                break;
  53.385 +            case BWIN_HIDE_WINDOW:
  53.386 +                Hide();
  53.387 +                break;
  53.388 +            case BWIN_MAXIMIZE_WINDOW:
  53.389 +                BWindow::Zoom();
  53.390 +                break;
  53.391 +            case BWIN_MINIMIZE_WINDOW:
  53.392 +                Minimize(true);
  53.393 +                break;
  53.394 +            case BWIN_RESTORE_WINDOW:
  53.395 +                _Restore();
  53.396 +                break;
  53.397 +            case BWIN_FULLSCREEN:
  53.398 +                _SetFullScreen(message);
  53.399 +                break;
  53.400 +            default:
  53.401 +                /* Perform normal message handling */
  53.402 +                BDirectWindow::MessageReceived(message);
  53.403 +                break;
  53.404 +        }
  53.405 +
  53.406 +    }
  53.407 +
  53.408 +
  53.409 +
  53.410 +    /* Accessor methods */
  53.411 +    bool IsShown() { return _shown; }
  53.412 +    int32 GetID() { return _id; }
  53.413 +    uint32 GetRowBytes() { return _row_bytes; }
  53.414 +    int32 GetFbX() { return _bounds.left; }
  53.415 +    int32 GetFbY() { return _bounds.top; }
  53.416 +    bool ConnectionEnabled() { return !_connection_disabled; }
  53.417 +    bool Connected() { return _connected; }
  53.418 +    clipping_rect *GetClips() { return _clips; }
  53.419 +    int32 GetNumClips() { return _num_clips; }
  53.420 +    uint8* GetBufferPx() { return _bits; }
  53.421 +    int32 GetBytesPerPx() { return _bytes_per_px; }
  53.422 +    bool CanTrashWindowBuffer() { return _trash_window_buffer; }
  53.423 +    bool BufferExists() { return _buffer_created; }
  53.424 +    bool BufferIsDirty() { return _buffer_dirty; }
  53.425 +    BBitmap *GetBitmap() { return _bitmap; }
  53.426 +#if SDL_VIDEO_OPENGL
  53.427 +    BGLView *GetGLView() { return _SDL_GLView; }
  53.428 +#endif
  53.429 +
  53.430 +    /* Setter methods */
  53.431 +    void SetID(int32 id) { _id = id; }
  53.432 +    void SetBufferExists(bool bufferExists) { _buffer_created = bufferExists; }
  53.433 +    void LockBuffer() { _buffer_locker->Lock(); }
  53.434 +    void UnlockBuffer() { _buffer_locker->Unlock(); }
  53.435 +    void SetBufferDirty(bool bufferDirty) { _buffer_dirty = bufferDirty; }
  53.436 +    void SetTrashBuffer(bool trash) { _trash_window_buffer = trash;     }
  53.437 +    void SetBitmap(BBitmap *bitmap) { _bitmap = bitmap; }
  53.438 +
  53.439 +
  53.440 +private:
  53.441 +    /* Event redirection */
  53.442 +    void _MouseMotionEvent(BPoint &where, int32 transit) {
  53.443 +        if(transit == B_EXITED_VIEW) {
  53.444 +            /* Change mouse focus */
  53.445 +            if(_mouse_focused) {
  53.446 +                _MouseFocusEvent(false);
  53.447 +            }
  53.448 +        } else {
  53.449 +            /* Change mouse focus */
  53.450 +            if (!_mouse_focused) {
  53.451 +                _MouseFocusEvent(true);
  53.452 +            }
  53.453 +            BMessage msg(BAPP_MOUSE_MOVED);
  53.454 +            msg.AddInt32("x", (int)where.x);
  53.455 +            msg.AddInt32("y", (int)where.y);
  53.456 +
  53.457 +            _PostWindowEvent(msg);
  53.458 +        }
  53.459 +    }
  53.460 +
  53.461 +    void _MouseFocusEvent(bool focusGained) {
  53.462 +        _mouse_focused = focusGained;
  53.463 +        BMessage msg(BAPP_MOUSE_FOCUS);
  53.464 +        msg.AddBool("focusGained", focusGained);
  53.465 +        _PostWindowEvent(msg);
  53.466 +
  53.467 +/* FIXME: Why were these here?
  53.468 + if false: be_app->SetCursor(B_HAND_CURSOR);
  53.469 + if true:  SDL_SetCursor(NULL); */
  53.470 +    }
  53.471 +
  53.472 +    void _MouseButtonEvent(int32 buttons) {
  53.473 +        int32 buttonStateChange = buttons ^ _last_buttons;
  53.474 +
  53.475 +        /* Make sure at least one button has changed state */
  53.476 +        if( !(buttonStateChange) ) {
  53.477 +            return;
  53.478 +        }
  53.479 +
  53.480 +        /* Add any mouse button events */
  53.481 +        if(buttonStateChange & B_PRIMARY_MOUSE_BUTTON) {
  53.482 +            _SendMouseButton(SDL_BUTTON_LEFT, buttons &
  53.483 +                B_PRIMARY_MOUSE_BUTTON);
  53.484 +        }
  53.485 +        if(buttonStateChange & B_SECONDARY_MOUSE_BUTTON) {
  53.486 +            _SendMouseButton(SDL_BUTTON_RIGHT, buttons &
  53.487 +                B_PRIMARY_MOUSE_BUTTON);
  53.488 +        }
  53.489 +        if(buttonStateChange & B_TERTIARY_MOUSE_BUTTON) {
  53.490 +            _SendMouseButton(SDL_BUTTON_MIDDLE, buttons &
  53.491 +                B_PRIMARY_MOUSE_BUTTON);
  53.492 +        }
  53.493 +
  53.494 +        _last_buttons = buttons;
  53.495 +    }
  53.496 +
  53.497 +    void _SendMouseButton(int32 button, int32 state) {
  53.498 +        BMessage msg(BAPP_MOUSE_BUTTON);
  53.499 +        msg.AddInt32("button-id", button);
  53.500 +        msg.AddInt32("button-state", state);
  53.501 +        _PostWindowEvent(msg);
  53.502 +    }
  53.503 +
  53.504 +    void _MouseWheelEvent(int32 x, int32 y) {
  53.505 +        /* Create a message to pass along to the BeApp thread */
  53.506 +        BMessage msg(BAPP_MOUSE_WHEEL);
  53.507 +        msg.AddInt32("xticks", x);
  53.508 +        msg.AddInt32("yticks", y);
  53.509 +        _PostWindowEvent(msg);
  53.510 +    }
  53.511 +
  53.512 +    void _KeyEvent(int32 keyCode, int32 keyState) {
  53.513 +        /* Create a message to pass along to the BeApp thread */
  53.514 +        BMessage msg(BAPP_KEY);
  53.515 +        msg.AddInt32("key-state", keyState);
  53.516 +        msg.AddInt32("key-scancode", keyCode);
  53.517 +        be_app->PostMessage(&msg);
  53.518 +        /* Apparently SDL only uses the scancode */
  53.519 +    }
  53.520 +
  53.521 +    void _RepaintEvent() {
  53.522 +        /* Force a repaint: Call the SDL exposed event */
  53.523 +        BMessage msg(BAPP_REPAINT);
  53.524 +        _PostWindowEvent(msg);
  53.525 +    }
  53.526 +    void _PostWindowEvent(BMessage &msg) {
  53.527 +        msg.AddInt32("window-id", _id);
  53.528 +        be_app->PostMessage(&msg);
  53.529 +    }
  53.530 +
  53.531 +    /* Command methods (functions called upon by SDL) */
  53.532 +    void _SetTitle(BMessage *msg) {
  53.533 +        const char *title;
  53.534 +        if(
  53.535 +            msg->FindString("window-title", &title) != B_OK
  53.536 +        ) {
  53.537 +            return;
  53.538 +        }
  53.539 +        SetTitle(title);
  53.540 +    }
  53.541 +
  53.542 +    void _MoveTo(BMessage *msg) {
  53.543 +        int32 x, y;
  53.544 +        if(
  53.545 +            msg->FindInt32("window-x", &x) != B_OK ||
  53.546 +            msg->FindInt32("window-y", &y) != B_OK
  53.547 +        ) {
  53.548 +            return;
  53.549 +        }
  53.550 +        MoveTo(x, y);
  53.551 +    }
  53.552 +
  53.553 +    void _ResizeTo(BMessage *msg) {
  53.554 +        int32 w, h;
  53.555 +        if(
  53.556 +            msg->FindInt32("window-w", &w) != B_OK ||
  53.557 +            msg->FindInt32("window-h", &h) != B_OK
  53.558 +        ) {
  53.559 +            return;
  53.560 +        }
  53.561 +        ResizeTo(w, h);
  53.562 +    }
  53.563 +
  53.564 +    void _SetBordered(BMessage *msg) {
  53.565 +        bool bEnabled;
  53.566 +        if(msg->FindBool("window-border", &bEnabled) != B_OK) {
  53.567 +            return;
  53.568 +        }
  53.569 +        SetLook(bEnabled ? B_BORDERED_WINDOW_LOOK : B_NO_BORDER_WINDOW_LOOK);
  53.570 +    }
  53.571 +
  53.572 +    void _Restore() {
  53.573 +        if(IsMinimized()) {
  53.574 +            Minimize(false);
  53.575 +        } else if(IsHidden()) {
  53.576 +            Show();
  53.577 +        } else if(_prev_frame != NULL) {    /* Zoomed */
  53.578 +            MoveTo(_prev_frame->left, _prev_frame->top);
  53.579 +            ResizeTo(_prev_frame->Width(), _prev_frame->Height());
  53.580 +        }
  53.581 +    }
  53.582 +
  53.583 +    void _SetFullScreen(BMessage *msg) {
  53.584 +        bool fullscreen;
  53.585 +        if(
  53.586 +            msg->FindBool("fullscreen", &fullscreen) != B_OK
  53.587 +        ) {
  53.588 +            return;
  53.589 +        }
  53.590 +        SetFullScreen(fullscreen);
  53.591 +    }
  53.592 +
  53.593 +    /* Members */
  53.594 +#if SDL_VIDEO_OPENGL
  53.595 +    BGLView * _SDL_GLView;
  53.596 +#endif
  53.597 +
  53.598 +    int32 _last_buttons;
  53.599 +    int32 _id;  /* Window id used by SDL_BApp */
  53.600 +    bool  _mouse_focused;       /* Does this window have mouse focus? */
  53.601 +    bool  _shown;
  53.602 +    bool  _inhibit_resize;
  53.603 +
  53.604 +    BRect *_prev_frame; /* Previous position and size of the window */
  53.605 +
  53.606 +    /* Framebuffer members */
  53.607 +    bool            _connected,
  53.608 +                    _connection_disabled,
  53.609 +                    _buffer_created,
  53.610 +                    _buffer_dirty,
  53.611 +                    _trash_window_buffer;
  53.612 +    uint8          *_bits;
  53.613 +    uint32          _row_bytes;
  53.614 +    clipping_rect   _bounds;
  53.615 +    BLocker        *_buffer_locker;
  53.616 +    clipping_rect  *_clips;
  53.617 +    int32           _num_clips;
  53.618 +    int32           _bytes_per_px;
  53.619 +    thread_id       _draw_thread_id;
  53.620 +
  53.621 +    BBitmap        *_bitmap;
  53.622 +};
  53.623 +
  53.624 +
  53.625 +/* FIXME:
  53.626 + * An explanation of framebuffer flags.
  53.627 + *
  53.628 + * _connected -           Original variable used to let the drawing thread know
  53.629 + *                         when changes are being made to the other framebuffer
  53.630 + *                         members.
  53.631 + * _connection_disabled - Used to signal to the drawing thread that the window
  53.632 + *                         is closing, and the thread should exit.
  53.633 + * _buffer_created -      True if the current buffer is valid
  53.634 + * _buffer_dirty -        True if the window should be redrawn.
  53.635 + * _trash_window_buffer - True if the window buffer needs to be trashed partway
  53.636 + *                         through a draw cycle.  Occurs when the previous
  53.637 + *                         buffer provided by DirectConnected() is invalidated.
  53.638 + */
  53.639 +#endif
    54.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    54.2 +++ b/src/video/haiku/SDL_bclipboard.cc	Thu Nov 14 22:35:28 2013 +0530
    54.3 @@ -0,0 +1,95 @@
    54.4 +/*
    54.5 +  Simple DirectMedia Layer
    54.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    54.7 +
    54.8 +  This software is provided 'as-is', without any express or implied
    54.9 +  warranty.  In no event will the authors be held liable for any damages
   54.10 +  arising from the use of this software.
   54.11 +
   54.12 +  Permission is granted to anyone to use this software for any purpose,
   54.13 +  including commercial applications, and to alter it and redistribute it
   54.14 +  freely, subject to the following restrictions:
   54.15 +
   54.16 +  1. The origin of this software must not be misrepresented; you must not
   54.17 +     claim that you wrote the original software. If you use this software
   54.18 +     in a product, an acknowledgment in the product documentation would be
   54.19 +     appreciated but is not required.
   54.20 +  2. Altered source versions must be plainly marked as such, and must not be
   54.21 +     misrepresented as being the original software.
   54.22 +  3. This notice may not be removed or altered from any source distribution.
   54.23 +*/
   54.24 +#include "SDL_config.h"
   54.25 +
   54.26 +#if SDL_VIDEO_DRIVER_HAIKU
   54.27 +
   54.28 +/* BWindow based framebuffer implementation */
   54.29 +
   54.30 +#include <unistd.h>
   54.31 +#include <TypeConstants.h>
   54.32 +
   54.33 +#include "SDL_BWin.h"
   54.34 +#include "SDL_timer.h"
   54.35 +#include "../SDL_sysvideo.h"
   54.36 +
   54.37 +#ifdef __cplusplus
   54.38 +extern "C" {
   54.39 +#endif
   54.40 +
   54.41 +int BE_SetClipboardText(_THIS, const char *text) {
   54.42 +	BMessage *clip = NULL;
   54.43 +	if(be_clipboard->Lock()) {
   54.44 +		be_clipboard->Clear();
   54.45 +		if((clip = be_clipboard->Data())) {
   54.46 +			/* Presumably the string of characters is ascii-format */
   54.47 +			ssize_t asciiLength = 0;
   54.48 +			for(; text[asciiLength] != 0; ++asciiLength) {}
   54.49 +			clip->AddData("text/plain", B_MIME_TYPE, &text, asciiLength);
   54.50 +			be_clipboard->Commit();
   54.51 +		}
   54.52 +		be_clipboard->Unlock();
   54.53 +	}
   54.54 +	return 0;
   54.55 +}
   54.56 +
   54.57 +char *BE_GetClipboardText(_THIS) {
   54.58 +	BMessage *clip = NULL;
   54.59 +	const char *text = NULL;	
   54.60 +	ssize_t length;
   54.61 +	char *result;
   54.62 +	if(be_clipboard->Lock()) {
   54.63 +		if((clip = be_clipboard->Data())) {
   54.64 +			/* Presumably the string of characters is ascii-format */
   54.65 +			clip->FindData("text/plain", B_MIME_TYPE, (const void**)&text,
   54.66 +				&length);
   54.67 +		} else {
   54.68 +			be_clipboard->Unlock();
   54.69 +		}
   54.70 +		be_clipboard->Unlock();
   54.71 +	} 
   54.72 +	
   54.73 +	if (!text) {
   54.74 +		result = SDL_strdup("");
   54.75 +	} else {
   54.76 +		/* Copy the data and pass on to SDL */
   54.77 +		result = (char*)SDL_calloc(1, sizeof(char*)*length);
   54.78 +		SDL_strlcpy(result, text, length);
   54.79 +	}
   54.80 +	
   54.81 +	return result;
   54.82 +}
   54.83 +
   54.84 +SDL_bool BE_HasClipboardText(_THIS) {
   54.85 +	SDL_bool result = SDL_FALSE;
   54.86 +	char *text = BE_GetClipboardText(_this);
   54.87 +	if (text) {
   54.88 +		result = text[0] != '\0' ? SDL_TRUE : SDL_FALSE;
   54.89 +		SDL_free(text);
   54.90 +	} 
   54.91 +	return result;
   54.92 +}
   54.93 +
   54.94 +#ifdef __cplusplus
   54.95 +}
   54.96 +#endif
   54.97 +
   54.98 +#endif /* SDL_VIDEO_DRIVER_HAIKU */
    55.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    55.2 +++ b/src/video/haiku/SDL_bclipboard.h	Thu Nov 14 22:35:28 2013 +0530
    55.3 @@ -0,0 +1,31 @@
    55.4 +/*
    55.5 +  Simple DirectMedia Layer
    55.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    55.7 +
    55.8 +  This software is provided 'as-is', without any express or implied
    55.9 +  warranty.  In no event will the authors be held liable for any damages
   55.10 +  arising from the use of this software.
   55.11 +
   55.12 +  Permission is granted to anyone to use this software for any purpose,
   55.13 +  including commercial applications, and to alter it and redistribute it
   55.14 +  freely, subject to the following restrictions:
   55.15 +
   55.16 +  1. The origin of this software must not be misrepresented; you must not
   55.17 +     claim that you wrote the original software. If you use this software
   55.18 +     in a product, an acknowledgment in the product documentation would be
   55.19 +     appreciated but is not required.
   55.20 +  2. Altered source versions must be plainly marked as such, and must not be
   55.21 +     misrepresented as being the original software.
   55.22 +  3. This notice may not be removed or altered from any source distribution.
   55.23 +*/
   55.24 +
   55.25 +#include "SDL_config.h"
   55.26 +
   55.27 +#ifndef SDL_BCLIPBOARD_H
   55.28 +#define SDL_BCLIPBOARD_H
   55.29 +
   55.30 +extern int BE_SetClipboardText(_THIS, const char *text);
   55.31 +extern char *BE_GetClipboardText(_THIS);
   55.32 +extern SDL_bool BE_HasClipboardText(_THIS);
   55.33 +
   55.34 +#endif
    56.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    56.2 +++ b/src/video/haiku/SDL_bevents.cc	Thu Nov 14 22:35:28 2013 +0530
    56.3 @@ -0,0 +1,39 @@
    56.4 +/*
    56.5 +  Simple DirectMedia Layer
    56.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    56.7 +
    56.8 +  This software is provided 'as-is', without any express or implied
    56.9 +  warranty.  In no event will the authors be held liable for any damages
   56.10 +  arising from the use of this software.
   56.11 +
   56.12 +  Permission is granted to anyone to use this software for any purpose,
   56.13 +  including commercial applications, and to alter it and redistribute it
   56.14 +  freely, subject to the following restrictions:
   56.15 +
   56.16 +  1. The origin of this software must not be misrepresented; you must not
   56.17 +     claim that you wrote the original software. If you use this software
   56.18 +     in a product, an acknowledgment in the product documentation would be
   56.19 +     appreciated but is not required.
   56.20 +  2. Altered source versions must be plainly marked as such, and must not be
   56.21 +     misrepresented as being the original software.
   56.22 +  3. This notice may not be removed or altered from any source distribution.
   56.23 +*/
   56.24 +#include "SDL_config.h"
   56.25 +
   56.26 +#if SDL_VIDEO_DRIVER_HAIKU
   56.27 +
   56.28 +#include "SDL_bevents.h"
   56.29 +
   56.30 +#ifdef __cplusplus
   56.31 +extern "C" {
   56.32 +#endif
   56.33 +
   56.34 +void BE_PumpEvents(_THIS) {
   56.35 +	/* Since the event thread is its own thread, this isn't really necessary */
   56.36 +}
   56.37 +
   56.38 +#ifdef __cplusplus
   56.39 +}
   56.40 +#endif
   56.41 +
   56.42 +#endif /* SDL_VIDEO_DRIVER_HAIKU */
    57.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    57.2 +++ b/src/video/haiku/SDL_bevents.h	Thu Nov 14 22:35:28 2013 +0530
    57.3 @@ -0,0 +1,37 @@
    57.4 +/*
    57.5 +  Simple DirectMedia Layer
    57.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    57.7 +
    57.8 +  This software is provided 'as-is', without any express or implied
    57.9 +  warranty.  In no event will the authors be held liable for any damages
   57.10 +  arising from the use of this software.
   57.11 +
   57.12 +  Permission is granted to anyone to use this software for any purpose,
   57.13 +  including commercial applications, and to alter it and redistribute it
   57.14 +  freely, subject to the following restrictions:
   57.15 +
   57.16 +  1. The origin of this software must not be misrepresented; you must not
   57.17 +     claim that you wrote the original software. If you use this software
   57.18 +     in a product, an acknowledgment in the product documentation would be
   57.19 +     appreciated but is not required.
   57.20 +  2. Altered source versions must be plainly marked as such, and must not be
   57.21 +     misrepresented as being the original software.
   57.22 +  3. This notice may not be removed or altered from any source distribution.
   57.23 +*/
   57.24 +
   57.25 +#ifndef SDL_BEVENTS_H
   57.26 +#define SDL_BEVENTS_H
   57.27 +
   57.28 +#include "../SDL_sysvideo.h"
   57.29 +
   57.30 +#ifdef __cplusplus
   57.31 +extern "C" {
   57.32 +#endif
   57.33 +
   57.34 +extern void BE_PumpEvents(_THIS);
   57.35 +
   57.36 +#ifdef __cplusplus
   57.37 +}
   57.38 +#endif
   57.39 +
   57.40 +#endif
    58.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    58.2 +++ b/src/video/haiku/SDL_bframebuffer.cc	Thu Nov 14 22:35:28 2013 +0530
    58.3 @@ -0,0 +1,254 @@
    58.4 +/*
    58.5 +  Simple DirectMedia Layer
    58.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    58.7 +
    58.8 +  This software is provided 'as-is', without any express or implied
    58.9 +  warranty.  In no event will the authors be held liable for any damages
   58.10 +  arising from the use of this software.
   58.11 +
   58.12 +  Permission is granted to anyone to use this software for any purpose,
   58.13 +  including commercial applications, and to alter it and redistribute it
   58.14 +  freely, subject to the following restrictions:
   58.15 +
   58.16 +  1. The origin of this software must not be misrepresented; you must not
   58.17 +     claim that you wrote the original software. If you use this software
   58.18 +     in a product, an acknowledgment in the product documentation would be
   58.19 +     appreciated but is not required.
   58.20 +  2. Altered source versions must be plainly marked as such, and must not be
   58.21 +     misrepresented as being the original software.
   58.22 +  3. This notice may not be removed or altered from any source distribution.
   58.23 +*/
   58.24 +#include "SDL_config.h"
   58.25 +
   58.26 +#if SDL_VIDEO_DRIVER_HAIKU
   58.27 +
   58.28 +#include "SDL_bframebuffer.h"
   58.29 +
   58.30 +#include <AppKit.h>
   58.31 +#include <InterfaceKit.h>
   58.32 +#include "SDL_bmodes.h"
   58.33 +#include "SDL_BWin.h"
   58.34 +
   58.35 +#include "../../main/haiku/SDL_BApp.h"
   58.36 +
   58.37 +#ifdef __cplusplus
   58.38 +extern "C" {
   58.39 +#endif
   58.40 +
   58.41 +int32 BE_UpdateOnce(SDL_Window *window);
   58.42 +
   58.43 +static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) {
   58.44 +	return ((SDL_BWin*)(window->driverdata));
   58.45 +}
   58.46 +
   58.47 +static SDL_INLINE SDL_BApp *_GetBeApp() {
   58.48 +	return ((SDL_BApp*)be_app);
   58.49 +}
   58.50 +
   58.51 +int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window,
   58.52 +                                       Uint32 * format,
   58.53 +                                       void ** pixels, int *pitch) {
   58.54 +	SDL_BWin *bwin = _ToBeWin(window);
   58.55 +	BScreen bscreen;
   58.56 +	if(!bscreen.IsValid()) {
   58.57 +		return -1;
   58.58 +	}
   58.59 +
   58.60 +	while(!bwin->Connected()) { snooze(100); }
   58.61 +	
   58.62 +	/* Make sure we have exclusive access to frame buffer data */
   58.63 +	bwin->LockBuffer();
   58.64 +
   58.65 +	/* format */
   58.66 +	display_mode bmode;
   58.67 +	bscreen.GetMode(&bmode);
   58.68 +	int32 bpp = BE_ColorSpaceToBitsPerPixel(bmode.space);
   58.69 +	*format = BE_BPPToSDLPxFormat(bpp);
   58.70 +
   58.71 +	/* Create the new bitmap object */
   58.72 +	BBitmap *bitmap = bwin->GetBitmap();
   58.73 +
   58.74 +	if(bitmap) {
   58.75 +		delete bitmap;
   58.76 +	}
   58.77 +	bitmap = new BBitmap(bwin->Bounds(), (color_space)bmode.space,
   58.78 +			false,	/* Views not accepted */
   58.79 +			true);	/* Contiguous memory required */
   58.80 +			
   58.81 +	if(bitmap->InitCheck() != B_OK) {
   58.82 +		return SDL_SetError("Could not initialize back buffer!\n");
   58.83 +	}
   58.84 +
   58.85 +
   58.86 +	bwin->SetBitmap(bitmap);
   58.87 +	
   58.88 +	/* Set the pixel pointer */
   58.89 +	*pixels = bitmap->Bits();
   58.90 +
   58.91 +	/* pitch = width of window, in bytes */
   58.92 +	*pitch = bitmap->BytesPerRow();
   58.93 +
   58.94 +	bwin->SetBufferExists(true);
   58.95 +	bwin->SetTrashBuffer(false);
   58.96 +	bwin->UnlockBuffer();
   58.97 +	return 0;
   58.98 +}
   58.99 +
  58.100 +
  58.101 +
  58.102 +int BE_UpdateWindowFramebuffer(_THIS, SDL_Window * window,
  58.103 +                                      const SDL_Rect * rects, int numrects) {
  58.104 +	if(!window)
  58.105 +		return 0;
  58.106 +
  58.107 +	SDL_BWin *bwin = _ToBeWin(window);
  58.108 +
  58.109 +#ifdef DRAWTHREAD	
  58.110 +	bwin->LockBuffer();
  58.111 +	bwin->SetBufferDirty(true);
  58.112 +	bwin->UnlockBuffer();
  58.113 +#else
  58.114 +	bwin->SetBufferDirty(true);
  58.115 +	BE_UpdateOnce(window);
  58.116 +#endif
  58.117 +
  58.118 +	return 0;
  58.119 +}
  58.120 +
  58.121 +int32 BE_DrawThread(void *data) {
  58.122 +	SDL_BWin *bwin = (SDL_BWin*)data;
  58.123 +	
  58.124 +	BScreen bscreen;
  58.125 +	if(!bscreen.IsValid()) {
  58.126 +		return -1;
  58.127 +	}
  58.128 +
  58.129 +	while(bwin->ConnectionEnabled()) {
  58.130 +		if( bwin->Connected() && bwin->BufferExists() && bwin->BufferIsDirty() ) {
  58.131 +			bwin->LockBuffer();
  58.132 +			BBitmap *bitmap = NULL;
  58.133 +			bitmap = bwin->GetBitmap();
  58.134 +			int32 windowPitch = bitmap->BytesPerRow();
  58.135 +			int32 bufferPitch = bwin->GetRowBytes();
  58.136 +			uint8 *windowpx;
  58.137 +			uint8 *bufferpx;
  58.138 +
  58.139 +			int32 BPP = bwin->GetBytesPerPx();
  58.140 +			int32 windowSub = bwin->GetFbX() * BPP +
  58.141 +						  bwin->GetFbY() * windowPitch;
  58.142 +			clipping_rect *clips = bwin->GetClips();
  58.143 +			int32 numClips = bwin->GetNumClips();
  58.144 +			int i, y;
  58.145 +
  58.146 +			/* Blit each clipping rectangle */
  58.147 +			bscreen.WaitForRetrace();
  58.148 +			for(i = 0; i < numClips; ++i) {
  58.149 +				clipping_rect rc = clips[i];
  58.150 +				/* Get addresses of the start of each clipping rectangle */
  58.151 +				int32 width = clips[i].right - clips[i].left + 1;
  58.152 +				int32 height = clips[i].bottom - clips[i].top + 1;
  58.153 +				bufferpx = bwin->GetBufferPx() + 
  58.154 +					clips[i].top * bufferPitch + clips[i].left * BPP;
  58.155 +				windowpx = (uint8*)bitmap->Bits() + 
  58.156 +					clips[i].top * windowPitch + clips[i].left * BPP -
  58.157 +					windowSub;
  58.158 +
  58.159 +				/* Copy each row of pixels from the window buffer into the frame
  58.160 +				   buffer */
  58.161 +				for(y = 0; y < height; ++y)
  58.162 +				{
  58.163 +
  58.164 +					if(bwin->CanTrashWindowBuffer()) {
  58.165 +						goto escape;	/* Break out before the buffer is killed */
  58.166 +					}
  58.167 +
  58.168 +					memcpy(bufferpx, windowpx, width * BPP);
  58.169 +					bufferpx += bufferPitch;
  58.170 +					windowpx += windowPitch;
  58.171 +				}
  58.172 +			}
  58.173 +
  58.174 +			bwin->SetBufferDirty(false);
  58.175 +escape:
  58.176 +			bwin->UnlockBuffer();
  58.177 +		} else {
  58.178 +			snooze(16000);
  58.179 +		}
  58.180 +	}
  58.181 +	
  58.182 +	return B_OK;
  58.183 +}
  58.184 +
  58.185 +void BE_DestroyWindowFramebuffer(_THIS, SDL_Window * window) {
  58.186 +	SDL_BWin *bwin = _ToBeWin(window);
  58.187 +	
  58.188 +	bwin->LockBuffer();
  58.189 +	
  58.190 +	/* Free and clear the window buffer */
  58.191 +	BBitmap *bitmap = bwin->GetBitmap();
  58.192 +	delete bitmap;
  58.193 +	bwin->SetBitmap(NULL);
  58.194 +	bwin->SetBufferExists(false);
  58.195 +	bwin->UnlockBuffer();
  58.196 +}
  58.197 +
  58.198 +
  58.199 +/*
  58.200 + * TODO:
  58.201 + * This was written to test if certain errors were caused by threading issues.
  58.202 + * The specific issues have since become rare enough that they may have been
  58.203 + * solved, but I doubt it- they were pretty sporadic before now.
  58.204 + */
  58.205 +int32 BE_UpdateOnce(SDL_Window *window) {
  58.206 +	SDL_BWin *bwin = _ToBeWin(window);
  58.207 +	BScreen bscreen;
  58.208 +	if(!bscreen.IsValid()) {
  58.209 +		return -1;
  58.210 +	}
  58.211 +
  58.212 +	if(bwin->ConnectionEnabled() && bwin->Connected()) {
  58.213 +		bwin->LockBuffer();
  58.214 +		int32 windowPitch = window->surface->pitch;
  58.215 +		int32 bufferPitch = bwin->GetRowBytes();
  58.216 +		uint8 *windowpx;
  58.217 +		uint8 *bufferpx;
  58.218 +
  58.219 +		int32 BPP = bwin->GetBytesPerPx();
  58.220 +		uint8 *windowBaseAddress = (uint8*)window->surface->pixels;
  58.221 +		int32 windowSub = bwin->GetFbX() * BPP +
  58.222 +						  bwin->GetFbY() * windowPitch;
  58.223 +		clipping_rect *clips = bwin->GetClips();
  58.224 +		int32 numClips = bwin->GetNumClips();
  58.225 +		int i, y;
  58.226 +
  58.227 +		/* Blit each clipping rectangle */
  58.228 +		bscreen.WaitForRetrace();
  58.229 +		for(i = 0; i < numClips; ++i) {
  58.230 +			clipping_rect rc = clips[i];
  58.231 +			/* Get addresses of the start of each clipping rectangle */
  58.232 +			int32 width = clips[i].right - clips[i].left + 1;
  58.233 +			int32 height = clips[i].bottom - clips[i].top + 1;
  58.234 +			bufferpx = bwin->GetBufferPx() + 
  58.235 +				clips[i].top * bufferPitch + clips[i].left * BPP;
  58.236 +			windowpx = windowBaseAddress + 
  58.237 +				clips[i].top * windowPitch + clips[i].left * BPP - windowSub;
  58.238 +
  58.239 +			/* Copy each row of pixels from the window buffer into the frame
  58.240 +			   buffer */
  58.241 +			for(y = 0; y < height; ++y)
  58.242 +			{
  58.243 +				memcpy(bufferpx, windowpx, width * BPP);
  58.244 +				bufferpx += bufferPitch;
  58.245 +				windowpx += windowPitch;
  58.246 +			}
  58.247 +		}
  58.248 +		bwin->UnlockBuffer();
  58.249 +	}
  58.250 +	return 0;
  58.251 +}
  58.252 +
  58.253 +#ifdef __cplusplus
  58.254 +}
  58.255 +#endif
  58.256 +
  58.257 +#endif /* SDL_VIDEO_DRIVER_HAIKU */
    59.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    59.2 +++ b/src/video/haiku/SDL_bframebuffer.h	Thu Nov 14 22:35:28 2013 +0530
    59.3 @@ -0,0 +1,45 @@
    59.4 +/*
    59.5 +  Simple DirectMedia Layer
    59.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    59.7 +
    59.8 +  This software is provided 'as-is', without any express or implied
    59.9 +  warranty.  In no event will the authors be held liable for any damages
   59.10 +  arising from the use of this software.
   59.11 +
   59.12 +  Permission is granted to anyone to use this software for any purpose,
   59.13 +  including commercial applications, and to alter it and redistribute it
   59.14 +  freely, subject to the following restrictions:
   59.15 +
   59.16 +  1. The origin of this software must not be misrepresented; you must not
   59.17 +     claim that you wrote the original software. If you use this software
   59.18 +     in a product, an acknowledgment in the product documentation would be
   59.19 +     appreciated but is not required.
   59.20 +  2. Altered source versions must be plainly marked as such, and must not be
   59.21 +     misrepresented as being the original software.
   59.22 +  3. This notice may not be removed or altered from any source distribution.
   59.23 +*/
   59.24 +
   59.25 +#ifndef SDL_BFRAMEBUFFER_H
   59.26 +#define SDL_BFRAMEBUFFER_H
   59.27 +#include <SupportDefs.h>
   59.28 +#ifdef __cplusplus
   59.29 +extern "C" {
   59.30 +#endif
   59.31 +
   59.32 +#define DRAWTHREAD
   59.33 +
   59.34 +#include "../SDL_sysvideo.h"
   59.35 +
   59.36 +extern int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window,
   59.37 +                                       Uint32 * format,
   59.38 +                                       void ** pixels, int *pitch);
   59.39 +extern int BE_UpdateWindowFramebuffer(_THIS, SDL_Window * window,
   59.40 +                                       const SDL_Rect * rects, int numrects);
   59.41 +extern void BE_DestroyWindowFramebuffer(_THIS, SDL_Window * window);
   59.42 +extern int32 BE_DrawThread(void *data);
   59.43 +
   59.44 +#ifdef __cplusplus
   59.45 +}
   59.46 +#endif
   59.47 +
   59.48 +#endif
    60.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    60.2 +++ b/src/video/haiku/SDL_bkeyboard.cc	Thu Nov 14 22:35:28 2013 +0530
    60.3 @@ -0,0 +1,188 @@
    60.4 +/*
    60.5 +  Simple DirectMedia Layer
    60.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    60.7 +
    60.8 +  This software is provided 'as-is', without any express or implied
    60.9 +  warranty.  In no event will the authors be held liable for any damages
   60.10 +  arising from the use of this software.
   60.11 +
   60.12 +  Permission is granted to anyone to use this software for any purpose,
   60.13 +  including commercial applications, and to alter it and redistribute it
   60.14 +  freely, subject to the following restrictions:
   60.15 +
   60.16 +  1. The origin of this software must not be misrepresented; you must not
   60.17 +     claim that you wrote the original software. If you use this software
   60.18 +     in a product, an acknowledgment in the product documentation would be
   60.19 +     appreciated but is not required.
   60.20 +  2. Altered source versions must be plainly marked as such, and must not be
   60.21 +     misrepresented as being the original software.
   60.22 +  3. This notice may not be removed or altered from any source distribution.
   60.23 +*/
   60.24 +#include "SDL_config.h"
   60.25 +
   60.26 +#if SDL_VIDEO_DRIVER_HAIKU
   60.27 +
   60.28 +#include <SupportDefs.h>
   60.29 +#include <support/UTF8.h>
   60.30 +
   60.31 +#ifdef __cplusplus
   60.32 +extern "C" {
   60.33 +#endif
   60.34 +
   60.35 +#include "SDL_events.h"
   60.36 +#include "SDL_keycode.h"
   60.37 +
   60.38 +#include "SDL_bkeyboard.h"
   60.39 +
   60.40 +
   60.41 +#define KEYMAP_SIZE 128
   60.42 +
   60.43 +
   60.44 +static SDL_Scancode keymap[KEYMAP_SIZE];
   60.45 +static int8 keystate[KEYMAP_SIZE];
   60.46 +
   60.47 +void BE_InitOSKeymap() {
   60.48 +		for( uint i = 0; i < SDL_TABLESIZE(keymap); ++i ) {
   60.49 +			keymap[i] = SDL_SCANCODE_UNKNOWN;
   60.50 +		}
   60.51 +
   60.52 +		for( uint i = 0; i < KEYMAP_SIZE; ++i ) {
   60.53 +			keystate[i] = SDL_RELEASED;
   60.54 +		}
   60.55 +
   60.56 +		keymap[0x01]		= SDL_GetScancodeFromKey(SDLK_ESCAPE);
   60.57 +		keymap[B_F1_KEY]	= SDL_GetScancodeFromKey(SDLK_F1);
   60.58 +		keymap[B_F2_KEY]	= SDL_GetScancodeFromKey(SDLK_F2);
   60.59 +		keymap[B_F3_KEY]	= SDL_GetScancodeFromKey(SDLK_F3);
   60.60 +		keymap[B_F4_KEY]	= SDL_GetScancodeFromKey(SDLK_F4);
   60.61 +		keymap[B_F5_KEY]	= SDL_GetScancodeFromKey(SDLK_F5);
   60.62 +		keymap[B_F6_KEY]	= SDL_GetScancodeFromKey(SDLK_F6);
   60.63 +		keymap[B_F7_KEY]	= SDL_GetScancodeFromKey(SDLK_F7);
   60.64 +		keymap[B_F8_KEY]	= SDL_GetScancodeFromKey(SDLK_F8);
   60.65 +		keymap[B_F9_KEY]	= SDL_GetScancodeFromKey(SDLK_F9);
   60.66 +		keymap[B_F10_KEY]	= SDL_GetScancodeFromKey(SDLK_F10);
   60.67 +		keymap[B_F11_KEY]	= SDL_GetScancodeFromKey(SDLK_F11);
   60.68 +		keymap[B_F12_KEY]	= SDL_GetScancodeFromKey(SDLK_F12);
   60.69 +		keymap[B_PRINT_KEY]	= SDL_GetScancodeFromKey(SDLK_PRINTSCREEN);
   60.70 +		keymap[B_SCROLL_KEY]	= SDL_GetScancodeFromKey(SDLK_SCROLLLOCK);
   60.71 +		keymap[B_PAUSE_KEY]	= SDL_GetScancodeFromKey(SDLK_PAUSE);
   60.72 +		keymap[0x11]		= SDL_GetScancodeFromKey(SDLK_BACKQUOTE);
   60.73 +		keymap[0x12]		= SDL_GetScancodeFromKey(SDLK_1);
   60.74 +		keymap[0x13]		= SDL_GetScancodeFromKey(SDLK_2);
   60.75 +		keymap[0x14]		= SDL_GetScancodeFromKey(SDLK_3);
   60.76 +		keymap[0x15]		= SDL_GetScancodeFromKey(SDLK_4);
   60.77 +		keymap[0x16]		= SDL_GetScancodeFromKey(SDLK_5);
   60.78 +		keymap[0x17]		= SDL_GetScancodeFromKey(SDLK_6);
   60.79 +		keymap[0x18]		= SDL_GetScancodeFromKey(SDLK_7);
   60.80 +		keymap[0x19]		= SDL_GetScancodeFromKey(SDLK_8);
   60.81 +		keymap[0x1a]		= SDL_GetScancodeFromKey(SDLK_9);
   60.82 +		keymap[0x1b]		= SDL_GetScancodeFromKey(SDLK_0);
   60.83 +		keymap[0x1c]		= SDL_GetScancodeFromKey(SDLK_MINUS);
   60.84 +		keymap[0x1d]		= SDL_GetScancodeFromKey(SDLK_EQUALS);
   60.85 +		keymap[0x1e]		= SDL_GetScancodeFromKey(SDLK_BACKSPACE);
   60.86 +		keymap[0x1f]		= SDL_GetScancodeFromKey(SDLK_INSERT);
   60.87 +		keymap[0x20]		= SDL_GetScancodeFromKey(SDLK_HOME);
   60.88 +		keymap[0x21]		= SDL_GetScancodeFromKey(SDLK_PAGEUP);
   60.89 +		keymap[0x22]		= SDL_GetScancodeFromKey(SDLK_NUMLOCKCLEAR);
   60.90 +		keymap[0x23]		= SDL_GetScancodeFromKey(SDLK_KP_DIVIDE);
   60.91 +		keymap[0x24]		= SDL_GetScancodeFromKey(SDLK_KP_MULTIPLY);
   60.92 +		keymap[0x25]		= SDL_GetScancodeFromKey(SDLK_KP_MINUS);
   60.93 +		keymap[0x26]		= SDL_GetScancodeFromKey(SDLK_TAB);
   60.94 +		keymap[0x27]		= SDL_GetScancodeFromKey(SDLK_q);
   60.95 +		keymap[0x28]		= SDL_GetScancodeFromKey(SDLK_w);
   60.96 +		keymap[0x29]		= SDL_GetScancodeFromKey(SDLK_e);
   60.97 +		keymap[0x2a]		= SDL_GetScancodeFromKey(SDLK_r);
   60.98 +		keymap[0x2b]		= SDL_GetScancodeFromKey(SDLK_t);
   60.99 +		keymap[0x2c]		= SDL_GetScancodeFromKey(SDLK_y);
  60.100 +		keymap[0x2d]		= SDL_GetScancodeFromKey(SDLK_u);
  60.101 +		keymap[0x2e]		= SDL_GetScancodeFromKey(SDLK_i);
  60.102 +		keymap[0x2f]		= SDL_GetScancodeFromKey(SDLK_o);
  60.103 +		keymap[0x30]		= SDL_GetScancodeFromKey(SDLK_p);
  60.104 +		keymap[0x31]		= SDL_GetScancodeFromKey(SDLK_LEFTBRACKET);
  60.105 +		keymap[0x32]		= SDL_GetScancodeFromKey(SDLK_RIGHTBRACKET);
  60.106 +		keymap[0x33]		= SDL_GetScancodeFromKey(SDLK_BACKSLASH);
  60.107 +		keymap[0x34]		= SDL_GetScancodeFromKey(SDLK_DELETE);
  60.108 +		keymap[0x35]		= SDL_GetScancodeFromKey(SDLK_END);
  60.109 +		keymap[0x36]		= SDL_GetScancodeFromKey(SDLK_PAGEDOWN);
  60.110 +		keymap[0x37]		= SDL_GetScancodeFromKey(SDLK_KP_7);
  60.111 +		keymap[0x38]		= SDL_GetScancodeFromKey(SDLK_KP_8);
  60.112 +		keymap[0x39]		= SDL_GetScancodeFromKey(SDLK_KP_9);
  60.113 +		keymap[0x3a]		= SDL_GetScancodeFromKey(SDLK_KP_PLUS);
  60.114 +		keymap[0x3b]		= SDL_GetScancodeFromKey(SDLK_CAPSLOCK);
  60.115 +		keymap[0x3c]		= SDL_GetScancodeFromKey(SDLK_a);
  60.116 +		keymap[0x3d]		= SDL_GetScancodeFromKey(SDLK_s);
  60.117 +		keymap[0x3e]		= SDL_GetScancodeFromKey(SDLK_d);
  60.118 +		keymap[0x3f]		= SDL_GetScancodeFromKey(SDLK_f);
  60.119 +		keymap[0x40]		= SDL_GetScancodeFromKey(SDLK_g);
  60.120 +		keymap[0x41]		= SDL_GetScancodeFromKey(SDLK_h);
  60.121 +		keymap[0x42]		= SDL_GetScancodeFromKey(SDLK_j);
  60.122 +		keymap[0x43]		= SDL_GetScancodeFromKey(SDLK_k);
  60.123 +		keymap[0x44]		= SDL_GetScancodeFromKey(SDLK_l);
  60.124 +		keymap[0x45]		= SDL_GetScancodeFromKey(SDLK_SEMICOLON);
  60.125 +		keymap[0x46]		= SDL_GetScancodeFromKey(SDLK_QUOTE);
  60.126 +		keymap[0x47]		= SDL_GetScancodeFromKey(SDLK_RETURN);
  60.127 +		keymap[0x48]		= SDL_GetScancodeFromKey(SDLK_KP_4);
  60.128 +		keymap[0x49]		= SDL_GetScancodeFromKey(SDLK_KP_5);
  60.129 +		keymap[0x4a]		= SDL_GetScancodeFromKey(SDLK_KP_6);
  60.130 +		keymap[0x4b]		= SDL_GetScancodeFromKey(SDLK_LSHIFT);
  60.131 +		keymap[0x4c]		= SDL_GetScancodeFromKey(SDLK_z);
  60.132 +		keymap[0x4d]		= SDL_GetScancodeFromKey(SDLK_x);
  60.133 +		keymap[0x4e]		= SDL_GetScancodeFromKey(SDLK_c);
  60.134 +		keymap[0x4f]		= SDL_GetScancodeFromKey(SDLK_v);
  60.135 +		keymap[0x50]		= SDL_GetScancodeFromKey(SDLK_b);
  60.136 +		keymap[0x51]		= SDL_GetScancodeFromKey(SDLK_n);
  60.137 +		keymap[0x52]		= SDL_GetScancodeFromKey(SDLK_m);
  60.138 +		keymap[0x53]		= SDL_GetScancodeFromKey(SDLK_COMMA);
  60.139 +		keymap[0x54]		= SDL_GetScancodeFromKey(SDLK_PERIOD);
  60.140 +		keymap[0x55]		= SDL_GetScancodeFromKey(SDLK_SLASH);
  60.141 +		keymap[0x56]		= SDL_GetScancodeFromKey(SDLK_RSHIFT);
  60.142 +		keymap[0x57]		= SDL_GetScancodeFromKey(SDLK_UP);
  60.143 +		keymap[0x58]		= SDL_GetScancodeFromKey(SDLK_KP_1);
  60.144 +		keymap[0x59]		= SDL_GetScancodeFromKey(SDLK_KP_2);
  60.145 +		keymap[0x5a]		= SDL_GetScancodeFromKey(SDLK_KP_3);
  60.146 +		keymap[0x5b]		= SDL_GetScancodeFromKey(SDLK_KP_ENTER);
  60.147 +		keymap[0x5c]		= SDL_GetScancodeFromKey(SDLK_LCTRL);
  60.148 +		keymap[0x5d]		= SDL_GetScancodeFromKey(SDLK_LALT);
  60.149 +		keymap[0x5e]		= SDL_GetScancodeFromKey(SDLK_SPACE);
  60.150 +		keymap[0x5f]		= SDL_GetScancodeFromKey(SDLK_RALT);
  60.151 +		keymap[0x60]		= SDL_GetScancodeFromKey(SDLK_RCTRL);
  60.152 +		keymap[0x61]		= SDL_GetScancodeFromKey(SDLK_LEFT);
  60.153 +		keymap[0x62]		= SDL_GetScancodeFromKey(SDLK_DOWN);
  60.154 +		keymap[0x63]		= SDL_GetScancodeFromKey(SDLK_RIGHT);
  60.155 +		keymap[0x64]		= SDL_GetScancodeFromKey(SDLK_KP_0);
  60.156 +		keymap[0x65]		= SDL_GetScancodeFromKey(SDLK_KP_PERIOD);
  60.157 +		keymap[0x66]		= SDL_GetScancodeFromKey(SDLK_LGUI);
  60.158 +		keymap[0x67]		= SDL_GetScancodeFromKey(SDLK_RGUI);
  60.159 +		keymap[0x68]		= SDL_GetScancodeFromKey(SDLK_MENU);
  60.160 +		keymap[0x69]		= SDL_GetScancodeFromKey(SDLK_2); /* SDLK_EURO */
  60.161 +		keymap[0x6a]		= SDL_GetScancodeFromKey(SDLK_KP_EQUALS);
  60.162 +		keymap[0x6b]		= SDL_GetScancodeFromKey(SDLK_POWER);
  60.163 +}
  60.164 +
  60.165 +SDL_Scancode BE_GetScancodeFromBeKey(int32 bkey) {
  60.166 +	if(bkey > 0 && bkey < (int32)SDL_TABLESIZE(keymap)) {
  60.167 +		return keymap[bkey];
  60.168 +	} else {
  60.169 +		return SDL_SCANCODE_UNKNOWN;
  60.170 +	}
  60.171 +}
  60.172 +
  60.173 +int8 BE_GetKeyState(int32 bkey) {
  60.174 +	if(bkey > 0 && bkey < KEYMAP_SIZE) {
  60.175 +		return keystate[bkey];
  60.176 +	} else {
  60.177 +		return SDL_RELEASED;
  60.178 +	}
  60.179 +}
  60.180 +
  60.181 +void BE_SetKeyState(int32 bkey, int8 state) {
  60.182 +	if(bkey > 0 && bkey < KEYMAP_SIZE) {
  60.183 +		keystate[bkey] = state;
  60.184 +	}
  60.185 +}
  60.186 +
  60.187 +#ifdef __cplusplus
  60.188 +}
  60.189 +#endif
  60.190 +
  60.191 +#endif /* SDL_VIDEO_DRIVER_HAIKU */
    61.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    61.2 +++ b/src/video/haiku/SDL_bkeyboard.h	Thu Nov 14 22:35:28 2013 +0530
    61.3 @@ -0,0 +1,42 @@
    61.4 +/*
    61.5 +  Simple DirectMedia Layer
    61.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    61.7 +
    61.8 +  This software is provided 'as-is', without any express or implied
    61.9 +  warranty.  In no event will the authors be held liable for any damages
   61.10 +  arising from the use of this software.
   61.11 +
   61.12 +  Permission is granted to anyone to use this software for any purpose,
   61.13 +  including commercial applications, and to alter it and redistribute it
   61.14 +  freely, subject to the following restrictions:
   61.15 +
   61.16 +  1. The origin of this software must not be misrepresented; you must not
   61.17 +     claim that you wrote the original software. If you use this software
   61.18 +     in a product, an acknowledgment in the product documentation would be
   61.19 +     appreciated but is not required.
   61.20 +  2. Altered source versions must be plainly marked as such, and must not be
   61.21 +     misrepresented as being the original software.
   61.22 +  3. This notice may not be removed or altered from any source distribution.
   61.23 +*/
   61.24 +
   61.25 +#ifndef SDL_BKEYBOARD_H
   61.26 +#define SDL_BKEYBOARD_H
   61.27 +
   61.28 +#include <SupportDefs.h>
   61.29 +
   61.30 +#ifdef __cplusplus
   61.31 +extern "C" {
   61.32 +#endif
   61.33 +
   61.34 +#include "../../../include/SDL_keyboard.h"
   61.35 +
   61.36 +extern void BE_InitOSKeymap();
   61.37 +extern SDL_Scancode BE_GetScancodeFromBeKey(int32 bkey);
   61.38 +extern int8 BE_GetKeyState(int32 bkey);
   61.39 +extern void BE_SetKeyState(int32 bkey, int8 state);
   61.40 +
   61.41 +#ifdef __cplusplus
   61.42 +}
   61.43 +#endif
   61.44 +
   61.45 +#endif
    62.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    62.2 +++ b/src/video/haiku/SDL_bmodes.cc	Thu Nov 14 22:35:28 2013 +0530
    62.3 @@ -0,0 +1,331 @@
    62.4 +/*
    62.5 +  Simple DirectMedia Layer
    62.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    62.7 +
    62.8 +  This software is provided 'as-is', without any express or implied
    62.9 +  warranty.  In no event will the authors be held liable for any damages
   62.10 +  arising from the use of this software.
   62.11 +
   62.12 +  Permission is granted to anyone to use this software for any purpose,
   62.13 +  including commercial applications, and to alter it and redistribute it
   62.14 +  freely, subject to the following restrictions:
   62.15 +
   62.16 +  1. The origin of this software must not be misrepresented; you must not
   62.17 +     claim that you wrote the original software. If you use this software
   62.18 +     in a product, an acknowledgment in the product documentation would be
   62.19 +     appreciated but is not required.
   62.20 +  2. Altered source versions must be plainly marked as such, and must not be
   62.21 +     misrepresented as being the original software.
   62.22 +  3. This notice may not be removed or altered from any source distribution.
   62.23 +*/
   62.24 +#include "SDL_config.h"
   62.25 +
   62.26 +#if SDL_VIDEO_DRIVER_HAIKU
   62.27 +
   62.28 +#include <AppKit.h>
   62.29 +#include <InterfaceKit.h>
   62.30 +#include "SDL_bmodes.h"
   62.31 +#include "SDL_BWin.h"
   62.32 +
   62.33 +#if SDL_VIDEO_OPENGL
   62.34 +#include "SDL_bopengl.h"
   62.35 +#endif
   62.36 +
   62.37 +#include "../../main/haiku/SDL_BApp.h"
   62.38 +
   62.39 +#ifdef __cplusplus
   62.40 +extern "C" {
   62.41 +#endif
   62.42 +
   62.43 +
   62.44 +#define WRAP_BMODE 1 /* FIXME: Some debate as to whether this is necessary */
   62.45 +
   62.46 +#if WRAP_BMODE
   62.47 +/* This wrapper is here so that the driverdata can be freed without freeing
   62.48 +   the display_mode structure */
   62.49 +typedef struct SDL_DisplayModeData {
   62.50 +	display_mode *bmode;
   62.51 +};
   62.52 +#endif
   62.53 +
   62.54 +static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) {
   62.55 +	return ((SDL_BWin*)(window->driverdata));
   62.56 +}
   62.57 +
   62.58 +static SDL_INLINE SDL_BApp *_GetBeApp() {
   62.59 +	return ((SDL_BApp*)be_app);
   62.60 +}
   62.61 +
   62.62 +static SDL_INLINE display_mode * _ExtractBMode(SDL_DisplayMode *mode) {
   62.63 +#if WRAP_BMODE
   62.64 +	return ((SDL_DisplayModeData*)mode->driverdata)->bmode;
   62.65 +#else
   62.66 +	return (display_mode*)(mode->driverdata);
   62.67 +#endif
   62.68 +}
   62.69 +
   62.70 +/* Copied from haiku/trunk/src/preferences/screen/ScreenMode.cpp */
   62.71 +static float get_refresh_rate(display_mode &mode) {
   62.72 +	return float(mode.timing.pixel_clock * 1000)
   62.73 +		/ float(mode.timing.h_total * mode.timing.v_total);
   62.74 +}
   62.75 +
   62.76 +
   62.77 +#if 0
   62.78 +/* TODO:
   62.79 + * This is a useful debugging tool.  Uncomment and insert into code as needed.
   62.80 + */
   62.81 +void _SpoutModeData(display_mode *bmode) {
   62.82 +	printf("BMode:\n");
   62.83 +	printf("\tw,h = (%i,%i)\n", bmode->virtual_width, bmode->virtual_height);
   62.84 +	printf("\th,v = (%i,%i)\n", bmode->h_display_start, 
   62.85 +			bmode->v_display_start);
   62.86 +	if(bmode->flags) {
   62.87 +		printf("\tFlags:\n");
   62.88 +		if(bmode->flags & B_SCROLL) {
   62.89 +			printf("\t\tB_SCROLL\n");
   62.90 +		}
   62.91 +		if(bmode->flags & B_8_BIT_DAC) {
   62.92 +			printf("\t\tB_8_BIT_DAC\n");
   62.93 +		}
   62.94 +		if(bmode->flags & B_HARDWARE_CURSOR) {
   62.95 +			printf("\t\tB_HARDWARE_CURSOR\n");
   62.96 +		}
   62.97 +		if(bmode->flags & B_PARALLEL_ACCESS) {
   62.98 +			printf("\t\tB_PARALLEL_ACCESS\n");
   62.99 +		}
  62.100 +		if(bmode->flags & B_DPMS) {
  62.101 +			printf("\t\tB_DPMS\n");
  62.102 +		}
  62.103 +		if(bmode->flags & B_IO_FB_NA) {
  62.104 +			printf("\t\tB_IO_FB_NA\n");
  62.105 +		}
  62.106 +	}
  62.107 +	printf("\tTiming:\n");
  62.108 +	printf("\t\tpx clock: %i\n", bmode->timing.pixel_clock);
  62.109 +	printf("\t\th - display: %i sync start: %i sync end: %i total: %i\n",
  62.110 +		bmode->timing.h_display, bmode->timing.h_sync_start,
  62.111 +		bmode->timing.h_sync_end, bmode->timing.h_total);
  62.112 +	printf("\t\tv - display: %i sync start: %i sync end: %i total: %i\n",
  62.113 +		bmode->timing.v_display, bmode->timing.v_sync_start,
  62.114 +		bmode->timing.v_sync_end, bmode->timing.v_total);
  62.115 +	if(bmode->timing.flags) {
  62.116 +		printf("\t\tFlags:\n");
  62.117 +		if(bmode->timing.flags & B_BLANK_PEDESTAL) {
  62.118 +			printf("\t\t\tB_BLANK_PEDESTAL\n");
  62.119 +		}
  62.120 +		if(bmode->timing.flags & B_TIMING_INTERLACED) {
  62.121 +			printf("\t\t\tB_TIMING_INTERLACED\n");
  62.122 +		}
  62.123 +		if(bmode->timing.flags & B_POSITIVE_HSYNC) {
  62.124 +			printf("\t\t\tB_POSITIVE_HSYNC\n");
  62.125 +		}
  62.126 +		if(bmode->timing.flags & B_POSITIVE_VSYNC) {
  62.127 +			printf("\t\t\tB_POSITIVE_VSYNC\n");
  62.128 +		}
  62.129 +		if(bmode->timing.flags & B_SYNC_ON_GREEN) {
  62.130 +			printf("\t\t\tB_SYNC_ON_GREEN\n");
  62.131 +		}
  62.132 +	}
  62.133 +}
  62.134 +#endif
  62.135 +
  62.136 +
  62.137 +
  62.138 +int32 BE_ColorSpaceToBitsPerPixel(uint32 colorspace)
  62.139 +{
  62.140 +	int bitsperpixel;
  62.141 +
  62.142 +	bitsperpixel = 0;
  62.143 +	switch (colorspace) {
  62.144 +	    case B_CMAP8:
  62.145 +		bitsperpixel = 8;
  62.146 +		break;
  62.147 +	    case B_RGB15:
  62.148 +	    case B_RGBA15:
  62.149 +	    case B_RGB15_BIG:
  62.150 +	    case B_RGBA15_BIG:
  62.151 +		bitsperpixel = 15;
  62.152 +		break;
  62.153 +	    case B_RGB16:
  62.154 +	    case B_RGB16_BIG:
  62.155 +		bitsperpixel = 16;
  62.156 +		break;
  62.157 +	    case B_RGB32:
  62.158 +	    case B_RGBA32:
  62.159 +	    case B_RGB32_BIG:
  62.160 +	    case B_RGBA32_BIG:
  62.161 +		bitsperpixel = 32;
  62.162 +		break;
  62.163 +	    default:
  62.164 +		break;
  62.165 +	}
  62.166 +	return(bitsperpixel);
  62.167 +}
  62.168 +
  62.169 +int32 BE_BPPToSDLPxFormat(int32 bpp) {
  62.170 +	/* Translation taken from SDL_windowsmodes.c */
  62.171 +	switch (bpp) {
  62.172 +	case 32:
  62.173 +		return SDL_PIXELFORMAT_RGB888;
  62.174 +		break;
  62.175 +	case 24:	/* May not be supported by Haiku */
  62.176 +		return SDL_PIXELFORMAT_RGB24;
  62.177 +		break;
  62.178 +	case 16:
  62.179 +		return SDL_PIXELFORMAT_RGB565;
  62.180 +		break;
  62.181 +	case 15:
  62.182 +		return SDL_PIXELFORMAT_RGB555;
  62.183 +		break;
  62.184 +	case 8:
  62.185 +		return SDL_PIXELFORMAT_INDEX8;
  62.186 +		break;
  62.187 +	case 4:		/* May not be supported by Haiku */
  62.188 +		return SDL_PIXELFORMAT_INDEX4LSB;
  62.189 +		break;
  62.190 +	}
  62.191 +
  62.192 +	/* May never get here, but safer and needed to shut up compiler */
  62.193 +	SDL_SetError("Invalid bpp value");
  62.194 +	return 0;       
  62.195 +}
  62.196 +
  62.197 +static void _BDisplayModeToSdlDisplayMode(display_mode *bmode,
  62.198 +		SDL_DisplayMode *mode) {
  62.199 +	mode->w = bmode->virtual_width;
  62.200 +	mode->h = bmode->virtual_height;
  62.201 +	mode->refresh_rate = (int)get_refresh_rate(*bmode);
  62.202 +
  62.203 +#if WRAP_BMODE
  62.204 +	SDL_DisplayModeData *data = (SDL_DisplayModeData*)SDL_calloc(1,
  62.205 +		sizeof(SDL_DisplayModeData));
  62.206 +	data->bmode = bmode;
  62.207 +	
  62.208 +	mode->driverdata = data;
  62.209 +
  62.210 +#else
  62.211 +
  62.212 +	mode->driverdata = bmode;
  62.213 +#endif
  62.214 +
  62.215 +	/* Set the format */
  62.216 +	int32 bpp = BE_ColorSpaceToBitsPerPixel(bmode->space);
  62.217 +	mode->format = BE_BPPToSDLPxFormat(bpp);
  62.218 +}
  62.219 +
  62.220 +/* Later, there may be more than one monitor available */
  62.221 +static void _AddDisplay(BScreen *screen) {
  62.222 +	SDL_VideoDisplay display;
  62.223 +	SDL_DisplayMode *mode = (SDL_DisplayMode*)SDL_calloc(1,
  62.224 +		sizeof(SDL_DisplayMode));
  62.225 +	display_mode *bmode = (display_mode*)SDL_calloc(1, sizeof(display_mode));
  62.226 +	screen->GetMode(bmode);
  62.227 +
  62.228 +	_BDisplayModeToSdlDisplayMode(bmode, mode);
  62.229 +	
  62.230 +	SDL_zero(display);
  62.231 +	display.desktop_mode = *mode;
  62.232 +	display.current_mode = *mode;
  62.233 +	
  62.234 +	SDL_AddVideoDisplay(&display);
  62.235 +}
  62.236 +
  62.237 +/*
  62.238 + * Functions called by SDL
  62.239 + */
  62.240 +
  62.241 +int BE_InitModes(_THIS) {
  62.242 +	BScreen screen;
  62.243 +
  62.244 +	/* TODO: When Haiku supports multiple display screens, call
  62.245 +	   _AddDisplayScreen() for each of them. */
  62.246 +	_AddDisplay(&screen);
  62.247 +	return 0;
  62.248 +}
  62.249 +
  62.250 +int BE_QuitModes(_THIS) {
  62.251 +	/* FIXME: Nothing really needs to be done here at the moment? */
  62.252 +	return 0;
  62.253 +}
  62.254 +
  62.255 +
  62.256 +int BE_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect) {
  62.257 +	BScreen bscreen;
  62.258 +	BRect rc = bscreen.Frame();
  62.259 +	rect->x = (int)rc.left;
  62.260 +	rect->y = (int)rc.top;
  62.261 +	rect->w = (int)rc.Width() + 1;
  62.262 +	rect->h = (int)rc.Height() + 1;
  62.263 +	return 0;
  62.264 +}
  62.265 +
  62.266 +void BE_GetDisplayModes(_THIS, SDL_VideoDisplay *display) {
  62.267 +	/* Get the current screen */
  62.268 +	BScreen bscreen;
  62.269 +
  62.270 +	/* Iterate through all of the modes */
  62.271 +	SDL_DisplayMode mode;
  62.272 +	display_mode this_bmode;
  62.273 +	display_mode *bmodes;
  62.274 +	uint32 count, i;
  62.275 +	
  62.276 +	/* Get graphics-hardware supported modes */
  62.277 +	bscreen.GetModeList(&bmodes, &count);
  62.278 +	bscreen.GetMode(&this_bmode);
  62.279 +	
  62.280 +	for(i = 0; i < count; ++i) {
  62.281 +		// FIXME: Apparently there are errors with colorspace changes
  62.282 +		if (bmodes[i].space == this_bmode.space) {
  62.283 +			_BDisplayModeToSdlDisplayMode(&bmodes[i], &mode);
  62.284 +			SDL_AddDisplayMode(display, &mode);
  62.285 +		}
  62.286 +	}
  62.287 +	free(bmodes);
  62.288 +}
  62.289 +
  62.290 +
  62.291 +int BE_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode){
  62.292 +	/* Get the current screen */
  62.293 +	BScreen bscreen;
  62.294 +	if(!bscreen.IsValid()) {
  62.295 +		printf(__FILE__": %d - ERROR: BAD SCREEN\n", __LINE__);
  62.296 +	}
  62.297 +
  62.298 +	/* Set the mode using the driver data */
  62.299 +	display_mode *bmode = _ExtractBMode(mode);
  62.300 +
  62.301 +
  62.302 +	/* FIXME: Is the first option always going to be the right one? */
  62.303 +	uint32 c = 0, i;
  62.304 +	display_mode *bmode_list;
  62.305 +	bscreen.GetModeList(&bmode_list, &c);
  62.306 +	for(i = 0; i < c; ++i) {
  62.307 +		if(	bmode_list[i].space == bmode->space &&
  62.308 +			bmode_list[i].virtual_width == bmode->virtual_width &&
  62.309 +			bmode_list[i].virtual_height == bmode->virtual_height ) {
  62.310 +				bmode = &bmode_list[i];
  62.311 +				break;
  62.312 +		}
  62.313 +	}
  62.314 +
  62.315 +	if(bscreen.SetMode(bmode) != B_OK) {
  62.316 +		return SDL_SetError("Bad video mode\n");
  62.317 +	}
  62.318 +	
  62.319 +	free(bmode_list);
  62.320 +	
  62.321 +#if SDL_VIDEO_OPENGL
  62.322 +	/* FIXME: Is there some way to reboot the OpenGL context?  This doesn't
  62.323 +	   help */
  62.324 +//	BE_GL_RebootContexts(_this);
  62.325 +#endif
  62.326 +
  62.327 +	return 0;
  62.328 +}
  62.329 +
  62.330 +#ifdef __cplusplus
  62.331 +}
  62.332 +#endif
  62.333 +
  62.334 +#endif /* SDL_VIDEO_DRIVER_HAIKU */
    63.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    63.2 +++ b/src/video/haiku/SDL_bmodes.h	Thu Nov 14 22:35:28 2013 +0530
    63.3 @@ -0,0 +1,46 @@
    63.4 +/*
    63.5 +  Simple DirectMedia Layer
    63.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    63.7 +
    63.8 +  This software is provided 'as-is', without any express or implied
    63.9 +  warranty.  In no event will the authors be held liable for any damages
   63.10 +  arising from the use of this software.
   63.11 +
   63.12 +  Permission is granted to anyone to use this software for any purpose,
   63.13 +  including commercial applications, and to alter it and redistribute it
   63.14 +  freely, subject to the following restrictions:
   63.15 +
   63.16 +  1. The origin of this software must not be misrepresented; you must not
   63.17 +     claim that you wrote the original software. If you use this software
   63.18 +     in a product, an acknowledgment in the product documentation would be
   63.19 +     appreciated but is not required.
   63.20 +  2. Altered source versions must be plainly marked as such, and must not be
   63.21 +     misrepresented as being the original software.
   63.22 +  3. This notice may not be removed or altered from any source distribution.
   63.23 +*/
   63.24 +
   63.25 +#ifndef SDL_BMODES_H
   63.26 +#define SDL_BMODES_H
   63.27 +
   63.28 +#ifdef __cplusplus
   63.29 +extern "C" {
   63.30 +#endif
   63.31 +
   63.32 +#include "../SDL_sysvideo.h"
   63.33 +
   63.34 +extern int32 BE_ColorSpaceToBitsPerPixel(uint32 colorspace);
   63.35 +extern int32 BE_BPPToSDLPxFormat(int32 bpp);
   63.36 +
   63.37 +extern int BE_InitModes(_THIS);
   63.38 +extern int BE_QuitModes(_THIS);
   63.39 +extern int BE_GetDisplayBounds(_THIS, SDL_VideoDisplay *display,
   63.40 +    SDL_Rect *rect);
   63.41 +extern void BE_GetDisplayModes(_THIS, SDL_VideoDisplay *display);
   63.42 +extern int BE_SetDisplayMode(_THIS, SDL_VideoDisplay *display,
   63.43 +    SDL_DisplayMode *mode);
   63.44 +
   63.45 +#ifdef __cplusplus
   63.46 +}
   63.47 +#endif
   63.48 +
   63.49 +#endif
    64.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    64.2 +++ b/src/video/haiku/SDL_bopengl.cc	Thu Nov 14 22:35:28 2013 +0530
    64.3 @@ -0,0 +1,219 @@
    64.4 +/*
    64.5 +  Simple DirectMedia Layer
    64.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    64.7 +
    64.8 +  This software is provided 'as-is', without any express or implied
    64.9 +  warranty.  In no event will the authors be held liable for any damages
   64.10 +  arising from the use of this software.
   64.11 +
   64.12 +  Permission is granted to anyone to use this software for any purpose,
   64.13 +  including commercial applications, and to alter it and redistribute it
   64.14 +  freely, subject to the following restrictions:
   64.15 +
   64.16 +  1. The origin of this software must not be misrepresented; you must not
   64.17 +     claim that you wrote the original software. If you use this software
   64.18 +     in a product, an acknowledgment in the product documentation would be
   64.19 +     appreciated but is not required.
   64.20 +  2. Altered source versions must be plainly marked as such, and must not be
   64.21 +     misrepresented as being the original software.
   64.22 +  3. This notice may not be removed or altered from any source distribution.
   64.23 +*/
   64.24 +#include "SDL_config.h"
   64.25 +
   64.26 +#if SDL_VIDEO_DRIVER_HAIKU
   64.27 +
   64.28 +#include "SDL_bopengl.h"
   64.29 +
   64.30 +#include <unistd.h>
   64.31 +#include <KernelKit.h>
   64.32 +#include <OpenGLKit.h>
   64.33 +#include "SDL_BWin.h"
   64.34 +#include "../../main/haiku/SDL_BApp.h"
   64.35 +
   64.36 +#ifdef __cplusplus
   64.37 +extern "C" {
   64.38 +#endif
   64.39 +
   64.40 +
   64.41 +#define BGL_FLAGS BGL_RGB | BGL_DOUBLE
   64.42 +
   64.43 +static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) {
   64.44 +	return ((SDL_BWin*)(window->driverdata));
   64.45 +}
   64.46 +
   64.47 +static SDL_INLINE SDL_BApp *_GetBeApp() {
   64.48 +	return ((SDL_BApp*)be_app);
   64.49 +}
   64.50 +
   64.51 +/* Passing a NULL path means load pointers from the application */
   64.52 +int BE_GL_LoadLibrary(_THIS, const char *path)
   64.53 +{
   64.54 +/* FIXME: Is this working correctly? */
   64.55 +	image_info info;
   64.56 +			int32 cookie = 0;
   64.57 +	while (get_next_image_info(0, &cookie, &info) == B_OK) {
   64.58 +		void *location = NULL;
   64.59 +		if( get_image_symbol(info.id, "glBegin", B_SYMBOL_TYPE_ANY,
   64.60 +				&location) == B_OK) {
   64.61 +
   64.62 +			_this->gl_config.dll_handle = (void *) info.id;
   64.63 +			_this->gl_config.driver_loaded = 1;
   64.64 +			SDL_strlcpy(_this->gl_config.driver_path, "libGL.so",
   64.65 +					SDL_arraysize(_this->gl_config.driver_path));
   64.66 +		}
   64.67 +	}
   64.68 +	return 0;
   64.69 +}
   64.70 +
   64.71 +void *BE_GL_GetProcAddress(_THIS, const char *proc)
   64.72 +{
   64.73 +	if (_this->gl_config.dll_handle != NULL) {
   64.74 +		void *location = NULL;
   64.75 +		status_t err;
   64.76 +		if ((err =
   64.77 +			get_image_symbol((image_id) _this->gl_config.dll_handle,
   64.78 +                              proc, B_SYMBOL_TYPE_ANY,
   64.79 +                              &location)) == B_OK) {
   64.80 +            return location;
   64.81 +        } else {
   64.82 +                SDL_SetError("Couldn't find OpenGL symbol");
   64.83 +                return NULL;
   64.84 +        }
   64.85 +	} else {
   64.86 +		SDL_SetError("OpenGL library not loaded");
   64.87 +		return NULL;
   64.88 +	}
   64.89 +}
   64.90 +
   64.91 +
   64.92 +
   64.93 +
   64.94 +void BE_GL_SwapWindow(_THIS, SDL_Window * window) {
   64.95 +    _ToBeWin(window)->SwapBuffers();
   64.96 +}
   64.97 +
   64.98 +int BE_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) {
   64.99 +	_GetBeApp()->SetCurrentContext(((SDL_BWin*)context)->GetGLView());
  64.100 +	return 0;
  64.101 +}
  64.102 +
  64.103 +
  64.104 +SDL_GLContext BE_GL_CreateContext(_THIS, SDL_Window * window) {
  64.105 +	/* FIXME: Not sure what flags should be included here; may want to have
  64.106 +	   most of them */
  64.107 +	SDL_BWin *bwin = _ToBeWin(window);
  64.108 +	bwin->CreateGLView(BGL_FLAGS);
  64.109 +	return (SDL_GLContext)(bwin);
  64.110 +}
  64.111 +
  64.112 +void BE_GL_DeleteContext(_THIS, SDL_GLContext context) {
  64.113 +	/* Currently, automatically unlocks the view */
  64.114 +	((SDL_BWin*)context)->RemoveGLView();
  64.115 +}
  64.116 +
  64.117 +
  64.118 +int BE_GL_SetSwapInterval(_THIS, int interval) {
  64.119 +	/* TODO: Implement this, if necessary? */
  64.120 +	return 0;
  64.121 +}
  64.122 +
  64.123 +int BE_GL_GetSwapInterval(_THIS) {
  64.124 +	/* TODO: Implement this, if necessary? */
  64.125 +	return 0;
  64.126 +}
  64.127 +
  64.128 +
  64.129 +void BE_GL_UnloadLibrary(_THIS) {
  64.130 +	/* TODO: Implement this, if necessary? */
  64.131 +}
  64.132 +
  64.133 +
  64.134 +/* FIXME: This function is meant to clear the OpenGL context when the video
  64.135 +   mode changes (see SDL_bmodes.cc), but it doesn't seem to help, and is not
  64.136 +   currently in use. */
  64.137 +void BE_GL_RebootContexts(_THIS) {
  64.138 +	SDL_Window *window = _this->windows;
  64.139 +	while(window) {
  64.140 +		SDL_BWin *bwin = _ToBeWin(window);
  64.141 +		if(bwin->GetGLView()) {
  64.142 +			bwin->LockLooper();
  64.143 +			bwin->RemoveGLView();
  64.144 +			bwin->CreateGLView(BGL_FLAGS);
  64.145 +			bwin->UnlockLooper();
  64.146 +		}
  64.147 +		window = window->next;
  64.148 +	}
  64.149 +}
  64.150 +
  64.151 +
  64.152 +#if 0 /* Functions from 1.2 that do not appear to be used in 1.3 */
  64.153 +
  64.154 +    int BE_GL_GetAttribute(_THIS, SDL_GLattr attrib, int *value)
  64.155 +    {
  64.156 +        /*
  64.157 +           FIXME? Right now BE_GL_GetAttribute shouldn't be called between glBegin() and glEnd() - it doesn't use "cached" values
  64.158 +         */
  64.159 +        switch (attrib) {
  64.160 +        case SDL_GL_RED_SIZE:
  64.161 +            glGetIntegerv(GL_RED_BITS, (GLint *) value);
  64.162 +            break;
  64.163 +        case SDL_GL_GREEN_SIZE:
  64.164 +            glGetIntegerv(GL_GREEN_BITS, (GLint *) value);
  64.165 +            break;
  64.166 +        case SDL_GL_BLUE_SIZE:
  64.167 +            glGetIntegerv(GL_BLUE_BITS, (GLint *) value);
  64.168 +            break;
  64.169 +        case SDL_GL_ALPHA_SIZE:
  64.170 +            glGetIntegerv(GL_ALPHA_BITS, (GLint *) value);
  64.171 +            break;
  64.172 +        case SDL_GL_DOUBLEBUFFER:
  64.173 +            glGetBooleanv(GL_DOUBLEBUFFER, (GLboolean *) value);
  64.174 +            break;
  64.175 +        case SDL_GL_BUFFER_SIZE:
  64.176 +            int v;
  64.177 +            glGetIntegerv(GL_RED_BITS, (GLint *) & v);
  64.178 +            *value = v;
  64.179 +            glGetIntegerv(GL_GREEN_BITS, (GLint *) & v);
  64.180 +            *value += v;
  64.181 +            glGetIntegerv(GL_BLUE_BITS, (GLint *) & v);
  64.182 +            *value += v;
  64.183 +            glGetIntegerv(GL_ALPHA_BITS, (GLint *) & v);
  64.184 +            *value += v;
  64.185 +            break;
  64.186 +        case SDL_GL_DEPTH_SIZE:
  64.187 +            glGetIntegerv(GL_DEPTH_BITS, (GLint *) value);      /* Mesa creates 16 only? r5 always 32 */
  64.188 +            break;
  64.189 +        case SDL_GL_STENCIL_SIZE:
  64.190 +            glGetIntegerv(GL_STENCIL_BITS, (GLint *) value);
  64.191 +            break;
  64.192 +        case SDL_GL_ACCUM_RED_SIZE:
  64.193 +            glGetIntegerv(GL_ACCUM_RED_BITS, (GLint *) value);
  64.194 +            break;
  64.195 +        case SDL_GL_ACCUM_GREEN_SIZE:
  64.196 +            glGetIntegerv(GL_ACCUM_GREEN_BITS, (GLint *) value);
  64.197 +            break;
  64.198 +        case SDL_GL_ACCUM_BLUE_SIZE:
  64.199 +            glGetIntegerv(GL_ACCUM_BLUE_BITS, (GLint *) value);
  64.200 +            break;
  64.201 +        case SDL_GL_ACCUM_ALPHA_SIZE:
  64.202 +            glGetIntegerv(GL_ACCUM_ALP