Mercurial > sdl-ios-xcode
comparison src/video/cybergfx/SDL_cgxaccel.c @ 1662:782fd950bd46 SDL-1.3
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid.
The code is now run through a consistent indent format:
indent -i4 -nut -nsc -br -ce
The headers are being converted to automatically generate doxygen documentation.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 28 May 2006 13:04:16 +0000 |
parents | d910939febfa |
children | 4da1ee79c9af |
comparison
equal
deleted
inserted
replaced
1661:281d3f4870e5 | 1662:782fd950bd46 |
---|---|
25 #include "SDL_video.h" | 25 #include "SDL_video.h" |
26 #include "../SDL_sysvideo.h" | 26 #include "../SDL_sysvideo.h" |
27 #include "../SDL_blit.h" | 27 #include "../SDL_blit.h" |
28 #include "SDL_cgxvideo.h" | 28 #include "SDL_cgxvideo.h" |
29 | 29 |
30 static int CGX_HWAccelBlit(SDL_Surface *src, SDL_Rect *srcrect, | 30 static int CGX_HWAccelBlit (SDL_Surface * src, SDL_Rect * srcrect, |
31 SDL_Surface *dst, SDL_Rect *dstrect); | 31 SDL_Surface * dst, SDL_Rect * dstrect); |
32 | 32 |
33 // These are needed to avoid register troubles with gcc -O2! | 33 // These are needed to avoid register troubles with gcc -O2! |
34 | 34 |
35 #if defined(__SASC) || defined(__PPC__) || defined(MORPHOS) | 35 #if defined(__SASC) || defined(__PPC__) || defined(MORPHOS) |
36 #define BMKBRP(a,b,c,d,e,f,g,h,i,j) BltMaskBitMapRastPort(a,b,c,d,e,f,g,h,i,j) | 36 #define BMKBRP(a,b,c,d,e,f,g,h,i,j) BltMaskBitMapRastPort(a,b,c,d,e,f,g,h,i,j) |
37 #define BBRP(a,b,c,d,e,f,g,h,i) BltBitMapRastPort(a,b,c,d,e,f,g,h,i) | 37 #define BBRP(a,b,c,d,e,f,g,h,i) BltBitMapRastPort(a,b,c,d,e,f,g,h,i) |
38 #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) | 38 #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) |
39 #else | 39 #else |
40 void BMKBRP(struct BitMap *a,WORD b, WORD c,struct RastPort *d,WORD e,WORD f,WORD g,WORD h,UBYTE i,APTR j) | 40 void |
41 {BltMaskBitMapRastPort(a,b,c,d,e,f,g,h,i,j);} | 41 BMKBRP (struct BitMap *a, WORD b, WORD c, struct RastPort *d, WORD e, WORD f, |
42 | 42 WORD g, WORD h, UBYTE i, APTR j) |
43 void BBRP(struct BitMap *a,WORD b, WORD c,struct RastPort *d,WORD e,WORD f,WORD g,WORD h,UBYTE i) | 43 { |
44 {BltBitMapRastPort(a,b,c,d,e,f,g,h,i);} | 44 BltMaskBitMapRastPort (a, b, c, d, e, f, g, h, i, j); |
45 | 45 } |
46 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) | 46 |
47 {BltBitMap(a,b,c,d,e,f,g,h,i,j,k);} | 47 void |
48 BBRP (struct BitMap *a, WORD b, WORD c, struct RastPort *d, WORD e, WORD f, | |
49 WORD g, WORD h, UBYTE i) | |
50 { | |
51 BltBitMapRastPort (a, b, c, d, e, f, g, h, i); | |
52 } | |
53 | |
54 void | |
55 BBB (struct BitMap *a, WORD b, WORD c, struct BitMap *d, WORD e, WORD f, | |
56 WORD g, WORD h, UBYTE i, UBYTE j, UWORD * k) | |
57 { | |
58 BltBitMap (a, b, c, d, e, f, g, h, i, j, k); | |
59 } | |
48 #endif | 60 #endif |
49 | 61 |
50 int CGX_SetHWColorKey(_THIS,SDL_Surface *surface, Uint32 key) | 62 int |
51 { | 63 CGX_SetHWColorKey (_THIS, SDL_Surface * surface, Uint32 key) |
52 if(surface->hwdata) | 64 { |
53 { | 65 if (surface->hwdata) { |
54 if(surface->hwdata->mask) | 66 if (surface->hwdata->mask) |
55 SDL_free(surface->hwdata->mask); | 67 SDL_free (surface->hwdata->mask); |
56 | 68 |
57 if(surface->hwdata->mask=SDL_malloc(RASSIZE(surface->w,surface->h))) | 69 if (surface->hwdata->mask = |
58 { | 70 SDL_malloc (RASSIZE (surface->w, surface->h))) { |
59 Uint32 pitch,ok=0; | 71 Uint32 pitch, ok = 0; |
60 APTR lock; | 72 APTR lock; |
61 | 73 |
62 SDL_memset(surface->hwdata->mask,255,RASSIZE(surface->w,surface->h)); | 74 SDL_memset (surface->hwdata->mask, 255, |
63 | 75 RASSIZE (surface->w, surface->h)); |
64 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)); | 76 |
65 | 77 D (bug |
66 if(lock=LockBitMapTags(surface->hwdata->bmap,LBMI_BASEADDRESS,(ULONG)&surface->pixels, | 78 ("Building colorkey mask: color: %ld, size: %ld x %ld, %ld bytes...Bpp:%ld\n", |
67 LBMI_BYTESPERROW,(ULONG)&pitch,TAG_DONE)) | 79 key, surface->w, surface->h, RASSIZE (surface->w, |
68 { | 80 surface->h), |
69 switch(surface->format->BytesPerPixel) | 81 surface->format->BytesPerPixel)); |
70 { | 82 |
71 case 1: | 83 if (lock = |
72 { | 84 LockBitMapTags (surface->hwdata->bmap, LBMI_BASEADDRESS, |
73 unsigned char k=key; | 85 (ULONG) & surface->pixels, |
74 register int i,j,t; | 86 LBMI_BYTESPERROW, (ULONG) & pitch, |
75 register unsigned char *dest=surface->hwdata->mask,*map=surface->pixels; | 87 TAG_DONE)) { |
76 | 88 switch (surface->format->BytesPerPixel) { |
77 pitch-=surface->w; | 89 case 1: |
78 | 90 { |
79 for(i=0;i<surface->h;i++) | 91 unsigned char k = key; |
80 { | 92 register int i, j, t; |
81 for(t=128,j=0;j<surface->w;j++) | 93 register unsigned char *dest = |
82 { | 94 surface->hwdata->mask, *map = surface->pixels; |
83 if(*map==k) | 95 |
84 *dest&=~t; | 96 pitch -= surface->w; |
85 | 97 |
86 t>>=1; | 98 for (i = 0; i < surface->h; i++) { |
87 | 99 for (t = 128, j = 0; j < surface->w; j++) { |
88 if(t==0) | 100 if (*map == k) |
89 { | 101 *dest &= ~t; |
90 dest++; | 102 |
91 t=128; | 103 t >>= 1; |
92 } | 104 |
93 map++; | 105 if (t == 0) { |
94 } | 106 dest++; |
95 map+=pitch; | 107 t = 128; |
96 } | 108 } |
97 } | 109 map++; |
98 break; | 110 } |
99 case 2: | 111 map += pitch; |
100 { | 112 } |
101 Uint16 k=key,*mapw; | 113 } |
102 register int i,j,t; | 114 break; |
103 register unsigned char *dest=surface->hwdata->mask,*map=surface->pixels; | 115 case 2: |
104 | 116 { |
105 for(i=surface->h;i;--i) | 117 Uint16 k = key, *mapw; |
106 { | 118 register int i, j, t; |
107 mapw=(Uint16 *)map; | 119 register unsigned char *dest = |
108 | 120 surface->hwdata->mask, *map = surface->pixels; |
109 for(t=128,j=surface->w;j;--j) | 121 |
110 { | 122 for (i = surface->h; i; --i) { |
111 if(*mapw==k) | 123 mapw = (Uint16 *) map; |
112 *dest&=~t; | 124 |
113 | 125 for (t = 128, j = surface->w; j; --j) { |
114 t>>=1; | 126 if (*mapw == k) |
115 | 127 *dest &= ~t; |
116 if(t==0) | 128 |
117 { | 129 t >>= 1; |
118 dest++; | 130 |
119 t=128; | 131 if (t == 0) { |
120 } | 132 dest++; |
121 mapw++; | 133 t = 128; |
122 } | 134 } |
123 map+=pitch; | 135 mapw++; |
124 } | 136 } |
125 } | 137 map += pitch; |
126 break; | 138 } |
127 case 4: | 139 } |
128 { | 140 break; |
129 Uint32 *mapl; | 141 case 4: |
130 register int i,j,t; | 142 { |
131 register unsigned char *dest=surface->hwdata->mask,*map=surface->pixels; | 143 Uint32 *mapl; |
132 | 144 register int i, j, t; |
133 for(i=surface->h;i;--i) | 145 register unsigned char *dest = |
134 { | 146 surface->hwdata->mask, *map = surface->pixels; |
135 mapl=(Uint32 *)map; | 147 |
136 | 148 for (i = surface->h; i; --i) { |
137 for(t=128,j=surface->w;j;--j) | 149 mapl = (Uint32 *) map; |
138 { | 150 |
139 if(*mapl==key) | 151 for (t = 128, j = surface->w; j; --j) { |
140 *dest&=~t; | 152 if (*mapl == key) |
141 | 153 *dest &= ~t; |
142 t>>=1; | 154 |
143 | 155 t >>= 1; |
144 if(t==0) | 156 |
145 { | 157 if (t == 0) { |
146 dest++; | 158 dest++; |
147 t=128; | 159 t = 128; |
148 } | 160 } |
149 mapl++; | 161 mapl++; |
150 } | 162 } |
151 map+=pitch; | 163 map += pitch; |
152 } | 164 } |
153 | 165 |
154 } | 166 } |
155 break; | 167 break; |
156 default: | 168 default: |
157 D(bug("Pixel mode non supported for color key...")); | 169 D (bug ("Pixel mode non supported for color key...")); |
158 SDL_free(surface->hwdata->mask); | 170 SDL_free (surface->hwdata->mask); |
159 surface->hwdata->mask=NULL; | 171 surface->hwdata->mask = NULL; |
160 ok=-1; | 172 ok = -1; |
161 } | 173 } |
162 UnLockBitMap(lock); | 174 UnLockBitMap (lock); |
163 D(bug("...Colorkey built!\n")); | 175 D (bug ("...Colorkey built!\n")); |
164 return ok; | 176 return ok; |
165 } | 177 } |
166 } | 178 } |
167 } | 179 } |
168 D(bug("HW colorkey not supported for this depth\n")); | 180 D (bug ("HW colorkey not supported for this depth\n")); |
169 | 181 |
170 return -1; | 182 return -1; |
171 } | 183 } |
172 | 184 |
173 int CGX_CheckHWBlit(_THIS,SDL_Surface *src,SDL_Surface *dst) | 185 int |
186 CGX_CheckHWBlit (_THIS, SDL_Surface * src, SDL_Surface * dst) | |
174 { | 187 { |
175 // Doesn't support yet alpha blitting | 188 // Doesn't support yet alpha blitting |
176 | 189 |
177 if(src->hwdata&& !(src->flags & (SDL_SRCALPHA))) | 190 if (src->hwdata && !(src->flags & (SDL_SRCALPHA))) { |
178 { | 191 D (bug ("CheckHW blit... OK!\n")); |
179 D(bug("CheckHW blit... OK!\n")); | 192 |
180 | 193 if ((src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) { |
181 if ( (src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) { | 194 if (CGX_SetHWColorKey (this, src, src->format->colorkey) < 0) { |
182 if ( CGX_SetHWColorKey(this, src, src->format->colorkey) < 0 ) { | 195 src->flags &= ~SDL_HWACCEL; |
183 src->flags &= ~SDL_HWACCEL; | 196 return -1; |
184 return -1; | 197 } |
185 } | 198 } |
186 } | 199 |
187 | 200 src->flags |= SDL_HWACCEL; |
188 src->flags|=SDL_HWACCEL; | 201 src->map->hw_blit = CGX_HWAccelBlit; |
189 src->map->hw_blit = CGX_HWAccelBlit; | 202 return 1; |
190 return 1; | 203 } else |
191 } | 204 src->flags &= ~SDL_HWACCEL; |
192 else | 205 |
193 src->flags &= ~SDL_HWACCEL; | 206 D (bug ("CheckHW blit... NO!\n")); |
194 | 207 |
195 D(bug("CheckHW blit... NO!\n")); | 208 return 0; |
196 | 209 } |
197 return 0; | 210 |
198 } | 211 static int temprp_init = 0; |
199 | |
200 static int temprp_init=0; | |
201 static struct RastPort temprp; | 212 static struct RastPort temprp; |
202 | 213 |
203 static int CGX_HWAccelBlit(SDL_Surface *src, SDL_Rect *srcrect, | 214 static int |
204 SDL_Surface *dst, SDL_Rect *dstrect) | 215 CGX_HWAccelBlit (SDL_Surface * src, SDL_Rect * srcrect, |
205 { | 216 SDL_Surface * dst, SDL_Rect * dstrect) |
206 struct SDL_VideoDevice *this=src->hwdata->videodata; | 217 { |
207 | 218 struct SDL_VideoDevice *this = src->hwdata->videodata; |
208 // D(bug("Accel blit!\n")); | 219 |
209 | 220 // D(bug("Accel blit!\n")); |
210 if(src->flags&SDL_SRCCOLORKEY && src->hwdata->mask) | 221 |
211 { | 222 if (src->flags & SDL_SRCCOLORKEY && src->hwdata->mask) { |
212 if(dst==SDL_VideoSurface) | 223 if (dst == SDL_VideoSurface) { |
213 { | 224 BMKBRP (src->hwdata->bmap, srcrect->x, srcrect->y, |
214 BMKBRP(src->hwdata->bmap,srcrect->x,srcrect->y, | 225 SDL_RastPort, dstrect->x + SDL_Window->BorderLeft, |
215 SDL_RastPort,dstrect->x+SDL_Window->BorderLeft,dstrect->y+SDL_Window->BorderTop, | 226 dstrect->y + SDL_Window->BorderTop, srcrect->w, |
216 srcrect->w,srcrect->h,0xc0,src->hwdata->mask); | 227 srcrect->h, 0xc0, src->hwdata->mask); |
217 } | 228 } else if (dst->hwdata) { |
218 else if(dst->hwdata) | 229 if (!temprp_init) { |
219 { | 230 InitRastPort (&temprp); |
220 if(!temprp_init) | 231 temprp_init = 1; |
221 { | 232 } |
222 InitRastPort(&temprp); | 233 temprp.BitMap = (struct BitMap *) dst->hwdata->bmap; |
223 temprp_init=1; | 234 |
224 } | 235 BMKBRP (src->hwdata->bmap, srcrect->x, srcrect->y, |
225 temprp.BitMap=(struct BitMap *)dst->hwdata->bmap; | 236 &temprp, dstrect->x, dstrect->y, |
226 | 237 srcrect->w, srcrect->h, 0xc0, src->hwdata->mask); |
227 BMKBRP(src->hwdata->bmap,srcrect->x,srcrect->y, | 238 |
228 &temprp,dstrect->x,dstrect->y, | 239 } |
229 srcrect->w,srcrect->h,0xc0,src->hwdata->mask); | 240 } else if (dst == SDL_VideoSurface) { |
230 | 241 BBRP (src->hwdata->bmap, srcrect->x, srcrect->y, SDL_RastPort, |
231 } | 242 dstrect->x + SDL_Window->BorderLeft, |
232 } | 243 dstrect->y + SDL_Window->BorderTop, srcrect->w, srcrect->h, |
233 else if(dst==SDL_VideoSurface) | 244 0xc0); |
234 { | 245 } else if (dst->hwdata) |
235 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); | 246 BBB (src->hwdata->bmap, srcrect->x, srcrect->y, dst->hwdata->bmap, |
236 } | 247 dstrect->x, dstrect->y, srcrect->w, srcrect->h, 0xc0, 0xff, |
237 else if(dst->hwdata) | 248 NULL); |
238 BBB(src->hwdata->bmap,srcrect->x,srcrect->y,dst->hwdata->bmap,dstrect->x,dstrect->y,srcrect->w,srcrect->h,0xc0,0xff,NULL); | 249 |
239 | 250 return 0; |
240 return 0; | 251 } |
241 } | 252 |
242 | 253 int |
243 int CGX_FillHWRect(_THIS,SDL_Surface *dst,SDL_Rect *dstrect,Uint32 color) | 254 CGX_FillHWRect (_THIS, SDL_Surface * dst, SDL_Rect * dstrect, Uint32 color) |
244 { | 255 { |
245 if(dst==SDL_VideoSurface) | 256 if (dst == SDL_VideoSurface) { |
246 { | 257 FillPixelArray (SDL_RastPort, dstrect->x + SDL_Window->BorderLeft, |
247 FillPixelArray(SDL_RastPort,dstrect->x+SDL_Window->BorderLeft,dstrect->y+SDL_Window->BorderTop,dstrect->w,dstrect->h,color); | 258 dstrect->y + SDL_Window->BorderTop, dstrect->w, |
248 } | 259 dstrect->h, color); |
249 else if(dst->hwdata) | 260 } else if (dst->hwdata) { |
250 { | 261 if (!temprp_init) { |
251 if(!temprp_init) | 262 InitRastPort (&temprp); |
252 { | 263 temprp_init = 1; |
253 InitRastPort(&temprp); | 264 } |
254 temprp_init=1; | 265 |
255 } | 266 temprp.BitMap = (struct BitMap *) dst->hwdata->bmap; |
256 | 267 |
257 temprp.BitMap=(struct BitMap *)dst->hwdata->bmap; | 268 FillPixelArray (&temprp, dstrect->x, dstrect->y, dstrect->w, |
258 | 269 dstrect->h, color); |
259 FillPixelArray(&temprp,dstrect->x,dstrect->y,dstrect->w,dstrect->h,color); | 270 } |
260 } | 271 return 0; |
261 return 0; | 272 } |
262 } | 273 |
274 /* vi: set ts=4 sw=4 expandtab: */ |