Mercurial > sdl-ios-xcode
annotate src/video/photon/SDL_ph_image.c @ 283:3d8b6b9f1e18
Date: Mon, 18 Feb 2002 16:46:59 +1200
From: Julian Kinraid <jkinraid@clear.net.nz>
Subject: Patches for photon port of SDL
Hi,
A couple more patches for photon and the nto audio. Adds mouse grabbing
support, fixed cursor images, unicode keyboard events (though no unicode
data on kye release, is that a problem?), hopefully fixing some audio
lag problems, and a few other fixes.
Thanks,
Julian Kinraid
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 20 Feb 2002 01:05:51 +0000 |
parents | c6abdda2f666 |
children | 68a8a8237c09 |
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 { | |
283
3d8b6b9f1e18
Date: Mon, 18 Feb 2002 16:46:59 +1200
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
178 #if 0 |
0 | 179 if(SDL_Image == NULL) |
180 return; | |
283
3d8b6b9f1e18
Date: Mon, 18 Feb 2002 16:46:59 +1200
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
181 #endif |
0 | 182 |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
183 if (OCImage.offscreen_context != NULL) |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
184 { |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
185 PhDCRelease(OCImage.offscreen_context); |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
186 OCImage.offscreen_context = NULL; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
187 free(OCImage.FrameData0); |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
188 OCImage.FrameData0 = NULL; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
189 free(OCImage.FrameData1); |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
190 OCImage.FrameData1 = NULL; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
191 } |
0 | 192 |
283
3d8b6b9f1e18
Date: Mon, 18 Feb 2002 16:46:59 +1200
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
193 if (SDL_Image) |
0 | 194 { |
19
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
195 // 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
|
196 // PhReleaseImage(SDL_Image); |
283
3d8b6b9f1e18
Date: Mon, 18 Feb 2002 16:46:59 +1200
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
197 if (SDL_Image->image) |
3d8b6b9f1e18
Date: Mon, 18 Feb 2002 16:46:59 +1200
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
198 PgShmemDestroy(SDL_Image->image); // Use this if you using shared memory, or uncomment |
19
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
199 // 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
|
200 free(SDL_Image); |
283
3d8b6b9f1e18
Date: Mon, 18 Feb 2002 16:46:59 +1200
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
201 SDL_Image = NULL; |
0 | 202 } |
203 | |
19
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
204 if ( screen ) |
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
205 { |
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
206 screen->pixels = NULL; |
0 | 207 } |
208 } | |
209 | |
210 int ph_ResizeImage(_THIS, SDL_Surface *screen, Uint32 flags) | |
211 { | |
212 ph_DestroyImage(this, screen); | |
213 | |
214 if( flags & SDL_HWSURFACE) | |
215 { | |
216 OCImage.flags = flags; //needed for SDL_DOUBLEBUF check | |
217 return ph_SetupOCImage(this,screen); | |
218 } | |
219 else if(flags & SDL_OPENGL) /* No image when using GL */ | |
220 { | |
221 return 0; | |
222 } | |
223 else | |
224 { | |
225 return ph_SetupImage(this, screen); | |
226 } | |
227 } | |
228 | |
229 int ph_AllocHWSurface(_THIS, SDL_Surface *surface) | |
230 { | |
231 return(-1); | |
232 } | |
233 | |
234 void ph_FreeHWSurface(_THIS, SDL_Surface *surface) | |
235 { | |
236 return; | |
237 } | |
238 | |
239 int ph_FlipHWSurface(_THIS, SDL_Surface *surface) | |
240 { | |
241 return(0); | |
242 } | |
243 | |
244 int ph_LockHWSurface(_THIS, SDL_Surface *surface) | |
245 { | |
246 if ( (surface == SDL_VideoSurface) && blit_queued ) { | |
247 // XSync(GFX_Display, False); | |
248 PgFlush(); | |
249 blit_queued = 0; | |
250 } | |
251 return(0); | |
252 } | |
253 | |
254 void ph_UnlockHWSurface(_THIS, SDL_Surface *surface) | |
255 { | |
256 return; | |
257 } | |
258 | |
259 static PhPoint_t ph_pos; | |
260 static PhRect_t ph_rect; | |
261 static int i; | |
262 | |
263 void ph_NormalUpdate(_THIS, int numrects, SDL_Rect *rects) | |
264 { | |
265 | |
266 for ( i=0; i<numrects; ++i ) | |
267 { | |
268 if ( rects[i].w == 0 ) { /* Clipped? */ | |
269 continue; | |
270 } | |
271 | |
272 ph_pos.x = rects[i].x; | |
273 ph_pos.y = rects[i].y; | |
274 ph_rect.ul.x = rects[i].x; | |
275 ph_rect.ul.y = rects[i].y; | |
276 ph_rect.lr.x = rects[i].x + rects[i].w; | |
277 ph_rect.lr.y = rects[i].y + rects[i].h; | |
278 | |
279 if (PgDrawPhImageRectmx( &ph_pos, SDL_Image, &ph_rect, 0 ) < 0) | |
280 { | |
281 fprintf(stderr,"error: PgDrawPhImageRectmx failed.\n"); | |
282 } | |
283 } | |
284 if (PgFlush() < 0) | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
285 { |
0 | 286 fprintf(stderr,"error: PgFlush failed.\n"); |
287 } | |
288 } | |
289 void ph_OCUpdate(_THIS, int numrects, SDL_Rect *rects) | |
290 { | |
291 PhPoint_t zero = {0}; | |
292 PhRect_t src_rect; | |
293 PhRect_t dest_rect; | |
294 | |
295 if(OCImage.direct_context == NULL) | |
296 { | |
297 return; | |
298 } | |
299 | |
300 PgSetRegion(PtWidgetRid(window)); | |
301 PgSetClipping(0,NULL); | |
302 PgWaitHWIdle(); | |
303 | |
304 | |
305 for ( i=0; i<numrects; ++i ) | |
306 { | |
307 if ( rects[i].w == 0 ) { /* Clipped? */ | |
308 continue; | |
309 } | |
310 | |
311 src_rect.ul.x=rects[i].x; | |
312 src_rect.ul.y=rects[i].y; | |
313 dest_rect.ul.x=rects[i].x; | |
314 dest_rect.ul.y=rects[i].y; | |
315 | |
316 dest_rect.lr.x=src_rect.lr.x= rects[i].x +rects[i].w; | |
317 dest_rect.lr.y=src_rect.lr.y= rects[i].y +rects[i].h; | |
318 | |
319 zero.x = zero.y = 0; | |
320 PgSetTranslation (&zero, 0); | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
321 PgSetRegion(PtWidgetRid(window)); |
0 | 322 PgSetClipping(0,NULL); |
323 PgContextBlitArea(OCImage.offscreen_context, (PhArea_t *)(&src_rect), NULL, (PhArea_t *)(&dest_rect)); | |
324 | |
325 } | |
326 if (PgFlush() < 0) | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
327 { |
0 | 328 fprintf(stderr,"error: PgFlush failed.\n"); |
329 } | |
330 | |
331 //later used to toggling double buffer | |
332 if(OCImage.current == 0) | |
333 { | |
334 OCImage.CurrentFrameData = OCImage.FrameData0; | |
335 } | |
336 else | |
337 { | |
338 OCImage.CurrentFrameData = OCImage.FrameData1; | |
339 } | |
340 } | |
341 |