Mercurial > sdl-ios-xcode
annotate src/video/photon/SDL_ph_modes.c @ 252:e8157fcb3114
Updated the source with the correct e-mail address
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 14 Dec 2001 12:38:15 +0000 |
parents | 62bad9a82022 |
children | c6abdda2f666 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
3 Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga | |
4 | |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 of the License, or (at your option) any later version. | |
9 | |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
204
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
22 | |
23 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
27 | |
28 | |
29 #include "SDL_ph_modes_c.h" | |
30 | |
31 static unsigned long key1, key2; | |
32 static PgVideoModeInfo_t mode_info; | |
33 static PgVideoModes_t mode_list; | |
34 /* The current list of available video modes */ | |
35 SDL_Rect SDL_modelist[127]; | |
36 SDL_Rect *SDLmod_ptr; | |
37 SDL_Rect **SDLmod_ptrptr ; | |
38 | |
39 static int compare_modes_by_res(const void* mode1, const void* mode2) | |
40 { | |
41 | |
42 if (PgGetVideoModeInfo(*(unsigned short*)mode1, &mode_info) < 0) | |
43 { | |
44 fprintf(stderr,"error: In compare_modes_by_res PgGetVideoModeInfo failed on mode: 0x%x\n", | |
45 *(unsigned short*)mode1); | |
46 return 0; | |
47 } | |
48 key1 = mode_info.width * mode_info.height; | |
49 | |
50 if (PgGetVideoModeInfo(*(unsigned short*)mode2, &mode_info) < 0) | |
51 { | |
52 fprintf(stderr,"error: In compare_modes_by_res PgGetVideoModeInfo failed on mode: 0x%x\n", | |
53 *(unsigned short*)mode2); | |
54 return 0; | |
55 } | |
56 key2 = mode_info.width * mode_info.height; | |
57 | |
58 if (key1 > key2) | |
59 return 1; | |
60 else if (key1 == key2) | |
61 return 0; | |
62 else | |
63 return -1; | |
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 int ph_GetVideoModes(_THIS) | |
94 { | |
95 unsigned short *front; | |
96 int i, bpp_group_size; | |
97 | |
98 // TODO: add mode_list member to _THIS | |
99 if (PgGetVideoModeList( &mode_list ) < 0) | |
100 { | |
101 fprintf(stderr,"error: PgGetVideoModeList failed\n"); | |
102 return -1; | |
103 } | |
104 | |
105 // sort list first by bits per pixel (bpp), | |
106 // then sort groups with same bpp by resolution. | |
107 qsort(mode_list.modes, mode_list.num_modes, sizeof(unsigned short), compare_modes_by_bpp); | |
108 bpp_group_size = 1; | |
109 front = &mode_list.modes[0]; | |
110 for(i=0;i<mode_list.num_modes-2;i++) | |
111 { | |
112 if (compare_modes_by_bpp(&mode_list.modes[i],&mode_list.modes[i+1])) | |
113 { | |
114 qsort(front, bpp_group_size, sizeof(unsigned short), compare_modes_by_res); | |
115 front = &mode_list.modes[i+1]; | |
116 bpp_group_size = 1; | |
117 } | |
118 else | |
119 { | |
120 bpp_group_size++; | |
121 } | |
122 } | |
123 | |
124 //SDL_modelist = (SDL_Rect **)malloc((mode_list.num_modes+1)*sizeof(SDL_Rect *)); | |
125 if ( SDL_modelist ) { | |
126 for (i=0;i<mode_list.num_modes;i++) { | |
127 // SDL_modelist[i] = (SDL_Rect *)malloc(sizeof(SDL_Rect)); | |
128 // if ( SDL_modelist[i] == NULL ) { | |
129 // break; | |
130 // } | |
131 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0) | |
132 { | |
133 fprintf(stderr,"error: PgGetVideoModeInfo failed on mode: 0x%x\n", | |
134 mode_list.modes[i]); | |
135 return -1; | |
136 } | |
137 SDL_modelist[i].x = 0; | |
138 SDL_modelist[i].y = 0; | |
139 SDL_modelist[i].w = mode_info.height; | |
140 SDL_modelist[i].h = mode_info.width; | |
141 } | |
142 //SDL_modelist[i] = NULL; | |
143 } | |
144 else | |
145 { | |
146 fprintf(stderr,"error: malloc failed on SDL_modelist\n"); | |
147 return -1; | |
148 } | |
149 | |
150 return 0; | |
151 } | |
152 | |
153 static SDL_Rect** ph_SupportedVisual( SDL_PixelFormat *format) | |
154 { | |
155 int i = 0; | |
156 int j = 0; | |
157 SDL_Rect Amodelist[127]; | |
158 | |
159 | |
160 if (PgGetVideoModeList( &mode_list ) < 0) | |
161 { | |
162 fprintf(stderr,"error: PgGetVideoModeList failed\n"); | |
163 return NULL; | |
164 } | |
165 | |
166 mode_info.bits_per_pixel = 0; | |
167 | |
168 for (i=0; i < mode_list.num_modes; i++) | |
169 { | |
170 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0) | |
171 { | |
172 fprintf(stderr,"error: PgGetVideoModeInfo failed on mode: 0x%x\n", | |
173 mode_list.modes[i]); | |
174 return NULL; | |
175 } | |
176 | |
177 if(mode_info.bits_per_pixel == format->BitsPerPixel) | |
178 { | |
179 Amodelist[j].w = mode_info.width; | |
180 Amodelist[j].h = mode_info.height; | |
181 Amodelist[j].x = 0; | |
182 Amodelist[j].y = 0; | |
183 j++; | |
184 } | |
185 } | |
186 | |
187 //reorder biggest for smallest , assume width dominates | |
188 for(i=0; i< j ; i++) | |
189 { | |
190 SDL_modelist[i].w = Amodelist[j - i -1].w; | |
191 SDL_modelist[i].h = Amodelist[j - i -1].h; | |
192 SDL_modelist[i].x = Amodelist[j - i -1].x; | |
193 SDL_modelist[i].y = Amodelist[j - i -1].y; | |
194 } | |
195 | |
196 SDLmod_ptr = SDL_modelist; | |
197 SDLmod_ptrptr = &SDLmod_ptr; | |
198 return SDLmod_ptrptr; | |
199 } | |
200 | |
201 SDL_Rect **ph_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) | |
202 { | |
203 return ph_SupportedVisual( format); | |
204 } | |
205 | |
206 void ph_FreeVideoModes(_THIS) | |
207 { | |
204
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
208 // int i; |
0 | 209 |
210 // if ( SDL_modelist ) { | |
211 // for ( i=0; SDL_modelist[i]; ++i ) { | |
212 // free(SDL_modelist[i]); | |
213 // } | |
214 // free(SDL_modelist); | |
215 // SDL_modelist = NULL; | |
216 // } | |
217 } | |
218 | |
219 static void set_best_resolution(_THIS, int width, int height) | |
220 { | |
221 | |
222 if ( use_vidmode ) { | |
223 PgDisplaySettings_t settings; | |
224 PgVideoModeInfo_t current_mode_info; | |
204
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
225 PgHWCaps_t my_hwcaps; |
0 | 226 unsigned short current_bpp; |
227 int i; | |
204
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
228 /* |
0 | 229 if (PgGetVideoMode( &settings ) < 0) |
230 { | |
231 fprintf(stderr,"error: PgGetVideoMode failed\n"); | |
232 return; | |
233 } | |
234 if (PgGetVideoModeInfo( settings.mode, ¤t_mode_info ) < 0) | |
235 { | |
236 fprintf(stderr,"error: PgGetVideoModeInfo failed\n"); | |
237 return; | |
238 } | |
204
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
239 */ |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
240 //lu_zero |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
241 if (PgGetGraphicsHWCaps(&my_hwcaps) < 0) |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
242 { |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
243 fprintf(stderr,"set_best_resolution: GetGraphicsHWCaps failed!! \n"); |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
244 //that HAVE to work |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
245 } |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
246 if (PgGetVideoModeInfo(my_hwcaps.current_video_mode, ¤t_mode_info) < 0) |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
247 { |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
248 fprintf(stderr,"set_best_resolution: PgGetVideoModeInfo failed\n"); |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
249 } |
0 | 250 current_bpp = current_mode_info.bits_per_pixel; |
251 | |
252 if (PgGetVideoModeList(&mode_list) >= 0) | |
253 { | |
254 qsort(mode_list.modes, mode_list.num_modes, sizeof(unsigned short), compare_modes_by_res); | |
255 #ifdef PH_DEBUG | |
256 printf("Available modes:\n"); | |
257 for ( i = 0; i < mode_list.num_modes; ++i ) | |
258 { | |
259 PgGetVideoModeInfo(mode_list.modes[i], &mode_info); | |
260 printf("Mode %d: %dx%d\n", i, mode_info.width, mode_info.height); | |
261 } | |
262 #endif | |
263 for ( i = mode_list.num_modes-1; i >= 0 ; --i ) | |
264 { | |
265 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0) | |
266 { | |
267 fprintf(stderr,"error: PgGetVideoModeInfo failed\n"); | |
268 } | |
269 if ( (mode_info.width >= width) && | |
270 (mode_info.height >= height) && | |
271 (mode_info.bits_per_pixel == current_bpp) ) | |
272 break; | |
273 } | |
274 if (i >= 0) | |
275 { | |
276 if ( (mode_info.width != current_mode_info.width) || | |
277 (mode_info.height != current_mode_info.height) ) | |
278 { | |
279 settings.mode = mode_list.modes[i]; | |
280 if(PgSetVideoMode( &settings ) < 0) | |
281 { | |
282 fprintf(stderr,"error: PgSetVideoMode failed\n"); | |
283 } | |
284 } | |
285 } | |
286 } | |
287 } | |
288 } | |
289 | |
290 static void get_real_resolution(_THIS, int* w, int* h) | |
291 { | |
292 | |
293 if ( use_vidmode ) { | |
204
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
294 //PgDisplaySettings_t settings; |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
295 PgVideoModeInfo_t current_mode_info; |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
296 PgHWCaps_t my_hwcaps; |
0 | 297 int unused; |
204
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
298 /* |
0 | 299 if (PgGetVideoMode( &settings ) >= 0) { |
300 *w = settings.xres; | |
301 *h = settings.yres; | |
302 return; | |
204
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
303 }*/ |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
304 if (PgGetGraphicsHWCaps(&my_hwcaps) >= 0) |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
305 { |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
306 if (PgGetVideoModeInfo(my_hwcaps.current_video_mode, ¤t_mode_info) < 0) |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
307 { |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
308 fprintf(stderr,"get_real_resolution: PgGetVideoModeInfo failed\n"); |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
309 } |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
310 *w = current_mode_info.width; |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
311 *h = current_mode_info.height; |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
312 } |
0 | 313 } |
314 // *w = DisplayWidth(SDL_Display, SDL_Screen); | |
315 // *h = DisplayHeight(SDL_Display, SDL_Screen); | |
316 } | |
317 | |
318 int ph_ResizeFullScreen(_THIS) | |
319 { | |
320 | |
321 if ( currently_fullscreen ) { | |
322 set_best_resolution(this, current_w, current_h); | |
323 } | |
324 return(1); | |
325 } | |
326 | |
327 int get_mode(int width, int height, int bpp) | |
328 /* return the mode associated with width, height and bpp */ | |
329 /* if there is no mode then zero is returned */ | |
330 { | |
331 int i; | |
332 | |
333 | |
334 if(width <640) | |
335 width = 640; | |
336 if(height < 480) | |
337 height = 480; | |
338 | |
339 | |
340 if (PgGetVideoModeList( &mode_list ) < 0) | |
341 { | |
342 fprintf(stderr,"error: PgGetVideoModeList failed\n"); | |
343 return -1; | |
344 } | |
345 | |
346 // search list for exact match | |
347 for (i=0;i<mode_list.num_modes;i++) | |
348 { | |
349 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0) | |
350 { | |
351 fprintf(stderr,"error: PgGetVideoModeInfo failed\n"); | |
352 return 0; | |
353 } | |
354 | |
355 | |
356 if ((mode_info.width == width) && | |
357 (mode_info.height == height) && | |
358 (mode_info.bits_per_pixel == bpp)) | |
359 { | |
360 return mode_list.modes[i]; | |
361 } | |
362 } | |
363 return (i == mode_list.num_modes) ? 0 : mode_list.modes[i]; | |
364 } | |
365 | |
366 int get_mode_any_format(int width, int height, int bpp) | |
367 /* return the mode associated with width, height and bpp */ | |
368 /* if requested bpp is not found the mode with closest bpp is returned */ | |
369 { | |
370 int i, closest, delta, min_delta; | |
371 | |
372 if (PgGetVideoModeList( &mode_list ) < 0) | |
373 { | |
374 fprintf(stderr,"error: PgGetVideoModeList failed\n"); | |
375 return -1; | |
376 } | |
377 | |
378 qsort(mode_list.modes, mode_list.num_modes, sizeof(unsigned short), compare_modes_by_res); | |
379 for(i=0;i<mode_list.num_modes;i++) | |
380 { | |
381 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0) | |
382 { | |
383 fprintf(stderr,"error: PgGetVideoModeInfo failed\n"); | |
384 return 0; | |
385 } | |
386 if ((mode_info.width == width) && | |
387 (mode_info.height == height)) | |
388 break; | |
389 } | |
390 if (i<mode_list.num_modes) | |
391 { | |
392 // get closest bpp | |
393 closest = i++; | |
394 if (mode_info.bits_per_pixel == bpp) | |
395 return mode_list.modes[ closest ]; | |
396 | |
397 min_delta = abs(mode_info.bits_per_pixel - bpp); | |
398 while(1) | |
399 { | |
400 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0) | |
401 { | |
402 fprintf(stderr,"error: PgGetVideoModeInfo failed\n"); | |
403 return 0; | |
404 } | |
405 | |
406 if ((mode_info.width != width) || | |
407 (mode_info.height != height)) | |
408 break; | |
409 else if (mode_info.bits_per_pixel == bpp) | |
410 { | |
411 closest = i; | |
412 break; | |
413 } | |
414 else | |
415 { | |
416 delta = abs(mode_info.bits_per_pixel - bpp); | |
417 if (delta < min_delta) | |
418 { | |
419 closest = i; | |
420 min_delta = delta; | |
421 } | |
422 i++; | |
423 } | |
424 } | |
425 return mode_list.modes[ closest ]; | |
426 } | |
427 else | |
428 return 0; | |
429 } | |
430 | |
431 void ph_WaitMapped(_THIS); | |
432 void ph_WaitUnmapped(_THIS); | |
433 void ph_QueueEnterFullScreen(_THIS); | |
434 | |
435 int ph_ToggleFullScreen(_THIS, int on) | |
436 { | |
437 | |
438 if(currently_fullscreen) | |
439 ph_LeaveFullScreen(this); | |
440 else | |
441 ph_EnterFullScreen(this); | |
442 | |
443 return 0; | |
444 | |
445 } | |
446 | |
447 int ph_EnterFullScreen(_THIS) | |
448 { | |
449 if ( ! currently_fullscreen ) | |
450 { | |
451 | |
452 if (old_video_mode==-1) | |
453 { | |
454 PgGetGraphicsHWCaps(&graphics_card_caps); | |
455 old_video_mode=graphics_card_caps.current_video_mode; | |
456 old_refresh_rate=graphics_card_caps.current_rrate; | |
457 } | |
458 | |
459 | |
460 if(OCImage.direct_context == NULL) | |
461 OCImage.direct_context=(PdDirectContext_t*)PdCreateDirectContext(); | |
462 if( !OCImage.direct_context ) | |
463 fprintf(stderr, "error: Can't create direct context\n" ); | |
464 | |
465 | |
466 /* Remove the cursor if in full screen mode */ | |
467 /* | |
468 region_info.cursor_type = Ph_CURSOR_NONE; | |
469 region_info.rid=PtWidgetRid(window); | |
470 PhRegionChange(Ph_REGION_CURSOR,0,®ion_info,NULL,NULL); | |
471 */ | |
472 | |
473 PdDirectStart( OCImage.direct_context ); | |
474 | |
475 currently_fullscreen = 1; | |
476 } | |
477 | |
478 | |
479 | |
480 return 1; | |
481 } | |
482 | |
483 int ph_LeaveFullScreen(_THIS ) | |
484 { | |
485 PgDisplaySettings_t mymode_settings; | |
486 | |
487 if ( currently_fullscreen ) | |
488 { | |
489 PdDirectStop(OCImage.direct_context); | |
490 PdReleaseDirectContext(OCImage.direct_context); | |
491 | |
492 //Restore old video mode | |
493 if (old_video_mode != -1) | |
494 { | |
495 mymode_settings.mode= (unsigned short) old_video_mode; | |
496 mymode_settings.refresh= (unsigned short) old_refresh_rate; | |
497 mymode_settings.flags = 0; | |
498 if(PgSetVideoMode(&mymode_settings) < 0) | |
499 { | |
500 fprintf(stderr,"error: PgSetVideoMode failed\n"); | |
501 } | |
502 } | |
503 | |
504 old_video_mode=-1; | |
505 old_refresh_rate=-1; | |
506 | |
507 // Restore cursor | |
508 | |
509 } | |
510 return 1; | |
511 } |