Mercurial > sdl-ios-xcode
comparison src/video/cybergfx/SDL_cgximage.c @ 255:dcb5e869f8b5
Updated Amiga port by Gabriele Greco
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 16 Dec 2001 20:00:27 +0000 |
parents | e8157fcb3114 |
children | f6ffac90895c |
comparison
equal
deleted
inserted
replaced
254:4fc12b8edf74 | 255:dcb5e869f8b5 |
---|---|
50 static void CGX_FakeUpdate(_THIS, int numrects, SDL_Rect *rects); | 50 static void CGX_FakeUpdate(_THIS, int numrects, SDL_Rect *rects); |
51 | 51 |
52 BOOL SafeDisp=TRUE,SafeChange=TRUE; | 52 BOOL SafeDisp=TRUE,SafeChange=TRUE; |
53 struct MsgPort *safeport=NULL,*dispport=NULL; | 53 struct MsgPort *safeport=NULL,*dispport=NULL; |
54 ULONG safe_sigbit,disp_sigbit; | 54 ULONG safe_sigbit,disp_sigbit; |
55 int use_picasso96=1; | |
55 | 56 |
56 int CGX_SetupImage(_THIS, SDL_Surface *screen) | 57 int CGX_SetupImage(_THIS, SDL_Surface *screen) |
57 { | 58 { |
58 if(screen->flags&SDL_HWSURFACE) | 59 SDL_Ximage=NULL; |
59 { | 60 |
60 Uint32 pitch; | 61 if(screen->flags&SDL_HWSURFACE) { |
61 SDL_Ximage=NULL; | 62 ULONG pitch; |
62 | 63 |
63 if(!screen->hwdata) | 64 if(!screen->hwdata) { |
64 { | |
65 if(!(screen->hwdata=malloc(sizeof(struct private_hwdata)))) | 65 if(!(screen->hwdata=malloc(sizeof(struct private_hwdata)))) |
66 { | |
67 return -1; | 66 return -1; |
68 } | 67 |
69 D(bug("Creating system accel struct\n")); | 68 D(bug("Creating system accel struct\n")); |
70 } | 69 } |
71 screen->hwdata->lock=0; | 70 screen->hwdata->lock=NULL; |
71 screen->hwdata->allocated=0; | |
72 screen->hwdata->mask=NULL; | |
72 screen->hwdata->bmap=SDL_RastPort->BitMap; | 73 screen->hwdata->bmap=SDL_RastPort->BitMap; |
73 screen->hwdata->videodata=this; | 74 screen->hwdata->videodata=this; |
74 | 75 |
75 if(!(screen->hwdata->lock=LockBitMapTags(screen->hwdata->bmap, | 76 if(!(screen->hwdata->lock=LockBitMapTags(screen->hwdata->bmap, |
76 LBMI_BASEADDRESS,(ULONG)&screen->pixels, | 77 LBMI_BASEADDRESS,(ULONG)&screen->pixels, |
77 LBMI_BYTESPERROW,(ULONG)&pitch,TAG_DONE))) | 78 LBMI_BYTESPERROW,(ULONG)&pitch,TAG_DONE))) { |
78 { | |
79 free(screen->hwdata); | 79 free(screen->hwdata); |
80 screen->hwdata=NULL; | 80 screen->hwdata=NULL; |
81 return -1; | 81 return -1; |
82 } | 82 } |
83 else | 83 else { |
84 { | |
85 UnLockBitMap(screen->hwdata->lock); | 84 UnLockBitMap(screen->hwdata->lock); |
86 screen->hwdata->lock=NULL; | 85 screen->hwdata->lock=NULL; |
87 } | 86 } |
88 | 87 |
89 screen->pitch=pitch; | 88 screen->pitch=pitch; |
99 if ( screen->pixels == NULL ) { | 98 if ( screen->pixels == NULL ) { |
100 SDL_OutOfMemory(); | 99 SDL_OutOfMemory(); |
101 return(-1); | 100 return(-1); |
102 } | 101 } |
103 | 102 |
104 /* | |
105 { | |
106 int bpp = screen->format->BytesPerPixel; | |
107 SDL_Ximage = XCreateImage(SDL_Display, SDL_Visual, | |
108 this->hidden->depth, ZPixmap, 0, | |
109 (char *)screen->pixels, | |
110 screen->w, screen->h, | |
111 (bpp == 3) ? 32 : bpp * 8, | |
112 0); | |
113 } | |
114 */ | |
115 SDL_Ximage=screen->pixels; | 103 SDL_Ximage=screen->pixels; |
116 | 104 |
117 if ( SDL_Ximage == NULL ) { | 105 if ( SDL_Ximage == NULL ) { |
118 SDL_SetError("Couldn't create XImage"); | 106 SDL_SetError("Couldn't create XImage"); |
119 return(-1); | 107 return(-1); |
130 free(SDL_Ximage); | 118 free(SDL_Ximage); |
131 SDL_Ximage = NULL; | 119 SDL_Ximage = NULL; |
132 } | 120 } |
133 if ( screen ) { | 121 if ( screen ) { |
134 screen->pixels = NULL; | 122 screen->pixels = NULL; |
123 | |
124 if(screen->hwdata) { | |
125 free(screen->hwdata); | |
126 screen->hwdata=NULL; | |
127 } | |
135 } | 128 } |
136 } | 129 } |
137 | 130 |
138 /* This is a hack to see whether this system has more than 1 CPU */ | 131 /* This is a hack to see whether this system has more than 1 CPU */ |
139 static int num_CPU(void) | 132 static int num_CPU(void) |
143 | 136 |
144 int CGX_ResizeImage(_THIS, SDL_Surface *screen, Uint32 flags) | 137 int CGX_ResizeImage(_THIS, SDL_Surface *screen, Uint32 flags) |
145 { | 138 { |
146 int retval; | 139 int retval; |
147 | 140 |
148 D(bug("Chiamata ResizeImage!\n")); | 141 D(bug("Calling ResizeImage()\n")); |
149 | 142 |
150 CGX_DestroyImage(this, screen); | 143 CGX_DestroyImage(this, screen); |
151 | 144 |
152 if ( flags & SDL_OPENGL ) { /* No image when using GL */ | 145 if ( flags & SDL_OPENGL ) { /* No image when using GL */ |
153 retval = 0; | 146 retval = 0; |
154 } else { | 147 } else { |
155 retval = CGX_SetupImage(this, screen); | 148 retval = CGX_SetupImage(this, screen); |
156 /* We support asynchronous blitting on the display */ | 149 /* We support asynchronous blitting on the display */ |
157 if ( flags & SDL_ASYNCBLIT ) { | 150 if ( flags & SDL_ASYNCBLIT ) { |
158 /* This is actually slower on single-CPU systems, | |
159 probably because of CPU contention between the | |
160 X server and the application. | |
161 Note: Is this still true with XFree86 4.0? | |
162 */ | |
163 if ( num_CPU() > 1 ) { | 151 if ( num_CPU() > 1 ) { |
164 screen->flags |= SDL_ASYNCBLIT; | 152 screen->flags |= SDL_ASYNCBLIT; |
165 } | 153 } |
166 } | 154 } |
167 } | 155 } |
168 return(retval); | 156 return(retval); |
169 } | 157 } |
170 | 158 |
171 /* We don't actually allow hardware surfaces other than the main one */ | |
172 int CGX_AllocHWSurface(_THIS, SDL_Surface *surface) | 159 int CGX_AllocHWSurface(_THIS, SDL_Surface *surface) |
173 { | 160 { |
174 D(bug("Alloc HW surface...%ld x %ld x %ld!\n",surface->w,surface->h,this->hidden->depth)); | 161 D(bug("Alloc HW surface...%ld x %ld x %ld!\n",surface->w,surface->h,this->hidden->depth)); |
175 | 162 |
176 if(surface==SDL_VideoSurface) | 163 if(surface==SDL_VideoSurface) |
183 { | 170 { |
184 if(!(surface->hwdata=malloc(sizeof(struct private_hwdata)))) | 171 if(!(surface->hwdata=malloc(sizeof(struct private_hwdata)))) |
185 return -1; | 172 return -1; |
186 } | 173 } |
187 | 174 |
175 surface->hwdata->mask=NULL; | |
188 surface->hwdata->lock=NULL; | 176 surface->hwdata->lock=NULL; |
189 surface->hwdata->videodata=this; | 177 surface->hwdata->videodata=this; |
178 surface->hwdata->allocated=0; | |
190 | 179 |
191 if(surface->hwdata->bmap=AllocBitMap(surface->w,surface->h,this->hidden->depth,BMF_MINPLANES,SDL_Display->RastPort.BitMap)) | 180 if(surface->hwdata->bmap=AllocBitMap(surface->w,surface->h,this->hidden->depth,BMF_MINPLANES,SDL_Display->RastPort.BitMap)) |
192 { | 181 { |
182 surface->hwdata->allocated=1; | |
193 surface->flags|=SDL_HWSURFACE; | 183 surface->flags|=SDL_HWSURFACE; |
194 D(bug("...OK\n")); | 184 D(bug("...OK\n")); |
195 return 0; | 185 return 0; |
196 } | 186 } |
197 else | 187 else |
209 D(bug("Free hw surface.\n")); | 199 D(bug("Free hw surface.\n")); |
210 | 200 |
211 if(surface->hwdata->mask) | 201 if(surface->hwdata->mask) |
212 free(surface->hwdata->mask); | 202 free(surface->hwdata->mask); |
213 | 203 |
214 if(surface->hwdata->bmap) | 204 if(surface->hwdata->bmap&&surface->hwdata->allocated) |
215 FreeBitMap(surface->hwdata->bmap); | 205 FreeBitMap(surface->hwdata->bmap); |
216 | 206 |
217 free(surface->hwdata); | 207 free(surface->hwdata); |
218 surface->hwdata=NULL; | 208 surface->hwdata=NULL; |
209 surface->pixels=NULL; | |
210 D(bug("end of free hw surface\n")); | |
219 } | 211 } |
220 return; | 212 return; |
221 } | 213 } |
222 | 214 |
223 int CGX_LockHWSurface(_THIS, SDL_Surface *surface) | 215 int CGX_LockHWSurface(_THIS, SDL_Surface *surface) |
240 | 232 |
241 if(!currently_fullscreen&&surface==SDL_VideoSurface) | 233 if(!currently_fullscreen&&surface==SDL_VideoSurface) |
242 surface->pixels=((char *)surface->pixels)+(surface->pitch*(SDL_Window->BorderTop+SDL_Window->TopEdge)+ | 234 surface->pixels=((char *)surface->pixels)+(surface->pitch*(SDL_Window->BorderTop+SDL_Window->TopEdge)+ |
243 surface->format->BytesPerPixel*(SDL_Window->BorderLeft+SDL_Window->LeftEdge)); | 235 surface->format->BytesPerPixel*(SDL_Window->BorderLeft+SDL_Window->LeftEdge)); |
244 } | 236 } |
245 else | 237 D(else bug("Already locked!!!\n")); |
246 D(bug("Already locked!!!\n")); | |
247 } | 238 } |
248 return(0); | 239 return(0); |
249 } | 240 } |
241 | |
250 void CGX_UnlockHWSurface(_THIS, SDL_Surface *surface) | 242 void CGX_UnlockHWSurface(_THIS, SDL_Surface *surface) |
251 { | 243 { |
252 if(surface->hwdata && surface->hwdata->lock) | 244 if(surface->hwdata && surface->hwdata->lock) |
253 { | 245 { |
254 UnLockBitMap(surface->hwdata->lock); | 246 UnLockBitMap(surface->hwdata->lock); |
396 { | 388 { |
397 int i,format,customroutine=0; | 389 int i,format,customroutine=0; |
398 #ifndef USE_CGX_WRITELUTPIXEL | 390 #ifndef USE_CGX_WRITELUTPIXEL |
399 int bpp; | 391 int bpp; |
400 #endif | 392 #endif |
401 if(this->hidden->same_format) | 393 if(this->hidden->same_format && !use_picasso96) |
402 { | 394 { |
403 format=RECTFMT_RAW; | 395 format=RECTFMT_RAW; |
404 } | 396 } |
405 else switch(this->screen->format->BytesPerPixel) | 397 else switch(this->screen->format->BytesPerPixel) |
406 { | 398 { |
443 } | 435 } |
444 | 436 |
445 /* Check for endian-swapped X server, swap if necessary (VERY slow!) */ | 437 /* Check for endian-swapped X server, swap if necessary (VERY slow!) */ |
446 if ( swap_pixels && | 438 if ( swap_pixels && |
447 ((this->screen->format->BytesPerPixel%2) == 0) ) { | 439 ((this->screen->format->BytesPerPixel%2) == 0) ) { |
448 D(bug("Swappo! Lento!\n")); | 440 D(bug("Software Swapping! SLOOOW!\n")); |
449 CGX_SwapPixels(this->screen, numrects, rects); | 441 CGX_SwapPixels(this->screen, numrects, rects); |
450 for ( i=0; i<numrects; ++i ) { | 442 for ( i=0; i<numrects; ++i ) { |
451 if ( ! rects[i].w ) { /* Clipped? */ | 443 if ( ! rects[i].w ) { /* Clipped? */ |
452 continue; | 444 continue; |
453 } | 445 } |
631 { | 623 { |
632 unsigned char *bm_address; | 624 unsigned char *bm_address; |
633 Uint32 destpitch; | 625 Uint32 destpitch; |
634 APTR handle; | 626 APTR handle; |
635 | 627 |
636 // D(bug("Uso customroutine!\n")); | 628 // D(bug("Using customroutine!\n")); |
637 | 629 |
638 if(handle=LockBitMapTags(SDL_RastPort->BitMap,LBMI_BASEADDRESS,(ULONG)&bm_address, | 630 if(handle=LockBitMapTags(SDL_RastPort->BitMap,LBMI_BASEADDRESS,(ULONG)&bm_address, |
639 LBMI_BYTESPERROW,(ULONG)&destpitch,TAG_DONE)) | 631 LBMI_BYTESPERROW,(ULONG)&destpitch,TAG_DONE)) |
640 { | 632 { |
641 unsigned char *destbase; | 633 unsigned char *destbase; |
683 continue; | 675 continue; |
684 } | 676 } |
685 USE_WPA(this->screen->pixels,rects[i].x, rects[i].y,this->screen->pitch, | 677 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, | 678 SDL_RastPort,SDL_Window->BorderLeft+rects[i].x,SDL_Window->BorderTop+rects[i].y, |
687 rects[i].w,rects[i].h,format); | 679 rects[i].w,rects[i].h,format); |
688 | 680 } |
689 /* | 681 } |
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 } | 682 } |
703 | 683 |
704 void CGX_RefreshDisplay(_THIS) | 684 void CGX_RefreshDisplay(_THIS) |
705 { | 685 { |
706 int format,customroutine=0; | 686 int format,customroutine=0; |
710 /* Don't refresh a display that doesn't have an image (like GL) */ | 690 /* Don't refresh a display that doesn't have an image (like GL) */ |
711 if ( ! SDL_Ximage ) { | 691 if ( ! SDL_Ximage ) { |
712 return; | 692 return; |
713 } | 693 } |
714 | 694 |
715 if(this->hidden->same_format) | 695 if(this->hidden->same_format && !use_picasso96) |
716 { | 696 { |
717 format=RECTFMT_RAW; | 697 format=RECTFMT_RAW; |
718 } | 698 } |
719 else switch(this->screen->format->BytesPerPixel) | 699 else switch(this->screen->format->BytesPerPixel) |
720 { | 700 { |