Mercurial > sdl-ios-xcode
annotate src/video/cybergfx/SDL_cgximage.c @ 156:7064032cbe77
Is this right??
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 20 Aug 2001 00:10:35 +0000 |
parents | 75a95f82bc1f |
children | e8157fcb3114 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
3 Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga | |
4 | |
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. | |
9 | |
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. | |
14 | |
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 | |
18 | |
19 Sam Lantinga | |
20 slouken@devolution.com | |
21 */ | |
22 | |
23 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
27 | |
28 #include <stdlib.h> | |
29 | |
30 #include "SDL_error.h" | |
31 #include "SDL_endian.h" | |
32 #include "SDL_cgximage_c.h" | |
33 | |
34 #ifdef HAVE_KSTAT | |
35 #include <kstat.h> | |
36 #endif | |
37 | |
38 #ifdef USE_CGX_WRITELUTPIXEL | |
39 #if defined(__SASC) || defined(__PPC__) | |
40 #define WLUT WriteLUTPixelArray | |
41 #else | |
42 void WLUT(APTR a,UWORD b,UWORD c,UWORD d,struct RastPort *e,APTR f,UWORD g,UWORD h,UWORD i,UWORD l,UBYTE m) | |
43 { WriteLUTPixelArray(a,b,c,d,e,f,g,h,i,l,m); } | |
44 #endif | |
45 | |
46 #endif | |
47 | |
48 /* Various screen update functions available */ | |
49 static void CGX_NormalUpdate(_THIS, int numrects, SDL_Rect *rects); | |
50 static void CGX_FakeUpdate(_THIS, int numrects, SDL_Rect *rects); | |
51 | |
52 BOOL SafeDisp=TRUE,SafeChange=TRUE; | |
53 struct MsgPort *safeport=NULL,*dispport=NULL; | |
54 ULONG safe_sigbit,disp_sigbit; | |
55 | |
56 int CGX_SetupImage(_THIS, SDL_Surface *screen) | |
57 { | |
58 if(screen->flags&SDL_HWSURFACE) | |
59 { | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
60 Uint32 pitch; |
0 | 61 SDL_Ximage=NULL; |
62 | |
63 if(!screen->hwdata) | |
64 { | |
65 if(!(screen->hwdata=malloc(sizeof(struct private_hwdata)))) | |
66 { | |
67 return -1; | |
68 } | |
69 D(bug("Creating system accel struct\n")); | |
70 } | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
71 screen->hwdata->lock=0; |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
72 screen->hwdata->bmap=SDL_RastPort->BitMap; |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
73 screen->hwdata->videodata=this; |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
74 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
75 if(!(screen->hwdata->lock=LockBitMapTags(screen->hwdata->bmap, |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
76 LBMI_BASEADDRESS,(ULONG)&screen->pixels, |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
77 LBMI_BYTESPERROW,(ULONG)&pitch,TAG_DONE))) |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
78 { |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
79 free(screen->hwdata); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
80 screen->hwdata=NULL; |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
81 return -1; |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
82 } |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
83 else |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
84 { |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
85 UnLockBitMap(screen->hwdata->lock); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
86 screen->hwdata->lock=NULL; |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
87 } |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
88 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
89 screen->pitch=pitch; |
0 | 90 |
91 this->UpdateRects = CGX_FakeUpdate; | |
92 | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
93 D(bug("Accel video image configured (%lx, pitch %ld).\n",screen->pixels,screen->pitch)); |
0 | 94 return 0; |
95 } | |
96 | |
97 screen->pixels = malloc(screen->h*screen->pitch); | |
98 | |
99 if ( screen->pixels == NULL ) { | |
100 SDL_OutOfMemory(); | |
101 return(-1); | |
102 } | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
103 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
104 /* |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
105 { |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
106 int bpp = screen->format->BytesPerPixel; |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
107 SDL_Ximage = XCreateImage(SDL_Display, SDL_Visual, |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
108 this->hidden->depth, ZPixmap, 0, |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
109 (char *)screen->pixels, |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
110 screen->w, screen->h, |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
111 (bpp == 3) ? 32 : bpp * 8, |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
112 0); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
113 } |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
114 */ |
0 | 115 SDL_Ximage=screen->pixels; |
116 | |
117 if ( SDL_Ximage == NULL ) { | |
118 SDL_SetError("Couldn't create XImage"); | |
119 return(-1); | |
120 } | |
121 | |
122 this->UpdateRects = CGX_NormalUpdate; | |
123 | |
124 return(0); | |
125 } | |
126 | |
127 void CGX_DestroyImage(_THIS, SDL_Surface *screen) | |
128 { | |
129 if ( SDL_Ximage ) { | |
130 free(SDL_Ximage); | |
131 SDL_Ximage = NULL; | |
132 } | |
133 if ( screen ) { | |
134 screen->pixels = NULL; | |
135 } | |
136 } | |
137 | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
138 /* This is a hack to see whether this system has more than 1 CPU */ |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
139 static int num_CPU(void) |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
140 { |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
141 return 1; |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
142 } |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
143 |
0 | 144 int CGX_ResizeImage(_THIS, SDL_Surface *screen, Uint32 flags) |
145 { | |
146 int retval; | |
147 | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
148 D(bug("Chiamata ResizeImage!\n")); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
149 |
0 | 150 CGX_DestroyImage(this, screen); |
151 | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
152 if ( flags & SDL_OPENGL ) { /* No image when using GL */ |
0 | 153 retval = 0; |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
154 } else { |
0 | 155 retval = CGX_SetupImage(this, screen); |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
156 /* We support asynchronous blitting on the display */ |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
157 if ( flags & SDL_ASYNCBLIT ) { |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
158 /* This is actually slower on single-CPU systems, |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
159 probably because of CPU contention between the |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
160 X server and the application. |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
161 Note: Is this still true with XFree86 4.0? |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
162 */ |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
163 if ( num_CPU() > 1 ) { |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
164 screen->flags |= SDL_ASYNCBLIT; |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
165 } |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
166 } |
0 | 167 } |
168 return(retval); | |
169 } | |
170 | |
171 /* We don't actually allow hardware surfaces other than the main one */ | |
172 int CGX_AllocHWSurface(_THIS, SDL_Surface *surface) | |
173 { | |
174 D(bug("Alloc HW surface...%ld x %ld x %ld!\n",surface->w,surface->h,this->hidden->depth)); | |
175 | |
176 if(surface==SDL_VideoSurface) | |
177 { | |
178 D(bug("Allocation skipped, it's system one!\n")); | |
179 return 0; | |
180 } | |
181 | |
182 if(!surface->hwdata) | |
183 { | |
184 if(!(surface->hwdata=malloc(sizeof(struct private_hwdata)))) | |
185 return -1; | |
186 } | |
187 | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
188 surface->hwdata->lock=NULL; |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
189 surface->hwdata->videodata=this; |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
190 |
0 | 191 if(surface->hwdata->bmap=AllocBitMap(surface->w,surface->h,this->hidden->depth,BMF_MINPLANES,SDL_Display->RastPort.BitMap)) |
192 { | |
193 surface->flags|=SDL_HWSURFACE; | |
194 D(bug("...OK\n")); | |
195 return 0; | |
196 } | |
197 else | |
198 { | |
199 free(surface->hwdata); | |
200 surface->hwdata=NULL; | |
201 } | |
202 | |
203 return(-1); | |
204 } | |
205 void CGX_FreeHWSurface(_THIS, SDL_Surface *surface) | |
206 { | |
207 if(surface && surface!=SDL_VideoSurface && surface->hwdata) | |
208 { | |
209 D(bug("Free hw surface.\n")); | |
210 | |
211 if(surface->hwdata->mask) | |
212 free(surface->hwdata->mask); | |
213 | |
214 if(surface->hwdata->bmap) | |
215 FreeBitMap(surface->hwdata->bmap); | |
216 | |
217 free(surface->hwdata); | |
218 surface->hwdata=NULL; | |
219 } | |
220 return; | |
221 } | |
222 | |
223 int CGX_LockHWSurface(_THIS, SDL_Surface *surface) | |
224 { | |
225 if (surface->hwdata) | |
226 { | |
227 // D(bug("Locking a bitmap...\n")); | |
228 if(!surface->hwdata->lock) | |
229 { | |
230 Uint32 pitch; | |
231 | |
232 if(!(surface->hwdata->lock=LockBitMapTags(surface->hwdata->bmap, | |
233 LBMI_BASEADDRESS,(ULONG)&surface->pixels, | |
234 LBMI_BYTESPERROW,(ULONG)&pitch,TAG_DONE))) | |
235 return -1; | |
236 | |
237 // surface->pitch e' a 16bit! | |
238 | |
239 surface->pitch=pitch; | |
240 | |
241 if(!currently_fullscreen&&surface==SDL_VideoSurface) | |
242 surface->pixels=((char *)surface->pixels)+(surface->pitch*(SDL_Window->BorderTop+SDL_Window->TopEdge)+ | |
243 surface->format->BytesPerPixel*(SDL_Window->BorderLeft+SDL_Window->LeftEdge)); | |
244 } | |
245 else | |
246 D(bug("Already locked!!!\n")); | |
247 } | |
248 return(0); | |
249 } | |
250 void CGX_UnlockHWSurface(_THIS, SDL_Surface *surface) | |
251 { | |
252 if(surface->hwdata && surface->hwdata->lock) | |
253 { | |
254 UnLockBitMap(surface->hwdata->lock); | |
255 surface->hwdata->lock=NULL; | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
256 // surface->pixels=NULL; |
0 | 257 } |
258 } | |
259 | |
260 int CGX_FlipHWSurface(_THIS, SDL_Surface *surface) | |
261 { | |
262 static int current=0; | |
263 | |
264 if(this->hidden->dbuffer) | |
265 { | |
266 if(!SafeChange) | |
267 { | |
268 Wait(disp_sigbit); | |
269 // Non faccio nulla, vuoto solo la porta | |
270 while(GetMsg(dispport)!=NULL) | |
271 ; | |
272 SafeChange=TRUE; | |
273 } | |
274 | |
275 if(ChangeScreenBuffer(SDL_Display,this->hidden->SB[current^1])) | |
276 { | |
277 surface->hwdata->bmap=SDL_RastPort->BitMap=this->hidden->SB[current]->sb_BitMap; | |
278 SafeChange=FALSE; | |
279 SafeDisp=FALSE; | |
280 current^=1; | |
281 } | |
282 | |
283 if(!SafeDisp) | |
284 { | |
285 Wait(safe_sigbit); | |
286 while(GetMsg(safeport)!=NULL) | |
287 ; | |
288 SafeDisp=TRUE; | |
289 } | |
290 | |
291 } | |
292 return(0); | |
293 } | |
294 | |
295 /* Byte-swap the pixels in the display image */ | |
296 static void CGX_SwapAllPixels(SDL_Surface *screen) | |
297 { | |
298 int x, y; | |
299 | |
300 switch (screen->format->BytesPerPixel) { | |
301 case 2: { | |
302 Uint16 *spot; | |
303 for ( y=0; y<screen->h; ++y ) { | |
304 spot = (Uint16 *) ((Uint8 *)screen->pixels + | |
305 y * screen->pitch); | |
306 for ( x=0; x<screen->w; ++x, ++spot ) { | |
307 *spot = SDL_Swap16(*spot); | |
308 } | |
309 } | |
310 } | |
311 break; | |
312 | |
313 case 4: { | |
314 Uint32 *spot; | |
315 for ( y=0; y<screen->h; ++y ) { | |
316 spot = (Uint32 *) ((Uint8 *)screen->pixels + | |
317 y * screen->pitch); | |
318 for ( x=0; x<screen->w; ++x, ++spot ) { | |
319 *spot = SDL_Swap32(*spot); | |
320 } | |
321 } | |
322 } | |
323 break; | |
324 | |
325 default: | |
326 /* should never get here */ | |
327 break; | |
328 } | |
329 } | |
330 static void CGX_SwapPixels(SDL_Surface *screen, int numrects, SDL_Rect *rects) | |
331 { | |
332 int i; | |
333 int x, minx, maxx; | |
334 int y, miny, maxy; | |
335 | |
336 switch (screen->format->BytesPerPixel) { | |
337 case 2: { | |
338 Uint16 *spot; | |
339 for ( i=0; i<numrects; ++i ) { | |
340 minx = rects[i].x; | |
341 maxx = rects[i].x+rects[i].w; | |
342 miny = rects[i].y; | |
343 maxy = rects[i].y+rects[i].h; | |
344 for ( y=miny; y<maxy; ++y ) { | |
345 spot = (Uint16 *) ((Uint8 *)screen->pixels + | |
346 y * screen->pitch + minx * 2); | |
347 for ( x=minx; x<maxx; ++x, ++spot ) { | |
348 *spot = SDL_Swap16(*spot); | |
349 } | |
350 } | |
351 } | |
352 } | |
353 break; | |
354 | |
355 case 4: { | |
356 Uint32 *spot; | |
357 for ( i=0; i<numrects; ++i ) { | |
358 minx = rects[i].x; | |
359 maxx = rects[i].x+rects[i].w; | |
360 miny = rects[i].y; | |
361 maxy = rects[i].y+rects[i].h; | |
362 for ( y=miny; y<maxy; ++y ) { | |
363 spot = (Uint32 *) ((Uint8 *)screen->pixels + | |
364 y * screen->pitch + minx * 4); | |
365 for ( x=minx; x<maxx; ++x, ++spot ) { | |
366 *spot = SDL_Swap32(*spot); | |
367 } | |
368 } | |
369 } | |
370 } | |
371 break; | |
372 | |
373 default: | |
374 /* should never get here */ | |
375 break; | |
376 } | |
377 } | |
378 | |
379 #ifdef __SASC | |
380 | |
381 #define USE_WPA WritePixelArray | |
382 #else | |
383 | |
384 void USE_WPA(char *a,int b,int c,int d, struct RastPort *e,int f,int g, int h, int i, Uint32 l) | |
385 { | |
386 WritePixelArray(a,b,c,d,e,f,g,h,i,l); | |
387 } | |
388 | |
389 #endif | |
390 | |
391 static void CGX_FakeUpdate(_THIS, int numrects, SDL_Rect *rects) | |
392 { | |
393 } | |
394 | |
395 static void CGX_NormalUpdate(_THIS, int numrects, SDL_Rect *rects) | |
396 { | |
397 int i,format,customroutine=0; | |
398 #ifndef USE_CGX_WRITELUTPIXEL | |
399 int bpp; | |
400 #endif | |
401 if(this->hidden->same_format) | |
402 { | |
403 format=RECTFMT_RAW; | |
404 } | |
405 else switch(this->screen->format->BytesPerPixel) | |
406 { | |
407 case 4: | |
408 format=RECTFMT_RGBA; | |
409 break; | |
410 case 3: | |
411 format=RECTFMT_RGB; | |
412 break; | |
413 case 2: | |
414 customroutine=1; | |
415 break; | |
416 case 1: | |
417 // D(bug("soft depth: 8 hardbpp: %ld\n",this->hidden->depth)); | |
418 if(this->hidden->depth>8) | |
419 { | |
420 #ifndef USE_CGX_WRITELUTPIXEL | |
421 if(this->hidden->depth>32) | |
422 customroutine=4; | |
423 else if(this->hidden->depth>16) | |
424 { | |
425 bpp=this->hidden->BytesPerPixel; // That one is the only one that needs bpp | |
426 customroutine=2; // The slow one! | |
427 } | |
428 else | |
429 customroutine=3; | |
430 #else | |
431 | |
432 customroutine=2; | |
433 #endif | |
434 | |
435 // format=RECTFMT_LUT8; Vecchia funzione x usare la WritePixelArray. | |
436 } | |
437 else | |
438 customroutine=1; | |
439 break; | |
440 default: | |
441 D(bug("Unable to blit this surface!\n")); | |
442 return; | |
443 } | |
444 | |
445 /* Check for endian-swapped X server, swap if necessary (VERY slow!) */ | |
446 if ( swap_pixels && | |
447 ((this->screen->format->BytesPerPixel%2) == 0) ) { | |
448 D(bug("Swappo! Lento!\n")); | |
449 CGX_SwapPixels(this->screen, numrects, rects); | |
450 for ( i=0; i<numrects; ++i ) { | |
451 if ( ! rects[i].w ) { /* Clipped? */ | |
452 continue; | |
453 } | |
454 USE_WPA(this->screen->pixels,rects[i].x, rects[i].y,this->screen->pitch, | |
455 SDL_RastPort,SDL_Window->BorderLeft+rects[i].x,SDL_Window->BorderTop+rects[i].y, | |
456 rects[i].w,rects[i].h,format); | |
457 } | |
458 CGX_SwapPixels(this->screen, numrects, rects); | |
459 } | |
460 else if (customroutine==2) | |
461 { | |
462 #ifdef USE_CGX_WRITELUTPIXEL | |
463 for ( i=0; i<numrects; ++i ) { | |
464 if ( ! rects[i].w ) { /* Clipped? */ | |
465 continue; | |
466 } | |
467 | |
468 WLUT(this->screen->pixels,rects[i].x, rects[i].y,this->screen->pitch, | |
469 SDL_RastPort,SDL_XPixels,SDL_Window->BorderLeft+rects[i].x,SDL_Window->BorderTop+rects[i].y, | |
470 rects[i].w,rects[i].h,CTABFMT_XRGB8); | |
471 } | |
472 #else | |
473 unsigned char *bm_address; | |
474 Uint32 destpitch; | |
475 APTR handle; | |
476 | |
477 if(handle=LockBitMapTags(SDL_RastPort->BitMap,LBMI_BASEADDRESS,&bm_address, | |
478 LBMI_BYTESPERROW,&destpitch,TAG_DONE)) | |
479 { | |
480 int srcwidth; | |
481 unsigned char *destbase; | |
482 register int j,k,t; | |
483 register unsigned char *mask,*dst; | |
484 register unsigned char *src,*dest; | |
485 | |
486 // Aggiungo il bordo della finestra se sono fullscreen. | |
487 if(currently_fullscreen) | |
488 destbase=bm_address; | |
489 else | |
490 destbase=bm_address+(SDL_Window->TopEdge+SDL_Window->BorderTop)*destpitch+(SDL_Window->BorderLeft+SDL_Window->LeftEdge)*this->hidden->BytesPerPixel; | |
491 | |
492 for ( i=0; i<numrects; ++i ) | |
493 { | |
494 srcwidth=rects[i].w; | |
495 | |
496 if ( !srcwidth ) { /* Clipped? */ | |
497 continue; | |
498 } | |
499 | |
500 dest=destbase+rects[i].x*this->hidden->BytesPerPixel; | |
501 dest+=(rects[i].y*destpitch); | |
502 src=((char *)(this->screen->pixels))+rects[i].x; | |
503 src+=(rects[i].y*this->screen->pitch); | |
504 | |
505 for(j=rects[i].h;j;--j) | |
506 { | |
507 dst=dest; | |
508 // SLOW routine, used for 8->24 bit mapping | |
509 for(k=0;k<srcwidth;k++) | |
510 { | |
511 mask=(unsigned char *)(&SDL_XPixels[src[k]]); | |
512 for(t=0;t<bpp;t++) | |
513 { | |
514 dst[t]=mask[t]; | |
515 } | |
516 dst+=bpp; | |
517 } | |
518 src+=this->screen->pitch; | |
519 dest+=destpitch; | |
520 } | |
521 } | |
522 UnLockBitMap(handle); | |
523 } | |
524 } | |
525 else if (customroutine==3) | |
526 { | |
527 unsigned char *bm_address; | |
528 Uint32 destpitch; | |
529 APTR handle; | |
530 | |
531 if(handle=LockBitMapTags(SDL_RastPort->BitMap,LBMI_BASEADDRESS,&bm_address, | |
532 LBMI_BYTESPERROW,&destpitch,TAG_DONE)) | |
533 { | |
534 int srcwidth; | |
535 unsigned char *destbase; | |
536 register int j,k; | |
537 register unsigned char *src,*dest; | |
538 register Uint16 *destl,*srcl; | |
539 | |
540 if(currently_fullscreen) | |
541 destbase=bm_address; | |
542 else | |
543 destbase=bm_address+(SDL_Window->TopEdge+SDL_Window->BorderTop)*destpitch+(SDL_Window->BorderLeft+SDL_Window->LeftEdge)*this->hidden->BytesPerPixel; | |
544 | |
545 for ( i=0; i<numrects; ++i ) | |
546 { | |
547 srcwidth=rects[i].w; | |
548 | |
549 if ( !srcwidth ) { /* Clipped? */ | |
550 continue; | |
551 } | |
552 | |
553 dest=destbase+rects[i].x*this->hidden->BytesPerPixel; | |
554 dest+=(rects[i].y*destpitch); | |
555 src=((char *)(this->screen->pixels))+rects[i].x; | |
556 src+=(rects[i].y*this->screen->pitch); | |
557 | |
558 // This is the fast, well not too slow, remapping code for 16bit displays | |
559 | |
560 for(j=rects[i].h;j;--j) | |
561 { | |
562 destl=(Uint16 *)dest; | |
563 | |
564 for(k=0;k<srcwidth;k++) | |
565 { | |
566 srcl=(Uint16 *)&SDL_XPixels[src[k]]; | |
567 *destl=*srcl; | |
568 destl++; | |
569 } | |
570 src+=this->screen->pitch; | |
571 dest+=destpitch; | |
572 } | |
573 } | |
574 UnLockBitMap(handle); | |
575 } | |
576 } | |
577 else if (customroutine==4) | |
578 { | |
579 unsigned char *bm_address; | |
580 Uint32 destpitch; | |
581 APTR handle; | |
582 | |
583 if(handle=LockBitMapTags(SDL_RastPort->BitMap,LBMI_BASEADDRESS,&bm_address, | |
584 LBMI_BYTESPERROW,&destpitch,TAG_DONE)) | |
585 { | |
586 int srcwidth; | |
587 unsigned char *destbase; | |
588 register int j,k; | |
589 register unsigned char *src,*dest; | |
590 register Uint32 *destl,*srcl; | |
591 | |
592 if(currently_fullscreen) | |
593 destbase=bm_address; | |
594 else | |
595 destbase=bm_address+(SDL_Window->TopEdge+SDL_Window->BorderTop)*destpitch+(SDL_Window->BorderLeft+SDL_Window->LeftEdge)*this->hidden->BytesPerPixel; | |
596 | |
597 for ( i=0; i<numrects; ++i ) | |
598 { | |
599 srcwidth=rects[i].w; | |
600 | |
601 if ( !srcwidth ) { /* Clipped? */ | |
602 continue; | |
603 } | |
604 | |
605 dest=destbase+rects[i].x*this->hidden->BytesPerPixel; | |
606 dest+=(rects[i].y*destpitch); | |
607 src=((char *)(this->screen->pixels))+rects[i].x; | |
608 src+=(rects[i].y*this->screen->pitch); | |
609 | |
610 // This is the fast, well not too slow, remapping code for 32bit displays | |
611 | |
612 for(j=rects[i].h;j;--j) | |
613 { | |
614 destl=(Uint32 *)dest; | |
615 | |
616 for(k=0;k<srcwidth;k++) | |
617 { | |
618 srcl=(Uint32 *)&SDL_XPixels[src[k]]; | |
619 *destl=*srcl; | |
620 destl++; | |
621 } | |
622 src+=this->screen->pitch; | |
623 dest+=destpitch; | |
624 } | |
625 } | |
626 UnLockBitMap(handle); | |
627 } | |
628 #endif | |
629 } | |
630 else if(customroutine) | |
631 { | |
632 unsigned char *bm_address; | |
633 Uint32 destpitch; | |
634 APTR handle; | |
635 | |
636 // D(bug("Uso customroutine!\n")); | |
637 | |
638 if(handle=LockBitMapTags(SDL_RastPort->BitMap,LBMI_BASEADDRESS,(ULONG)&bm_address, | |
639 LBMI_BYTESPERROW,(ULONG)&destpitch,TAG_DONE)) | |
640 { | |
641 unsigned char *destbase; | |
642 register int j,srcwidth; | |
643 register unsigned char *src,*dest; | |
644 | |
645 // Aggiungo il bordo della finestra se sono fullscreen. | |
646 if(currently_fullscreen) | |
647 destbase=bm_address; | |
648 else | |
649 destbase=bm_address+(SDL_Window->TopEdge+SDL_Window->BorderTop)*destpitch+(SDL_Window->BorderLeft+SDL_Window->LeftEdge)*this->screen->format->BytesPerPixel; | |
650 | |
651 for ( i=0; i<numrects; ++i ) | |
652 { | |
653 srcwidth=rects[i].w; | |
654 | |
655 if ( !srcwidth ) { /* Clipped? */ | |
656 continue; | |
657 } | |
658 | |
659 dest=destbase+rects[i].x*this->screen->format->BytesPerPixel; | |
660 dest+=(rects[i].y*destpitch); | |
661 src=((char *)(this->screen->pixels))+rects[i].x*this->screen->format->BytesPerPixel; | |
662 src+=(rects[i].y*this->screen->pitch); | |
663 | |
664 srcwidth*=this->screen->format->BytesPerPixel; | |
665 | |
666 // D(bug("Rects: %ld,%ld %ld,%ld Src:%lx Dest:%lx\n",rects[i].x,rects[i].y,rects[i].w,rects[i].h,src,dest)); | |
667 | |
668 for(j=rects[i].h;j;--j) | |
669 { | |
670 memcpy(dest,src,srcwidth); | |
671 src+=this->screen->pitch; | |
672 dest+=destpitch; | |
673 } | |
674 } | |
675 UnLockBitMap(handle); | |
676 // D(bug("Rectblit addr: %lx pitch: %ld rects:%ld srcptr: %lx srcpitch: %ld\n",bm_address,destpitch,numrects,this->screen->pixels,this->screen->pitch)); | |
677 } | |
678 } | |
679 else | |
680 { | |
681 for ( i=0; i<numrects; ++i ) { | |
682 if ( ! rects[i].w ) { /* Clipped? */ | |
683 continue; | |
684 } | |
685 USE_WPA(this->screen->pixels,rects[i].x, rects[i].y,this->screen->pitch, | |
686 SDL_RastPort,SDL_Window->BorderLeft+rects[i].x,SDL_Window->BorderTop+rects[i].y, | |
687 rects[i].w,rects[i].h,format); | |
688 | |
689 /* | |
690 XPutImage(GFX_Display, SDL_Window, SDL_GC, SDL_Ximage, | |
691 rects[i].x, rects[i].y, | |
692 rects[i].x, rects[i].y, rects[i].w, rects[i].h); | |
693 */ | |
694 } | |
695 } | |
696 /* | |
697 if ( SDL_VideoSurface->flags & SDL_ASYNCBLIT ) { | |
698 ++blit_queued; | |
699 } else { | |
700 } | |
701 */ | |
702 } | |
703 | |
704 void CGX_RefreshDisplay(_THIS) | |
705 { | |
706 int format,customroutine=0; | |
707 #ifndef USE_CGX_WRITELUTPIXEL | |
708 int bpp; | |
709 #endif | |
710 /* Don't refresh a display that doesn't have an image (like GL) */ | |
711 if ( ! SDL_Ximage ) { | |
712 return; | |
713 } | |
714 | |
715 if(this->hidden->same_format) | |
716 { | |
717 format=RECTFMT_RAW; | |
718 } | |
719 else switch(this->screen->format->BytesPerPixel) | |
720 { | |
721 case 4: | |
722 format=RECTFMT_RGBA; | |
723 break; | |
724 case 3: | |
725 format=RECTFMT_RGB; | |
726 break; | |
727 case 2: | |
728 customroutine=1; | |
729 break; | |
730 case 1: | |
731 // D(bug("soft depth: 8 hardbpp: %ld\n",this->hidden->depth)); | |
732 if(this->hidden->depth>8) | |
733 { | |
734 #ifndef USE_CGX_WRITELUTPIXEL | |
735 if(this->hidden->depth>32) | |
736 customroutine=4; | |
737 else if(this->hidden->depth>16) | |
738 { | |
739 bpp=this->hidden->BytesPerPixel; // That one is the only one that needs bpp | |
740 customroutine=2; // The slow one! | |
741 } | |
742 else | |
743 customroutine=3; | |
744 #else | |
745 | |
746 customroutine=2; | |
747 #endif | |
748 // format=RECTFMT_LUT8; | |
749 } | |
750 else | |
751 customroutine=1; | |
752 break; | |
753 | |
754 } | |
755 | |
756 /* Check for endian-swapped X server, swap if necessary */ | |
757 if ( swap_pixels && | |
758 ((this->screen->format->BytesPerPixel%2) == 0) ) { | |
759 CGX_SwapAllPixels(this->screen); | |
760 USE_WPA(this->screen->pixels,0,0,this->screen->pitch, | |
761 SDL_RastPort,SDL_Window->BorderLeft,SDL_Window->BorderTop, | |
762 this->screen->w,this->screen->h,format); | |
763 CGX_SwapAllPixels(this->screen); | |
764 } | |
765 else if (customroutine==2) | |
766 { | |
767 #ifdef USE_CGX_WRITELUTPIXEL | |
768 WLUT(this->screen->pixels,0,0,this->screen->pitch, | |
769 SDL_RastPort,SDL_XPixels,SDL_Window->BorderLeft,SDL_Window->BorderTop, | |
770 this->screen->w,this->screen->h,CTABFMT_XRGB8); | |
771 #else | |
772 unsigned char *bm_address; | |
773 Uint32 destpitch; | |
774 APTR handle; | |
775 | |
776 if(handle=LockBitMapTags(SDL_RastPort->BitMap,LBMI_BASEADDRESS,(ULONG)&bm_address, | |
777 LBMI_BYTESPERROW,(ULONG)&destpitch,TAG_DONE)) | |
778 { | |
779 register int j,k,t; | |
780 register unsigned char *mask,*dst; | |
781 register unsigned char *src,*dest; | |
782 | |
783 // Aggiungo il bordo della finestra se sono fullscreen. | |
784 if(!currently_fullscreen) | |
785 dest=bm_address+(SDL_Window->TopEdge+SDL_Window->BorderTop)*destpitch+(SDL_Window->BorderLeft+SDL_Window->LeftEdge)*this->hidden->BytesPerPixel; | |
786 else | |
787 dest=bm_address; | |
788 | |
789 src=this->screen->pixels; | |
790 | |
791 for(j=this->screen->h;j;--j) | |
792 { | |
793 dst=dest; | |
794 // SLOW routine, used for 8->24 bit mapping | |
795 for(k=0;k<this->screen->w;k++) | |
796 { | |
797 mask=(unsigned char *)(&SDL_XPixels[src[k]]); | |
798 for(t=0;t<bpp;t++) | |
799 { | |
800 dst[t]=mask[t]; | |
801 } | |
802 dst+=bpp; | |
803 } | |
804 src+=this->screen->pitch; | |
805 dest+=destpitch; | |
806 } | |
807 UnLockBitMap(handle); | |
808 } | |
809 } | |
810 else if (customroutine==3) | |
811 { | |
812 unsigned char *bm_address; | |
813 Uint32 destpitch; | |
814 APTR handle; | |
815 | |
816 if(handle=LockBitMapTags(SDL_RastPort->BitMap,LBMI_BASEADDRESS,(ULONG)&bm_address, | |
817 LBMI_BYTESPERROW,(ULONG)&destpitch,TAG_DONE)) | |
818 { | |
819 register int j,k; | |
820 register unsigned char *src,*dest; | |
821 register Uint16 *destl,*srcl; | |
822 | |
823 if(!currently_fullscreen) | |
824 dest=bm_address+(SDL_Window->TopEdge+SDL_Window->BorderTop)*destpitch+(SDL_Window->BorderLeft+SDL_Window->LeftEdge)*this->hidden->BytesPerPixel; | |
825 else | |
826 dest=bm_address; | |
827 | |
828 src=this->screen->pixels; | |
829 | |
830 // This is the fast, well not too slow, remapping code for 16bit displays | |
831 | |
832 for(j=this->screen->h;j;--j) | |
833 { | |
834 destl=(Uint16 *)dest; | |
835 | |
836 for(k=0;k<this->screen->w;k++) | |
837 { | |
838 srcl=(Uint16 *)&SDL_XPixels[src[k]]; | |
839 *destl=*srcl; | |
840 destl++; | |
841 } | |
842 src+=this->screen->pitch; | |
843 dest+=destpitch; | |
844 } | |
845 UnLockBitMap(handle); | |
846 } | |
847 } | |
848 else if (customroutine==4) | |
849 { | |
850 unsigned char *bm_address; | |
851 Uint32 destpitch; | |
852 APTR handle; | |
853 | |
854 if(handle=LockBitMapTags(SDL_RastPort->BitMap,LBMI_BASEADDRESS,(ULONG)&bm_address, | |
855 LBMI_BYTESPERROW,(ULONG)&destpitch,TAG_DONE)) | |
856 { | |
857 register int j,k; | |
858 register unsigned char *src,*dest; | |
859 register Uint32 *destl,*srcl; | |
860 | |
861 if(!currently_fullscreen) | |
862 dest=bm_address+(SDL_Window->TopEdge+SDL_Window->BorderTop)*destpitch+(SDL_Window->BorderLeft+SDL_Window->LeftEdge)*this->hidden->BytesPerPixel; | |
863 else | |
864 dest=bm_address; | |
865 | |
866 src=this->screen->pixels; | |
867 | |
868 // This is the fast, well not too slow, remapping code for 32bit displays | |
869 | |
870 for(j=this->screen->h;j;--j) | |
871 { | |
872 destl=(Uint32 *)dest; | |
873 | |
874 for(k=0;k<this->screen->w;k++) | |
875 { | |
876 srcl=(Uint32 *)&SDL_XPixels[src[k]]; | |
877 *destl=*srcl; | |
878 destl++; | |
879 } | |
880 src+=this->screen->pitch; | |
881 dest+=destpitch; | |
882 } | |
883 UnLockBitMap(handle); | |
884 } | |
885 #endif | |
886 } | |
887 else if(customroutine) | |
888 { | |
889 unsigned char *bm_address; | |
890 Uint32 destpitch; | |
891 APTR handle; | |
892 | |
893 if(handle=LockBitMapTags(SDL_RastPort->BitMap, | |
894 LBMI_BASEADDRESS,(ULONG)&bm_address, | |
895 LBMI_BYTESPERROW,(ULONG)&destpitch,TAG_DONE)) | |
896 { | |
897 register int j; | |
898 register unsigned char *src,*dest; | |
899 | |
900 if(!currently_fullscreen) | |
901 dest=bm_address+(SDL_Window->TopEdge+SDL_Window->BorderTop)*destpitch+(SDL_Window->BorderLeft+SDL_Window->LeftEdge)*this->screen->format->BytesPerPixel; | |
902 else | |
903 dest=bm_address; | |
904 | |
905 src=this->screen->pixels; | |
906 | |
907 // D(bug("addr: %lx pitch: %ld src:%lx srcpitch: %ld\n",dest,destpitch,this->screen->pixels,this->screen->pitch)); | |
908 | |
909 if(this->screen->pitch==destpitch) | |
910 { | |
911 memcpy(dest,src,this->screen->pitch*this->screen->h); | |
912 } | |
913 else | |
914 { | |
915 for(j=this->screen->h;j;--j) | |
916 { | |
917 memcpy(dest,src,this->screen->pitch); | |
918 src+=this->screen->pitch; | |
919 dest+=destpitch; | |
920 } | |
921 } | |
922 | |
923 UnLockBitMap(handle); | |
924 } | |
925 } | |
926 else | |
927 { | |
928 USE_WPA(this->screen->pixels,0,0,this->screen->pitch, | |
929 SDL_RastPort,SDL_Window->BorderLeft,SDL_Window->BorderTop, | |
930 this->screen->w,this->screen->h,format); | |
931 } | |
932 | |
933 } |