Mercurial > sdl-ios-xcode
comparison 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 |
comparison
equal
deleted
inserted
replaced
1132:a0d3514c04b2 | 1133:609c060fd2a2 |
---|---|
24 static char rcsid = | 24 static char rcsid = |
25 "@(#) $Id$"; | 25 "@(#) $Id$"; |
26 #endif | 26 #endif |
27 | 27 |
28 /* This file takes care of command line argument parsing, and stdio redirection | 28 /* This file takes care of command line argument parsing, and stdio redirection |
29 in the MacOS environment. | 29 in the MacOS environment. (stdio/stderr is *not* directed for Mach-O builds) |
30 */ | 30 */ |
31 | 31 |
32 #include <stdio.h> | 32 #include <stdio.h> |
33 #include <stdlib.h> | 33 #include <stdlib.h> |
34 #include <string.h> | 34 #include <string.h> |
35 #include <ctype.h> | 35 #include <ctype.h> |
36 #if TARGET_API_MAC_CARBON | 36 #if defined(__APPLE__) && defined(__MACH__) |
37 #include <Carbon/Carbon.h> | |
38 #elif TARGET_API_MAC_CARBON && (UNIVERSAL_INTERFACES_VERSION > 0x0335) | |
37 #include <Carbon.h> | 39 #include <Carbon.h> |
38 #else | 40 #else |
39 #include <Dialogs.h> | 41 #include <Dialogs.h> |
40 #include <Fonts.h> | 42 #include <Fonts.h> |
41 #include <Events.h> | 43 #include <Events.h> |
48 #include "SDL_main.h" | 50 #include "SDL_main.h" |
49 #ifdef main | 51 #ifdef main |
50 #undef main | 52 #undef main |
51 #endif | 53 #endif |
52 | 54 |
55 #if !(defined(__APPLE__) && defined(__MACH__)) | |
53 /* The standard output files */ | 56 /* The standard output files */ |
54 #define STDOUT_FILE "stdout.txt" | 57 #define STDOUT_FILE "stdout.txt" |
55 #define STDERR_FILE "stderr.txt" | 58 #define STDERR_FILE "stderr.txt" |
59 #endif | |
56 | 60 |
57 #if !defined(__MWERKS__) && !TARGET_API_MAC_CARBON | 61 #if !defined(__MWERKS__) && !TARGET_API_MAC_CARBON |
58 /* In MPW, the qd global has been removed from the libraries */ | 62 /* In MPW, the qd global has been removed from the libraries */ |
59 QDGlobals qd; | 63 QDGlobals qd; |
60 #endif | 64 #endif |
76 if (((unsigned char *) theKeyMap)[6] & 0x80) { | 80 if (((unsigned char *) theKeyMap)[6] & 0x80) { |
77 return(true); | 81 return(true); |
78 } | 82 } |
79 return(false); | 83 return(false); |
80 } | 84 } |
85 | |
86 #if !(defined(__APPLE__) && defined(__MACH__)) | |
81 | 87 |
82 /* Parse a command line buffer into arguments */ | 88 /* Parse a command line buffer into arguments */ |
83 static int ParseCommandLine(char *cmdline, char **argv) | 89 static int ParseCommandLine(char *cmdline, char **argv) |
84 { | 90 { |
85 char *bufp; | 91 char *bufp; |
156 remove(STDERR_FILE); | 162 remove(STDERR_FILE); |
157 } | 163 } |
158 } | 164 } |
159 } | 165 } |
160 | 166 |
167 #endif //!(defined(__APPLE__) && defined(__MACH__)) | |
168 | |
161 static int getCurrentAppName (StrFileName name) { | 169 static int getCurrentAppName (StrFileName name) { |
162 | 170 |
163 ProcessSerialNumber process; | 171 ProcessSerialNumber process; |
164 ProcessInfoRec process_info; | 172 ProcessInfoRec process_info; |
165 FSSpec process_fsp; | 173 FSSpec process_fsp; |
205 memcpy (prefs_name + 1, app_name + 1, app_name[0]); | 213 memcpy (prefs_name + 1, app_name + 1, app_name[0]); |
206 memcpy (prefs_name + app_name[0] + 1, SUFFIX, strlen (SUFFIX)); | 214 memcpy (prefs_name + app_name[0] + 1, SUFFIX, strlen (SUFFIX)); |
207 prefs_name[0] = app_name[0] + strlen (SUFFIX); | 215 prefs_name[0] = app_name[0] + strlen (SUFFIX); |
208 | 216 |
209 /* Make the file spec for prefs file */ | 217 /* Make the file spec for prefs file */ |
210 if ( noErr != FSMakeFSSpec (volume_ref_number, directory_id, prefs_name, prefs_fsp) ) | 218 if ( noErr != FSMakeFSSpec (volume_ref_number, directory_id, prefs_name, prefs_fsp) ) { |
211 if ( !create ) | 219 if ( !create ) |
212 return 0; | 220 return 0; |
213 else { | 221 else { |
214 /* Create the prefs file */ | 222 /* Create the prefs file */ |
215 memcpy (prefs_fsp->name, prefs_name, prefs_name[0] + 1); | 223 memcpy (prefs_fsp->name, prefs_name, prefs_name[0] + 1); |
216 prefs_fsp->parID = directory_id; | 224 prefs_fsp->parID = directory_id; |
217 prefs_fsp->vRefNum = volume_ref_number; | 225 prefs_fsp->vRefNum = volume_ref_number; |
218 | 226 |
219 FSpCreateResFile (prefs_fsp, '????', 'pref', 0); | 227 FSpCreateResFile (prefs_fsp, 0x3f3f3f3f, 'pref', 0); // '????' parsed as trigraph |
220 | 228 |
221 if ( noErr != ResError () ) | 229 if ( noErr != ResError () ) |
222 return 0; | 230 return 0; |
223 } | 231 } |
224 | 232 } |
225 return 1; | 233 return 1; |
226 } | 234 } |
227 | 235 |
228 static int readPrefsResource (PrefsRecord *prefs) { | 236 static int readPrefsResource (PrefsRecord *prefs) { |
229 | 237 |
231 | 239 |
232 prefs_handle = Get1Resource( 'CLne', 128 ); | 240 prefs_handle = Get1Resource( 'CLne', 128 ); |
233 | 241 |
234 if (prefs_handle != NULL) { | 242 if (prefs_handle != NULL) { |
235 int offset = 0; | 243 int offset = 0; |
236 int j = 0; | 244 // int j = 0; |
237 | 245 |
238 HLock(prefs_handle); | 246 HLock(prefs_handle); |
239 | 247 |
240 /* Get command line string */ | 248 /* Get command line string */ |
241 memcpy (prefs->command_line, *prefs_handle, (*prefs_handle)[0]+1); | 249 memcpy (prefs->command_line, *prefs_handle, (*prefs_handle)[0]+1); |
347 | 355 |
348 /* This is where execution begins */ | 356 /* This is where execution begins */ |
349 int main(int argc, char *argv[]) | 357 int main(int argc, char *argv[]) |
350 { | 358 { |
351 | 359 |
360 #if !(defined(__APPLE__) && defined(__MACH__)) | |
352 #pragma unused(argc, argv) | 361 #pragma unused(argc, argv) |
362 #endif | |
353 | 363 |
354 #define DEFAULT_ARGS "\p" /* pascal string for default args */ | 364 #define DEFAULT_ARGS "\p" /* pascal string for default args */ |
355 #define DEFAULT_VIDEO_DRIVER "\ptoolbox" /* pascal string for default video driver name */ | 365 #define DEFAULT_VIDEO_DRIVER "\ptoolbox" /* pascal string for default video driver name */ |
356 #define DEFAULT_OUTPUT_TO_FILE 1 /* 1 == output to file, 0 == no output */ | 366 #define DEFAULT_OUTPUT_TO_FILE 1 /* 1 == output to file, 0 == no output */ |
357 | 367 |
358 #define VIDEO_ID_DRAWSPROCKET 1 /* these correspond to popup menu choices */ | 368 #define VIDEO_ID_DRAWSPROCKET 1 /* these correspond to popup menu choices */ |
359 #define VIDEO_ID_TOOLBOX 2 | 369 #define VIDEO_ID_TOOLBOX 2 |
360 | 370 |
361 PrefsRecord prefs = { DEFAULT_ARGS, DEFAULT_VIDEO_DRIVER, DEFAULT_OUTPUT_TO_FILE }; | 371 PrefsRecord prefs = { DEFAULT_ARGS, DEFAULT_VIDEO_DRIVER, DEFAULT_OUTPUT_TO_FILE }; |
362 | 372 |
373 #if !(defined(__APPLE__) && defined(__MACH__)) | |
363 int nargs; | 374 int nargs; |
364 char **args; | 375 char **args; |
365 char *commandLine; | 376 char *commandLine; |
366 | 377 |
367 StrFileName appNameText; | 378 StrFileName appNameText; |
379 #endif | |
368 int videodriver = VIDEO_ID_TOOLBOX; | 380 int videodriver = VIDEO_ID_TOOLBOX; |
369 int settingsChanged = 0; | 381 int settingsChanged = 0; |
370 | 382 |
371 long i; | 383 long i; |
372 | 384 |
397 Rect dummyRect; | 409 Rect dummyRect; |
398 Handle dummyHandle; | 410 Handle dummyHandle; |
399 short itemHit; | 411 short itemHit; |
400 | 412 |
401 errorDialog = GetNewDialog (1001, nil, (WindowPtr)-1); | 413 errorDialog = GetNewDialog (1001, nil, (WindowPtr)-1); |
414 if (errorDialog == NULL) | |
415 return -1; | |
402 DrawDialog (errorDialog); | 416 DrawDialog (errorDialog); |
403 | 417 |
404 GetDialogItem (errorDialog, kErr_Text, &dummyType, &dummyHandle, &dummyRect); | 418 GetDialogItem (errorDialog, kErr_Text, &dummyType, &dummyHandle, &dummyRect); |
405 SetDialogItemText (dummyHandle, "\pError Initializing SDL"); | 419 SetDialogItemText (dummyHandle, "\pError Initializing SDL"); |
406 | 420 |
421 #if TARGET_API_MAC_CARBON | |
422 SetPort (GetDialogPort(errorDialog)); | |
423 #else | |
407 SetPort (errorDialog); | 424 SetPort (errorDialog); |
425 #endif | |
408 do { | 426 do { |
409 ModalDialog (nil, &itemHit); | 427 ModalDialog (nil, &itemHit); |
410 } while (itemHit != kErr_OK); | 428 } while (itemHit != kErr_OK); |
411 | 429 |
412 DisposeDialog (errorDialog); | 430 DisposeDialog (errorDialog); |
440 DialogPtr commandDialog; | 458 DialogPtr commandDialog; |
441 short dummyType; | 459 short dummyType; |
442 Rect dummyRect; | 460 Rect dummyRect; |
443 Handle dummyHandle; | 461 Handle dummyHandle; |
444 short itemHit; | 462 short itemHit; |
445 | 463 #if TARGET_API_MAC_CARBON |
464 ControlRef control; | |
465 #endif | |
466 | |
446 /* Assume that they will change settings, rather than do exhaustive check */ | 467 /* Assume that they will change settings, rather than do exhaustive check */ |
447 settingsChanged = 1; | 468 settingsChanged = 1; |
448 | 469 |
449 /* Create dialog and display it */ | 470 /* Create dialog and display it */ |
450 commandDialog = GetNewDialog (1000, nil, (DialogPtr)-1); | 471 commandDialog = GetNewDialog (1000, nil, (WindowPtr)-1); |
472 #if TARGET_API_MAC_CARBON | |
473 SetPort ( GetDialogPort(commandDialog) ); | |
474 #else | |
451 SetPort (commandDialog); | 475 SetPort (commandDialog); |
452 | 476 #endif |
477 | |
453 /* Setup controls */ | 478 /* Setup controls */ |
479 #if TARGET_API_MAC_CARBON | |
480 GetDialogItemAsControl(commandDialog, kCL_File, &control); | |
481 SetControlValue (control, prefs.output_to_file); | |
482 #else | |
454 GetDialogItem (commandDialog, kCL_File, &dummyType, &dummyHandle, &dummyRect); /* MJS */ | 483 GetDialogItem (commandDialog, kCL_File, &dummyType, &dummyHandle, &dummyRect); /* MJS */ |
455 SetControlValue ((ControlHandle)dummyHandle, prefs.output_to_file ); | 484 SetControlValue ((ControlHandle)dummyHandle, prefs.output_to_file ); |
485 #endif | |
456 | 486 |
457 GetDialogItem (commandDialog, kCL_Text, &dummyType, &dummyHandle, &dummyRect); | 487 GetDialogItem (commandDialog, kCL_Text, &dummyType, &dummyHandle, &dummyRect); |
458 SetDialogItemText (dummyHandle, prefs.command_line); | 488 SetDialogItemText (dummyHandle, prefs.command_line); |
459 | 489 |
490 #if TARGET_API_MAC_CARBON | |
491 GetDialogItemAsControl(commandDialog, kCL_Video, &control); | |
492 SetControlValue (control, videodriver); | |
493 #else | |
460 GetDialogItem (commandDialog, kCL_Video, &dummyType, &dummyHandle, &dummyRect); | 494 GetDialogItem (commandDialog, kCL_Video, &dummyType, &dummyHandle, &dummyRect); |
461 SetControlValue ((ControlRef)dummyHandle, videodriver); | 495 SetControlValue ((ControlRef)dummyHandle, videodriver); |
496 #endif | |
462 | 497 |
463 SetDialogDefaultItem (commandDialog, kCL_OK); | 498 SetDialogDefaultItem (commandDialog, kCL_OK); |
464 SetDialogCancelItem (commandDialog, kCL_Cancel); | 499 SetDialogCancelItem (commandDialog, kCL_Cancel); |
465 | 500 |
466 do { | 501 do { |
467 | 502 |
468 ModalDialog(nil, &itemHit); /* wait for user response */ | 503 ModalDialog(nil, &itemHit); /* wait for user response */ |
469 | 504 |
470 /* Toggle command-line output checkbox */ | 505 /* Toggle command-line output checkbox */ |
471 if ( itemHit == kCL_File ) { | 506 if ( itemHit == kCL_File ) { |
507 #if TARGET_API_MAC_CARBON | |
508 GetDialogItemAsControl(commandDialog, kCL_File, &control); | |
509 SetControlValue (control, !GetControlValue(control)); | |
510 #else | |
472 GetDialogItem(commandDialog, kCL_File, &dummyType, &dummyHandle, &dummyRect); /* MJS */ | 511 GetDialogItem(commandDialog, kCL_File, &dummyType, &dummyHandle, &dummyRect); /* MJS */ |
473 SetControlValue((ControlHandle)dummyHandle, !GetControlValue((ControlHandle)dummyHandle) ); | 512 SetControlValue((ControlHandle)dummyHandle, !GetControlValue((ControlHandle)dummyHandle) ); |
513 #endif | |
474 } | 514 } |
475 | 515 |
476 } while (itemHit != kCL_OK && itemHit != kCL_Cancel); | 516 } while (itemHit != kCL_OK && itemHit != kCL_Cancel); |
477 | 517 |
478 /* Get control values, even if they did not change */ | 518 /* Get control values, even if they did not change */ |
479 GetDialogItem (commandDialog, kCL_Text, &dummyType, &dummyHandle, &dummyRect); /* MJS */ | 519 GetDialogItem (commandDialog, kCL_Text, &dummyType, &dummyHandle, &dummyRect); /* MJS */ |
480 GetDialogItemText (dummyHandle, prefs.command_line); | 520 GetDialogItemText (dummyHandle, prefs.command_line); |
481 | 521 |
522 #if TARGET_API_MAC_CARBON | |
523 GetDialogItemAsControl(commandDialog, kCL_File, &control); | |
524 prefs.output_to_file = GetControlValue(control); | |
525 #else | |
482 GetDialogItem (commandDialog, kCL_File, &dummyType, &dummyHandle, &dummyRect); /* MJS */ | 526 GetDialogItem (commandDialog, kCL_File, &dummyType, &dummyHandle, &dummyRect); /* MJS */ |
483 prefs.output_to_file = GetControlValue ((ControlHandle)dummyHandle); | 527 prefs.output_to_file = GetControlValue ((ControlHandle)dummyHandle); |
484 | 528 #endif |
529 | |
530 #if TARGET_API_MAC_CARBON | |
531 GetDialogItemAsControl(commandDialog, kCL_Video, &control); | |
532 videodriver = GetControlValue(control); | |
533 #else | |
485 GetDialogItem (commandDialog, kCL_Video, &dummyType, &dummyHandle, &dummyRect); | 534 GetDialogItem (commandDialog, kCL_Video, &dummyType, &dummyHandle, &dummyRect); |
486 videodriver = GetControlValue ((ControlRef)dummyHandle); | 535 videodriver = GetControlValue ((ControlRef)dummyHandle); |
536 #endif | |
487 | 537 |
488 DisposeDialog (commandDialog); | 538 DisposeDialog (commandDialog); |
489 | 539 |
490 if (itemHit == kCL_Cancel ) { | 540 if (itemHit == kCL_Cancel ) { |
491 exit (0); | 541 exit (0); |
502 putenv ("SDL_VIDEODRIVER=toolbox"); | 552 putenv ("SDL_VIDEODRIVER=toolbox"); |
503 memcpy (prefs.video_driver_name, "\ptoolbox", 8); | 553 memcpy (prefs.video_driver_name, "\ptoolbox", 8); |
504 break; | 554 break; |
505 } | 555 } |
506 | 556 |
557 #if !(defined(__APPLE__) && defined(__MACH__)) | |
507 /* Redirect standard I/O to files */ | 558 /* Redirect standard I/O to files */ |
508 if ( prefs.output_to_file ) { | 559 if ( prefs.output_to_file ) { |
509 freopen (STDOUT_FILE, "w", stdout); | 560 freopen (STDOUT_FILE, "w", stdout); |
510 freopen (STDERR_FILE, "w", stderr); | 561 freopen (STDERR_FILE, "w", stderr); |
511 } else { | 562 } else { |
512 fclose (stdout); | 563 fclose (stdout); |
513 fclose (stderr); | 564 fclose (stderr); |
514 } | 565 } |
566 #endif | |
515 | 567 |
516 if (settingsChanged) { | 568 if (settingsChanged) { |
517 /* Save the prefs, even if they might not have changed (but probably did) */ | 569 /* Save the prefs, even if they might not have changed (but probably did) */ |
518 if ( ! writePreferences (&prefs) ) | 570 if ( ! writePreferences (&prefs) ) |
519 fprintf (stderr, "WARNING: Could not save preferences!\n"); | 571 fprintf (stderr, "WARNING: Could not save preferences!\n"); |
520 } | 572 } |
521 | 573 |
574 #if !(defined(__APPLE__) && defined(__MACH__)) | |
575 appNameText[0] = 0; | |
522 getCurrentAppName (appNameText); /* check for error here ? */ | 576 getCurrentAppName (appNameText); /* check for error here ? */ |
523 | 577 |
524 commandLine = (char*) malloc (appNameText[0] + prefs.command_line[0] + 2); | 578 commandLine = (char*) malloc (appNameText[0] + prefs.command_line[0] + 2); |
525 if ( commandLine == NULL ) { | 579 if ( commandLine == NULL ) { |
526 exit(-1); | 580 exit(-1); |
551 free (args); | 605 free (args); |
552 free (commandLine); | 606 free (commandLine); |
553 | 607 |
554 /* Remove useless stdout.txt and stderr.txt */ | 608 /* Remove useless stdout.txt and stderr.txt */ |
555 cleanup_output (); | 609 cleanup_output (); |
610 #else // defined(__APPLE__) && defined(__MACH__) | |
611 SDL_main(argc, argv); | |
612 #endif | |
556 | 613 |
557 /* Exit cleanly, calling atexit() functions */ | 614 /* Exit cleanly, calling atexit() functions */ |
558 exit (0); | 615 exit (0); |
559 | 616 |
560 /* Never reached, but keeps the compiler quiet */ | 617 /* Never reached, but keeps the compiler quiet */ |