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