comparison src/video/photon/SDL_ph_video.c @ 320:66f815c147ed

Date: Thu, 28 Mar 2002 09:20:03 +0200 From: "Mike Gorchak" <mike@malva.ua> Subject: New QNX patch. Hi ! 1. Removed warning (possible bug) with invalid type, passing to the function in ph_WarpedMotion. 2. Rewritten handler of Ph_WM_RESIZE message, now works, but buggy (old handler doesn't work at all). 3. Added stub handler for Ph_WM_MAX (maximize) message. 4. Added more #ifdef HAVE_OPENGL to disable OpenGL stuff when it not needed. 5. Added support for SDL_NOFRAME and SDL_RESIZABLE flags (in OpenGL windows too). 6. Added cosmetic changes, if no SDL_RESIZABLE flag defined, disable resize handlers in window border and maximize button at caption. 7. Fixed my bug with invalid arguments count passed to PtCreateWidget call. 8. Fixed some palette problems. 9. Updated README.QNX file. And I changed testgl.c test application: 10. Added in testgl.c application support for SDL_NOFRAME flag and option -noframe.
author Sam Lantinga <slouken@libsdl.org>
date Thu, 28 Mar 2002 16:20:10 +0000
parents 3333b6e68289
children ba72f259bc88
comparison
equal deleted inserted replaced
319:189a6a3416c7 320:66f815c147ed
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 int i;
179 unsigned long *tempptr;
180 int rtnval;
181 PgVideoModeInfo_t my_mode_info; 178 PgVideoModeInfo_t my_mode_info;
182 PgHWCaps_t my_hwcaps; 179 PgHWCaps_t my_hwcaps;
183 180
184 window=NULL; 181 window=NULL;
182 desktoppal=SDLPH_PAL_NONE;
183 #ifdef HAVE_OPENGL
185 oglctx=NULL; 184 oglctx=NULL;
186 desktoppal=SDLPH_PAL_NONE; 185 #endif /* HAVE_OPENGL */
187 186
188 captionflag=0; 187 captionflag=0;
189 old_video_mode=-1; 188 old_video_mode=-1;
190 old_refresh_rate=-1; 189 old_refresh_rate=-1;
191 190
216 215
217 /* We need to return BytesPerPixel as it in used by CreateRGBsurface */ 216 /* We need to return BytesPerPixel as it in used by CreateRGBsurface */
218 vformat->BitsPerPixel = my_mode_info.bits_per_pixel; 217 vformat->BitsPerPixel = my_mode_info.bits_per_pixel;
219 vformat->BytesPerPixel = my_mode_info.bytes_per_scanline/my_mode_info.width; 218 vformat->BytesPerPixel = my_mode_info.bytes_per_scanline/my_mode_info.width;
220 desktopbpp = my_mode_info.bits_per_pixel; 219 desktopbpp = my_mode_info.bits_per_pixel;
220
221 /* save current palette */
222 if (desktopbpp==8)
223 {
224 PgGetPalette(ph_palette);
225 }
221 226
222 /* return a palette if we are in 256 color mode */
223 if (vformat->BitsPerPixel == 8)
224 {
225 vformat->palette = malloc(sizeof(SDL_Palette));
226 memset(vformat->palette, 0, sizeof(SDL_Palette));
227 vformat->palette->ncolors = 256;
228 vformat->palette->colors = (SDL_Color *)malloc(256 *sizeof(SDL_Color));
229
230 /* fill the palette */
231 rtnval = PgGetPalette(ph_palette);
232 if (rtnval < 0)
233 {
234 fprintf(stderr, "ph_VideoInit: PgGetPalette failed\n");
235 }
236
237 tempptr = (unsigned long *)vformat->palette->colors;
238
239 for(i=0;i<256; i++)
240 {
241 *tempptr = (((unsigned long)ph_palette[i]) << 8);
242 tempptr++;
243 }
244 }
245
246 currently_fullscreen = 0; 227 currently_fullscreen = 0;
247 228
248 this->info.wm_available = 1; 229 this->info.wm_available = 1;
249 230
250 return 0; 231 return 0;
266 dim.h=height; 247 dim.h=height;
267 248
268 /* Lock the event thread, in multi-threading environments */ 249 /* Lock the event thread, in multi-threading environments */
269 SDL_Lock_EventThread(); 250 SDL_Lock_EventThread();
270 251
252 current->flags = flags;
253
271 /* create window if no OpenGL support selected */ 254 /* create window if no OpenGL support selected */
272 if ((flags & SDL_OPENGL)!=SDL_OPENGL) 255 if ((flags & SDL_OPENGL)!=SDL_OPENGL)
273 { 256 {
274 pargc=0; 257 pargc=0;
275 258
276 PtSetArg(&arg[pargc++], Pt_ARG_DIM, &dim, 0); 259 PtSetArg(&arg[pargc++], Pt_ARG_DIM, &dim, 0);
277 PtSetArg(&arg[pargc++], Pt_ARG_RESIZE_FLAGS, Pt_FALSE, Pt_RESIZE_XY_AS_REQUIRED); 260 PtSetArg(&arg[pargc++], Pt_ARG_RESIZE_FLAGS, Pt_FALSE, Pt_RESIZE_XY_AS_REQUIRED);
261
262 /* enable window minimizing */
263 PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE, Ph_WM_HIDE);
264
265 /* remove border and caption if no frame flag selected */
266 if ((flags & SDL_NOFRAME) == SDL_NOFRAME)
267 {
268 PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, Ph_WM_RENDER_TITLE | Ph_WM_RENDER_BORDER);
269 }
270 else
271 {
272 PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, Ph_WM_RENDER_TITLE | Ph_WM_RENDER_BORDER);
273 }
274
275 /* if window is not resizable then remove resize handles and maximize button */
276 if ((flags & SDL_RESIZABLE) != SDL_RESIZABLE)
277 {
278 PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX);
279 PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, Ph_WM_RESIZE | Ph_WM_MAX);
280 PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_FALSE, Ph_WM_RESIZE | Ph_WM_MAX);
281 }
282 else
283 {
284 PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX);
285 /* it is need to be Pt_FALSE to allow the application to process the resize callback */
286 PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, Ph_WM_RESIZE | Ph_WM_MAX);
287 PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE, Ph_WM_RESIZE | Ph_WM_MAX);
288 }
278 289
279 if (window!=NULL) 290 if (window!=NULL)
280 { 291 {
281 PtUnrealizeWidget(window); 292 PtUnrealizeWidget(window);
282 PtDestroyWidget(window); 293 PtDestroyWidget(window);
283 window=NULL; 294 window=NULL;
284 } 295 }
285 296
286 window=PtCreateWidget(PtWindow, NULL, pargc-1, arg); 297 window=PtCreateWidget(PtWindow, NULL, pargc, arg);
287 PtRealizeWidget(window); 298 PtRealizeWidget(window);
288 299
289 PtFlush(); 300 PtFlush();
290 } 301 }
291 302
293 if (flags & SDL_OPENGL) 304 if (flags & SDL_OPENGL)
294 { 305 {
295 /* ph_SetupOpenGLContext creates also window as need */ 306 /* ph_SetupOpenGLContext creates also window as need */
296 if (ph_SetupOpenGLContext(this, width, height, bpp, flags)==0) 307 if (ph_SetupOpenGLContext(this, width, height, bpp, flags)==0)
297 { 308 {
298 current->flags=flags;
299 /* setup OGL update function ... ugly method */ 309 /* setup OGL update function ... ugly method */
300 ph_ResizeImage(this, current, flags); 310 ph_ResizeImage(this, current, flags);
301 } 311 }
302 else 312 else
303 { 313 {
361 ph_EnterFullScreen(this); 371 ph_EnterFullScreen(this);
362 372
363 } /* end fullscreen flag */ 373 } /* end fullscreen flag */
364 else 374 else
365 { 375 {
366 if (flags & SDL_HWSURFACE) /* Use offscreen memory iff SDL_HWSURFACE flag is set */ 376 /* Use offscreen memory iff SDL_HWSURFACE flag is set */
367 { 377 if (flags & SDL_HWSURFACE)
368 /* Hardware surface is Offsceen Context. ph_ResizeImage handles the switch */ 378 {
369 current->flags = (flags & (~SDL_RESIZABLE)); /* no stretch blit in offscreen context */ 379 /* no stretch blit in offscreen context */
370 } 380 current->flags = (flags & (~SDL_RESIZABLE));
371 else /* must be SDL_SWSURFACE */ 381 }
372 { 382
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 */ 383 /* using palette emulation code in window mode */
376 if (bpp==8) 384 if (bpp==8)
377 { 385 {
378 if (desktopbpp>=15) 386 if (desktopbpp>=15)
379 { 387 {
423 if (captionflag) 431 if (captionflag)
424 { 432 {
425 ph_SetCaption(this, this->wm_title, NULL); 433 ph_SetCaption(this, this->wm_title, NULL);
426 } 434 }
427 435
436 /* finish window drawing */
437 PtFlush();
438
428 SDL_Unlock_EventThread(); 439 SDL_Unlock_EventThread();
429 440
430 /* We're done! */ 441 /* We're done! */
431 return (current); 442 return (current);
432 } 443 }
433 444
434 static void ph_VideoQuit(_THIS) 445 static void ph_VideoQuit(_THIS)
435 { 446 {
447 #ifdef HAVE_OPENGL
436 PhRegion_t region_info; 448 PhRegion_t region_info;
449 #endif /* HAVE_OPENGL */
437 450
438 ph_DestroyImage(this, SDL_VideoSurface); 451 ph_DestroyImage(this, SDL_VideoSurface);
439 452
440 if (currently_fullscreen) 453 if (currently_fullscreen)
441 { 454 {
442 ph_LeaveFullScreen(this); 455 ph_LeaveFullScreen(this);
443 } 456 }
444 457
445 #ifdef HAVE_OPENGL 458 #ifdef HAVE_OPENGL
446 /* prevent double SEGFAULT with parachute mode */ 459 /* prevent double SEGFAULT during parachute mode */
447 if (this->screen) 460 if (this->screen)
448 { 461 {
449 if (((this->screen->flags & SDL_FULLSCREEN)==SDL_FULLSCREEN) && 462 if (((this->screen->flags & SDL_FULLSCREEN)==SDL_FULLSCREEN) &&
450 ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL)) 463 ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL))
451 { 464 {
516 } 529 }
517 530
518 if ((this->screen->flags & SDL_FULLSCREEN) != SDL_FULLSCREEN) 531 if ((this->screen->flags & SDL_FULLSCREEN) != SDL_FULLSCREEN)
519 { 532 {
520 /* window mode must use soft palette */ 533 /* window mode must use soft palette */
521 PgSetPalette((PgColor_t*)&syspalph, 0, firstcolor, ncolors, Pg_PALSET_SOFT, 0); 534 PgSetPalette((PgColor_t*)&syspalph[firstcolor], 0, firstcolor, ncolors, Pg_PALSET_SOFT, 0);
522 /* image needs to be redrawed, very slow method */ 535 /* image needs to be redrawed, very slow method */
523 PgDrawPhImage(&point, SDL_Image, 0); 536 PgDrawPhImage(&point, SDL_Image, 0);
524 } 537 }
525 else 538 else
526 { 539 {
527 /* fullscreen mode must use hardware palette */ 540 /* fullscreen mode must use hardware palette */
528 PgSetPalette((PgColor_t*)&syspalph, 0, firstcolor, ncolors, Pg_PALSET_GLOBAL, 0); 541 PgSetPalette((PgColor_t*)&syspalph[firstcolor], 0, firstcolor, ncolors, Pg_PALSET_GLOBAL, 0);
529 } 542 }
530 } 543 }
531 else 544 else
532 { 545 {
533 /* SDLPH_PAL_NONE do nothing */ 546 /* SDLPH_PAL_NONE do nothing */
584 } 597 }
585 else 598 else
586 { 599 {
587 oglctx=PdCreateOpenGLContext(1, &dim, 0, OGLAttrib); 600 oglctx=PdCreateOpenGLContext(1, &dim, 0, OGLAttrib);
588 } 601 }
602
589 if (oglctx==NULL) 603 if (oglctx==NULL)
590 { 604 {
591 fprintf(stderr,"error: cannot create OpenGL context.\n"); 605 fprintf(stderr,"ph_SetupOpenGLContext: cannot create OpenGL context.\n");
592 return (-1); 606 return (-1);
593 } 607 }
594 608
595 PhDCSetCurrent(oglctx); 609 PhDCSetCurrent(oglctx);
596 610
606 620
607 pos.x=0; 621 pos.x=0;
608 pos.y=0; 622 pos.y=0;
609 623
610 PtSetArg(&args[pargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, ~0); 624 PtSetArg(&args[pargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, ~0);
611 PtSetArg(&args[pargc++], Pt_ARG_WINDOW_MANAGED_FLAGS,Pt_TRUE, Ph_WM_FFRONT | Ph_WM_CLOSE | Ph_WM_TOFRONT | Ph_WM_CONSWITCH); 625 PtSetArg(&args[pargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE, Ph_WM_FFRONT | Ph_WM_CLOSE | Ph_WM_TOFRONT | Ph_WM_CONSWITCH);
612 PtSetArg(&args[pargc++], Pt_ARG_WINDOW_STATE, Pt_TRUE, Ph_WM_STATE_ISFRONT | Ph_WM_STATE_ISFOCUS); 626 PtSetArg(&args[pargc++], Pt_ARG_WINDOW_STATE, Pt_TRUE, Ph_WM_STATE_ISFRONT | Ph_WM_STATE_ISFOCUS);
613 PtSetArg(&args[pargc++], Pt_ARG_POS, &pos, 0); 627 PtSetArg(&args[pargc++], Pt_ARG_POS, &pos, 0);
628 }
629 else
630 {
631 /* remove border and caption if no frame flag selected */
632 if ((flags & SDL_NOFRAME) == SDL_NOFRAME)
633 {
634 PtSetArg(&args[pargc++], Pt_ARG_WINDOW_RENDER_FLAGS, 0, Ph_WM_RENDER_TITLE | Ph_WM_RENDER_BORDER);
635 }
636 else
637 {
638 /* if window is not resizable then remove resize handles */
639 if ((flags & SDL_RESIZABLE) != SDL_RESIZABLE)
640 {
641 PtSetArg(&args[pargc++], Pt_ARG_WINDOW_RENDER_FLAGS, 0, Ph_WM_RENDER_RESIZE);
642 }
643 }
614 } 644 }
615 645
616 if (window!=NULL) 646 if (window!=NULL)
617 { 647 {
618 PtUnrealizeWidget(window); 648 PtUnrealizeWidget(window);
619 PtDestroyWidget(window); 649 PtDestroyWidget(window);
620 window=NULL; 650 window=NULL;
621 } 651 }
622 652
623 window=PtCreateWidget(PtWindow, NULL, pargc-1, args); 653 window=PtCreateWidget(PtWindow, NULL, pargc, args);
624 PtRealizeWidget(window); 654 PtRealizeWidget(window);
625 655
626 /* disable mouse for fullscreen */ 656 /* disable mouse for fullscreen */
627 if (flags & SDL_FULLSCREEN) 657 if (flags & SDL_FULLSCREEN)
628 { 658 {