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