Mercurial > sdl-ios-xcode
comparison src/video/macdsp/SDL_dspvideo.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 | c1c2efca4548 |
children | cf6133247d34 |
comparison
equal
deleted
inserted
replaced
1132:a0d3514c04b2 | 1133:609c060fd2a2 |
---|---|
64 ------------------------------------------------------------------------------------ | 64 ------------------------------------------------------------------------------------ |
65 | 65 |
66 System requirements (* denotes optional): | 66 System requirements (* denotes optional): |
67 | 67 |
68 1. DrawSprocket 1.7.3 | 68 1. DrawSprocket 1.7.3 |
69 2. *MacOS 9 or later for hardware accelerated blit / fill | 69 2. *MacOS 9 or later (but *not* Mac OS X) for hardware accelerated blit / fill |
70 3. *May also require certain graphics hardware for (2). I trust that all Apple OEM | 70 3. *May also require certain graphics hardware for (2). I trust that all Apple OEM |
71 hardware will work. Third party accelerators may work if they have QuickDraw | 71 hardware will work. Third party accelerators may work if they have QuickDraw |
72 acceleration in the drivers and the drivers have been updated for OS 9. The current | 72 acceleration in the drivers and the drivers have been updated for OS 9. The current |
73 Voodoo 3 drivers (1.0b12) do not work. | 73 Voodoo 3 drivers (1.0b12) do not work. |
74 | 74 |
128 #endif | 128 #endif |
129 | 129 |
130 #include <stdio.h> | 130 #include <stdio.h> |
131 #include <stdlib.h> | 131 #include <stdlib.h> |
132 | 132 |
133 #if TARGET_API_MAC_CARBON | 133 #if defined(__APPLE__) && defined(__MACH__) |
134 #include <Carbon/Carbon.h> | |
135 #include <DrawSprocket/DrawSprocket.h> | |
136 #elif TARGET_API_MAC_CARBON && (UNIVERSAL_INTERFACES_VERSION > 0x0335) | |
134 #include <Carbon.h> | 137 #include <Carbon.h> |
138 #include <DrawSprocket.h> | |
135 #else | 139 #else |
136 #include <LowMem.h> | 140 #include <LowMem.h> |
137 #include <Gestalt.h> | 141 #include <Gestalt.h> |
138 #include <Devices.h> | 142 #include <Devices.h> |
139 #include <DiskInit.h> | 143 #include <DiskInit.h> |
140 #include <QDOffscreen.h> | 144 #include <QDOffscreen.h> |
145 #include <DrawSprocket.h> | |
141 #endif | 146 #endif |
142 | 147 |
143 #include "SDL_video.h" | 148 #include "SDL_video.h" |
144 #include "SDL_blit.h" | 149 #include "SDL_blit.h" |
145 #include "SDL_error.h" | 150 #include "SDL_error.h" |
146 #include "SDL_syswm.h" | 151 #include "SDL_syswm.h" |
147 #include "SDL_sysvideo.h" | 152 #include "SDL_sysvideo.h" |
153 #include "SDL_pixels_c.h" | |
148 #include "SDL_dspvideo.h" | 154 #include "SDL_dspvideo.h" |
149 #include "SDL_macgl_c.h" | 155 #include "SDL_macgl_c.h" |
150 #include "SDL_macwm_c.h" | 156 #include "SDL_macwm_c.h" |
151 #include "SDL_macmouse_c.h" | 157 #include "SDL_macmouse_c.h" |
152 #include "SDL_macevents_c.h" | 158 #include "SDL_macevents_c.h" |
219 /* Macintosh toolbox driver bootstrap functions */ | 225 /* Macintosh toolbox driver bootstrap functions */ |
220 | 226 |
221 static int DSp_Available(void) | 227 static int DSp_Available(void) |
222 { | 228 { |
223 /* Check for DrawSprocket */ | 229 /* Check for DrawSprocket */ |
230 #if ! TARGET_API_MAC_OSX | |
224 /* This check is only meaningful if you weak-link DrawSprocketLib */ | 231 /* This check is only meaningful if you weak-link DrawSprocketLib */ |
225 return ((Ptr)DSpStartup != (Ptr)kUnresolvedCFragSymbolAddress); | 232 return ((Ptr)DSpStartup != (Ptr)kUnresolvedCFragSymbolAddress); |
233 #else | |
234 return 1; // DrawSprocket.framework doesn't have it all, but it's there | |
235 #endif | |
226 } | 236 } |
227 | 237 |
228 static void DSp_DeleteDevice(SDL_VideoDevice *device) | 238 static void DSp_DeleteDevice(SDL_VideoDevice *device) |
229 { | 239 { |
230 /* -dw- taking no chances with null pointers */ | 240 /* -dw- taking no chances with null pointers */ |
428 OSStatus err; | 438 OSStatus err; |
429 Rect bounds; | 439 Rect bounds; |
430 | 440 |
431 SetRect (&bounds, 0, 0, 320, 240); | 441 SetRect (&bounds, 0, 0, 320, 240); |
432 | 442 |
443 #if useDistantHdwrMem && useLocalHdwrMem | |
433 err = NewGWorld (&offscreen, vformat->BitsPerPixel, &bounds, NULL, SDL_Display, useDistantHdwrMem | noNewDevice); | 444 err = NewGWorld (&offscreen, vformat->BitsPerPixel, &bounds, NULL, SDL_Display, useDistantHdwrMem | noNewDevice); |
434 if (err == noErr) { | 445 if (err == noErr) { |
435 dsp_vram_available = SDL_TRUE; | 446 dsp_vram_available = SDL_TRUE; |
436 DisposeGWorld (offscreen); | 447 DisposeGWorld (offscreen); |
437 } | 448 } |
439 err = NewGWorld (&offscreen, vformat->BitsPerPixel, &bounds, NULL, SDL_Display, useLocalHdwrMem | noNewDevice); | 450 err = NewGWorld (&offscreen, vformat->BitsPerPixel, &bounds, NULL, SDL_Display, useLocalHdwrMem | noNewDevice); |
440 if (err == noErr) { | 451 if (err == noErr) { |
441 DisposeGWorld (offscreen); | 452 DisposeGWorld (offscreen); |
442 dsp_agp_available = SDL_TRUE; | 453 dsp_agp_available = SDL_TRUE; |
443 } | 454 } |
455 #endif | |
444 } | 456 } |
445 } | 457 } |
446 | 458 |
447 static int DSp_GetMainDevice (_THIS, GDHandle *device) | 459 static int DSp_GetMainDevice (_THIS, GDHandle *device) |
448 { | 460 { |
506 #endif | 518 #endif |
507 } | 519 } |
508 | 520 |
509 static int DSp_VideoInit(_THIS, SDL_PixelFormat *vformat) | 521 static int DSp_VideoInit(_THIS, SDL_PixelFormat *vformat) |
510 { | 522 { |
511 | 523 NumVersion dsp_version; |
512 NumVersion dsp_version = DSpGetVersion (); | 524 |
525 dsp_version = DSpGetVersion (); | |
513 | 526 |
514 if ( (dsp_version.majorRev == 1 && dsp_version.minorAndBugRev < 0x73) || | 527 if ( (dsp_version.majorRev == 1 && dsp_version.minorAndBugRev < 0x73) || |
515 (dsp_version.majorRev < 1) ) { | 528 (dsp_version.majorRev < 1) ) { |
516 | 529 |
517 /* StandardAlert (kAlertStopAlert, "\pError!", | 530 /* StandardAlert (kAlertStopAlert, "\pError!", |
613 } | 626 } |
614 | 627 |
615 /* Various screen update functions available */ | 628 /* Various screen update functions available */ |
616 static void DSp_DirectUpdate(_THIS, int numrects, SDL_Rect *rects); | 629 static void DSp_DirectUpdate(_THIS, int numrects, SDL_Rect *rects); |
617 | 630 |
631 #if ! TARGET_API_MAC_OSX | |
632 | |
618 static volatile unsigned int retrace_count = 0; /* -dw- need volatile because it updates asychronously */ | 633 static volatile unsigned int retrace_count = 0; /* -dw- need volatile because it updates asychronously */ |
619 | 634 |
620 #if ! TARGET_API_MAC_OSX | |
621 Boolean DSp_VBLProc ( DSpContextReference context, void *ref_con ) | 635 Boolean DSp_VBLProc ( DSpContextReference context, void *ref_con ) |
622 { | 636 { |
623 retrace_count++; | 637 retrace_count++; |
624 | 638 |
625 return 1; /* Darrell, is this right? */ | 639 return 1; /* Darrell, is this right? */ |
626 } | 640 } |
627 #endif | |
628 | 641 |
629 static void DSp_SetHWError (OSStatus err, int is_agp) | 642 static void DSp_SetHWError (OSStatus err, int is_agp) |
630 { | 643 { |
631 char message[1024]; | 644 char message[1024]; |
632 const char *fmt, *mem; | 645 const char *fmt, *mem; |
648 break; | 661 break; |
649 } | 662 } |
650 sprintf(message, fmt, mem); | 663 sprintf(message, fmt, mem); |
651 SDL_SetError(message); | 664 SDL_SetError(message); |
652 } | 665 } |
666 #endif // TARGET_API_MAC_OSX | |
653 | 667 |
654 /* put up a dialog to verify display change */ | 668 /* put up a dialog to verify display change */ |
655 static int DSp_ConfirmSwitch () { | 669 static int DSp_ConfirmSwitch () { |
656 | 670 |
657 /* resource id's for dialog */ | 671 /* resource id's for dialog */ |
669 | 683 |
670 dialog = GetNewDialog (rDialog, NULL, (WindowPtr) -1); | 684 dialog = GetNewDialog (rDialog, NULL, (WindowPtr) -1); |
671 if (dialog == NULL) | 685 if (dialog == NULL) |
672 return (0); | 686 return (0); |
673 | 687 |
674 SetPort (dialog); | 688 #if TARGET_API_CARBON |
689 SetPort (GetDialogPort(dialog)); | |
690 #else | |
691 SetPort ((WindowPtr) dialog); | |
692 #endif | |
675 | 693 |
676 SetDialogDefaultItem (dialog, bCancel); | 694 SetDialogDefaultItem (dialog, bCancel); |
677 SetDialogCancelItem (dialog, bCancel); | 695 SetDialogCancelItem (dialog, bCancel); |
678 | 696 |
679 SetEventMask (everyEvent); | 697 SetEventMask (everyEvent); |
691 | 709 |
692 ModalDialog ( NULL, &item ); | 710 ModalDialog ( NULL, &item ); |
693 | 711 |
694 } while ( item != bCancel && item != bOK && err != noErr); | 712 } while ( item != bCancel && item != bOK && err != noErr); |
695 | 713 |
696 DisposeWindow (dialog); | 714 |
715 DisposeDialog (dialog); | |
697 SetPort (savePort); | 716 SetPort (savePort); |
698 | 717 |
699 SetEventMask(everyEvent - autoKeyMask); | 718 SetEventMask(everyEvent - autoKeyMask); |
700 FlushEvents(everyEvent, 0); | 719 FlushEvents(everyEvent, 0); |
701 | 720 |
738 | 757 |
739 static SDL_Surface *DSp_SetVideoMode(_THIS, | 758 static SDL_Surface *DSp_SetVideoMode(_THIS, |
740 SDL_Surface *current, int width, int height, int bpp, Uint32 flags) | 759 SDL_Surface *current, int width, int height, int bpp, Uint32 flags) |
741 { | 760 { |
742 | 761 |
743 DisplayIDType display_id; | 762 #if !TARGET_API_MAC_OSX |
763 DisplayIDType display_id; | |
764 Fixed freq; | |
765 #endif | |
744 DSpContextAttributes attrib; | 766 DSpContextAttributes attrib; |
745 Fixed freq; | |
746 OSStatus err; | 767 OSStatus err; |
747 UInt32 rmask = 0, gmask = 0, bmask = 0; | 768 UInt32 rmask = 0, gmask = 0, bmask = 0; |
748 | 769 |
749 int page_count; | 770 int page_count; |
750 int double_buf; | 771 int double_buf; |
922 return NULL; | 943 return NULL; |
923 } | 944 } |
924 | 945 |
925 /* Set window color to black to avoid white flash*/ | 946 /* Set window color to black to avoid white flash*/ |
926 GetPort (&save_port); | 947 GetPort (&save_port); |
948 #if TARGET_API_MAC_CARBON | |
949 SetPort (GetWindowPort(SDL_Window)); | |
950 #else | |
927 SetPort (SDL_Window); | 951 SetPort (SDL_Window); |
952 #endif | |
928 RGBForeColor (&rgb); | 953 RGBForeColor (&rgb); |
929 PaintRect (&rect); | 954 PaintRect (&rect); |
930 SetPort (save_port); | 955 SetPort (save_port); |
931 | 956 |
932 SetPortWindowPort (SDL_Window); | 957 SetPortWindowPort (SDL_Window); |
1029 OSStatus err; | 1054 OSStatus err; |
1030 Rect bounds; | 1055 Rect bounds; |
1031 | 1056 |
1032 SetRect (&bounds, 0, 0, width, height); | 1057 SetRect (&bounds, 0, 0, width, height); |
1033 | 1058 |
1059 #if useDistantHdwrMem && useLocalHdwrMem | |
1034 if (dsp_vram_available) { | 1060 if (dsp_vram_available) { |
1035 /* try VRAM */ | 1061 /* try VRAM */ |
1036 err = NewGWorld (port, depth, &bounds, 0 , SDL_Display, useDistantHdwrMem | noNewDevice ); | 1062 err = NewGWorld (port, depth, &bounds, 0 , SDL_Display, useDistantHdwrMem | noNewDevice ); |
1037 if (err != noErr) | 1063 if (err != noErr) |
1038 DSp_SetHWError (err, SDL_FALSE); | 1064 DSp_SetHWError (err, SDL_FALSE); |
1047 if (err != noErr) | 1073 if (err != noErr) |
1048 DSp_SetHWError (err, SDL_TRUE); | 1074 DSp_SetHWError (err, SDL_TRUE); |
1049 else | 1075 else |
1050 return (0); | 1076 return (0); |
1051 } | 1077 } |
1078 #endif | |
1052 | 1079 |
1053 return (-1); | 1080 return (-1); |
1054 } | 1081 } |
1055 | 1082 |
1056 static int DSp_AllocHWSurface(_THIS, SDL_Surface *surface) | 1083 static int DSp_AllocHWSurface(_THIS, SDL_Surface *surface) |
1208 { | 1235 { |
1209 if ( (surface->flags & SDL_HWSURFACE) ) { | 1236 if ( (surface->flags & SDL_HWSURFACE) ) { |
1210 CGrafPtr dsp_front_buffer, save_port; | 1237 CGrafPtr dsp_front_buffer, save_port; |
1211 Rect rect; | 1238 Rect rect; |
1212 | 1239 |
1240 #if ! TARGET_API_MAC_OSX | |
1213 unsigned int old_count; | 1241 unsigned int old_count; |
1214 | 1242 #endif |
1243 | |
1215 /* pseudo page flipping for VRAM back buffer*/ | 1244 /* pseudo page flipping for VRAM back buffer*/ |
1216 DSpContext_GetFrontBuffer (dsp_context, &dsp_front_buffer); | 1245 DSpContext_GetFrontBuffer (dsp_context, &dsp_front_buffer); |
1217 SetRect (&rect, 0, 0, surface->w-1, surface->h-1); | 1246 SetRect (&rect, 0, 0, surface->w-1, surface->h-1); |
1218 | 1247 |
1219 GetPort ((GrafPtr *)&save_port); | 1248 GetPort ((GrafPtr *)&save_port); |