Mercurial > sdl-ios-xcode
annotate src/video/photon/SDL_ph_modes.c @ 288:2f5a6062db86
Updated for Watcom C++ and LCC compilers
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 28 Feb 2002 00:28:26 +0000 |
parents | c6abdda2f666 |
children | f6ffac90895c |
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 #include "SDL_ph_modes_c.h" | |
29 | |
30 static unsigned long key1, key2; | |
31 static PgVideoModeInfo_t mode_info; | |
32 static PgVideoModes_t mode_list; | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
33 |
0 | 34 /* The current list of available video modes */ |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
35 SDL_Rect SDL_modelist[PH_MAX_VIDEOMODES]; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
36 SDL_Rect* SDL_modearray[PH_MAX_VIDEOMODES]; |
0 | 37 |
38 static int compare_modes_by_res(const void* mode1, const void* mode2) | |
39 { | |
40 | |
41 if (PgGetVideoModeInfo(*(unsigned short*)mode1, &mode_info) < 0) | |
42 { | |
43 fprintf(stderr,"error: In compare_modes_by_res PgGetVideoModeInfo failed on mode: 0x%x\n", | |
44 *(unsigned short*)mode1); | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
45 return 0; |
0 | 46 } |
47 key1 = mode_info.width * mode_info.height; | |
48 | |
49 if (PgGetVideoModeInfo(*(unsigned short*)mode2, &mode_info) < 0) | |
50 { | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
51 fprintf(stderr,"error: In compare_modes_by_res PgGetVideoModeInfo failed on mode: 0x%x\n", |
0 | 52 *(unsigned short*)mode2); |
53 return 0; | |
54 } | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
55 key2 = mode_info.width * mode_info.height; |
0 | 56 |
57 if (key1 > key2) | |
58 return 1; | |
59 else if (key1 == key2) | |
60 return 0; | |
61 else | |
62 return -1; | |
63 } | |
64 | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
65 /* |
0 | 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 } | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
92 */ |
0 | 93 |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
94 /* |
0 | 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 } | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
154 */ |
0 | 155 |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
156 SDL_Rect **ph_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) |
0 | 157 { |
158 int i = 0; | |
159 int j = 0; | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
160 SDL_Rect Amodelist[PH_MAX_VIDEOMODES]; |
0 | 161 |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
162 for (i=0; i<PH_MAX_VIDEOMODES; i++) |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
163 { |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
164 SDL_modearray[i]=&SDL_modelist[i]; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
165 } |
0 | 166 |
167 if (PgGetVideoModeList( &mode_list ) < 0) | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
168 { |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
169 fprintf(stderr,"error: PgGetVideoModeList failed\n"); |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
170 return NULL; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
171 } |
0 | 172 |
173 mode_info.bits_per_pixel = 0; | |
174 | |
175 for (i=0; i < mode_list.num_modes; i++) | |
176 { | |
177 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0) | |
178 { | |
179 fprintf(stderr,"error: PgGetVideoModeInfo failed on mode: 0x%x\n", | |
180 mode_list.modes[i]); | |
181 return NULL; | |
182 } | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
183 |
0 | 184 if(mode_info.bits_per_pixel == format->BitsPerPixel) |
185 { | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
186 Amodelist[j].w = mode_info.width; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
187 Amodelist[j].h = mode_info.height; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
188 Amodelist[j].x = 0; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
189 Amodelist[j].y = 0; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
190 j++; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
191 } |
0 | 192 } |
193 | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
194 //reorder biggest for smallest, assume width dominates |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
195 |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
196 for(i=0; i< j ; i++) |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
197 { |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
198 SDL_modelist[i].w = Amodelist[j - i -1].w; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
199 SDL_modelist[i].h = Amodelist[j - i -1].h; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
200 SDL_modelist[i].x = Amodelist[j - i -1].x; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
201 SDL_modelist[i].y = Amodelist[j - i -1].y; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
202 } |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
203 SDL_modearray[j]=NULL; |
0 | 204 |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
205 return SDL_modearray; |
0 | 206 } |
207 | |
208 void ph_FreeVideoModes(_THIS) | |
209 { | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
210 return; |
0 | 211 } |
212 | |
213 static void set_best_resolution(_THIS, int width, int height) | |
214 { | |
215 | |
216 if ( use_vidmode ) { | |
217 PgDisplaySettings_t settings; | |
218 PgVideoModeInfo_t current_mode_info; | |
204
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
219 PgHWCaps_t my_hwcaps; |
0 | 220 unsigned short current_bpp; |
221 int i; | |
204
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
222 /* |
0 | 223 if (PgGetVideoMode( &settings ) < 0) |
224 { | |
225 fprintf(stderr,"error: PgGetVideoMode failed\n"); | |
226 return; | |
227 } | |
228 if (PgGetVideoModeInfo( settings.mode, ¤t_mode_info ) < 0) | |
229 { | |
230 fprintf(stderr,"error: PgGetVideoModeInfo failed\n"); | |
231 return; | |
232 } | |
204
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
233 */ |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
234 //lu_zero |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
235 if (PgGetGraphicsHWCaps(&my_hwcaps) < 0) |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
236 { |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
237 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
|
238 //that HAVE to work |
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 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
|
241 { |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
242 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
|
243 } |
0 | 244 current_bpp = current_mode_info.bits_per_pixel; |
245 | |
246 if (PgGetVideoModeList(&mode_list) >= 0) | |
247 { | |
248 qsort(mode_list.modes, mode_list.num_modes, sizeof(unsigned short), compare_modes_by_res); | |
249 #ifdef PH_DEBUG | |
250 printf("Available modes:\n"); | |
251 for ( i = 0; i < mode_list.num_modes; ++i ) | |
252 { | |
253 PgGetVideoModeInfo(mode_list.modes[i], &mode_info); | |
254 printf("Mode %d: %dx%d\n", i, mode_info.width, mode_info.height); | |
255 } | |
256 #endif | |
257 for ( i = mode_list.num_modes-1; i >= 0 ; --i ) | |
258 { | |
259 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0) | |
260 { | |
261 fprintf(stderr,"error: PgGetVideoModeInfo failed\n"); | |
262 } | |
263 if ( (mode_info.width >= width) && | |
264 (mode_info.height >= height) && | |
265 (mode_info.bits_per_pixel == current_bpp) ) | |
266 break; | |
267 } | |
268 if (i >= 0) | |
269 { | |
270 if ( (mode_info.width != current_mode_info.width) || | |
271 (mode_info.height != current_mode_info.height) ) | |
272 { | |
273 settings.mode = mode_list.modes[i]; | |
274 if(PgSetVideoMode( &settings ) < 0) | |
275 { | |
276 fprintf(stderr,"error: PgSetVideoMode failed\n"); | |
277 } | |
278 } | |
279 } | |
280 } | |
281 } | |
282 } | |
283 | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
284 /* |
0 | 285 static void get_real_resolution(_THIS, int* w, int* h) |
286 { | |
287 | |
288 if ( use_vidmode ) { | |
204
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
289 //PgDisplaySettings_t settings; |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
290 PgVideoModeInfo_t current_mode_info; |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
291 PgHWCaps_t my_hwcaps; |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
292 // int unused; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
293 |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
294 // if (PgGetVideoMode( &settings ) >= 0) { |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
295 // *w = settings.xres; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
296 // *h = settings.yres; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
297 // return; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
298 // } |
204
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
299 if (PgGetGraphicsHWCaps(&my_hwcaps) >= 0) |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
300 { |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
301 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
|
302 { |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
303 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
|
304 } |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
305 *w = current_mode_info.width; |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
306 *h = current_mode_info.height; |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
307 } |
0 | 308 } |
309 // *w = DisplayWidth(SDL_Display, SDL_Screen); | |
310 // *h = DisplayHeight(SDL_Display, SDL_Screen); | |
311 } | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
312 */ |
0 | 313 |
314 int ph_ResizeFullScreen(_THIS) | |
315 { | |
316 | |
317 if ( currently_fullscreen ) { | |
318 set_best_resolution(this, current_w, current_h); | |
319 } | |
320 return(1); | |
321 } | |
322 | |
323 int get_mode(int width, int height, int bpp) | |
324 /* return the mode associated with width, height and bpp */ | |
325 /* if there is no mode then zero is returned */ | |
326 { | |
327 int i; | |
328 | |
329 | |
330 if(width <640) | |
331 width = 640; | |
332 if(height < 480) | |
333 height = 480; | |
334 | |
335 | |
336 if (PgGetVideoModeList( &mode_list ) < 0) | |
337 { | |
338 fprintf(stderr,"error: PgGetVideoModeList failed\n"); | |
339 return -1; | |
340 } | |
341 | |
342 // search list for exact match | |
343 for (i=0;i<mode_list.num_modes;i++) | |
344 { | |
345 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0) | |
346 { | |
347 fprintf(stderr,"error: PgGetVideoModeInfo failed\n"); | |
348 return 0; | |
349 } | |
350 | |
351 | |
352 if ((mode_info.width == width) && | |
353 (mode_info.height == height) && | |
354 (mode_info.bits_per_pixel == bpp)) | |
355 { | |
356 return mode_list.modes[i]; | |
357 } | |
358 } | |
359 return (i == mode_list.num_modes) ? 0 : mode_list.modes[i]; | |
360 } | |
361 | |
362 int get_mode_any_format(int width, int height, int bpp) | |
363 /* return the mode associated with width, height and bpp */ | |
364 /* if requested bpp is not found the mode with closest bpp is returned */ | |
365 { | |
366 int i, closest, delta, min_delta; | |
367 | |
368 if (PgGetVideoModeList( &mode_list ) < 0) | |
369 { | |
370 fprintf(stderr,"error: PgGetVideoModeList failed\n"); | |
371 return -1; | |
372 } | |
373 | |
374 qsort(mode_list.modes, mode_list.num_modes, sizeof(unsigned short), compare_modes_by_res); | |
375 for(i=0;i<mode_list.num_modes;i++) | |
376 { | |
377 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0) | |
378 { | |
379 fprintf(stderr,"error: PgGetVideoModeInfo failed\n"); | |
380 return 0; | |
381 } | |
382 if ((mode_info.width == width) && | |
383 (mode_info.height == height)) | |
384 break; | |
385 } | |
386 if (i<mode_list.num_modes) | |
387 { | |
388 // get closest bpp | |
389 closest = i++; | |
390 if (mode_info.bits_per_pixel == bpp) | |
391 return mode_list.modes[ closest ]; | |
392 | |
393 min_delta = abs(mode_info.bits_per_pixel - bpp); | |
394 while(1) | |
395 { | |
396 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0) | |
397 { | |
398 fprintf(stderr,"error: PgGetVideoModeInfo failed\n"); | |
399 return 0; | |
400 } | |
401 | |
402 if ((mode_info.width != width) || | |
403 (mode_info.height != height)) | |
404 break; | |
405 else if (mode_info.bits_per_pixel == bpp) | |
406 { | |
407 closest = i; | |
408 break; | |
409 } | |
410 else | |
411 { | |
412 delta = abs(mode_info.bits_per_pixel - bpp); | |
413 if (delta < min_delta) | |
414 { | |
415 closest = i; | |
416 min_delta = delta; | |
417 } | |
418 i++; | |
419 } | |
420 } | |
421 return mode_list.modes[ closest ]; | |
422 } | |
423 else | |
424 return 0; | |
425 } | |
426 | |
427 void ph_WaitMapped(_THIS); | |
428 void ph_WaitUnmapped(_THIS); | |
429 void ph_QueueEnterFullScreen(_THIS); | |
430 | |
431 int ph_ToggleFullScreen(_THIS, int on) | |
432 { | |
433 | |
434 if(currently_fullscreen) | |
435 ph_LeaveFullScreen(this); | |
436 else | |
437 ph_EnterFullScreen(this); | |
438 | |
439 return 0; | |
440 | |
441 } | |
442 | |
443 int ph_EnterFullScreen(_THIS) | |
444 { | |
445 if ( ! currently_fullscreen ) | |
446 { | |
447 | |
448 if (old_video_mode==-1) | |
449 { | |
450 PgGetGraphicsHWCaps(&graphics_card_caps); | |
451 old_video_mode=graphics_card_caps.current_video_mode; | |
452 old_refresh_rate=graphics_card_caps.current_rrate; | |
453 } | |
454 | |
455 | |
456 if(OCImage.direct_context == NULL) | |
457 OCImage.direct_context=(PdDirectContext_t*)PdCreateDirectContext(); | |
458 if( !OCImage.direct_context ) | |
459 fprintf(stderr, "error: Can't create direct context\n" ); | |
460 | |
461 | |
462 /* Remove the cursor if in full screen mode */ | |
463 /* | |
464 region_info.cursor_type = Ph_CURSOR_NONE; | |
465 region_info.rid=PtWidgetRid(window); | |
466 PhRegionChange(Ph_REGION_CURSOR,0,®ion_info,NULL,NULL); | |
467 */ | |
468 | |
469 PdDirectStart( OCImage.direct_context ); | |
470 | |
471 currently_fullscreen = 1; | |
472 } | |
473 | |
474 | |
475 | |
476 return 1; | |
477 } | |
478 | |
479 int ph_LeaveFullScreen(_THIS ) | |
480 { | |
481 PgDisplaySettings_t mymode_settings; | |
482 | |
483 if ( currently_fullscreen ) | |
484 { | |
485 PdDirectStop(OCImage.direct_context); | |
486 PdReleaseDirectContext(OCImage.direct_context); | |
487 | |
488 //Restore old video mode | |
489 if (old_video_mode != -1) | |
490 { | |
491 mymode_settings.mode= (unsigned short) old_video_mode; | |
492 mymode_settings.refresh= (unsigned short) old_refresh_rate; | |
493 mymode_settings.flags = 0; | |
494 if(PgSetVideoMode(&mymode_settings) < 0) | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
495 { |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
496 fprintf(stderr,"error: PgSetVideoMode failed\n"); |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
497 } |
0 | 498 } |
499 | |
500 old_video_mode=-1; | |
501 old_refresh_rate=-1; | |
502 | |
503 // Restore cursor | |
504 | |
505 } | |
506 return 1; | |
507 } |