# HG changeset patch
# User Sam Lantinga
# Date 1147853908 0
# Node ID 14717b52abc036a362089e9d8d7e6a240df65c9d
# Parent e49147870aaca22c2c65af08953607dd9a2f762e
Merge trunk-1.3-3
diff -r e49147870aac -r 14717b52abc0 CWprojects.sea.bin
Binary file CWprojects.sea.bin has changed
diff -r e49147870aac -r 14717b52abc0 Makefile.in
--- a/Makefile.in Mon May 01 06:58:33 2006 +0000
+++ b/Makefile.in Wed May 17 08:18:28 2006 +0000
@@ -38,7 +38,7 @@
SDLMAIN_SOURCES = @SDLMAIN_SOURCES@
SDLMAIN_OBJECTS = @SDLMAIN_OBJECTS@
-DIST = acinclude.m4 autogen.sh Borland.html Borland.zip BUGS build-scripts configure configure.in COPYING CREDITS CWprojects.sea.bin docs docs.html EpocBuildFiles.zip include INSTALL Makefile.dc Makefile.minimal Makefile.in MPWmake.sea.bin README* sdl-config.in sdl.m4 SDL.qpg.in SDL.spec SDL.spec.in src test TODO VisualCE.zip VisualC.html VisualC.zip Watcom-OS2.zip WhatsNew Xcode.tar.gz
+DIST = acinclude.m4 autogen.sh Borland.html Borland.zip BUGS build-scripts configure configure.in COPYING CREDITS CWprojects.sea.bin docs docs.html EpocBuildFiles.zip include INSTALL Makefile.dc Makefile.minimal Makefile.in MPWmake.sea.bin README* sdl-config.in sdl.m4 SDL.qpg.in SDL.spec SDL.spec.in src test TODO VisualCE.zip VisualC.html VisualC.zip Watcom-OS2.zip Watcom-Win32.zip WhatsNew Xcode.tar.gz
LT_AGE = @LT_AGE@
LT_CURRENT = @LT_CURRENT@
@@ -78,7 +78,7 @@
$(AR) cru $@ $(SDLMAIN_OBJECTS)
$(RANLIB) $@
-install: install-bin install-hdrs install-lib install-data install-man
+install: all install-bin install-hdrs install-lib install-data install-man
install-bin:
$(SHELL) $(auxdir)/mkinstalldirs $(bindir)
$(INSTALL) -m 755 sdl-config $(bindir)/sdl-config
@@ -131,7 +131,6 @@
distclean: clean
rm -f Makefile include/SDL_config.h sdl-config
- rm -f include/SDL_config.h sdl-config
rm -f SDL.qpg
rm -f config.status config.cache config.log libtool $(depend)
rm -rf $(srcdir)/autom4te*
@@ -151,8 +150,15 @@
tar cf - $(DIST) | (cd $(distdir); tar xf -)
cp $(distdir)/include/SDL_config.h.default $(distdir)/include/SDL_config.h
rm -rf `find $(distdir) -name .svn`
- rm -f `find $(distdir) -name '.#*'`
- rmdir `find $(distdir) -type d -empty`
+ find $(distdir) \( \
+ -name '*~' -o \
+ -name '*.bak' -o \
+ -name '*.old' -o \
+ -name '*.rej' -o \
+ -name '*.orig' -o \
+ -name '.#*' \) \
+ -exec rm -f {} \;
+ if test -f $(distdir)/test/Makefile; then (cd $(distdir)/test && make distclean); fi
tar cvf - $(distdir) | gzip --best >$(distfile)
rm -rf $(distdir)
diff -r e49147870aac -r 14717b52abc0 README
--- a/README Mon May 01 06:58:33 2006 +0000
+++ b/README Wed May 17 08:18:28 2006 +0000
@@ -12,14 +12,15 @@
level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL,
and 2D framebuffer across multiple platforms.
-SDL is written in C, but works with C++ natively, and has bindings to
-several other languages, including Ada, C#, Eiffel, Java, Lua, ML,
-Objective C, Pascal, Perl, PHP, Pike, Python, and Ruby.
+The current version supports Linux, Windows, Windows CE, BeOS, MacOS,
+Mac OS X, FreeBSD, NetBSD, OpenBSD, BSD/OS, Solaris, IRIX, and QNX.
+The code contains support for AmigaOS, Dreamcast, Atari, AIX, OSF/Tru64,
+RISC OS, SymbianOS, and OS/2, but these are not officially supported.
-The current version supports Linux, Windows, BeOS, MacOS, Mac OS X,
-FreeBSD, OpenBSD, BSD/OS, Solaris, IRIX, and QNX. The code contains
-support for Windows CE, AmigaOS, Dreamcast, Atari, NetBSD, AIX, OSF/Tru64,
-RISC OS, SymbianOS, and OS/2, but these are not officially supported.
+SDL is written in C, but works with C++ natively, and has bindings to
+several other languages, including Ada, C#, Eiffel, Erlang, Euphoria,
+Guile, Haskell, Java, Lisp, Lua, ML, Objective C, Pascal, Perl, PHP,
+Pike, Pliant, Python, Ruby, and Smalltalk.
This library is distributed under GNU LGPL version 2, which can be
found in the file "COPYING". This license allows you to use SDL
@@ -29,7 +30,9 @@
The best way to learn how to use SDL is to check out the header files in
the "include" subdirectory and the programs in the "test" subdirectory.
The header files and test programs are well commented and always up to date.
-More documentation is available in HTML format in "./docs/index.html"
+More documentation is available in HTML format in "docs/index.html", and
+a documentation wiki is available online at:
+ http://www.libsdl.org/cgi/docwiki.cgi
The test programs in the "test" subdirectory are in the public domain.
diff -r e49147870aac -r 14717b52abc0 README.MacOSX
--- a/README.MacOSX Mon May 01 06:58:33 2006 +0000
+++ b/README.MacOSX Wed May 17 08:18:28 2006 +0000
@@ -21,6 +21,10 @@
the fatbuild.sh script in build-scripts:
sh build-scripts/fatbuild.sh
sudo build-scripts/fatbuild.sh install
+This script builds SDL with 10.2 ABI compatibility on PowerPC and 10.4
+ABI compatibility on Intel architectures. For best compatibility you
+should compile your application the same way. A script which wraps
+gcc to make this easy is provided in test/gcc-fat.sh
To use the library once it's built, you essential have two possibilities:
use the traditional autoconf/automake/make method, or use Xcode.
diff -r e49147870aac -r 14717b52abc0 README.OS2
--- a/README.OS2 Mon May 01 06:58:33 2006 +0000
+++ b/README.OS2 Wed May 17 08:18:28 2006 +0000
@@ -3,7 +3,7 @@
SDL on OS/2
===========
-Last updated on Feb. 26, 2006.
+Last updated on May. 1, 2006.
1. How to compile?
@@ -16,10 +16,9 @@
- The FSLib library
(ftp://ftp.netlabs.org/pub/SDL)
-First of all, you have to put the OS/2-specific Watcom makefiles into the
-source code tree by unzipping the file Watcom-OS2.zip here. This will
-result in a Watcom.mif and a setvars.cmd file in this folder, and several
-Makefile.wat files in the src\ folder and in some of its subfolders.
+First of all, you have to unzip the Watcom-OS2.zip file. This will result in a
+file called "makefile" and a file called "setvars.cmd" in this folder (and some
+more files...).
Please edit the second, fourth and fifth lines of setvars.cmd file
to set the folders where the toolkit, the OW compiler and the FSLib are.
@@ -27,23 +26,22 @@
Run setvars.cmd, and you should get a shell in which you can
compile SDL.
-Check the "Watcom.mif" file. This is the file which is included by all the
-Watcom makefiles, so changes here will affect the whole build process.
-There is a line in there which determines if the resulting SDL.DLL will be
-a 'debug' or a 'release' build. The 'debug' version is full of printf()'s,
-so if something goes wrong, its output can help a lot for debugging.
+Check the "makefile" file. There is a line in there which determines if the
+resulting SDL.DLL will be a 'debug' or a 'release' build. The 'debug' version
+is full of printf()'s, so if something goes wrong, its output can help a lot
+for debugging.
-Then go to the 'src' folder, and run "wmake -f makefile.wat".
-This should create the SDL.DLL and the corresponding SDL.LIB file there.
+Then run "wmake".
+This should create the SDL.DLL and the corresponding SDL.LIB file here.
To test applications, it's a good idea to use the 'debug' build of SDL, and
redirect the standard output and standard error output to files, to see what
happens internally in SDL.
(like: testsprite >stdout.txt 2>stderr.txt)
-To rebuild SDL, use the following commands in 'src' folder:
-wmake -f makefile.wat clean
-wmake -f makefile.wat
+To rebuild SDL, use the following commands in this folder:
+wmake clean
+wmake
@@ -53,7 +51,7 @@
Once you have SDL.DLL compiled, navigate into the 'test' folder, copy in there
the newly built SDL.DLL, and copy in there FSLib.DLL.
-Then run "wmake -f makefile.wat" in there to compile some of the testapps.
+Then run "wmake" in there to compile some of the testapps.
@@ -193,6 +191,10 @@
10. Changelog of the OS/2 port
------------------------------
+Version 1.2 - 2006-05-01 - Doodle
+ - Modified makefile system to have only one makefile
+ - Included FSLib headers, DLL and LIB file
+
Version 1.2 - 2006-02-26 - Doodle
- Updated the official SDL version with the OS/2 specific changes.
- Added support for real unicode keycode conversion.
diff -r e49147870aac -r 14717b52abc0 README.SVN
--- a/README.SVN Mon May 01 06:58:33 2006 +0000
+++ b/README.SVN Wed May 17 08:18:28 2006 +0000
@@ -9,10 +9,12 @@
svn checkout svn://libsdl.org/trunk/SDL
-When you check out a fresh copy of SDL out via svn, you need to
-generate the files used by make by running the "autogen.sh"
-script, which will run aclocal, automake, autoconf and then
-run configure.
+If you are building SDL with an IDE, you will need to copy the file
+include/SDL_config.h.default to include/SDL_config.h before building.
-There is a web interface to svn at http://www.libsdl.org/wsvn
+If you are building SDL via configure, you will need to run autogen.sh
+before running configure.
+There is a web interface to the subversion repository at:
+ http://www.libsdl.org/cgi/viewvc.cgi
+
diff -r e49147870aac -r 14717b52abc0 README.Watcom
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/README.Watcom Wed May 17 08:18:28 2006 +0000
@@ -0,0 +1,129 @@
+
+Using SDL under Windows with the OpenWatcom compiler
+====================================================
+
+Prerequisites
+-------------
+
+I have done the port under Windows XP Home with SP2 installed. Windows
+2000 should also be working. I'm not so sure about ancient Windows NT,
+since only DirectX 3 is available there. Building should be possible,
+but running the compiled applications will probalbly fail with
+SDL_VIDEODRIVER=directx. The windib driver should work, though.
+
+To compile and use the SDL with Open Watcom you will need the following:
+- Open Watcom compiler. I used version 1.5. The environment variables
+ PATH, WATCOM and INCLUDE need to be set appropriately - please consult
+ the OpenWatcom documentation and instructions given during the
+ installation of the compiler.
+ My setup looks like this in owvars.bat:
+ set WATCOM=C:\watcom
+ set INCLUDE=%WATCOM%\h;%WATCOM%\h\nt
+ set PATH=%PATH%;%WATCOM%\binnt;%WATCOM%\binw
+- A fairly recent DirectX SDK. The original unmodified DX8 SDK works, as
+ well as the minimal DirectX 7 SDK from the Allegro download site
+ ().
+- The SDL sources from Subversion
+- The file Watcom-Win32.zip (now available in Subversion)
+
+
+Building the Library
+--------------------
+
+1) In the SDL base directory extract the archive Watcom-Win32.zip. This
+ creates a subdirectory named 'watcom'.
+2) The makefile expects the environment variable DXDIR to be set to the
+ base directory of a DirectX SDK. I have tried a stock DX8 SDK from
+ Microsoft as well as the minimal DirectX 7 SDK from the Allegro
+ download site.
+ You can also edit the makefile directly and hard code your path to
+ the SDK on your system.
+ I have this in my setup:
+ set DXDIR=D:\devel\DX8_SDK
+3) Enter the watcom directory and run
+ wmake sdl
+4) All tests from the test directory are working and can be built by
+ running
+ wmake tests
+
+Notes:
+
+ The makefile offers some options to tweak the way the library is built.
+ You have at your disposal the option to build a static (default)
+ library, or a DLL (with tgt=dll). You can also choose whether to build
+ a Release (default) or a Debug version (with build=debug) of the tests
+ and library. Please consult the usage comment at the top of the
+ makefile for usage instructions.
+
+ If you specify a test target (i.e. 'wmake tests' for all tests, or
+ selected targets like 'wmake testgl testvidinfo testoverlay2'), the
+ tests are always freshly compiled and linked. This is done to
+ minimise hassle when switching between library versions (static vs.
+ DLL), because they require subtly different options.
+ Also, the test executables are put directly into the test directory,
+ so they can find their data files. The clean target of the makefile
+ removes the test executables and the SDL.dll file from the test
+ directory.
+
+ To use the library in your own projects with Open Watcom, you can use
+ the way the tests are built as base of your own build environment.
+
+
+Test applications
+-----------------
+
+I've tried to make all tests work. The following table gives an overview
+of the current status.
+
+ Testname Status
+~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+checkkeys +
+graywin +
+loopwave +
+testalpha +
+testbitmap +
+testdyngl +
+testerror +
+testfile +
+testgamma +
+testgl +
+testhread +
+testiconv - (all failed)
+testkeys +
+testlock +
+testoverlay + (needs 'set SDL_VIDEODRIVER=directx')
+testoverlay2 + (needs 'set SDL_VIDEODRIVER=directx')
+testpalette +
+testplatform +
+testsem +
+testsprite +
+testtimer +
+testver +
+testvidinfo +
+testwin - (fading doesn't seem right)
+testwm +
+torturethread +
+testcdrom +
+testjoystick not tested
+threadwin +
+
+
+TODO
+----
+
+There is room for further improvement:
+- Test joystick functionality.
+- Investigate fading issue in 'testwin' test.
+- Fix the UTF-8 support.
+- Adapt the makefile/object file list to support more target systems
+- Use "#pragma aux" syntax for the CPU info functions.
+
+
+Questions and Comments
+----------------------
+
+Please direct any questions or comments to me:
+
+ Happy Coding!
+
+ Marc Peter
diff -r e49147870aac -r 14717b52abc0 SDL.spec.in
--- a/SDL.spec.in Mon May 01 06:58:33 2006 +0000
+++ b/SDL.spec.in Wed May 17 08:18:28 2006 +0000
@@ -9,9 +9,12 @@
BuildRoot: %{_tmppath}/%{name}-%{version}-buildroot
Prefix: %{_prefix}
%ifos linux
-Provides: libSDL-1.1.so.0
+Provides: libSDL-1.2.so.0
%endif
+%define __defattr %defattr(-,root,root)
+%define __soext so
+
%description
This is the Simple DirectMedia Layer, a generic API that provides low
level access to audio, keyboard, mouse, and display framebuffer across
@@ -59,25 +62,13 @@
%clean
rm -rf $RPM_BUILD_ROOT
-%ifnos darwin
-%define __defattr %defattr(-,root,root)
-%define __soext so
-%else
-%define __defattr %defattr(-,root,wheel)
-%define __soext dylib
-%endif
-
%files
%{__defattr}
%doc README-SDL.txt COPYING CREDITS BUGS
-%ifnos darwin
%{_libdir}/lib*.%{__soext}.*
-%else
-%{_libdir}/lib*.*.%{__soext}
-%endif
%files devel
-%defattr(-,root,root)
+%{__defattr}
%doc README README-SDL.txt COPYING CREDITS BUGS WhatsNew docs.html
%doc docs/index.html docs/html
%{_bindir}/*-config
@@ -90,6 +81,9 @@
%{_mandir}/man3/*
%changelog
+* Tue May 16 2006 Sam Lantinga
+- Removed support for Darwin, due to build problems on ps2linux
+
* Mon Jan 03 2004 Anders Bjorklund
- Added support for Darwin, updated spec file
diff -r e49147870aac -r 14717b52abc0 TODO
--- a/TODO Mon May 01 06:58:33 2006 +0000
+++ b/TODO Wed May 17 08:18:28 2006 +0000
@@ -2,6 +2,7 @@
Wish list for the 1.3 development branch:
http://bugzilla.libsdl.org/
+ * Add internal support for adding video modes and refresh rates
* Support querying and setting refresh rate with video modes
* Add mousewheel events (new unified event architecture?)
* DirectInput joystick support needs to be implemented
diff -r e49147870aac -r 14717b52abc0 VisualCE.zip
Binary file VisualCE.zip has changed
diff -r e49147870aac -r 14717b52abc0 Watcom-OS2.zip
Binary file Watcom-OS2.zip has changed
diff -r e49147870aac -r 14717b52abc0 Watcom-Win32.zip
Binary file Watcom-Win32.zip has changed
diff -r e49147870aac -r 14717b52abc0 WhatsNew
--- a/WhatsNew Mon May 01 06:58:33 2006 +0000
+++ b/WhatsNew Wed May 17 08:18:28 2006 +0000
@@ -4,6 +4,19 @@
Version 1.0:
1.2.10:
+ If SDL_OpenAudio() is passed zero for the desired format
+ fields, the following environment variables will be used
+ to fill them in:
+ SDL_AUDIO_FREQUENCY
+ SDL_AUDIO_FORMAT
+ SDL_AUDIO_CHANNELS
+ SDL_AUDIO_SAMPLES
+ If an environment variable is not specified, it will be set
+ to a reasonable default value.
+
+ Added support for the SDL_VIDEO_FULLSCREEN_HEAD environment
+ variable, currently supported on X11 Xinerama configurations.
+
Added SDL_GL_SWAP_CONTROL to wait for vsync in OpenGL applications.
Added SDL_GL_ACCELERATED_VISUAL to guarantee hardware acceleration.
diff -r e49147870aac -r 14717b52abc0 autogen.sh
--- a/autogen.sh Mon May 01 06:58:33 2006 +0000
+++ b/autogen.sh Wed May 17 08:18:28 2006 +0000
@@ -6,7 +6,7 @@
# Regenerate configuration files
cp acinclude.m4 aclocal.m4
found=false
-for autoconf in autoconf autoconf259
+for autoconf in autoconf autoconf259 autoconf-2.59
do if which $autoconf >/dev/null 2>&1; then $autoconf && found=true; break; fi
done
if test x$found = xfalse; then
diff -r e49147870aac -r 14717b52abc0 build-scripts/fatbuild.sh
--- a/build-scripts/fatbuild.sh Mon May 01 06:58:33 2006 +0000
+++ b/build-scripts/fatbuild.sh Wed May 17 08:18:28 2006 +0000
@@ -10,7 +10,12 @@
# Generic, cross-platform CFLAGS you always want go here.
CFLAGS="-O3 -g -pipe"
-# PowerPC compiler flags (10.2 runtime compatibility)
+# PowerPC configure flags (10.2 runtime compatibility)
+# We dynamically load X11, so using the system X11 headers is fine.
+CONFIG_PPC="--build=`uname -p`-apple-darwin --host=powerpc-apple-darwin \
+--x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib"
+
+# PowerPC compiler flags
CC_PPC="gcc-3.3 -arch ppc"
CXX_PPC="g++-3.3 -arch ppc"
CFLAGS_PPC=""
@@ -26,7 +31,12 @@
-F/Developer/SDKs/MacOSX10.2.8.sdk/System/Library/Frameworks \
-Wl,-syslibroot,/Developer/SDKs/MacOSX10.2.8.sdk"
-# Intel compiler flags (10.4 runtime compatibility)
+# Intel configure flags (10.4 runtime compatibility)
+# We dynamically load X11, so using the system X11 headers is fine.
+CONFIG_X86="--build=`uname -p`-apple-darwin --host=i386-apple-darwin \
+--x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib"
+
+# Intel compiler flags
CC_X86="gcc-4.0 -arch i386"
CXX_X86="g++-4.0 -arch i386"
CFLAGS_X86="-mmacosx-version-min=10.4"
@@ -158,7 +168,7 @@
#
if test x$configure_ppc = xyes; then
(cd build/ppc && \
- sh ../../configure --build=`uname -p`-apple-darwin --host=powerpc-apple-darwin CC="$CC_PPC" CXX="$CXX_PPC" CFLAGS="$CFLAGS $CFLAGS_PPC" CPPFLAGS="$CPPFLAGS_PPC" LDFLAGS="$LFLAGS_PPC") || exit 2
+ sh ../../configure $CONFIG_PPC CC="$CC_PPC" CXX="$CXX_PPC" CFLAGS="$CFLAGS $CFLAGS_PPC" CPPFLAGS="$CPPFLAGS_PPC" LDFLAGS="$LFLAGS_PPC") || exit 2
fi
if test x$make_ppc = xyes; then
(cd build/ppc && ls include && make -j$NJOB) || exit 3
@@ -169,7 +179,7 @@
#
if test x$configure_x86 = xyes; then
(cd build/x86 && \
- sh ../../configure --build=`uname -p`-apple-darwin --host=i386-apple-darwin CC="$CC_X86" CXX="$CXX_X86" CFLAGS="$CFLAGS $CFLAGS_X86" CPPFLAGS="$CPPFLAGS_X86" LDFLAGS="$LFLAGS_X86") || exit 2
+ sh ../../configure $CONFIG_X86 CC="$CC_X86" CXX="$CXX_X86" CFLAGS="$CFLAGS $CFLAGS_X86" CPPFLAGS="$CPPFLAGS_X86" LDFLAGS="$LFLAGS_X86") || exit 2
fi
if test x$make_x86 = xyes; then
(cd build/x86 && make -j$NJOB) || exit 3
diff -r e49147870aac -r 14717b52abc0 build-scripts/ltmain.sh
--- a/build-scripts/ltmain.sh Mon May 01 06:58:33 2006 +0000
+++ b/build-scripts/ltmain.sh Wed May 17 08:18:28 2006 +0000
@@ -5008,7 +5008,7 @@
EOF
case $host_os in
- mingw*)
+ *cygwin* | *mingw* )
cat >> $cwrappersource </dev/null | sort -r | sed 's/.*\/\(.*\)/\1/; q'`]
+ if test "x$x11_lib" = "x"; then
+ x11_lib=[`ls -- $path/libX11.so.[0-9]* 2>/dev/null | sort -r | sed 's/.*\/\(.*\)/\1/; q'`]
+ fi
fi
if test "x$x11ext_lib" = "x"; then
x11ext_lib=[`ls -- $path/libXext.so.[0-9] 2>/dev/null | sort -r | sed 's/.*\/\(.*\)/\1/; q'`]
+ if test "x$x11ext_lib" = "x"; then
+ x11ext_lib=[`ls -- $path/libXext.so.[0-9]* 2>/dev/null | sort -r | sed 's/.*\/\(.*\)/\1/; q'`]
+ fi
fi
if test "x$xrender_lib" = "x"; then
xrender_lib=[`ls -- $path/libXrender.so.[0-9] 2>/dev/null | sort -r | sed 's/.*\/\(.*\)/\1/; q'`]
+ if test "x$xrender_lib" = "x"; then
+ xrender_lib=[`ls -- $path/libXrender.so.[0-9]* 2>/dev/null | sort -r | sed 's/.*\/\(.*\)/\1/; q'`]
+ fi
fi
if test "x$xrandr_lib" = "x"; then
xrandr_lib=[`ls -- $path/libXrandr.so.[0-9] 2>/dev/null | sort -r | sed 's/.*\/\(.*\)/\1/; q'`]
+ if test "x$xrandr_lib" = "x"; then
+ xrandr_lib=[`ls -- $path/libXrandr.so.[0-9]* 2>/dev/null | sort -r | sed 's/.*\/\(.*\)/\1/; q'`]
+ fi
fi
done
;;
@@ -831,6 +855,8 @@
if test x$ac_cv_func_shmat != xyes; then
X_CFLAGS="$X_CFLAGS -DNO_SHARED_MEMORY"
fi
+ CFLAGS="$CFLAGS $X_CFLAGS"
+ LDFLAGS="$LDFLAGS $X_LIBS"
AC_DEFINE(SDL_VIDEO_DRIVER_X11)
SOURCES="$SOURCES $srcdir/src/video/x11/*.c"
@@ -925,10 +951,22 @@
fi
fi
fi
-
if test x$definitely_enable_video_x11_xrandr = xyes; then
AC_DEFINE(SDL_VIDEO_DRIVER_X11_XRANDR)
fi
+ AC_ARG_ENABLE(video-x11-dpms,
+AC_HELP_STRING([--enable-video-x11-dpms], [enable X11 DPMS extension [[default=yes]]]),
+ , enable_video_x11_dpms=yes)
+ if test x$enable_video_x11_dpms = xyes; then
+ AC_CHECK_HEADER(X11/extensions/dpms.h,
+ have_dpms_h_hdr=yes,
+ have_dpms_h_hdr=no,
+ [#include
+ ])
+ if test x$have_dpms_h_hdr = xyes; then
+ AC_DEFINE(SDL_VIDEO_DRIVER_X11_DPMS)
+ fi
+ fi
fi
fi
}
@@ -1197,6 +1235,8 @@
#include
],[
VGLBitmap bitmap;
+ bitmap.Type = VIDBUF32;
+ bitmap.PixelBytes = 4;
exit(bitmap.Bitmap);
],[
video_vgl=yes
@@ -1359,7 +1399,7 @@
video_gem=yes
AC_DEFINE(SDL_VIDEO_DRIVER_GEM)
SOURCES="$SOURCES $srcdir/src/video/gem/*.c"
- EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lgem"
+ SDL_LIBS="$SDL_LIBS -lgem"
have_video=yes
fi
fi
@@ -1494,8 +1534,8 @@
fi
AC_DEFINE(SDL_VIDEO_OPENGL)
AC_DEFINE(SDL_VIDEO_OPENGL_OSMESA)
- EXTRA_CFLAGS="$EXTRA_CFLAGS $OSMESA_CFLAGS"
- EXTRA_LDFLAGS="$EXTRA_LDFLAGS $OSMESA_LIBS"
+ SDL_CFLAGS="$SDL_CFLAGS $OSMESA_CFLAGS"
+ SDL_LIBS="$SDL_LIBS $OSMESA_LIBS"
AC_ARG_ENABLE(osmesa-shared,
AC_HELP_STRING([--enable-osmesa-shared], [dynamically load OSMesa OpenGL support [[default=yes]]]),
@@ -1597,7 +1637,7 @@
AC_HELP_STRING([--enable-pthread-sem], [use pthread semaphores [[default=yes]]]),
, enable_pthread_sem=yes)
case "$host" in
- *-*-linux*)
+ *-*-linux*|*-*-uclinux*)
pthread_cflags="-D_REENTRANT"
pthread_lib="-lpthread"
;;
@@ -1865,7 +1905,7 @@
if test x$have_ldg_hdr = xyes -a x$have_ldg_lib = xyes; then
AC_DEFINE(SDL_LOADSO_LDG)
SOURCES="$SOURCES $srcdir/src/loadso/mint/*.c"
- EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lldg -lgem"
+ SDL_LIBS="$SDL_LIBS -lldg -lgem"
have_loadso=yes
fi
fi
@@ -2048,9 +2088,10 @@
have_timers=yes
fi
;;
- *-*-linux*|*-*-gnu*|*-*-k*bsd*-gnu|*-*-bsdi*|*-*-freebsd*|*-*-dragonfly*|*-*-netbsd*|*-*-openbsd*|*-*-sysv5*|*-*-solaris*|*-*-hpux*|*-*-irix*|*-*-aix*|*-*-osf*)
+ *-*-linux*|*-*-uclinux*|*-*-gnu*|*-*-k*bsd*-gnu|*-*-bsdi*|*-*-freebsd*|*-*-dragonfly*|*-*-netbsd*|*-*-openbsd*|*-*-sysv5*|*-*-solaris*|*-*-hpux*|*-*-irix*|*-*-aix*|*-*-osf*)
case "$host" in
*-*-linux*) ARCH=linux ;;
+ *-*-uclinux*) ARCH=linux ;;
*-*-kfreebsd*-gnu) ARCH=kfreebsd-gnu ;;
*-*-knetbsd*-gnu) ARCH=knetbsd-gnu ;;
*-*-kopenbsd*-gnu) ARCH=kopenbsd-gnu ;;
@@ -2570,9 +2611,6 @@
if test x$enable_video = xyes -a x$enable_video_carbon = xyes; then
SDL_LIBS="$SDL_LIBS -Wl,-framework,Carbon"
fi
- if test x$enable_video = xyes -a x$enable_video_opengl = xyes; then
- SDL_LIBS="$SDL_LIBS -Wl,-framework,OpenGL"
- fi
# Evil hack to allow static linking on Mac OS X
SDL_STATIC_LIBS="\${exec_prefix}/lib/libSDLmain.a \${exec_prefix}/lib/libSDL.a $EXTRA_LDFLAGS"
;;
diff -r e49147870aac -r 14717b52abc0 docs.html
--- a/docs.html Mon May 01 06:58:33 2006 +0000
+++ b/docs.html Wed May 17 08:18:28 2006 +0000
@@ -11,779 +11,165 @@
The latest stable release may be found on the
SDL website.
-
+
+ SDL 1.2.10 Release Notes
-
-
-Major changes since SDL 1.0.0:
-
+SDL 1.2.10 is a major release, featuring a revamp of the build system and many API improvements and bug fixes.
+
+ API enhancements
-
-Major changes since SDL 0.10.0:
-
-
- - 0.11.5: Fixed mouse warping in fullscreen mode
-
- 0.11.5: Added a new function SDL_GetVideoSurface()
-
- 0.11.5: Renamed SDL_AllocSurface() SDL_CreateRGBSurface()
-
- 0.11.5: Added a new function SDL_CreateRGBSurfaceFrom()
-
- 0.11.4: Added support for multiple compiled-in video drivers
-
- 0.11.3: Fixed 16 --> 32 bpp blitting - using C instead of Hermes.
-
- 0.11.3: Fixed double-buffering bug in the DirectX driver
-
- 0.11.3: Added GGI video driver (thanks Jon Taylor)
-
- 0.11.2: Added automake/aclocal/autoconf support
-
- 0.11.1: Added an initial (buggy) MacOS CD-ROM driver
-
- 0.11.1: Improved Linux CD-ROM detection
-
- 0.11.1: Added a workaround for DGA mouse bug on Voodoo 3
-
- 0.11.1: Fixed 24bpp --> 8bpp blit crash
-
- 0.11.1: Fixed a bug in blit mapping when palette changed
-
- 0.11.1: Added a Linux SBLive beta driver workaround
-
- 0.11.1: Fixed Win32 cross-compile problem with mingw32
-
- 0.11.1: Loss of keyboard focus now causes keys to be reset
-
- 0.11.1: DGA DirectMouse is conditionally compiled (default off)
-
+ General Notes
+
+
+
+ The SDL website now has an RSS feed!
+
+ The SDL development source code is now managed with Subversion.
+
+ SDL now uses the Bugzilla bug tracking system, hosted by icculus.org.
+
+ SDL is licensed under version 2.1 of the GNU Lesser General Public License.
+
+ The entire build system has been revamped to make it much more portable, including versions of C library functions to make it possible to run SDL on a minimal embedded environment. See README.Porting in the SDL source distribution for information on how to port SDL to a new platform.
+
+ SDL_opengl.h has been updated with the latest glext.h from http://oss.sgi.com/projects/ogl-sample/registry/
+
+ Alex Volkov contributed highly optimized RGB <-> RGBA blitters.
+
+
+ Unix Notes
-
-Major changes since SDL 0.8.0:
-
-
- - 0.9.16: Made SDL error messages thread-safe
-
- 0.9.15: If you have r/w access to /dev/mem, DGA works on Linux
-
- 0.9.15: Added support for Linux on the ARM (Netwinder)
-
- 0.9.14: Removed color cursor support, fixed b/w cursors
-
- 0.9.14: Fixed long-standing X11 DGA colormap problem
-
- 0.9.13: Added dynamic load function: SDL_SetLibraryPath()
-
- 0.9.13: Added unofficial support for MacOS
-
- 0.9.13: Added unofficial support for FreeBSD
-
- 0.9.13: Added unofficial support for IRIX
-
- 0.9.13: Updated support for BeOS from R3 to R4.5
-
- 0.9.13: Added SDL_SetLibraryPath() function (thanks Karsten Laux)
-
- 0.9.13: Fixed 8-bit audio conversion when using SDL_MixAudio()
-
- 0.9.13: Fixed audio thread lingering when app dies on Linux
-
- 0.9.13: Fixed color problem in X display to other-endian systems
-
- 0.9.13: Finally able to detect X11 key repeat (thanks GII team!)
-
- 0.9.13: Added support for Visual C++ 5.0 development environment
-
- 0.9.13: Added support for Linux on the Alpha
-
- 0.9.13: Added support for international keyboards (see WhatsNew)
-
- 0.9.12: Added support for loading IMA ADPCM compressed WAV files
-
- 0.9.12: Fixed bug when mixing 8-bit audio in SDL_MixAudio()
-
- 0.9.12: Added Enlightenment Sound Daemon audio support on Linux
-
- 0.9.12: Added MTRR support for Linux/X11 (thanks David Barth)
-
- 0.9.12: Added support for LinuxPPC 5.0
-
- 0.9.12: Fixed place where some audio conversions aren't detected
-
- 0.9.12: Fixed serious bug in installation script
-
- 0.9.12: Added SDL_FreeWAV() function for freeing DLL memory
-
- 0.9.12: Fixed potential memory leak in SDL_LoadWAV_RW()
-
- 0.9.11: Freeing video surface has no longer crashes SDL_Quit()
-
- 0.9.11: Included new asm blitters from Hermes library 1.2.4
-
- 0.9.11: SDL_WaitThread() now gets the thread's return status
-
- 0.9.11: SDL_MixAudio() takes a larger volume range (0-128)
-
- 0.9.11: SDL no longer changes the X11 keyboard repeat
-
- 0.9.11: Added a data source abstraction for loading/saving data
-
- 0.9.11: Added three built in data abstractions:
- SDL_RWFromFile(), SDL_RWFromFP(), SDL_RWFromMem()
- - 0.9.11: Added stdio-like functions for using data sources:
- SDL_RWseek(), SDL_RWread(), SDL_RWwrite(), SDL_RWclose()
- - 0.9.11: Replaced SDL_CalculateEndian() with SDL_BYTEORDER macro
-
- 0.9.11: Endian swapping functions are now macros, for speed.
-
- 0.9.11: Endian read/write functions now use data sources
-
- 0.9.11: Added function SDL_LoadWAV_RW() for data sources
-
- 0.9.11: Added function SDL_LoadBMP_RW() for data sources
-
- 0.9.11: Added function SDL_SaveBMP_RW() for data sources
-
- 0.9.10: Mixer no longer fails if timidity isn't installed
-
- 0.9.10: Mixer restarts MOD files on play (thanks Bill Kendrick)
-
- 0.9.10: Fixed occasional crashing of the mixer library
-
- 0.9.10: Fixed icon display on Afterstep under Linux
-
- 0.9.10: Fixed occasional crash in mixer example
-
- 0.9.10: Linux cdrom list now comes from /etc/fstab
-
- 0.9.10: Fixed support for UK keyboard (thanks John Elliott)
-
- 0.9.10: The event queue is now thread-safe
-
- 0.9.10: Added event queue pump function: SDL_PumpEvents()
-
- 0.9.10: Added low level event function: SDL_PeepEvents()
-
- 0.9.10: Added a new thread function: SDL_ThreadID()
-
- 0.9.10: Fixed an audio rate conversion memory overrun
-
- 0.9.10: Fixed crash with RLE acceleration on big surfaces
-
- 0.9.10: Improved MacOS display driver - added fullscreen
-
- 0.9.10: Removed spurious warnings from Linux X11 driver
-
- 0.9.10: Fixed memory leak in SDL_InvalidateMap()
-
- 0.9.10: Fixed right button of 2-button mice on Win32
-
- 0.9.10: Enabled XFree86 mode changes on older servers
-
- 0.9.9: SDL_LoadBMP() handles BMP files created with GIMP
-
- 0.9.9: SDL_LoadWAV() handles WAV files with "LIST" chunks
-
- 0.9.9: Fixed problem with audio underflow on Solaris
-
- 0.9.9: Initial support for 4-speaker audio output devices
-
- 0.9.8: Fixed corrupt VC++ 5.0 desktop file
-
- 0.9.8: Now detects fixed version of Metro-X X11 server
-
- 0.9.8: Fixed XFree86 DGA banked mode update
-
- 0.9.8: Fixed mouse press viewport shift on XFree86 DGA
-
- 0.9.7: Fixed problem with displaying remotely via X11
-
- 0.9.7: Win32 uses software cursor when fullscreen
-
- 0.9.7: Win32 mouse uses DirectInput when fullscreen
-
- 0.9.7: Added OpenGL software rendering via Mesa (demos archive)
-
- 0.9.7: Fixed memory leak in ADPCM WAV decoding
-
- 0.9.6: Added CD-ROM audio API documentation
-
- 0.9.6: Fixed potential BeOS audio-related crash
-
- 0.9.6: Fixed crash when resetting the video mode in DirectX
-
- 0.9.6: Fixed errors compiling with the SparcWorks compiler
-
- 0.9.6: Replaced SDL_GetDisplayFormat() with SDL_GetVideoInfo()
-
- 0.9.6: Added a new fast fill function: SDL_FillRect()
-
- 0.9.6: Added blit acceleration flags to SDL_AllocSurface()
-
- 0.9.6: Added new double-buffering function: SDL_Flip()
-
- 0.9.6: Fixed problem with buggy Metro-X X11 server
-
- 0.9.6: Fixed 8-bit audio on Solaris with dbri hardware
-
- 0.9.6: Fixed alarm clock problem with Solaris pthreads
-
- 0.9.6: Fixed BeOS compilation problem
-
- 0.9.5: Added tools to create Win32 icons in directx/icon/
-
- 0.9.5: You can now pass a NULL mask to SDL_WM_SetIcon()
-
- 0.9.5: Added support files for compiling with VC++ 5.0
-
- 0.9.5: Fixed icon color bug under Win32
-
- 0.9.5: Re-added SDL_LowerBlit() - not safe for use on display
-
- 0.9.5: Fixed 0.9.x cursor blit deadlock
-
- 0.9.5: Added SDL_FPLoadWAV(), SDL_FPLoadBMP(), SDL_FPSaveBMP()
-
- 0.9.5: Added Linux, Win32, and BeOS CD audio support
-
- 0.9.5: MMX accelerated blit disabled -- temporarily broken
-
- 0.9.4: Fixed endianness issue with BeOS x86 blitting
-
- 0.9.4: Fixed quit interrupt delivery on BeOS
-
- 0.9.4: Fixed dynamic loading on BeOS
-
- 0.9.4: Fixed DirectX audio on Win98
-
- 0.9.4: Fixed possible sound-related crash on Linux PPC
-
- 0.9.3: Mouse motion arrives as absolute and relative coordinates
-
- 0.9.3: Fixed Visual C++ structure packing
-
- 0.9.3: Fixed UNIX dynamic link library installation
-
- 0.9.2: DirectX audio no longer hangs when app loses focus
-
- 0.9.2: Fixed DirectX HiColor crash (palette bug)
-
- 0.9.1: Fixed DirectX <ALT> key handling
-
- 0.9.1: Fixed DirectX windowed palette problems
-
- 0.9.1: Removed SDL_MapSurface() and SDL_UnmapSurface()
-
- 0.9.0: Initial port to IRIX 6.x
-
- 0.9.0: Initial port to OSF/1 3.2 (no sound yet)
-
- 0.9.0: MacOS port in progress
-
+
+
+ The X11 libraries are dynamically loaded at runtime by default. This allows the distributed version of SDL to run on systems without X11 libraries installed.
+
+ The XiG XME extension code is now included in the X11 video driver by default.
+
+ XRandR support for video mode switching has been added to the X11 driver, but is disabled because of undesired interactions with window managers. You can enable this by setting the environment variable SDL_VIDEO_X11_XRANDR to 1.
+
+ Xinerama multi-head displays are properly handled now, and the SDL_VIDEO_FULLSCREEN_HEAD environment variable can be used to select the screen used for fullscreen video modes. Note that changing the video modes only works on screen 0.
+
+ XVidMode video modes are now sorted so they maintain the refresh rates specified in the X11 configuration file.
+
+ SDL windows are no longer transparent in X11 compositing systems like XGL.
+
+ The mouse is properly released by the X11 video driver if the fullscreen window loses focus.
+
+ The X11 input driver now uses XIM to handle international input.
+
+ The screensaver and DPMS monitor blanking are disabled while SDL games are running under the X11 and DGA video drivers. This behavior will be formalized and selectable in SDL 1.3.
+
+ Fixed a bug preventing stereo OpenGL contexts from being selected on the X11 driver.
+
+ The DGA video driver now waits for pending blits involving surfaces before they are freed. This prevents display oddities when using SDL_DisplayFormat() to convert many images.
+
+ The framebuffer console video driver now has a parser for /etc/fb.modes for improved video mode handling.
+
+ The framebuffer console video driver now allows asynchronous VT switching, and restores the full contents of the screen when switched back.
+
+ The framebuffer console now uses CTRL-ALT-FN to switch virtual terminals, to avoid collisions with application key bindings.
+
+ The framebuffer console input driver correctly sets IMPS/2 mode for wheel mice. It also properly detects when gpm is in IMPS/2 protocol mode, or passing raw protocol from an IMPS/2 mouse.
+
+ The SVGAlib video driver now has support for banked (non-linear) video modes.
+
+ A video driver for OpenBSD on the Sharp Zaurus has been contributed by Staffan Ulfberg. See the file README.wscons in the SDL source distribution for details.
+
+ Many patches have been incorporated from *BSD ports.
+
+
+ Windows Notes
-
-Major changes since SDL 0.7:
-
-
- - Separated the demos and examples into a separate archive
-
- Added support for loading Microsoft compressed WAV files
-
- Added "soft" application crash recovery (signal handlers)
-
- Fixed POSIX signal handling interaction with threads
-
- Fixed audio output on MKLinux
-
- Added dynamic library version checking
-
- Updated for DirectX 6.0
-
- Cleaned up dynamic linking and added static linking
-
- Added automatic audio format and rate conversion
-
- Optimized some blitter cases (8 --> 16/32 and 32 --> 16/8)
-
- Removed precalculated alpha blending acceleration
-
- Key and mouse button events are split into up/down events
-
- It is now much easier to set an optimal video mode
-
+
+
+ The "windib" video driver is the default now, to prevent problems with certain laptops, 64-bit Windows, and Windows Vista. The DirectX driver is still available, and can be selected by setting the environment variable SDL_VIDEODRIVER to "directx".
+
+ SDL has been ported to 64-bit Windows.
+
+ Dmitry Yakimov contributed a GAPI video driver for Windows CE.
+
+ The default fullscreen refresh rate has been increased to match the desktop refresh rate, when using equivalent resolutions. A full API for querying and selecting refresh rates is planned for SDL 1.3.
+
+ Dialog boxes are now shown when SDL is in windowed OpenGL mode.
+
+ The SDL window is recreated when necessary to maintain OpenGL context attributes, when switching between windowed and fullscreen modes.
+
+ An SDL_VIDEORESIZE event is properly sent when the SDL window is maximized and restored.
+
+ Window positions are retained when switching between fullscreen and windowed modes.
+
+ ToUnicode() is used, when available, for improved handling of international keyboard input.
+
+ The PrtScrn is now treated normally with both key down and key up events.
+
+ Pressing ALT-F4 now delivers an SDL_QUIT event to SDL applications.
+
+ Joystick names are now correct for joysticks which have been unplugged and then plugged back in since booting.
+
+ An MCI error when playing the last track on a CD-ROM has been fixed.
+
+ OpenWatcom projects for building SDL have been provided by Marc Peter.
+
-
-Major changes since SDL 0.5:
-
-
- - Ported to Solaris 2.6
-
- Added XFree86 Direct Graphic Access support
-
- Supports LinuxPPC without threads
-
- Completely rewritten video/surface API -- see SDL_video.h
-
- Completely rewritten event API
-
- Optimized black-white cursor creation
-
- Added support for run-length-encoded colorkeying
-
- Added support for hardware accelerated blits
-
- Added support for blitting from 1-bit surfaces (bitmaps)
-
- Added a function to simplify setting video modes
-
- Added support for loading WAV files
-
- Added endian swapping functions for memory values
-
- Added alpha blending using alpha value or channel
-
- Added precalculated alpha blending acceleration
-
- Added function to return current time in milliseconds
-
- New event type SDL_ACTIVEEVENT, to detect iconification
-
- New event type SDL_SYSWMEVENT, for custom window hooks
-
- Added a platform dependent function to get window handle
-
- Added a function to check the run-time version of SDL
-
- Added periodic timer support at 10 ms resolution
-
- Added support for the SDL_DEBUG environment variable
-
- Miscellaneous internal cleanups
-
+ Mac OS X Notes
-
-Major changes since SDL 0.4:
-
-
- - SDL library code is now dynamically loaded
-
- Added support for pthreads (Linux glibc2)
-
- Removed SDL_mutexN() and SDL_mutexIncr()
-
+
+
+ SDL now supports building Universal binaries, both through Xcode projects and when using configure/make. See README.MacOSX in the SDL source archive for details.
+
+ The X11 video driver with GLX support can be built on Mac OS X, if the X11 development SDK is installed.
+
+ Transitions between fullscreen resolutions and windowed mode now use a much faster asynchronous fade to hide desktop flicker.
+
+ Icons set with SDL_WM_SetIcon() now have the proper colors on Intel Macs.
+
-
-Major changes since SDL 0.3:
-
-
- - Added support for DirectX 5.0
-
- Added support for surfaces in video memory
-
- Added support for source color-key blitting
-
- Added support for single-rectangle clipping
-
- Added support for warping (moving) the cursor
-
- Added support for color cursors
-
- Greatly simplified internal event queue
-
- Minor bug-fixes
-
+ OS/2 Notes
+
+ Projects for building SDL on OS/2 with OpenWatcom have been contributed by Doodle. See the file README.OS2 in the SDL source distribution for details.
+
+
-
This library is designed to make it easy to write games that run on Linux,
-Win32 and BeOS using the various native high-performance media interfaces,
+
+
Simple DirectMedia Layer Introduction
+
+
+
+
+
+This library is designed to make it easy to write games that run on many
+different platforms using the various native high-performance media interfaces,
(for video, audio, etc) and presenting a single source-code level API to
your application. This is a fairly low level API, but using this, completely
-portable applications can be written with a great deal of flexibility.
The library is loaded as a dynamically linked library on its native
-platform, and is currently compiled natively for Linux, compiled for
-Win32 using a Linux hosted GCC
-cross-compilation
-environment, and compiled using the EGCS C++ compiler under BeOS.
An introduction to SDL can be found online at:
-http://www.libsdl.org/intro/
There are code examples on each of the main library pages, and there are
-fully fleshed example C++ classes and programs in the examples archive,
-available on the
-SDL download page.
For an introduction to basic multi-media programming concepts, you might try
-some of the following links:
-
Enjoy!
Sam Lantinga
-<slouken@libsdl.org>
-
+portable applications can be written with a great deal of flexibility.
+
+An introduction to SDL can be found online at:
+
+ http://www.libsdl.org/intro.php
+
+Tutorials on a variety of topics can be found online at:
+
+ http://www.libsdl.org/tutorials.php
+
+Documentation in Wiki form can be found online at:
+
+ http://www.libsdl.org/cgi/docwiki.cgi/
+
+Enjoy!
+
+ Sam Lantinga
+<slouken@libsdl.org>
+
Table of Contents
diff -r e49147870aac -r 14717b52abc0 include/SDL_config.h.in
--- a/include/SDL_config.h.in Mon May 01 06:58:33 2006 +0000
+++ b/include/SDL_config.h.in Wed May 17 08:18:28 2006 +0000
@@ -279,6 +279,7 @@
#undef SDL_VIDEO_DRIVER_WSCONS
#undef SDL_VIDEO_DRIVER_X11
#undef SDL_VIDEO_DRIVER_X11_DGAMOUSE
+#undef SDL_VIDEO_DRIVER_X11_DPMS
#undef SDL_VIDEO_DRIVER_X11_DYNAMIC
#undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT
#undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR
diff -r e49147870aac -r 14717b52abc0 include/SDL_config_macos.h
--- a/include/SDL_config_macos.h Mon May 01 06:58:33 2006 +0000
+++ b/include/SDL_config_macos.h Wed May 17 08:18:28 2006 +0000
@@ -27,14 +27,20 @@
/* This is a set of defines to configure the SDL features */
-typedef signed char int8_t;
-typedef unsigned char uint8_t;
-typedef signed short int16_t;
-typedef unsigned short uint16_t;
-typedef signed long int32_t;
-typedef unsigned long uint32_t;
+#include
+
+typedef SInt8 int8_t;
+typedef UInt8 uint8_t;
+typedef SInt16 int16_t;
+typedef UInt16 uint16_t;
+typedef SInt32 int32_t;
+typedef UInt32 uint32_t;
+typedef SInt64 int64_t;
+typedef UInt64 uint64_t;
typedef unsigned long uintptr_t;
+#define SDL_HAS_64BIT_TYPE 1
+
/* Useful headers */
#define HAVE_STDIO_H 1
#define STDC_HEADERS 1
@@ -73,10 +79,18 @@
#define SDL_AUDIO_DRIVER_DUMMY 1
/* Enable various cdrom drivers */
-#define SDL_CDROM_MACOS 1
+#if TARGET_API_MAC_CARBON
+#define SDL_CDROM_DUMMY 1
+#else
+#define SDL_CDROM_MACOS 1
+#endif
/* Enable various input drivers */
+#if TARGET_API_MAC_CARBON
+#define SDL_JOYSTICK_DUMMY 1
+#else
#define SDL_JOYSTICK_MACOS 1
+#endif
/* Enable various shared object loading systems */
#define SDL_LOADSO_MACOS 1
diff -r e49147870aac -r 14717b52abc0 include/SDL_config_macosx.h
--- a/include/SDL_config_macosx.h Mon May 01 06:58:33 2006 +0000
+++ b/include/SDL_config_macosx.h Wed May 17 08:18:28 2006 +0000
@@ -30,7 +30,10 @@
#define SDL_HAS_64BIT_TYPE 1
/* Useful headers */
+/* If we specified an SDK or have a post-PowerPC chip, then alloca.h exists. */
+#if ( (MAC_OS_X_VERSION_MIN_REQUIRED >= 1030) || (!defined(__POWERPC__)) )
#define HAVE_ALLOCA_H 1
+#endif
#define HAVE_SYS_TYPES_H 1
#define HAVE_STDIO_H 1
#define STDC_HEADERS 1
@@ -46,12 +49,7 @@
#define HAVE_CALLOC 1
#define HAVE_REALLOC 1
#define HAVE_FREE 1
-
-/* If we specified an SDK or have a post-PowerPC chip, then alloca.h exists. */
-#if ( (MAC_OS_X_VERSION_MIN_REQUIRED >= 1030) || (!defined(__POWERPC__)) )
#define HAVE_ALLOCA 1
-#endif
-
#define HAVE_GETENV 1
#define HAVE_PUTENV 1
#define HAVE_UNSETENV 1
@@ -116,8 +114,11 @@
/* Enable various video drivers */
#define SDL_VIDEO_DRIVER_DUMMY 1
-#define SDL_VIDEO_DRIVER_GLSDL 1
+#if TARGET_API_MAC_CARBON
+#define SDL_VIDEO_DRIVER_TOOLBOX 1
+#else
#define SDL_VIDEO_DRIVER_QUARTZ 1
+#endif
/* Enable OpenGL support */
#define SDL_VIDEO_OPENGL 1
diff -r e49147870aac -r 14717b52abc0 include/SDL_platform.h
--- a/include/SDL_platform.h Mon May 01 06:58:33 2006 +0000
+++ b/include/SDL_platform.h Wed May 17 08:18:28 2006 +0000
@@ -61,13 +61,12 @@
#undef __LINUX__
#define __LINUX__ 1
#endif
-#if defined(macintosh)
-#undef __MACOS__
-#define __MACOS__ 1
-#endif
#if defined(__APPLE__)
#undef __MACOSX__
#define __MACOSX__ 1
+#elif defined(macintosh)
+#undef __MACOS__
+#define __MACOS__ 1
#endif
#if defined(__NetBSD__)
#undef __NETBSD__
diff -r e49147870aac -r 14717b52abc0 include/SDL_stdinc.h
--- a/include/SDL_stdinc.h Mon May 01 06:58:33 2006 +0000
+++ b/include/SDL_stdinc.h Wed May 17 08:18:28 2006 +0000
@@ -168,8 +168,12 @@
# elif defined(_MSC_VER)
# include
# define alloca _alloca
+# elif defined(__WATCOMC__)
+# include
# elif defined(__AIX__)
#pragma alloca
+# elif defined(__MRC__)
+ void *alloca (unsigned);
# else
char *alloca ();
# endif
diff -r e49147870aac -r 14717b52abc0 include/SDL_syswm.h
--- a/include/SDL_syswm.h Mon May 01 06:58:33 2006 +0000
+++ b/include/SDL_syswm.h Wed May 17 08:18:28 2006 +0000
@@ -115,7 +115,7 @@
GR_WINDOW_ID window ; /* The display window */
} SDL_SysWMinfo;
-#elif defined(SDL_VIDEO_DRIVER_WINDIB) || defined(SDL_VIDEO_DRIVER_DDRAW)
+#elif defined(SDL_VIDEO_DRIVER_WINDIB) || defined(SDL_VIDEO_DRIVER_DDRAW) || defined(SDL_VIDEO_DRIVER_GAPI)
#define WIN32_LEAN_AND_MEAN
#include
diff -r e49147870aac -r 14717b52abc0 sdl.m4
--- a/sdl.m4 Mon May 01 06:58:33 2006 +0000
+++ b/sdl.m4 Wed May 17 08:18:28 2006 +0000
@@ -20,19 +20,21 @@
, enable_sdltest=yes)
if test x$sdl_exec_prefix != x ; then
- sdl_args="$sdl_args --exec-prefix=$sdl_exec_prefix"
- if test x${SDL_CONFIG+set} != xset ; then
- SDL_CONFIG=$sdl_exec_prefix/bin/sdl-config
- fi
+ sdl_args="$sdl_args --exec-prefix=$sdl_exec_prefix"
+ if test x${SDL_CONFIG+set} != xset ; then
+ SDL_CONFIG=$sdl_exec_prefix/bin/sdl-config
+ fi
fi
if test x$sdl_prefix != x ; then
- sdl_args="$sdl_args --prefix=$sdl_prefix"
- if test x${SDL_CONFIG+set} != xset ; then
- SDL_CONFIG=$sdl_prefix/bin/sdl-config
- fi
+ sdl_args="$sdl_args --prefix=$sdl_prefix"
+ if test x${SDL_CONFIG+set} != xset ; then
+ SDL_CONFIG=$sdl_prefix/bin/sdl-config
+ fi
fi
- PATH="$prefix/bin:$prefix/usr/bin:$PATH"
+ if test "x$prefix" != xNONE; then
+ PATH="$prefix/bin:$prefix/usr/bin:$PATH"
+ fi
AC_PATH_PROG(SDL_CONFIG, sdl-config, no, [$PATH])
min_sdl_version=ifelse([$1], ,0.11.0,$1)
AC_MSG_CHECKING(for SDL - version >= $min_sdl_version)
diff -r e49147870aac -r 14717b52abc0 src/SDL_error.c
--- a/src/SDL_error.c Mon May 01 06:58:33 2006 +0000
+++ b/src/SDL_error.c Wed May 17 08:18:28 2006 +0000
@@ -39,15 +39,10 @@
/* Private functions */
-static void SDL_LookupString(const Uint8 *key, Uint16 *buf, int buflen)
+static const char *SDL_LookupString(const char *key)
{
/* FIXME: Add code to lookup key in language string hash-table */
-
- /* Key not found in language string hash-table */
- while ( *key && (--buflen > 0) ) {
- *buf++ = *key++;
- }
- *buf = 0; /* NULL terminate string */
+ return key;
}
/* Public functions */
@@ -66,17 +61,20 @@
error->argc = 0;
while ( *fmt ) {
if ( *fmt++ == '%' ) {
+ while ( *fmt == '.' || (*fmt >= '0' && *fmt <= '9') ) {
+ ++fmt;
+ }
switch (*fmt++) {
case 0: /* Malformed format string.. */
--fmt;
break;
-#if 0 /* What is a character anyway? (UNICODE issues) */
case 'c':
- error->args[error->argc++].value_c =
- va_arg(ap, unsigned char);
- break;
-#endif
+ case 'i':
case 'd':
+ case 'u':
+ case 'o':
+ case 'x':
+ case 'X':
error->args[error->argc++].value_i =
va_arg(ap, int);
break;
@@ -114,124 +112,67 @@
#endif
}
-/* Print out an integer value to a UNICODE buffer */
-static int PrintInt(Uint16 *str, unsigned int maxlen, int value)
-{
- char tmp[128];
- int len, i;
-
- SDL_snprintf(tmp, SDL_arraysize(tmp), "%d", value);
- len = 0;
- if ( SDL_strlen(tmp) < maxlen ) {
- for ( i=0; tmp[i]; ++i ) {
- *str++ = tmp[i];
- ++len;
- }
- }
- return(len);
-}
-/* Print out a double value to a UNICODE buffer */
-static int PrintDouble(Uint16 *str, unsigned int maxlen, double value)
-{
- char tmp[128];
- int len, i;
-
- SDL_snprintf(tmp, SDL_arraysize(tmp), "%f", value);
- len = 0;
- if ( SDL_strlen(tmp) < maxlen ) {
- for ( i=0; tmp[i]; ++i ) {
- *str++ = tmp[i];
- ++len;
- }
- }
- return(len);
-}
-/* Print out a pointer value to a UNICODE buffer */
-static int PrintPointer(Uint16 *str, unsigned int maxlen, void *value)
-{
- char tmp[128];
- int len, i;
-
- SDL_snprintf(tmp, SDL_arraysize(tmp), "%p", value);
- len = 0;
- if ( SDL_strlen(tmp) < maxlen ) {
- for ( i=0; tmp[i]; ++i ) {
- *str++ = tmp[i];
- ++len;
- }
- }
- return(len);
-}
-
/* This function has a bit more overhead than most error functions
so that it supports internationalization and thread-safe errors.
*/
-Uint16 *SDL_GetErrorMsgUNICODE(Uint16 *errstr, unsigned int maxlen)
+char *SDL_GetErrorMsg(char *errstr, unsigned int maxlen)
{
SDL_error *error;
/* Clear the error string */
- *errstr = 0; --maxlen;
+ *errstr = '\0'; --maxlen;
/* Get the thread-safe error, and print it out */
error = SDL_GetErrBuf();
if ( error->error ) {
- Uint16 translated[ERR_MAX_STRLEN], *fmt, *msg;
+ const char *fmt;
+ char *msg = errstr;
int len;
int argi;
- /* Print out the UNICODE error message */
- SDL_LookupString(error->key, translated, sizeof(translated));
- msg = errstr;
+ fmt = SDL_LookupString(error->key);
argi = 0;
- for ( fmt=translated; *fmt && (maxlen > 0); ) {
+ while ( *fmt && (maxlen > 0) ) {
if ( *fmt == '%' ) {
- switch (fmt[1]) {
- case 'S': /* Special SKIP operand */
- argi += (fmt[2] - '0');
- ++fmt;
- break;
+ char tmp[32], *spot = tmp;
+ *spot++ = *fmt++;
+ while ( (*fmt == '.' || (*fmt >= '0' && *fmt <= '9')) && spot < (tmp+SDL_arraysize(tmp)-2) ) {
+ *spot++ = *fmt++;
+ }
+ *spot++ = *fmt++;
+ *spot++ = '\0';
+ switch (spot[-2]) {
case '%':
*msg++ = '%';
maxlen -= 1;
break;
-#if 0 /* What is a character anyway? (UNICODE issues) */
case 'c':
- *msg++ = (unsigned char)
- error->args[argi++].value_c;
- maxlen -= 1;
- break;
-#endif
- case 'd':
- len = PrintInt(msg, maxlen,
- error->args[argi++].value_i);
+ case 'i':
+ case 'd':
+ case 'u':
+ case 'o':
+ case 'x':
+ case 'X':
+ len = SDL_snprintf(msg, maxlen, tmp, error->args[argi++].value_i);
msg += len;
maxlen -= len;
break;
case 'f':
- len = PrintDouble(msg, maxlen,
- error->args[argi++].value_f);
+ len = SDL_snprintf(msg, maxlen, tmp, error->args[argi++].value_f);
msg += len;
maxlen -= len;
break;
case 'p':
- len = PrintPointer(msg, maxlen,
- error->args[argi++].value_ptr);
+ len = SDL_snprintf(msg, maxlen, tmp, error->args[argi++].value_ptr);
msg += len;
maxlen -= len;
break;
- case 's': /* UNICODE string */
- { Uint16 buf[ERR_MAX_STRLEN], *str;
- SDL_LookupString(error->args[argi++].buf, buf, sizeof(buf));
- str = buf;
- while ( *str && (maxlen > 0) ) {
- *msg++ = *str++;
- maxlen -= 1;
- }
- }
+ case 's':
+ len = SDL_snprintf(msg, maxlen, tmp, SDL_LookupString(error->args[argi++].buf));
+ msg += len;
+ maxlen -= len;
break;
}
- fmt += 2;
} else {
*msg++ = *fmt++;
maxlen -= 1;
@@ -242,38 +183,12 @@
return(errstr);
}
-Uint8 *SDL_GetErrorMsg(Uint8 *errstr, unsigned int maxlen)
-{
- Uint16 *errstr16;
- unsigned int i;
-
- /* Allocate the UNICODE buffer */
- errstr16 = (Uint16 *)SDL_malloc(maxlen * (sizeof *errstr16));
- if ( ! errstr16 ) {
- SDL_strlcpy((char *)errstr, "Out of memory", maxlen);
- return(errstr);
- }
-
- /* Get the error message */
- SDL_GetErrorMsgUNICODE(errstr16, maxlen);
-
- /* Convert from UNICODE to Latin1 encoding */
- for ( i=0; imixer_lock);
}
+static Uint16 SDL_ParseAudioFormat(const char *string)
+{
+ Uint16 format = 0;
+
+ switch (*string) {
+ case 'U':
+ ++string;
+ format |= 0x0000;
+ break;
+ case 'S':
+ ++string;
+ format |= 0x8000;
+ break;
+ default:
+ return 0;
+ }
+ switch (SDL_atoi(string)) {
+ case 8:
+ string += 1;
+ format |= 8;
+ break;
+ case 16:
+ string += 2;
+ format |= 16;
+ if ( SDL_strcmp(string, "LSB") == 0
+#if SDL_BYTEORDER == SDL_LIL_ENDIAN
+ || SDL_strcmp(string, "SYS") == 0
+#endif
+ ) {
+ format |= 0x0000;
+ }
+ if ( SDL_strcmp(string, "MSB") == 0
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ || SDL_strcmp(string, "SYS") == 0
+#endif
+ ) {
+ format |= 0x1000;
+ }
+ break;
+ default:
+ return 0;
+ }
+ return format;
+}
+
int SDL_AudioInit(const char *driver_name)
{
SDL_AudioDevice *audio;
@@ -386,6 +431,7 @@
int SDL_OpenAudio(SDL_AudioSpec *desired, SDL_AudioSpec *obtained)
{
SDL_AudioDevice *audio;
+ const char *env;
/* Start up the audio driver, if necessary */
if ( ! current_audio ) {
@@ -402,9 +448,35 @@
}
/* Verify some parameters */
- if ( desired->callback == NULL ) {
- SDL_SetError("SDL_OpenAudio() passed a NULL callback");
- return(-1);
+ if ( desired->freq == 0 ) {
+ env = SDL_getenv("SDL_AUDIO_FREQUENCY");
+ if ( env ) {
+ desired->freq = SDL_atoi(env);
+ }
+ }
+ if ( desired->freq == 0 ) {
+ /* Pick some default audio frequency */
+ desired->freq = 22050;
+ }
+ if ( desired->format == 0 ) {
+ env = SDL_getenv("SDL_AUDIO_FORMAT");
+ if ( env ) {
+ desired->format = SDL_ParseAudioFormat(env);
+ }
+ }
+ if ( desired->format == 0 ) {
+ /* Pick some default audio format */
+ desired->format = AUDIO_S16;
+ }
+ if ( desired->channels == 0 ) {
+ env = SDL_getenv("SDL_AUDIO_CHANNELS");
+ if ( env ) {
+ desired->channels = SDL_atoi(env);
+ }
+ }
+ if ( desired->channels == 0 ) {
+ /* Pick a default number of channels */
+ desired->channels = 2;
}
switch ( desired->channels ) {
case 1: /* Mono */
@@ -416,6 +488,25 @@
SDL_SetError("1 (mono) and 2 (stereo) channels supported");
return(-1);
}
+ if ( desired->samples == 0 ) {
+ env = SDL_getenv("SDL_AUDIO_SAMPLES");
+ if ( env ) {
+ desired->samples = SDL_atoi(env);
+ }
+ }
+ if ( desired->samples == 0 ) {
+ /* Pick a default of ~46 ms at desired frequency */
+ int samples = (desired->freq / 1000) * 46;
+ int power2 = 1;
+ while ( power2 < samples ) {
+ power2 *= 2;
+ }
+ desired->samples = power2;
+ }
+ if ( desired->callback == NULL ) {
+ SDL_SetError("SDL_OpenAudio() passed a NULL callback");
+ return(-1);
+ }
#if defined(__MACOS__) || (defined(__RISCOS__) && SDL_THREADS_DISABLED)
/* FIXME: Need to implement PPC interrupt asm for SDL_LockAudio() */
diff -r e49147870aac -r 14717b52abc0 src/audio/SDL_audio_c.h
--- a/src/audio/SDL_audio_c.h Mon May 01 06:58:33 2006 +0000
+++ b/src/audio/SDL_audio_c.h Wed May 17 08:18:28 2006 +0000
@@ -31,4 +31,4 @@
extern void SDL_CalculateAudioSpec(SDL_AudioSpec *spec);
/* The actual mixing thread function */
-extern int SDL_RunAudio(void *audiop);
+extern int SDLCALL SDL_RunAudio(void *audiop);
diff -r e49147870aac -r 14717b52abc0 src/audio/SDL_audiocvt.c
--- a/src/audio/SDL_audiocvt.c Mon May 01 06:58:33 2006 +0000
+++ b/src/audio/SDL_audiocvt.c Wed May 17 08:18:28 2006 +0000
@@ -27,7 +27,7 @@
/* Effectively mix right and left channels into a single channel */
-void SDL_ConvertMono(SDL_AudioCVT *cvt, Uint16 format)
+void SDLCALL SDL_ConvertMono(SDL_AudioCVT *cvt, Uint16 format)
{
int i;
Sint32 sample;
@@ -169,7 +169,7 @@
}
/* Discard top 4 channels */
-void SDL_ConvertStrip(SDL_AudioCVT *cvt, Uint16 format)
+void SDLCALL SDL_ConvertStrip(SDL_AudioCVT *cvt, Uint16 format)
{
int i;
Sint32 lsample, rsample;
@@ -285,7 +285,7 @@
/* Discard top 2 channels of 6 */
-void SDL_ConvertStrip_2(SDL_AudioCVT *cvt, Uint16 format)
+void SDLCALL SDL_ConvertStrip_2(SDL_AudioCVT *cvt, Uint16 format)
{
int i;
Sint32 lsample, rsample;
@@ -400,7 +400,7 @@
}
/* Duplicate a mono channel to both stereo channels */
-void SDL_ConvertStereo(SDL_AudioCVT *cvt, Uint16 format)
+void SDLCALL SDL_ConvertStereo(SDL_AudioCVT *cvt, Uint16 format)
{
int i;
@@ -438,7 +438,7 @@
/* Duplicate a stereo channel to a pseudo-5.1 stream */
-void SDL_ConvertSurround(SDL_AudioCVT *cvt, Uint16 format)
+void SDLCALL SDL_ConvertSurround(SDL_AudioCVT *cvt, Uint16 format)
{
int i;
@@ -615,7 +615,7 @@
/* Duplicate a stereo channel to a pseudo-4.0 stream */
-void SDL_ConvertSurround_4(SDL_AudioCVT *cvt, Uint16 format)
+void SDLCALL SDL_ConvertSurround_4(SDL_AudioCVT *cvt, Uint16 format)
{
int i;
@@ -768,7 +768,7 @@
/* Convert 8-bit to 16-bit - LSB */
-void SDL_Convert16LSB(SDL_AudioCVT *cvt, Uint16 format)
+void SDLCALL SDL_Convert16LSB(SDL_AudioCVT *cvt, Uint16 format)
{
int i;
Uint8 *src, *dst;
@@ -791,7 +791,7 @@
}
}
/* Convert 8-bit to 16-bit - MSB */
-void SDL_Convert16MSB(SDL_AudioCVT *cvt, Uint16 format)
+void SDLCALL SDL_Convert16MSB(SDL_AudioCVT *cvt, Uint16 format)
{
int i;
Uint8 *src, *dst;
@@ -815,7 +815,7 @@
}
/* Convert 16-bit to 8-bit */
-void SDL_Convert8(SDL_AudioCVT *cvt, Uint16 format)
+void SDLCALL SDL_Convert8(SDL_AudioCVT *cvt, Uint16 format)
{
int i;
Uint8 *src, *dst;
@@ -841,7 +841,7 @@
}
/* Toggle signed/unsigned */
-void SDL_ConvertSign(SDL_AudioCVT *cvt, Uint16 format)
+void SDLCALL SDL_ConvertSign(SDL_AudioCVT *cvt, Uint16 format)
{
int i;
Uint8 *data;
@@ -870,7 +870,7 @@
}
/* Toggle endianness */
-void SDL_ConvertEndian(SDL_AudioCVT *cvt, Uint16 format)
+void SDLCALL SDL_ConvertEndian(SDL_AudioCVT *cvt, Uint16 format)
{
int i;
Uint8 *data, tmp;
@@ -892,7 +892,7 @@
}
/* Convert rate up by multiple of 2 */
-void SDL_RateMUL2(SDL_AudioCVT *cvt, Uint16 format)
+void SDLCALL SDL_RateMUL2(SDL_AudioCVT *cvt, Uint16 format)
{
int i;
Uint8 *src, *dst;
@@ -930,7 +930,7 @@
/* Convert rate up by multiple of 2, for stereo */
-void SDL_RateMUL2_c2(SDL_AudioCVT *cvt, Uint16 format)
+void SDLCALL SDL_RateMUL2_c2(SDL_AudioCVT *cvt, Uint16 format)
{
int i;
Uint8 *src, *dst;
@@ -973,7 +973,7 @@
}
/* Convert rate up by multiple of 2, for quad */
-void SDL_RateMUL2_c4(SDL_AudioCVT *cvt, Uint16 format)
+void SDLCALL SDL_RateMUL2_c4(SDL_AudioCVT *cvt, Uint16 format)
{
int i;
Uint8 *src, *dst;
@@ -1029,7 +1029,7 @@
/* Convert rate up by multiple of 2, for 5.1 */
-void SDL_RateMUL2_c6(SDL_AudioCVT *cvt, Uint16 format)
+void SDLCALL SDL_RateMUL2_c6(SDL_AudioCVT *cvt, Uint16 format)
{
int i;
Uint8 *src, *dst;
@@ -1096,7 +1096,7 @@
}
/* Convert rate down by multiple of 2 */
-void SDL_RateDIV2(SDL_AudioCVT *cvt, Uint16 format)
+void SDLCALL SDL_RateDIV2(SDL_AudioCVT *cvt, Uint16 format)
{
int i;
Uint8 *src, *dst;
@@ -1131,7 +1131,7 @@
/* Convert rate down by multiple of 2, for stereo */
-void SDL_RateDIV2_c2(SDL_AudioCVT *cvt, Uint16 format)
+void SDLCALL SDL_RateDIV2_c2(SDL_AudioCVT *cvt, Uint16 format)
{
int i;
Uint8 *src, *dst;
@@ -1169,7 +1169,7 @@
/* Convert rate down by multiple of 2, for quad */
-void SDL_RateDIV2_c4(SDL_AudioCVT *cvt, Uint16 format)
+void SDLCALL SDL_RateDIV2_c4(SDL_AudioCVT *cvt, Uint16 format)
{
int i;
Uint8 *src, *dst;
@@ -1212,7 +1212,7 @@
}
/* Convert rate down by multiple of 2, for 5.1 */
-void SDL_RateDIV2_c6(SDL_AudioCVT *cvt, Uint16 format)
+void SDLCALL SDL_RateDIV2_c6(SDL_AudioCVT *cvt, Uint16 format)
{
int i;
Uint8 *src, *dst;
@@ -1261,7 +1261,7 @@
}
/* Very slow rate conversion routine */
-void SDL_RateSLOW(SDL_AudioCVT *cvt, Uint16 format)
+void SDLCALL SDL_RateSLOW(SDL_AudioCVT *cvt, Uint16 format)
{
double ipos;
int i, clen;
@@ -1474,7 +1474,7 @@
Uint32 hi_rate, lo_rate;
int len_mult;
double len_ratio;
- void (*rate_cvt)(SDL_AudioCVT *cvt, Uint16 format);
+ void (SDLCALL *rate_cvt)(SDL_AudioCVT *cvt, Uint16 format);
if ( src_rate > dst_rate ) {
hi_rate = src_rate;
diff -r e49147870aac -r 14717b52abc0 src/audio/SDL_wave.c
--- a/src/audio/SDL_wave.c Mon May 01 06:58:33 2006 +0000
+++ b/src/audio/SDL_wave.c Wed May 17 08:18:28 2006 +0000
@@ -478,6 +478,11 @@
}
IMA_ADPCM_encoded = 1;
break;
+ case MP3_CODE:
+ SDL_SetError("MPEG Layer 3 data not supported",
+ SDL_SwapLE16(format->encoding));
+ was_error = 1;
+ goto done;
default:
SDL_SetError("Unknown WAVE data format: 0x%.4x",
SDL_SwapLE16(format->encoding));
diff -r e49147870aac -r 14717b52abc0 src/audio/SDL_wave.h
--- a/src/audio/SDL_wave.h Mon May 01 06:58:33 2006 +0000
+++ b/src/audio/SDL_wave.h Wed May 17 08:18:28 2006 +0000
@@ -35,6 +35,7 @@
#define PCM_CODE 0x0001
#define MS_ADPCM_CODE 0x0002
#define IMA_ADPCM_CODE 0x0011
+#define MP3_CODE 0x0055
#define WAVE_MONO 1
#define WAVE_STEREO 2
diff -r e49147870aac -r 14717b52abc0 src/audio/mint/SDL_mintaudio.c
--- a/src/audio/mint/SDL_mintaudio.c Mon May 01 06:58:33 2006 +0000
+++ b/src/audio/mint/SDL_mintaudio.c Wed May 17 08:18:28 2006 +0000
@@ -42,9 +42,9 @@
SDL_AudioDevice *SDL_MintAudio_device;
Uint8 *SDL_MintAudio_audiobuf[2]; /* Pointers to buffers */
unsigned long SDL_MintAudio_audiosize; /* Length of audio buffer=spec->size */
-unsigned short SDL_MintAudio_numbuf; /* Buffer to play */
-unsigned short SDL_MintAudio_mutex;
-unsigned long SDL_MintAudio_clocktics;
+volatile unsigned short SDL_MintAudio_numbuf; /* Buffer to play */
+volatile unsigned short SDL_MintAudio_mutex;
+volatile unsigned long SDL_MintAudio_clocktics;
cookie_stfa_t *SDL_MintAudio_stfa;
/* MiNT thread variables */
diff -r e49147870aac -r 14717b52abc0 src/audio/mint/SDL_mintaudio.h
--- a/src/audio/mint/SDL_mintaudio.h Mon May 01 06:58:33 2006 +0000
+++ b/src/audio/mint/SDL_mintaudio.h Wed May 17 08:18:28 2006 +0000
@@ -119,10 +119,10 @@
extern SDL_AudioDevice *SDL_MintAudio_device;
extern Uint8 *SDL_MintAudio_audiobuf[2]; /* Pointers to buffers */
extern unsigned long SDL_MintAudio_audiosize; /* Length of audio buffer=spec->size */
-extern unsigned short SDL_MintAudio_numbuf; /* Buffer to play */
-extern unsigned short SDL_MintAudio_mutex;
+extern volatile unsigned short SDL_MintAudio_numbuf; /* Buffer to play */
+extern volatile unsigned short SDL_MintAudio_mutex;
extern cookie_stfa_t *SDL_MintAudio_stfa;
-extern unsigned long SDL_MintAudio_clocktics;
+extern volatile unsigned long SDL_MintAudio_clocktics;
/* MiNT thread variables */
extern SDL_bool SDL_MintAudio_mint_present;
diff -r e49147870aac -r 14717b52abc0 src/cdrom/macosx/AudioFilePlayer.c
--- a/src/cdrom/macosx/AudioFilePlayer.c Mon May 01 06:58:33 2006 +0000
+++ b/src/cdrom/macosx/AudioFilePlayer.c Wed May 17 08:18:28 2006 +0000
@@ -153,7 +153,7 @@
}
if (afp->mForkRefNum) {
- FSClose (afp->mForkRefNum);
+ FSCloseFork (afp->mForkRefNum);
afp->mForkRefNum = 0;
}
SDL_free(afp);
diff -r e49147870aac -r 14717b52abc0 src/cdrom/macosx/SDL_syscdrom.c
--- a/src/cdrom/macosx/SDL_syscdrom.c Mon May 01 06:58:33 2006 +0000
+++ b/src/cdrom/macosx/SDL_syscdrom.c Wed May 17 08:18:28 2006 +0000
@@ -453,8 +453,8 @@
static int SDL_SYS_CDEject(SDL_CD *cdrom)
{
OSStatus err;
- HParamBlockRec pb;
-
+ pid_t dissenter;
+
if (fakeCD) {
SDL_SetError (kErrorFakeDevice);
return -1;
@@ -475,9 +475,7 @@
status = CD_STOPPED;
/* Eject the volume */
- pb.ioParam.ioNamePtr = NULL;
- pb.ioParam.ioVRefNum = volumes[cdrom->id];
- err = PBUnmountVol((ParamBlockRec *) &pb);
+ err = FSEjectVolumeSync(volumes[cdrom->id], kNilOptions, &dissenter);
if (err != noErr) {
Unlock ();
diff -r e49147870aac -r 14717b52abc0 src/events/SDL_events.c
--- a/src/events/SDL_events.c Mon May 01 06:58:33 2006 +0000
+++ b/src/events/SDL_events.c Wed May 17 08:18:28 2006 +0000
@@ -87,7 +87,7 @@
#include
#endif
-static int SDL_GobbleEvents(void *unused)
+static int SDLCALL SDL_GobbleEvents(void *unused)
{
event_thread = SDL_ThreadID();
diff -r e49147870aac -r 14717b52abc0 src/events/SDL_keyboard.c
--- a/src/events/SDL_keyboard.c Mon May 01 06:58:33 2006 +0000
+++ b/src/events/SDL_keyboard.c Wed May 17 08:18:28 2006 +0000
@@ -59,7 +59,7 @@
/* Initialize the tables */
SDL_ModState = KMOD_NONE;
- SDL_memset(keynames, 0, sizeof(keynames));
+ SDL_memset((void*)keynames, 0, sizeof(keynames));
SDL_memset(SDL_KeyState, 0, sizeof(SDL_KeyState));
video->InitOSKeymap(this);
diff -r e49147870aac -r 14717b52abc0 src/file/SDL_rwops.c
--- a/src/file/SDL_rwops.c Mon May 01 06:58:33 2006 +0000
+++ b/src/file/SDL_rwops.c Wed May 17 08:18:28 2006 +0000
@@ -43,7 +43,7 @@
#define INVALID_SET_FILE_POINTER 0xFFFFFFFF
#endif
-static int win32_file_open(SDL_RWops *context, const char *filename, const char *mode)
+static int SDLCALL win32_file_open(SDL_RWops *context, const char *filename, const char *mode)
{
#ifndef _WIN32_WCE
UINT old_error_mode;
@@ -108,7 +108,7 @@
return 0; /* ok */
}
-static int win32_file_seek(SDL_RWops *context, int offset, int whence)
+static int SDLCALL win32_file_seek(SDL_RWops *context, int offset, int whence)
{
DWORD win32whence;
int file_pos;
@@ -138,7 +138,7 @@
SDL_Error(SDL_EFSEEK);
return -1; /* error */
}
-static int win32_file_read(SDL_RWops *context, void *ptr, int size, int maxnum)
+static int SDLCALL win32_file_read(SDL_RWops *context, void *ptr, int size, int maxnum)
{
int total_bytes;
@@ -156,7 +156,7 @@
nread = byte_read/size;
return nread;
}
-static int win32_file_write(SDL_RWops *context, const void *ptr, int size, int num)
+static int SDLCALL win32_file_write(SDL_RWops *context, const void *ptr, int size, int num)
{
int total_bytes;
@@ -183,7 +183,7 @@
nwritten = byte_written/size;
return nwritten;
}
-static int win32_file_close(SDL_RWops *context)
+static int SDLCALL win32_file_close(SDL_RWops *context)
{
if ( context ) {
@@ -201,7 +201,7 @@
/* Functions to read/write stdio file pointers */
-static int stdio_seek(SDL_RWops *context, int offset, int whence)
+static int SDLCALL stdio_seek(SDL_RWops *context, int offset, int whence)
{
if ( fseek(context->hidden.stdio.fp, offset, whence) == 0 ) {
return(ftell(context->hidden.stdio.fp));
@@ -210,7 +210,7 @@
return(-1);
}
}
-static int stdio_read(SDL_RWops *context, void *ptr, int size, int maxnum)
+static int SDLCALL stdio_read(SDL_RWops *context, void *ptr, int size, int maxnum)
{
size_t nread;
@@ -220,7 +220,7 @@
}
return(nread);
}
-static int stdio_write(SDL_RWops *context, const void *ptr, int size, int num)
+static int SDLCALL stdio_write(SDL_RWops *context, const void *ptr, int size, int num)
{
size_t nwrote;
@@ -230,7 +230,7 @@
}
return(nwrote);
}
-static int stdio_close(SDL_RWops *context)
+static int SDLCALL stdio_close(SDL_RWops *context)
{
if ( context ) {
if ( context->hidden.stdio.autoclose ) {
@@ -245,7 +245,7 @@
/* Functions to read/write memory pointers */
-static int mem_seek(SDL_RWops *context, int offset, int whence)
+static int SDLCALL mem_seek(SDL_RWops *context, int offset, int whence)
{
Uint8 *newpos;
@@ -272,7 +272,7 @@
context->hidden.mem.here = newpos;
return(context->hidden.mem.here-context->hidden.mem.base);
}
-static int mem_read(SDL_RWops *context, void *ptr, int size, int maxnum)
+static int SDLCALL mem_read(SDL_RWops *context, void *ptr, int size, int maxnum)
{
size_t total_bytes;
size_t mem_available;
@@ -292,7 +292,7 @@
return (total_bytes / size);
}
-static int mem_write(SDL_RWops *context, const void *ptr, int size, int num)
+static int SDLCALL mem_write(SDL_RWops *context, const void *ptr, int size, int num)
{
if ( (context->hidden.mem.here + (num*size)) > context->hidden.mem.stop ) {
num = (context->hidden.mem.stop-context->hidden.mem.here)/size;
@@ -301,12 +301,12 @@
context->hidden.mem.here += num*size;
return(num);
}
-static int mem_writeconst(SDL_RWops *context, const void *ptr, int size, int num)
+static int SDLCALL mem_writeconst(SDL_RWops *context, const void *ptr, int size, int num)
{
SDL_SetError("Can't write to read-only memory");
return(-1);
}
-static int mem_close(SDL_RWops *context)
+static int SDLCALL mem_close(SDL_RWops *context)
{
if ( context ) {
SDL_FreeRW(context);
diff -r e49147870aac -r 14717b52abc0 src/joystick/linux/SDL_sysjoystick.c
--- a/src/joystick/linux/SDL_sysjoystick.c Mon May 01 06:58:33 2006 +0000
+++ b/src/joystick/linux/SDL_sysjoystick.c Wed May 17 08:18:28 2006 +0000
@@ -30,9 +30,6 @@
#include
#include
#include /* For the definition of PATH_MAX */
-#ifdef __arm__
-#include /* Arm cross-compiler needs this */
-#endif
#include
#if SDL_INPUT_LINUXEV
#include
@@ -980,7 +977,8 @@
#ifndef NO_LOGICAL_JOYSTICKS
if (SDL_joylist[joystick->index].fname == NULL) {
SDL_joylist_head(i, joystick->index);
- return JS_HandleEvents(SDL_joylist[i].joy);
+ JS_HandleEvents(SDL_joylist[i].joy);
+ return;
}
#endif
diff -r e49147870aac -r 14717b52abc0 src/joystick/win32/SDL_mmjoystick.c
--- a/src/joystick/win32/SDL_mmjoystick.c Mon May 01 06:58:33 2006 +0000
+++ b/src/joystick/win32/SDL_mmjoystick.c Wed May 17 08:18:28 2006 +0000
@@ -154,34 +154,26 @@
JOYCAPS joycaps;
MMRESULT result;
- numdevs = 0;
- maxdevs = joyGetNumDevs();
-
- if ( maxdevs > MAX_JOYSTICKS ) {
- maxdevs = MAX_JOYSTICKS;
- }
-
-
- for ( i = 0; i < MAX_JOYSTICKS; i++ ) {
- SYS_JoystickID[i] = JOYSTICKID1 + i;
+ /* Reset the joystick ID & name mapping tables */
+ for ( i = 0; i < MAX_JOYSTICKS; ++i ) {
+ SYS_JoystickID[i] = 0;
SYS_JoystickName[i] = NULL;
}
-
- for ( i = 0; (i < maxdevs); ++i ) {
+ /* Loop over all potential joystick devices */
+ numdevs = 0;
+ maxdevs = joyGetNumDevs();
+ for ( i = JOYSTICKID1; i < maxdevs && numdevs < MAX_JOYSTICKS; ++i ) {
- /* added 8/31/2001 By Vitaliy Mikitchenko */
joyinfo.dwSize = sizeof(joyinfo);
joyinfo.dwFlags = JOY_RETURNALL;
- /* end addition */
-
result = joyGetPosEx(SYS_JoystickID[i], &joyinfo);
if ( result == JOYERR_NOERROR ) {
- result = joyGetDevCaps(SYS_JoystickID[i], &joycaps, sizeof(joycaps));
+ result = joyGetDevCaps(i, &joycaps, sizeof(joycaps));
if ( result == JOYERR_NOERROR ) {
- SYS_JoystickID[numdevs] = SYS_JoystickID[i];
+ SYS_JoystickID[numdevs] = i;
SYS_Joystick[numdevs] = joycaps;
- SYS_JoystickName[numdevs] = GetJoystickName(numdevs, joycaps.szRegKey);
+ SYS_JoystickName[numdevs] = GetJoystickName(i, joycaps.szRegKey);
numdevs++;
}
}
diff -r e49147870aac -r 14717b52abc0 src/loadso/macosx/SDL_dlcompat.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/loadso/macosx/SDL_dlcompat.c Wed May 17 08:18:28 2006 +0000
@@ -0,0 +1,1407 @@
+/*
+ SDL - Simple DirectMedia Layer
+ Copyright (C) 1997-2006 Sam Lantinga
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+ Sam Lantinga
+ slouken@libsdl.org
+*/
+#include "SDL_config.h"
+
+#ifdef SDL_LOADSO_DLCOMPAT
+
+/* Please note that dlcompat apparently ships in current Mac OS X versions
+ * as a system library that provides compatibility with the Unix "dlopen"
+ * interface. In order to allow SDL to work on older OS X releases and also
+ * not conflict with the system lib on newer versions, we include dlcompat
+ * in SDL and change the symbols to prevent symbol clash with any existing
+ * system libraries. --ryan.
+ */
+
+/* here is the dlcompat license: */
+
+/*
+Copyright (c) 2002 Jorge Acereda &
+ Peter O'Gorman
+
+Portions may be copyright others, see the AUTHORS file included with this
+distribution.
+
+Maintained by Peter O'Gorman
+
+Bug Reports and other queries should go to
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "SDL_stdinc.h"
+
+/* Just playing to see if it would compile with the freebsd headers, it does,
+ * but because of the different values for RTLD_LOCAL etc, it would break binary
+ * compat... oh well
+ */
+#ifndef __BSD_VISIBLE
+#define __BSD_VISIBLE 1
+#endif
+
+/*include "dlfcn.h"*/
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if defined (__GNUC__) && __GNUC__ > 3
+#define dl_restrict __restrict
+#else
+#define dl_restrict
+#endif
+
+#if 0
+#ifndef _POSIX_SOURCE
+/*
+ * Structure filled in by dladdr().
+ */
+typedef struct SDL_OSX_dl_info {
+ const char *dli_fname; /* Pathname of shared object */
+ void *dli_fbase; /* Base address of shared object */
+ const char *dli_sname; /* Name of nearest symbol */
+ void *dli_saddr; /* Address of nearest symbol */
+} SDL_OSX_Dl_info;
+
+static int SDL_OSX_dladdr(const void * dl_restrict, SDL_OSX_Dl_info * dl_restrict);
+#endif /* ! _POSIX_SOURCE */
+#endif /* 0 */
+
+static int SDL_OSX_dlclose(void * handle);
+static const char * SDL_OSX_dlerror(void);
+static void * SDL_OSX_dlopen(const char *path, int mode);
+static void * SDL_OSX_dlsym(void * dl_restrict handle, const char * dl_restrict symbol);
+
+#define RTLD_LAZY 0x1
+#define RTLD_NOW 0x2
+#define RTLD_LOCAL 0x4
+#define RTLD_GLOBAL 0x8
+
+#ifndef _POSIX_SOURCE
+#define RTLD_NOLOAD 0x10
+#define RTLD_NODELETE 0x80
+
+/*
+ * Special handle arguments for SDL_OSX_dlsym().
+ */
+#define RTLD_NEXT ((void *) -1) /* Search subsequent objects. */
+#define RTLD_DEFAULT ((void *) -2) /* Use default search algorithm. */
+#endif /* ! _POSIX_SOURCE */
+
+#ifdef __cplusplus
+}
+#endif
+
+#ifndef dl_restrict
+#define dl_restrict __restrict
+#endif
+/* This is not available on 10.1 */
+#ifndef LC_LOAD_WEAK_DYLIB
+#define LC_LOAD_WEAK_DYLIB (0x18 | LC_REQ_DYLD)
+#endif
+
+/* With this stuff here, this thing may actually compile/run on 10.0 systems
+ * Not that I have a 10.0 system to test it on anylonger
+ */
+#ifndef LC_REQ_DYLD
+#define LC_REQ_DYLD 0x80000000
+#endif
+#ifndef NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED
+#define NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED 0x4
+#endif
+#ifndef NSADDIMAGE_OPTION_RETURN_ON_ERROR
+#define NSADDIMAGE_OPTION_RETURN_ON_ERROR 0x1
+#endif
+#ifndef NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
+#define NSLOOKUPSYMBOLINIMAGE_OPTION_BIND 0x0
+#endif
+#ifndef NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR
+#define NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR 0x4
+#endif
+/* These symbols will be looked for in dyld */
+static const struct mach_header *(*dyld_NSAddImage) (const char *, unsigned long) = 0;
+static int (*dyld_NSIsSymbolNameDefinedInImage) (const struct mach_header *, const char *) = 0;
+static NSSymbol(*dyld_NSLookupSymbolInImage)
+ (const struct mach_header *, const char *, unsigned long) = 0;
+
+/* Define this to make dlcompat reuse data block. This way in theory we save
+ * a little bit of overhead. However we then couldn't correctly catch excess
+ * calls to SDL_OSX_dlclose(). Hence we don't use this feature
+ */
+#undef REUSE_STATUS
+
+/* Size of the internal error message buffer (used by dlerror()) */
+#define ERR_STR_LEN 251
+
+/* Maximum number of search paths supported by getSearchPath */
+#define MAX_SEARCH_PATHS 32
+
+
+#define MAGIC_DYLIB_OFI ((NSObjectFileImage) 'DYOF')
+#define MAGIC_DYLIB_MOD ((NSModule) 'DYMO')
+
+/* internal flags */
+#define DL_IN_LIST 0x01
+
+/* our mutex */
+static pthread_mutex_t dlcompat_mutex;
+/* Our thread specific storage
+ */
+static pthread_key_t dlerror_key;
+
+struct dlthread
+{
+ int lockcnt;
+ unsigned char errset;
+ char errstr[ERR_STR_LEN];
+};
+
+/* This is our central data structure. Whenever a module is loaded via
+ * SDL_OSX_dlopen(), we create such a struct.
+ */
+struct dlstatus
+{
+ struct dlstatus *next; /* pointer to next element in the linked list */
+ NSModule module;
+ const struct mach_header *lib;
+ int refs; /* reference count */
+ int mode; /* mode in which this module was loaded */
+ dev_t device;
+ ino_t inode;
+ int flags; /* Any internal flags we may need */
+};
+
+/* Head node of the dlstatus list */
+static struct dlstatus mainStatus = { 0, MAGIC_DYLIB_MOD, NULL, -1, RTLD_GLOBAL, 0, 0, 0 };
+static struct dlstatus *stqueue = &mainStatus;
+
+
+/* Storage for the last error message (used by dlerror()) */
+/* static char err_str[ERR_STR_LEN]; */
+/* static int err_filled = 0; */
+
+/* Prototypes to internal functions */
+static void debug(const char *fmt, ...);
+static void error(const char *str, ...);
+static const char *safegetenv(const char *s);
+static const char *searchList(void);
+static const char *getSearchPath(int i);
+static const char *getFullPath(int i, const char *file);
+static const struct stat *findFile(const char *file, const char **fullPath);
+static int isValidStatus(struct dlstatus *status);
+static inline int isFlagSet(int mode, int flag);
+static struct dlstatus *lookupStatus(const struct stat *sbuf);
+static void insertStatus(struct dlstatus *dls, const struct stat *sbuf);
+static int promoteLocalToGlobal(struct dlstatus *dls);
+static void *reference(struct dlstatus *dls, int mode);
+static void *dlsymIntern(struct dlstatus *dls, const char *symbol, int canSetError);
+static struct dlstatus *allocStatus(void);
+static struct dlstatus *loadModule(const char *path, const struct stat *sbuf, int mode);
+static NSSymbol search_linked_libs(const struct mach_header *mh, const char *symbol);
+static const char *get_lib_name(const struct mach_header *mh);
+static const struct mach_header *get_mach_header_from_NSModule(NSModule mod);
+static void dlcompat_init_func(void);
+static inline void dlcompat_init_check(void);
+static inline void dolock(void);
+static inline void dounlock(void);
+static void dlerrorfree(void *data);
+static void resetdlerror(void);
+static const struct mach_header *my_find_image(const char *name);
+static const struct mach_header *image_for_address(const void *address);
+static inline char *dyld_error_str(void);
+
+#if FINK_BUILD
+/* Two Global Functions */
+static void *dlsym_prepend_underscore(void *handle, const char *symbol);
+static void *dlsym_auto_underscore(void *handle, const char *symbol);
+
+/* And their _intern counterparts */
+static void *dlsym_prepend_underscore_intern(void *handle, const char *symbol);
+static void *dlsym_auto_underscore_intern(void *handle, const char *symbol);
+#endif
+
+/* Functions */
+
+static void debug(const char *fmt, ...)
+{
+#if DEBUG > 1
+ va_list arg;
+ va_start(arg, fmt);
+ fprintf(stderr, "DLDEBUG: ");
+ vfprintf(stderr, fmt, arg);
+ fprintf(stderr, "\n");
+ fflush(stderr);
+ va_end(arg);
+#endif
+}
+
+static void error(const char *str, ...)
+{
+ va_list arg;
+ struct dlthread *tss;
+ char * err_str;
+ va_start(arg, str);
+ tss = pthread_getspecific(dlerror_key);
+ err_str = tss->errstr;
+ SDL_strlcpy(err_str, "dlcompat: ", ERR_STR_LEN);
+ vsnprintf(err_str + 10, ERR_STR_LEN - 10, str, arg);
+ va_end(arg);
+ debug("ERROR: %s\n", err_str);
+ tss->errset = 1;
+}
+
+static void warning(const char *str)
+{
+#if DEBUG > 0
+ fprintf(stderr, "WARNING: dlcompat: %s\n", str);
+#endif
+}
+
+static const char *safegetenv(const char *s)
+{
+ const char *ss = SDL_getenv(s);
+ return ss ? ss : "";
+}
+
+/* because this is only used for debugging and error reporting functions, we
+ * don't really care about how elegant it is... it could use the load
+ * commands to find the install name of the library, but...
+ */
+static const char *get_lib_name(const struct mach_header *mh)
+{
+ unsigned long count = _dyld_image_count();
+ unsigned long i;
+ const char *val = NULL;
+ if (mh)
+ {
+ for (i = 0; i < count; i++)
+ {
+ if (mh == _dyld_get_image_header(i))
+ {
+ val = _dyld_get_image_name(i);
+ break;
+ }
+ }
+ }
+ return val;
+}
+
+/* Returns the mach_header for the module bu going through all the loaded images
+ * and finding the one with the same name as the module. There really ought to be
+ * an api for doing this, would be faster, but there isn't one right now
+ */
+static const struct mach_header *get_mach_header_from_NSModule(NSModule mod)
+{
+ const char *mod_name = NSNameOfModule(mod);
+ const struct mach_header *mh = NULL;
+ unsigned long count = _dyld_image_count();
+ unsigned long i;
+ debug("Module name: %s", mod_name);
+ for (i = 0; i < count; i++)
+ {
+ if (!SDL_strcmp(mod_name, _dyld_get_image_name(i)))
+ {
+ mh = _dyld_get_image_header(i);
+ break;
+ }
+ }
+ return mh;
+}
+
+
+/* Compute and return a list of all directories that we should search when
+ * trying to locate a module. We first look at the values of LD_LIBRARY_PATH
+ * and DYLD_LIBRARY_PATH, and then finally fall back to looking into
+ * /usr/lib and /lib. Since both of the environments variables can contain a
+ * list of colon seperated paths, we simply concat them and the two other paths
+ * into one big string, which we then can easily parse.
+ * Splitting this string into the actual path list is done by getSearchPath()
+ */
+static const char *searchList()
+{
+ size_t buf_size;
+ static char *buf=NULL;
+ const char *ldlp = safegetenv("LD_LIBRARY_PATH");
+ const char *dyldlp = safegetenv("DYLD_LIBRARY_PATH");
+ const char *stdpath = SDL_getenv("DYLD_FALLBACK_LIBRARY_PATH");
+ if (!stdpath)
+ stdpath = "/usr/local/lib:/lib:/usr/lib";
+ if (!buf)
+ {
+ buf_size = SDL_strlen(ldlp) + SDL_strlen(dyldlp) + SDL_strlen(stdpath) + 4;
+ buf = SDL_malloc(buf_size);
+ SDL_snprintf(buf, buf_size, "%s%s%s%s%s%c", dyldlp, (dyldlp[0] ? ":" : ""), ldlp, (ldlp[0] ? ":" : ""),
+ stdpath, '\0');
+ }
+ return buf;
+}
+
+/* Returns the ith search path from the list as computed by searchList() */
+static const char *getSearchPath(int i)
+{
+ static const char *list = 0;
+ static char **path = (char **)0;
+ static int end = 0;
+ static int numsize = MAX_SEARCH_PATHS;
+ static char **tmp;
+ /* So we can call SDL_free() in the "destructor" we use i=-1 to return the alloc'd array */
+ if (i == -1)
+ {
+ return (const char*)path;
+ }
+ if (!path)
+ {
+ path = (char **)SDL_calloc(MAX_SEARCH_PATHS, sizeof(char **));
+ }
+ if (!list && !end)
+ list = searchList();
+ if (i >= (numsize))
+ {
+ debug("Increasing size for long PATH");
+ tmp = (char **)SDL_calloc((MAX_SEARCH_PATHS + numsize), sizeof(char **));
+ if (tmp)
+ {
+ SDL_memcpy(tmp, path, sizeof(char **) * numsize);
+ SDL_free(path);
+ path = tmp;
+ numsize += MAX_SEARCH_PATHS;
+ }
+ else
+ {
+ return 0;
+ }
+ }
+
+ while (!path[i] && !end)
+ {
+ path[i] = strsep((char **)&list, ":");
+
+ if (path[i][0] == 0)
+ path[i] = 0;
+ end = (list == 0);
+ }
+ return path[i];
+}
+
+static const char *getFullPath(int i, const char *file)
+{
+ static char buf[PATH_MAX];
+ const char *path = getSearchPath(i);
+ if (path)
+ {
+ SDL_snprintf(buf, PATH_MAX, "%s/%s", path, file);
+ }
+ return path ? buf : 0;
+}
+
+/* Given a file name, try to determine the full path for that file. Starts
+ * its search in the current directory, and then tries all paths in the
+ * search list in the order they are specified there.
+ */
+static const struct stat *findFile(const char *file, const char **fullPath)
+{
+ int i = 0;
+ static struct stat sbuf;
+ char *fileName;
+ debug("finding file %s", file);
+ *fullPath = file;
+ if (0 == stat(file, &sbuf))
+ return &sbuf;
+ if (SDL_strchr(file, '/'))
+ return 0; /* If the path had a / we don't look in env var places */
+ fileName = NULL;
+ if (!fileName)
+ fileName = (char *)file;
+ while ((*fullPath = getFullPath(i++, fileName)))
+ {
+ if (0 == stat(*fullPath, &sbuf))
+ return &sbuf;
+ }
+ ;
+ return 0;
+}
+
+/* Determine whether a given dlstatus is valid or not */
+static int isValidStatus(struct dlstatus *status)
+{
+ /* Walk the list to verify status is contained in it */
+ struct dlstatus *dls = stqueue;
+ while (dls && status != dls)
+ dls = dls->next;
+ if (dls == 0)
+ error("invalid handle");
+ else if ((dls->module == 0) || (dls->refs == 0))
+ error("handle to closed library");
+ else
+ return TRUE;
+ return FALSE;
+}
+
+static inline int isFlagSet(int mode, int flag)
+{
+ return (mode & flag) == flag;
+}
+
+static struct dlstatus *lookupStatus(const struct stat *sbuf)
+{
+ struct dlstatus *dls = stqueue;
+ debug("looking for status");
+ while (dls && ( /* isFlagSet(dls->mode, RTLD_UNSHARED) */ 0
+ || sbuf->st_dev != dls->device || sbuf->st_ino != dls->inode))
+ dls = dls->next;
+ return dls;
+}
+
+static void insertStatus(struct dlstatus *dls, const struct stat *sbuf)
+{
+ debug("inserting status");
+ dls->inode = sbuf->st_ino;
+ dls->device = sbuf->st_dev;
+ dls->refs = 0;
+ dls->mode = 0;
+ if ((dls->flags & DL_IN_LIST) == 0)
+ {
+ dls->next = stqueue;
+ stqueue = dls;
+ dls->flags |= DL_IN_LIST;
+ }
+}
+
+static struct dlstatus *allocStatus()
+{
+ struct dlstatus *dls;
+#ifdef REUSE_STATUS
+ dls = stqueue;
+ while (dls && dls->module)
+ dls = dls->next;
+ if (!dls)
+#endif
+ dls = SDL_calloc(sizeof(*dls),1);
+ return dls;
+}
+
+static int promoteLocalToGlobal(struct dlstatus *dls)
+{
+ static int (*p) (NSModule module) = 0;
+ debug("promoting");
+ if (!p)
+ _dyld_func_lookup("__dyld_NSMakePrivateModulePublic", (void **)&p);
+ return (dls->module == MAGIC_DYLIB_MOD) || (p && p(dls->module));
+}
+
+static void *reference(struct dlstatus *dls, int mode)
+{
+ if (dls)
+ {
+ if (dls->module == MAGIC_DYLIB_MOD && isFlagSet(mode, RTLD_LOCAL))
+ {
+ warning("trying to open a .dylib with RTLD_LOCAL");
+ error("unable to open a .dylib with RTLD_LOCAL");
+ return NULL;
+ }
+ if (isFlagSet(mode, RTLD_GLOBAL) &&
+ !isFlagSet(dls->mode, RTLD_GLOBAL) && !promoteLocalToGlobal(dls))
+ {
+ error("unable to promote local module to global");
+ return NULL;
+ }
+ dls->mode |= mode;
+ dls->refs++;
+ }
+ else
+ debug("reference called with NULL argument");
+
+ return dls;
+}
+
+static const struct mach_header *my_find_image(const char *name)
+{
+ const struct mach_header *mh = 0;
+ const char *id = NULL;
+ int i = _dyld_image_count();
+ int j;
+ mh = (struct mach_header *)
+ dyld_NSAddImage(name, NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED |
+ NSADDIMAGE_OPTION_RETURN_ON_ERROR);
+ if (!mh)
+ {
+ for (j = 0; j < i; j++)
+ {
+ id = _dyld_get_image_name(j);
+ if (!SDL_strcmp(id, name))
+ {
+ mh = _dyld_get_image_header(j);
+ break;
+ }
+ }
+ }
+ return mh;
+}
+
+/*
+ * dyld adds libraries by first adding the directly dependant libraries in link order, and
+ * then adding the dependencies for those libraries, so we should do the same... but we don't
+ * bother adding the extra dependencies, if the symbols are neither in the loaded image nor
+ * any of it's direct dependencies, then it probably isn't there.
+ */
+static NSSymbol search_linked_libs(const struct mach_header * mh, const char *symbol)
+{
+ unsigned int n;
+ struct load_command *lc = 0;
+ struct mach_header *wh;
+ NSSymbol nssym = 0;
+ if (dyld_NSAddImage && dyld_NSIsSymbolNameDefinedInImage && dyld_NSLookupSymbolInImage)
+ {
+ lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
+ for (n = 0; n < mh->ncmds; n++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
+ {
+ if ((LC_LOAD_DYLIB == lc->cmd) || (LC_LOAD_WEAK_DYLIB == lc->cmd))
+ {
+ if ((wh = (struct mach_header *)
+ my_find_image((char *)(((struct dylib_command *)lc)->dylib.name.offset +
+ (char *)lc))))
+ {
+ if (dyld_NSIsSymbolNameDefinedInImage(wh, symbol))
+ {
+ nssym = dyld_NSLookupSymbolInImage(wh,
+ symbol,
+ NSLOOKUPSYMBOLINIMAGE_OPTION_BIND |
+ NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
+ break;
+ }
+ }
+ }
+ }
+ if ((!nssym) && NSIsSymbolNameDefined(symbol))
+ {
+ /* I've never seen this debug message...*/
+ debug("Symbol \"%s\" is defined but was not found", symbol);
+ }
+ }
+ return nssym;
+}
+
+/* Up to the caller to SDL_free() returned string */
+static inline char *dyld_error_str()
+{
+ NSLinkEditErrors dylder;
+ int dylderno;
+ const char *dylderrstr;
+ const char *dyldfile;
+ char* retStr = NULL;
+ NSLinkEditError(&dylder, &dylderno, &dyldfile, &dylderrstr);
+ if (dylderrstr && *dylderrstr)
+ {
+ retStr = SDL_strdup(dylderrstr);
+ }
+ return retStr;
+}
+
+static void *dlsymIntern(struct dlstatus *dls, const char *symbol, int canSetError)
+{
+ NSSymbol nssym = 0;
+#ifdef __GCC__
+ void *caller = __builtin_return_address(1); /* Be *very* careful about inlining */
+#else
+ void *caller = NULL;
+#endif
+ const struct mach_header *caller_mh = 0;
+ char *savedErrorStr = NULL;
+ resetdlerror();
+#ifndef RTLD_SELF
+#define RTLD_SELF ((void *) -3)
+#endif
+ if (NULL == dls)
+ dls = RTLD_SELF;
+ if ((RTLD_NEXT == dls) || (RTLD_SELF == dls))
+ {
+ if (dyld_NSIsSymbolNameDefinedInImage && dyld_NSLookupSymbolInImage && caller)
+ {
+ caller_mh = image_for_address(caller);
+ if (RTLD_SELF == dls)
+ {
+ /* FIXME: We should be using the NSModule api, if SELF is an MH_BUNDLE
+ * But it appears to work anyway, and looking at the code in dyld_libfuncs.c
+ * this is acceptable.
+ */
+ if (dyld_NSIsSymbolNameDefinedInImage(caller_mh, symbol))
+ {
+ nssym = dyld_NSLookupSymbolInImage(caller_mh,
+ symbol,
+ NSLOOKUPSYMBOLINIMAGE_OPTION_BIND |
+ NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
+ }
+ }
+ if (!nssym)
+ {
+ if (RTLD_SELF == dls)
+ savedErrorStr = dyld_error_str();
+ nssym = search_linked_libs(caller_mh, symbol);
+ }
+ }
+ else
+ {
+ if (canSetError)
+ error("RTLD_SELF and RTLD_NEXT are not supported");
+ return NULL;
+ }
+ }
+ if (!nssym)
+ {
+
+ if (RTLD_DEFAULT == dls)
+ {
+ dls = &mainStatus;
+ }
+ if (!isValidStatus(dls))
+ return NULL;
+
+ if (dls->module != MAGIC_DYLIB_MOD)
+ {
+ nssym = NSLookupSymbolInModule(dls->module, symbol);
+ if (!nssym && NSIsSymbolNameDefined(symbol))
+ {
+ debug("Searching dependencies");
+ savedErrorStr = dyld_error_str();
+ nssym = search_linked_libs(get_mach_header_from_NSModule(dls->module), symbol);
+ }
+ }
+ else if (dls->lib && dyld_NSIsSymbolNameDefinedInImage && dyld_NSLookupSymbolInImage)
+ {
+ if (dyld_NSIsSymbolNameDefinedInImage(dls->lib, symbol))
+ {
+ nssym = dyld_NSLookupSymbolInImage(dls->lib,
+ symbol,
+ NSLOOKUPSYMBOLINIMAGE_OPTION_BIND |
+ NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
+ }
+ else if (NSIsSymbolNameDefined(symbol))
+ {
+ debug("Searching dependencies");
+ savedErrorStr = dyld_error_str();
+ nssym = search_linked_libs(dls->lib, symbol);
+ }
+ }
+ else if (dls->module == MAGIC_DYLIB_MOD)
+ {
+ /* Global context, use NSLookupAndBindSymbol */
+ if (NSIsSymbolNameDefined(symbol))
+ {
+ /* There doesn't seem to be a return on error option for this call???
+ this is potentially broken, if binding fails, it will improperly
+ exit the application. */
+ nssym = NSLookupAndBindSymbol(symbol);
+ }
+ else
+ {
+ if (savedErrorStr)
+ SDL_free(savedErrorStr);
+ savedErrorStr = SDL_malloc(256);
+ SDL_snprintf(savedErrorStr, 256, "Symbol \"%s\" not in global context",symbol);
+ }
+ }
+ }
+ /* Error reporting */
+ if (!nssym)
+ {
+ if (!savedErrorStr || !SDL_strlen(savedErrorStr))
+ {
+ if (savedErrorStr)
+ SDL_free(savedErrorStr);
+ savedErrorStr = SDL_malloc(256);
+ SDL_snprintf(savedErrorStr, 256,"Symbol \"%s\" not found",symbol);
+ }
+ if (canSetError)
+ {
+ error(savedErrorStr);
+ }
+ else
+ {
+ debug(savedErrorStr);
+ }
+ if (savedErrorStr)
+ SDL_free(savedErrorStr);
+ return NULL;
+ }
+ return NSAddressOfSymbol(nssym);
+}
+
+static struct dlstatus *loadModule(const char *path, const struct stat *sbuf, int mode)
+{
+ NSObjectFileImage ofi = 0;
+ NSObjectFileImageReturnCode ofirc;
+ struct dlstatus *dls;
+ NSLinkEditErrors ler;
+ int lerno;
+ const char *errstr;
+ const char *file;
+ void (*init) (void);
+
+ ofirc = NSCreateObjectFileImageFromFile(path, &ofi);
+ switch (ofirc)
+ {
+ case NSObjectFileImageSuccess:
+ break;
+ case NSObjectFileImageInappropriateFile:
+ if (dyld_NSAddImage && dyld_NSIsSymbolNameDefinedInImage && dyld_NSLookupSymbolInImage)
+ {
+ if (isFlagSet(mode, RTLD_LOCAL))
+ {
+ warning("trying to open a .dylib with RTLD_LOCAL");
+ error("unable to open this file with RTLD_LOCAL");
+ return NULL;
+ }
+ }
+ else
+ {
+ error("opening this file is unsupported on this system");
+ return NULL;
+ }
+ break;
+ case NSObjectFileImageFailure:
+ error("object file setup failure");
+ return NULL;
+ case NSObjectFileImageArch:
+ error("no object for this architecture");
+ return NULL;
+ case NSObjectFileImageFormat:
+ error("bad object file format");
+ return NULL;
+ case NSObjectFileImageAccess:
+ error("can't read object file");
+ return NULL;
+ default:
+ error("unknown error from NSCreateObjectFileImageFromFile()");
+ return NULL;
+ }
+ dls = lookupStatus(sbuf);
+ if (!dls)
+ {
+ dls = allocStatus();
+ }
+ if (!dls)
+ {
+ error("unable to allocate memory");
+ return NULL;
+ }
+ // dls->lib = 0;
+ if (ofirc == NSObjectFileImageInappropriateFile)
+ {
+ if ((dls->lib = dyld_NSAddImage(path, NSADDIMAGE_OPTION_RETURN_ON_ERROR)))
+ {
+ debug("Dynamic lib loaded at %ld", dls->lib);
+ ofi = MAGIC_DYLIB_OFI;
+ dls->module = MAGIC_DYLIB_MOD;
+ ofirc = NSObjectFileImageSuccess;
+ /* Although it is possible with a bit of work to modify this so it works and
+ functions with RTLD_NOW, I don't deem it necessary at the moment */
+ }
+ if (!(dls->module))
+ {
+ NSLinkEditError(&ler, &lerno, &file, &errstr);
+ if (!errstr || (!SDL_strlen(errstr)))
+ error("Can't open this file type");
+ else
+ error(errstr);
+ if ((dls->flags & DL_IN_LIST) == 0)
+ {
+ SDL_free(dls);
+ }
+ return NULL;
+ }
+ }
+ else
+ {
+ dls->module = NSLinkModule(ofi, path,
+ NSLINKMODULE_OPTION_RETURN_ON_ERROR |
+ NSLINKMODULE_OPTION_PRIVATE |
+ (isFlagSet(mode, RTLD_NOW) ? NSLINKMODULE_OPTION_BINDNOW : 0));
+ NSDestroyObjectFileImage(ofi);
+ if (dls->module)
+ {
+ dls->lib = get_mach_header_from_NSModule(dls->module);
+ }
+ }
+ if (!dls->module)
+ {
+ NSLinkEditError(&ler, &lerno, &file, &errstr);
+ if ((dls->flags & DL_IN_LIST) == 0)
+ {
+ SDL_free(dls);
+ }
+ error(errstr);
+ return NULL;
+ }
+
+ insertStatus(dls, sbuf);
+ dls = reference(dls, mode);
+ if ((init = dlsymIntern(dls, "__init", 0)))
+ {
+ debug("calling _init()");
+ init();
+ }
+ return dls;
+}
+
+inline static void dlcompat_init_check(void)
+{
+ static pthread_mutex_t l = PTHREAD_MUTEX_INITIALIZER;
+ static int init_done = 0;
+
+ pthread_mutex_lock(&l);
+ if (!init_done) {
+ dlcompat_init_func();
+ init_done = 1;
+ }
+ pthread_mutex_unlock(&l);
+}
+
+static void dlcompat_init_func(void)
+{
+ _dyld_func_lookup("__dyld_NSAddImage", (void **)&dyld_NSAddImage);
+ _dyld_func_lookup("__dyld_NSIsSymbolNameDefinedInImage",
+ (void **)&dyld_NSIsSymbolNameDefinedInImage);
+ _dyld_func_lookup("__dyld_NSLookupSymbolInImage", (void **)&dyld_NSLookupSymbolInImage);
+ if (pthread_mutex_init(&dlcompat_mutex, NULL))
+ exit(1);
+ if (pthread_key_create(&dlerror_key, &dlerrorfree))
+ exit(1);
+}
+
+static void resetdlerror()
+{
+ struct dlthread *tss;
+ tss = pthread_getspecific(dlerror_key);
+ tss->errset = 0;
+}
+
+static void dlerrorfree(void *data)
+{
+ SDL_free(data);
+}
+
+/* We kind of want a recursive lock here, but meet a little trouble
+ * because they are not available pre OS X 10.2, so we fake it
+ * using thread specific storage to keep a lock count
+ */
+static inline void dolock(void)
+{
+ int err = 0;
+ struct dlthread *tss;
+ dlcompat_init_check();
+ tss = pthread_getspecific(dlerror_key);
+ if (!tss)
+ {
+ tss = SDL_malloc(sizeof(struct dlthread));
+ tss->lockcnt = 0;
+ tss->errset = 0;
+ if (pthread_setspecific(dlerror_key, tss))
+ {
+ fprintf(stderr,"dlcompat: pthread_setspecific failed\n");
+ exit(1);
+ }
+ }
+ if (!tss->lockcnt)
+ err = pthread_mutex_lock(&dlcompat_mutex);
+ tss->lockcnt = tss->lockcnt +1;
+ if (err)
+ exit(err);
+}
+
+static inline void dounlock(void)
+{
+ int err = 0;
+ struct dlthread *tss;
+ tss = pthread_getspecific(dlerror_key);
+ tss->lockcnt = tss->lockcnt -1;
+ if (!tss->lockcnt)
+ err = pthread_mutex_unlock(&dlcompat_mutex);
+ if (err)
+ exit(err);
+}
+
+static void *SDL_OSX_dlopen(const char *path, int mode)
+{
+ const struct stat *sbuf;
+ struct dlstatus *dls;
+ const char *fullPath;
+
+ dolock();
+ resetdlerror();
+ if (!path)
+ {
+ dls = &mainStatus;
+ goto dlopenok;
+ }
+ if (!(sbuf = findFile(path, &fullPath)))
+ {
+ error("file \"%s\" not found", path);
+ goto dlopenerror;
+ }
+ /* Now checks that it hasn't been closed already */
+ if ((dls = lookupStatus(sbuf)) && (dls->refs > 0))
+ {
+ /* debug("status found"); */
+ dls = reference(dls, mode);
+ goto dlopenok;
+ }
+#ifdef RTLD_NOLOAD
+ if (isFlagSet(mode, RTLD_NOLOAD))
+ {
+ error("no existing handle and RTLD_NOLOAD specified");
+ goto dlopenerror;
+ }
+#endif
+ if (isFlagSet(mode, RTLD_LAZY) && isFlagSet(mode, RTLD_NOW))
+ {
+ error("how can I load something both RTLD_LAZY and RTLD_NOW?");
+ goto dlopenerror;
+ }
+ dls = loadModule(fullPath, sbuf, mode);
+
+ dlopenok:
+ dounlock();
+ return (void *)dls;
+ dlopenerror:
+ dounlock();
+ return NULL;
+}
+
+#if !FINK_BUILD
+static void *SDL_OSX_dlsym(void * dl_restrict handle, const char * dl_restrict symbol)
+{
+ int sym_len = SDL_strlen(symbol);
+ void *value = NULL;
+ char *malloc_sym = NULL;
+ dolock();
+ malloc_sym = SDL_malloc(sym_len + 2);
+ if (malloc_sym)
+ {
+ SDL_snprintf(malloc_sym, sym_len+2, "_%s", symbol);
+ value = dlsymIntern(handle, malloc_sym, 1);
+ SDL_free(malloc_sym);
+ }
+ else
+ {
+ error("Unable to allocate memory");
+ goto dlsymerror;
+ }
+ dounlock();
+ return value;
+ dlsymerror:
+ dounlock();
+ return NULL;
+}
+#endif
+
+#if FINK_BUILD
+
+static void *dlsym_prepend_underscore(void *handle, const char *symbol)
+{
+ void *answer;
+ dolock();
+ answer = dlsym_prepend_underscore_intern(handle, symbol);
+ dounlock();
+ return answer;
+}
+
+static void *dlsym_prepend_underscore_intern(void *handle, const char *symbol)
+{
+/*
+ * A quick and easy way for porting packages which call dlsym(handle,"sym")
+ * If the porter adds -Ddlsym=dlsym_prepend_underscore to the CFLAGS then
+ * this function will be called, and will add the required underscore.
+ *
+ * Note that I haven't figured out yet which should be "standard", prepend
+ * the underscore always, or not at all. These global functions need to go away
+ * for opendarwin.
+ */
+ int sym_len = SDL_strlen(symbol);
+ void *value = NULL;
+ char *malloc_sym = NULL;
+ malloc_sym = SDL_malloc(sym_len + 2);
+ if (malloc_sym)
+ {
+ SDL_snprintf(malloc_sym, sym_len+2, "_%s", symbol);
+ value = dlsymIntern(handle, malloc_sym, 1);
+ SDL_free(malloc_sym);
+ }
+ else
+ {
+ error("Unable to allocate memory");
+ }
+ return value;
+}
+
+static void *dlsym_auto_underscore(void *handle, const char *symbol)
+{
+ void *answer;
+ dolock();
+ answer = dlsym_auto_underscore_intern(handle, symbol);
+ dounlock();
+ return answer;
+
+}
+static void *dlsym_auto_underscore_intern(void *handle, const char *symbol)
+{
+ struct dlstatus *dls = handle;
+ void *addr = 0;
+ addr = dlsymIntern(dls, symbol, 0);
+ if (!addr)
+ addr = dlsym_prepend_underscore_intern(handle, symbol);
+ return addr;
+}
+
+
+static void *SDL_OSX_dlsym(void * dl_restrict handle, const char * dl_restrict symbol)
+{
+ struct dlstatus *dls = handle;
+ void *addr = 0;
+ dolock();
+ addr = dlsymIntern(dls, symbol, 1);
+ dounlock();
+ return addr;
+}
+#endif
+
+static int SDL_OSX_dlclose(void *handle)
+{
+ struct dlstatus *dls = handle;
+ dolock();
+ resetdlerror();
+ if (!isValidStatus(dls))
+ {
+ goto dlcloseerror;
+ }
+ if (dls->module == MAGIC_DYLIB_MOD)
+ {
+ const char *name;
+ if (!dls->lib)
+ {
+ name = "global context";
+ }
+ else
+ {
+ name = get_lib_name(dls->lib);
+ }
+ warning("trying to close a .dylib!");
+ error("Not closing \"%s\" - dynamic libraries cannot be closed", name);
+ goto dlcloseerror;
+ }
+ if (!dls->module)
+ {
+ error("module already closed");
+ goto dlcloseerror;
+ }
+
+ if (dls->refs == 1)
+ {
+ unsigned long options = 0;
+ void (*fini) (void);
+ if ((fini = dlsymIntern(dls, "__fini", 0)))
+ {
+ debug("calling _fini()");
+ fini();
+ }
+ options |= NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES;
+#ifdef RTLD_NODELETE
+ if (isFlagSet(dls->mode, RTLD_NODELETE))
+ options |= NSUNLINKMODULE_OPTION_KEEP_MEMORY_MAPPED;
+#endif
+ if (!NSUnLinkModule(dls->module, options))
+ {
+ error("unable to unlink module");
+ goto dlcloseerror;
+ }
+ dls->refs--;
+ dls->module = 0;
+ /* Note: the dlstatus struct dls is neither removed from the list
+ * nor is the memory it occupies freed. This shouldn't pose a
+ * problem in mostly all cases, though.
+ */
+ }
+ dounlock();
+ return 0;
+ dlcloseerror:
+ dounlock();
+ return 1;
+}
+
+static const char *SDL_OSX_dlerror(void)
+{
+ struct dlthread *tss;
+ const char * err_str = NULL;
+ dlcompat_init_check();
+ tss = pthread_getspecific(dlerror_key);
+ if (tss != NULL && tss->errset != 0) {
+ tss->errset = 0;
+ err_str = tss->errstr;
+ }
+ return (err_str);
+}
+
+/* Given an address, return the mach_header for the image containing it
+ * or zero if the given address is not contained in any loaded images.
+ */
+static const struct mach_header *image_for_address(const void *address)
+{
+ unsigned long i;
+ unsigned long j;
+ unsigned long count = _dyld_image_count();
+ const struct mach_header *mh = 0;
+ struct load_command *lc = 0;
+ unsigned long addr = 0;
+ for (i = 0; i < count; i++)
+ {
+ addr = (unsigned long)address - _dyld_get_image_vmaddr_slide(i);
+ mh = _dyld_get_image_header(i);
+ if (mh)
+ {
+ lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
+ for (j = 0; j < mh->ncmds; j++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
+ {
+ if (LC_SEGMENT == lc->cmd &&
+ addr >= ((struct segment_command *)lc)->vmaddr &&
+ addr <
+ ((struct segment_command *)lc)->vmaddr + ((struct segment_command *)lc)->vmsize)
+ {
+ goto image_found;
+ }
+ }
+ }
+ mh = 0;
+ }
+ image_found:
+ return mh;
+}
+
+#if 0 /* unused */
+static int SDL_OSX_dladdr(const void * dl_restrict p, SDL_OSX_Dl_info * dl_restrict info)
+{
+/*
+ FIXME: USe the routine image_for_address.
+*/
+ unsigned long i;
+ unsigned long j;
+ unsigned long count = _dyld_image_count();
+ struct mach_header *mh = 0;
+ struct load_command *lc = 0;
+ unsigned long addr = NULL;
+ unsigned long table_off = (unsigned long)0;
+ int found = 0;
+ if (!info)
+ return 0;
+ dolock();
+ resetdlerror();
+ info->dli_fname = 0;
+ info->dli_fbase = 0;
+ info->dli_sname = 0;
+ info->dli_saddr = 0;
+/* Some of this was swiped from code posted by Douglas Davidson
+ * to darwin-development AT lists DOT apple DOT com and slightly modified
+ */
+ for (i = 0; i < count; i++)
+ {
+ addr = (unsigned long)p - _dyld_get_image_vmaddr_slide(i);
+ mh = _dyld_get_image_header(i);
+ if (mh)
+ {
+ lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
+ for (j = 0; j < mh->ncmds; j++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
+ {
+ if (LC_SEGMENT == lc->cmd &&
+ addr >= ((struct segment_command *)lc)->vmaddr &&
+ addr <
+ ((struct segment_command *)lc)->vmaddr + ((struct segment_command *)lc)->vmsize)
+ {
+ info->dli_fname = _dyld_get_image_name(i);
+ info->dli_fbase = (void *)mh;
+ found = 1;
+ break;
+ }
+ }
+ if (found)
+ break;
+ }
+ }
+ if (!found)
+ {
+ dounlock();
+ return 0;
+ }
+ lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
+ for (j = 0; j < mh->ncmds; j++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
+ {
+ if (LC_SEGMENT == lc->cmd)
+ {
+ if (!SDL_strcmp(((struct segment_command *)lc)->segname, "__LINKEDIT"))
+ break;
+ }
+ }
+ table_off =
+ ((unsigned long)((struct segment_command *)lc)->vmaddr) -
+ ((unsigned long)((struct segment_command *)lc)->fileoff) + _dyld_get_image_vmaddr_slide(i);
+ debug("table off %x", table_off);
+
+ lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
+ for (j = 0; j < mh->ncmds; j++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
+ {
+ if (LC_SYMTAB == lc->cmd)
+ {
+
+ struct nlist *symtable = (struct nlist *)(((struct symtab_command *)lc)->symoff + table_off);
+ unsigned long numsyms = ((struct symtab_command *)lc)->nsyms;
+ struct nlist *nearest = NULL;
+ unsigned long diff = 0xffffffff;
+ unsigned long strtable = (unsigned long)(((struct symtab_command *)lc)->stroff + table_off);
+ debug("symtable %x", symtable);
+ for (i = 0; i < numsyms; i++)
+ {
+ /* Ignore the following kinds of Symbols */
+ if ((!symtable->n_value) /* Undefined */
+ || (symtable->n_type >= N_PEXT) /* Debug symbol */
+ || (!(symtable->n_type & N_EXT)) /* Local Symbol */
+ )
+ {
+ symtable++;
+ continue;
+ }
+ if ((addr >= symtable->n_value) && (diff >= (symtable->n_value - addr)))
+ {
+ diff = (unsigned long)symtable->n_value - addr;
+ nearest = symtable;
+ }
+ symtable++;
+ }
+ if (nearest)
+ {
+ info->dli_saddr = nearest->n_value + ((void *)p - addr);
+ info->dli_sname = (char *)(strtable + nearest->n_un.n_strx);
+ }
+ }
+ }
+ dounlock();
+ return 1;
+}
+#endif
+
+/*
+ * Implement the dlfunc() interface, which behaves exactly the same as
+ * dlsym() except that it returns a function pointer instead of a data
+ * pointer. This can be used by applications to avoid compiler warnings
+ * about undefined behavior, and is intended as prior art for future
+ * POSIX standardization. This function requires that all pointer types
+ * have the same representation, which is true on all platforms FreeBSD
+ * runs on, but is not guaranteed by the C standard.
+ */
+#if 0
+static dlfunc_t SDL_OSX_dlfunc(void * dl_restrict handle, const char * dl_restrict symbol)
+{
+ union
+ {
+ void *d;
+ dlfunc_t f;
+ } rv;
+ int sym_len = SDL_strlen(symbol);
+ char *malloc_sym = NULL;
+ dolock();
+ malloc_sym = SDL_malloc(sym_len + 2);
+ if (malloc_sym)
+ {
+ SDL_snprintf(malloc_sym, sym_len+2, "_%s", symbol);
+ rv.d = dlsymIntern(handle, malloc_sym, 1);
+ SDL_free(malloc_sym);
+ }
+ else
+ {
+ error("Unable to allocate memory");
+ goto dlfuncerror;
+ }
+ dounlock();
+ return rv.f;
+ dlfuncerror:
+ dounlock();
+ return NULL;
+}
+#endif
+
+
+
+/* dlcompat ends, here's the SDL interface... --ryan. */
+
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+/* System dependent library loading routines */
+
+#include "SDL_loadso.h"
+
+void *SDL_LoadObject(const char *sofile)
+{
+ void *handle = SDL_OSX_dlopen(sofile, RTLD_NOW);
+ const char *loaderror = SDL_OSX_dlerror();
+ if ( handle == NULL ) {
+ SDL_SetError("Failed loading %s: %s", sofile, loaderror);
+ }
+ return(handle);
+}
+
+void *SDL_LoadFunction(void *handle, const char *name)
+{
+ void *symbol = SDL_OSX_dlsym(handle, name);
+ if ( symbol == NULL ) {
+ SDL_SetError("Failed loading %s: %s", name, SDL_OSX_dlerror());
+ }
+ return(symbol);
+}
+
+void SDL_UnloadObject(void *handle)
+{
+ if ( handle != NULL ) {
+ SDL_OSX_dlclose(handle);
+ }
+}
+
+#endif /* SDL_LOADSO_DLCOMPAT */
diff -r e49147870aac -r 14717b52abc0 src/loadso/macosx/SDL_sysloadso.c
--- a/src/loadso/macosx/SDL_sysloadso.c Mon May 01 06:58:33 2006 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,1404 +0,0 @@
-/*
- SDL - Simple DirectMedia Layer
- Copyright (C) 1997-2006 Sam Lantinga
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
- Sam Lantinga
- slouken@libsdl.org
-*/
-#include "SDL_config.h"
-
-#ifdef SDL_LOADSO_DLCOMPAT
-
-/* Please note that dlcompat apparently ships in current Mac OS X versions
- * as a system library that provides compatibility with the Unix "dlopen"
- * interface. In order to allow SDL to work on older OS X releases and also
- * not conflict with the system lib on newer versions, we include dlcompat
- * in SDL and change the symbols to prevent symbol clash with any existing
- * system libraries. --ryan.
- */
-
-/* here is the dlcompat license: */
-
-/*
-Copyright (c) 2002 Jorge Acereda &
- Peter O'Gorman
-
-Portions may be copyright others, see the AUTHORS file included with this
-distribution.
-
-Maintained by Peter O'Gorman
-
-Bug Reports and other queries should go to
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include "SDL_stdinc.h"
-
-/* Just playing to see if it would compile with the freebsd headers, it does,
- * but because of the different values for RTLD_LOCAL etc, it would break binary
- * compat... oh well
- */
-#ifndef __BSD_VISIBLE
-#define __BSD_VISIBLE 1
-#endif
-
-/*include "dlfcn.h"*/
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#if defined (__GNUC__) && __GNUC__ > 3
-#define dl_restrict __restrict
-#else
-#define dl_restrict
-#endif
-
-#ifndef _POSIX_SOURCE
-/*
- * Structure filled in by dladdr().
- */
-typedef struct SDL_OSX_dl_info {
- const char *dli_fname; /* Pathname of shared object */
- void *dli_fbase; /* Base address of shared object */
- const char *dli_sname; /* Name of nearest symbol */
- void *dli_saddr; /* Address of nearest symbol */
-} SDL_OSX_Dl_info;
-
-static int SDL_OSX_dladdr(const void * dl_restrict, SDL_OSX_Dl_info * dl_restrict);
-#endif /* ! _POSIX_SOURCE */
-
-static int SDL_OSX_dlclose(void * handle);
-static const char * SDL_OSX_dlerror(void);
-static void * SDL_OSX_dlopen(const char *path, int mode);
-static void * SDL_OSX_dlsym(void * dl_restrict handle, const char * dl_restrict symbol);
-
-#define RTLD_LAZY 0x1
-#define RTLD_NOW 0x2
-#define RTLD_LOCAL 0x4
-#define RTLD_GLOBAL 0x8
-
-#ifndef _POSIX_SOURCE
-#define RTLD_NOLOAD 0x10
-#define RTLD_NODELETE 0x80
-
-/*
- * Special handle arguments for SDL_OSX_dlsym().
- */
-#define RTLD_NEXT ((void *) -1) /* Search subsequent objects. */
-#define RTLD_DEFAULT ((void *) -2) /* Use default search algorithm. */
-#endif /* ! _POSIX_SOURCE */
-
-#ifdef __cplusplus
-}
-#endif
-
-#ifndef dl_restrict
-#define dl_restrict __restrict
-#endif
-/* This is not available on 10.1 */
-#ifndef LC_LOAD_WEAK_DYLIB
-#define LC_LOAD_WEAK_DYLIB (0x18 | LC_REQ_DYLD)
-#endif
-
-/* With this stuff here, this thing may actually compile/run on 10.0 systems
- * Not that I have a 10.0 system to test it on anylonger
- */
-#ifndef LC_REQ_DYLD
-#define LC_REQ_DYLD 0x80000000
-#endif
-#ifndef NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED
-#define NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED 0x4
-#endif
-#ifndef NSADDIMAGE_OPTION_RETURN_ON_ERROR
-#define NSADDIMAGE_OPTION_RETURN_ON_ERROR 0x1
-#endif
-#ifndef NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
-#define NSLOOKUPSYMBOLINIMAGE_OPTION_BIND 0x0
-#endif
-#ifndef NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR
-#define NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR 0x4
-#endif
-/* These symbols will be looked for in dyld */
-static const struct mach_header *(*dyld_NSAddImage) (const char *, unsigned long) = 0;
-static int (*dyld_NSIsSymbolNameDefinedInImage) (const struct mach_header *, const char *) = 0;
-static NSSymbol(*dyld_NSLookupSymbolInImage)
- (const struct mach_header *, const char *, unsigned long) = 0;
-
-/* Define this to make dlcompat reuse data block. This way in theory we save
- * a little bit of overhead. However we then couldn't correctly catch excess
- * calls to SDL_OSX_dlclose(). Hence we don't use this feature
- */
-#undef REUSE_STATUS
-
-/* Size of the internal error message buffer (used by dlerror()) */
-#define ERR_STR_LEN 251
-
-/* Maximum number of search paths supported by getSearchPath */
-#define MAX_SEARCH_PATHS 32
-
-
-#define MAGIC_DYLIB_OFI ((NSObjectFileImage) 'DYOF')
-#define MAGIC_DYLIB_MOD ((NSModule) 'DYMO')
-
-/* internal flags */
-#define DL_IN_LIST 0x01
-
-/* our mutex */
-static pthread_mutex_t dlcompat_mutex;
-/* Our thread specific storage
- */
-static pthread_key_t dlerror_key;
-
-struct dlthread
-{
- int lockcnt;
- unsigned char errset;
- char errstr[ERR_STR_LEN];
-};
-
-/* This is our central data structure. Whenever a module is loaded via
- * SDL_OSX_dlopen(), we create such a struct.
- */
-struct dlstatus
-{
- struct dlstatus *next; /* pointer to next element in the linked list */
- NSModule module;
- const struct mach_header *lib;
- int refs; /* reference count */
- int mode; /* mode in which this module was loaded */
- dev_t device;
- ino_t inode;
- int flags; /* Any internal flags we may need */
-};
-
-/* Head node of the dlstatus list */
-static struct dlstatus mainStatus = { 0, MAGIC_DYLIB_MOD, NULL, -1, RTLD_GLOBAL, 0, 0, 0 };
-static struct dlstatus *stqueue = &mainStatus;
-
-
-/* Storage for the last error message (used by dlerror()) */
-/* static char err_str[ERR_STR_LEN]; */
-/* static int err_filled = 0; */
-
-/* Prototypes to internal functions */
-static void debug(const char *fmt, ...);
-static void error(const char *str, ...);
-static const char *safegetenv(const char *s);
-static const char *searchList(void);
-static const char *getSearchPath(int i);
-static const char *getFullPath(int i, const char *file);
-static const struct stat *findFile(const char *file, const char **fullPath);
-static int isValidStatus(struct dlstatus *status);
-static inline int isFlagSet(int mode, int flag);
-static struct dlstatus *lookupStatus(const struct stat *sbuf);
-static void insertStatus(struct dlstatus *dls, const struct stat *sbuf);
-static int promoteLocalToGlobal(struct dlstatus *dls);
-static void *reference(struct dlstatus *dls, int mode);
-static void *dlsymIntern(struct dlstatus *dls, const char *symbol, int canSetError);
-static struct dlstatus *allocStatus(void);
-static struct dlstatus *loadModule(const char *path, const struct stat *sbuf, int mode);
-static NSSymbol *search_linked_libs(const struct mach_header *mh, const char *symbol);
-static const char *get_lib_name(const struct mach_header *mh);
-static const struct mach_header *get_mach_header_from_NSModule(NSModule * mod);
-static void dlcompat_init_func(void);
-static inline void dlcompat_init_check(void);
-static inline void dolock(void);
-static inline void dounlock(void);
-static void dlerrorfree(void *data);
-static void resetdlerror(void);
-static const struct mach_header *my_find_image(const char *name);
-static const struct mach_header *image_for_address(const void *address);
-static inline char *dyld_error_str(void);
-
-#if FINK_BUILD
-/* Two Global Functions */
-static void *dlsym_prepend_underscore(void *handle, const char *symbol);
-static void *dlsym_auto_underscore(void *handle, const char *symbol);
-
-/* And their _intern counterparts */
-static void *dlsym_prepend_underscore_intern(void *handle, const char *symbol);
-static void *dlsym_auto_underscore_intern(void *handle, const char *symbol);
-#endif
-
-/* Functions */
-
-static void debug(const char *fmt, ...)
-{
-#if DEBUG > 1
- va_list arg;
- va_start(arg, fmt);
- fprintf(stderr, "DLDEBUG: ");
- vfprintf(stderr, fmt, arg);
- fprintf(stderr, "\n");
- fflush(stderr);
- va_end(arg);
-#endif
-}
-
-static void error(const char *str, ...)
-{
- va_list arg;
- struct dlthread *tss;
- char * err_str;
- va_start(arg, str);
- tss = pthread_getspecific(dlerror_key);
- err_str = tss->errstr;
- SDL_strlcpy(err_str, "dlcompat: ", ERR_STR_LEN);
- vsnprintf(err_str + 10, ERR_STR_LEN - 10, str, arg);
- va_end(arg);
- debug("ERROR: %s\n", err_str);
- tss->errset = 1;
-}
-
-static void warning(const char *str)
-{
-#if DEBUG > 0
- fprintf(stderr, "WARNING: dlcompat: %s\n", str);
-#endif
-}
-
-static const char *safegetenv(const char *s)
-{
- const char *ss = SDL_getenv(s);
- return ss ? ss : "";
-}
-
-/* because this is only used for debugging and error reporting functions, we
- * don't really care about how elegant it is... it could use the load
- * commands to find the install name of the library, but...
- */
-static const char *get_lib_name(const struct mach_header *mh)
-{
- unsigned long count = _dyld_image_count();
- unsigned long i;
- const char *val = NULL;
- if (mh)
- {
- for (i = 0; i < count; i++)
- {
- if (mh == _dyld_get_image_header(i))
- {
- val = _dyld_get_image_name(i);
- break;
- }
- }
- }
- return val;
-}
-
-/* Returns the mach_header for the module bu going through all the loaded images
- * and finding the one with the same name as the module. There really ought to be
- * an api for doing this, would be faster, but there isn't one right now
- */
-static const struct mach_header *get_mach_header_from_NSModule(NSModule * mod)
-{
- const char *mod_name = NSNameOfModule(mod);
- struct mach_header *mh = NULL;
- unsigned long count = _dyld_image_count();
- unsigned long i;
- debug("Module name: %s", mod_name);
- for (i = 0; i < count; i++)
- {
- if (!SDL_strcmp(mod_name, _dyld_get_image_name(i)))
- {
- mh = _dyld_get_image_header(i);
- break;
- }
- }
- return mh;
-}
-
-
-/* Compute and return a list of all directories that we should search when
- * trying to locate a module. We first look at the values of LD_LIBRARY_PATH
- * and DYLD_LIBRARY_PATH, and then finally fall back to looking into
- * /usr/lib and /lib. Since both of the environments variables can contain a
- * list of colon seperated paths, we simply concat them and the two other paths
- * into one big string, which we then can easily parse.
- * Splitting this string into the actual path list is done by getSearchPath()
- */
-static const char *searchList()
-{
- size_t buf_size;
- static char *buf=NULL;
- const char *ldlp = safegetenv("LD_LIBRARY_PATH");
- const char *dyldlp = safegetenv("DYLD_LIBRARY_PATH");
- const char *stdpath = SDL_getenv("DYLD_FALLBACK_LIBRARY_PATH");
- if (!stdpath)
- stdpath = "/usr/local/lib:/lib:/usr/lib";
- if (!buf)
- {
- buf_size = SDL_strlen(ldlp) + SDL_strlen(dyldlp) + SDL_strlen(stdpath) + 4;
- buf = SDL_malloc(buf_size);
- SDL_snprintf(buf, buf_size, "%s%s%s%s%s%c", dyldlp, (dyldlp[0] ? ":" : ""), ldlp, (ldlp[0] ? ":" : ""),
- stdpath, '\0');
- }
- return buf;
-}
-
-/* Returns the ith search path from the list as computed by searchList() */
-static const char *getSearchPath(int i)
-{
- static const char *list = 0;
- static char **path = (char **)0;
- static int end = 0;
- static int numsize = MAX_SEARCH_PATHS;
- static char **tmp;
- /* So we can call SDL_free() in the "destructor" we use i=-1 to return the alloc'd array */
- if (i == -1)
- {
- return (const char*)path;
- }
- if (!path)
- {
- path = (char **)SDL_calloc(MAX_SEARCH_PATHS, sizeof(char **));
- }
- if (!list && !end)
- list = searchList();
- if (i >= (numsize))
- {
- debug("Increasing size for long PATH");
- tmp = (char **)SDL_calloc((MAX_SEARCH_PATHS + numsize), sizeof(char **));
- if (tmp)
- {
- SDL_memcpy(tmp, path, sizeof(char **) * numsize);
- SDL_free(path);
- path = tmp;
- numsize += MAX_SEARCH_PATHS;
- }
- else
- {
- return 0;
- }
- }
-
- while (!path[i] && !end)
- {
- path[i] = strsep((char **)&list, ":");
-
- if (path[i][0] == 0)
- path[i] = 0;
- end = (list == 0);
- }
- return path[i];
-}
-
-static const char *getFullPath(int i, const char *file)
-{
- static char buf[PATH_MAX];
- const char *path = getSearchPath(i);
- if (path)
- {
- SDL_snprintf(buf, PATH_MAX, "%s/%s", path, file);
- }
- return path ? buf : 0;
-}
-
-/* Given a file name, try to determine the full path for that file. Starts
- * its search in the current directory, and then tries all paths in the
- * search list in the order they are specified there.
- */
-static const struct stat *findFile(const char *file, const char **fullPath)
-{
- int i = 0;
- static struct stat sbuf;
- char *fileName;
- debug("finding file %s", file);
- *fullPath = file;
- if (0 == stat(file, &sbuf))
- return &sbuf;
- if (SDL_strchr(file, '/'))
- return 0; /* If the path had a / we don't look in env var places */
- fileName = NULL;
- if (!fileName)
- fileName = (char *)file;
- while ((*fullPath = getFullPath(i++, fileName)))
- {
- if (0 == stat(*fullPath, &sbuf))
- return &sbuf;
- }
- ;
- return 0;
-}
-
-/* Determine whether a given dlstatus is valid or not */
-static int isValidStatus(struct dlstatus *status)
-{
- /* Walk the list to verify status is contained in it */
- struct dlstatus *dls = stqueue;
- while (dls && status != dls)
- dls = dls->next;
- if (dls == 0)
- error("invalid handle");
- else if ((dls->module == 0) || (dls->refs == 0))
- error("handle to closed library");
- else
- return TRUE;
- return FALSE;
-}
-
-static inline int isFlagSet(int mode, int flag)
-{
- return (mode & flag) == flag;
-}
-
-static struct dlstatus *lookupStatus(const struct stat *sbuf)
-{
- struct dlstatus *dls = stqueue;
- debug("looking for status");
- while (dls && ( /* isFlagSet(dls->mode, RTLD_UNSHARED) */ 0
- || sbuf->st_dev != dls->device || sbuf->st_ino != dls->inode))
- dls = dls->next;
- return dls;
-}
-
-static void insertStatus(struct dlstatus *dls, const struct stat *sbuf)
-{
- debug("inserting status");
- dls->inode = sbuf->st_ino;
- dls->device = sbuf->st_dev;
- dls->refs = 0;
- dls->mode = 0;
- if ((dls->flags & DL_IN_LIST) == 0)
- {
- dls->next = stqueue;
- stqueue = dls;
- dls->flags |= DL_IN_LIST;
- }
-}
-
-static struct dlstatus *allocStatus()
-{
- struct dlstatus *dls;
-#ifdef REUSE_STATUS
- dls = stqueue;
- while (dls && dls->module)
- dls = dls->next;
- if (!dls)
-#endif
- dls = SDL_calloc(sizeof(*dls),1);
- return dls;
-}
-
-static int promoteLocalToGlobal(struct dlstatus *dls)
-{
- static int (*p) (NSModule module) = 0;
- debug("promoting");
- if (!p)
- _dyld_func_lookup("__dyld_NSMakePrivateModulePublic", (unsigned long *)&p);
- return (dls->module == MAGIC_DYLIB_MOD) || (p && p(dls->module));
-}
-
-static void *reference(struct dlstatus *dls, int mode)
-{
- if (dls)
- {
- if (dls->module == MAGIC_DYLIB_MOD && isFlagSet(mode, RTLD_LOCAL))
- {
- warning("trying to open a .dylib with RTLD_LOCAL");
- error("unable to open a .dylib with RTLD_LOCAL");
- return NULL;
- }
- if (isFlagSet(mode, RTLD_GLOBAL) &&
- !isFlagSet(dls->mode, RTLD_GLOBAL) && !promoteLocalToGlobal(dls))
- {
- error("unable to promote local module to global");
- return NULL;
- }
- dls->mode |= mode;
- dls->refs++;
- }
- else
- debug("reference called with NULL argument");
-
- return dls;
-}
-
-static const struct mach_header *my_find_image(const char *name)
-{
- const struct mach_header *mh = 0;
- const char *id = NULL;
- int i = _dyld_image_count();
- int j;
- mh = (struct mach_header *)
- dyld_NSAddImage(name, NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED |
- NSADDIMAGE_OPTION_RETURN_ON_ERROR);
- if (!mh)
- {
- for (j = 0; j < i; j++)
- {
- id = _dyld_get_image_name(j);
- if (!SDL_strcmp(id, name))
- {
- mh = _dyld_get_image_header(j);
- break;
- }
- }
- }
- return mh;
-}
-
-/*
- * dyld adds libraries by first adding the directly dependant libraries in link order, and
- * then adding the dependencies for those libraries, so we should do the same... but we don't
- * bother adding the extra dependencies, if the symbols are neither in the loaded image nor
- * any of it's direct dependencies, then it probably isn't there.
- */
-static NSSymbol *search_linked_libs(const struct mach_header * mh, const char *symbol)
-{
- unsigned int n;
- struct load_command *lc = 0;
- struct mach_header *wh;
- NSSymbol *nssym = 0;
- if (dyld_NSAddImage && dyld_NSIsSymbolNameDefinedInImage && dyld_NSLookupSymbolInImage)
- {
- lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
- for (n = 0; n < mh->ncmds; n++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
- {
- if ((LC_LOAD_DYLIB == lc->cmd) || (LC_LOAD_WEAK_DYLIB == lc->cmd))
- {
- if ((wh = (struct mach_header *)
- my_find_image((char *)(((struct dylib_command *)lc)->dylib.name.offset +
- (char *)lc))))
- {
- if (dyld_NSIsSymbolNameDefinedInImage(wh, symbol))
- {
- nssym = dyld_NSLookupSymbolInImage(wh,
- symbol,
- NSLOOKUPSYMBOLINIMAGE_OPTION_BIND |
- NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
- break;
- }
- }
- }
- }
- if ((!nssym) && NSIsSymbolNameDefined(symbol))
- {
- /* I've never seen this debug message...*/
- debug("Symbol \"%s\" is defined but was not found", symbol);
- }
- }
- return nssym;
-}
-
-/* Up to the caller to SDL_free() returned string */
-static inline char *dyld_error_str()
-{
- NSLinkEditErrors dylder;
- int dylderno;
- const char *dylderrstr;
- const char *dyldfile;
- char* retStr = NULL;
- NSLinkEditError(&dylder, &dylderno, &dyldfile, &dylderrstr);
- if (dylderrstr && *dylderrstr)
- {
- retStr = SDL_strdup(dylderrstr);
- }
- return retStr;
-}
-
-static void *dlsymIntern(struct dlstatus *dls, const char *symbol, int canSetError)
-{
- NSSymbol *nssym = 0;
-#ifdef __GCC__
- void *caller = __builtin_return_address(1); /* Be *very* careful about inlining */
-#else
- void *caller = NULL;
-#endif
- const struct mach_header *caller_mh = 0;
- char *savedErrorStr = NULL;
- resetdlerror();
-#ifndef RTLD_SELF
-#define RTLD_SELF ((void *) -3)
-#endif
- if (NULL == dls)
- dls = RTLD_SELF;
- if ((RTLD_NEXT == dls) || (RTLD_SELF == dls))
- {
- if (dyld_NSIsSymbolNameDefinedInImage && dyld_NSLookupSymbolInImage && caller)
- {
- caller_mh = image_for_address(caller);
- if (RTLD_SELF == dls)
- {
- /* FIXME: We should be using the NSModule api, if SELF is an MH_BUNDLE
- * But it appears to work anyway, and looking at the code in dyld_libfuncs.c
- * this is acceptable.
- */
- if (dyld_NSIsSymbolNameDefinedInImage(caller_mh, symbol))
- {
- nssym = dyld_NSLookupSymbolInImage(caller_mh,
- symbol,
- NSLOOKUPSYMBOLINIMAGE_OPTION_BIND |
- NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
- }
- }
- if (!nssym)
- {
- if (RTLD_SELF == dls)
- savedErrorStr = dyld_error_str();
- nssym = search_linked_libs(caller_mh, symbol);
- }
- }
- else
- {
- if (canSetError)
- error("RTLD_SELF and RTLD_NEXT are not supported");
- return NULL;
- }
- }
- if (!nssym)
- {
-
- if (RTLD_DEFAULT == dls)
- {
- dls = &mainStatus;
- }
- if (!isValidStatus(dls))
- return NULL;
-
- if (dls->module != MAGIC_DYLIB_MOD)
- {
- nssym = NSLookupSymbolInModule(dls->module, symbol);
- if (!nssym && NSIsSymbolNameDefined(symbol))
- {
- debug("Searching dependencies");
- savedErrorStr = dyld_error_str();
- nssym = search_linked_libs(get_mach_header_from_NSModule(dls->module), symbol);
- }
- }
- else if (dls->lib && dyld_NSIsSymbolNameDefinedInImage && dyld_NSLookupSymbolInImage)
- {
- if (dyld_NSIsSymbolNameDefinedInImage(dls->lib, symbol))
- {
- nssym = dyld_NSLookupSymbolInImage(dls->lib,
- symbol,
- NSLOOKUPSYMBOLINIMAGE_OPTION_BIND |
- NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
- }
- else if (NSIsSymbolNameDefined(symbol))
- {
- debug("Searching dependencies");
- savedErrorStr = dyld_error_str();
- nssym = search_linked_libs(dls->lib, symbol);
- }
- }
- else if (dls->module == MAGIC_DYLIB_MOD)
- {
- /* Global context, use NSLookupAndBindSymbol */
- if (NSIsSymbolNameDefined(symbol))
- {
- /* There doesn't seem to be a return on error option for this call???
- this is potentially broken, if binding fails, it will improperly
- exit the application. */
- nssym = NSLookupAndBindSymbol(symbol);
- }
- else
- {
- if (savedErrorStr)
- SDL_free(savedErrorStr);
- savedErrorStr = SDL_malloc(256);
- SDL_snprintf(savedErrorStr, 256, "Symbol \"%s\" not in global context",symbol);
- }
- }
- }
- /* Error reporting */
- if (!nssym)
- {
- if (!savedErrorStr || !SDL_strlen(savedErrorStr))
- {
- if (savedErrorStr)
- SDL_free(savedErrorStr);
- savedErrorStr = SDL_malloc(256);
- SDL_snprintf(savedErrorStr, 256,"Symbol \"%s\" not found",symbol);
- }
- if (canSetError)
- {
- error(savedErrorStr);
- }
- else
- {
- debug(savedErrorStr);
- }
- if (savedErrorStr)
- SDL_free(savedErrorStr);
- return NULL;
- }
- return NSAddressOfSymbol(nssym);
-}
-
-static struct dlstatus *loadModule(const char *path, const struct stat *sbuf, int mode)
-{
- NSObjectFileImage ofi = 0;
- NSObjectFileImageReturnCode ofirc;
- struct dlstatus *dls;
- NSLinkEditErrors ler;
- int lerno;
- const char *errstr;
- const char *file;
- void (*init) (void);
-
- ofirc = NSCreateObjectFileImageFromFile(path, &ofi);
- switch (ofirc)
- {
- case NSObjectFileImageSuccess:
- break;
- case NSObjectFileImageInappropriateFile:
- if (dyld_NSAddImage && dyld_NSIsSymbolNameDefinedInImage && dyld_NSLookupSymbolInImage)
- {
- if (isFlagSet(mode, RTLD_LOCAL))
- {
- warning("trying to open a .dylib with RTLD_LOCAL");
- error("unable to open this file with RTLD_LOCAL");
- return NULL;
- }
- }
- else
- {
- error("opening this file is unsupported on this system");
- return NULL;
- }
- break;
- case NSObjectFileImageFailure:
- error("object file setup failure");
- return NULL;
- case NSObjectFileImageArch:
- error("no object for this architecture");
- return NULL;
- case NSObjectFileImageFormat:
- error("bad object file format");
- return NULL;
- case NSObjectFileImageAccess:
- error("can't read object file");
- return NULL;
- default:
- error("unknown error from NSCreateObjectFileImageFromFile()");
- return NULL;
- }
- dls = lookupStatus(sbuf);
- if (!dls)
- {
- dls = allocStatus();
- }
- if (!dls)
- {
- error("unable to allocate memory");
- return NULL;
- }
- // dls->lib = 0;
- if (ofirc == NSObjectFileImageInappropriateFile)
- {
- if ((dls->lib = dyld_NSAddImage(path, NSADDIMAGE_OPTION_RETURN_ON_ERROR)))
- {
- debug("Dynamic lib loaded at %ld", dls->lib);
- ofi = MAGIC_DYLIB_OFI;
- dls->module = MAGIC_DYLIB_MOD;
- ofirc = NSObjectFileImageSuccess;
- /* Although it is possible with a bit of work to modify this so it works and
- functions with RTLD_NOW, I don't deem it necessary at the moment */
- }
- if (!(dls->module))
- {
- NSLinkEditError(&ler, &lerno, &file, &errstr);
- if (!errstr || (!SDL_strlen(errstr)))
- error("Can't open this file type");
- else
- error(errstr);
- if ((dls->flags & DL_IN_LIST) == 0)
- {
- SDL_free(dls);
- }
- return NULL;
- }
- }
- else
- {
- dls->module = NSLinkModule(ofi, path,
- NSLINKMODULE_OPTION_RETURN_ON_ERROR |
- NSLINKMODULE_OPTION_PRIVATE |
- (isFlagSet(mode, RTLD_NOW) ? NSLINKMODULE_OPTION_BINDNOW : 0));
- NSDestroyObjectFileImage(ofi);
- if (dls->module)
- {
- dls->lib = get_mach_header_from_NSModule(dls->module);
- }
- }
- if (!dls->module)
- {
- NSLinkEditError(&ler, &lerno, &file, &errstr);
- if ((dls->flags & DL_IN_LIST) == 0)
- {
- SDL_free(dls);
- }
- error(errstr);
- return NULL;
- }
-
- insertStatus(dls, sbuf);
- dls = reference(dls, mode);
- if ((init = dlsymIntern(dls, "__init", 0)))
- {
- debug("calling _init()");
- init();
- }
- return dls;
-}
-
-inline static void dlcompat_init_check(void)
-{
- static pthread_mutex_t l = PTHREAD_MUTEX_INITIALIZER;
- static int init_done = 0;
-
- pthread_mutex_lock(&l);
- if (!init_done) {
- dlcompat_init_func();
- init_done = 1;
- }
- pthread_mutex_unlock(&l);
-}
-
-static void dlcompat_init_func(void)
-{
- _dyld_func_lookup("__dyld_NSAddImage", (unsigned long *)&dyld_NSAddImage);
- _dyld_func_lookup("__dyld_NSIsSymbolNameDefinedInImage",
- (unsigned long *)&dyld_NSIsSymbolNameDefinedInImage);
- _dyld_func_lookup("__dyld_NSLookupSymbolInImage", (unsigned long *)&dyld_NSLookupSymbolInImage);
- if (pthread_mutex_init(&dlcompat_mutex, NULL))
- exit(1);
- if (pthread_key_create(&dlerror_key, &dlerrorfree))
- exit(1);
-}
-
-static void resetdlerror()
-{
- struct dlthread *tss;
- tss = pthread_getspecific(dlerror_key);
- tss->errset = 0;
-}
-
-static void dlerrorfree(void *data)
-{
- SDL_free(data);
-}
-
-/* We kind of want a recursive lock here, but meet a little trouble
- * because they are not available pre OS X 10.2, so we fake it
- * using thread specific storage to keep a lock count
- */
-static inline void dolock(void)
-{
- int err = 0;
- struct dlthread *tss;
- dlcompat_init_check();
- tss = pthread_getspecific(dlerror_key);
- if (!tss)
- {
- tss = SDL_malloc(sizeof(struct dlthread));
- tss->lockcnt = 0;
- tss->errset = 0;
- if (pthread_setspecific(dlerror_key, tss))
- {
- fprintf(stderr,"dlcompat: pthread_setspecific failed\n");
- exit(1);
- }
- }
- if (!tss->lockcnt)
- err = pthread_mutex_lock(&dlcompat_mutex);
- tss->lockcnt = tss->lockcnt +1;
- if (err)
- exit(err);
-}
-
-static inline void dounlock(void)
-{
- int err = 0;
- struct dlthread *tss;
- tss = pthread_getspecific(dlerror_key);
- tss->lockcnt = tss->lockcnt -1;
- if (!tss->lockcnt)
- err = pthread_mutex_unlock(&dlcompat_mutex);
- if (err)
- exit(err);
-}
-
-static void *SDL_OSX_dlopen(const char *path, int mode)
-{
- const struct stat *sbuf;
- struct dlstatus *dls;
- const char *fullPath;
-
- dolock();
- resetdlerror();
- if (!path)
- {
- dls = &mainStatus;
- goto dlopenok;
- }
- if (!(sbuf = findFile(path, &fullPath)))
- {
- error("file \"%s\" not found", path);
- goto dlopenerror;
- }
- /* Now checks that it hasn't been closed already */
- if ((dls = lookupStatus(sbuf)) && (dls->refs > 0))
- {
- /* debug("status found"); */
- dls = reference(dls, mode);
- goto dlopenok;
- }
-#ifdef RTLD_NOLOAD
- if (isFlagSet(mode, RTLD_NOLOAD))
- {
- error("no existing handle and RTLD_NOLOAD specified");
- goto dlopenerror;
- }
-#endif
- if (isFlagSet(mode, RTLD_LAZY) && isFlagSet(mode, RTLD_NOW))
- {
- error("how can I load something both RTLD_LAZY and RTLD_NOW?");
- goto dlopenerror;
- }
- dls = loadModule(fullPath, sbuf, mode);
-
- dlopenok:
- dounlock();
- return (void *)dls;
- dlopenerror:
- dounlock();
- return NULL;
-}
-
-#if !FINK_BUILD
-static void *SDL_OSX_dlsym(void * dl_restrict handle, const char * dl_restrict symbol)
-{
- int sym_len = SDL_strlen(symbol);
- void *value = NULL;
- char *malloc_sym = NULL;
- dolock();
- malloc_sym = SDL_malloc(sym_len + 2);
- if (malloc_sym)
- {
- SDL_snprintf(malloc_sym, sym_len+2, "_%s", symbol);
- value = dlsymIntern(handle, malloc_sym, 1);
- SDL_free(malloc_sym);
- }
- else
- {
- error("Unable to allocate memory");
- goto dlsymerror;
- }
- dounlock();
- return value;
- dlsymerror:
- dounlock();
- return NULL;
-}
-#endif
-
-#if FINK_BUILD
-
-static void *dlsym_prepend_underscore(void *handle, const char *symbol)
-{
- void *answer;
- dolock();
- answer = dlsym_prepend_underscore_intern(handle, symbol);
- dounlock();
- return answer;
-}
-
-static void *dlsym_prepend_underscore_intern(void *handle, const char *symbol)
-{
-/*
- * A quick and easy way for porting packages which call dlsym(handle,"sym")
- * If the porter adds -Ddlsym=dlsym_prepend_underscore to the CFLAGS then
- * this function will be called, and will add the required underscore.
- *
- * Note that I haven't figured out yet which should be "standard", prepend
- * the underscore always, or not at all. These global functions need to go away
- * for opendarwin.
- */
- int sym_len = SDL_strlen(symbol);
- void *value = NULL;
- char *malloc_sym = NULL;
- malloc_sym = SDL_malloc(sym_len + 2);
- if (malloc_sym)
- {
- SDL_snprintf(malloc_sym, sym_len+2, "_%s", symbol);
- value = dlsymIntern(handle, malloc_sym, 1);
- SDL_free(malloc_sym);
- }
- else
- {
- error("Unable to allocate memory");
- }
- return value;
-}
-
-static void *dlsym_auto_underscore(void *handle, const char *symbol)
-{
- void *answer;
- dolock();
- answer = dlsym_auto_underscore_intern(handle, symbol);
- dounlock();
- return answer;
-
-}
-static void *dlsym_auto_underscore_intern(void *handle, const char *symbol)
-{
- struct dlstatus *dls = handle;
- void *addr = 0;
- addr = dlsymIntern(dls, symbol, 0);
- if (!addr)
- addr = dlsym_prepend_underscore_intern(handle, symbol);
- return addr;
-}
-
-
-static void *SDL_OSX_dlsym(void * dl_restrict handle, const char * dl_restrict symbol)
-{
- struct dlstatus *dls = handle;
- void *addr = 0;
- dolock();
- addr = dlsymIntern(dls, symbol, 1);
- dounlock();
- return addr;
-}
-#endif
-
-static int SDL_OSX_dlclose(void *handle)
-{
- struct dlstatus *dls = handle;
- dolock();
- resetdlerror();
- if (!isValidStatus(dls))
- {
- goto dlcloseerror;
- }
- if (dls->module == MAGIC_DYLIB_MOD)
- {
- const char *name;
- if (!dls->lib)
- {
- name = "global context";
- }
- else
- {
- name = get_lib_name(dls->lib);
- }
- warning("trying to close a .dylib!");
- error("Not closing \"%s\" - dynamic libraries cannot be closed", name);
- goto dlcloseerror;
- }
- if (!dls->module)
- {
- error("module already closed");
- goto dlcloseerror;
- }
-
- if (dls->refs == 1)
- {
- unsigned long options = 0;
- void (*fini) (void);
- if ((fini = dlsymIntern(dls, "__fini", 0)))
- {
- debug("calling _fini()");
- fini();
- }
- options |= NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES;
-#ifdef RTLD_NODELETE
- if (isFlagSet(dls->mode, RTLD_NODELETE))
- options |= NSUNLINKMODULE_OPTION_KEEP_MEMORY_MAPPED;
-#endif
- if (!NSUnLinkModule(dls->module, options))
- {
- error("unable to unlink module");
- goto dlcloseerror;
- }
- dls->refs--;
- dls->module = 0;
- /* Note: the dlstatus struct dls is neither removed from the list
- * nor is the memory it occupies freed. This shouldn't pose a
- * problem in mostly all cases, though.
- */
- }
- dounlock();
- return 0;
- dlcloseerror:
- dounlock();
- return 1;
-}
-
-static const char *SDL_OSX_dlerror(void)
-{
- struct dlthread *tss;
- const char * err_str = NULL;
- dlcompat_init_check();
- tss = pthread_getspecific(dlerror_key);
- if (tss != NULL && tss->errset != 0) {
- tss->errset = 0;
- err_str = tss->errstr;
- }
- return (err_str);
-}
-
-/* Given an address, return the mach_header for the image containing it
- * or zero if the given address is not contained in any loaded images.
- */
-static const struct mach_header *image_for_address(const void *address)
-{
- unsigned long i;
- unsigned long j;
- unsigned long count = _dyld_image_count();
- struct mach_header *mh = 0;
- struct load_command *lc = 0;
- unsigned long addr = NULL;
- for (i = 0; i < count; i++)
- {
- addr = (unsigned long)address - _dyld_get_image_vmaddr_slide(i);
- mh = _dyld_get_image_header(i);
- if (mh)
- {
- lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
- for (j = 0; j < mh->ncmds; j++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
- {
- if (LC_SEGMENT == lc->cmd &&
- addr >= ((struct segment_command *)lc)->vmaddr &&
- addr <
- ((struct segment_command *)lc)->vmaddr + ((struct segment_command *)lc)->vmsize)
- {
- goto image_found;
- }
- }
- }
- mh = 0;
- }
- image_found:
- return mh;
-}
-
-static int SDL_OSX_dladdr(const void * dl_restrict p, SDL_OSX_Dl_info * dl_restrict info)
-{
-/*
- FIXME: USe the routine image_for_address.
-*/
- unsigned long i;
- unsigned long j;
- unsigned long count = _dyld_image_count();
- struct mach_header *mh = 0;
- struct load_command *lc = 0;
- unsigned long addr = NULL;
- unsigned long table_off = (unsigned long)0;
- int found = 0;
- if (!info)
- return 0;
- dolock();
- resetdlerror();
- info->dli_fname = 0;
- info->dli_fbase = 0;
- info->dli_sname = 0;
- info->dli_saddr = 0;
-/* Some of this was swiped from code posted by Douglas Davidson
- * to darwin-development AT lists DOT apple DOT com and slightly modified
- */
- for (i = 0; i < count; i++)
- {
- addr = (unsigned long)p - _dyld_get_image_vmaddr_slide(i);
- mh = _dyld_get_image_header(i);
- if (mh)
- {
- lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
- for (j = 0; j < mh->ncmds; j++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
- {
- if (LC_SEGMENT == lc->cmd &&
- addr >= ((struct segment_command *)lc)->vmaddr &&
- addr <
- ((struct segment_command *)lc)->vmaddr + ((struct segment_command *)lc)->vmsize)
- {
- info->dli_fname = _dyld_get_image_name(i);
- info->dli_fbase = (void *)mh;
- found = 1;
- break;
- }
- }
- if (found)
- break;
- }
- }
- if (!found)
- {
- dounlock();
- return 0;
- }
- lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
- for (j = 0; j < mh->ncmds; j++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
- {
- if (LC_SEGMENT == lc->cmd)
- {
- if (!SDL_strcmp(((struct segment_command *)lc)->segname, "__LINKEDIT"))
- break;
- }
- }
- table_off =
- ((unsigned long)((struct segment_command *)lc)->vmaddr) -
- ((unsigned long)((struct segment_command *)lc)->fileoff) + _dyld_get_image_vmaddr_slide(i);
- debug("table off %x", table_off);
-
- lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
- for (j = 0; j < mh->ncmds; j++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
- {
- if (LC_SYMTAB == lc->cmd)
- {
-
- struct nlist *symtable = (struct nlist *)(((struct symtab_command *)lc)->symoff + table_off);
- unsigned long numsyms = ((struct symtab_command *)lc)->nsyms;
- struct nlist *nearest = NULL;
- unsigned long diff = 0xffffffff;
- unsigned long strtable = (unsigned long)(((struct symtab_command *)lc)->stroff + table_off);
- debug("symtable %x", symtable);
- for (i = 0; i < numsyms; i++)
- {
- /* Ignore the following kinds of Symbols */
- if ((!symtable->n_value) /* Undefined */
- || (symtable->n_type >= N_PEXT) /* Debug symbol */
- || (!(symtable->n_type & N_EXT)) /* Local Symbol */
- )
- {
- symtable++;
- continue;
- }
- if ((addr >= symtable->n_value) && (diff >= (symtable->n_value - addr)))
- {
- diff = (unsigned long)symtable->n_value - addr;
- nearest = symtable;
- }
- symtable++;
- }
- if (nearest)
- {
- info->dli_saddr = nearest->n_value + ((void *)p - addr);
- info->dli_sname = (char *)(strtable + nearest->n_un.n_strx);
- }
- }
- }
- dounlock();
- return 1;
-}
-
-
-/*
- * Implement the dlfunc() interface, which behaves exactly the same as
- * dlsym() except that it returns a function pointer instead of a data
- * pointer. This can be used by applications to avoid compiler warnings
- * about undefined behavior, and is intended as prior art for future
- * POSIX standardization. This function requires that all pointer types
- * have the same representation, which is true on all platforms FreeBSD
- * runs on, but is not guaranteed by the C standard.
- */
-#if 0
-static dlfunc_t SDL_OSX_dlfunc(void * dl_restrict handle, const char * dl_restrict symbol)
-{
- union
- {
- void *d;
- dlfunc_t f;
- } rv;
- int sym_len = SDL_strlen(symbol);
- char *malloc_sym = NULL;
- dolock();
- malloc_sym = SDL_malloc(sym_len + 2);
- if (malloc_sym)
- {
- SDL_snprintf(malloc_sym, sym_len+2, "_%s", symbol);
- rv.d = dlsymIntern(handle, malloc_sym, 1);
- SDL_free(malloc_sym);
- }
- else
- {
- error("Unable to allocate memory");
- goto dlfuncerror;
- }
- dounlock();
- return rv.f;
- dlfuncerror:
- dounlock();
- return NULL;
-}
-#endif
-
-
-
-/* dlcompat ends, here's the SDL interface... --ryan. */
-
-
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-/* System dependent library loading routines */
-
-#include "SDL_loadso.h"
-
-void *SDL_LoadObject(const char *sofile)
-{
- void *handle = SDL_OSX_dlopen(sofile, RTLD_NOW);
- const char *loaderror = SDL_OSX_dlerror();
- if ( handle == NULL ) {
- SDL_SetError("Failed loading %s: %s", sofile, loaderror);
- }
- return(handle);
-}
-
-void *SDL_LoadFunction(void *handle, const char *name)
-{
- void *symbol = SDL_OSX_dlsym(handle, name);
- if ( symbol == NULL ) {
- SDL_SetError("Failed loading %s: %s", name, SDL_OSX_dlerror());
- }
- return(symbol);
-}
-
-void SDL_UnloadObject(void *handle)
-{
- if ( handle != NULL ) {
- SDL_OSX_dlclose(handle);
- }
-}
-
-#endif /* SDL_LOADSO_DLCOMPAT */
diff -r e49147870aac -r 14717b52abc0 src/main/dummy/SDL_dummy_main.c
--- a/src/main/dummy/SDL_dummy_main.c Mon May 01 06:58:33 2006 +0000
+++ b/src/main/dummy/SDL_dummy_main.c Wed May 17 08:18:28 2006 +0000
@@ -9,5 +9,5 @@
return(SDL_main(argc, argv));
}
#else
-/* Nothing to do on this platform */;
+/* Nothing to do on this platform */
#endif
diff -r e49147870aac -r 14717b52abc0 src/main/macosx/SDLMain.m
--- a/src/main/macosx/SDLMain.m Mon May 01 06:58:33 2006 +0000
+++ b/src/main/macosx/SDLMain.m Wed May 17 08:18:28 2006 +0000
@@ -252,19 +252,24 @@
*/
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
{
+ const char *temparg;
+ size_t arglen;
+ char *arg;
+ char **newargv;
+
if (!gFinderLaunch) /* MacOS is passing command line args. */
return FALSE;
if (gCalledAppMainline) /* app has started, ignore this document. */
return FALSE;
- const char *temparg = [filename UTF8String];
- size_t arglen = SDL_strlen(temparg) + 1;
- char *arg = (char *) SDL_malloc(arglen);
+ temparg = [filename UTF8String];
+ arglen = SDL_strlen(temparg) + 1;
+ arg = (char *) SDL_malloc(arglen);
if (arg == NULL)
return FALSE;
- char **newargv = (char **) realloc(gArgv, sizeof (char *) * (gArgc + 2));
+ newargv = (char **) realloc(gArgv, sizeof (char *) * (gArgc + 2));
if (newargv == NULL)
{
SDL_free(arg);
@@ -376,3 +381,4 @@
#endif
return 0;
}
+
diff -r e49147870aac -r 14717b52abc0 src/main/win32/SDL_win32_main.c
--- a/src/main/win32/SDL_win32_main.c Mon May 01 06:58:33 2006 +0000
+++ b/src/main/win32/SDL_win32_main.c Wed May 17 08:18:28 2006 +0000
@@ -121,8 +121,15 @@
return FALSE;
}
+/* SDL_Quit() shouldn't be used with atexit() directly because
+ calling conventions may differ... */
+static void cleanup(void)
+{
+ SDL_Quit();
+}
+
/* Remove the output files if there was no output written */
-static void __cdecl cleanup_output(void)
+static void cleanup_output(void)
{
#ifndef NO_STDIO_REDIRECT
FILE *file;
@@ -188,7 +195,7 @@
if ( bufp == NULL ) {
return OutOfMemory();
}
- SDL_strlcpy(bufp, appname, n);
+ SDL_strlcpy(bufp, appname, n+1);
appname = bufp;
/* Load SDL dynamic link library */
@@ -197,7 +204,7 @@
return(FALSE);
}
atexit(cleanup_output);
- atexit(SDL_Quit);
+ atexit(cleanup);
/* Sam:
We still need to pass in the application handle so that
diff -r e49147870aac -r 14717b52abc0 src/stdlib/SDL_string.c
--- a/src/stdlib/SDL_string.c Mon May 01 06:58:33 2006 +0000
+++ b/src/stdlib/SDL_string.c Wed May 17 08:18:28 2006 +0000
@@ -985,10 +985,10 @@
SDL_ltoa(value, num, radix);
size = SDL_strlen(num);
- if ( size > maxlen ) {
- size = maxlen;
+ if ( size >= maxlen ) {
+ size = maxlen-1;
}
- SDL_strlcpy(text, num, size);
+ SDL_strlcpy(text, num, size+1);
return size;
}
@@ -999,10 +999,10 @@
SDL_ultoa(value, num, radix);
size = SDL_strlen(num);
- if ( size > maxlen ) {
- size = maxlen;
+ if ( size >= maxlen ) {
+ size = maxlen-1;
}
- SDL_strlcpy(text, num, size);
+ SDL_strlcpy(text, num, size+1);
return size;
}
@@ -1014,10 +1014,10 @@
SDL_lltoa(value, num, radix);
size = SDL_strlen(num);
- if ( size > maxlen ) {
- size = maxlen;
+ if ( size >= maxlen ) {
+ size = maxlen-1;
}
- SDL_strlcpy(text, num, size);
+ SDL_strlcpy(text, num, size+1);
return size;
}
@@ -1028,10 +1028,10 @@
SDL_ulltoa(value, num, radix);
size = SDL_strlen(num);
- if ( size > maxlen ) {
- size = maxlen;
+ if ( size >= maxlen ) {
+ size = maxlen-1;
}
- SDL_strlcpy(text, num, size);
+ SDL_strlcpy(text, num, size+1);
return size;
}
@@ -1101,6 +1101,9 @@
++fmt;
/* FIXME: implement more of the format specifiers */
+ while ( *fmt == '.' || (*fmt >= '0' && *fmt <= '9') ) {
+ ++fmt;
+ }
while (!done) {
switch(*fmt) {
case '%':
diff -r e49147870aac -r 14717b52abc0 src/thread/SDL_thread.c
--- a/src/thread/SDL_thread.c Mon May 01 06:58:33 2006 +0000
+++ b/src/thread/SDL_thread.c Wed May 17 08:18:28 2006 +0000
@@ -168,7 +168,7 @@
/* Arguments and callback to setup and run the user thread function */
typedef struct {
- int (*func)(void *);
+ int (SDLCALL *func)(void *);
void *data;
SDL_Thread *info;
SDL_sem *wait;
@@ -177,7 +177,7 @@
void SDL_RunThread(void *data)
{
thread_args *args;
- int (*userfunc)(void *);
+ int (SDLCALL *userfunc)(void *);
void *userdata;
int *statusloc;
@@ -204,9 +204,9 @@
#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
#undef SDL_CreateThread
-DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(int (*fn)(void *), void *data, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread)
+DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(int (SDLCALL *fn)(void *), void *data, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread)
#else
-DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(int (*fn)(void *), void *data)
+DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(int (SDLCALL *fn)(void *), void *data)
#endif
{
SDL_Thread *thread;
diff -r e49147870aac -r 14717b52abc0 src/thread/pth/SDL_systhread.c
--- a/src/thread/pth/SDL_systhread.c Mon May 01 06:58:33 2006 +0000
+++ b/src/thread/pth/SDL_systhread.c Wed May 17 08:18:28 2006 +0000
@@ -27,12 +27,13 @@
* Patrice Mandin
*/
-#include "SDL_thread.h"
-#include "../SDL_systhread.h"
-
#include
#include
+#include "SDL_thread.h"
+#include "../SDL_thread_c.h"
+#include "../SDL_systhread.h"
+
/* List of signals to mask in the subthreads */
static int sig_list[] = {
SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGWINCH,
diff -r e49147870aac -r 14717b52abc0 src/thread/win32/SDL_systhread.c
--- a/src/thread/win32/SDL_systhread.c Mon May 01 06:58:33 2006 +0000
+++ b/src/thread/win32/SDL_systhread.c Wed May 17 08:18:28 2006 +0000
@@ -41,6 +41,15 @@
unsigned (__stdcall *func)(void *), void *arg,
unsigned, unsigned *threadID);
typedef void (__cdecl *pfnSDL_CurrentEndThread)(unsigned code);
+#elif defined(__WATCOMC__)
+/* This is for Watcom targets except OS2 */
+#if __WATCOMC__ < 1240
+#define __watcall
+#endif
+typedef unsigned long (__watcall *pfnSDL_CurrentBeginThread) (void *, unsigned,
+ unsigned (__stdcall *func)(void *), void *arg,
+ unsigned, unsigned *threadID);
+typedef void (__watcall *pfnSDL_CurrentEndThread)(unsigned code);
#else
typedef uintptr_t (__cdecl *pfnSDL_CurrentBeginThread) (void *, unsigned,
unsigned (__stdcall *func)(void *), void *arg,
diff -r e49147870aac -r 14717b52abc0 src/timer/SDL_timer.c
--- a/src/timer/SDL_timer.c Mon May 01 06:58:33 2006 +0000
+++ b/src/timer/SDL_timer.c Wed May 17 08:18:28 2006 +0000
@@ -95,6 +95,7 @@
}
if ( SDL_timer_threaded ) {
SDL_DestroyMutex(SDL_timer_mutex);
+ SDL_timer_mutex = NULL;
}
SDL_timer_started = 0;
SDL_timer_threaded = 0;
diff -r e49147870aac -r 14717b52abc0 src/timer/macos/FastTimes.c
--- a/src/timer/macos/FastTimes.c Mon May 01 06:58:33 2006 +0000
+++ b/src/timer/macos/FastTimes.c Wed May 17 08:18:28 2006 +0000
@@ -19,6 +19,11 @@
#include "FastTimes.h"
+#ifdef TARGET_CPU_PPC
+#undef GENERATINGPOWERPC /* stop whining */
+#define GENERATINGPOWERPC TARGET_CPU_PPC
+#endif
+
/* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */
/* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */
/*
diff -r e49147870aac -r 14717b52abc0 src/timer/macos/SDL_systimer.c
--- a/src/timer/macos/SDL_systimer.c Mon May 01 06:58:33 2006 +0000
+++ b/src/timer/macos/SDL_systimer.c Wed May 17 08:18:28 2006 +0000
@@ -36,6 +36,10 @@
#include "FastTimes.h"
+#if TARGET_API_MAC_CARBON
+#define NewTimerProc NewTimerUPP
+#endif
+
#define MS_PER_TICK (1000.0/60.0) /* MacOS tick = 1/60 second */
@@ -67,7 +71,11 @@
stop = SDL_GetTicks() + ms;
do {
+ #if TARGET_API_MAC_CARBON
+ MPYield();
+ #else
SystemTask();
+ #endif
now = SDL_GetTicks();
diff -r e49147870aac -r 14717b52abc0 src/video/SDL_blit_A.c
--- a/src/video/SDL_blit_A.c Mon May 01 06:58:33 2006 +0000
+++ b/src/video/SDL_blit_A.c Wed May 17 08:18:28 2006 +0000
@@ -637,6 +637,9 @@
#endif /* GCC_ASMBLIT, MSVC_ASMBLIT */
#if SDL_ALTIVEC_BLITTERS
+#if __MWERKS__
+#pragma altivec_model on
+#endif
#if HAVE_ALTIVEC_H
#include
#endif
@@ -1406,6 +1409,9 @@
dstp += dstskip;
}
}
+#if __MWERKS__
+#pragma altivec_model off
+#endif
#endif /* SDL_ALTIVEC_BLITTERS */
/* fast RGB888->(A)RGB888 blending with surface alpha=128 special case */
diff -r e49147870aac -r 14717b52abc0 src/video/SDL_blit_N.c
--- a/src/video/SDL_blit_N.c Mon May 01 06:58:33 2006 +0000
+++ b/src/video/SDL_blit_N.c Wed May 17 08:18:28 2006 +0000
@@ -29,6 +29,9 @@
/* Functions to blit from N-bit surfaces to other surfaces */
#if SDL_ALTIVEC_BLITTERS
+#if __MWERKS__
+#pragma altivec_model on
+#endif
#ifdef HAVE_ALTIVEC_H
#include
#endif
@@ -830,6 +833,9 @@
}
return features;
}
+#if __MWERKS__
+#pragma altivec_model off
+#endif
#else
/* Feature 1 is has-MMX */
#define GetBlitFeatures() ((Uint32)(SDL_HasMMX() ? 1 : 0))
diff -r e49147870aac -r 14717b52abc0 src/video/ataricommon/SDL_ikbdinterrupt_s.h
--- a/src/video/ataricommon/SDL_ikbdinterrupt_s.h Mon May 01 06:58:33 2006 +0000
+++ b/src/video/ataricommon/SDL_ikbdinterrupt_s.h Wed May 17 08:18:28 2006 +0000
@@ -44,14 +44,14 @@
/* Variables */
-extern Uint8 SDL_AtariIkbd_keyboard[128]; /* Keyboard table */
-extern Uint16 SDL_AtariIkbd_mouseb; /* Mouse on port 0, buttons */
-extern Sint16 SDL_AtariIkbd_mousex; /* Mouse X relative motion */
-extern Sint16 SDL_AtariIkbd_mousey; /* Mouse Y relative motion */
-extern Uint16 SDL_AtariIkbd_joystick; /* Joystick on port 1 */
+extern volatile Uint8 SDL_AtariIkbd_keyboard[128]; /* Keyboard table */
+extern volatile Uint16 SDL_AtariIkbd_mouseb; /* Mouse on port 0, buttons */
+extern volatile Sint16 SDL_AtariIkbd_mousex; /* Mouse X relative motion */
+extern volatile Sint16 SDL_AtariIkbd_mousey; /* Mouse Y relative motion */
+extern volatile Uint16 SDL_AtariIkbd_joystick; /* Joystick on port 1 */
-extern Uint16 SDL_AtariIkbd_enabled; /* For joystick driver to know
- if this is usable */
+/* For joystick driver to know if this is usable */
+extern Uint16 SDL_AtariIkbd_enabled;
/* Functions */
diff -r e49147870aac -r 14717b52abc0 src/video/ataricommon/SDL_xbiosinterrupt_s.h
--- a/src/video/ataricommon/SDL_xbiosinterrupt_s.h Mon May 01 06:58:33 2006 +0000
+++ b/src/video/ataricommon/SDL_xbiosinterrupt_s.h Wed May 17 08:18:28 2006 +0000
@@ -36,10 +36,10 @@
/* Variables */
-extern Uint16 SDL_AtariXbios_mouseb; /* buttons */
-extern Sint16 SDL_AtariXbios_mousex; /* X relative motion */
-extern Sint16 SDL_AtariXbios_mousey; /* Y relative motion */
-extern Uint16 SDL_AtariXbios_joystick; /* Joystick */
+extern volatile Uint16 SDL_AtariXbios_mouseb; /* buttons */
+extern volatile Sint16 SDL_AtariXbios_mousex; /* X relative motion */
+extern volatile Sint16 SDL_AtariXbios_mousey; /* Y relative motion */
+extern volatile Uint16 SDL_AtariXbios_joystick; /* Joystick */
/* Functions */
diff -r e49147870aac -r 14717b52abc0 src/video/dga/SDL_dgavideo.c
--- a/src/video/dga/SDL_dgavideo.c Mon May 01 06:58:33 2006 +0000
+++ b/src/video/dga/SDL_dgavideo.c Wed May 17 08:18:28 2006 +0000
@@ -41,6 +41,13 @@
/* get function pointers... */
#include "../x11/SDL_x11dyn.h"
+/*#define DGA_DEBUG*/
+
+/* Heheh we're using X11 event code */
+extern void X11_SaveScreenSaver(Display *display, int *saved_timeout, BOOL *dpms);
+extern void X11_DisableScreenSaver(Display *display);
+extern void X11_RestoreScreenSaver(Display *display, int saved_timeout, BOOL dpms);
+
/* Initialization/Query functions */
static int DGA_VideoInit(_THIS, SDL_PixelFormat *vformat);
static SDL_Rect **DGA_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
@@ -169,7 +176,7 @@
static int DGA_AddMode(_THIS, int bpp, int w, int h)
{
SDL_Rect *mode;
- int i, index;
+ int index;
int next_mode;
/* Check to see if we already have this mode */
@@ -177,8 +184,8 @@
return(0);
}
index = ((bpp+7)/8)-1;
- for ( i=0; i 0 ) {
+ mode = SDL_modelist[index][SDL_nummodes[index]-1];
if ( (mode->w == w) && (mode->h == h) ) {
return(0);
}
@@ -281,14 +288,21 @@
const SDL_NAME(XDGAMode) *a = (const SDL_NAME(XDGAMode) *)va;
const SDL_NAME(XDGAMode) *b = (const SDL_NAME(XDGAMode) *)vb;
- /* Prefer DirectColor visuals for otherwise equal modes */
if ( (a->viewportWidth == b->viewportWidth) &&
(b->viewportHeight == a->viewportHeight) ) {
- if ( a->visualClass == DirectColor )
+ /* Prefer 32 bpp over 24 bpp, 16 bpp over 15 bpp */
+ int a_bpp = a->depth == 24 ? a->bitsPerPixel : a->depth;
+ int b_bpp = b->depth == 24 ? b->bitsPerPixel : b->depth;
+ if ( a_bpp != b_bpp ) {
+ return b_bpp - a_bpp;
+ }
+ /* Prefer DirectColor visuals, for gamma support */
+ if ( a->visualClass == DirectColor && b->visualClass != DirectColor )
return -1;
- if ( b->visualClass == DirectColor )
+ if ( b->visualClass == DirectColor && a->visualClass != DirectColor )
return 1;
- return 0;
+ /* Maintain server refresh rate sorting */
+ return a->num - b->num;
} else if ( a->viewportWidth == b->viewportWidth ) {
return b->viewportHeight - a->viewportHeight;
} else {
@@ -387,16 +401,21 @@
return(-1);
}
+ /* Save DPMS and screensaver settings */
+ X11_SaveScreenSaver(DGA_Display, &screensaver_timeout, &dpms_enabled);
+ X11_DisableScreenSaver(DGA_Display);
+
/* Query for the list of available video modes */
modes = SDL_NAME(XDGAQueryModes)(DGA_Display, DGA_Screen, &num_modes);
SDL_qsort(modes, num_modes, sizeof *modes, cmpmodes);
for ( i=0; inext ) {
if ( bucket == (vidmem_bucket *)surface->hwdata ) {
@@ -1032,7 +1061,7 @@
SDL_NAME(XDGACloseFramebuffer)(DGA_Display, DGA_Screen);
if ( this->screen ) {
/* Tell SDL not to free the pixels */
- this->screen->pixels = NULL;
+ DGA_FreeHWSurface(this, this->screen);
}
SDL_NAME(XDGASetMode)(DGA_Display, DGA_Screen, 0);
@@ -1048,7 +1077,6 @@
}
#endif /* LOCK_DGA_DISPLAY */
-
/* Clean up defined video modes */
for ( i=0; i
+#include
#include "SDL_mouse.h"
#include "SDL_mutex.h"
#include "../SDL_sysvideo.h"
+#if SDL_VIDEO_DRIVER_X11_DPMS
+#include
+#endif
+
/* Hidden "this" pointer for the video functions */
#define _THIS SDL_VideoDevice *this
@@ -86,6 +91,10 @@
#ifdef LOCK_DGA_DISPLAY
SDL_mutex *event_lock;
#endif
+
+ /* Screensaver settings */
+ int screensaver_timeout;
+ BOOL dpms_enabled;
};
/* Old variable names */
#define DGA_Display (this->hidden->DGA_Display)
@@ -107,5 +116,7 @@
#define hw_lock (this->hidden->hw_lock)
#define DGA_event_base (this->hidden->event_base)
#define event_lock (this->hidden->event_lock)
+#define screensaver_timeout (this->hidden->screensaver_timeout)
+#define dpms_enabled (this->hidden->dpms_enabled)
#endif /* _SDL_dgavideo_h */
diff -r e49147870aac -r 14717b52abc0 src/video/directfb/SDL_DirectFB_events.c
--- a/src/video/directfb/SDL_DirectFB_events.c Mon May 01 06:58:33 2006 +0000
+++ b/src/video/directfb/SDL_DirectFB_events.c Wed May 17 08:18:28 2006 +0000
@@ -155,7 +155,7 @@
keymap[DIKI_SHIFT_L - DIKI_UNKNOWN] = SDLK_LSHIFT;
keymap[DIKI_SHIFT_R - DIKI_UNKNOWN] = SDLK_RSHIFT;
keymap[DIKI_ALT_L - DIKI_UNKNOWN] = SDLK_LALT;
- keymap[DIKI_ALTGR - DIKI_UNKNOWN] = SDLK_RALT;
+ keymap[DIKI_ALT_R - DIKI_UNKNOWN] = SDLK_RALT;
keymap[DIKI_TAB - DIKI_UNKNOWN] = SDLK_TAB;
keymap[DIKI_ENTER - DIKI_UNKNOWN] = SDLK_RETURN;
keymap[DIKI_SPACE - DIKI_UNKNOWN] = SDLK_SPACE;
diff -r e49147870aac -r 14717b52abc0 src/video/directfb/SDL_DirectFB_video.c
--- a/src/video/directfb/SDL_DirectFB_video.c Mon May 01 06:58:33 2006 +0000
+++ b/src/video/directfb/SDL_DirectFB_video.c Wed May 17 08:18:28 2006 +0000
@@ -191,6 +191,9 @@
HIDDEN->nummodes++;
+ if (enumlist && enumlist->r.w == width && enumlist->r.h == height)
+ return DFENUM_OK;
+
enumrect = SDL_calloc(1, sizeof(struct DirectFBEnumRect));
if (!enumrect)
{
diff -r e49147870aac -r 14717b52abc0 src/video/directfb/SDL_DirectFB_yuv.c
--- a/src/video/directfb/SDL_DirectFB_yuv.c Mon May 01 06:58:33 2006 +0000
+++ b/src/video/directfb/SDL_DirectFB_yuv.c Wed May 17 08:18:28 2006 +0000
@@ -200,7 +200,7 @@
{
DFBResult ret;
void *data;
- unsigned int pitch;
+ int pitch;
IDirectFBSurface *surface = overlay->hwdata->surface;
ret = surface->Lock (surface, DSLF_READ | DSLF_WRITE, &data, &pitch);
diff -r e49147870aac -r 14717b52abc0 src/video/fbcon/SDL_fb3dfx.c
--- a/src/video/fbcon/SDL_fb3dfx.c Mon May 01 06:58:33 2006 +0000
+++ b/src/video/fbcon/SDL_fb3dfx.c Wed May 17 08:18:28 2006 +0000
@@ -57,6 +57,9 @@
int dstX, dstY;
/* Don't blit to the display surface when switched away */
+ if ( switched_away ) {
+ return -2; /* no hardware access */
+ }
if ( dst == this->screen ) {
SDL_mutexP(hw_lock);
}
@@ -102,6 +105,9 @@
Uint32 use_colorkey;
/* Don't blit to the display surface when switched away */
+ if ( switched_away ) {
+ return -2; /* no hardware access */
+ }
if ( dst == this->screen ) {
SDL_mutexP(hw_lock);
}
diff -r e49147870aac -r 14717b52abc0 src/video/fbcon/SDL_fbevents.c
--- a/src/video/fbcon/SDL_fbevents.c Mon May 01 06:58:33 2006 +0000
+++ b/src/video/fbcon/SDL_fbevents.c Wed May 17 08:18:28 2006 +0000
@@ -55,6 +55,8 @@
#define GPM_NODE_FIFO "/dev/gpmdata"
#endif
+/*#define DEBUG_KEYBOARD*/
+/*#define DEBUG_MOUSE*/
/* The translation tables from a console scancode to a SDL keysym */
#define NUM_VGAKEYMAPS (1< 0 ) {
ioctl(keyboard_fd, VT_ACTIVATE, saved_vt);
}
@@ -280,8 +285,15 @@
}
if ( keyboard_fd < 0 ) {
/* Last resort, maybe our tty is a usable VT */
- current_vt = 0;
+ struct vt_stat vtstate;
+
keyboard_fd = open("/dev/tty", O_RDWR);
+
+ if ( ioctl(keyboard_fd, VT_GETSTATE, &vtstate) == 0 ) {
+ current_vt = vtstate.v_active;
+ } else {
+ current_vt = 0;
+ }
}
#ifdef DEBUG_KEYBOARD
fprintf(stderr, "Current VT: %d\n", current_vt);
@@ -360,7 +372,7 @@
}
/* Returns true if /dev/gpmdata is being written to by gpm */
-static int gpm_available(void)
+static int gpm_available(char *proto, size_t protolen)
{
int available;
DIR *proc;
@@ -370,6 +382,9 @@
char args[PATH_MAX], *arg;
/* Don't bother looking if the fifo isn't there */
+#ifdef DEBUG_MOUSE
+ fprintf(stderr,"testing gpm\n");
+#endif
if ( access(GPM_NODE_FIFO, F_OK) < 0 ) {
return(0);
}
@@ -377,17 +392,37 @@
available = 0;
proc = opendir("/proc");
if ( proc ) {
- while ( (pid=find_pid(proc, "gpm")) > 0 ) {
+ char raw_proto[10] = { '\0' };
+ char repeat_proto[10] = { '\0' };
+ while ( !available && (pid=find_pid(proc, "gpm")) > 0 ) {
SDL_snprintf(path, SDL_arraysize(path), "/proc/%d/cmdline", pid);
cmdline = open(path, O_RDONLY, 0);
if ( cmdline >= 0 ) {
len = read(cmdline, args, sizeof(args));
arg = args;
while ( len > 0 ) {
- if ( SDL_strcmp(arg, "-R") == 0 ) {
+ arglen = SDL_strlen(arg)+1;
+#ifdef DEBUG_MOUSE
+ fprintf(stderr,"gpm arg %s len %d\n",arg,arglen);
+#endif
+ if ( SDL_strcmp(arg, "-t") == 0) {
+ /* protocol string, keep it for later */
+ char *t, *s;
+ t = arg + arglen;
+ s = SDL_strchr(t, ' ');
+ if (s) *s = 0;
+ SDL_strlcpy(raw_proto, t, SDL_arraysize(raw_proto));
+ if (s) *s = ' ';
+ }
+ if ( SDL_strncmp(arg, "-R", 2) == 0 ) {
+ char *t, *s;
available = 1;
+ t = arg + 2;
+ s = SDL_strchr(t, ' ');
+ if (s) *s = 0;
+ SDL_strlcpy(repeat_proto, t, SDL_arraysize(repeat_proto));
+ if (s) *s = ' ';
}
- arglen = SDL_strlen(arg)+1;
len -= arglen;
arg += arglen;
}
@@ -395,6 +430,16 @@
}
}
closedir(proc);
+
+ if ( available ) {
+ if ( SDL_strcmp(repeat_proto, "raw") == 0 ) {
+ SDL_strlcpy(proto, raw_proto, protolen);
+ } else if ( *repeat_proto ) {
+ SDL_strlcpy(proto, repeat_proto, protolen);
+ } else {
+ SDL_strlcpy(proto, "msc", protolen);
+ }
+ }
}
return available;
}
@@ -414,7 +459,7 @@
{0xFF}
*/
Uint8 set_imps2[] = {0xf3, 200, 0xf3, 100, 0xf3, 80};
- Uint8 reset = 0xff;
+ /*Uint8 reset = 0xff;*/
fd_set fdset;
struct timeval tv;
int retval = 0;
@@ -552,14 +597,35 @@
};
/* First try to use GPM in repeater mode */
if ( mouse_fd < 0 ) {
- if ( gpm_available() ) {
+ char proto[10];
+ if ( gpm_available(proto, SDL_arraysize(proto)) ) {
mouse_fd = open(GPM_NODE_FIFO, O_RDONLY, 0);
if ( mouse_fd >= 0 ) {
+ if ( SDL_strcmp(proto, "msc") == 0 ) {
+ mouse_drv = MOUSE_MSC;
+ } else if ( SDL_strcmp(proto, "ps2") == 0 ) {
+ mouse_drv = MOUSE_PS2;
+ } else if ( SDL_strcmp(proto, "imps2") == 0 ) {
+ mouse_drv = MOUSE_IMPS2;
+ } else if ( SDL_strcmp(proto, "ms") == 0 ||
+ SDL_strcmp(proto, "bare") == 0 ) {
+ mouse_drv = MOUSE_MS;
+ } else if ( SDL_strcmp(proto, "bm") == 0 ) {
+ mouse_drv = MOUSE_BM;
+ } else {
+ /* Unknown protocol... */
#ifdef DEBUG_MOUSE
-fprintf(stderr, "Using GPM mouse\n");
+ fprintf(stderr, "GPM mouse using unknown protocol = %s\n", proto);
#endif
- mouse_drv = MOUSE_MSC;
+ close(mouse_fd);
+ mouse_fd = -1;
+ }
}
+#ifdef DEBUG_MOUSE
+ if ( mouse_fd >= 0 ) {
+ fprintf(stderr, "Using GPM mouse, protocol = %s\n", proto);
+ }
+#endif /* DEBUG_MOUSE */
}
}
/* Now try to use a modern PS/2 mouse */
@@ -853,65 +919,65 @@
return;
}
-/* Handle switching to another VC, returns when our VC is back.
- This isn't necessarily the best solution. For SDL 1.3 we need
- a way of notifying the application when we lose access to the
- video hardware and when we regain it.
- */
+/* Handle switching to another VC, returns when our VC is back */
+static void switch_vt_prep(_THIS)
+{
+ SDL_Surface *screen = SDL_VideoSurface;
+
+ SDL_PrivateAppActive(0, (SDL_APPACTIVE|SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS));
+
+ /* Save the contents of the screen, and go to text mode */
+ wait_idle(this);
+ screen_arealen = ((screen->h + (2*this->offset_y)) * screen->pitch);
+ screen_contents = (Uint8 *)SDL_malloc(screen_arealen);
+ if ( screen_contents ) {
+ SDL_memcpy(screen_contents, screen->pixels, screen_arealen);
+ }
+ FB_SavePaletteTo(this, 256, screen_palette);
+ ioctl(console_fd, FBIOGET_VSCREENINFO, &screen_vinfo);
+ ioctl(keyboard_fd, KDSETMODE, KD_TEXT);
+ ioctl(keyboard_fd, VT_UNLOCKSWITCH, 1);
+}
+static void switch_vt_done(_THIS)
+{
+ SDL_Surface *screen = SDL_VideoSurface;
+
+ /* Restore graphics mode and the contents of the screen */
+ ioctl(keyboard_fd, VT_LOCKSWITCH, 1);
+ ioctl(keyboard_fd, KDSETMODE, KD_GRAPHICS);
+ ioctl(console_fd, FBIOPUT_VSCREENINFO, &screen_vinfo);
+ FB_RestorePaletteFrom(this, 256, screen_palette);
+ if ( screen_contents ) {
+ SDL_memcpy(screen->pixels, screen_contents, screen_arealen);
+ SDL_free(screen_contents);
+ screen_contents = NULL;
+ }
+
+ /* Get updates to the shadow surface while switched away */
+ if ( SDL_ShadowSurface ) {
+ SDL_UpdateRect(SDL_ShadowSurface, 0, 0, 0, 0);
+ }
+
+ SDL_PrivateAppActive(1, (SDL_APPACTIVE|SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS));
+}
static void switch_vt(_THIS, unsigned short which)
{
- struct fb_var_screeninfo vinfo;
struct vt_stat vtstate;
- unsigned short v_active;
- __u16 saved_pal[3*256];
- SDL_Surface *screen;
- Uint32 screen_arealen;
- Uint8 *screen_contents = NULL;
/* Figure out whether or not we're switching to a new console */
if ( (ioctl(keyboard_fd, VT_GETSTATE, &vtstate) < 0) ||
(which == vtstate.v_active) ) {
return;
}
- v_active = vtstate.v_active;
-
- /* Save the contents of the screen, and go to text mode */
- SDL_mutexP(hw_lock);
- wait_idle(this);
- screen = SDL_VideoSurface;
- if ( !SDL_ShadowSurface ) {
- screen_arealen = (screen->h*screen->pitch);
- screen_contents = (Uint8 *)SDL_malloc(screen_arealen);
- if ( screen_contents ) {
- SDL_memcpy(screen_contents, (Uint8 *)screen->pixels + screen->offset, screen_arealen);
- }
- }
- FB_SavePaletteTo(this, 256, saved_pal);
- ioctl(console_fd, FBIOGET_VSCREENINFO, &vinfo);
- ioctl(keyboard_fd, KDSETMODE, KD_TEXT);
/* New console, switch to it */
+ SDL_mutexP(hw_lock);
+ switch_vt_prep(this);
if ( ioctl(keyboard_fd, VT_ACTIVATE, which) == 0 ) {
- /* Wait for our console to be activated again */
ioctl(keyboard_fd, VT_WAITACTIVE, which);
- while ( ioctl(keyboard_fd, VT_WAITACTIVE, v_active) < 0 ) {
- if ( (errno != EINTR) && (errno != EAGAIN) ) {
- /* Unknown VT error - cancel this */
- break;
- }
- SDL_Delay(500);
- }
- }
-
- /* Restore graphics mode and the contents of the screen */
- ioctl(keyboard_fd, KDSETMODE, KD_GRAPHICS);
- ioctl(console_fd, FBIOPUT_VSCREENINFO, &vinfo);
- FB_RestorePaletteFrom(this, 256, saved_pal);
- if ( screen_contents ) {
- SDL_memcpy((Uint8 *)screen->pixels + screen->offset, screen_contents, screen_arealen);
- SDL_free(screen_contents);
+ switched_away = 1;
} else {
- SDL_UpdateRect(screen, 0, 0, 0, 0);
+ switch_vt_done(this);
}
SDL_mutexV(hw_lock);
}
@@ -969,6 +1035,18 @@
static struct timeval zero;
do {
+ if ( switched_away ) {
+ struct vt_stat vtstate;
+
+ SDL_mutexP(hw_lock);
+ if ( (ioctl(keyboard_fd, VT_GETSTATE, &vtstate) == 0) &&
+ vtstate.v_active == current_vt ) {
+ switched_away = 0;
+ switch_vt_done(this);
+ }
+ SDL_mutexV(hw_lock);
+ }
+
posted = 0;
FD_ZERO(&fdset);
@@ -1037,6 +1115,12 @@
case SCANCODE_LEFTWIN:
keymap[i] = SDLK_LSUPER;
break;
+ case SCANCODE_LEFTALT:
+ keymap[i] = SDLK_LALT;
+ break;
+ case SCANCODE_RIGHTALT:
+ keymap[i] = SDLK_RALT;
+ break;
case 127:
keymap[i] = SDLK_MENU;
break;
@@ -1138,10 +1222,10 @@
if ( modstate & KMOD_CTRL ) {
map |= (1<screen ) {
SDL_mutexP(hw_lock);
}
@@ -132,6 +135,9 @@
}
/* Don't blit to the display surface when switched away */
+ if ( switched_away ) {
+ return -2; /* no hardware access */
+ }
if ( dst == this->screen ) {
SDL_mutexP(hw_lock);
}
diff -r e49147870aac -r 14717b52abc0 src/video/fbcon/SDL_fbriva.c
--- a/src/video/fbcon/SDL_fbriva.c Mon May 01 06:58:33 2006 +0000
+++ b/src/video/fbcon/SDL_fbriva.c Wed May 17 08:18:28 2006 +0000
@@ -77,6 +77,9 @@
RivaBitmap *Bitmap = (RivaBitmap *)(mapped_io + BITMAP_OFFSET);
/* Don't blit to the display surface when switched away */
+ if ( switched_away ) {
+ return -2; /* no hardware access */
+ }
if ( dst == this->screen ) {
SDL_mutexP(hw_lock);
}
@@ -120,6 +123,9 @@
}
/* Don't blit to the display surface when switched away */
+ if ( switched_away ) {
+ return -2; /* no hardware access */
+ }
if ( dst == this->screen ) {
SDL_mutexP(hw_lock);
}
diff -r e49147870aac -r 14717b52abc0 src/video/fbcon/SDL_fbvideo.c
--- a/src/video/fbcon/SDL_fbvideo.c Mon May 01 06:58:33 2006 +0000
+++ b/src/video/fbcon/SDL_fbvideo.c Wed May 17 08:18:28 2006 +0000
@@ -149,11 +149,25 @@
struct fb_var_screeninfo *vinfo);
static void FB_RestorePalette(_THIS);
+/* Small wrapper for mmap() so we can play nicely with no-mmu hosts
+ * (non-mmu hosts disallow the MAP_SHARED flag) */
+
+static void *do_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset)
+{
+ void *ret;
+ ret = mmap(start, length, prot, flags, fd, offset);
+ if ( ret == (char *)-1 && (flags & MAP_SHARED) ) {
+ ret = mmap(start, length, prot,
+ (flags & ~MAP_SHARED) | MAP_PRIVATE, fd, offset);
+ }
+ return ret;
+}
+
/* FB driver bootstrap functions */
static int FB_Available(void)
{
- int console;
+ int console = -1;
/* Added check for /fb/0 (devfs) */
/* but - use environment variable first... if it fails, still check defaults */
int idx = 0;
@@ -535,7 +549,7 @@
mapped_offset = (((long)finfo.smem_start) -
(((long)finfo.smem_start)&~(PAGE_SIZE-1)));
mapped_memlen = finfo.smem_len+mapped_offset;
- mapped_mem = mmap(NULL, mapped_memlen,
+ mapped_mem = do_mmap(NULL, mapped_memlen,
PROT_READ|PROT_WRITE, MAP_SHARED, console_fd, 0);
if ( mapped_mem == (char *)-1 ) {
SDL_SetError("Unable to memory map the video hardware");
@@ -579,7 +593,7 @@
ioctl(console_fd, FBIOPUT_VSCREENINFO, &vinfo);
if ( finfo.accel && finfo.mmio_len ) {
mapped_iolen = finfo.mmio_len;
- mapped_io = mmap(NULL, mapped_iolen, PROT_READ|PROT_WRITE,
+ mapped_io = do_mmap(NULL, mapped_iolen, PROT_READ|PROT_WRITE,
MAP_SHARED, console_fd, mapped_memlen);
if ( mapped_io == (char *)-1 ) {
/* Hmm, failed to memory map I/O registers */
@@ -1238,26 +1252,10 @@
surface->hwdata = NULL;
}
-/* Routine to check to see if the frame buffer virtual terminal */
-/* is the current(active) one. If it is not, result will cause */
-/* Lock to fail. (would have waited forever, since the fbevent */
-/* keyboard handler maintains a lock when switched away from */
-/* current) */
-static __inline__ int FB_IsFrameBufferActive(_THIS)
-{
- struct vt_stat vtstate;
- if ( (ioctl(keyboard_fd, VT_GETSTATE, &vtstate) < 0) ||
- (current_vt != vtstate.v_active) ) {
- return 0;
- }
- return 1;
-}
-
-
static int FB_LockHWSurface(_THIS, SDL_Surface *surface)
{
- if ( !FB_IsFrameBufferActive(this) ) {
- return -1; /* fail locking. */
+ if ( switched_away ) {
+ return -2; /* no hardware access */
}
if ( surface == this->screen ) {
SDL_mutexP(hw_lock);
@@ -1293,6 +1291,10 @@
static int FB_FlipHWSurface(_THIS, SDL_Surface *surface)
{
+ if ( switched_away ) {
+ return -2; /* no hardware access */
+ }
+
/* Wait for vertical retrace and then flip display */
cache_vinfo.yoffset = flip_page*surface->h;
if ( FB_IsSurfaceBusy(this->screen) ) {
@@ -1333,6 +1335,10 @@
Uint32 *src, *srcPtr;
Uint8 *dst, *dstPtr;
+ if ( switched_away ) {
+ return; /* no hardware access */
+ }
+
screen = this->screen;
FBPitch = screen->w >> 3;
SRCPitch = screen->pitch >> 2;
diff -r e49147870aac -r 14717b52abc0 src/video/fbcon/SDL_fbvideo.h
--- a/src/video/fbcon/SDL_fbvideo.h Mon May 01 06:58:33 2006 +0000
+++ b/src/video/fbcon/SDL_fbvideo.h Wed May 17 08:18:28 2006 +0000
@@ -85,6 +85,11 @@
int surfaces_memleft;
SDL_mutex *hw_lock;
+ int switched_away;
+ struct fb_var_screeninfo screen_vinfo;
+ Uint32 screen_arealen;
+ Uint8 *screen_contents;
+ __u16 screen_palette[3*256];
void (*wait_vbl)(_THIS);
void (*wait_idle)(_THIS);
@@ -117,6 +122,11 @@
#define surfaces_memtotal (this->hidden->surfaces_memtotal)
#define surfaces_memleft (this->hidden->surfaces_memleft)
#define hw_lock (this->hidden->hw_lock)
+#define switched_away (this->hidden->switched_away)
+#define screen_vinfo (this->hidden->screen_vinfo)
+#define screen_arealen (this->hidden->screen_arealen)
+#define screen_contents (this->hidden->screen_contents)
+#define screen_palette (this->hidden->screen_palette)
#define wait_vbl (this->hidden->wait_vbl)
#define wait_idle (this->hidden->wait_idle)
diff -r e49147870aac -r 14717b52abc0 src/video/maccommon/SDL_macgl.c
--- a/src/video/maccommon/SDL_macgl.c Mon May 01 06:58:33 2006 +0000
+++ b/src/video/maccommon/SDL_macgl.c Wed May 17 08:18:28 2006 +0000
@@ -168,7 +168,11 @@
int Mac_GL_LoadLibrary(_THIS, const char *location)
{
if (location == NULL)
+#if __MACH__
+ location = "/System/Library/Frameworks/OpenGL.framework/OpenGL";
+#else
location = "OpenGLLibrary";
+#endif
this->hidden->libraryHandle = SDL_LoadObject(location);
diff -r e49147870aac -r 14717b52abc0 src/video/maccommon/SDL_macgl_c.h
--- a/src/video/maccommon/SDL_macgl_c.h Mon May 01 06:58:33 2006 +0000
+++ b/src/video/maccommon/SDL_macgl_c.h Wed May 17 08:18:28 2006 +0000
@@ -26,7 +26,7 @@
#if SDL_VIDEO_OPENGL
#include "SDL_opengl.h"
-#ifdef MACOSX
+#if __MACOSX__
#include /* AGL.framework */
#else
#include
diff -r e49147870aac -r 14717b52abc0 src/video/macdsp/SDL_dspvideo.c
--- a/src/video/macdsp/SDL_dspvideo.c Mon May 01 06:58:33 2006 +0000
+++ b/src/video/macdsp/SDL_dspvideo.c Wed May 17 08:18:28 2006 +0000
@@ -682,7 +682,7 @@
if (dialog == NULL)
return (0);
-#if TARGET_API_CARBON
+#if TARGET_API_MAC_CARBON
SetPort (GetDialogPort(dialog));
#else
SetPort ((WindowPtr) dialog);
diff -r e49147870aac -r 14717b52abc0 src/video/macrom/SDL_romvideo.c
--- a/src/video/macrom/SDL_romvideo.c Mon May 01 06:58:33 2006 +0000
+++ b/src/video/macrom/SDL_romvideo.c Wed May 17 08:18:28 2006 +0000
@@ -35,6 +35,7 @@
#include
#endif
#else
+#include
#include
#include
#include
@@ -637,12 +638,12 @@
SetPortWindowPort(SDL_Window);
thePort = GetWindowPort(SDL_Window);
memworld = (GWorldPtr)GetWRefCon(SDL_Window);
-#if TARGET_API_MAC_CARBON
+#if TARGET_API_MAC_CARBON && ACCESSOR_CALLS_ARE_FUNCTIONS
memBits = GetPortBitMapForCopyBits((CGrafPtr) memworld);
#else
memBits = &((GrafPtr)memworld)->portBits;
#endif
-#if TARGET_API_MAC_CARBON
+#if TARGET_API_MAC_CARBON && ACCESSOR_CALLS_ARE_FUNCTIONS
winBits = GetPortBitMapForCopyBits(thePort);
#else
winBits = &SDL_Window->portBits;
diff -r e49147870aac -r 14717b52abc0 src/video/ps2gs/SDL_gsyuv.c
--- a/src/video/ps2gs/SDL_gsyuv.c Mon May 01 06:58:33 2006 +0000
+++ b/src/video/ps2gs/SDL_gsyuv.c Wed May 17 08:18:28 2006 +0000
@@ -325,7 +325,7 @@
int lum_pitch;
int crb_pitch;
Uint32 *lum_src, *Cr_src, *Cb_src;
- Uint32 *src, *dst;
+ Uint32 *srcp, *dstp;
unsigned int x, y;
SDL_Surface *screen;
@@ -345,7 +345,7 @@
SDL_SetError("Unsupported YUV format in blit (?)");
return(-1);
}
- dst = (Uint32 *)hwdata->ipu_imem;
+ dstp = (Uint32 *)hwdata->ipu_imem;
lum_pitch = overlay->w/4;
crb_pitch = (overlay->w/2)/4;
@@ -355,28 +355,28 @@
Cr_src = Cr;
Cb_src = Cb;
for ( w=overlay->w/16; w; --w ) {
- src = lum_src;
+ srcp = lum_src;
for ( i=0; i<16; ++i ) {
- dst[0] = src[0];
- dst[1] = src[1];
- dst[2] = src[2];
- dst[3] = src[3];
- src += lum_pitch;
- dst += 4;
+ dstp[0] = srcp[0];
+ dstp[1] = srcp[1];
+ dstp[2] = srcp[2];
+ dstp[3] = srcp[3];
+ srcp += lum_pitch;
+ dstp += 4;
}
- src = Cb_src;
+ srcp = Cb_src;
for ( i=0; i<8; ++i ) {
- dst[0] = src[0];
- dst[1] = src[1];
- src += crb_pitch;
- dst += 2;
+ dstp[0] = srcp[0];
+ dstp[1] = srcp[1];
+ srcp += crb_pitch;
+ dstp += 2;
}
- src = Cr_src;
+ srcp = Cr_src;
for ( i=0; i<8; ++i ) {
- dst[0] = src[0];
- dst[1] = src[1];
- src += crb_pitch;
- dst += 2;
+ dstp[0] = srcp[0];
+ dstp[1] = srcp[1];
+ srcp += crb_pitch;
+ dstp += 2;
}
lum_src += 16 / 4;
Cb_src += 8 / 4;
diff -r e49147870aac -r 14717b52abc0 src/video/quartz/SDL_QuartzVideo.m
--- a/src/video/quartz/SDL_QuartzVideo.m Mon May 01 06:58:33 2006 +0000
+++ b/src/video/quartz/SDL_QuartzVideo.m Wed May 17 08:18:28 2006 +0000
@@ -117,14 +117,14 @@
SDL_VideoDevice *device;
SDL_PrivateVideoData *hidden;
- device = (SDL_VideoDevice*) malloc (sizeof (*device) );
- hidden = (SDL_PrivateVideoData*) malloc (sizeof (*hidden) );
+ device = (SDL_VideoDevice*) SDL_malloc (sizeof (*device) );
+ hidden = (SDL_PrivateVideoData*) SDL_malloc (sizeof (*hidden) );
if (device == NULL || hidden == NULL)
SDL_OutOfMemory ();
- memset (device, 0, sizeof (*device) );
- memset (hidden, 0, sizeof (*hidden) );
+ SDL_memset (device, 0, sizeof (*device) );
+ SDL_memset (hidden, 0, sizeof (*hidden) );
device->hidden = hidden;
@@ -178,8 +178,8 @@
static void QZ_DeleteDevice (SDL_VideoDevice *device) {
- free (device->hidden);
- free (device);
+ SDL_free (device->hidden);
+ SDL_free (device);
}
static int QZ_VideoInit (_THIS, SDL_PixelFormat *video_format) {
@@ -242,9 +242,9 @@
int i;
for (i = 0; client_mode_list[i] != NULL; i++)
- free (client_mode_list[i]);
+ SDL_free (client_mode_list[i]);
- free (client_mode_list);
+ SDL_free (client_mode_list);
client_mode_list = NULL;
}
@@ -297,12 +297,12 @@
if (client_mode_list == NULL)
client_mode_list = (SDL_Rect**)
- malloc (sizeof(*client_mode_list) * (list_size+1) );
+ SDL_malloc (sizeof(*client_mode_list) * (list_size+1) );
else
client_mode_list = (SDL_Rect**)
- realloc (client_mode_list, sizeof(*client_mode_list) * (list_size+1));
+ SDL_realloc (client_mode_list, sizeof(*client_mode_list) * (list_size+1));
- rect = (SDL_Rect*) malloc (sizeof(**client_mode_list));
+ rect = (SDL_Rect*) SDL_malloc (sizeof(**client_mode_list));
if (client_mode_list == NULL || rect == NULL) {
SDL_OutOfMemory ();
@@ -372,7 +372,7 @@
SDL_WaitThread (thread, NULL);
SDL_DestroySemaphore (sem1);
SDL_DestroySemaphore (sem2);
- free (sw_buffers[0]);
+ SDL_free (sw_buffers[0]);
}
/*
@@ -493,7 +493,7 @@
this->UnlockHWSurface = QZ_UnlockDoubleBuffer;
this->FlipHWSurface = QZ_FlipDoubleBuffer;
- current->pixels = malloc (current->pitch * current->h * 2);
+ current->pixels = SDL_malloc (current->pitch * current->h * 2);
if (current->pixels == NULL) {
SDL_OutOfMemory ();
goto ERR_DOUBLEBUF;
@@ -984,7 +984,7 @@
while ( h-- ) {
- memcpy (dst, src, len);
+ SDL_memcpy (dst, src, len);
src += skip;
dst += skip;
}
@@ -1211,7 +1211,7 @@
dockIconCacheMiss) {
numCachedDockIcons = i - firstDockIcon;
- memcpy (dockIcons, &(windows[firstDockIcon]),
+ SDL_memcpy (dockIcons, &(windows[firstDockIcon]),
numCachedDockIcons * sizeof(*windows));
}
diff -r e49147870aac -r 14717b52abc0 src/video/quartz/SDL_QuartzWM.m
--- a/src/video/quartz/SDL_QuartzWM.m Mon May 01 06:58:33 2006 +0000
+++ b/src/video/quartz/SDL_QuartzWM.m Wed May 17 08:18:28 2006 +0000
@@ -41,12 +41,12 @@
int row, bytes;
/* Allocate the cursor memory */
- cursor = (WMcursor *)malloc(sizeof(WMcursor));
+ cursor = (WMcursor *)SDL_malloc(sizeof(WMcursor));
if ( cursor == NULL ) {
SDL_OutOfMemory();
return(NULL);
}
- memset(cursor, 0, sizeof(*cursor));
+ SDL_memset(cursor, 0, sizeof(*cursor));
if (w > 16)
w = 16;
@@ -57,11 +57,11 @@
bytes = (w+7)/8;
for ( row=0; rowcurs.data[row], data, bytes);
+ SDL_memcpy(&cursor->curs.data[row], data, bytes);
data += bytes;
}
for ( row=0; rowcurs.mask[row], mask, bytes);
+ SDL_memcpy(&cursor->curs.mask[row], mask, bytes);
mask += bytes;
}
cursor->curs.hotSpot.h = hot_x;
@@ -262,68 +262,67 @@
NSBitmapImageRep *imgrep;
NSImage *img;
SDL_Surface *mergedSurface;
- int i,j;
NSAutoreleasePool *pool;
- SDL_Rect rrect;
- NSSize imgSize = {icon->w, icon->h};
+ Uint8 *pixels;
+ SDL_bool iconSrcAlpha;
+ Uint8 iconAlphaValue;
+ int i, j, maskPitch, index;
pool = [ [ NSAutoreleasePool alloc ] init ];
- SDL_GetClipRect(icon, &rrect);
+
+ imgrep = [ [ [ NSBitmapImageRep alloc ] initWithBitmapDataPlanes: NULL pixelsWide: icon->w pixelsHigh: icon->h bitsPerSample: 8 samplesPerPixel: 4 hasAlpha: YES isPlanar: NO colorSpaceName: NSDeviceRGBColorSpace bytesPerRow: 4*icon->w bitsPerPixel: 32 ] autorelease ];
+ if (imgrep == nil) goto freePool;
+ pixels = [ imgrep bitmapData ];
+ SDL_memset(pixels, 0, 4*icon->w*icon->h); /* make the background, which will survive in colorkeyed areas, completely transparent */
- /* create a big endian RGBA surface */
- mergedSurface = SDL_CreateRGBSurface(SDL_SWSURFACE|SDL_SRCALPHA,
- icon->w, icon->h, 32, 0xff<<24, 0xff<<16, 0xff<<8, 0xff<<0);
- if (mergedSurface==NULL) {
- NSLog(@"Error creating surface for merge");
- goto freePool;
- }
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+#define BYTEORDER_DEPENDENT_RGBA_MASKS 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF
+#else
+#define BYTEORDER_DEPENDENT_RGBA_MASKS 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000
+#endif
+ mergedSurface = SDL_CreateRGBSurfaceFrom(pixels, icon->w, icon->h, 32, 4*icon->w, BYTEORDER_DEPENDENT_RGBA_MASKS);
+ if (mergedSurface == NULL) goto freePool;
- if (mergedSurface->pitch !=
- mergedSurface->format->BytesPerPixel * mergedSurface->w) {
- SDL_SetError ("merged surface has wrong format");
- SDL_FreeSurface (mergedSurface);
- goto freePool;
- }
+ /* blit, with temporarily cleared SRCALPHA flag because we want to copy, not alpha-blend */
+ iconSrcAlpha = ((icon->flags & SDL_SRCALPHA) != 0);
+ iconAlphaValue = icon->format->alpha;
+ SDL_SetAlpha(icon, 0, 255);
+ SDL_BlitSurface(icon, NULL, mergedSurface, NULL);
+ if (iconSrcAlpha) SDL_SetAlpha(icon, SDL_SRCALPHA, iconAlphaValue);
- if (SDL_BlitSurface(icon,&rrect,mergedSurface,&rrect)) {
- NSLog(@"Error blitting to mergedSurface");
- goto freePool;
- }
+ SDL_FreeSurface(mergedSurface);
- if (mask) {
-
- Uint32 *pixels = mergedSurface->pixels;
- for (i = 0; i < mergedSurface->h; i++) {
- for (j = 0; j < mergedSurface->w; j++) {
-
- int index = i * mergedSurface->w + j;
- int mindex = index >> 3;
- int bindex = 7 - (index & 0x7);
-
- if (mask[mindex] & (1 << bindex))
- pixels[index] |= 0x000000FF;
- else
- pixels[index] &= 0xFFFFFF00;
+ /* apply mask, source alpha, and premultiply color values by alpha */
+ maskPitch = (icon->w+7)/8;
+ for (i = 0; i < icon->h; i++) {
+ for (j = 0; j < icon->w; j++) {
+ index = i*4*icon->w + j*4;
+ if (!(mask[i*maskPitch + j/8] & (128 >> j%8))) {
+ pixels[index + 3] = 0;
+ }
+ else {
+ if (iconSrcAlpha) {
+ if (icon->format->Amask == 0) pixels[index + 3] = icon->format->alpha;
+ }
+ else {
+ pixels[index + 3] = 255;
+ }
+ }
+ if (pixels[index + 3] < 255) {
+ pixels[index + 0] = (Uint16)pixels[index + 0]*pixels[index + 3]/255;
+ pixels[index + 1] = (Uint16)pixels[index + 1]*pixels[index + 3]/255;
+ pixels[index + 2] = (Uint16)pixels[index + 2]*pixels[index + 3]/255;
}
}
}
- imgrep = [ [ NSBitmapImageRep alloc]
- initWithBitmapDataPlanes:(unsigned char **)&mergedSurface->pixels
- pixelsWide:icon->w pixelsHigh:icon->h bitsPerSample:8 samplesPerPixel:4
- hasAlpha:YES isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace
- bytesPerRow:icon->w<<2 bitsPerPixel:32 ];
-
- img = [ [ NSImage alloc ] initWithSize:imgSize ];
-
+ img = [ [ [ NSImage alloc ] initWithSize: NSMakeSize(icon->w, icon->h) ] autorelease ];
+ if (img == nil) goto freePool;
[ img addRepresentation: imgrep ];
[ NSApp setApplicationIconImage:img ];
- [ img release ];
- [ imgrep release ];
- SDL_FreeSurface(mergedSurface);
freePool:
- [pool release];
+ [ pool release ];
}
int QZ_IconifyWindow (_THIS) {
diff -r e49147870aac -r 14717b52abc0 src/video/quartz/SDL_QuartzYUV.m
--- a/src/video/quartz/SDL_QuartzYUV.m Mon May 01 06:58:33 2006 +0000
+++ b/src/video/quartz/SDL_QuartzYUV.m Wed May 17 08:18:28 2006 +0000
@@ -91,16 +91,16 @@
CDSequenceEnd (yuv_seq);
ExitMovies();
- free (overlay->hwfuncs);
- free (overlay->pitches);
- free (overlay->pixels);
+ SDL_free (overlay->hwfuncs);
+ SDL_free (overlay->pitches);
+ SDL_free (overlay->pixels);
if (SDL_VideoSurface->flags & SDL_FULLSCREEN) {
[ qz_window close ];
qz_window = nil;
}
- free (yuv_matrix);
+ SDL_free (yuv_matrix);
DisposeHandle ((Handle)yuv_idh);
}
@@ -134,7 +134,7 @@
return NULL;
}
- yuv_matrix = (MatrixRecordPtr) malloc (sizeof(MatrixRecord));
+ yuv_matrix = (MatrixRecordPtr) SDL_malloc (sizeof(MatrixRecord));
if (yuv_matrix == NULL) {
SDL_OutOfMemory();
return NULL;
@@ -234,7 +234,7 @@
return NULL;
}
- overlay = (SDL_Overlay*) malloc (sizeof(*overlay));
+ overlay = (SDL_Overlay*) SDL_malloc (sizeof(*overlay));
if (overlay == NULL) {
SDL_OutOfMemory();
return NULL;
@@ -267,15 +267,15 @@
return NULL;
}
- pixels = (Uint8**) malloc (sizeof(*pixels) * 3);
- pitches = (Uint16*) malloc (sizeof(*pitches) * 3);
+ pixels = (Uint8**) SDL_malloc (sizeof(*pixels) * 3);
+ pitches = (Uint16*) SDL_malloc (sizeof(*pitches) * 3);
if (pixels == NULL || pitches == NULL) {
SDL_OutOfMemory();
return NULL;
}
yuv_pixmap = (PlanarPixmapInfoYUV420*)
- malloc (sizeof(PlanarPixmapInfoYUV420) +
+ SDL_malloc (sizeof(PlanarPixmapInfoYUV420) +
(width * height * 2));
if (yuv_pixmap == NULL) {
SDL_OutOfMemory ();
@@ -310,7 +310,7 @@
overlay->pitches = pitches;
}
- overlay->hwfuncs = malloc (sizeof(*overlay->hwfuncs));
+ overlay->hwfuncs = SDL_malloc (sizeof(*overlay->hwfuncs));
if (overlay->hwfuncs == NULL) {
SDL_OutOfMemory();
return NULL;
diff -r e49147870aac -r 14717b52abc0 src/video/wincommon/SDL_wingl.c
--- a/src/video/wincommon/SDL_wingl.c Mon May 01 06:58:33 2006 +0000
+++ b/src/video/wincommon/SDL_wingl.c Wed May 17 08:18:28 2006 +0000
@@ -177,6 +177,7 @@
int iAttribs[64];
int *iAttr;
float fAttribs[1] = { 0 };
+ const GLubyte *(WINAPI *glGetStringFunc)(GLenum);
const char *wglext;
/* load the gl driver from a default path */
@@ -338,8 +339,14 @@
* somewhat a documented and reliable hack - it was originally
* as a feature added by mistake, but since so many people rely
* on it, it will not be removed. strstr should be safe here.*/
- wglext = (const char *)this->glGetString(GL_EXTENSIONS);
- if ( !SDL_strstr(wglext, "WGL_EXT_swap_control") ) {
+ glGetStringFunc = WIN_GL_GetProcAddress(this, "glGetString");
+ if ( glGetStringFunc ) {
+ wglext = (const char *)glGetStringFunc(GL_EXTENSIONS);
+ } else {
+ /* Uh oh, something is seriously wrong here... */
+ wglext = NULL;
+ }
+ if ( !wglext || !SDL_strstr(wglext, "WGL_EXT_swap_control") ) {
this->gl_data->wglSwapIntervalEXT = NULL;
this->gl_data->wglGetSwapIntervalEXT = NULL;
}
diff -r e49147870aac -r 14717b52abc0 src/video/windib/SDL_dibvideo.c
--- a/src/video/windib/SDL_dibvideo.c Mon May 01 06:58:33 2006 +0000
+++ b/src/video/windib/SDL_dibvideo.c Wed May 17 08:18:28 2006 +0000
@@ -348,7 +348,6 @@
#endif
}
/* Sort the mode lists */
- if( i > 1 )
for ( i=0; i 0 ) {
SDL_qsort(SDL_modelist[i], SDL_nummodes[i], sizeof *SDL_modelist[i], cmpmodes);
@@ -361,7 +360,7 @@
// because SDL surface conversion is much faster than the WinCE one.
// Although it should be tested on devices with graphics accelerator.
- DIB_AddMode(this, vformat->BitsPerPixel,
+ DIB_AddMode(this, vformat->BitsPerPixel,
GetDeviceCaps(GetDC(NULL), HORZRES),
GetDeviceCaps(GetDC(NULL), VERTRES));
diff -r e49147870aac -r 14717b52abc0 src/video/windx5/SDL_dx5video.c
--- a/src/video/windx5/SDL_dx5video.c Mon May 01 06:58:33 2006 +0000
+++ b/src/video/windx5/SDL_dx5video.c Wed May 17 08:18:28 2006 +0000
@@ -636,6 +636,16 @@
DX5_Available, DX5_CreateDevice
};
+static int cmpmodes(const void *va, const void *vb)
+{
+ SDL_Rect *a = *(SDL_Rect **)va;
+ SDL_Rect *b = *(SDL_Rect **)vb;
+ if ( a->w == b->w )
+ return b->h - a->h;
+ else
+ return b->w - a->w;
+}
+
static HRESULT WINAPI EnumModes2(DDSURFACEDESC *desc, VOID *udata)
{
SDL_VideoDevice *this = (SDL_VideoDevice *)udata;
@@ -955,6 +965,10 @@
SDL_modelist[i][j] = &rect->r;
}
SDL_modelist[i][j] = NULL;
+
+ if ( SDL_nummodes[i] > 0 ) {
+ SDL_qsort(SDL_modelist[i], SDL_nummodes[i], sizeof *SDL_modelist[i], cmpmodes);
+ }
}
/* Fill in some window manager capabilities */
diff -r e49147870aac -r 14717b52abc0 src/video/x11/SDL_x11dyn.c
--- a/src/video/x11/SDL_x11dyn.c Mon May 01 06:58:33 2006 +0000
+++ b/src/video/x11/SDL_x11dyn.c Wed May 17 08:18:28 2006 +0000
@@ -61,30 +61,27 @@
{ NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR },
};
-static void *X11_GetSym(const char *fnname, int *rc)
+static void X11_GetSym(const char *fnname, int *rc, void **fn)
{
int i;
- void *fn = NULL;
for (i = 0; i < SDL_TABLESIZE(x11libs); i++) {
if (x11libs[i].lib != NULL)
{
- fn = SDL_LoadFunction(x11libs[i].lib, fnname);
- if (fn != NULL)
+ *fn = SDL_LoadFunction(x11libs[i].lib, fnname);
+ if (*fn != NULL)
break;
}
}
#if DEBUG_DYNAMIC_X11
- if (fn != NULL)
- printf("X11: Found '%s' in %s (%p)\n", fnname, x11libs[i].libname, fn);
+ if (*fn != NULL)
+ printf("X11: Found '%s' in %s (%p)\n", fnname, x11libs[i].libname, *fn);
else
printf("X11: Symbol '%s' NOT FOUND!\n", fnname);
#endif
- if (fn == NULL)
+ if (*fn == NULL)
*rc = 0; /* kill this module. */
-
- return fn;
}
@@ -159,13 +156,13 @@
}
}
#define SDL_X11_MODULE(modname) thismod = &SDL_X11_HAVE_##modname;
- #define SDL_X11_SYM(a,fn,x,y,z) p##fn = X11_GetSym(#fn,thismod);
+ #define SDL_X11_SYM(a,fn,x,y,z) X11_GetSym(#fn,thismod,(void**)&p##fn);
#include "SDL_x11sym.h"
#undef SDL_X11_MODULE
#undef SDL_X11_SYM
#ifdef X_HAVE_UTF8_STRING
- pXCreateIC = X11_GetSym("XCreateIC",&SDL_X11_HAVE_UTF8);
+ X11_GetSym("XCreateIC",&SDL_X11_HAVE_UTF8,(void **)&pXCreateIC);
#endif
if (!SDL_X11_HAVE_BASEXLIB) { /* some required symbol didn't load. */
diff -r e49147870aac -r 14717b52abc0 src/video/x11/SDL_x11events.c
--- a/src/video/x11/SDL_x11events.c Mon May 01 06:58:33 2006 +0000
+++ b/src/video/x11/SDL_x11events.c Wed May 17 08:18:28 2006 +0000
@@ -291,11 +291,10 @@
(xevent.xcrossing.mode != NotifyUngrab) ) {
if ( this->input_grab == SDL_GRAB_OFF ) {
posted = SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
- } else {
- posted = SDL_PrivateMouseMotion(0, 0,
- xevent.xcrossing.x,
- xevent.xcrossing.y);
}
+ posted = SDL_PrivateMouseMotion(0, 0,
+ xevent.xcrossing.x,
+ xevent.xcrossing.y);
}
}
break;
@@ -1118,3 +1117,57 @@
X11_InitKeymap();
}
+void X11_SaveScreenSaver(Display *display, int *saved_timeout, BOOL *dpms)
+{
+ int timeout, interval, prefer_blank, allow_exp;
+ XGetScreenSaver(display, &timeout, &interval, &prefer_blank, &allow_exp);
+ *saved_timeout = timeout;
+
+#if SDL_VIDEO_DRIVER_X11_DPMS
+ if ( SDL_X11_HAVE_DPMS ) {
+ int dummy;
+ if ( DPMSQueryExtension(display, &dummy, &dummy) ) {
+ CARD16 state;
+ DPMSInfo(display, &state, dpms);
+ }
+ }
+#else
+ *dpms = 0;
+#endif /* SDL_VIDEO_DRIVER_X11_DPMS */
+}
+
+void X11_DisableScreenSaver(Display *display)
+{
+ int timeout, interval, prefer_blank, allow_exp;
+ XGetScreenSaver(display, &timeout, &interval, &prefer_blank, &allow_exp);
+ timeout = 0;
+ XSetScreenSaver(display, timeout, interval, prefer_blank, allow_exp);
+
+#if SDL_VIDEO_DRIVER_X11_DPMS
+ if ( SDL_X11_HAVE_DPMS ) {
+ int dummy;
+ if ( DPMSQueryExtension(display, &dummy, &dummy) ) {
+ DPMSDisable(display);
+ }
+ }
+#endif /* SDL_VIDEO_DRIVER_X11_DPMS */
+}
+
+void X11_RestoreScreenSaver(Display *display, int saved_timeout, BOOL dpms)
+{
+ int timeout, interval, prefer_blank, allow_exp;
+ XGetScreenSaver(display, &timeout, &interval, &prefer_blank, &allow_exp);
+ timeout = saved_timeout;
+ XSetScreenSaver(display, timeout, interval, prefer_blank, allow_exp);
+
+#if SDL_VIDEO_DRIVER_X11_DPMS
+ if ( SDL_X11_HAVE_DPMS ) {
+ int dummy;
+ if ( DPMSQueryExtension(display, &dummy, &dummy) ) {
+ if ( dpms ) {
+ DPMSEnable(display);
+ }
+ }
+ }
+#endif /* SDL_VIDEO_DRIVER_X11_DPMS */
+}
diff -r e49147870aac -r 14717b52abc0 src/video/x11/SDL_x11events_c.h
--- a/src/video/x11/SDL_x11events_c.h Mon May 01 06:58:33 2006 +0000
+++ b/src/video/x11/SDL_x11events_c.h Wed May 17 08:18:28 2006 +0000
@@ -28,3 +28,6 @@
extern void X11_PumpEvents(_THIS);
extern void X11_SetKeyboardState(Display *display, const char *key_vec);
+extern void X11_SaveScreenSaver(Display *display, int *saved_timeout, BOOL *dpms);
+extern void X11_DisableScreenSaver(Display *display);
+extern void X11_RestoreScreenSaver(Display *display, int saved_timeout, BOOL dpms);
diff -r e49147870aac -r 14717b52abc0 src/video/x11/SDL_x11gl.c
--- a/src/video/x11/SDL_x11gl.c Mon May 01 06:58:33 2006 +0000
+++ b/src/video/x11/SDL_x11gl.c Wed May 17 08:18:28 2006 +0000
@@ -46,6 +46,7 @@
#ifndef GLX_EXT_visual_rating
#define GLX_EXT_visual_rating
#define GLX_VISUAL_CAVEAT_EXT 0x20
+#define GLX_NONE_EXT 0x8000
#define GLX_SLOW_VISUAL_EXT 0x8001
#define GLX_NON_CONFORMANT_VISUAL_EXT 0x800D
#endif
@@ -182,7 +183,7 @@
if( this->gl_config.accelerated >= 0 &&
glXExtensionSupported(this, "GLX_EXT_visual_rating") ) {
attribs[i++] = GLX_VISUAL_CAVEAT_EXT;
- attribs[i++] = this->gl_config.accelerated ? GLX_NONE : GLX_DONT_CARE;
+ attribs[i++] = GLX_NONE_EXT;
}
#ifdef GLX_DIRECT_COLOR /* Try for a DirectColor visual for gamma support */
diff -r e49147870aac -r 14717b52abc0 src/video/x11/SDL_x11modes.c
--- a/src/video/x11/SDL_x11modes.c Mon May 01 06:58:33 2006 +0000
+++ b/src/video/x11/SDL_x11modes.c Wed May 17 08:18:28 2006 +0000
@@ -33,12 +33,22 @@
#include "SDL_x11modes_c.h"
#include "SDL_x11image_c.h"
-#if SDL_VIDEO_DRIVER_X11_XINERAMA
-#include "../Xext/extensions/Xinerama.h"
-#endif
+/*#define X11MODES_DEBUG*/
#define MAX(a, b) (a > b ? a : b)
+#if SDL_VIDEO_DRIVER_X11_XRANDR
+static int cmpmodelist(const void *va, const void *vb)
+{
+ const SDL_Rect *a = *(const SDL_Rect **)va;
+ const SDL_Rect *b = *(const SDL_Rect **)vb;
+ if ( a->w == b->w )
+ return b->h - a->h;
+ else
+ return b->w - a->w;
+}
+#endif
+
#if SDL_VIDEO_DRIVER_X11_VIDMODE
Bool SDL_NAME(XF86VidModeGetModeInfo)(Display *dpy, int scr, SDL_NAME(XF86VidModeModeInfo) *info)
{
@@ -86,18 +96,6 @@
}
#endif
-#if SDL_VIDEO_DRIVER_X11_XRANDR
-static int cmpmodelist(const void *va, const void *vb)
-{
- const SDL_Rect *a = *(const SDL_Rect **)va;
- const SDL_Rect *b = *(const SDL_Rect **)vb;
- if ( a->w == b->w )
- return b->h - a->h;
- else
- return b->w - a->w;
-}
-#endif
-
static void get_real_resolution(_THIS, int* w, int* h);
static void set_best_resolution(_THIS, int width, int height)
@@ -107,45 +105,37 @@
SDL_NAME(XF86VidModeModeLine) mode;
SDL_NAME(XF86VidModeModeInfo) **modes;
int i;
- int best_width = 0, best_height = 0;
int nmodes;
+ int best = -1;
if ( SDL_NAME(XF86VidModeGetModeLine)(SDL_Display, SDL_Screen, &i, &mode) &&
- SDL_NAME(XF86VidModeGetAllModeLines)(SDL_Display,SDL_Screen,&nmodes,&modes)){
-#ifdef XFREE86_DEBUG
- printf("Available modes (unsorted):\n");
- for ( i = 0; i < nmodes; ++i ) {
- printf("Mode %d: %d x %d @ %d\n", i,
- modes[i]->hdisplay, modes[i]->vdisplay,
- 1000 * modes[i]->dotclock / (modes[i]->htotal *
- modes[i]->vtotal) );
- }
-#endif
+ SDL_NAME(XF86VidModeGetAllModeLines)(SDL_Display,SDL_Screen,&nmodes,&modes) ) {
for ( i = 0; i < nmodes ; i++ ) {
if ( (modes[i]->hdisplay == width) &&
- (modes[i]->vdisplay == height) )
- goto match;
- }
- qsort(modes, nmodes, sizeof *modes, cmpmodes);
- for ( i = nmodes-1; i > 0 ; i-- ) {
- if ( ! best_width ) {
- if ( (modes[i]->hdisplay >= width) &&
- (modes[i]->vdisplay >= height) ) {
- best_width = modes[i]->hdisplay;
- best_height = modes[i]->vdisplay;
- }
- } else {
- if ( (modes[i]->hdisplay != best_width) ||
- (modes[i]->vdisplay != best_height) ) {
- i++;
- break;
+ (modes[i]->vdisplay == height) ) {
+ best = i;
+ break;
+ }
+ if ( modes[i]->hdisplay >= width &&
+ modes[i]->vdisplay >= height ) {
+ if ( best < 0 ||
+ (modes[i]->hdisplay < modes[best]->hdisplay &&
+ modes[i]->vdisplay <= modes[best]->vdisplay) ||
+ (modes[i]->vdisplay < modes[best]->vdisplay &&
+ modes[i]->hdisplay <= modes[best]->hdisplay) ) {
+ best = i;
}
}
}
- match:
- if ( (modes[i]->hdisplay != mode.hdisplay) ||
- (modes[i]->vdisplay != mode.vdisplay) ) {
- SDL_NAME(XF86VidModeSwitchToMode)(SDL_Display, SDL_Screen, modes[i]);
+ if ( best >= 0 &&
+ ((modes[best]->hdisplay != mode.hdisplay) ||
+ (modes[best]->vdisplay != mode.vdisplay)) ) {
+#ifdef X11MODES_DEBUG
+ printf("Best Mode %d: %d x %d @ %d\n", best,
+ modes[best]->hdisplay, modes[best]->vdisplay,
+ (modes[best]->htotal && modes[best]->vtotal) ? (1000 * modes[best]->dotclock / (modes[best]->htotal * modes[best]->vtotal)) : 0 );
+#endif
+ SDL_NAME(XF86VidModeSwitchToMode)(SDL_Display, SDL_Screen, modes[best]);
}
XFree(modes);
}
@@ -154,13 +144,13 @@
/* XiG */
#if SDL_VIDEO_DRIVER_X11_XME
-#ifdef XIG_DEBUG
- fprintf(stderr, "XME: set_best_resolution(): w = %d, h = %d\n",
- width, height);
-#endif
- if ( SDL_modelist ) {
+ if ( use_xme && SDL_modelist ) {
int i;
+#ifdef X11MODES_DEBUG
+ fprintf(stderr, "XME: set_best_resolution(): w = %d, h = %d\n",
+ width, height);
+#endif
for ( i=0; SDL_modelist[i]; ++i ) {
if ( (SDL_modelist[i]->w >= width) &&
(SDL_modelist[i]->h >= height) ) {
@@ -175,11 +165,11 @@
get_real_resolution(this, &w, &h);
if ( (SDL_modelist[i]->w != w) || (SDL_modelist[i]->h != h) ) {
-# ifdef XIG_DEBUG
+#ifdef X11MODES_DEBUG
fprintf(stderr, "XME: set_best_resolution: "
"XiGMiscChangeResolution: %d %d\n",
- SDL_modelist[s]->w, SDL_modelist[s]->h);
-# endif
+ SDL_modelist[i]->w, SDL_modelist[i]->h);
+#endif
XiGMiscChangeResolution(SDL_Display,
SDL_Screen,
0, /* view */
@@ -193,58 +183,73 @@
#endif /* SDL_VIDEO_DRIVER_X11_XME */
#if SDL_VIDEO_DRIVER_X11_XRANDR
- if ( use_xrandr ) {
-#ifdef XRANDR_DEBUG
+ if ( use_xrandr && SDL_modelist ) {
+#ifdef X11MODES_DEBUG
fprintf(stderr, "XRANDR: set_best_resolution(): w = %d, h = %d\n",
width, height);
#endif
- if ( SDL_modelist ) {
- int i, nsizes;
- XRRScreenSize *sizes;
+ int i, nsizes;
+ XRRScreenSize *sizes;
- /* find the smallest resolution that is at least as big as the user requested */
- sizes = XRRConfigSizes(screen_config, &nsizes);
- for ( i = (nsizes-1); i >= 0; i-- ) {
- if ( (SDL_modelist[i]->w >= width) &&
- (SDL_modelist[i]->h >= height) ) {
- break;
- }
+ /* find the smallest resolution that is at least as big as the user requested */
+ sizes = XRRConfigSizes(screen_config, &nsizes);
+ for ( i = (nsizes-1); i >= 0; i-- ) {
+ if ( (SDL_modelist[i]->w >= width) &&
+ (SDL_modelist[i]->h >= height) ) {
+ break;
}
+ }
- if ( i >= 0 && SDL_modelist[i] ) { /* found one, lets try it */
- int w, h;
+ if ( i >= 0 && SDL_modelist[i] ) { /* found one, lets try it */
+ int w, h;
- /* check current mode so we can avoid uneccessary mode changes */
- get_real_resolution(this, &w, &h);
+ /* check current mode so we can avoid uneccessary mode changes */
+ get_real_resolution(this, &w, &h);
- if ( (SDL_modelist[i]->w != w) || (SDL_modelist[i]->h != h) ) {
- int size_id;
+ if ( (SDL_modelist[i]->w != w) || (SDL_modelist[i]->h != h) ) {
+ int size_id;
-#ifdef XRANDR_DEBUG
- fprintf(stderr, "XRANDR: set_best_resolution: "
- "XXRSetScreenConfig: %d %d\n",
- SDL_modelist[i]->w, SDL_modelist[i]->h);
+#ifdef X11MODES_DEBUG
+ fprintf(stderr, "XRANDR: set_best_resolution: "
+ "XXRSetScreenConfig: %d %d\n",
+ SDL_modelist[i]->w, SDL_modelist[i]->h);
#endif
- /* find the matching size entry index */
- for ( size_id = 0; size_id < nsizes; ++size_id ) {
- if ( (sizes[size_id].width == SDL_modelist[i]->w) &&
- (sizes[size_id].height == SDL_modelist[i]->h) )
- break;
- }
+ /* find the matching size entry index */
+ for ( size_id = 0; size_id < nsizes; ++size_id ) {
+ if ( (sizes[size_id].width == SDL_modelist[i]->w) &&
+ (sizes[size_id].height == SDL_modelist[i]->h) )
+ break;
+ }
- XRRSetScreenConfig(SDL_Display, screen_config, SDL_Root,
- size_id, saved_rotation, CurrentTime);
- }
+ XRRSetScreenConfig(SDL_Display, screen_config, SDL_Root,
+ size_id, saved_rotation, CurrentTime);
}
}
}
#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
-
}
static void get_real_resolution(_THIS, int* w, int* h)
{
+#if SDL_VIDEO_DRIVER_X11_XME
+ if ( use_xme ) {
+ int ractive;
+ XiGMiscResolutionInfo *modelist;
+
+ XiGMiscQueryResolutions(SDL_Display, SDL_Screen,
+ 0, /* view */
+ &ractive, &modelist);
+ *w = modelist[ractive].width;
+ *h = modelist[ractive].height;
+#ifdef X11MODES_DEBUG
+ fprintf(stderr, "XME: get_real_resolution: w = %d h = %d\n", *w, *h);
+#endif
+ XFree(modelist);
+ return;
+ }
+#endif /* SDL_VIDEO_DRIVER_X11_XME */
+
#if SDL_VIDEO_DRIVER_X11_VIDMODE
if ( use_vidmode ) {
SDL_NAME(XF86VidModeModeLine) mode;
@@ -258,24 +263,6 @@
}
#endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */
-#if SDL_VIDEO_DRIVER_X11_XME
- if ( use_xme ) {
- int ractive;
- XiGMiscResolutionInfo *modelist;
-
- XiGMiscQueryResolutions(SDL_Display, SDL_Screen,
- 0, /* view */
- &ractive, &modelist);
- *w = modelist[ractive].width;
- *h = modelist[ractive].height;
-#ifdef XIG_DEBUG
- fprintf(stderr, "XME: get_real_resolution: w = %d h = %d\n", *w, *h);
-#endif
- XFree(modelist);
- return;
- }
-#endif /* SDL_VIDEO_DRIVER_X11_XME */
-
#if SDL_VIDEO_DRIVER_X11_XRANDR
if ( use_xrandr ) {
int nsizes;
@@ -291,7 +278,7 @@
*w = sizes[cur_size].width;
*h = sizes[cur_size].height;
}
-#ifdef XRANDR_DEBUG
+#ifdef X11MODES_DEBUG
fprintf(stderr, "XRANDR: get_real_resolution: w = %d h = %d\n", *w, *h);
#endif
return;
@@ -299,6 +286,14 @@
}
#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
+#if SDL_VIDEO_DRIVER_X11_XINERAMA
+ if ( use_xinerama ) {
+ *w = xinerama_info.width;
+ *h = xinerama_info.height;
+ return;
+ }
+#endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
+
*w = DisplayWidth(SDL_Display, SDL_Screen);
*h = DisplayHeight(SDL_Display, SDL_Screen);
}
@@ -360,10 +355,136 @@
/* Global for the error handler */
int vm_event, vm_error = -1;
+#if SDL_VIDEO_DRIVER_X11_XINERAMA
+static int CheckXinerama(_THIS, int *major, int *minor)
+{
+ const char *env;
+
+ /* Default the extension not available */
+ *major = *minor = 0;
+
+ /* Allow environment override */
+ env = getenv("SDL_VIDEO_X11_XINERAMA");
+ if ( env && !SDL_atoi(env) ) {
+ return 0;
+ }
+
+ /* Query the extension version */
+ if ( !SDL_NAME(XineramaQueryExtension)(SDL_Display, major, minor) ||
+ !SDL_NAME(XineramaIsActive)(SDL_Display) ) {
+ return 0;
+ }
+ return 1;
+}
+#endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
+
+#if SDL_VIDEO_DRIVER_X11_XRANDR
+static int CheckXRandR(_THIS, int *major, int *minor)
+{
+ const char *env;
+
+ /* Default the extension not available */
+ *major = *minor = 0;
+
+ /* Allow environment override */
+ env = getenv("SDL_VIDEO_X11_XRANDR");
+ if ( env && !SDL_atoi(env) ) {
+ return 0;
+ }
+
+ /* This defaults off now, due to KDE window maximize problems */
+ if ( !env ) {
+ return 0;
+ }
+
+ if ( !SDL_X11_HAVE_XRANDR ) {
+ return 0;
+ }
+
+ /* Query the extension version */
+ if ( !XRRQueryVersion(SDL_Display, major, minor) ) {
+ return 0;
+ }
+ return 1;
+}
+#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
+
+#if SDL_VIDEO_DRIVER_X11_VIDMODE
+static int CheckVidMode(_THIS, int *major, int *minor)
+{
+ const char *env;
+
+ /* Default the extension not available */
+ *major = *minor = 0;
+
+ /* Allow environment override */
+ env = getenv("SDL_VIDEO_X11_VIDMODE");
+ if ( env && !SDL_atoi(env) ) {
+ return 0;
+ }
+
+ /* Metro-X 4.3.0 and earlier has a broken implementation of
+ XF86VidModeGetAllModeLines() - it hangs the client.
+ */
+ if ( SDL_strcmp(ServerVendor(SDL_Display), "Metro Link Incorporated") == 0 ) {
+ FILE *metro_fp;
+
+ metro_fp = fopen("/usr/X11R6/lib/X11/Metro/.version", "r");
+ if ( metro_fp != NULL ) {
+ int major, minor, patch, version;
+ major = 0; minor = 0; patch = 0;
+ fscanf(metro_fp, "%d.%d.%d", &major, &minor, &patch);
+ fclose(metro_fp);
+ version = major*100+minor*10+patch;
+ if ( version < 431 ) {
+ return 0;
+ }
+ }
+ }
+
+ /* Query the extension version */
+ vm_error = -1;
+ if ( !SDL_NAME(XF86VidModeQueryExtension)(SDL_Display, &vm_event, &vm_error) ||
+ !SDL_NAME(XF86VidModeQueryVersion)(SDL_Display, major, minor) ) {
+ return 0;
+ }
+ return 1;
+}
+#endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */
+
+#if SDL_VIDEO_DRIVER_X11_XME
+static int CheckXME(_THIS, int *major, int *minor)
+{
+ const char *env;
+
+ /* Default the extension not available */
+ *major = *minor = 0;
+
+ /* Allow environment override */
+ env = getenv("SDL_VIDEO_X11_VIDMODE");
+ if ( env && !SDL_atoi(env) ) {
+ return 0;
+ }
+
+ /* Query the extension version */
+ if ( !XiGMiscQueryVersion(SDL_Display, major, minor) ) {
+ return 0;
+ }
+ return 1;
+}
+#endif /* SDL_VIDEO_DRIVER_X11_XME */
+
int X11_GetVideoModes(_THIS)
{
+#if SDL_VIDEO_DRIVER_X11_XINERAMA
+ int xinerama_major, xinerama_minor;
+#endif
+#if SDL_VIDEO_DRIVER_X11_XRANDR
+ int xrandr_major, xrandr_minor;
+ int nsizes;
+ XRRScreenSize *sizes;
+#endif
#if SDL_VIDEO_DRIVER_X11_VIDMODE
- int buggy_X11;
int vm_major, vm_minor;
int nmodes;
SDL_NAME(XF86VidModeModeInfo) **modes;
@@ -373,30 +494,90 @@
int ractive, nummodes;
XiGMiscResolutionInfo *modelist;
#endif
-#if SDL_VIDEO_DRIVER_X11_XRANDR
- int xrandr_major, xrandr_minor;
- int nsizes;
- XRRScreenSize *sizes;
-#endif
int i, n;
int screen_w;
int screen_h;
- vm_error = -1;
+ use_xinerama = 0;
+ use_xrandr = 0;
use_vidmode = 0;
- use_xrandr = 0;
+ use_xme = 0;
screen_w = DisplayWidth(SDL_Display, SDL_Screen);
screen_h = DisplayHeight(SDL_Display, SDL_Screen);
+#if SDL_VIDEO_DRIVER_X11_XINERAMA
+ /* Query Xinerama extention */
+ if ( CheckXinerama(this, &xinerama_major, &xinerama_minor) ) {
+ /* Find out which screen is the desired one */
+ int desired = 0;
+ int screens;
+ int w, h;
+ SDL_NAME(XineramaScreenInfo) *xinerama;
+
+ const char *variable = SDL_getenv("SDL_VIDEO_FULLSCREEN_HEAD");
+ if ( variable ) {
+ desired = SDL_atoi(variable);
+ }
+#ifdef X11MODES_DEBUG
+ printf("X11 detected Xinerama:\n");
+#endif
+ xinerama = SDL_NAME(XineramaQueryScreens)(SDL_Display, &screens);
+ for ( i = 0; i < screens; i++ ) {
+#ifdef X11MODES_DEBUG
+ printf("xinerama %d: %dx%d+%d+%d\n",
+ xinerama[i].screen_number,
+ xinerama[i].width, xinerama[i].height,
+ xinerama[i].x_org, xinerama[i].y_org);
+#endif
+ if ( xinerama[i].screen_number == desired ) {
+ use_xinerama = 1;
+ xinerama_info = xinerama[i];
+ }
+ }
+ XFree(xinerama);
+
+ if ( use_xinerama ) {
+ SDL_modelist = (SDL_Rect **)SDL_malloc(3*sizeof(SDL_Rect *));
+ if ( !SDL_modelist ) {
+ SDL_OutOfMemory();
+ return -1;
+ }
+
+ /* Add the full xinerama mode */
+ n = 0;
+ w = xinerama_info.width;
+ h = xinerama_info.height;
+ if ( screen_w > w || screen_h > h) {
+ SDL_modelist[n] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
+ if ( SDL_modelist[n] ) {
+ SDL_modelist[n]->x = 0;
+ SDL_modelist[n]->y = 0;
+ SDL_modelist[n]->w = screen_w;
+ SDL_modelist[n]->h = screen_h;
+ ++n;
+ }
+ }
+
+ /* Add the head xinerama mode */
+ SDL_modelist[n] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
+ if ( SDL_modelist[n] ) {
+ SDL_modelist[n]->x = 0;
+ SDL_modelist[n]->y = 0;
+ SDL_modelist[n]->w = w;
+ SDL_modelist[n]->h = h;
+ ++n;
+ }
+ SDL_modelist[n] = NULL;
+ }
+ }
+#endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
+
+#if SDL_VIDEO_DRIVER_X11_XRANDR
/* XRandR */
-#if SDL_VIDEO_DRIVER_X11_XRANDR
/* require at least XRandR v1.0 (arbitrary) */
- if ( ( SDL_X11_HAVE_XRANDR ) &&
- ( getenv("SDL_VIDEO_X11_NO_XRANDR") == NULL ) &&
- ( XRRQueryVersion(SDL_Display, &xrandr_major, &xrandr_minor) ) &&
- ( xrandr_major >= 1 ) ) {
-
-#ifdef XRANDR_DEBUG
+ if ( CheckXRandR(this, &xrandr_major, &xrandr_minor) && (xrandr_major >= 1) )
+ {
+#ifdef X11MODES_DEBUG
fprintf(stderr, "XRANDR: XRRQueryVersion: V%d.%d\n",
xrandr_major, xrandr_minor);
#endif
@@ -409,27 +590,36 @@
/* retrieve the list of resolution */
sizes = XRRConfigSizes(screen_config, &nsizes);
if (nsizes > 0) {
+ if ( SDL_modelist ) {
+ for ( i = 0; SDL_modelist[i]; ++i ) {
+ SDL_free(SDL_modelist[i]);
+ }
+ SDL_free(SDL_modelist);
+ }
SDL_modelist = (SDL_Rect **)malloc((nsizes+1)*sizeof(SDL_Rect *));
- if (SDL_modelist) {
- for ( i=0; i < nsizes; i++ ) {
- if ((SDL_modelist[i] =
- (SDL_Rect *)malloc(sizeof(SDL_Rect))) == NULL)
- break;
-#ifdef XRANDR_DEBUG
- fprintf(stderr, "XRANDR: mode = %4d, w = %4d, h = %4d\n",
- i, sizes[i].width, sizes[i].height);
+ if ( !SDL_modelist ) {
+ SDL_OutOfMemory();
+ return -1;
+ }
+ for ( i=0; i < nsizes; i++ ) {
+ if ((SDL_modelist[i] =
+ (SDL_Rect *)malloc(sizeof(SDL_Rect))) == NULL)
+ break;
+#ifdef X11MODES_DEBUG
+ fprintf(stderr, "XRANDR: mode = %4d, w = %4d, h = %4d\n",
+ i, sizes[i].width, sizes[i].height);
#endif
- SDL_modelist[i]->x = 0;
- SDL_modelist[i]->y = 0;
- SDL_modelist[i]->w = sizes[i].width;
- SDL_modelist[i]->h = sizes[i].height;
+ SDL_modelist[i]->x = 0;
+ SDL_modelist[i]->y = 0;
+ SDL_modelist[i]->w = sizes[i].width;
+ SDL_modelist[i]->h = sizes[i].height;
- }
- /* sort the mode list descending as SDL expects */
- qsort(SDL_modelist, nsizes, sizeof *SDL_modelist, cmpmodelist);
- SDL_modelist[i] = NULL; /* terminator */
}
+ /* sort the mode list descending as SDL expects */
+ SDL_qsort(SDL_modelist, nsizes, sizeof *SDL_modelist, cmpmodelist);
+ SDL_modelist[i] = NULL; /* terminator */
+
use_xrandr = xrandr_major * 100 + xrandr_minor;
saved_size_id = XRRConfigCurrentConfiguration(screen_config, &saved_rotation);
}
@@ -437,110 +627,73 @@
#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
#if SDL_VIDEO_DRIVER_X11_VIDMODE
- /* Metro-X 4.3.0 and earlier has a broken implementation of
- XF86VidModeGetAllModeLines() - it hangs the client.
- */
- buggy_X11 = 0;
- if ( SDL_strcmp(ServerVendor(SDL_Display), "Metro Link Incorporated") == 0 ) {
- FILE *metro_fp;
-
- metro_fp = fopen("/usr/X11R6/lib/X11/Metro/.version", "r");
- if ( metro_fp != NULL ) {
- int major, minor, patch, version;
- major = 0; minor = 0; patch = 0;
- fscanf(metro_fp, "%d.%d.%d", &major, &minor, &patch);
- version = major*100+minor*10+patch;
- if ( version < 431 ) {
- buggy_X11 = 1;
- }
- fclose(metro_fp);
- }
- }
-#if 0 /* Let's try this again... hopefully X servers have improved... */
-#if defined(__alpha__) || defined(__sparc64__) || defined(__powerpc__)
- /* The alpha, sparc64 and PPC XFree86 servers are also buggy */
- buggy_X11 = 1;
-#endif
-#endif
- /* Enumerate the available fullscreen modes */
- if ( ! buggy_X11 ) {
- if ( SDL_NAME(XF86VidModeQueryExtension)(SDL_Display, &vm_event, &vm_error) &&
- SDL_NAME(XF86VidModeQueryVersion)(SDL_Display, &vm_major, &vm_minor) ) {
-#ifdef BROKEN_XFREE86_4001
-#ifdef X_XF86VidModeGetDotClocks /* Compiled under XFree86 4.0 */
- /* Earlier X servers hang when doing vidmode */
- if ( vm_major < 2 ) {
-#ifdef XFREE86_DEBUG
- printf("Compiled under XFree86 4.0, server is XFree86 3.X\n");
-#endif
- buggy_X11 = 1;
- }
-#else
- /* XFree86 3.X code works with XFree86 4.0 servers */;
-#endif /* XFree86 4.0 */
-#endif /* XFree86 4.02 and newer are fixed wrt backwards compatibility */
- } else {
- buggy_X11 = 1;
- }
- }
- if ( ! buggy_X11 && ! use_xrandr &&
- SDL_NAME(XF86VidModeGetAllModeLines)(SDL_Display, SDL_Screen,&nmodes,&modes) ) {
-
-#ifdef XFREE86_DEBUG
- printf("Available modes: (sorted)\n");
+ /* XVidMode */
+ if ( !use_xrandr &&
+ (!use_xinerama || xinerama_info.screen_number == 0) &&
+ CheckVidMode(this, &vm_major, &vm_minor) &&
+ SDL_NAME(XF86VidModeGetAllModeLines)(SDL_Display, SDL_Screen,&nmodes,&modes) )
+ {
+#ifdef X11MODES_DEBUG
+ printf("VidMode modes: (unsorted)\n");
for ( i = 0; i < nmodes; ++i ) {
printf("Mode %d: %d x %d @ %d\n", i,
modes[i]->hdisplay, modes[i]->vdisplay,
- 1000 * modes[i]->dotclock / (modes[i]->htotal *
- modes[i]->vtotal) );
+ (modes[i]->htotal && modes[i]->vtotal) ? (1000 * modes[i]->dotclock / (modes[i]->htotal * modes[i]->vtotal)) : 0 );
}
#endif
-
- SDL_qsort(modes, nmodes, sizeof *modes, cmpmodes);
+ if ( SDL_modelist ) {
+ for ( i = 0; SDL_modelist[i]; ++i ) {
+ SDL_free(SDL_modelist[i]);
+ }
+ SDL_free(SDL_modelist);
+ }
SDL_modelist = (SDL_Rect **)SDL_malloc((nmodes+2)*sizeof(SDL_Rect *));
- if ( SDL_modelist ) {
- n = 0;
- for ( i=0; i 0 &&
- modes[i]->hdisplay == modes[i-1]->hdisplay &&
- modes[i]->vdisplay == modes[i-1]->vdisplay ) {
- continue;
- }
+ /* Eliminate duplicate modes with different refresh rates */
+ if ( i > 0 &&
+ modes[i]->hdisplay == modes[i-1]->hdisplay &&
+ modes[i]->vdisplay == modes[i-1]->vdisplay ) {
+ continue;
+ }
- /* Check to see if we should add the screen size (Xinerama) */
- w = modes[i]->hdisplay;
- h = modes[i]->vdisplay;
- if ( (screen_w * screen_h) >= (w * h) ) {
- if ( (screen_w != w) || (screen_h != h) ) {
- SDL_modelist[n] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
- if ( SDL_modelist[n] ) {
- SDL_modelist[n]->x = 0;
- SDL_modelist[n]->y = 0;
- SDL_modelist[n]->w = screen_w;
- SDL_modelist[n]->h = screen_h;
- ++n;
- }
+ /* Check to see if we should add the screen size (Xinerama) */
+ w = modes[i]->hdisplay;
+ h = modes[i]->vdisplay;
+ if ( (screen_w * screen_h) >= (w * h) ) {
+ if ( (screen_w != w) || (screen_h != h) ) {
+ SDL_modelist[n] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
+ if ( SDL_modelist[n] ) {
+ SDL_modelist[n]->x = 0;
+ SDL_modelist[n]->y = 0;
+ SDL_modelist[n]->w = screen_w;
+ SDL_modelist[n]->h = screen_h;
+ ++n;
}
- screen_w = 0;
- screen_h = 0;
}
+ screen_w = 0;
+ screen_h = 0;
+ }
- /* Add the size from the video mode list */
- SDL_modelist[n] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
- if ( SDL_modelist[n] == NULL ) {
- break;
- }
- SDL_modelist[n]->x = 0;
- SDL_modelist[n]->y = 0;
- SDL_modelist[n]->w = w;
- SDL_modelist[n]->h = h;
- ++n;
+ /* Add the size from the video mode list */
+ SDL_modelist[n] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
+ if ( SDL_modelist[n] == NULL ) {
+ break;
}
- SDL_modelist[n] = NULL;
+ SDL_modelist[n]->x = 0;
+ SDL_modelist[n]->y = 0;
+ SDL_modelist[n]->w = w;
+ SDL_modelist[n]->h = h;
+ ++n;
}
+ SDL_modelist[n] = NULL;
XFree(modes);
use_vidmode = vm_major * 100 + vm_minor;
@@ -548,71 +701,53 @@
}
#endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */
- /* XiG */
#if SDL_VIDEO_DRIVER_X11_XME
+ /* XiG */
+ modelist = NULL;
/* first lets make sure we have the extension, and it's at least v2.0 */
- if (XiGMiscQueryVersion(SDL_Display, &xme_major, &xme_minor)) {
-#ifdef XIG_DEBUG
- fprintf(stderr, "XME: XiGMiscQueryVersion: V%d.%d\n",
- xme_major, xme_minor);
-#endif
- /* work around a XiGMisc bogosity in our version of libXext */
- if (xme_major == 0 && xme_major == 0) {
- /* Ideally libxme would spit this out, but the problem is that
- the right Query func will never be called if using the bogus
- libXext version.
- */
- fprintf(stderr,
-"XME: If you are using Xi Graphics CDE and a Summit server, you need to\n"
-"XME: get the libXext update from Xi's ftp site before fullscreen switching\n"
-"XME: will work. Fullscreen switching is only supported on Summit Servers\n");
- }
- } else {
- /* not there. Bummer. */
- xme_major = xme_minor = 0;
- }
-
- modelist = NULL;
- if (xme_major >= 2 && (nummodes = XiGMiscQueryResolutions(SDL_Display,
- SDL_Screen,
- 0, /* view */
- &ractive,
- &modelist)) > 1)
+ if ( CheckXME(this, &xme_major, &xme_minor) && xme_major >= 2 &&
+ (nummodes = XiGMiscQueryResolutions(SDL_Display, SDL_Screen,
+ 0, /* view */
+ &ractive, &modelist)) > 1 )
{ /* then we actually have some */
int j;
-#ifdef XIG_DEBUG
+ /* We get the list already sorted in descending order.
+ We'll copy it in reverse order so SDL is happy */
+#ifdef X11MODES_DEBUG
fprintf(stderr, "XME: nummodes = %d, active mode = %d\n",
nummodes, ractive);
#endif
-
+ if ( SDL_modelist ) {
+ for ( i = 0; SDL_modelist[i]; ++i ) {
+ SDL_free(SDL_modelist[i]);
+ }
+ SDL_free(SDL_modelist);
+ }
SDL_modelist = (SDL_Rect **)SDL_malloc((nummodes+1)*sizeof(SDL_Rect *));
+ if ( !SDL_modelist ) {
+ SDL_OutOfMemory();
+ return -1;
+ }
+ for ( i=0, j=nummodes-1; j>=0; i++, j-- ) {
+ if ((SDL_modelist[i] =
+ (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect))) == NULL)
+ break;
+#ifdef X11MODES_DEBUG
+ fprintf(stderr, "XME: mode = %4d, w = %4d, h = %4d\n",
+ i, modelist[i].width, modelist[i].height);
+#endif
+
+ SDL_modelist[i]->x = 0;
+ SDL_modelist[i]->y = 0;
+ SDL_modelist[i]->w = modelist[j].width;
+ SDL_modelist[i]->h = modelist[j].height;
+
+ }
+ SDL_modelist[i] = NULL; /* terminator */
- /* we get the list already sorted in */
- /* descending order. We'll copy it in */
- /* reverse order so SDL is happy */
- if (SDL_modelist) {
- for ( i=0, j=nummodes-1; j>=0; i++, j-- ) {
- if ((SDL_modelist[i] =
- (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect))) == NULL)
- break;
-#ifdef XIG_DEBUG
- fprintf(stderr, "XME: mode = %4d, w = %4d, h = %4d\n",
- i, modelist[i].width, modelist[i].height);
-#endif
-
- SDL_modelist[i]->x = 0;
- SDL_modelist[i]->y = 0;
- SDL_modelist[i]->w = modelist[j].width;
- SDL_modelist[i]->h = modelist[j].height;
-
- }
- SDL_modelist[i] = NULL; /* terminator */
- }
- use_xme = 1;
+ use_xme = xme_major * 100 + xme_minor;
saved_res = modelist[ractive]; /* save the current resolution */
- } else {
- use_xme = 0;
}
if ( modelist ) {
XFree(modelist);
@@ -668,31 +803,38 @@
if ( SDL_modelist == NULL ) {
SDL_modelist = (SDL_Rect **)SDL_malloc((1+1)*sizeof(SDL_Rect *));
- if ( SDL_modelist ) {
- n = 0;
- SDL_modelist[n] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
- if ( SDL_modelist[n] ) {
- SDL_modelist[n]->x = 0;
- SDL_modelist[n]->y = 0;
- SDL_modelist[n]->w = screen_w;
- SDL_modelist[n]->h = screen_h;
- ++n;
- }
- SDL_modelist[n] = NULL;
+ if ( !SDL_modelist ) {
+ SDL_OutOfMemory();
+ return -1;
}
+ n = 0;
+ SDL_modelist[n] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
+ if ( SDL_modelist[n] ) {
+ SDL_modelist[n]->x = 0;
+ SDL_modelist[n]->y = 0;
+ SDL_modelist[n]->w = screen_w;
+ SDL_modelist[n]->h = screen_h;
+ ++n;
+ }
+ SDL_modelist[n] = NULL;
}
-#if defined(XFREE86_DEBUG) || defined(XIG_DEBUG)
- if ( use_vidmode ) {
- printf("XFree86 VidMode is enabled\n");
+#ifdef X11MODES_DEBUG
+ if ( use_xinerama ) {
+ printf("Xinerama is enabled\n");
}
-#if SDL_VIDEO_DRIVER_X11_XME
- if ( use_xme )
- printf("Xi Graphics XME fullscreen is enabled\n");
- else
- printf("Xi Graphics XME fullscreen is not available\n");
-#endif
+ if ( use_xrandr ) {
+ printf("XRandR is enabled\n");
+ }
+
+ if ( use_vidmode ) {
+ printf("VidMode is enabled\n");
+ }
+
+ if ( use_xme ) {
+ printf("Xi Graphics XME fullscreen is enabled\n");
+ }
if ( SDL_modelist ) {
printf("X11 video mode list:\n");
@@ -700,46 +842,7 @@
printf("\t%dx%d\n", SDL_modelist[i]->w, SDL_modelist[i]->h);
}
}
-#endif /* XFREE86_DEBUG || XIG_DEBUG */
-
- /* The default X/Y fullscreen offset is 0/0 */
- xinerama_x = 0;
- xinerama_y = 0;
-
-#if SDL_VIDEO_DRIVER_X11_XINERAMA
- /* Query Xinerama extention */
- if ( SDL_NAME(XineramaQueryExtension)(SDL_Display, &i, &i) &&
- SDL_NAME(XineramaIsActive)(SDL_Display) ) {
- /* Find out which screen is the desired one */
- int desired = 0;
- int screens;
- SDL_NAME(XineramaScreenInfo) *xinerama;
-
-#ifdef XINERAMA_DEBUG
- printf("X11 detected Xinerama:\n");
-#endif
-#if 0 /* Apparently the vidmode extension doesn't work with Xinerama */
- const char *variable = SDL_getenv("SDL_VIDEO_X11_XINERAMA_SCREEN");
- if ( variable ) {
- desired = atoi(variable);
- }
-#endif
- xinerama = SDL_NAME(XineramaQueryScreens)(SDL_Display, &screens);
- for ( i = 0; i < screens; i++ ) {
-#ifdef XINERAMA_DEBUG
- printf("xinerama %d: %dx%d+%d+%d\n",
- xinerama[i].screen_number,
- xinerama[i].width, xinerama[i].height,
- xinerama[i].x_org, xinerama[i].y_org);
-#endif
- if ( xinerama[i].screen_number == desired ) {
- xinerama_x = xinerama[i].x_org;
- xinerama_y = xinerama[i].y_org;
- }
- }
- XFree(xinerama);
- }
-#endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
+#endif /* X11MODES_DEBUG */
return 0;
}
@@ -789,7 +892,7 @@
int X11_ResizeFullScreen(_THIS)
{
- int x, y;
+ int x = 0, y = 0;
int real_w, real_h;
int screen_w;
int screen_h;
@@ -797,8 +900,14 @@
screen_w = DisplayWidth(SDL_Display, SDL_Screen);
screen_h = DisplayHeight(SDL_Display, SDL_Screen);
- x = xinerama_x;
- y = xinerama_y;
+#if SDL_VIDEO_DRIVER_X11_VIDMODE
+ if ( use_xinerama &&
+ window_w <= xinerama_info.width &&
+ window_h <= xinerama_info.height ) {
+ x = xinerama_info.x_org;
+ y = xinerama_info.y_org;
+ }
+#endif
if ( currently_fullscreen ) {
/* Switch resolution and cover it with the FSwindow */
move_cursor_to(this, x, y);
@@ -840,6 +949,7 @@
Window tmpwin, *windows;
int i, nwindows;
#endif
+ int x = 0, y = 0;
int real_w, real_h;
int screen_w;
int screen_h;
@@ -852,6 +962,14 @@
/* Ungrab the input so that we can move the mouse around */
X11_GrabInputNoLock(this, SDL_GRAB_OFF);
+#if SDL_VIDEO_DRIVER_X11_VIDMODE
+ if ( use_xinerama &&
+ window_w <= xinerama_info.width &&
+ window_h <= xinerama_info.height ) {
+ x = xinerama_info.x_org;
+ y = xinerama_info.y_org;
+ }
+#endif
/* Map the fullscreen window to blank the screen */
screen_w = DisplayWidth(SDL_Display, SDL_Screen);
screen_h = DisplayHeight(SDL_Display, SDL_Screen);
@@ -863,7 +981,7 @@
real_h = MAX(real_h, screen_h);
}
XMoveResizeWindow(SDL_Display, FSwindow,
- xinerama_x, xinerama_y, real_w, real_h);
+ x, y, real_w, real_h);
XMapRaised(SDL_Display, FSwindow);
X11_WaitMapped(this, FSwindow);
@@ -908,8 +1026,9 @@
if ( SDL_XColorMap ) {
XInstallColormap(SDL_Display, SDL_XColorMap);
}
- if ( okay )
+ if ( okay ) {
X11_GrabInputNoLock(this, this->input_grab | SDL_GRAB_FULLSCREEN);
+ }
/* We may need to refresh the screen at this point (no backing store)
We also don't get an event, which is why we explicitly refresh. */
diff -r e49147870aac -r 14717b52abc0 src/video/x11/SDL_x11sym.h
--- a/src/video/x11/SDL_x11sym.h Mon May 01 06:58:33 2006 +0000
+++ b/src/video/x11/SDL_x11sym.h Wed May 17 08:18:28 2006 +0000
@@ -56,9 +56,9 @@
SDL_X11_SYM(int,XGetErrorDatabaseText,(Display* a,_Xconst char* b,_Xconst char* c,_Xconst char* d,char* e,int f),(a,b,c,d,e,f),return)
SDL_X11_SYM(XModifierKeymap*,XGetModifierMapping,(Display* a),(a),return)
SDL_X11_SYM(int,XGetPointerControl,(Display* a,int* b,int* c,int* d),(a,b,c,d),return)
+SDL_X11_SYM(int,XGetScreenSaver,(Display* a,int* b,int* c,int* d, int* e),(a,b,c,d,e),return)
SDL_X11_SYM(XVisualInfo*,XGetVisualInfo,(Display* a,long b,XVisualInfo* c,int* d),(a,b,c,d),return)
SDL_X11_SYM(XWMHints*,XGetWMHints,(Display* a,Window b),(a,b),return)
-SDL_X11_SYM(Status,XGetTextProperty,(Display* a,Window b,XTextProperty* c,Atom d),(a,b,c,d),return)
SDL_X11_SYM(Status,XGetWindowAttributes,(Display* a,Window b,XWindowAttributes* c),(a,b,c),return)
SDL_X11_SYM(int,XGrabKeyboard,(Display* a,Window b,Bool c,int d,int e,Time f),(a,b,c,d,e,f),return)
SDL_X11_SYM(int,XGrabPointer,(Display* a,Window b,Bool c,unsigned int d,int e,int f,Window g,Cursor h,Time i),(a,b,c,d,e,f,g,h,i),return)
@@ -91,6 +91,7 @@
SDL_X11_SYM(int,XSetClassHint,(Display* a,Window b,XClassHint* c),(a,b,c),return)
SDL_X11_SYM(XErrorHandler,XSetErrorHandler,(XErrorHandler a),(a),return)
SDL_X11_SYM(XIOErrorHandler,XSetIOErrorHandler,(XIOErrorHandler a),(a),return)
+SDL_X11_SYM(int,XSetScreenSaver,(Display* a,int b,int c,int d,int e),(a,b,c,d,e),return)
SDL_X11_SYM(int,XSetTransientForHint,(Display* a,Window b,Window c),(a,b,c),return)
SDL_X11_SYM(int,XSetWMHints,(Display* a,Window b,XWMHints* c),(a,b,c),return)
SDL_X11_SYM(void,XSetTextProperty,(Display* a,Window b,XTextProperty* c,Atom d),(a,b,c,d),)
@@ -187,5 +188,14 @@
SDL_X11_SYM(void,XRRFreeScreenConfigInfo,(XRRScreenConfiguration *config),(config),)
#endif
+/* DPMS support */
+#if SDL_VIDEO_DRIVER_X11_DPMS
+SDL_X11_MODULE(DPMS)
+SDL_X11_SYM(Status,DPMSQueryExtension,(Display *dpy,int *major_versionp,int *minor_versionp),(dpy,major_versionp,minor_versionp),return)
+SDL_X11_SYM(Status,DPMSInfo,(Display *dpy,CARD16 *state,BOOL *onoff),(dpy,state,onoff),return)
+SDL_X11_SYM(Status,DPMSEnable,(Display *dpy),(dpy),return)
+SDL_X11_SYM(Status,DPMSDisable,(Display *dpy),(dpy),return)
+#endif
+
/* end of SDL_x11sym.h ... */
diff -r e49147870aac -r 14717b52abc0 src/video/x11/SDL_x11video.c
--- a/src/video/x11/SDL_x11video.c Mon May 01 06:58:33 2006 +0000
+++ b/src/video/x11/SDL_x11video.c Wed May 17 08:18:28 2006 +0000
@@ -197,7 +197,7 @@
(((e->error_code == BadRequest)&&(e->request_code == vm_error)) ||
((e->error_code > vm_error) &&
(e->error_code <= (vm_error+XF86VidModeNumberErrors)))) ) {
-#ifdef XFREE86_DEBUG
+#ifdef X11_DEBUG
{ char errmsg[1024];
XGetErrorText(d, e->error_code, errmsg, sizeof(errmsg));
printf("VidMode error: %s\n", errmsg);
@@ -212,7 +212,7 @@
if ( (dga_error >= 0) &&
((e->error_code > dga_error) &&
(e->error_code <= (dga_error+XF86DGANumberErrors))) ) {
-#ifdef XFREE86_DEBUG
+#ifdef X11_DEBUG
{ char errmsg[1024];
XGetErrorText(d, e->error_code, errmsg, sizeof(errmsg));
printf("DGA error: %s\n", errmsg);
@@ -244,7 +244,7 @@
static int (*Xext_handler)(Display *, _Xconst char *, _Xconst char *) = NULL;
static int xext_errhandler(Display *d, _Xconst char *ext, _Xconst char *reason)
{
-#ifdef XFREE86_DEBUG
+#ifdef X11_DEBUG
printf("Xext error inside SDL (may be harmless):\n");
printf(" Extension \"%s\" %s on display \"%s\".\n",
ext, reason, XDisplayString(d));
@@ -310,18 +310,14 @@
/* Create auxiliary (toplevel) windows with the current visual */
static void create_aux_windows(_THIS)
{
- Atom _NET_WM_NAME;
- Atom _NET_WM_ICON_NAME;
+ int x = 0, y = 0;
char classname[1024];
XSetWindowAttributes xattr;
XWMHints *hints;
- XTextProperty titleprop, titlepropUTF8, iconprop, iconpropUTF8;
int def_vis = (SDL_Visual == DefaultVisual(SDL_Display, SDL_Screen));
/* Look up some useful Atoms */
WM_DELETE_WINDOW = XInternAtom(SDL_Display, "WM_DELETE_WINDOW", False);
- _NET_WM_NAME = XInternAtom(SDL_Display, "_NET_WM_NAME", False);
- _NET_WM_ICON_NAME = XInternAtom(SDL_Display, "_NET_WM_ICON_NAME", False);
/* Don't create any extra windows if we are being managed */
if ( SDL_windowid ) {
@@ -333,13 +329,19 @@
if(FSwindow)
XDestroyWindow(SDL_Display, FSwindow);
+#if SDL_VIDEO_DRIVER_X11_VIDMODE
+ if ( use_xinerama ) {
+ x = xinerama_info.x_org;
+ y = xinerama_info.y_org;
+ }
+#endif
xattr.override_redirect = True;
xattr.background_pixel = def_vis ? BlackPixel(SDL_Display, SDL_Screen) : 0;
xattr.border_pixel = 0;
xattr.colormap = SDL_XColorMap;
FSwindow = XCreateWindow(SDL_Display, SDL_Root,
- xinerama_x, xinerama_y, 32, 32, 0,
+ x, y, 32, 32, 0,
this->hidden->depth, InputOutput, SDL_Visual,
CWOverrideRedirect | CWBackPixel | CWBorderPixel
| CWColormap,
@@ -365,21 +367,16 @@
}
hints = NULL;
- titleprop.value = titlepropUTF8.value = NULL;
- iconprop.value = iconpropUTF8.value = NULL;
if(WMwindow) {
/* All window attributes must survive the recreation */
hints = XGetWMHints(SDL_Display, WMwindow);
- XGetTextProperty(SDL_Display, WMwindow, &titleprop, XA_WM_NAME);
- XGetTextProperty(SDL_Display, WMwindow, &titlepropUTF8, _NET_WM_NAME);
- XGetTextProperty(SDL_Display, WMwindow, &iconprop, XA_WM_ICON_NAME);
- XGetTextProperty(SDL_Display, WMwindow, &iconpropUTF8, _NET_WM_ICON_NAME);
XDestroyWindow(SDL_Display, WMwindow);
}
/* Create the window for windowed management */
/* (reusing the xattr structure above) */
- WMwindow = XCreateWindow(SDL_Display, SDL_Root, 0, 0, 32, 32, 0,
+ WMwindow = XCreateWindow(SDL_Display, SDL_Root,
+ x, y, 32, 32, 0,
this->hidden->depth, InputOutput, SDL_Visual,
CWBackPixel | CWBorderPixel | CWColormap,
&xattr);
@@ -392,22 +389,7 @@
}
XSetWMHints(SDL_Display, WMwindow, hints);
XFree(hints);
- if(titleprop.value) {
- XSetTextProperty(SDL_Display, WMwindow, &titleprop, XA_WM_NAME);
- XFree(titleprop.value);
- }
- if(titlepropUTF8.value) {
- XSetTextProperty(SDL_Display, WMwindow, &titlepropUTF8, _NET_WM_NAME);
- XFree(titlepropUTF8.value);
- }
- if(iconprop.value) {
- XSetTextProperty(SDL_Display, WMwindow, &iconprop, XA_WM_ICON_NAME);
- XFree(iconprop.value);
- }
- if(iconpropUTF8.value) {
- XSetTextProperty(SDL_Display, WMwindow, &iconpropUTF8, _NET_WM_ICON_NAME);
- XFree(iconpropUTF8.value);
- }
+ X11_SetCaptionNoLock(this, this->wm_title, this->wm_icon);
XSelectInput(SDL_Display, WMwindow,
FocusChangeMask | KeyPressMask | KeyReleaseMask
@@ -562,6 +544,10 @@
}
X11_SaveVidModeGamma(this);
+ /* Save DPMS and screensaver settings */
+ X11_SaveScreenSaver(SDL_Display, &screensaver_timeout, &dpms_enabled);
+ X11_DisableScreenSaver(SDL_Display);
+
/* See if we have been passed a window to use */
SDL_windowid = SDL_getenv("SDL_WINDOWID");
@@ -1382,11 +1368,15 @@
SDL_free(SDL_iconcolors);
SDL_iconcolors = NULL;
}
+
/* Restore gamma settings if they've changed */
if ( SDL_GetAppState() & SDL_APPACTIVE ) {
X11_SwapVidModeGamma(this);
}
+ /* Restore DPMS and screensaver settings */
+ X11_RestoreScreenSaver(SDL_Display, screensaver_timeout, dpms_enabled);
+
/* Free that blank cursor */
if ( SDL_BlankCursor != NULL ) {
this->FreeWMCursor(this, SDL_BlankCursor);
diff -r e49147870aac -r 14717b52abc0 src/video/x11/SDL_x11video.h
--- a/src/video/x11/SDL_x11video.h Mon May 01 06:58:33 2006 +0000
+++ b/src/video/x11/SDL_x11video.h Wed May 17 08:18:28 2006 +0000
@@ -34,14 +34,20 @@
#if SDL_VIDEO_DRIVER_X11_DGAMOUSE
#include "../Xext/extensions/xf86dga.h"
#endif
+#if SDL_VIDEO_DRIVER_X11_XINERAMA
+#include "../Xext/extensions/Xinerama.h"
+#endif
+#if SDL_VIDEO_DRIVER_X11_XRANDR
+#include
+#endif
#if SDL_VIDEO_DRIVER_X11_VIDMODE
#include "../Xext/extensions/xf86vmode.h"
#endif
#if SDL_VIDEO_DRIVER_X11_XME
#include "../Xext/extensions/xme.h"
#endif
-#if SDL_VIDEO_DRIVER_X11_XRANDR
-#include
+#if SDL_VIDEO_DRIVER_X11_DPMS
+#include
#endif
#include "SDL_x11dyn.h"
@@ -109,6 +115,14 @@
int depth; /* current visual depth (not bpp) */
/* Variables used by the X11 video mode code */
+#if SDL_VIDEO_DRIVER_X11_XINERAMA
+ SDL_NAME(XineramaScreenInfo) xinerama_info;
+#endif
+#if SDL_VIDEO_DRIVER_X11_XRANDR
+ XRRScreenConfiguration* screen_config;
+ int saved_size_id;
+ Rotation saved_rotation;
+#endif
#if SDL_VIDEO_DRIVER_X11_VIDMODE
SDL_NAME(XF86VidModeModeInfo) saved_mode;
struct {
@@ -116,19 +130,13 @@
} saved_view;
#endif
#if SDL_VIDEO_DRIVER_X11_XME /* XiG XME fullscreen */
- int use_xme;
XiGMiscResolutionInfo saved_res;
#endif
-#if SDL_VIDEO_DRIVER_X11_XRANDR
- XRRScreenConfiguration* screen_config;
- int saved_size_id;
- Rotation saved_rotation;
-#endif
- int xinerama_x;
- int xinerama_y;
+ int use_xinerama;
+ int use_xrandr;
int use_vidmode;
- int use_xrandr;
+ int use_xme;
int currently_fullscreen;
/* Automatic mode switching support (entering/leaving fullscreen) */
@@ -146,6 +154,10 @@
int gamma_changed; /* flag: has VidMode gamma been modified? */
short *iconcolors; /* List of colors used by the icon */
+
+ /* Screensaver settings */
+ int screensaver_timeout;
+ BOOL dpms_enabled;
};
/* Old variable names */
@@ -174,17 +186,17 @@
#define mouse_accel (this->hidden->mouse_accel)
#define mouse_relative (this->hidden->mouse_relative)
#define SDL_modelist (this->hidden->modelist)
+#define xinerama_info (this->hidden->xinerama_info)
#define saved_mode (this->hidden->saved_mode)
#define saved_view (this->hidden->saved_view)
-#define use_xme (this->hidden->use_xme)
#define saved_res (this->hidden->saved_res)
-#define use_xrandr (this->hidden->use_xrandr)
#define screen_config (this->hidden->screen_config)
#define saved_size_id (this->hidden->saved_size_id)
#define saved_rotation (this->hidden->saved_rotation)
-#define xinerama_x (this->hidden->xinerama_x)
-#define xinerama_y (this->hidden->xinerama_y)
+#define use_xinerama (this->hidden->use_xinerama)
#define use_vidmode (this->hidden->use_vidmode)
+#define use_xrandr (this->hidden->use_xrandr)
+#define use_xme (this->hidden->use_xme)
#define currently_fullscreen (this->hidden->currently_fullscreen)
#define switch_waiting (this->hidden->switch_waiting)
#define switch_time (this->hidden->switch_time)
@@ -196,6 +208,8 @@
#define gamma_saved (this->hidden->gamma_saved)
#define gamma_changed (this->hidden->gamma_changed)
#define SDL_iconcolors (this->hidden->iconcolors)
+#define screensaver_timeout (this->hidden->screensaver_timeout)
+#define dpms_enabled (this->hidden->dpms_enabled)
/* Some versions of XFree86 have bugs - detect if this is one of them */
#define BUGGY_XFREE86(condition, buggy_version) \
((SDL_strcmp(ServerVendor(SDL_Display), "The XFree86 Project, Inc") == 0) && \
diff -r e49147870aac -r 14717b52abc0 src/video/x11/SDL_x11wm.c
--- a/src/video/x11/SDL_x11wm.c Mon May 01 06:58:33 2006 +0000
+++ b/src/video/x11/SDL_x11wm.c Wed May 17 08:18:28 2006 +0000
@@ -240,7 +240,7 @@
SDL_FreeSurface(sicon);
}
-void X11_SetCaption(_THIS, const char *title, const char *icon)
+void X11_SetCaptionNoLock(_THIS, const char *title, const char *icon)
{
XTextProperty titleprop, iconprop;
Status status;
@@ -256,9 +256,6 @@
}
#endif
- /* Lock the event thread, in multi-threading environments */
- SDL_Lock_EventThread();
-
if ( title != NULL ) {
char *title_latin1 = SDL_iconv_utf8_latin1((char *)title);
if ( !title_latin1 ) {
@@ -306,7 +303,12 @@
#endif
}
XSync(SDL_Display, False);
+}
+void X11_SetCaption(_THIS, const char *title, const char *icon)
+{
+ SDL_Lock_EventThread();
+ X11_SetCaptionNoLock(this, title, icon);
SDL_Unlock_EventThread();
}
@@ -344,7 +346,7 @@
#if 0 /* We'll wait here until we actually grab, otherwise behavior undefined */
for ( numtries = 0; numtries < 10; ++numtries ) {
#else
- while ( 1 ) {
+ for ( ; ; ) {
#endif
result = XGrabPointer(SDL_Display, SDL_Window, True, 0,
GrabModeAsync, GrabModeAsync,
diff -r e49147870aac -r 14717b52abc0 src/video/x11/SDL_x11wm_c.h
--- a/src/video/x11/SDL_x11wm_c.h Mon May 01 06:58:33 2006 +0000
+++ b/src/video/x11/SDL_x11wm_c.h Wed May 17 08:18:28 2006 +0000
@@ -24,6 +24,7 @@
#include "SDL_x11video.h"
/* Functions to be exported */
+extern void X11_SetCaptionNoLock(_THIS, const char *title, const char *icon);
extern void X11_SetCaption(_THIS, const char *title, const char *icon);
extern void X11_SetIcon(_THIS, SDL_Surface *icon, Uint8 *mask);
extern int X11_IconifyWindow(_THIS);
diff -r e49147870aac -r 14717b52abc0 src/video/xbios/SDL_xbios.c
--- a/src/video/xbios/SDL_xbios.c Mon May 01 06:58:33 2006 +0000
+++ b/src/video/xbios/SDL_xbios.c Wed May 17 08:18:28 2006 +0000
@@ -418,6 +418,7 @@
/* Determine the current screen size */
if ( XBIOS_nummodes > 0 ) {
+ /* FIXME: parse video mode list to search for current mode */
this->info.current_w = XBIOS_modelist[0].width;
this->info.current_h = XBIOS_modelist[0].height;
}
diff -r e49147870aac -r 14717b52abc0 test/acinclude.m4
--- a/test/acinclude.m4 Mon May 01 06:58:33 2006 +0000
+++ b/test/acinclude.m4 Wed May 17 08:18:28 2006 +0000
@@ -20,19 +20,21 @@
, enable_sdltest=yes)
if test x$sdl_exec_prefix != x ; then
- sdl_args="$sdl_args --exec-prefix=$sdl_exec_prefix"
- if test x${SDL_CONFIG+set} != xset ; then
- SDL_CONFIG=$sdl_exec_prefix/bin/sdl-config
- fi
+ sdl_args="$sdl_args --exec-prefix=$sdl_exec_prefix"
+ if test x${SDL_CONFIG+set} != xset ; then
+ SDL_CONFIG=$sdl_exec_prefix/bin/sdl-config
+ fi
fi
if test x$sdl_prefix != x ; then
- sdl_args="$sdl_args --prefix=$sdl_prefix"
- if test x${SDL_CONFIG+set} != xset ; then
- SDL_CONFIG=$sdl_prefix/bin/sdl-config
- fi
+ sdl_args="$sdl_args --prefix=$sdl_prefix"
+ if test x${SDL_CONFIG+set} != xset ; then
+ SDL_CONFIG=$sdl_prefix/bin/sdl-config
+ fi
fi
- PATH="$prefix/bin:$prefix/usr/bin:$PATH"
+ if test "x$prefix" != xNONE; then
+ PATH="$prefix/bin:$prefix/usr/bin:$PATH"
+ fi
AC_PATH_PROG(SDL_CONFIG, sdl-config, no, [$PATH])
min_sdl_version=ifelse([$1], ,0.11.0,$1)
AC_MSG_CHECKING(for SDL - version >= $min_sdl_version)
diff -r e49147870aac -r 14717b52abc0 test/autogen.sh
--- a/test/autogen.sh Mon May 01 06:58:33 2006 +0000
+++ b/test/autogen.sh Wed May 17 08:18:28 2006 +0000
@@ -3,7 +3,7 @@
# Regenerate configuration files
cp acinclude.m4 aclocal.m4
found=false
-for autoconf in autoconf autoconf259
+for autoconf in autoconf autoconf259 autoconf-2.59
do if which $autoconf >/dev/null 2>&1; then $autoconf && found=true; break; fi
done
if test x$found = xfalse; then
diff -r e49147870aac -r 14717b52abc0 test/configure.in
--- a/test/configure.in Mon May 01 06:58:33 2006 +0000
+++ b/test/configure.in Wed May 17 08:18:28 2006 +0000
@@ -28,7 +28,7 @@
*-*-darwin* )
EXE=""
MATHLIB=""
- SYS_GL_LIBS=""
+ SYS_GL_LIBS="-Wl,-framework,OpenGL"
;;
*-*-aix*)
EXE=""
diff -r e49147870aac -r 14717b52abc0 test/gcc-fat.sh
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/gcc-fat.sh Wed May 17 08:18:28 2006 +0000
@@ -0,0 +1,110 @@
+#!/bin/sh
+#
+# Build Universal binaries on Mac OS X, thanks Ryan!
+#
+# Usage: ./configure CC="sh gcc-fat.sh" && make && rm -rf ppc x86
+
+# PowerPC compiler flags (10.2 runtime compatibility)
+GCC_COMPILE_PPC="gcc-3.3 -arch ppc \
+-DMAC_OS_X_VERSION_MIN_REQUIRED=1020 \
+-nostdinc \
+-F/Developer/SDKs/MacOSX10.2.8.sdk/System/Library/Frameworks \
+-I/Developer/SDKs/MacOSX10.2.8.sdk/usr/include/gcc/darwin/3.3 \
+-isystem /Developer/SDKs/MacOSX10.2.8.sdk/usr/include"
+
+GCC_LINK_PPC="\
+-L/Developer/SDKs/MacOSX10.2.8.sdk/usr/lib/gcc/darwin/3.3 \
+-F/Developer/SDKs/MacOSX10.2.8.sdk/System/Library/Frameworks \
+-Wl,-syslibroot,/Developer/SDKs/MacOSX10.2.8.sdk"
+
+# Intel compiler flags (10.4 runtime compatibility)
+GCC_COMPILE_X86="gcc-4.0 -arch i386 -mmacosx-version-min=10.4 \
+-DMAC_OS_X_VERSION_MIN_REQUIRED=1040 \
+-nostdinc \
+-F/Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks \
+-I/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin8/4.0.1/include \
+-isystem /Developer/SDKs/MacOSX10.4u.sdk/usr/include"
+
+GCC_LINK_X86="\
+-L/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin8/4.0.0 \
+-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk"
+
+# Output both PowerPC and Intel object files
+args="$*"
+compile=yes
+link=yes
+while test x$1 != x; do
+ case $1 in
+ --version) exec gcc $1;;
+ -v) exec gcc $1;;
+ -V) exec gcc $1;;
+ -print-prog-name=*) exec gcc $1;;
+ -print-search-dirs) exec gcc $1;;
+ -E) GCC_COMPILE_PPC="$GCC_COMPILE_PPC -E"
+ GCC_COMPILE_X86="$GCC_COMPILE_X86 -E"
+ compile=no; link=no;;
+ -c) link=no;;
+ -o) output=$2;;
+ *.c|*.cc|*.cpp|*.S) source=$1;;
+ esac
+ shift
+done
+if test x$link = xyes; then
+ GCC_COMPILE_PPC="$GCC_COMPILE_PPC $GCC_LINK_PPC"
+ GCC_COMPILE_X86="$GCC_COMPILE_X86 $GCC_LINK_X86"
+fi
+if test x"$output" = x; then
+ if test x$link = xyes; then
+ output=a.out
+ elif test x$compile = xyes; then
+ output=`echo $source | sed -e 's|.*/||' -e 's|\(.*\)\.[^\.]*|\1|'`.o
+ fi
+fi
+
+if test x"$output" != x; then
+ dir=ppc/`dirname $output`
+ if test -d $dir; then
+ :
+ else
+ mkdir -p $dir
+ fi
+fi
+set -- $args
+while test x$1 != x; do
+ if test -f "ppc/$1" && test "$1" != "$output"; then
+ ppc_args="$ppc_args ppc/$1"
+ else
+ ppc_args="$ppc_args $1"
+ fi
+ shift
+done
+$GCC_COMPILE_PPC $ppc_args || exit $?
+if test x"$output" != x; then
+ cp $output ppc/$output
+fi
+
+if test x"$output" != x; then
+ dir=x86/`dirname $output`
+ if test -d $dir; then
+ :
+ else
+ mkdir -p $dir
+ fi
+fi
+set -- $args
+while test x$1 != x; do
+ if test -f "x86/$1" && test "$1" != "$output"; then
+ x86_args="$x86_args x86/$1"
+ else
+ x86_args="$x86_args $1"
+ fi
+ shift
+done
+$GCC_COMPILE_X86 $x86_args || exit $?
+if test x"$output" != x; then
+ cp $output x86/$output
+fi
+
+if test x"$output" != x; then
+ lipo -create -o $output ppc/$output x86/$output
+fi
diff -r e49147870aac -r 14717b52abc0 test/loopwave.c
--- a/test/loopwave.c Mon May 01 06:58:33 2006 +0000
+++ b/test/loopwave.c Wed May 17 08:18:28 2006 +0000
@@ -32,7 +32,7 @@
}
-void fillerup(void *unused, Uint8 *stream, int len)
+void SDLCALL fillerup(void *unused, Uint8 *stream, int len)
{
Uint8 *waveptr;
int waveleft;
diff -r e49147870aac -r 14717b52abc0 test/testalpha.c
--- a/test/testalpha.c Mon May 01 06:58:33 2006 +0000
+++ b/test/testalpha.c Wed May 17 08:18:28 2006 +0000
@@ -505,7 +505,10 @@
}
break;
case SDL_KEYDOWN:
- /* Any keypress quits the app... */
+ if ( event.key.keysym.sym == SDLK_ESCAPE ) {
+ done = 1;
+ }
+ break;
case SDL_QUIT:
done = 1;
break;
diff -r e49147870aac -r 14717b52abc0 test/testdyngl.c
--- a/test/testdyngl.c Mon May 01 06:58:33 2006 +0000
+++ b/test/testdyngl.c Wed May 17 08:18:28 2006 +0000
@@ -19,6 +19,10 @@
#include "SDL.h"
+#ifdef __MACOS__
+#define HAVE_OPENGL
+#endif
+
#ifdef HAVE_OPENGL
#include "SDL_opengl.h"
diff -r e49147870aac -r 14717b52abc0 test/testerror.c
--- a/test/testerror.c Mon May 01 06:58:33 2006 +0000
+++ b/test/testerror.c Wed May 17 08:18:28 2006 +0000
@@ -17,7 +17,7 @@
exit(rc);
}
-int ThreadFunc(void *data)
+int SDLCALL ThreadFunc(void *data)
{
/* Set the child thread error string */
SDL_SetError("Thread %s (%d) had a problem: %s",
diff -r e49147870aac -r 14717b52abc0 test/testfile.c
--- a/test/testfile.c Mon May 01 06:58:33 2006 +0000
+++ b/test/testfile.c Wed May 17 08:18:28 2006 +0000
@@ -2,6 +2,7 @@
/* sanity tests on SDL_rwops.c (usefull for alternative implementations of stdio rwops) */
#include
+#include
#include "SDL.h"
#include "SDL_endian.h"
diff -r e49147870aac -r 14717b52abc0 test/testgl.c
--- a/test/testgl.c Mon May 01 06:58:33 2006 +0000
+++ b/test/testgl.c Wed May 17 08:18:28 2006 +0000
@@ -5,6 +5,10 @@
#include "SDL.h"
+#ifdef __MACOS__
+#define HAVE_OPENGL
+#endif
+
#ifdef HAVE_OPENGL
#include "SDL_opengl.h"
diff -r e49147870aac -r 14717b52abc0 test/testhread.c
--- a/test/testhread.c Mon May 01 06:58:33 2006 +0000
+++ b/test/testhread.c Wed May 17 08:18:28 2006 +0000
@@ -17,7 +17,7 @@
exit(rc);
}
-int ThreadFunc(void *data)
+int SDLCALL ThreadFunc(void *data)
{
printf("Started thread %s: My thread id is %u\n",
(char *)data, SDL_ThreadID());
diff -r e49147870aac -r 14717b52abc0 test/testlock.c
--- a/test/testlock.c Mon May 01 06:58:33 2006 +0000
+++ b/test/testlock.c Wed May 17 08:18:28 2006 +0000
@@ -5,7 +5,6 @@
#include
#include
-#include
#include "SDL.h"
#include "SDL_mutex.h"
@@ -14,6 +13,7 @@
static SDL_mutex *mutex = NULL;
static Uint32 mainthread;
static SDL_Thread *threads[6];
+static volatile int doterminate = 0;
/*
* SDL_Quit() shouldn't be used with atexit() directly because
@@ -31,8 +31,8 @@
void terminate(int sig)
{
- printf("Process %u: raising SIGTERM\n", SDL_ThreadID());
- raise(SIGTERM);
+ signal(SIGINT, terminate);
+ doterminate = 1;
}
void closemutex(int sig)
{
@@ -44,7 +44,7 @@
SDL_DestroyMutex(mutex);
exit(sig);
}
-int Run(void *data)
+int SDLCALL Run(void *data)
{
if ( SDL_ThreadID() == mainthread )
signal(SIGTERM, closemutex);
@@ -63,6 +63,10 @@
}
/* If this sleep isn't done, then threads may starve */
SDL_Delay(10);
+ if (SDL_ThreadID() == mainthread && doterminate) {
+ printf("Process %u: raising SIGTERM\n", SDL_ThreadID());
+ raise(SIGTERM);
+ }
}
return(0);
}
diff -r e49147870aac -r 14717b52abc0 test/testpalette.c
--- a/test/testpalette.c Mon May 01 06:58:33 2006 +0000
+++ b/test/testpalette.c Wed May 17 08:18:28 2006 +0000
@@ -15,7 +15,7 @@
#define M_PI 3.14159265358979323846
#endif
-#include
+#include "SDL.h"
/* screen size */
#define SCRW 640
diff -r e49147870aac -r 14717b52abc0 test/testsem.c
--- a/test/testsem.c Mon May 01 06:58:33 2006 +0000
+++ b/test/testsem.c Wed May 17 08:18:28 2006 +0000
@@ -13,7 +13,7 @@
static SDL_sem *sem;
int alive = 1;
-int ThreadFunc(void *data)
+int SDLCALL ThreadFunc(void *data)
{
int threadnum = (int)(uintptr_t)data;
while ( alive ) {
diff -r e49147870aac -r 14717b52abc0 test/testtimer.c
--- a/test/testtimer.c Mon May 01 06:58:33 2006 +0000
+++ b/test/testtimer.c Wed May 17 08:18:28 2006 +0000
@@ -12,13 +12,13 @@
static int ticks = 0;
-static Uint32 ticktock(Uint32 interval)
+static Uint32 SDLCALL ticktock(Uint32 interval)
{
++ticks;
return(interval);
}
-static Uint32 callback(Uint32 interval, void *param)
+static Uint32 SDLCALL callback(Uint32 interval, void *param)
{
printf("Timer %d : param = %d\n", interval, (int)(uintptr_t)param);
return interval;
diff -r e49147870aac -r 14717b52abc0 test/testwin.c
--- a/test/testwin.c Mon May 01 06:58:33 2006 +0000
+++ b/test/testwin.c Wed May 17 08:18:28 2006 +0000
@@ -250,9 +250,9 @@
delay = 1;
#ifdef _WIN32_WCE
- w = 640;
+ w = 240;
h = 320;
- desired_bpp = 0;
+ desired_bpp = 8;
video_flags = SDL_FULLSCREEN;
#else
w = 640;
diff -r e49147870aac -r 14717b52abc0 test/testwm.c
--- a/test/testwm.c Mon May 01 06:58:33 2006 +0000
+++ b/test/testwm.c Wed May 17 08:18:28 2006 +0000
@@ -168,7 +168,7 @@
SDL_PushEvent(&event);
}
-int FilterEvents(const SDL_Event *event)
+int SDLCALL FilterEvents(const SDL_Event *event)
{
static int reallyquit = 0;
@@ -180,10 +180,10 @@
event->active.gain ? "gained" : "lost");
if ( event->active.state & SDL_APPACTIVE )
printf("active ");
+ if ( event->active.state & SDL_APPINPUTFOCUS )
+ printf("input ");
if ( event->active.state & SDL_APPMOUSEFOCUS )
printf("mouse ");
- if ( event->active.state & SDL_APPINPUTFOCUS )
- printf("input ");
printf("focus\n");
/* See if we are iconified or restored */
diff -r e49147870aac -r 14717b52abc0 test/threadwin.c
--- a/test/threadwin.c Mon May 01 06:58:33 2006 +0000
+++ b/test/threadwin.c Wed May 17 08:18:28 2006 +0000
@@ -77,7 +77,7 @@
return(icon);
}
-int FilterEvents(const SDL_Event *event)
+int SDLCALL FilterEvents(const SDL_Event *event)
{
static int reallyquit = 0;
@@ -127,7 +127,7 @@
}
}
-int HandleMouse(void *unused)
+int SDLCALL HandleMouse(void *unused)
{
SDL_Event events[10];
int i, found;
@@ -164,7 +164,7 @@
return(0);
}
-int HandleKeyboard(void *unused)
+int SDLCALL HandleKeyboard(void *unused)
{
SDL_Event events[10];
int i, found;
diff -r e49147870aac -r 14717b52abc0 test/torturethread.c
--- a/test/torturethread.c Mon May 01 06:58:33 2006 +0000
+++ b/test/torturethread.c Wed May 17 08:18:28 2006 +0000
@@ -20,14 +20,14 @@
exit(rc);
}
-int SubThreadFunc(void *data) {
+int SDLCALL SubThreadFunc(void *data) {
while(! *(int volatile *)data) {
; /*SDL_Delay(10);*/ /* do nothing */
}
return 0;
}
-int ThreadFunc(void *data) {
+int SDLCALL ThreadFunc(void *data) {
SDL_Thread *sub_threads[NUMTHREADS];
int flags[NUMTHREADS];
int i;
diff -r e49147870aac -r 14717b52abc0 docs/images/rainbow.gif
Binary file docs/images/rainbow.gif has changed
diff -r e49147870aac -r 14717b52abc0 docs/index.html
--- a/docs/index.html Mon May 01 06:58:33 2006 +0000
+++ b/docs/index.html Wed May 17 08:18:28 2006 +0000
@@ -1,102 +1,36 @@
-