Skip to content

Commit

Permalink
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Browse files Browse the repository at this point in the history
To: SDL Developers <sdl@libsdl.org>
From: =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb@algonet.se>
Date: Mon, 30 May 2005 23:29:04 +0200
Subject: [SDL] Mac OS X Video Drivers [patch]

I've updated/added the Carbon and X11 video drivers
to the Mac OS X port of SDL 1.2 (the CVS version),
and made the Cocoa driver and runtime *optional*.

The default is still Cocoa, and the "Quartz" driver.
But you can now also use "toolbox" for Carbon, and
"x11" for running with Apple's (or other) X11 server:

export SDL_VIDEODRIVER=x11
export SDL_VIDEO_GL_DRIVER=/usr/X11R6/lib/libGL.dylib

It also checks if the frameworks are available, by a:
#include <Carbon/Carbon.h> or #import <Cocoa/Cocoa.h>
(this should make it configure on plain Darwin as well?)


Here are the new configure targets:
   --enable-video-cocoa    use Cocoa/Quartz video driver default=yes
   --enable-video-carbon   use Carbon/QuickDraw video driver default=yes
   --enable-video-x11	   use X11 video driver default=no

./configure --enable-video-cocoa --enable-video-carbon
--enable-video-x11 \
	     --x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib

The Carbon version is just an updated version of the old
SDL driver for Mac OS 9, and could probably be improved...
(but it does work, including the Carbon version of SDLmain)

If you disable cocoa, you can run with -framework Carbon only,
and the C version of SDL_main.c. And if you disable carbon too,
you can still use the X11 version which doesn't require SDLmain.

I updated the DrawSprocket version, but did not include it.
(no blitters or VRAM GWorlds etc. available on OS X anyway)
Besides for Mac OS 9, I don't think there's any use for it ?

And note that any performance on Mac OS X equals OpenGL anyway...
You can get "fair" software SDL results on captured CG displays,
but for decent frame rates you need to be using GL for rendering.


Finally, here is the patch itself:
http://www.algonet.se/~afb/SDL-12CVS-macvideo.patch

--anders

PS. It says "video", but as usual it applies to mouse/keyboard too.


------


To: A list for developers using the SDL library <sdl@libsdl.org>
From: =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb@algonet.se>
Date: Sun, 4 Sep 2005 10:02:15 +0200
Subject: [SDL] Updated Mac patch

Updated the previous Mac patch to disable Carbon by default.
Also "fixed" the SDL.spec again, so that it builds on Darwin.

http://www.algonet.se/~afb/SDL-1.2.9-mac.patch
Also applied fine to SDL12 CVS, when I tried it.
  • Loading branch information
icculus committed Sep 8, 2005
1 parent f89f3b5 commit 05a8e21
Show file tree
Hide file tree
Showing 15 changed files with 304 additions and 67 deletions.
64 changes: 42 additions & 22 deletions SDL.spec.in
@@ -1,18 +1,16 @@
%define name @PACKAGE@
%define version @VERSION@
%define release 1

Summary: Simple DirectMedia Layer
Name: %{name}
Version: %{version}
Release: %{release}
Source0: %{name}-%{version}.tar.gz
Name: @PACKAGE@
Version: @VERSION@
Release: 1
Source: http://www.libsdl.org/release/%{name}-%{version}.tar.gz
URL: http://www.libsdl.org/
Copyright: LGPL
License: LGPL
Group: System Environment/Libraries
BuildRoot: /var/tmp/%{name}-buildroot
BuildRoot: %{_tmppath}/%{name}-%{version}-buildroot
Prefix: %{_prefix}
%ifos linux
Provides: libSDL-1.1.so.0
%endif

%description
This is the Simple DirectMedia Layer, a generic API that provides low
Expand All @@ -22,7 +20,7 @@ multiple platforms.
%package devel
Summary: Libraries, includes and more to develop SDL applications.
Group: Development/Libraries
Requires: %{name}
Requires: %{name} = %{version}

