comparison src/video/cybergfx/SDL_cgxaccel.c @ 0:74212992fb08

Initial revision
author Sam Lantinga <slouken@lokigames.com>
date Thu, 26 Apr 2001 16:45:43 +0000
parents
children 75a95f82bc1f
comparison
equal deleted inserted replaced
-1:000000000000 0:74212992fb08
1 #include "SDL_error.h"
2 #include "SDL_endian.h"
3 #include "SDL_sysvideo.h"
4 #include "SDL_blit.h"
5 #include "SDL_video.h"
6 #include "SDL_cgxvideo.h"
7
8 static int CGX_HWAccelBlit(SDL_Surface *src, SDL_Rect *srcrect,
9 SDL_Surface *dst, SDL_Rect *dstrect);
10
11 // These are needed to avoid register troubles with gcc -O2!
12
13 #if defined(__SASC) || defined(__PPC__)
14 #define BMKBRP(a,b,c,d,e,f,g,h,i,j) BltMaskBitMapRastPort(a,b,c,d,e,f,g,h,i,j)
15 #define BBRP(a,b,c,d,e,f,g,h,i) BltBitMapRastPort(a,b,c,d,e,f,g,h,i)
16 #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)
17 #else
18 void BMKBRP(struct BitMap *a,WORD b, WORD c,struct RastPort *d,WORD e,WORD f,WORD g,WORD h,UBYTE i,APTR j)
19 {BltMaskBitMapRastPort(a,b,c,d,e,f,g,h,i,j);}
20
21 void BBRP(struct BitMap *a,WORD b, WORD c,struct RastPort *d,WORD e,WORD f,WORD g,WORD h,UBYTE i)
22 {BltBitMapRastPort(a,b,c,d,e,f,g,h,i);}
23
24 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)
25 {BltBitMap(a,b,c,d,e,f,g,h,i,j,k);}
26 #endif
27
28 int CGX_SetHWColorKey(_THIS,SDL_Surface *surface, Uint32 key)
29 {
30 if(surface->hwdata)
31 {
32 if(surface->hwdata->mask)
33 free(surface->hwdata->mask);
34
35 if(surface->hwdata->mask=malloc(RASSIZE(surface->w,surface->h)))
36 {
37 Uint32 pitch,ok=0;
38 APTR lock;
39
40 memset(surface->hwdata->mask,255,RASSIZE(surface->w,surface->h));
41
42 D(bug("Costruisco colorkey: colore: %ld, size: %ld x %ld, %ld bytes...Bpp:%ld\n",key,surface->w,surface->h,RASSIZE(surface->w,surface->h),surface->format->BytesPerPixel));
43
44 if(lock=LockBitMapTags(surface->hwdata->bmap,LBMI_BASEADDRESS,(ULONG)&surface->pixels,
45 LBMI_BYTESPERROW,(ULONG)&pitch,TAG_DONE))
46 {
47 switch(surface->format->BytesPerPixel)
48 {
49 case 1:
50 {
51 unsigned char k=key;
52 register int i,j,t;
53 register unsigned char *dest=surface->hwdata->mask,*map=surface->pixels;
54
55 pitch-=surface->w;
56
57 for(i=0;i<surface->h;i++)
58 {
59 for(t=128,j=0;j<surface->w;j++)
60 {
61 if(*map==k)
62 *dest&=~t;
63
64 t>>=1;
65
66 if(t==0)
67 {
68 dest++;
69 t=128;
70 }
71 map++;
72 }
73 map+=pitch;
74 }
75 }
76 break;
77 case 2:
78 {
79 Uint16 k=key,*mapw;
80 register int i,j,t;
81 register unsigned char *dest=surface->hwdata->mask,*map=surface->pixels;
82
83 for(i=surface->h;i;--i)
84 {
85 mapw=(Uint16 *)map;
86
87 for(t=128,j=surface->w;j;--j)
88 {
89 if(*mapw==k)
90 *dest&=~t;
91
92 t>>=1;
93
94 if(t==0)
95 {
96 dest++;
97 t=128;
98 }
99 mapw++;
100 }
101 map+=pitch;
102 }
103 }
104 break;
105 case 4:
106 {
107 Uint32 *mapl;
108 register int i,j,t;
109 register unsigned char *dest=surface->hwdata->mask,*map=surface->pixels;
110
111 for(i=surface->h;i;--i)
112 {
113 mapl=(Uint32 *)map;
114
115 for(t=128,j=surface->w;j;--j)
116 {
117 if(*mapl==key)
118 *dest&=~t;
119
120 t>>=1;
121
122 if(t==0)
123 {
124 dest++;
125 t=128;
126 }
127 mapl++;
128 }
129 map+=pitch;
130 }
131
132 }
133 break;
134 default:
135 D(bug("Pixel mode non supported for color key..."));
136 free(surface->hwdata->mask);
137 surface->hwdata->mask=NULL;
138 ok=-1;
139 }
140 UnLockBitMap(lock);
141 D(bug("...Colorkey costruito!\n"));
142 return ok;
143 }
144 }
145 }
146 D(bug("HW colorkey not supported for this depth\n"));
147
148 return -1;
149 }
150
151 int CGX_CheckHWBlit(_THIS,SDL_Surface *src,SDL_Surface *dst)
152 {
153 // Doesn't support yet alpha blitting
154
155 if(src->hwdata&& !(src->flags & (SDL_SRCALPHA)))
156 {
157 D(bug("CheckHW blit... OK!\n"));
158
159 if ( (src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) {
160 if ( CGX_SetHWColorKey(this, src, src->format->colorkey) < 0 ) {
161 src->flags &= ~SDL_HWACCEL;
162 return -1;
163 }
164 }
165
166 src->flags|=SDL_HWACCEL;
167 src->map->hw_blit = CGX_HWAccelBlit;
168 return 1;
169 }
170 else
171 src->flags &= ~SDL_HWACCEL;
172
173 D(bug("CheckHW blit... NO!\n"));
174
175 return 0;
176 }
177
178 static int temprp_init=0;
179 static struct RastPort temprp;
180
181 static int CGX_HWAccelBlit(SDL_Surface *src, SDL_Rect *srcrect,
182 SDL_Surface *dst, SDL_Rect *dstrect)
183 {
184 struct SDL_VideoDevice *this=src->hwdata->videodata;
185
186 // D(bug("Accel blit!\n"));
187
188 if(src->flags&SDL_SRCCOLORKEY && src->hwdata->mask)
189 {
190 if(dst==SDL_VideoSurface)
191 {
192 BMKBRP(src->hwdata->bmap,srcrect->x,srcrect->y,
193 SDL_RastPort,dstrect->x+SDL_Window->BorderLeft,dstrect->y+SDL_Window->BorderTop,
194 srcrect->w,srcrect->h,0xc0,src->hwdata->mask);
195 }
196 else if(dst->hwdata)
197 {
198 if(!temprp_init)
199 {
200 InitRastPort(&temprp);
201 temprp_init=1;
202 }
203 temprp.BitMap=(struct BitMap *)dst->hwdata->bmap;
204
205 BMKBRP(src->hwdata->bmap,srcrect->x,srcrect->y,
206 &temprp,dstrect->x,dstrect->y,
207 srcrect->w,srcrect->h,0xc0,src->hwdata->mask);
208
209 }
210 }
211 else if(dst==SDL_VideoSurface)
212 {
213 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);
214 }
215 else if(dst->hwdata)
216 BBB(src->hwdata->bmap,srcrect->x,srcrect->y,dst->hwdata->bmap,dstrect->x,dstrect->y,srcrect->w,srcrect->h,0xc0,0xff,NULL);
217 }
218
219 int CGX_FillHWRect(_THIS,SDL_Surface *dst,SDL_Rect *dstrect,Uint32 color)
220 {
221 if(dst==SDL_VideoSurface)
222 {
223 FillPixelArray(SDL_RastPort,dstrect->x+SDL_Window->BorderLeft,dstrect->y+SDL_Window->BorderTop,dstrect->w,dstrect->h,color);
224 }
225 else if(dst->hwdata)
226 {
227 if(!temprp_init)
228 {
229 InitRastPort(&temprp);
230 temprp_init=1;
231 }
232
233 temprp.BitMap=(struct BitMap *)dst->hwdata->bmap;
234
235 FillPixelArray(&temprp,dstrect->x,dstrect->y,dstrect->w,dstrect->h,color);
236 }
237 }