comparison src/video/photon/SDL_ph_modes.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 8e3ce997621c
comparison
equal deleted inserted replaced
314:bff64eba7721 315:3333b6e68289
60 return 0; 60 return 0;
61 else 61 else
62 return -1; 62 return -1;
63 } 63 }
64 64
65 /*
66 static int compare_modes_by_bpp(const void* mode1, const void* mode2)
67 {
68
69 if (PgGetVideoModeInfo(*(unsigned short*)mode1, &mode_info) < 0)
70 {
71 fprintf(stderr,"error: In compare_modes_by_bpp PgGetVideoModeInfo failed on mode: 0x%x\n",
72 *(unsigned short*)mode1);
73 return 0;
74 }
75 key1 = mode_info.bits_per_pixel;
76
77 if (PgGetVideoModeInfo(*(unsigned short*)mode2, &mode_info) < 0)
78 {
79 fprintf(stderr,"error: In compare_modes_by_bpp PgGetVideoModeInfo failed on mode: 0x%x\n",
80 *(unsigned short*)mode2);
81 return 0;
82 }
83 key2 = mode_info.bits_per_pixel;
84
85 if (key1 > key2)
86 return 1;
87 else if (key1 == key2)
88 return 0;
89 else
90 return -1;
91 }
92 */
93
94 /*
95 int ph_GetVideoModes(_THIS)
96 {
97 unsigned short *front;
98 int i, bpp_group_size;
99
100 // TODO: add mode_list member to _THIS
101 if (PgGetVideoModeList( &mode_list ) < 0)
102 {
103 fprintf(stderr,"error: PgGetVideoModeList failed\n");
104 return -1;
105 }
106
107 // sort list first by bits per pixel (bpp),
108 // then sort groups with same bpp by resolution.
109 qsort(mode_list.modes, mode_list.num_modes, sizeof(unsigned short), compare_modes_by_bpp);
110 bpp_group_size = 1;
111 front = &mode_list.modes[0];
112 for(i=0;i<mode_list.num_modes-2;i++)
113 {
114 if (compare_modes_by_bpp(&mode_list.modes[i],&mode_list.modes[i+1]))
115 {
116 qsort(front, bpp_group_size, sizeof(unsigned short), compare_modes_by_res);
117 front = &mode_list.modes[i+1];
118 bpp_group_size = 1;
119 }
120 else
121 {
122 bpp_group_size++;
123 }
124 }
125
126 //SDL_modelist = (SDL_Rect **)malloc((mode_list.num_modes+1)*sizeof(SDL_Rect *));
127 if ( SDL_modelist ) {
128 for (i=0;i<mode_list.num_modes;i++) {
129 // SDL_modelist[i] = (SDL_Rect *)malloc(sizeof(SDL_Rect));
130 // if ( SDL_modelist[i] == NULL ) {
131 // break;
132 // }
133 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0)
134 {
135 fprintf(stderr,"error: PgGetVideoModeInfo failed on mode: 0x%x\n",
136 mode_list.modes[i]);
137 return -1;
138 }
139 SDL_modelist[i].x = 0;
140 SDL_modelist[i].y = 0;
141 SDL_modelist[i].w = mode_info.height;
142 SDL_modelist[i].h = mode_info.width;
143 }
144 //SDL_modelist[i] = NULL;
145 }
146 else
147 {
148 fprintf(stderr,"error: malloc failed on SDL_modelist\n");
149 return -1;
150 }
151
152 return 0;
153 }
154 */
155
156 SDL_Rect **ph_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) 65 SDL_Rect **ph_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
157 { 66 {
158 int i = 0; 67 int i = 0;
159 int j = 0; 68 int j = 0;
160 SDL_Rect Amodelist[PH_MAX_VIDEOMODES]; 69 SDL_Rect Amodelist[PH_MAX_VIDEOMODES];
206 void ph_FreeVideoModes(_THIS) 115 void ph_FreeVideoModes(_THIS)
207 { 116 {
208 return; 117 return;
209 } 118 }
210 119
120 #if 0
211 static void set_best_resolution(_THIS, int width, int height) 121 static void set_best_resolution(_THIS, int width, int height)
212 { 122 {
213 123 /* warning ! dead variable use_vidmode ! */
214 if ( use_vidmode ) { 124 if ( use_vidmode ) {
215 PgDisplaySettings_t settings; 125 PgDisplaySettings_t settings;
216 PgVideoModeInfo_t current_mode_info; 126 PgVideoModeInfo_t current_mode_info;
217 PgHWCaps_t my_hwcaps; 127 PgHWCaps_t my_hwcaps;
218 unsigned short current_bpp; 128 unsigned short current_bpp;
279 } 189 }
280 } 190 }
281 191
282 int ph_ResizeFullScreen(_THIS) 192 int ph_ResizeFullScreen(_THIS)
283 { 193 {
284 if (currently_fullscreen) { 194 if (currently_fullscreen)
195 {
285 set_best_resolution(this, current_w, current_h); 196 set_best_resolution(this, current_w, current_h);
286 } 197 }
198
287 return (1); 199 return (1);
288 } 200 }
201 #endif /* 0 */
289 202
290 /* return the mode associated with width, height and bpp */ 203 /* return the mode associated with width, height and bpp */
291 /* if there is no mode then zero is returned */ 204 /* if there is no mode then zero is returned */
292 int get_mode(int width, int height, int bpp) 205 int get_mode(int width, int height, int bpp)
293 { 206 {
352 (mode_info.height == height)) 265 (mode_info.height == height))
353 break; 266 break;
354 } 267 }
355 if (i<mode_list.num_modes) 268 if (i<mode_list.num_modes)
356 { 269 {
357 // get closest bpp 270 /* get closest bpp */
358 closest = i++; 271 closest = i++;
359 if (mode_info.bits_per_pixel == bpp) 272 if (mode_info.bits_per_pixel == bpp)
360 return mode_list.modes[ closest ]; 273 return mode_list.modes[ closest ];
361 274
362 min_delta = abs(mode_info.bits_per_pixel - bpp); 275 min_delta = abs(mode_info.bits_per_pixel - bpp);
413 326
414 int ph_EnterFullScreen(_THIS) 327 int ph_EnterFullScreen(_THIS)
415 { 328 {
416 if (!currently_fullscreen) 329 if (!currently_fullscreen)
417 { 330 {
331 if (this->screen)
332 {
333 if ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL)
334 {
335 #ifdef HAVE_OPENGL
336 #endif /* HAVE_OPENGL */
337 return 0;
338 }
339 }
340
341 if (OCImage.direct_context == NULL)
342 {
343 OCImage.direct_context=(PdDirectContext_t*)PdCreateDirectContext();
344 }
345
346 if (!OCImage.direct_context)
347 {
348 fprintf(stderr, "ph_EnterFullScreen: Can't create direct context\n" );
349 }
350
351 PdDirectStart(OCImage.direct_context);
352
353 currently_fullscreen = 1;
354 }
355
356 return 1;
357 }
358
359 int ph_LeaveFullScreen(_THIS)
360 {
361 PgDisplaySettings_t mymode_settings;
362
363 if (currently_fullscreen)
364 {
418 if ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL) 365 if ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL)
419 { 366 {
420 #ifdef HAVE_OPENGL 367 #ifdef HAVE_OPENGL
421 #endif /* HAVE_OPENGL */ 368 #endif /* HAVE_OPENGL */
422 return 0; 369 return 0;
423 } 370 }
424 else 371 else
425 { 372 {
426 if (old_video_mode==-1)
427 {
428 PgGetGraphicsHWCaps(&graphics_card_caps);
429 old_video_mode=graphics_card_caps.current_video_mode;
430 old_refresh_rate=graphics_card_caps.current_rrate;
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;
454
455 if (currently_fullscreen)
456 {
457 if ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL)
458 {
459 #ifdef HAVE_OPENGL
460 #endif /* HAVE_OPENGL */
461 return 0;
462 }
463 else
464 {
465 PdDirectStop(OCImage.direct_context); 373 PdDirectStop(OCImage.direct_context);
466 PdReleaseDirectContext(OCImage.direct_context); 374 PdReleaseDirectContext(OCImage.direct_context);
375
376 currently_fullscreen=0;
467 377
468 /* Restore old video mode */ 378 /* Restore old video mode */
469 if (old_video_mode != -1) 379 if (old_video_mode != -1)
470 { 380 {
471 mymode_settings.mode= (unsigned short) old_video_mode; 381 mymode_settings.mode= (unsigned short) old_video_mode;
472 mymode_settings.refresh= (unsigned short) old_refresh_rate; 382 mymode_settings.refresh= (unsigned short) old_refresh_rate;
473 mymode_settings.flags = 0; 383 mymode_settings.flags= 0;
384
474 if (PgSetVideoMode(&mymode_settings) < 0) 385 if (PgSetVideoMode(&mymode_settings) < 0)
475 { 386 {
476 fprintf(stderr,"error: PgSetVideoMode failed\n"); 387 fprintf(stderr,"error: PgSetVideoMode failed\n");
477 } 388 }
478 } 389 }
479 390
480 old_video_mode=-1; 391 old_video_mode=-1;
481 old_refresh_rate=-1; 392 old_refresh_rate=-1;
482 } 393 }
483 394
484 } 395 }
485 return 1; 396 return 1;
486 } 397 }