Mercurial > sdl-ios-xcode
annotate src/video/photon/SDL_ph_image.c @ 266:c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 18 Jan 2002 18:14:03 +0000 |
parents | e8157fcb3114 |
children | 3d8b6b9f1e18 |
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 | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
19
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 #include <Ph.h> | |
30 #include <photon/Pg.h> | |
31 | |
32 #include "SDL_error.h" | |
33 #include "SDL_endian.h" | |
34 #include "SDL_ph_image_c.h" | |
35 | |
36 //printf("%s:%s:%d\n", __FILE__, __PRETTY_FUNCTION__, __LINE__ ); | |
37 | |
38 /* Various screen update functions available */ | |
39 //static void ph_NormalUpdate(_THIS, int numrects, SDL_Rect *rects); | |
40 //static void ph_DummyUpdate(_THIS, int numrects, SDL_Rect *rects); | |
41 | |
42 int ph_SetupImage(_THIS, SDL_Surface *screen) | |
43 { | |
44 int type = 0; | |
45 | |
46 /* Determine image type */ | |
47 switch(screen->format->BitsPerPixel) | |
48 { | |
49 case 8:{ | |
50 type = Pg_IMAGE_PALETTE_BYTE; | |
51 } | |
52 break; | |
53 case 15:{ | |
54 type = Pg_IMAGE_DIRECT_555; | |
55 } | |
56 break; | |
57 case 16:{ | |
58 type = Pg_IMAGE_DIRECT_565; | |
59 } | |
60 break; | |
61 | |
62 case 24:{ | |
63 type = Pg_IMAGE_DIRECT_888; | |
64 } | |
65 break; | |
66 | |
67 case 32:{ | |
68 type = Pg_IMAGE_DIRECT_8888; | |
69 } | |
70 break; | |
71 default:{ | |
72 /* should never get here */ | |
73 fprintf(stderr,"error: unsupported bbp = %d\n", | |
74 screen->format->BitsPerPixel); | |
75 return -1; | |
76 } | |
77 break; | |
78 } | |
79 | |
80 //using shared memory for speed (set last param to 1) | |
19
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
81 if ((SDL_Image = PhCreateImage( NULL, screen->w, screen->h, type, NULL, 0, 1 )) == NULL) |
0 | 82 { |
83 fprintf(stderr,"error: PhCreateImage failed.\n"); | |
84 return -1; | |
85 } | |
86 | |
87 screen->pixels = SDL_Image->image; | |
88 | |
89 this->UpdateRects = ph_NormalUpdate; | |
90 | |
91 return 0; | |
92 } | |
93 | |
94 int ph_SetupOCImage(_THIS, SDL_Surface *screen) //Offscreen context | |
95 { | |
96 int type = 0; | |
97 | |
98 /* Determine image type */ | |
99 switch(screen->format->BitsPerPixel) | |
100 { | |
101 case 8:{ | |
102 type = Pg_IMAGE_PALETTE_BYTE; | |
103 } | |
104 break; | |
105 case 15:{ | |
106 type = Pg_IMAGE_DIRECT_555; | |
107 } | |
108 break; | |
109 case 16:{ | |
110 type = Pg_IMAGE_DIRECT_565; | |
111 } | |
112 break; | |
113 | |
114 case 24:{ | |
115 type = Pg_IMAGE_DIRECT_888; | |
116 } | |
117 break; | |
118 | |
119 case 32:{ | |
120 type = Pg_IMAGE_DIRECT_8888; | |
121 } | |
122 break; | |
123 default:{ | |
124 /* should never get here */ | |
125 fprintf(stderr,"error: unsupported bbp = %d\n", | |
126 screen->format->BitsPerPixel); | |
127 return -1; | |
128 } | |
129 break; | |
130 } | |
131 | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
132 OCImage.FrameData0 = (FRAMEDATA *) malloc((size_t)(sizeof( FRAMEDATA))); |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
133 OCImage.FrameData1 = (FRAMEDATA *) malloc((size_t)(sizeof( FRAMEDATA))); |
0 | 134 |
135 if(OCImage.direct_context == NULL) | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
136 OCImage.direct_context = PdCreateDirectContext(); |
0 | 137 |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
138 OCImage.offscreen_context = PdCreateOffscreenContext(0,screen->w,screen->h, Pg_OSC_MEM_PAGE_ALIGN); |
0 | 139 |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
140 if (OCImage.offscreen_context == NULL) |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
141 { |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
142 printf("PdCreateOffscreenContext failed\n"); |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
143 return -1; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
144 } |
0 | 145 |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
146 OCImage.Stride = OCImage.offscreen_context->pitch; |
0 | 147 |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
148 if (OCImage.flags & SDL_DOUBLEBUF) |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
149 printf("hardware flag for doublebuf offscreen context\n"); |
0 | 150 |
151 | |
152 OCImage.dc_ptr.ptr8 = (unsigned char *) PdGetOffscreenContextPtr(OCImage.offscreen_context); | |
153 | |
154 OCImage.CurrentFrameData = OCImage.FrameData0; | |
155 OCImage.CurrentFrameData->Y = OCImage.dc_ptr.ptr8; | |
156 OCImage.CurrentFrameData->U = NULL; | |
157 OCImage.CurrentFrameData->V = NULL; | |
158 OCImage.current = 0; | |
159 | |
160 if(OCImage.dc_ptr.ptr8 == NULL) | |
161 { | |
162 printf("PdGetOffscreenContextPtr failed\n"); | |
163 return -1; | |
164 } | |
165 | |
166 PhDCSetCurrent(OCImage.offscreen_context); | |
167 | |
168 screen->pixels = OCImage.CurrentFrameData->Y; | |
169 | |
170 this->UpdateRects = ph_OCUpdate; | |
171 | |
172 return 0; | |
173 } | |
174 | |
175 | |
176 void ph_DestroyImage(_THIS, SDL_Surface *screen) | |
177 { | |
178 if(SDL_Image == NULL) | |
179 return; | |
180 | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
181 if (OCImage.offscreen_context != NULL) |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
182 { |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
183 PhDCRelease(OCImage.offscreen_context); |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
184 OCImage.offscreen_context = NULL; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
185 free(OCImage.FrameData0); |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
186 OCImage.FrameData0 = NULL; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
187 free(OCImage.FrameData1); |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
188 OCImage.FrameData1 = NULL; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
189 } |
0 | 190 |
191 if (SDL_Image->image) | |
192 { | |
19
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
193 // SDL_Image->flags=Ph_RELEASE_IMAGE; |
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
194 // PhReleaseImage(SDL_Image); |
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
195 PgShmemDestroy(SDL_Image->image); // Use this if you using shared memory, or uncomment |
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
196 // lines above if not (and comment this line ;-) |
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
197 free(SDL_Image); |
0 | 198 } |
199 | |
19
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
200 if ( screen ) |
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
201 { |
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
202 screen->pixels = NULL; |
0 | 203 } |
204 | |
205 SDL_Image = NULL; | |
206 } | |
207 | |
208 int ph_ResizeImage(_THIS, SDL_Surface *screen, Uint32 flags) | |
209 { | |
210 ph_DestroyImage(this, screen); | |
211 | |
212 if( flags & SDL_HWSURFACE) | |
213 { | |
214 OCImage.flags = flags; //needed for SDL_DOUBLEBUF check | |
215 return ph_SetupOCImage(this,screen); | |
216 } | |
217 else if(flags & SDL_OPENGL) /* No image when using GL */ | |
218 { | |
219 return 0; | |
220 } | |
221 else | |
222 { | |
223 return ph_SetupImage(this, screen); | |
224 } | |
225 } | |
226 | |
227 int ph_AllocHWSurface(_THIS, SDL_Surface *surface) | |
228 { | |
229 return(-1); | |
230 } | |
231 | |
232 void ph_FreeHWSurface(_THIS, SDL_Surface *surface) | |
233 { | |
234 return; | |
235 } | |
236 | |
237 int ph_FlipHWSurface(_THIS, SDL_Surface *surface) | |
238 { | |
239 return(0); | |
240 } | |
241 | |
242 int ph_LockHWSurface(_THIS, SDL_Surface *surface) | |
243 { | |
244 if ( (surface == SDL_VideoSurface) && blit_queued ) { | |
245 // XSync(GFX_Display, False); | |
246 PgFlush(); | |
247 blit_queued = 0; | |
248 } | |
249 return(0); | |
250 } | |
251 | |
252 void ph_UnlockHWSurface(_THIS, SDL_Surface *surface) | |
253 { | |
254 return; | |
255 } | |
256 | |
257 static PhPoint_t ph_pos; | |
258 static PhRect_t ph_rect; | |
259 static int i; | |
260 | |
261 void ph_NormalUpdate(_THIS, int numrects, SDL_Rect *rects) | |
262 { | |
263 | |
264 for ( i=0; i<numrects; ++i ) | |
265 { | |
266 if ( rects[i].w == 0 ) { /* Clipped? */ | |
267 continue; | |
268 } | |
269 | |
270 ph_pos.x = rects[i].x; | |
271 ph_pos.y = rects[i].y; | |
272 ph_rect.ul.x = rects[i].x; | |
273 ph_rect.ul.y = rects[i].y; | |
274 ph_rect.lr.x = rects[i].x + rects[i].w; | |
275 ph_rect.lr.y = rects[i].y + rects[i].h; | |
276 | |
277 if (PgDrawPhImageRectmx( &ph_pos, SDL_Image, &ph_rect, 0 ) < 0) | |
278 { | |
279 fprintf(stderr,"error: PgDrawPhImageRectmx failed.\n"); | |
280 } | |
281 } | |
282 if (PgFlush() < 0) | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
283 { |
0 | 284 fprintf(stderr,"error: PgFlush failed.\n"); |
285 } | |
286 } | |
287 void ph_OCUpdate(_THIS, int numrects, SDL_Rect *rects) | |
288 { | |
289 PhPoint_t zero = {0}; | |
290 PhRect_t src_rect; | |
291 PhRect_t dest_rect; | |
292 | |
293 if(OCImage.direct_context == NULL) | |
294 { | |
295 return; | |
296 } | |
297 | |
298 PgSetRegion(PtWidgetRid(window)); | |
299 PgSetClipping(0,NULL); | |
300 PgWaitHWIdle(); | |
301 | |
302 | |
303 for ( i=0; i<numrects; ++i ) | |
304 { | |
305 if ( rects[i].w == 0 ) { /* Clipped? */ | |
306 continue; | |
307 } | |
308 | |
309 src_rect.ul.x=rects[i].x; | |
310 src_rect.ul.y=rects[i].y; | |
311 dest_rect.ul.x=rects[i].x; | |
312 dest_rect.ul.y=rects[i].y; | |
313 | |
314 dest_rect.lr.x=src_rect.lr.x= rects[i].x +rects[i].w; | |
315 dest_rect.lr.y=src_rect.lr.y= rects[i].y +rects[i].h; | |
316 | |
317 zero.x = zero.y = 0; | |
318 PgSetTranslation (&zero, 0); | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
319 PgSetRegion(PtWidgetRid(window)); |
0 | 320 PgSetClipping(0,NULL); |
321 PgContextBlitArea(OCImage.offscreen_context, (PhArea_t *)(&src_rect), NULL, (PhArea_t *)(&dest_rect)); | |
322 | |
323 } | |
324 if (PgFlush() < 0) | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
325 { |
0 | 326 fprintf(stderr,"error: PgFlush failed.\n"); |
327 } | |
328 | |
329 //later used to toggling double buffer | |
330 if(OCImage.current == 0) | |
331 { | |
332 OCImage.CurrentFrameData = OCImage.FrameData0; | |
333 } | |
334 else | |
335 { | |
336 OCImage.CurrentFrameData = OCImage.FrameData1; | |
337 } | |
338 } | |
339 |