2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997, 1998, 1999, 2000 Sam Lantinga
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include "SDL_error.h"
29 #include "SDL_endian.h"
30 #include "SDL_sysvideo.h"
32 #include "SDL_video.h"
33 #include "SDL_cgxvideo.h"
39 static int CGX_HWAccelBlit(SDL_Surface
*src
, SDL_Rect
*srcrect
,
40 SDL_Surface
*dst
, SDL_Rect
*dstrect
);
42 // These are needed to avoid register troubles with gcc -O2!
46 * it was: defined(__SASC) || defined(__PPC__) || defined(MORPHOS)
48 * This is a workaround for an old gcc 2.7.x bug...
51 #define BMKBRP(a,b,c,d,e,f,g,h,i,j) BltMaskBitMapRastPort(a,b,c,d,e,f,g,h,i,j)
52 #define BBRP(a,b,c,d,e,f,g,h,i) BltBitMapRastPort(a,b,c,d,e,f,g,h,i)
53 #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)
55 void BMKBRP(struct BitMap
*a
,long b
, long c
,struct RastPort
*d
,long e
,long f
,long g
,long h
,unsigned long i
,APTR j
)
56 {BltMaskBitMapRastPort(a
,b
,c
,d
,e
,f
,g
,h
,i
,j
);}
58 void BBRP(struct BitMap
*a
,long b
, long c
,struct RastPort
*d
,long e
,long f
,long g
,long h
,unsigned long i
)
59 {BltBitMapRastPort(a
,b
,c
,d
,e
,f
,g
,h
,i
);}
61 void BBB(struct BitMap
*a
,long b
, long c
,struct BitMap
*d
,long e
,long f
,long g
,long h
,unsigned long i
,unsigned long j
,PLANEPTR k
)
62 {BltBitMap(a
,b
,c
,d
,e
,f
,g
,h
,i
,j
,k
);}
65 int CGX_SetHWColorKey(_THIS
,SDL_Surface
*surface
, Uint32 key
)
69 if(surface
->hwdata
->mask
)
70 free(surface
->hwdata
->mask
);
72 if((surface
->hwdata
->mask
=malloc(RASSIZE(surface
->w
,surface
->h
))))
77 memset(surface
->hwdata
->mask
,255,RASSIZE(surface
->w
,surface
->h
));
79 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
));
81 if((lock
=LockBitMapTags(surface
->hwdata
->bmap
,LBMI_BASEADDRESS
,(ULONG
)&surface
->pixels
,
82 LBMI_BYTESPERROW
,(ULONG
)&pitch
,TAG_DONE
)))
84 switch(surface
->format
->BytesPerPixel
)
90 register unsigned char *dest
=surface
->hwdata
->mask
,*map
=surface
->pixels
;
94 for(i
=0;i
<surface
->h
;i
++)
96 for(t
=128,j
=0;j
<surface
->w
;j
++)
118 register unsigned char *dest
=surface
->hwdata
->mask
,*map
=surface
->pixels
;
120 for(i
=surface
->h
;i
;--i
)
124 for(t
=128,j
=surface
->w
;j
;--j
)
146 register unsigned char *dest
=surface
->hwdata
->mask
,*map
=surface
->pixels
;
148 for(i
=surface
->h
;i
;--i
)
152 for(t
=128,j
=surface
->w
;j
;--j
)
172 D(bug("Pixel mode non supported for color key..."));
173 free(surface
->hwdata
->mask
);
174 surface
->hwdata
->mask
=NULL
;
178 D(bug("...Colorkey built!\n"));
183 D(bug("HW colorkey not supported for this depth\n"));
188 int CGX_CheckHWBlit(_THIS
,SDL_Surface
*src
,SDL_Surface
*dst
)
190 // Doesn't support yet alpha blitting
192 if(src
->hwdata
&& !(src
->flags
& (SDL_SRCALPHA
)))
194 D(bug("CheckHW blit... OK!\n"));
196 if ( (src
->flags
& SDL_SRCCOLORKEY
) == SDL_SRCCOLORKEY
) {
197 if ( CGX_SetHWColorKey(this, src
, src
->format
->colorkey
) < 0 ) {
198 src
->flags
&= ~SDL_HWACCEL
;
203 src
->flags
|=SDL_HWACCEL
;
204 src
->map
->hw_blit
= CGX_HWAccelBlit
;
208 src
->flags
&= ~SDL_HWACCEL
;
210 D(bug("CheckHW blit... NO!\n"));
215 static int temprp_init
=0;
216 static struct RastPort temprp
;
218 static int CGX_HWAccelBlit(SDL_Surface
*src
, SDL_Rect
*srcrect
,
219 SDL_Surface
*dst
, SDL_Rect
*dstrect
)
221 struct SDL_VideoDevice
*this=src
->hwdata
->videodata
;
223 // D(bug("Accel blit!\n"));
225 if(src
->flags
&SDL_SRCCOLORKEY
&& src
->hwdata
->mask
)
227 if(dst
==SDL_VideoSurface
)
229 BMKBRP(src
->hwdata
->bmap
,srcrect
->x
,srcrect
->y
,
230 SDL_RastPort
,dstrect
->x
+SDL_Window
->BorderLeft
,dstrect
->y
+SDL_Window
->BorderTop
,
231 srcrect
->w
,srcrect
->h
,0xc0,src
->hwdata
->mask
);
237 InitRastPort(&temprp
);
240 temprp
.BitMap
=(struct BitMap
*)dst
->hwdata
->bmap
;
242 BMKBRP(src
->hwdata
->bmap
,srcrect
->x
,srcrect
->y
,
243 &temprp
,dstrect
->x
,dstrect
->y
,
244 srcrect
->w
,srcrect
->h
,0xc0,src
->hwdata
->mask
);
248 else if(dst
==SDL_VideoSurface
)
250 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);
253 BBB(src
->hwdata
->bmap
,srcrect
->x
,srcrect
->y
,dst
->hwdata
->bmap
,dstrect
->x
,dstrect
->y
,srcrect
->w
,srcrect
->h
,0xc0,0xff,NULL
);
258 int CGX_FillHWRect(_THIS
,SDL_Surface
*dst
,SDL_Rect
*dstrect
,Uint32 color
)
260 if(dst
==SDL_VideoSurface
)
262 FillPixelArray(SDL_RastPort
,dstrect
->x
+SDL_Window
->BorderLeft
,dstrect
->y
+SDL_Window
->BorderTop
,dstrect
->w
,dstrect
->h
,color
);
268 InitRastPort(&temprp
);
272 temprp
.BitMap
=(struct BitMap
*)dst
->hwdata
->bmap
;
274 FillPixelArray(&temprp
,dstrect
->x
,dstrect
->y
,dstrect
->w
,dstrect
->h
,color
);