%description devel
This is the Simple DirectMedia Layer, a generic API that provides low
Expand All @@ -34,40 +32,62 @@ to develop SDL applications.


%prep
rm -rf ${RPM_BUILD_ROOT}

%setup -q

%build
%ifos linux
CFLAGS="$RPM_OPT_FLAGS" ./configure --prefix=%{prefix} --disable-video-svga --disable-video-ggi --disable-video-aalib --disable-debug --enable-dlopen --enable-esd-shared --enable-arts-shared
%else
%configure --disable-debug --enable-dlopen
%endif
make

%install
rm -rf $RPM_BUILD_ROOT
%ifos linux
make install prefix=$RPM_BUILD_ROOT/%{prefix}
ln -s libSDL-1.2.so.0 $RPM_BUILD_ROOT/%{prefix}/lib/libSDL-1.1.so.0
%else
%makeinstall
%endif

%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(-,root,root)
%{__defattr}
%doc README-SDL.txt COPYING CREDITS BUGS
%{prefix}/lib/lib*.so.*
%ifnos darwin
%{_libdir}/lib*.%{__soext}.*
%else
%{_libdir}/lib*.*.%{__soext}
%endif

%files devel
%defattr(-,root,root)
%doc README README-SDL.txt COPYING CREDITS BUGS WhatsNew docs.html
%doc docs/index.html docs/html
%{prefix}/bin/*-config
%{prefix}/lib/lib*.a
%{prefix}/lib/lib*.la
%{prefix}/lib/lib*.so
%{prefix}/include/SDL/
%{prefix}/man/man3/*
%{prefix}/share/aclocal/*
%{_bindir}/*-config
%{_libdir}/lib*.a
%{_libdir}/lib*.la
%{_libdir}/lib*.%{__soext}
%dir %{_includedir}/SDL
%{_includedir}/SDL/*.h
%{_mandir}/man3/*
%{_datadir}/aclocal/*

%changelog
* Mon Jan 03 2004 Anders Bjorklund <afb@algonet.se>
- Added support for Darwin, updated spec file

* Wed Jan 19 2000 Sam Lantinga <slouken@libsdl.org>
- Re-integrated spec file into SDL distribution
- 'name' and 'version' come from configure
Expand Down
108 changes: 98 additions & 10 deletions configure.in
Expand Up @@ -742,6 +742,28 @@ CheckX11()
fi
}


dnl Check for X11 on Mac OS X / Darwin
CheckMacX11()
{
AC_ARG_ENABLE(video-x11,
[ --enable-video-x11 use X11 video driver [default=no]],
, enable_video_x11=no)
if test x$enable_video = xyes -a x$enable_video_x11 = xyes; then
AC_PATH_X
AC_PATH_XTRA
if test x$have_x = xyes; then
CFLAGS="$CFLAGS $X_CFLAGS -DENABLE_X11 -DXTHREADS -I$srcdir/include -I$srcdir/src/video"
if test x$ac_cv_func_shmat != xyes; then
CFLAGS="$CFLAGS -DNO_SHARED_MEMORY"
fi
SYSTEM_LIBS="$SYSTEM_LIBS $X_LIBS -lX11 -lXext"
VIDEO_SUBDIRS="$VIDEO_SUBDIRS x11"
VIDEO_DRIVERS="$VIDEO_DRIVERS x11/libvideo_x11.la"
fi
fi
}

dnl Find the X11 DGA 2.0 include and library directories
CheckDGA()
{
Expand Down Expand Up @@ -1128,7 +1150,9 @@ CheckMacGL()
CFLAGS="$CFLAGS -DHAVE_OPENGL"
case "$target" in
*-*-darwin*)
SYSTEM_LIBS="$SYSTEM_LIBS -framework OpenGL -framework AGL"
SYSTEM_LIBS="$SYSTEM_LIBS -framework OpenGL"
# The following is probably not available in Darwin:
SYSTEM_LIBS="$SYSTEM_LIBS -framework AGL"
esac
fi
}
Expand Down Expand Up @@ -1635,15 +1659,34 @@ CheckPicoGUI()
dnl Set up the Mac toolbox video driver for Mac OS 7-9
CheckTOOLBOX()
{
CFLAGS="$CFLAGS -DENABLE_TOOLBOX -DENABLE_DRAWSPROCKET"
VIDEO_SUBDIRS="$VIDEO_SUBDIRS maccommon"
VIDEO_DRIVERS="$VIDEO_DRIVERS maccommon/libvideo_maccommon.la"
VIDEO_SUBDIRS="$VIDEO_SUBDIRS macrom"
VIDEO_DRIVERS="$VIDEO_DRIVERS macrom/libvideo_macrom.la"
VIDEO_SUBDIRS="$VIDEO_SUBDIRS macdsp"
VIDEO_DRIVERS="$VIDEO_DRIVERS macdsp/libvideo_macdsp.la"
}

dnl Set up the Mac toolbox video driver for Mac OS X
dnl Set up the Carbon/QuickDraw video driver for Mac OS X (but not Darwin)
CheckCARBON()
{
AC_ARG_ENABLE(video-carbon,
[ --enable-video-carbon use Carbon/QuickDraw video driver [default=no]],
, enable_video_carbon=no)
if test x$enable_video = xyes -a x$enable_video_carbon = xyes; then
AC_MSG_CHECKING(for Carbon framework)
have_carbon=no
if test x$have_carbon != xyes; then
AC_TRY_COMPILE([
#include <Carbon/Carbon.h>
],[
],[
have_carbon=yes
])
fi
AC_MSG_RESULT($have_carbon)
if test x$have_carbon = xyes; then
# "MACOSX" is not an official definition, but it's commonly
# accepted as a way to differentiate between what runs on X
# and what runs on older Macs - while in theory "Carbon" defns
Expand All @@ -1656,11 +1699,35 @@ CheckCARBON()
VIDEO_DRIVERS="$VIDEO_DRIVERS maccommon/libvideo_maccommon.la"
VIDEO_SUBDIRS="$VIDEO_SUBDIRS macrom"
VIDEO_DRIVERS="$VIDEO_DRIVERS macrom/libvideo_macrom.la"
#VIDEO_SUBDIRS="$VIDEO_SUBDIRS macdsp"
#VIDEO_DRIVERS="$VIDEO_DRIVERS macdsp/libvideo_macdsp.la"
fi
fi
}

dnl Set up the Mac toolbox video driver for Mac OS X
CheckQUARTZ()
dnl Set up the Cocoa/Quartz video driver for Mac OS X (but not Darwin)
CheckCOCOA()
{
AC_ARG_ENABLE(video-cocoa,
[ --enable-video-cocoa use Cocoa/Quartz video driver [default=yes]],
, enable_video_cocoa=yes)
if test x$enable_video = xyes -a x$enable_video_cocoa = xyes; then
old_CFLAGS="$CFLAGS"
dnl work around that we don't have Objective-C support in autoconf
CFLAGS="$CFLAGS -x objective-c"
AC_MSG_CHECKING(for Cocoa framework)
have_cocoa=no
if test x$have_cocoa != xyes; then
AC_TRY_COMPILE([
#import <Cocoa/Cocoa.h>
],[
],[
have_cocoa=yes
])
fi
AC_MSG_RESULT($have_cocoa)
CFLAGS="$old_CFLAGS"
if test x$have_cocoa = xyes; then
# "MACOSX" is not an official definition, but it's commonly
# accepted as a way to differentiate between what runs on X
# and what runs on older Macs - while in theory "Carbon" defns
Expand All @@ -1672,6 +1739,8 @@ CheckQUARTZ()
-DENABLE_QUARTZ -DMACOSX -DTARGET_API_${mac_autoconf_target_workaround}_CARBON=1 -I\$(top_srcdir)/src/video/quartz"
VIDEO_SUBDIRS="$VIDEO_SUBDIRS quartz"
VIDEO_DRIVERS="$VIDEO_DRIVERS quartz/libvideo_quartz.la"
fi
fi
}

dnl Check for the dlfcn.h interface for dynamically loading objects
Expand Down Expand Up @@ -2581,13 +2650,15 @@ case "$target" in
SDL_LIBS="-lSDLmain $SDL_LIBS"
;;
*-*-darwin* )
# Strictly speaking, we want "Mac OS X", not "Darwin", which is
# This could be either full "Mac OS X", or plain "Darwin" which is
# just the OS X kernel sans upper layers like Carbon and Cocoa.
# But config.guess comes back with "darwin", so go with the flow.
# Next line is broken, and a few files below require Mac OS X (full)
ARCH=macosx
CheckDummyVideo
CheckDiskAudio
CheckQUARTZ
CheckCOCOA
CheckCARBON
CheckMacX11
CheckMacGL
CheckPTHREAD
CheckSIGACTION
Expand Down Expand Up @@ -2625,8 +2696,16 @@ case "$target" in
fi
# The MacOS X platform requires special setup.
SDL_LIBS="-lSDLmain $SDL_LIBS"
# The Cocoa backend still needs Carbon, and the YUV code QuickTime
SYSTEM_LIBS="$SYSTEM_LIBS -framework Cocoa -framework Carbon -framework QuickTime"
if test x$enable_video_cocoa = xyes; then
SYSTEM_LIBS="$SYSTEM_LIBS -framework Cocoa"
fi
if test x$enable_video_carbon = xyes -o x$enable_video_cocoa = xyes; then
# The Cocoa backend still needs Carbon, and the YUV code QuickTime
SYSTEM_LIBS="$SYSTEM_LIBS -framework Carbon -framework QuickTime"
fi
#if test x$enable_video_carbon = xyes; then
# SYSTEM_LIBS="$SYSTEM_LIBS -framework DrawSprocket"
#fi
;;
*-*-mint*)
ARCH=mint
Expand Down Expand Up @@ -2746,6 +2825,8 @@ AM_CONDITIONAL(TARGET_MINT, test $ARCH = mint)
AM_CONDITIONAL(USE_DIRECTX, test x$use_directx = xyes)
AM_CONDITIONAL(USE_CLONE, test x$use_clone = xyes)
AM_CONDITIONAL(HAVE_NASM, test x$use_nasm = xyes)
AM_CONDITIONAL(USE_COCOA, test x$enable_video_cocoa = xyes)
AM_CONDITIONAL(USE_CARBON, test x$enable_video_carbon = xyes)

# Set conditional variables for shared and static library selection.
# These are not used in any Makefile.am but in sdl-config.in.
Expand Down Expand Up @@ -2773,7 +2854,13 @@ case "$ARCH" in
SHARED_SYSTEM_LIBS="$SYSTEM_LIBS"
;;
macosx)
SHARED_SYSTEM_LIBS="-framework Cocoa"
SHARED_SYSTEM_LIBS=""
if test x$enable_video = xyes -a x$enable_video_cocoa = xyes; then
SHARED_SYSTEM_LIBS="$SHARED_SYSTEM_LIBS -framework Cocoa"
fi
if test x$enable_video = xyes -a x$enable_video_carbon = xyes; then
SHARED_SYSTEM_LIBS="$SHARED_SYSTEM_LIBS -framework Carbon"
fi
if test x$enable_video = xyes -a x$enable_video_opengl = xyes; then
SHARED_SYSTEM_LIBS="$SHARED_SYSTEM_LIBS -framework OpenGL"
fi
Expand Down Expand Up @@ -2874,6 +2961,7 @@ docs/man3/Makefile
include/Makefile
src/Makefile
src/main/Makefile
src/main/macos/Makefile
src/main/macosx/Makefile
src/main/macosx/Info.plist
src/audio/Makefile
Expand Down
16 changes: 14 additions & 2 deletions include/SDL_syswm.h
Expand Up @@ -48,14 +48,26 @@ struct SDL_SysWMinfo;
typedef struct SDL_SysWMinfo SDL_SysWMinfo;
#else

#if defined(__APPLE__) && defined(__MACH__)
// conflicts with Quickdraw.h
#define Cursor X11Cursor
#endif

/* This is the structure for custom window manager events */
#if (defined(unix) || defined(__unix__) || defined(_AIX) || defined(__OpenBSD__) || defined(__NetBSD__)) && \
#if (defined(unix) || defined(__unix__) || defined(_AIX) || \
defined(__OpenBSD__) || defined(__NetBSD__) || \
(defined(__APPLE__) && defined(__MACH__))) && \
(!defined(DISABLE_X11) && !defined(__CYGWIN32__) && !defined(ENABLE_NANOX) && \
!defined(__QNXNTO__))
!defined(__QNXNTO__))
/* AIX is unix, of course, but the native compiler CSet doesn't define unix */
#include <X11/Xlib.h>
#include <X11/Xatom.h>

