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