diff src/main/macos/SDL_main.c @ 1133:609c060fd2a2

The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails: 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.
author Ryan C. Gordon <icculus@icculus.org>
date Thu, 08 Sep 2005 06:16:14 +0000
parents b8d311d90021
children c9b51268668f
line wrap: on
line diff
--- a/src/main/macos/SDL_main.c	Thu Aug 25 20:31:58 2005 +0000
+++ b/src/main/macos/SDL_main.c	Thu Sep 08 06:16:14 2005 +0000
@@ -26,14 +26,16 @@
 #endif
 
 /* This file takes care of command line argument parsing, and stdio redirection
-   in the MacOS environment.
+   in the MacOS environment. (stdio/stderr is *not* directed for Mach-O builds)
  */
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>	
-#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 <Dialogs.h>
@@ -50,9 +52,11 @@
 #undef main
 #endif
 
+#if !(defined(__APPLE__) && defined(__MACH__))
 /* The standard output files */
 #define STDOUT_FILE	"stdout.txt"
 #define STDERR_FILE	"stderr.txt"
+#endif
 
 #if !defined(__MWERKS__) && !TARGET_API_MAC_CARBON
 	/* In MPW, the qd global has been removed from the libraries */
@@ -79,6 +83,8 @@
 	return(false);
 }
 
+#if !(defined(__APPLE__) && defined(__MACH__))
+
 /* Parse a command line buffer into arguments */
 static int ParseCommandLine(char *cmdline, char **argv)
 {
@@ -158,6 +164,8 @@
 	}
 }
 
+#endif //!(defined(__APPLE__) && defined(__MACH__))
+
 static int getCurrentAppName (StrFileName name) {
 	
     ProcessSerialNumber process;
@@ -207,7 +215,7 @@
     prefs_name[0] = app_name[0] + strlen (SUFFIX);
    
     /* Make the file spec for prefs file */
-    if ( noErr != FSMakeFSSpec (volume_ref_number, directory_id, prefs_name, prefs_fsp) )
+    if ( noErr != FSMakeFSSpec (volume_ref_number, directory_id, prefs_name, prefs_fsp) ) {
         if ( !create )
             return 0;
         else {
@@ -216,12 +224,12 @@
             prefs_fsp->parID   = directory_id;
             prefs_fsp->vRefNum = volume_ref_number;
                 
-            FSpCreateResFile (prefs_fsp, '????', 'pref', 0);
+            FSpCreateResFile (prefs_fsp, 0x3f3f3f3f, 'pref', 0); // '????' parsed as trigraph
             
             if ( noErr != ResError () )
                 return 0;
         }
-      
+     }
     return 1;
 }
 
