Mercurial > sdl-ios-xcode
annotate src/video/cybergfx/SDL_cgxaccel.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 | dcb5e869f8b5 |
children | c9b51268668f |
rev | line source |
---|---|
255
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
21
diff
changeset
|
1 /* |
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
21
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
21
diff
changeset
|
3 Copyright (C) 1997, 1998, 1999, 2000 Sam Lantinga |
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
21
diff
changeset
|
4 |
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
21
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
21
diff
changeset
|
6 modify it under the terms of the GNU Library General Public |
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
21
diff
changeset
|
7 License as published by the Free Software Foundation; either |
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
21
diff
changeset
|
8 version 2 of the License, or (at your option) any later version. |
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
21
diff
changeset
|
9 |
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
21
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
21
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
21
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
21
diff
changeset
|
13 Library General Public License for more details. |
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
21
diff
changeset
|
14 |
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
21
diff
changeset
|
15 You should have received a copy of the GNU Library General Public |
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
21
diff
changeset
|
16 License along with this library; if not, write to the Free |
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
21
diff
changeset
|
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
21
diff
changeset
|
18 |
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
21
diff
changeset
|
19 Sam Lantinga |
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
21
diff
changeset
|
20 slouken@libsdl.org |
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
21
diff
changeset
|
21 */ |
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
21
diff
changeset
|
22 |
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
21
diff
changeset
|
23 #ifdef SAVE_RCSID |
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
21
diff
changeset
|
24 static char rcsid = |
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
21
diff
changeset
|
25 "@(#) $Id$"; |
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
21
diff
changeset
|
26 #endif |
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
21
diff
changeset
|
27 |
0 | 28 #include "SDL_error.h" |
29 #include "SDL_endian.h" | |
30 #include "SDL_sysvideo.h" | |
31 #include "SDL_blit.h" | |
32 #include "SDL_video.h" | |
33 #include "SDL_cgxvideo.h" | |
34 | |
35 static int CGX_HWAccelBlit(SDL_Surface *src, SDL_Rect *srcrect, | |
36 SDL_Surface *dst, SDL_Rect *dstrect); | |
37 | |
38 // These are needed to avoid register troubles with gcc -O2! | |
39 | |
255
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
21
diff
changeset
|
40 #if defined(__SASC) || defined(__PPC__) || defined(MORPHOS) |
0 | 41 #define BMKBRP(a,b,c,d,e,f,g,h,i,j) BltMaskBitMapRastPort(a,b,c,d,e,f,g,h,i,j) |
42 #define BBRP(a,b,c,d,e,f,g,h,i) BltBitMapRastPort(a,b,c,d,e,f,g,h,i) | |
43 #define BBB(a,b,c,d,e,f,g,h,i,j,k) BltBitMap(a,b,c,d,e,f,g,h,i,j,k) | |
44 #else | |
45 void BMKBRP(struct BitMap *a,WORD b, WORD c,struct RastPort *d,WORD e,WORD f,WORD g,WORD h,UBYTE i,APTR j) | |
46 {BltMaskBitMapRastPort(a,b,c,d,e,f,g,h,i,j);} | |
47 | |
255
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
21
diff
changeset
|
48 void BBRP(struct BitMap *a,WORD b, WORD c,struct RastPort *d,WORD e,WORD f,WORD g,WORD h,UBYTE i) |
0 | 49 {BltBitMapRastPort(a,b,c,d,e,f,g,h,i);} |
50 | |
255
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
21
diff
changeset
|
51 void BBB(struct BitMap *a,WORD b, WORD c,struct BitMap *d,WORD e,WORD f,WORD g,WORD h,UBYTE i,UBYTE j,UWORD *k) |
0 | 52 {BltBitMap(a,b,c,d,e,f,g,h,i,j,k);} |
53 #endif | |
54 | |
55 int CGX_SetHWColorKey(_THIS,SDL_Surface *surface, Uint32 key) | |
56 { | |
57 if(surface->hwdata) | |
58 { | |
59 if(surface->hwdata->mask) | |
60 free(surface->hwdata->mask); | |
61 | |
62 if(surface->hwdata->mask=malloc(RASSIZE(surface->w,surface->h))) | |
63 { | |
64 Uint32 pitch,ok=0; | |
65 APTR lock; | |
66 | |
67 memset(surface->hwdata->mask,255,RASSIZE(surface->w,surface->h)); | |
68 | |
255
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
21
diff
changeset
|
69 D(bug("Building colorkey mask: color: %ld, size: %ld x %ld, %ld bytes...Bpp:%ld\n",key,surface->w,surface->h,RASSIZE(surface->w,surface->h),surface->format->BytesPerPixel)); |
0 | 70 |
71 if(lock=LockBitMapTags(surface->hwdata->bmap,LBMI_BASEADDRESS,(ULONG)&surface->pixels, | |
72 LBMI_BYTESPERROW,(ULONG)&pitch,TAG_DONE)) | |
73 { | |
74 switch(surface->format->BytesPerPixel) | |
75 { | |
76 case 1: | |
77 { | |
78 unsigned char k=key; | |
79 register int i,j,t; | |
80 register unsigned char *dest=surface->hwdata->mask,*map=surface->pixels; | |
81 | |
82 pitch-=surface->w; | |
83 | |
84 for(i=0;i<surface->h;i++) | |
85 { | |
86 for(t=128,j=0;j<surface->w;j++) | |
87 { | |
88 if(*map==k) | |
89 *dest&=~t; | |
90 | |
91 t>>=1; | |
92 | |
93 if(t==0) | |
94 { | |
95 dest++; | |
96 t=128; | |
97 } | |
98 map++; | |
99 } | |
100 map+=pitch; | |
101 } | |
102 } | |
103 break; | |
104 case 2: | |
105 { | |
106 Uint16 k=key,*mapw; | |
107 register int i,j,t; | |
108 register unsigned char *dest=surface->hwdata->mask,*map=surface->pixels; | |
109 | |
110 for(i=surface->h;i;--i) | |
111 { | |
112 mapw=(Uint16 *)map; | |
113 | |
114 for(t=128,j=surface->w;j;--j) | |
115 { | |
116 if(*mapw==k) | |
117 *dest&=~t; | |
118 | |
119 t>>=1; | |
120 | |
121 if(t==0) | |
122 { | |
123 dest++; | |
124 t=128; | |
125 } | |
126 mapw++; | |
127 } | |
128 map+=pitch; | |
129 } | |
130 } | |
131 break; | |
132 case 4: | |
133 { | |
134 Uint32 *mapl; | |
135 register int i,j,t; | |
136 register unsigned char *dest=surface->hwdata->mask,*map=surface->pixels; | |
137 | |
138 for(i=surface->h;i;--i) | |
139 { | |
140 mapl=(Uint32 *)map; | |
141 | |
142 for(t=128,j=surface->w;j;--j) | |
143 { | |
144 if(*mapl==key) | |
145 *dest&=~t; | |
146 | |
147 t>>=1; | |
148 | |
149 if(t==0) | |
150 { | |
151 dest++; | |
152 t=128; | |
153 } | |
154 mapl++; | |
155 } | |
156 map+=pitch; | |
157 } | |
158 | |
159 } | |
160 break; | |
161 default: | |
162 D(bug("Pixel mode non supported for color key...")); | |
163 free(surface->hwdata->mask); | |
164 surface->hwdata->mask=NULL; | |
165 ok=-1; | |
166 } | |
167 UnLockBitMap(lock); | |
255
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
21
diff
changeset
|
168 D(bug("...Colorkey built!\n")); |
0 | 169 return ok; |
170 } | |
171 } | |
172 } | |
173 D(bug("HW colorkey not supported for this depth\n")); | |
174 | |
175 return -1; | |
176 } | |
177 | |
178 int CGX_CheckHWBlit(_THIS,SDL_Surface *src,SDL_Surface *dst) | |
179 { | |
180 // Doesn't support yet alpha blitting | |
181 | |
182 if(src->hwdata&& !(src->flags & (SDL_SRCALPHA))) | |
183 { | |
184 D(bug("CheckHW blit... OK!\n")); | |
185 | |
186 if ( (src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) { | |
187 if ( CGX_SetHWColorKey(this, src, src->format->colorkey) < 0 ) { | |
188 src->flags &= ~SDL_HWACCEL; | |
189 return -1; | |
190 } | |
191 } | |
192 | |
193 src->flags|=SDL_HWACCEL; | |
194 src->map->hw_blit = CGX_HWAccelBlit; | |
195 return 1; | |
196 } | |
197 else | |
198 src->flags &= ~SDL_HWACCEL; | |
199 | |
200 D(bug("CheckHW blit... NO!\n")); | |
201 | |
202 return 0; | |
203 } | |
204 | |
205 static int temprp_init=0; | |
206 static struct RastPort temprp; | |
207 | |
208 static int CGX_HWAccelBlit(SDL_Surface *src, SDL_Rect *srcrect, | |
209 SDL_Surface *dst, SDL_Rect *dstrect) | |
210 { | |
211 struct SDL_VideoDevice *this=src->hwdata->videodata; | |
212 | |
213 // D(bug("Accel blit!\n")); | |
214 | |
215 if(src->flags&SDL_SRCCOLORKEY && src->hwdata->mask) | |
216 { | |
217 if(dst==SDL_VideoSurface) | |
218 { | |
219 BMKBRP(src->hwdata->bmap,srcrect->x,srcrect->y, | |
220 SDL_RastPort,dstrect->x+SDL_Window->BorderLeft,dstrect->y+SDL_Window->BorderTop, | |
221 srcrect->w,srcrect->h,0xc0,src->hwdata->mask); | |
222 } | |
223 else if(dst->hwdata) | |
224 { | |
225 if(!temprp_init) | |
226 { | |
227 InitRastPort(&temprp); | |
228 temprp_init=1; | |
229 } | |
230 temprp.BitMap=(struct BitMap *)dst->hwdata->bmap; | |
231 | |
232 BMKBRP(src->hwdata->bmap,srcrect->x,srcrect->y, | |
233 &temprp,dstrect->x,dstrect->y, | |
234 srcrect->w,srcrect->h,0xc0,src->hwdata->mask); | |
235 | |
236 } | |
237 } | |
238 else if(dst==SDL_VideoSurface) | |
239 { | |
240 BBRP(src->hwdata->bmap,srcrect->x,srcrect->y,SDL_RastPort,dstrect->x+SDL_Window->BorderLeft,dstrect->y+SDL_Window->BorderTop,srcrect->w,srcrect->h,0xc0); | |
241 } | |
242 else if(dst->hwdata) | |
243 BBB(src->hwdata->bmap,srcrect->x,srcrect->y,dst->hwdata->bmap,dstrect->x,dstrect->y,srcrect->w,srcrect->h,0xc0,0xff,NULL); | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
244 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
245 return 0; |
0 | 246 } |
247 | |
248 int CGX_FillHWRect(_THIS,SDL_Surface *dst,SDL_Rect *dstrect,Uint32 color) | |
249 { | |
250 if(dst==SDL_VideoSurface) | |
251 { | |
252 FillPixelArray(SDL_RastPort,dstrect->x+SDL_Window->BorderLeft,dstrect->y+SDL_Window->BorderTop,dstrect->w,dstrect->h,color); | |
253 } | |
254 else if(dst->hwdata) | |
255 { | |
256 if(!temprp_init) | |
257 { | |
258 InitRastPort(&temprp); | |
259 temprp_init=1; | |
260 } | |
261 | |
262 temprp.BitMap=(struct BitMap *)dst->hwdata->bmap; | |
263 | |
264 FillPixelArray(&temprp,dstrect->x,dstrect->y,dstrect->w,dstrect->h,color); | |
265 } | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
266 return 0; |
0 | 267 } |