comparison src/video/photon/SDL_ph_modes.c @ 309:2de77f7b7a28

*** empty log message ***
author Sam Lantinga <slouken@libsdl.org>
date Mon, 11 Mar 2002 17:38:56 +0000
parents f6ffac90895c
children 3333b6e68289
comparison
equal deleted inserted replaced
308:ee32ed29a507 309:2de77f7b7a28
153 } 153 }
154 */ 154 */
155 155
156 SDL_Rect **ph_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) 156 SDL_Rect **ph_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
157 { 157 {
158 int i = 0; 158 int i = 0;
159 int j = 0; 159 int j = 0;
160 SDL_Rect Amodelist[PH_MAX_VIDEOMODES]; 160 SDL_Rect Amodelist[PH_MAX_VIDEOMODES];
161 161
162 for (i=0; i<PH_MAX_VIDEOMODES; i++) 162 for (i=0; i<PH_MAX_VIDEOMODES; i++)
163 { 163 {
164 SDL_modearray[i]=&SDL_modelist[i]; 164 SDL_modearray[i]=&SDL_modelist[i];
165 } 165 }
166 166
167 if (PgGetVideoModeList( &mode_list ) < 0) 167 if (PgGetVideoModeList( &mode_list ) < 0)
168 { 168 {
169 fprintf(stderr,"error: PgGetVideoModeList failed\n"); 169 fprintf(stderr,"error: PgGetVideoModeList failed\n");
170 return NULL; 170 return NULL;
171 } 171 }
172 172
173 mode_info.bits_per_pixel = 0; 173 mode_info.bits_per_pixel = 0;
174 174
175 for (i=0; i < mode_list.num_modes; i++) 175 for (i=0; i < mode_list.num_modes; i++)
176 { 176 {
177 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0) 177 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0)
178 { 178 {
179 fprintf(stderr,"error: PgGetVideoModeInfo failed on mode: 0x%x\n", 179 fprintf(stderr,"error: PgGetVideoModeInfo failed on mode: 0x%x\n", mode_list.modes[i]);
180 mode_list.modes[i]); 180 return NULL;
181 return NULL; 181 }
182 } 182 if(mode_info.bits_per_pixel == format->BitsPerPixel)
183 183 {
184 if(mode_info.bits_per_pixel == format->BitsPerPixel) 184 Amodelist[j].w = mode_info.width;
185 { 185 Amodelist[j].h = mode_info.height;
186 Amodelist[j].w = mode_info.width; 186 Amodelist[j].x = 0;
187 Amodelist[j].h = mode_info.height; 187 Amodelist[j].y = 0;
188 Amodelist[j].x = 0; 188 j++;
189 Amodelist[j].y = 0; 189 }
190 j++; 190 }
191 }
192 }
193 191
194 //reorder biggest for smallest, assume width dominates 192 /* reorder biggest for smallest, assume width dominates */
195 193
196 for(i=0; i< j ; i++) 194 for(i=0; i<j; i++)
197 { 195 {
198 SDL_modelist[i].w = Amodelist[j - i -1].w; 196 SDL_modelist[i].w = Amodelist[j - i -1].w;
199 SDL_modelist[i].h = Amodelist[j - i -1].h; 197 SDL_modelist[i].h = Amodelist[j - i -1].h;
200 SDL_modelist[i].x = Amodelist[j - i -1].x; 198 SDL_modelist[i].x = Amodelist[j - i -1].x;
201 SDL_modelist[i].y = Amodelist[j - i -1].y; 199 SDL_modelist[i].y = Amodelist[j - i -1].y;
202 } 200 }
203 SDL_modearray[j]=NULL; 201 SDL_modearray[j]=NULL;
204 202
205 return SDL_modearray; 203 return SDL_modearray;
206 } 204 }
207 205
208 void ph_FreeVideoModes(_THIS) 206 void ph_FreeVideoModes(_THIS)
209 { 207 {
210 return; 208 return;
279 } 277 }
280 } 278 }
281 } 279 }
282 } 280 }
283 281
284 /*
285 static void get_real_resolution(_THIS, int* w, int* h)
286 {
287
288 if ( use_vidmode ) {
289 //PgDisplaySettings_t settings;
290 PgVideoModeInfo_t current_mode_info;
291 PgHWCaps_t my_hwcaps;
292 // int unused;
293
294 // if (PgGetVideoMode( &settings ) >= 0) {
295 // *w = settings.xres;
296 // *h = settings.yres;
297 // return;
298 // }
299 if (PgGetGraphicsHWCaps(&my_hwcaps) >= 0)
300 {
301 if (PgGetVideoModeInfo(my_hwcaps.current_video_mode, &current_mode_info) < 0)
302 {
303 fprintf(stderr,"get_real_resolution: PgGetVideoModeInfo failed\n");
304 }
305 *w = current_mode_info.width;
306 *h = current_mode_info.height;
307 }
308 }
309 // *w = DisplayWidth(SDL_Display, SDL_Screen);
310 // *h = DisplayHeight(SDL_Display, SDL_Screen);
311 }
312 */
313
314 int ph_ResizeFullScreen(_THIS) 282 int ph_ResizeFullScreen(_THIS)
315 { 283 {
316 284 if (currently_fullscreen) {
317 if ( currently_fullscreen ) {
318 set_best_resolution(this, current_w, current_h); 285 set_best_resolution(this, current_w, current_h);
319 } 286 }
320 return(1); 287 return (1);
321 } 288 }
322 289
290 /* return the mode associated with width, height and bpp */
291 /* if there is no mode then zero is returned */
323 int get_mode(int width, int height, int bpp) 292 int get_mode(int width, int height, int bpp)
324 /* return the mode associated with width, height and bpp */ 293 {
325 /* if there is no mode then zero is returned */ 294 int i;
326 { 295
327 int i; 296 if(width<640)
328 297 {
329 298 width=640;
330 if(width <640) 299 }
331 width = 640; 300 if(height<480)
332 if(height < 480) 301 {
333 height = 480; 302 height=480;
334 303 }
335 304
336 if (PgGetVideoModeList( &mode_list ) < 0) 305 if (PgGetVideoModeList(&mode_list) < 0)
337 { 306 {
338 fprintf(stderr,"error: PgGetVideoModeList failed\n"); 307 fprintf(stderr,"error: PgGetVideoModeList failed\n");
339 return -1; 308 return -1;
340 } 309 }
341 310
342 // search list for exact match 311 /* search list for exact match */
343 for (i=0;i<mode_list.num_modes;i++) 312 for (i=0;i<mode_list.num_modes;i++)
344 { 313 {
345 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0) 314 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0)
346 { 315 {
347 fprintf(stderr,"error: PgGetVideoModeInfo failed\n"); 316 fprintf(stderr,"error: PgGetVideoModeInfo failed\n");
348 return 0; 317 return 0;
349 } 318 }
350 319
351 320 if ((mode_info.width == width) &&
352 if ((mode_info.width == width) && 321 (mode_info.height == height) &&
353 (mode_info.height == height) && 322 (mode_info.bits_per_pixel == bpp))
354 (mode_info.bits_per_pixel == bpp)) 323 {
355 { 324 return mode_list.modes[i];
356 return mode_list.modes[i]; 325 }
357 } 326 }
358 } 327
359 return (i == mode_list.num_modes) ? 0 : mode_list.modes[i]; 328 return (i == mode_list.num_modes) ? 0 : mode_list.modes[i];
360 } 329 }
361 330
362 int get_mode_any_format(int width, int height, int bpp) 331 int get_mode_any_format(int width, int height, int bpp)
363 /* return the mode associated with width, height and bpp */ 332 /* return the mode associated with width, height and bpp */
364 /* if requested bpp is not found the mode with closest bpp is returned */ 333 /* if requested bpp is not found the mode with closest bpp is returned */
419 } 388 }
420 } 389 }
421 return mode_list.modes[ closest ]; 390 return mode_list.modes[ closest ];
422 } 391 }
423 else 392 else
424 return 0; 393 return 0;
425 } 394 }
426 395
427 void ph_WaitMapped(_THIS); 396 void ph_WaitMapped(_THIS);
428 void ph_WaitUnmapped(_THIS); 397 void ph_WaitUnmapped(_THIS);
429 void ph_QueueEnterFullScreen(_THIS); 398 void ph_QueueEnterFullScreen(_THIS);
430 399
431 int ph_ToggleFullScreen(_THIS, int on) 400 int ph_ToggleFullScreen(_THIS, int on)
432 { 401 {
433 402 if (currently_fullscreen)
434 if(currently_fullscreen) 403 {
435 ph_LeaveFullScreen(this); 404 return ph_LeaveFullScreen(this);
436 else 405 }
437 ph_EnterFullScreen(this); 406 else
407 {
408 return ph_EnterFullScreen(this);
409 }
438 410
439 return 0; 411 return 0;
440
441 } 412 }
442 413
443 int ph_EnterFullScreen(_THIS) 414 int ph_EnterFullScreen(_THIS)
444 { 415 {
445 if ( ! currently_fullscreen ) 416 if (!currently_fullscreen)
446 { 417 {
447 418 if ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL)
448 if (old_video_mode==-1) 419 {
449 { 420 #ifdef HAVE_OPENGL
450 PgGetGraphicsHWCaps(&graphics_card_caps); 421 #endif /* HAVE_OPENGL */
451 old_video_mode=graphics_card_caps.current_video_mode; 422 return 0;
452 old_refresh_rate=graphics_card_caps.current_rrate; 423 }
453 } 424 else
454 425 {
455 426 if (old_video_mode==-1)
456 if(OCImage.direct_context == NULL) 427 {
457 OCImage.direct_context=(PdDirectContext_t*)PdCreateDirectContext(); 428 PgGetGraphicsHWCaps(&graphics_card_caps);
458 if( !OCImage.direct_context ) 429 old_video_mode=graphics_card_caps.current_video_mode;
459 fprintf(stderr, "error: Can't create direct context\n" ); 430 old_refresh_rate=graphics_card_caps.current_rrate;
460 431 }
432
433 if(OCImage.direct_context == NULL)
434 {
435 OCImage.direct_context=(PdDirectContext_t*)PdCreateDirectContext();
436 }
437 if(!OCImage.direct_context)
438 {
439 fprintf(stderr, "error: Can't create direct context\n" );
440 }
441
442 PdDirectStart(OCImage.direct_context);
443
444 currently_fullscreen = 1;
445 }
446 }
447
448 return 1;
449 }
450
451 int ph_LeaveFullScreen(_THIS )
452 {
453 PgDisplaySettings_t mymode_settings;
461 454
462 /* Remove the cursor if in full screen mode */ 455 if (currently_fullscreen)
463 /* 456 {
464 region_info.cursor_type = Ph_CURSOR_NONE; 457 if ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL)
465 region_info.rid=PtWidgetRid(window); 458 {
466 PhRegionChange(Ph_REGION_CURSOR,0,&region_info,NULL,NULL); 459 #ifdef HAVE_OPENGL
467 */ 460 #endif /* HAVE_OPENGL */
468 461 return 0;
469 PdDirectStart( OCImage.direct_context ); 462 }
470 463 else
471 currently_fullscreen = 1; 464 {
472 } 465 PdDirectStop(OCImage.direct_context);
473 466 PdReleaseDirectContext(OCImage.direct_context);
474 467
475 468 /* Restore old video mode */
476 return 1; 469 if (old_video_mode != -1)
477 } 470 {
478 471 mymode_settings.mode= (unsigned short) old_video_mode;
479 int ph_LeaveFullScreen(_THIS ) 472 mymode_settings.refresh= (unsigned short) old_refresh_rate;
480 { 473 mymode_settings.flags = 0;
481 PgDisplaySettings_t mymode_settings; 474 if (PgSetVideoMode(&mymode_settings) < 0)
482 475 {
483 if ( currently_fullscreen ) 476 fprintf(stderr,"error: PgSetVideoMode failed\n");
484 { 477 }
485 PdDirectStop(OCImage.direct_context); 478 }
486 PdReleaseDirectContext(OCImage.direct_context); 479
487 480 old_video_mode=-1;
488 //Restore old video mode 481 old_refresh_rate=-1;
489 if (old_video_mode != -1) 482 }
490 { 483
491 mymode_settings.mode= (unsigned short) old_video_mode; 484 }
492 mymode_settings.refresh= (unsigned short) old_refresh_rate; 485 return 1;
493 mymode_settings.flags = 0; 486 }
494 if(PgSetVideoMode(&mymode_settings) < 0)
495 {
496 fprintf(stderr,"error: PgSetVideoMode failed\n");
497 }
498 }
499
500 old_video_mode=-1;
501 old_refresh_rate=-1;
502
503 // Restore cursor
504
505 }
506 return 1;
507 }