comparison src/video/photon/SDL_ph_video.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 2de77f7b7a28
children 66f815c147ed
comparison
equal deleted inserted replaced
314:bff64eba7721 315:3333b6e68289
148 148
149 return device; 149 return device;
150 } 150 }
151 151
152 VideoBootStrap ph_bootstrap = { 152 VideoBootStrap ph_bootstrap = {
153 "photon", "QNX Photon video output", 153 "photon", "QNX Photon video output",
154 ph_Available, ph_CreateDevice 154 ph_Available, ph_CreateDevice
155 }; 155 };
156 156
157 static void ph_DeleteDevice(SDL_VideoDevice *device) 157 static void ph_DeleteDevice(SDL_VideoDevice *device)
158 { 158 {
159 if (device) 159 if (device)
173 } 173 }
174 } 174 }
175 175
176 static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat) 176 static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat)
177 { 177 {
178 PgColor_t ph_palette[_Pg_MAX_PALETTE];
179 int i; 178 int i;
180 unsigned long *tempptr; 179 unsigned long *tempptr;
181 int rtnval; 180 int rtnval;
182 PgVideoModeInfo_t my_mode_info; 181 PgVideoModeInfo_t my_mode_info;
183 PgHWCaps_t my_hwcaps; 182 PgHWCaps_t my_hwcaps;
184 183
185 window=NULL; 184 window=NULL;
186 oglctx=NULL; 185 oglctx=NULL;
186 desktoppal=SDLPH_PAL_NONE;
187
188 captionflag=0;
189 old_video_mode=-1;
190 old_refresh_rate=-1;
187 191
188 if (NULL == (event = malloc(EVENT_SIZE))) 192 if (NULL == (event = malloc(EVENT_SIZE)))
189 { 193 {
190 exit(EXIT_FAILURE); 194 exit(EXIT_FAILURE);
191 } 195 }
211 } 215 }
212 216
213 /* We need to return BytesPerPixel as it in used by CreateRGBsurface */ 217 /* We need to return BytesPerPixel as it in used by CreateRGBsurface */
214 vformat->BitsPerPixel = my_mode_info.bits_per_pixel; 218 vformat->BitsPerPixel = my_mode_info.bits_per_pixel;
215 vformat->BytesPerPixel = my_mode_info.bytes_per_scanline/my_mode_info.width; 219 vformat->BytesPerPixel = my_mode_info.bytes_per_scanline/my_mode_info.width;
220 desktopbpp = my_mode_info.bits_per_pixel;
216 221
217 /* return a palette if we are in 256 color mode */ 222 /* return a palette if we are in 256 color mode */
218 if (vformat->BitsPerPixel == 8) 223 if (vformat->BitsPerPixel == 8)
219 { 224 {
220 vformat->palette = malloc(sizeof(SDL_Palette)); 225 vformat->palette = malloc(sizeof(SDL_Palette));
251 PgDisplaySettings_t settings; 256 PgDisplaySettings_t settings;
252 int mode; 257 int mode;
253 PtArg_t arg[32]; 258 PtArg_t arg[32];
254 PhDim_t dim; 259 PhDim_t dim;
255 int rtnval; 260 int rtnval;
256 PgColor_t ph_palette[_Pg_MAX_PALETTE];
257 int i; 261 int i;
258 unsigned long *tempptr; 262 unsigned long *tempptr;
259 int pargc; 263 int pargc;
260 264
261 dim.w=width; 265 dim.w=width;
279 window=NULL; 283 window=NULL;
280 } 284 }
281 285
282 window=PtCreateWidget(PtWindow, NULL, pargc-1, arg); 286 window=PtCreateWidget(PtWindow, NULL, pargc-1, arg);
283 PtRealizeWidget(window); 287 PtRealizeWidget(window);
284 288
285 PtFlush(); 289 PtFlush();
286 } 290 }
287 291
288 #ifdef HAVE_OPENGL 292 #ifdef HAVE_OPENGL
289 if (flags & SDL_OPENGL) 293 if (flags & SDL_OPENGL)
328 { 332 {
329 fprintf(stderr,"error: get_mode failed\n"); 333 fprintf(stderr,"error: get_mode failed\n");
330 exit(1); 334 exit(1);
331 } 335 }
332 } 336 }
337
338 if (bpp==8)
339 {
340 desktoppal=SDLPH_PAL_SYSTEM;
341 }
342
343 /* save old video mode caps */
344 PgGetVideoMode(&settings);
345 old_video_mode=settings.mode;
346 old_refresh_rate=settings.refresh;
347
348 /* setup new video mode */
333 settings.mode = mode; 349 settings.mode = mode;
334 settings.refresh = 0; 350 settings.refresh = 0;
335 settings.flags = 0; 351 settings.flags = 0;
336 352
337 if (PgSetVideoMode( &settings ) < 0) 353 if (PgSetVideoMode(&settings) < 0)
338 { 354 {
339 fprintf(stderr,"error: PgSetVideoMode failed\n"); 355 fprintf(stderr,"error: PgSetVideoMode failed\n");
340 } 356 }
341 357
342 /* Get the true height and width */
343
344 current->flags = (flags & (~SDL_RESIZABLE)); /* no resize for Direct Context */ 358 current->flags = (flags & (~SDL_RESIZABLE)); /* no resize for Direct Context */
345 359
346 /* Begin direct mode */ 360 /* Begin direct mode */
347
348 ph_EnterFullScreen(this); 361 ph_EnterFullScreen(this);
349 362
350 } /* end fullscreen flag */ 363 } /* end fullscreen flag */
351 else 364 else
352 { 365 {
356 current->flags = (flags & (~SDL_RESIZABLE)); /* no stretch blit in offscreen context */ 369 current->flags = (flags & (~SDL_RESIZABLE)); /* no stretch blit in offscreen context */
357 } 370 }
358 else /* must be SDL_SWSURFACE */ 371 else /* must be SDL_SWSURFACE */
359 { 372 {
360 current->flags = (flags | SDL_RESIZABLE); /* yes we can resize as this is a software surface */ 373 current->flags = (flags | SDL_RESIZABLE); /* yes we can resize as this is a software surface */
374 }
375 /* using palette emulation code in window mode */
376 if (bpp==8)
377 {
378 if (desktopbpp>=15)
379 {
380 desktoppal=SDLPH_PAL_EMULATE;
381 }
382 else
383 {
384 desktoppal=SDLPH_PAL_SYSTEM;
385 }
386 }
387 else
388 {
389 desktoppal=SDLPH_PAL_NONE;
361 } 390 }
362 } 391 }
363 392
364 /* If we are setting video to use the palette make sure we have allocated memory for it */ 393 /* If we are setting video to use the palette make sure we have allocated memory for it */
365 if (bpp==8) 394 if (bpp==8)
388 current->format->BytesPerPixel = (bpp+7)/8; 417 current->format->BytesPerPixel = (bpp+7)/8;
389 current->pitch = SDL_CalculatePitch(current); 418 current->pitch = SDL_CalculatePitch(current);
390 /* Must call at least once it setup image planes */ 419 /* Must call at least once it setup image planes */
391 ph_ResizeImage(this, current, flags); 420 ph_ResizeImage(this, current, flags);
392 421
422 /* delayed set caption call */
423 if (captionflag)
424 {
425 ph_SetCaption(this, this->wm_title, NULL);
426 }
427
393 SDL_Unlock_EventThread(); 428 SDL_Unlock_EventThread();
394 429
395 /* We're done! */ 430 /* We're done! */
396 return(current); 431 return (current);
397 } 432 }
398 433
399 static void ph_VideoQuit(_THIS) 434 static void ph_VideoQuit(_THIS)
400 { 435 {
401 PhRegion_t region_info; 436 PhRegion_t region_info;
402 437
403 ph_DestroyImage(this, SDL_VideoSurface); 438 ph_DestroyImage(this, SDL_VideoSurface);
404 439
405 if (currently_fullscreen) 440 if (currently_fullscreen)
406 { 441 {
407 PdDirectStop(directContext); 442 ph_LeaveFullScreen(this);
408 PdReleaseDirectContext(directContext);
409 directContext=0;
410 currently_fullscreen=0;
411 } 443 }
412 444
413 #ifdef HAVE_OPENGL 445 #ifdef HAVE_OPENGL
414 if (((this->screen->flags & SDL_FULLSCREEN)==SDL_FULLSCREEN) && 446 /* prevent double SEGFAULT with parachute mode */
415 ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL)) 447 if (this->screen)
416 { 448 {
417 region_info.cursor_type=Ph_CURSOR_POINTER; 449 if (((this->screen->flags & SDL_FULLSCREEN)==SDL_FULLSCREEN) &&
418 region_info.rid=PtWidgetRid(window); 450 ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL))
419 PhRegionChange(Ph_REGION_CURSOR, 0, &region_info, NULL, NULL); 451 {
452 region_info.cursor_type=Ph_CURSOR_POINTER;
453 region_info.rid=PtWidgetRid(window);
454 PhRegionChange(Ph_REGION_CURSOR, 0, &region_info, NULL, NULL);
455 }
420 } 456 }
421 457
422 PtFlush(); 458 PtFlush();
423 #endif /* HAVE_OPENGL */ 459 #endif /* HAVE_OPENGL */
424 460
426 { 462 {
427 PtUnrealizeWidget(window); 463 PtUnrealizeWidget(window);
428 PtDestroyWidget(window); 464 PtDestroyWidget(window);
429 window=NULL; 465 window=NULL;
430 } 466 }
467
468 /* restore palette */
469 if (desktoppal!=SDLPH_PAL_NONE)
470 {
471 PgSetPalette(ph_palette, 0, 0, _Pg_MAX_PALETTE, Pg_PALSET_GLOBAL | Pg_PALSET_FORCE_EXPOSE, 0);
472 }
431 473
432 #ifdef HAVE_OPENGL 474 #ifdef HAVE_OPENGL
433 if (oglctx) 475 if (oglctx)
434 { 476 {
435 PhDCSetCurrent(NULL); 477 PhDCSetCurrent(NULL);
439 #endif /* HAVE_OPENGL */ 481 #endif /* HAVE_OPENGL */
440 } 482 }
441 483
442 static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) 484 static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
443 { 485 {
444 PgColor_t *in, *out; 486 int i;
445 int i, j; 487 PhPoint_t point={0, 0};
446 int alloct_all = 1; 488 PgColor_t syspalph[_Pg_MAX_PALETTE];
447 489
448 colors = this->screen->format->palette->colors; 490 /* palette emulation code, using palette of the PhImage_t struct */
449 491 if (desktoppal==SDLPH_PAL_EMULATE)
450 in = alloca( ncolors*sizeof(PgColor_t) ); 492 {
451 if ( in == NULL ) { 493 if ((SDL_Image) && (SDL_Image->palette))
452 return 0; 494 {
453 } 495 for (i=firstcolor; i<firstcolor+ncolors; i++)
454 memset(in,0,ncolors*sizeof(PgColor_t)); 496 {
455 497 SDL_Image->palette[i] = 0x00000000UL;
456 out = alloca( ncolors*sizeof(PgColor_t) ); 498 SDL_Image->palette[i] |= colors[i-firstcolor].r<<16;
457 if ( out == NULL ) { 499 SDL_Image->palette[i] |= colors[i-firstcolor].g<<8;
458 return 0; 500 SDL_Image->palette[i] |= colors[i-firstcolor].b;
459 } 501 }
460 502 }
461 for (i=0,j=firstcolor;i<ncolors;i++,j++) 503 /* image needs to be redrawed, very slow method */
462 { 504 PgDrawPhImage(&point, SDL_Image, 0);
463 in[i] |= colors[j].r<<16 ; 505 }
464 in[i] |= colors[j].g<<8 ; 506 else
465 in[i] |= colors[j].b ; 507 {
466 } 508 if (desktoppal==SDLPH_PAL_SYSTEM)
467 509 {
468 if ( (this->screen->flags & SDL_HWPALETTE) == SDL_HWPALETTE ) 510 for (i=firstcolor; i<firstcolor+ncolors; i++)
469 { 511 {
470 if( PgSetPalette( in, 0, 0, ncolors, Pg_PALSET_HARD, 0) < 0 ) 512 syspalph[i] = 0x00000000UL;
471 { 513 syspalph[i] |= colors[i-firstcolor].r<<16;
472 fprintf(stderr,"error: PgSetPalette(..,Pg_PALSET_HARD) failed\n"); 514 syspalph[i] |= colors[i-firstcolor].g<<8;
473 return 0; 515 syspalph[i] |= colors[i-firstcolor].b;
474 } 516 }
475 } 517
476 else 518 if ((this->screen->flags & SDL_FULLSCREEN) != SDL_FULLSCREEN)
477 { 519 {
478 if ( PgColorMatch(ncolors, in, out) < 0 ) 520 /* window mode must use soft palette */
479 { 521 PgSetPalette((PgColor_t*)&syspalph, 0, firstcolor, ncolors, Pg_PALSET_SOFT, 0);
480 fprintf(stderr,"error: PgColorMatch failed\n"); 522 /* image needs to be redrawed, very slow method */
481 return 0; 523 PgDrawPhImage(&point, SDL_Image, 0);
482 } 524 }
483 for (i=0;i<ncolors;i++) 525 else
484 { 526 {
485 if (memcmp(&in[i],&out[i],sizeof(PgColor_t))) 527 /* fullscreen mode must use hardware palette */
486 { 528 PgSetPalette((PgColor_t*)&syspalph, 0, firstcolor, ncolors, Pg_PALSET_GLOBAL, 0);
487 alloct_all = 0; 529 }
488 break; 530 }
489 } 531 else
490 } 532 {
491 if( PgSetPalette( out, 0, 0, ncolors, Pg_PALSET_SOFT, 0) < 0 ) 533 /* SDLPH_PAL_NONE do nothing */
492 { 534 }
493 fprintf(stderr,"error: PgSetPalette(..,Pg_PALSET_SOFT) failed\n"); 535 }
494 return 0; 536
495 } 537 return 1;
496 }
497 return alloct_all;
498 } 538 }
499 539
500 #ifdef HAVE_OPENGL 540 #ifdef HAVE_OPENGL
501 541
502 int ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags) 542 int ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags)