Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
272 lines (226 loc) · 8.93 KB

SDL_cgxaccel.c

File metadata and controls

272 lines (226 loc) · 8.93 KB
 
Dec 16, 2001
Dec 16, 2001
1
2
/*
SDL - Simple DirectMedia Layer
Feb 1, 2006
Feb 1, 2006
3
Copyright (C) 1997-2006 Sam Lantinga
Dec 16, 2001
Dec 16, 2001
4
5
This library is free software; you can redistribute it and/or
Feb 1, 2006
Feb 1, 2006
6
modify it under the terms of the GNU Lesser General Public
Dec 16, 2001
Dec 16, 2001
7
License as published by the Free Software Foundation; either
Feb 1, 2006
Feb 1, 2006
8
version 2.1 of the License, or (at your option) any later version.
Dec 16, 2001
Dec 16, 2001
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
Feb 1, 2006
Feb 1, 2006
13
Lesser General Public License for more details.
Dec 16, 2001
Dec 16, 2001
14
Feb 1, 2006
Feb 1, 2006
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
Dec 16, 2001
Dec 16, 2001
18
19
20
21
Sam Lantinga
slouken@libsdl.org
*/
Feb 21, 2006
Feb 21, 2006
22
#include "SDL_config.h"
Dec 16, 2001
Dec 16, 2001
23
Apr 26, 2001
Apr 26, 2001
24
#include "SDL_endian.h"
Feb 10, 2006
Feb 10, 2006
25
#include "SDL_video.h"
Feb 16, 2006
Feb 16, 2006
26
27
#include "../SDL_sysvideo.h"
#include "../SDL_blit.h"
Apr 26, 2001
Apr 26, 2001
28
29
#include "SDL_cgxvideo.h"
May 29, 2006
May 29, 2006
30
31
static int CGX_HWAccelBlit(SDL_Surface * src, SDL_Rect * srcrect,
SDL_Surface * dst, SDL_Rect * dstrect);
Apr 26, 2001
Apr 26, 2001
32
33
34
// These are needed to avoid register troubles with gcc -O2!
Dec 16, 2001
Dec 16, 2001
35
#if defined(__SASC) || defined(__PPC__) || defined(MORPHOS)
Apr 26, 2001
Apr 26, 2001
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
May 28, 2006
May 28, 2006
40
void
May 29, 2006
May 29, 2006
41
42
BMKBRP(struct BitMap *a, WORD b, WORD c, struct RastPort *d, WORD e, WORD f,
WORD g, WORD h, UBYTE i, APTR j)
May 28, 2006
May 28, 2006
43
{
May 29, 2006
May 29, 2006
44
BltMaskBitMapRastPort(a, b, c, d, e, f, g, h, i, j);
May 28, 2006
May 28, 2006
45
}
Apr 26, 2001
Apr 26, 2001
46
May 28, 2006
May 28, 2006
47
void
May 29, 2006
May 29, 2006
48
49
BBRP(struct BitMap *a, WORD b, WORD c, struct RastPort *d, WORD e, WORD f,
WORD g, WORD h, UBYTE i)
May 28, 2006
May 28, 2006
50
{
May 29, 2006
May 29, 2006
51
BltBitMapRastPort(a, b, c, d, e, f, g, h, i);
May 28, 2006
May 28, 2006
52
}
Apr 26, 2001
Apr 26, 2001
53
May 28, 2006
May 28, 2006
54
void
May 29, 2006
May 29, 2006
55
56
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)
May 28, 2006
May 28, 2006
57
{
May 29, 2006
May 29, 2006
58
BltBitMap(a, b, c, d, e, f, g, h, i, j, k);
May 28, 2006
May 28, 2006
59
}
Apr 26, 2001
Apr 26, 2001
60
61
#endif
May 28, 2006
May 28, 2006
62
int
May 29, 2006
May 29, 2006
63
CGX_SetHWColorKey(_THIS, SDL_Surface * surface, Uint32 key)
Apr 26, 2001
Apr 26, 2001
64
{
May 28, 2006
May 28, 2006
65
66
if (surface->hwdata) {
if (surface->hwdata->mask)
May 29, 2006
May 29, 2006
67
SDL_free(surface->hwdata->mask);
May 28, 2006
May 28, 2006
68
69
if (surface->hwdata->mask =
May 29, 2006
May 29, 2006
70
SDL_malloc(RASSIZE(surface->w, surface->h))) {
May 28, 2006
May 28, 2006
71
72
73
Uint32 pitch, ok = 0;
APTR lock;
May 29, 2006
May 29, 2006
74
75
SDL_memset(surface->hwdata->mask, 255,
RASSIZE(surface->w, surface->h));
May 28, 2006
May 28, 2006
76
May 29, 2006
May 29, 2006
77
78
79
80
81
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));
May 28, 2006
May 28, 2006
82
83
if (lock =
May 29, 2006
May 29, 2006
84
85
86
LockBitMapTags(surface->hwdata->bmap, LBMI_BASEADDRESS,
(ULONG) & surface->pixels,
LBMI_BYTESPERROW, (ULONG) & pitch, TAG_DONE)) {
May 28, 2006
May 28, 2006
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
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:
May 29, 2006
May 29, 2006
168
169
D(bug("Pixel mode non supported for color key..."));
SDL_free(surface->hwdata->mask);
May 28, 2006
May 28, 2006
170
171
172
surface->hwdata->mask = NULL;
ok = -1;
}
May 29, 2006
May 29, 2006
173
174
UnLockBitMap(lock);
D(bug("...Colorkey built!\n"));
May 28, 2006
May 28, 2006
175
176
177
178
return ok;
}
}
}
May 29, 2006
May 29, 2006
179
D(bug("HW colorkey not supported for this depth\n"));
May 28, 2006
May 28, 2006
180
181
return -1;
Apr 26, 2001
Apr 26, 2001
182
183
}
May 28, 2006
May 28, 2006
184
int
May 29, 2006
May 29, 2006
185
CGX_CheckHWBlit(_THIS, SDL_Surface * src, SDL_Surface * dst)
Apr 26, 2001
Apr 26, 2001
186
187
188
{
// Doesn't support yet alpha blitting
May 28, 2006
May 28, 2006
189
if (src->hwdata && !(src->flags & (SDL_SRCALPHA))) {
May 29, 2006
May 29, 2006
190
D(bug("CheckHW blit... OK!\n"));
Apr 26, 2001
Apr 26, 2001
191
May 28, 2006
May 28, 2006
192
if ((src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
May 29, 2006
May 29, 2006
193
if (CGX_SetHWColorKey(this, src, src->format->colorkey) < 0) {
May 28, 2006
May 28, 2006
194
195
196
197
src->flags &= ~SDL_HWACCEL;
return -1;
}
}
Apr 26, 2001
Apr 26, 2001
198
May 28, 2006
May 28, 2006
199
200
201
202
203
src->flags |= SDL_HWACCEL;
src->map->hw_blit = CGX_HWAccelBlit;
return 1;
} else
src->flags &= ~SDL_HWACCEL;
Apr 26, 2001
Apr 26, 2001
204
May 29, 2006
May 29, 2006
205
D(bug("CheckHW blit... NO!\n"));
Apr 26, 2001
Apr 26, 2001
206
May 28, 2006
May 28, 2006
207
return 0;
Apr 26, 2001
Apr 26, 2001
208
209
}
May 28, 2006
May 28, 2006
210
static int temprp_init = 0;
Apr 26, 2001
Apr 26, 2001
211
212
static struct RastPort temprp;
May 28, 2006
May 28, 2006
213
static int
May 29, 2006
May 29, 2006
214
215
CGX_HWAccelBlit(SDL_Surface * src, SDL_Rect * srcrect,
SDL_Surface * dst, SDL_Rect * dstrect)
Apr 26, 2001
Apr 26, 2001
216
{
May 28, 2006
May 28, 2006
217
218
219
220
221
222
struct SDL_VideoDevice *this = src->hwdata->videodata;
// D(bug("Accel blit!\n"));
if (src->flags & SDL_SRCCOLORKEY && src->hwdata->mask) {
if (dst == SDL_VideoSurface) {
May 29, 2006
May 29, 2006
223
224
225
226
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);
May 28, 2006
May 28, 2006
227
228
} else if (dst->hwdata) {
if (!temprp_init) {
May 29, 2006
May 29, 2006
229
InitRastPort(&temprp);
May 28, 2006
May 28, 2006
230
231
232
233
temprp_init = 1;
}
temprp.BitMap = (struct BitMap *) dst->hwdata->bmap;
May 29, 2006
May 29, 2006
234
235
236
BMKBRP(src->hwdata->bmap, srcrect->x, srcrect->y,
&temprp, dstrect->x, dstrect->y,
srcrect->w, srcrect->h, 0xc0, src->hwdata->mask);
May 28, 2006
May 28, 2006
237
238
239
}
} else if (dst == SDL_VideoSurface) {
May 29, 2006
May 29, 2006
240
241
242
243
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);
May 28, 2006
May 28, 2006
244
} else if (dst->hwdata)
May 29, 2006
May 29, 2006
245
246
BBB(src->hwdata->bmap, srcrect->x, srcrect->y, dst->hwdata->bmap,
dstrect->x, dstrect->y, srcrect->w, srcrect->h, 0xc0, 0xff, NULL);
May 28, 2006
May 28, 2006
247
248
return 0;
Apr 26, 2001
Apr 26, 2001
249
250
}
May 28, 2006
May 28, 2006
251
int
May 29, 2006
May 29, 2006
252
CGX_FillHWRect(_THIS, SDL_Surface * dst, SDL_Rect * dstrect, Uint32 color)
Apr 26, 2001
Apr 26, 2001
253
{
May 28, 2006
May 28, 2006
254
if (dst == SDL_VideoSurface) {
May 29, 2006
May 29, 2006
255
256
257
FillPixelArray(SDL_RastPort, dstrect->x + SDL_Window->BorderLeft,
dstrect->y + SDL_Window->BorderTop, dstrect->w,
dstrect->h, color);
May 28, 2006
May 28, 2006
258
259
} else if (dst->hwdata) {
if (!temprp_init) {
May 29, 2006
May 29, 2006
260
InitRastPort(&temprp);
May 28, 2006
May 28, 2006
261
262
263
264
265
temprp_init = 1;
}
temprp.BitMap = (struct BitMap *) dst->hwdata->bmap;
May 29, 2006
May 29, 2006
266
267
FillPixelArray(&temprp, dstrect->x, dstrect->y, dstrect->w,
dstrect->h, color);
May 28, 2006
May 28, 2006
268
269
}
return 0;
Apr 26, 2001
Apr 26, 2001
270
}
May 28, 2006
May 28, 2006
271
272
/* vi: set ts=4 sw=4 expandtab: */