comparison src/video/photon/SDL_ph_image.c @ 315:3333b6e68289

Date: Sat, 23 Mar 2002 13:53:37 +0200 From: "Mike Gorchak" <mike@malva.ua> Subject: Big QNX patch again. Added 8bit palette emulation code for window mode with bpp>=15. Added store/restore original palette for 8bit modes. Added more information about photon API call fails. Rewroten change palette code, slow but works. Fixed bug with set caption before window was inited. Fixed bugs with some initial state of variables. Fixed bug with storing old video mode settings. Fixed bug with switching to fullscreen mode and back. Fixed few double SEGFAULTS during parachute mode. Removed compilation warning with no PgWaitHWIdle prototype. Removed pack of dead unusable code. Cleanups SDL_PrivateVideoData structure, some headers. Some code formatting.
author Sam Lantinga <slouken@libsdl.org>
date Sat, 23 Mar 2002 20:19:44 +0000
parents f6ffac90895c
children ba72f259bc88
comparison
equal deleted inserted replaced
314:bff64eba7721 315:3333b6e68289
31 31
32 #include "SDL_error.h" 32 #include "SDL_error.h"
33 #include "SDL_endian.h" 33 #include "SDL_endian.h"
34 #include "SDL_ph_image_c.h" 34 #include "SDL_ph_image_c.h"
35 35
36 /* remove this line, if photon headers updates */
37 int PgWaitHWIdle(void);
38
36 int ph_SetupImage(_THIS, SDL_Surface *screen) 39 int ph_SetupImage(_THIS, SDL_Surface *screen)
37 { 40 {
38 int type = 0; 41 int type=0;
42 PgColor_t* palette=NULL;
39 43
40 /* Determine image type */ 44 /* Determine image type */
41 switch(screen->format->BitsPerPixel) 45 switch(screen->format->BitsPerPixel)
42 { 46 {
43 case 8:{ 47 case 8:{
67 return -1; 71 return -1;
68 } 72 }
69 break; 73 break;
70 } 74 }
71 75
72 /* using shared memory for speed (set last param to 1) */ 76 /* palette emulation code */
73 if ((SDL_Image = PhCreateImage(NULL, screen->w, screen->h, type, NULL, 0, 1)) == NULL) 77 if ((screen->format->BitsPerPixel==8) && (desktoppal==SDLPH_PAL_EMULATE))
74 { 78 {
75 fprintf(stderr,"error: PhCreateImage failed.\n"); 79 /* creating image palette */
76 return -1; 80 palette=malloc(_Pg_MAX_PALETTE*sizeof(PgColor_t));
81 PgGetPalette(palette);
82
83 /* using shared memory for speed (set last param to 1) */
84 if ((SDL_Image = PhCreateImage(NULL, screen->w, screen->h, type, palette, _Pg_MAX_PALETTE, 1)) == NULL)
85 {
86 fprintf(stderr,"ph_SetupImage: PhCreateImage failed for bpp=8.\n");
87 return -1;
88 }
89 }
90 else
91 {
92 /* using shared memory for speed (set last param to 1) */
93 if ((SDL_Image = PhCreateImage(NULL, screen->w, screen->h, type, NULL, 0, 1)) == NULL)
94 {
95 fprintf(stderr,"ph_SetupImage: PhCreateImage failed.\n");
96 return -1;
97 }
77 } 98 }
78 99
79 screen->pixels = SDL_Image->image; 100 screen->pixels = SDL_Image->image;
80 101
81 this->UpdateRects = ph_NormalUpdate; 102 this->UpdateRects = ph_NormalUpdate;
82 103
83 return 0; 104 return 0;
84 } 105 }
85 106
86 int ph_SetupOCImage(_THIS, SDL_Surface *screen) //Offscreen context 107 int ph_SetupOCImage(_THIS, SDL_Surface *screen)
87 { 108 {
88 int type = 0; 109 int type = 0;
89 110
90 /* Determine image type */ 111 /* Determine image type */
91 switch(screen->format->BitsPerPixel) 112 switch(screen->format->BitsPerPixel)
183 OCImage.FrameData1 = NULL; 204 OCImage.FrameData1 = NULL;
184 } 205 }
185 206
186 if (SDL_Image) 207 if (SDL_Image)
187 { 208 {
209 /* if palette allocated, free it */
210 if (SDL_Image->palette)
211 {
212 free(SDL_Image->palette);
213 }
188 PgShmemDestroy(SDL_Image->image); 214 PgShmemDestroy(SDL_Image->image);
189 free(SDL_Image); 215 free(SDL_Image);
190 SDL_Image = NULL; 216 }
191 } 217
218 /* Must be zeroed everytime */
219 SDL_Image = NULL;
192 220
193 if (screen) 221 if (screen)
194 { 222 {
195 screen->pixels = NULL; 223 screen->pixels = NULL;
196 } 224 }
198 226
199 int ph_ResizeImage(_THIS, SDL_Surface *screen, Uint32 flags) 227 int ph_ResizeImage(_THIS, SDL_Surface *screen, Uint32 flags)
200 { 228 {
201 ph_DestroyImage(this, screen); 229 ph_DestroyImage(this, screen);
202 230
203 if( flags & SDL_HWSURFACE) 231 if (flags & SDL_HWSURFACE)
204 { 232 {
205 OCImage.flags = flags; /* needed for SDL_DOUBLEBUF check */ 233 OCImage.flags = flags; /* needed for SDL_DOUBLEBUF check */
206 return ph_SetupOCImage(this, screen); 234 return ph_SetupOCImage(this, screen);
207 } 235 }
208 else if(flags & SDL_OPENGL) 236 else if (flags & SDL_OPENGL)
209 { 237 {
210 return ph_SetupOpenGLImage(this, screen); 238 return ph_SetupOpenGLImage(this, screen);
211 } 239 }
212 else 240 else
213 { 241 {
214 return ph_SetupImage(this, screen); 242 return ph_SetupImage(this, screen);
215 } 243 }
216 } 244 }
217 245
218 int ph_AllocHWSurface(_THIS, SDL_Surface *surface) 246 int ph_AllocHWSurface(_THIS, SDL_Surface *surface)
219 { 247 {
220 return(-1); 248 return(-1);
221 } 249 }
222 250
223 void ph_FreeHWSurface(_THIS, SDL_Surface *surface) 251 void ph_FreeHWSurface(_THIS, SDL_Surface *surface)
224 { 252 {
225 return; 253 return;
226 } 254 }
227 255
228 int ph_FlipHWSurface(_THIS, SDL_Surface *surface) 256 int ph_FlipHWSurface(_THIS, SDL_Surface *surface)
229 { 257 {
230 return(0); 258 return(0);
231 } 259 }
232 260
233 int ph_LockHWSurface(_THIS, SDL_Surface *surface) 261 int ph_LockHWSurface(_THIS, SDL_Surface *surface)
234 { 262 {
235 if ( (surface == SDL_VideoSurface) && blit_queued ) { 263 if ((surface == SDL_VideoSurface) && blit_queued) {
236 // XSync(GFX_Display, False); 264 PgFlush();
237 PgFlush(); 265 blit_queued = 0;
238 blit_queued = 0; 266 }
239 } 267
240 return(0); 268 return(0);
241 } 269 }
242 270
243 void ph_UnlockHWSurface(_THIS, SDL_Surface *surface) 271 void ph_UnlockHWSurface(_THIS, SDL_Surface *surface)
244 { 272 {
245 return; 273 return;
246 } 274 }
247 275
248 static PhPoint_t ph_pos; 276 static PhPoint_t ph_pos;
249 static PhRect_t ph_rect; 277 static PhRect_t ph_rect;
250 static int i; 278 static int i;
256 return; 284 return;
257 } 285 }
258 286
259 void ph_NormalUpdate(_THIS, int numrects, SDL_Rect *rects) 287 void ph_NormalUpdate(_THIS, int numrects, SDL_Rect *rects)
260 { 288 {
261
262 for ( i=0; i<numrects; ++i ) 289 for ( i=0; i<numrects; ++i )
263 { 290 {
264 if ( rects[i].w == 0 ) { /* Clipped? */ 291 if (rects[i].w==0) /* Clipped? */
265 continue; 292 {
266 } 293 continue;
267 294 }
268 ph_pos.x = rects[i].x; 295
269 ph_pos.y = rects[i].y; 296 ph_pos.x = rects[i].x;
270 ph_rect.ul.x = rects[i].x; 297 ph_pos.y = rects[i].y;
271 ph_rect.ul.y = rects[i].y; 298 ph_rect.ul.x = rects[i].x;
272 ph_rect.lr.x = rects[i].x + rects[i].w; 299 ph_rect.ul.y = rects[i].y;
273 ph_rect.lr.y = rects[i].y + rects[i].h; 300 ph_rect.lr.x = rects[i].x + rects[i].w;
274 301 ph_rect.lr.y = rects[i].y + rects[i].h;
275 if (PgDrawPhImageRectmx( &ph_pos, SDL_Image, &ph_rect, 0 ) < 0) 302
276 { 303 if (PgDrawPhImageRectmx(&ph_pos, SDL_Image, &ph_rect, 0) < 0)
277 fprintf(stderr,"error: PgDrawPhImageRectmx failed.\n"); 304 {
278 } 305 fprintf(stderr,"ph_NormalUpdate: PgDrawPhImageRectmx failed.\n");
279 } 306 }
307 }
308
280 if (PgFlush() < 0) 309 if (PgFlush() < 0)
281 { 310 {
282 fprintf(stderr,"error: PgFlush failed.\n"); 311 fprintf(stderr,"ph_NormalUpdate: PgFlush failed.\n");
283 } 312 }
284 } 313 }
285 void ph_OCUpdate(_THIS, int numrects, SDL_Rect *rects) 314 void ph_OCUpdate(_THIS, int numrects, SDL_Rect *rects)
286 { 315 {
287 PhPoint_t zero = {0}; 316 PhPoint_t zero = {0};
288 PhRect_t src_rect; 317 PhRect_t src_rect;
289 PhRect_t dest_rect; 318 PhRect_t dest_rect;
290 319
291 if(OCImage.direct_context == NULL) 320 if(OCImage.direct_context == NULL)
292 { 321 {
293 return; 322 return;
294 } 323 }
295 324
296 PgSetRegion(PtWidgetRid(window)); 325 PgSetRegion(PtWidgetRid(window));
297 PgSetClipping(0,NULL); 326 PgSetClipping(0,NULL);
298 PgWaitHWIdle(); 327 PgWaitHWIdle();
299 328
300 329 for (i=0; i<numrects; ++i)
301 for ( i=0; i<numrects; ++i ) 330 {
302 { 331 if (rects[i].w == 0) /* Clipped? */
303 if ( rects[i].w == 0 ) { /* Clipped? */ 332 {
304 continue; 333 continue;
305 } 334 }
306 335
307 src_rect.ul.x=rects[i].x; 336 src_rect.ul.x=rects[i].x;
308 src_rect.ul.y=rects[i].y; 337 src_rect.ul.y=rects[i].y;
309 dest_rect.ul.x=rects[i].x; 338 dest_rect.ul.x=rects[i].x;
310 dest_rect.ul.y=rects[i].y; 339 dest_rect.ul.y=rects[i].y;
311 340
312 dest_rect.lr.x=src_rect.lr.x= rects[i].x +rects[i].w; 341 dest_rect.lr.x=src_rect.lr.x= rects[i].x +rects[i].w;
313 dest_rect.lr.y=src_rect.lr.y= rects[i].y +rects[i].h; 342 dest_rect.lr.y=src_rect.lr.y= rects[i].y +rects[i].h;
314 343
315 zero.x = zero.y = 0; 344 zero.x = zero.y = 0;
316 PgSetTranslation (&zero, 0); 345 PgSetTranslation (&zero, 0);
317 PgSetRegion(PtWidgetRid(window)); 346 PgSetRegion(PtWidgetRid(window));
318 PgSetClipping(0,NULL); 347 PgSetClipping(0,NULL);
319 PgContextBlitArea(OCImage.offscreen_context, (PhArea_t *)(&src_rect), NULL, (PhArea_t *)(&dest_rect)); 348 PgContextBlitArea(OCImage.offscreen_context, (PhArea_t *)(&src_rect), NULL, (PhArea_t *)(&dest_rect));
320 349
321 } 350 }
322 if (PgFlush() < 0) 351 if (PgFlush() < 0)
323 { 352 {
324 fprintf(stderr,"error: PgFlush failed.\n"); 353 fprintf(stderr,"ph_OCUpdate: PgFlush failed.\n");
325 } 354 }
326 355
327 //later used to toggling double buffer 356 /* later used to toggling double buffer */
328 if(OCImage.current == 0) 357 if (OCImage.current == 0)
329 { 358 {
330 OCImage.CurrentFrameData = OCImage.FrameData0; 359 OCImage.CurrentFrameData = OCImage.FrameData0;
331 } 360 }
332 else 361 else
333 { 362 {
334 OCImage.CurrentFrameData = OCImage.FrameData1; 363 OCImage.CurrentFrameData = OCImage.FrameData1;
335 } 364 }
336 } 365 }
337