#if defined(__APPLE__) && defined(__MACH__)
// matches the re-define above
#undef Cursor
#endif

/* These are the various supported subsystems under UNIX */
typedef enum {
SDL_SYSWM_X11
Expand Down
12 changes: 10 additions & 2 deletions src/audio/macrom/SDL_romaudio.c
Expand Up @@ -25,7 +25,9 @@ static char rcsid =
"@(#) $Id$";
#endif

#if TARGET_API_MAC_CARBON
#if defined(__APPLE__) && defined(__MACH__)
# include <Carbon/Carbon.h>
#elif TARGET_API_MAC_CARBON && (UNIVERSAL_INTERFACES_VERSION > 0x0335)
# include <Carbon.h>
#else
# include <Sound.h> /* SoundManager interface */
Expand All @@ -36,6 +38,12 @@ static char rcsid =
#include <stdlib.h>
#include <stdio.h>

#if !defined(NewSndCallBackUPP) && (UNIVERSAL_INTERFACES_VERSION < 0x0335)
#if !defined(NewSndCallBackProc) /* avoid circular redefinition... */
#define NewSndCallBackUPP NewSndCallBackProc
#endif
#endif

#include "SDL_endian.h"
#include "SDL_audio.h"
#include "SDL_audio_c.h"
Expand Down Expand Up @@ -229,7 +237,7 @@ static int Mac_OpenAudio(_THIS, SDL_AudioSpec *spec) {

/* initialize bufferCmd header */
memset (&header, 0, sizeof(header));
callback = NewSndCallBackUPP (callBackProc);
callback = (SndCallBackUPP) NewSndCallBackUPP (callBackProc);
sample_bits = spec->size / spec->samples / spec->channels * 8;

#ifdef DEBUG_AUDIO
Expand Down
2 changes: 2 additions & 0 deletions src/joystick/macos/SDL_sysjoystick.c
Expand Up @@ -72,7 +72,9 @@ int SDL_SYS_JoystickInit(void)
{
static ISpDeviceClass classes[4] = {
kISpDeviceClass_Joystick,
#if kISpDeviceClass_Gamepad
kISpDeviceClass_Gamepad,
#endif
kISpDeviceClass_Wheel,
0
};
Expand Down
6 changes: 6 additions & 0 deletions src/main/Makefile.am
Expand Up @@ -19,8 +19,14 @@ if TARGET_WIN32
MAINLIB_ARCH_SRCS = win32/SDL_win32_main.c
else
if TARGET_MACOSX
if USE_COCOA
MAINLIB_ARCH_SRCS = macosx/SDLMain.m macosx/SDLMain.h
else
if USE_CARBON
MAINLIB_ARCH_SRCS = macos/SDL_main.c
endif # USE_CARBON
endif # USE_COCOA
else
if TARGET_QTOPIA
MAINLIB_ARCH_SRCS = qtopia/SDL_qtopia_main.cc
else
Expand Down

0 comments on commit 05a8e21

Please sign in to comment.