@@ -233,7 +241,7 @@
 
 	if (prefs_handle != NULL) {
 		int offset = 0;
-		int j      = 0;
+//		int j      = 0;
 		
 		HLock(prefs_handle);
 		
@@ -349,7 +357,9 @@
 int main(int argc, char *argv[])
 {
 
+#if !(defined(__APPLE__) && defined(__MACH__))
 #pragma unused(argc, argv)
+#endif
 	
 #define DEFAULT_ARGS "\p"                /* pascal string for default args */
 #define DEFAULT_VIDEO_DRIVER "\ptoolbox" /* pascal string for default video driver name */	
@@ -360,11 +370,13 @@
 
     PrefsRecord prefs = { DEFAULT_ARGS, DEFAULT_VIDEO_DRIVER, DEFAULT_OUTPUT_TO_FILE }; 
 	
+#if !(defined(__APPLE__) && defined(__MACH__))
 	int     nargs;
 	char   **args;
 	char   *commandLine;
 	
 	StrFileName  appNameText;
+#endif
 	int     videodriver     = VIDEO_ID_TOOLBOX;
     int     settingsChanged = 0;
     
@@ -399,12 +411,18 @@
 	    short     itemHit;
 	
 		errorDialog = GetNewDialog (1001, nil, (WindowPtr)-1);
+		if (errorDialog == NULL)
+		    return -1;
 		DrawDialog (errorDialog);
 		
 		GetDialogItem (errorDialog, kErr_Text, &dummyType, &dummyHandle, &dummyRect);
 		SetDialogItemText (dummyHandle, "\pError Initializing SDL");
 		
+#if TARGET_API_MAC_CARBON
+		SetPort (GetDialogPort(errorDialog));
+#else
 		SetPort (errorDialog);
+#endif
 		do {
 			ModalDialog (nil, &itemHit);
 		} while (itemHit != kErr_OK);
@@ -442,23 +460,40 @@
         Rect	  dummyRect;
         Handle    dummyHandle;
         short     itemHit;
-
+   #if TARGET_API_MAC_CARBON
+        ControlRef control;
+   #endif
+        
         /* Assume that they will change settings, rather than do exhaustive check */
         settingsChanged = 1;
         
         /* Create dialog and display it */
-        commandDialog = GetNewDialog (1000, nil, (DialogPtr)-1);
+        commandDialog = GetNewDialog (1000, nil, (WindowPtr)-1);
+    #if TARGET_API_MAC_CARBON
+        SetPort ( GetDialogPort(commandDialog) );
+    #else
         SetPort (commandDialog);
-            
+     #endif
+           
         /* Setup controls */
+    #if TARGET_API_MAC_CARBON
+        GetDialogItemAsControl(commandDialog, kCL_File, &control);
+        SetControlValue (control, prefs.output_to_file);
+    #else
         GetDialogItem   (commandDialog, kCL_File, &dummyType, &dummyHandle, &dummyRect); /* MJS */
         SetControlValue ((ControlHandle)dummyHandle, prefs.output_to_file );
+    #endif
 
         GetDialogItem     (commandDialog, kCL_Text, &dummyType, &dummyHandle, &dummyRect);
         SetDialogItemText (dummyHandle, prefs.command_line);
 
+    #if TARGET_API_MAC_CARBON
+        GetDialogItemAsControl(commandDialog, kCL_Video, &control);
+        SetControlValue (control, videodriver);
+   #else
         GetDialogItem   (commandDialog, kCL_Video, &dummyType, &dummyHandle, &dummyRect);
         SetControlValue ((ControlRef)dummyHandle, videodriver);
+     #endif
 
         SetDialogDefaultItem (commandDialog, kCL_OK);
         SetDialogCancelItem  (commandDialog, kCL_Cancel);
@@ -469,8 +504,13 @@
             
             /* Toggle command-line output checkbox */	
         	if ( itemHit == kCL_File ) {
+        #if TARGET_API_MAC_CARBON
+        		GetDialogItemAsControl(commandDialog, kCL_File, &control);
+        		SetControlValue (control, !GetControlValue(control));
+        #else
         		GetDialogItem(commandDialog, kCL_File, &dummyType, &dummyHandle, &dummyRect); /* MJS */
         		SetControlValue((ControlHandle)dummyHandle, !GetControlValue((ControlHandle)dummyHandle) );
+        #endif
         	}
 
         } while (itemHit != kCL_OK && itemHit != kCL_Cancel);
@@ -479,11 +519,21 @@
         GetDialogItem     (commandDialog, kCL_Text, &dummyType, &dummyHandle, &dummyRect); /* MJS */
         GetDialogItemText (dummyHandle, prefs.command_line);
 
+    #if TARGET_API_MAC_CARBON
+        GetDialogItemAsControl(commandDialog, kCL_File, &control);
+        prefs.output_to_file = GetControlValue(control);
+	#else
         GetDialogItem (commandDialog, kCL_File, &dummyType, &dummyHandle, &dummyRect); /* MJS */
         prefs.output_to_file = GetControlValue ((ControlHandle)dummyHandle);
+ 	#endif
 
+    #if TARGET_API_MAC_CARBON
+        GetDialogItemAsControl(commandDialog, kCL_Video, &control);
+        videodriver = GetControlValue(control);
+    #else
         GetDialogItem (commandDialog, kCL_Video, &dummyType, &dummyHandle, &dummyRect);
         videodriver = GetControlValue ((ControlRef)dummyHandle);
+     #endif
 
         DisposeDialog (commandDialog);
 
@@ -504,6 +554,7 @@
 	      break;
 	}
 
+#if !(defined(__APPLE__) && defined(__MACH__))
     /* Redirect standard I/O to files */
 	if ( prefs.output_to_file ) {
 		freopen (STDOUT_FILE, "w", stdout);
@@ -512,6 +563,7 @@
 		fclose (stdout);
 		fclose (stderr);
 	}
+#endif
    
     if (settingsChanged) {
         /* Save the prefs, even if they might not have changed (but probably did) */
@@ -519,6 +571,8 @@
             fprintf (stderr, "WARNING: Could not save preferences!\n");
     }
    
+#if !(defined(__APPLE__) && defined(__MACH__))
+    appNameText[0] = 0;
     getCurrentAppName (appNameText); /* check for error here ? */
 
     commandLine = (char*) malloc (appNameText[0] + prefs.command_line[0] + 2);
@@ -553,6 +607,9 @@
    
    	/* Remove useless stdout.txt and stderr.txt */
    	cleanup_output ();
+#else // defined(__APPLE__) && defined(__MACH__)
+	SDL_main(argc, argv);
+#endif
    	
 	/* Exit cleanly, calling atexit() functions */
 	exit (0);