comparison src/video/photon/SDL_ph_video.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 04351f59b051
comparison
equal deleted inserted replaced
265:35d9c8a5aa10 266:c6abdda2f666
54 static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current, 54 static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current,
55 int width, int height, int bpp, Uint32 flags); 55 int width, int height, int bpp, Uint32 flags);
56 static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors); 56 static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors);
57 static void ph_VideoQuit(_THIS); 57 static void ph_VideoQuit(_THIS);
58 static void ph_DeleteDevice(SDL_VideoDevice *device); 58 static void ph_DeleteDevice(SDL_VideoDevice *device);
59 static void ph_GL_SwapBuffers(_THIS);
60
61 PdOpenGLContext_t* OGLContext=NULL;
59 62
60 static int ph_Available(void) 63 static int ph_Available(void)
61 { 64 {
62
63 return 1; 65 return 1;
64 } 66 }
65 67
66 static SDL_VideoDevice *ph_CreateDevice(int devindex) 68 static SDL_VideoDevice *ph_CreateDevice(int devindex)
67 { 69 {
84 86
85 /* Set the driver flags */ 87 /* Set the driver flags */
86 device->handles_any_size = 1; //JB not true for fullscreen 88 device->handles_any_size = 1; //JB not true for fullscreen
87 89
88 /* Set the function pointers */ 90 /* Set the function pointers */
89 device->CreateYUVOverlay = ph_CreateYUVOverlay; 91 device->CreateYUVOverlay = ph_CreateYUVOverlay;
90 device->VideoInit = ph_VideoInit; 92 device->VideoInit = ph_VideoInit;
91 device->ListModes = ph_ListModes; 93 device->ListModes = ph_ListModes;
92 device->SetVideoMode = ph_SetVideoMode; 94 device->SetVideoMode = ph_SetVideoMode;
93 device->ToggleFullScreen = ph_ToggleFullScreen; 95 device->ToggleFullScreen = ph_ToggleFullScreen;
94 device->UpdateMouse = NULL; 96 device->UpdateMouse = NULL;
115 device->WarpWMCursor = ph_WarpWMCursor; 117 device->WarpWMCursor = ph_WarpWMCursor;
116 device->CheckMouseMode = ph_CheckMouseMode; 118 device->CheckMouseMode = ph_CheckMouseMode;
117 device->InitOSKeymap = ph_InitOSKeymap; 119 device->InitOSKeymap = ph_InitOSKeymap;
118 device->PumpEvents = ph_PumpEvents; 120 device->PumpEvents = ph_PumpEvents;
119 121
122 // OpenGL support.
123 device->GL_LoadLibrary = NULL;
124 device->GL_GetProcAddress = NULL;
125 device->GL_GetAttribute = NULL;
126 device->GL_MakeCurrent = NULL;
127 device->GL_SwapBuffers = ph_GL_SwapBuffers;
128
120 device->free = ph_DeleteDevice; 129 device->free = ph_DeleteDevice;
121 130
122 return device; 131 return device;
123 } 132 }
124 133
145 } 154 }
146 155
147 static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat) 156 static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat)
148 { 157 {
149 PtArg_t arg[1]; 158 PtArg_t arg[1];
150 PhDim_t dim; 159 PhDim_t dim;
151 PgColor_t ph_palette[_Pg_MAX_PALETTE]; 160 PgColor_t ph_palette[_Pg_MAX_PALETTE];
152 int i; 161 int i;
153 unsigned long *tempptr; 162 unsigned long *tempptr;
154 int rtnval; 163 int rtnval;
155 PgDisplaySettings_t mysettings; 164 // PgDisplaySettings_t mysettings;
156 PgVideoModeInfo_t my_mode_info; 165 PgVideoModeInfo_t my_mode_info;
157 PgHWCaps_t my_hwcaps; 166 PgHWCaps_t my_hwcaps;
158 167
159 if( NULL == ( event = malloc( EVENT_SIZE ) ) ) 168 if( NULL == ( event = malloc( EVENT_SIZE ) ) )
160 exit( EXIT_FAILURE ); 169 exit( EXIT_FAILURE );
161 170
162 /* Create a widget 'window' to capture events */ 171 /* Create a widget 'window' to capture events */
163 dim.w=0; //JB test320; 172 dim.w=0; //JB test320;
164 dim.h=0; //JB test240; 173 dim.h=0; //JB test240;
165 //We need to return BytesPerPixel as it in used by CreateRGBsurface 174 //We need to return BytesPerPixel as it in used by CreateRGBsurface
188 printf("Photon application init failed, probably Photon is not running.\n"); 197 printf("Photon application init failed, probably Photon is not running.\n");
189 exit( EXIT_FAILURE ); 198 exit( EXIT_FAILURE );
190 // PtExit(EXIT_FAILURE); // Got SEGFAULT. 199 // PtExit(EXIT_FAILURE); // Got SEGFAULT.
191 } 200 }
192 201
193 //PgSetDrawBufferSize(16 *1024); 202 //PgSetDrawBufferSize(16 *1024);
194 PgSetRegion(PtWidgetRid(window)); 203 PgSetRegion(PtWidgetRid(window));
195 PgSetClipping(0,NULL); 204 PgSetClipping(0,NULL);
196 PtRealizeWidget(window); 205 PtRealizeWidget(window);
197 206
198 207
199 /* Get the available video modes */ 208 /* Get the available video modes */
200 // if(ph_GetVideoModes(this) < 0) 209 // if(ph_GetVideoModes(this) < 0)
201 // return -1; 210 // return -1;
214 fprintf(stderr,"ph_VideoInit: PgGetVideoMode failed patch A?? \n"); 223 fprintf(stderr,"ph_VideoInit: PgGetVideoMode failed patch A?? \n");
215 //QNX6/Patch A always fails return code even though call succeeds. fixed Patch B 224 //QNX6/Patch A always fails return code even though call succeeds. fixed Patch B
216 } 225 }
217 */ 226 */
218 if (PgGetGraphicsHWCaps(&my_hwcaps) < 0) 227 if (PgGetGraphicsHWCaps(&my_hwcaps) < 0)
219 { 228 {
220 fprintf(stderr,"ph_VideoInit: GetGraphicsHWCaps failed!! \n"); 229 fprintf(stderr,"ph_VideoInit: GetGraphicsHWCaps failed!! \n");
221 //that HAVE to work 230 //that HAVE to work
222 } 231 }
223 if (PgGetVideoModeInfo(my_hwcaps.current_video_mode, &my_mode_info) < 0) 232 if (PgGetVideoModeInfo(my_hwcaps.current_video_mode, &my_mode_info) < 0)
224 { 233 {
225 fprintf(stderr,"ph_VideoInit: PgGetVideoModeInfo failed\n"); 234 fprintf(stderr,"ph_VideoInit: PgGetVideoModeInfo failed\n");
226 } 235 }
236
227 //We need to return BytesPerPixel as it in used by CreateRGBsurface 237 //We need to return BytesPerPixel as it in used by CreateRGBsurface
228 vformat->BitsPerPixel = my_mode_info.bits_per_pixel; 238 vformat->BitsPerPixel = my_mode_info.bits_per_pixel;
229 vformat->BytesPerPixel = vformat->BitsPerPixel/8; 239 vformat->BytesPerPixel = vformat->BitsPerPixel/8;
230 240
231 //return a palette if we are in 256 color mode 241 //return a palette if we are in 256 color mode
261 } 271 }
262 272
263 static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current, 273 static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current,
264 int width, int height, int bpp, Uint32 flags) 274 int width, int height, int bpp, Uint32 flags)
265 { 275 {
266 PhRegion_t region_info; 276 // PhRegion_t region_info;
267 PgDisplaySettings_t settings; 277 PgDisplaySettings_t settings;
268 PgHWCaps_t my_hwcaps; 278 PgHWCaps_t my_hwcaps;
269 PgVideoModeInfo_t mode_info; 279 PgVideoModeInfo_t mode_info;
270 int mode, actual_width, actual_height; 280 int mode, actual_width, actual_height;
271 PtArg_t arg[5]; 281 PtArg_t arg[5];
272 PhDim_t dim; 282 PhDim_t dim;
273 int rtnval; 283 int rtnval;
274 SDL_Rect ** mymodelist; 284 PgColor_t ph_palette[_Pg_MAX_PALETTE];
275 SDL_PixelFormat myformat; 285 int i;
276 PgColor_t ph_palette[_Pg_MAX_PALETTE]; 286 unsigned long *tempptr;
277 int i; 287 uint64_t OGLAttrib[PH_OGL_MAX_ATTRIBS];
278 unsigned long *tempptr; 288
279 289 actual_width = width;
280 actual_width = width; 290 actual_height = height;
281 actual_height = height; 291
282 292 dim.w=width;
293 dim.h=height;
283 294
284 /* Lock the event thread, in multi-threading environments */ 295 /* Lock the event thread, in multi-threading environments */
285 SDL_Lock_EventThread(); 296 SDL_Lock_EventThread();
286
287 297
288 /* Initialize the window */ 298 /* Initialize the window */
289 if (flags & SDL_FULLSCREEN) //Direct Context , assume SDL_HWSURFACE also set 299 if (flags & SDL_FULLSCREEN) //Direct Context , assume SDL_HWSURFACE also set
290 { 300 {
291
292 /* 301 /*
293 if (old_video_mode==-1) 302 if (old_video_mode==-1)
294 { 303 {
295 PgGetGraphicsHWCaps(&graphics_card_caps); 304 PgGetGraphicsHWCaps(&graphics_card_caps);
296 old_video_mode=graphics_card_caps.current_video_mode; 305 old_video_mode=graphics_card_caps.current_video_mode;
297 old_refresh_rate=graphics_card_caps.current_rrate; 306 old_refresh_rate=graphics_card_caps.current_rrate;
298 } 307 }
299 */ 308 */
300 309
301
302
303 /* Get the video mode and set it */ 310 /* Get the video mode and set it */
304 if (bpp == 0) 311 if (bpp == 0)
305 { 312 {
306 /*again same issue, same solution 313 /*again same issue, same solution
307 if (PgGetVideoMode( &settings ) < 0) 314 if (PgGetVideoMode( &settings ) < 0)
308 { 315 {
309 fprintf(stderr,"error: PgGetVideoMode failed\n"); 316 fprintf(stderr,"error: PgGetVideoMode failed\n");
310 } 317 }
311 */ 318 */
312 if (PgGetGraphicsHWCaps(&my_hwcaps) < 0) 319 if (PgGetGraphicsHWCaps(&my_hwcaps) < 0)
313 { 320 {
314 fprintf(stderr,"ph_SetVideoMode: GetGraphicsHWCaps failed!! \n"); 321 fprintf(stderr,"ph_SetVideoMode: GetGraphicsHWCaps failed!! \n");
315 //that HAVE to work 322 //that HAVE to work
316 } 323 }
317 if (PgGetVideoModeInfo(my_hwcaps.current_video_mode, &mode_info) < 0) 324 if (PgGetVideoModeInfo(my_hwcaps.current_video_mode, &mode_info) < 0)
318 { 325 {
319 fprintf(stderr,"ph_SetVideoMode: PgGetVideoModeInfo failed\n"); 326 fprintf(stderr,"ph_SetVideoMode: PgGetVideoModeInfo failed\n");
320 } 327 }
321 bpp = mode_info.bits_per_pixel; 328 bpp = mode_info.bits_per_pixel;
322 } 329 }
323 if (flags & SDL_ANYFORMAT) 330 if (flags & SDL_ANYFORMAT)
324 { 331 {
325 if ((mode = get_mode_any_format(width, height, bpp)) == 0) 332 if ((mode = get_mode_any_format(width, height, bpp)) == 0)
339 346
340 } 347 }
341 settings.mode = mode; 348 settings.mode = mode;
342 settings.refresh = 0; 349 settings.refresh = 0;
343 settings.flags = 0; 350 settings.flags = 0;
344 351
345
346 if (PgSetVideoMode( &settings ) < 0) 352 if (PgSetVideoMode( &settings ) < 0)
347 { 353 {
348 fprintf(stderr,"error: PgSetVideoMode failed\n"); 354 fprintf(stderr,"error: PgSetVideoMode failed\n");
349 } 355 }
350 356
356 ph_EnterFullScreen(this); 362 ph_EnterFullScreen(this);
357 363
358 364
359 365
360 } //end fullscreen flag 366 } //end fullscreen flag
361 else if (flags & SDL_HWSURFACE) /* Use offscreen memory iff SDL_HWSURFACE flag is set */ 367 else
362 { 368 {
363 // Hardware surface is Offsceen Context. ph_ResizeImage handles the switch 369 if (flags & SDL_HWSURFACE) /* Use offscreen memory iff SDL_HWSURFACE flag is set */
364 current->flags = (flags|(~SDL_RESIZABLE)); //no stretch blit in offscreen context 370 {
371 // Hardware surface is Offsceen Context. ph_ResizeImage handles the switch
372 current->flags = (flags|(~SDL_RESIZABLE)); //no stretch blit in offscreen context
373 }
374 else // must be SDL_SWSURFACE
375 {
376 current->flags = (flags|SDL_RESIZABLE); //yes we can resize as this is a software surface
377 }
378
379 if (flags & SDL_OPENGL) // for now support OpenGL in window mode only
380 {
381 OGLAttrib[0]=PHOGL_ATTRIB_DEPTH_BITS;
382 OGLAttrib[1]=bpp;
383 OGLAttrib[2]=PHOGL_ATTRIB_NONE;
384 OGLContext=PdCreateOpenGLContext(2, &dim, 0, OGLAttrib);
385 if (OGLContext==NULL)
386 {
387 fprintf(stderr,"error: cannot create OpenGL context\n");
388 exit(1);
389 }
390 PhDCSetCurrent(OGLContext);
391 }
392
365 } 393 }
366 else // must be SDL_SWSURFACE
367 {
368 current->flags = (flags|SDL_RESIZABLE); //yes we can resize as this is a software surface
369 }
370
371 394
372 //If we are setting video to use the palette make sure we have allocated memory for it 395 //If we are setting video to use the palette make sure we have allocated memory for it
373 if(bpp == 8) 396 if(bpp == 8)
374 { 397 {
375 current->format->palette = malloc(sizeof(SDL_Palette)); 398 current->format->palette = malloc(sizeof(SDL_Palette));
377 current->format->palette->ncolors = 256; 400 current->format->palette->ncolors = 256;
378 current->format->palette->colors = (SDL_Color *)malloc(256 *sizeof(SDL_Color)); 401 current->format->palette->colors = (SDL_Color *)malloc(256 *sizeof(SDL_Color));
379 //fill the palette 402 //fill the palette
380 rtnval = PgGetPalette(ph_palette); 403 rtnval = PgGetPalette(ph_palette);
381 404
382 tempptr = (unsigned long *)current->format->palette->colors; 405 tempptr = (unsigned long *)current->format->palette->colors;
383 406
384 for(i=0;i<256; i++) 407 for(i=0;i<256; i++)
385 { 408 {
386 *tempptr = (((unsigned long)ph_palette[i]) << 8); 409 *tempptr = (((unsigned long)ph_palette[i]) << 8);
387 tempptr++; 410 tempptr++;
395 418
396 //If we need to resize the window 419 //If we need to resize the window
397 if((dim.w != width)||(dim.h != height)) 420 if((dim.w != width)||(dim.h != height))
398 { 421 {
399 dim.w=width; 422 dim.w=width;
400 dim.h=height; 423 dim.h=height;
401 PtSetArg(&arg[0], Pt_ARG_DIM, &dim,0); 424 PtSetArg(&arg[0], Pt_ARG_DIM, &dim,0);
402 PtSetResources( window, 1, arg ); 425 PtSetResources( window, 1, arg );
403 current->w = width; 426 current->w = width;
404 current->h = height; 427 current->h = height;
405 current->format->BitsPerPixel = bpp; 428 current->format->BitsPerPixel = bpp;
406 current->format->BytesPerPixel = bpp/8; 429 current->format->BytesPerPixel = bpp/8;
407 current->pitch = SDL_CalculatePitch(current); 430 current->pitch = SDL_CalculatePitch(current);
408 //Must call at least once it setup image planes 431 //Must call at least once it setup image planes
409 ph_ResizeImage(this, current, flags); 432 ph_ResizeImage(this, current, flags);
410 } 433 }
411 434
412 435
413 SDL_Unlock_EventThread(); 436 SDL_Unlock_EventThread();
414 437
415 /* We're done! */ 438 /* We're done! */
419 static void ph_VideoQuit(_THIS) 442 static void ph_VideoQuit(_THIS)
420 { 443 {
421 444
422 if(SDL_Image != NULL) 445 if(SDL_Image != NULL)
423 { 446 {
424 ph_DestroyImage(this, SDL_VideoSurface); 447 ph_DestroyImage(this, SDL_VideoSurface);
425
426 } 448 }
427 449
428 if (currently_fullscreen) 450 if (currently_fullscreen)
429 { 451 {
430 PdDirectStop( directContext ); 452 PdDirectStop( directContext );
492 } 514 }
493 } 515 }
494 return alloct_all; 516 return alloct_all;
495 } 517 }
496 518
519 void ph_GL_SwapBuffers(_THIS)
520 {
521 PgSetRegion(PtWidgetRid(window));
522 PdOpenGLContextSwapBuffers(OGLContext);
523 }
524
525 /*
497 static int ph_ResizeWindow(_THIS, 526 static int ph_ResizeWindow(_THIS,
498 SDL_Surface *screen, int w, int h, Uint32 flags) 527 SDL_Surface *screen, int w, int h, Uint32 flags)
499 { 528 {
500 PhWindowEvent_t winevent; 529 PhWindowEvent_t winevent;
501 530
510 } 539 }
511 current_w = w; 540 current_w = w;
512 current_h = h; 541 current_h = h;
513 return(0); 542 return(0);
514 } 543 }
515 544 */
516