Mercurial > sdl-ios-xcode
annotate 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 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
297
f6ffac90895c
Updated copyright information for 2002
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
3 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga |
0 | 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 { |
309
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
158 int i = 0; |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
159 int j = 0; |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
160 SDL_Rect Amodelist[PH_MAX_VIDEOMODES]; |
0 | 161 |
309
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
162 for (i=0; i<PH_MAX_VIDEOMODES; i++) |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
163 { |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
164 SDL_modearray[i]=&SDL_modelist[i]; |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
165 } |
0 | 166 |
309
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
167 if (PgGetVideoModeList( &mode_list ) < 0) |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
168 { |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
169 fprintf(stderr,"error: PgGetVideoModeList failed\n"); |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
170 return NULL; |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
171 } |
0 | 172 |
309
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
173 mode_info.bits_per_pixel = 0; |
0 | 174 |
309
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
175 for (i=0; i < mode_list.num_modes; i++) |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
176 { |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
177 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0) |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
178 { |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
179 fprintf(stderr,"error: PgGetVideoModeInfo failed on mode: 0x%x\n", mode_list.modes[i]); |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
180 return NULL; |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
181 } |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
182 if(mode_info.bits_per_pixel == format->BitsPerPixel) |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
183 { |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
184 Amodelist[j].w = mode_info.width; |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
185 Amodelist[j].h = mode_info.height; |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
186 Amodelist[j].x = 0; |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
187 Amodelist[j].y = 0; |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
188 j++; |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
189 } |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
190 } |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
191 |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
192 /* reorder biggest for smallest, assume width dominates */ |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
193 |
309
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
194 for(i=0; i<j; i++) |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
195 { |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
196 SDL_modelist[i].w = Amodelist[j - i -1].w; |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
197 SDL_modelist[i].h = Amodelist[j - i -1].h; |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
198 SDL_modelist[i].x = Amodelist[j - i -1].x; |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
199 SDL_modelist[i].y = Amodelist[j - i -1].y; |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
200 } |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
201 SDL_modearray[j]=NULL; |
0 | 202 |
309
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
203 return SDL_modearray; |
0 | 204 } |
205 | |
206 void ph_FreeVideoModes(_THIS) | |
207 { | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
208 return; |
0 | 209 } |
210 | |
211 static void set_best_resolution(_THIS, int width, int height) | |
212 { | |
213 | |
214 if ( use_vidmode ) { | |
215 PgDisplaySettings_t settings; | |
216 PgVideoModeInfo_t current_mode_info; | |
204
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
217 PgHWCaps_t my_hwcaps; |
0 | 218 unsigned short current_bpp; |
219 int i; | |
204
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
220 /* |
0 | 221 if (PgGetVideoMode( &settings ) < 0) |
222 { | |
223 fprintf(stderr,"error: PgGetVideoMode failed\n"); | |
224 return; | |
225 } | |
226 if (PgGetVideoModeInfo( settings.mode, ¤t_mode_info ) < 0) | |
227 { | |
228 fprintf(stderr,"error: PgGetVideoModeInfo failed\n"); | |
229 return; | |
230 } | |
204
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
231 */ |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
232 //lu_zero |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
233 if (PgGetGraphicsHWCaps(&my_hwcaps) < 0) |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
234 { |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
235 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
|
236 //that HAVE to work |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
237 } |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
238 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
|
239 { |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
240 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
|
241 } |
0 | 242 current_bpp = current_mode_info.bits_per_pixel; |
243 | |
244 if (PgGetVideoModeList(&mode_list) >= 0) | |
245 { | |
246 qsort(mode_list.modes, mode_list.num_modes, sizeof(unsigned short), compare_modes_by_res); | |
247 #ifdef PH_DEBUG | |
248 printf("Available modes:\n"); | |
249 for ( i = 0; i < mode_list.num_modes; ++i ) | |
250 { | |
251 PgGetVideoModeInfo(mode_list.modes[i], &mode_info); | |
252 printf("Mode %d: %dx%d\n", i, mode_info.width, mode_info.height); | |
253 } | |
254 #endif | |
255 for ( i = mode_list.num_modes-1; i >= 0 ; --i ) | |
256 { | |
257 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0) | |
258 { | |
259 fprintf(stderr,"error: PgGetVideoModeInfo failed\n"); | |
260 } | |
261 if ( (mode_info.width >= width) && | |
262 (mode_info.height >= height) && | |
263 (mode_info.bits_per_pixel == current_bpp) ) | |
264 break; | |
265 } | |
266 if (i >= 0) | |
267 { | |
268 if ( (mode_info.width != current_mode_info.width) || | |
269 (mode_info.height != current_mode_info.height) ) | |
270 { | |
271 settings.mode = mode_list.modes[i]; | |
272 if(PgSetVideoMode( &settings ) < 0) | |
273 { | |
274 fprintf(stderr,"error: PgSetVideoMode failed\n"); | |
275 } | |
276 } | |
277 } | |
278 } | |
279 } | |
280 } | |
281 | |
282 int ph_ResizeFullScreen(_THIS) | |
283 { | |
309
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
284 if (currently_fullscreen) { |
0 | 285 set_best_resolution(this, current_w, current_h); |
286 } | |
309
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
287 return (1); |
0 | 288 } |
289 | |
309
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
290 /* return the mode associated with width, height and bpp */ |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
291 /* if there is no mode then zero is returned */ |
0 | 292 int get_mode(int width, int height, int bpp) |
293 { | |
309
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
294 int i; |
0 | 295 |
309
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
296 if(width<640) |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
297 { |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
298 width=640; |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
299 } |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
300 if(height<480) |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
301 { |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
302 height=480; |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
303 } |
0 | 304 |
309
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
305 if (PgGetVideoModeList(&mode_list) < 0) |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
306 { |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
307 fprintf(stderr,"error: PgGetVideoModeList failed\n"); |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
308 return -1; |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
309 } |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
310 |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
311 /* search list for exact match */ |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
312 for (i=0;i<mode_list.num_modes;i++) |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
313 { |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
314 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0) |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
315 { |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
316 fprintf(stderr,"error: PgGetVideoModeInfo failed\n"); |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
317 return 0; |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
318 } |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
319 |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
320 if ((mode_info.width == width) && |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
321 (mode_info.height == height) && |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
322 (mode_info.bits_per_pixel == bpp)) |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
323 { |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
324 return mode_list.modes[i]; |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
325 } |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
326 } |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
327 |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
328 return (i == mode_list.num_modes) ? 0 : mode_list.modes[i]; |
0 | 329 } |
330 | |
331 int get_mode_any_format(int width, int height, int bpp) | |
332 /* return the mode associated with width, height and bpp */ | |
333 /* if requested bpp is not found the mode with closest bpp is returned */ | |
334 { | |
335 int i, closest, delta, min_delta; | |
336 | |
337 if (PgGetVideoModeList( &mode_list ) < 0) | |
338 { | |
339 fprintf(stderr,"error: PgGetVideoModeList failed\n"); | |
340 return -1; | |
341 } | |
342 | |
343 qsort(mode_list.modes, mode_list.num_modes, sizeof(unsigned short), compare_modes_by_res); | |
344 for(i=0;i<mode_list.num_modes;i++) | |
345 { | |
346 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0) | |
347 { | |
348 fprintf(stderr,"error: PgGetVideoModeInfo failed\n"); | |
349 return 0; | |
350 } | |
351 if ((mode_info.width == width) && | |
352 (mode_info.height == height)) | |
353 break; | |
354 } | |
355 if (i<mode_list.num_modes) | |
356 { | |
357 // get closest bpp | |
358 closest = i++; | |
359 if (mode_info.bits_per_pixel == bpp) | |
360 return mode_list.modes[ closest ]; | |
361 | |
362 min_delta = abs(mode_info.bits_per_pixel - bpp); | |
363 while(1) | |
364 { | |
365 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0) | |
366 { | |
367 fprintf(stderr,"error: PgGetVideoModeInfo failed\n"); | |
368 return 0; | |
369 } | |
370 | |
371 if ((mode_info.width != width) || | |
372 (mode_info.height != height)) | |
373 break; | |
374 else if (mode_info.bits_per_pixel == bpp) | |
375 { | |
376 closest = i; | |
377 break; | |
378 } | |
379 else | |
380 { | |
381 delta = abs(mode_info.bits_per_pixel - bpp); | |
382 if (delta < min_delta) | |
383 { | |
384 closest = i; | |
385 min_delta = delta; | |
386 } | |
387 i++; | |
388 } | |
389 } | |
390 return mode_list.modes[ closest ]; | |
391 } | |
392 else | |
309
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
393 return 0; |
0 | 394 } |
395 | |
396 void ph_WaitMapped(_THIS); | |
397 void ph_WaitUnmapped(_THIS); | |
398 void ph_QueueEnterFullScreen(_THIS); | |
399 | |
400 int ph_ToggleFullScreen(_THIS, int on) | |
401 { | |
309
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
402 if (currently_fullscreen) |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
403 { |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
404 return ph_LeaveFullScreen(this); |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
405 } |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
406 else |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
407 { |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
408 return ph_EnterFullScreen(this); |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
409 } |
0 | 410 |
309
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
411 return 0; |
0 | 412 } |
413 | |
414 int ph_EnterFullScreen(_THIS) | |
415 { | |
309
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
416 if (!currently_fullscreen) |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
417 { |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
418 if ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL) |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
419 { |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
420 #ifdef HAVE_OPENGL |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
421 #endif /* HAVE_OPENGL */ |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
422 return 0; |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
423 } |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
424 else |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
425 { |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
426 if (old_video_mode==-1) |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
427 { |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
428 PgGetGraphicsHWCaps(&graphics_card_caps); |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
429 old_video_mode=graphics_card_caps.current_video_mode; |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
430 old_refresh_rate=graphics_card_caps.current_rrate; |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
431 } |
0 | 432 |
309
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
433 if(OCImage.direct_context == NULL) |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
434 { |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
435 OCImage.direct_context=(PdDirectContext_t*)PdCreateDirectContext(); |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
436 } |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
437 if(!OCImage.direct_context) |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
438 { |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
439 fprintf(stderr, "error: Can't create direct context\n" ); |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
440 } |
0 | 441 |
309
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
442 PdDirectStart(OCImage.direct_context); |
0 | 443 |
309
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
444 currently_fullscreen = 1; |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
445 } |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
446 } |
0 | 447 |
309
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
448 return 1; |
0 | 449 } |
450 | |
451 int ph_LeaveFullScreen(_THIS ) | |
452 { | |
309
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
453 PgDisplaySettings_t mymode_settings; |
0 | 454 |
309
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
455 if (currently_fullscreen) |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
456 { |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
457 if ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL) |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
458 { |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
459 #ifdef HAVE_OPENGL |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
460 #endif /* HAVE_OPENGL */ |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
461 return 0; |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
462 } |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
463 else |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
464 { |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
465 PdDirectStop(OCImage.direct_context); |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
466 PdReleaseDirectContext(OCImage.direct_context); |
0 | 467 |
309
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
468 /* Restore old video mode */ |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
469 if (old_video_mode != -1) |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
470 { |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
471 mymode_settings.mode= (unsigned short) old_video_mode; |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
472 mymode_settings.refresh= (unsigned short) old_refresh_rate; |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
473 mymode_settings.flags = 0; |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
474 if (PgSetVideoMode(&mymode_settings) < 0) |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
475 { |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
476 fprintf(stderr,"error: PgSetVideoMode failed\n"); |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
477 } |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
478 } |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
479 |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
480 old_video_mode=-1; |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
481 old_refresh_rate=-1; |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
482 } |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
483 |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
484 } |
2de77f7b7a28
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
485 return 1; |
0 | 486 } |