Mercurial > sdl-ios-xcode
comparison src/video/photon/SDL_ph_modes.c @ 1668:4da1ee79c9af SDL-1.3
more tweaking indent options
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 29 May 2006 04:04:35 +0000 |
parents | 782fd950bd46 |
children |
comparison
equal
deleted
inserted
replaced
1667:1fddae038bc8 | 1668:4da1ee79c9af |
---|---|
29 /* The current list of available video modes */ | 29 /* The current list of available video modes */ |
30 SDL_Rect SDL_modelist[PH_MAX_VIDEOMODES]; | 30 SDL_Rect SDL_modelist[PH_MAX_VIDEOMODES]; |
31 SDL_Rect *SDL_modearray[PH_MAX_VIDEOMODES]; | 31 SDL_Rect *SDL_modearray[PH_MAX_VIDEOMODES]; |
32 | 32 |
33 static int | 33 static int |
34 compare_modes_by_res (const void *mode1, const void *mode2) | 34 compare_modes_by_res(const void *mode1, const void *mode2) |
35 { | 35 { |
36 PgVideoModeInfo_t mode1_info; | 36 PgVideoModeInfo_t mode1_info; |
37 PgVideoModeInfo_t mode2_info; | 37 PgVideoModeInfo_t mode2_info; |
38 | 38 |
39 if (PgGetVideoModeInfo (*(unsigned short *) mode1, &mode1_info) < 0) { | 39 if (PgGetVideoModeInfo(*(unsigned short *) mode1, &mode1_info) < 0) { |
40 return 0; | 40 return 0; |
41 } | 41 } |
42 | 42 |
43 if (PgGetVideoModeInfo (*(unsigned short *) mode2, &mode2_info) < 0) { | 43 if (PgGetVideoModeInfo(*(unsigned short *) mode2, &mode2_info) < 0) { |
44 return 0; | 44 return 0; |
45 } | 45 } |
46 | 46 |
47 if (mode1_info.width == mode2_info.width) { | 47 if (mode1_info.width == mode2_info.width) { |
48 return mode2_info.height - mode1_info.height; | 48 return mode2_info.height - mode1_info.height; |
50 return mode2_info.width - mode1_info.width; | 50 return mode2_info.width - mode1_info.width; |
51 } | 51 } |
52 } | 52 } |
53 | 53 |
54 SDL_Rect ** | 54 SDL_Rect ** |
55 ph_ListModes (_THIS, SDL_PixelFormat * format, Uint32 flags) | 55 ph_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags) |
56 { | 56 { |
57 int i = 0; | 57 int i = 0; |
58 int j = 0; | 58 int j = 0; |
59 SDL_Rect Amodelist[PH_MAX_VIDEOMODES]; | 59 SDL_Rect Amodelist[PH_MAX_VIDEOMODES]; |
60 | 60 |
61 for (i = 0; i < PH_MAX_VIDEOMODES; i++) { | 61 for (i = 0; i < PH_MAX_VIDEOMODES; i++) { |
62 SDL_modearray[i] = &SDL_modelist[i]; | 62 SDL_modearray[i] = &SDL_modelist[i]; |
63 } | 63 } |
64 | 64 |
65 if (PgGetVideoModeList (&mode_list) < 0) { | 65 if (PgGetVideoModeList(&mode_list) < 0) { |
66 SDL_SetError | 66 SDL_SetError |
67 ("ph_ListModes(): PgGetVideoModeList() function failed !\n"); | 67 ("ph_ListModes(): PgGetVideoModeList() function failed !\n"); |
68 return NULL; | 68 return NULL; |
69 } | 69 } |
70 | 70 |
71 mode_info.bits_per_pixel = 0; | 71 mode_info.bits_per_pixel = 0; |
72 | 72 |
73 for (i = 0; i < mode_list.num_modes; i++) { | 73 for (i = 0; i < mode_list.num_modes; i++) { |
74 if (PgGetVideoModeInfo (mode_list.modes[i], &mode_info) < 0) { | 74 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0) { |
75 SDL_SetError | 75 SDL_SetError |
76 ("ph_ListModes(): PgGetVideoModeInfo() function failed on mode: 0x%X.\n", | 76 ("ph_ListModes(): PgGetVideoModeInfo() function failed on mode: 0x%X.\n", |
77 mode_list.modes[i]); | 77 mode_list.modes[i]); |
78 return NULL; | 78 return NULL; |
79 } | 79 } |
98 | 98 |
99 return SDL_modearray; | 99 return SDL_modearray; |
100 } | 100 } |
101 | 101 |
102 void | 102 void |
103 ph_FreeVideoModes (_THIS) | 103 ph_FreeVideoModes(_THIS) |
104 { | 104 { |
105 return; | 105 return; |
106 } | 106 } |
107 | 107 |
108 /* return the mode associated with width, height and bpp */ | 108 /* return the mode associated with width, height and bpp */ |
109 /* if there is no mode then zero is returned */ | 109 /* if there is no mode then zero is returned */ |
110 int | 110 int |
111 ph_GetVideoMode (int width, int height, int bpp) | 111 ph_GetVideoMode(int width, int height, int bpp) |
112 { | 112 { |
113 int i; | 113 int i; |
114 int modestage = 0; | 114 int modestage = 0; |
115 int closestmode = 0; | 115 int closestmode = 0; |
116 | 116 |
117 if (PgGetVideoModeList (&mode_list) < 0) { | 117 if (PgGetVideoModeList(&mode_list) < 0) { |
118 return -1; | 118 return -1; |
119 } | 119 } |
120 | 120 |
121 /* special case for the double-sized 320x200 mode */ | 121 /* special case for the double-sized 320x200 mode */ |
122 if ((width == 640) && (height == 400)) { | 122 if ((width == 640) && (height == 400)) { |
123 modestage = 1; | 123 modestage = 1; |
124 } | 124 } |
125 | 125 |
126 /* search list for exact match */ | 126 /* search list for exact match */ |
127 for (i = 0; i < mode_list.num_modes; i++) { | 127 for (i = 0; i < mode_list.num_modes; i++) { |
128 if (PgGetVideoModeInfo (mode_list.modes[i], &mode_info) < 0) { | 128 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0) { |
129 return 0; | 129 return 0; |
130 } | 130 } |
131 | 131 |
132 if ((mode_info.width == width) && (mode_info.height == height) && | 132 if ((mode_info.width == width) && (mode_info.height == height) && |
133 (mode_info.bits_per_pixel == bpp)) { | 133 (mode_info.bits_per_pixel == bpp)) { |
151 } | 151 } |
152 | 152 |
153 /* return the mode associated with width, height and bpp */ | 153 /* return the mode associated with width, height and bpp */ |
154 /* if requested bpp is not found the mode with closest bpp is returned */ | 154 /* if requested bpp is not found the mode with closest bpp is returned */ |
155 int | 155 int |
156 get_mode_any_format (int width, int height, int bpp) | 156 get_mode_any_format(int width, int height, int bpp) |
157 { | 157 { |
158 int i, closest, delta, min_delta; | 158 int i, closest, delta, min_delta; |
159 | 159 |
160 if (PgGetVideoModeList (&mode_list) < 0) { | 160 if (PgGetVideoModeList(&mode_list) < 0) { |
161 return -1; | 161 return -1; |
162 } | 162 } |
163 | 163 |
164 SDL_qsort (mode_list.modes, mode_list.num_modes, sizeof (unsigned short), | 164 SDL_qsort(mode_list.modes, mode_list.num_modes, sizeof(unsigned short), |
165 compare_modes_by_res); | 165 compare_modes_by_res); |
166 | 166 |
167 for (i = 0; i < mode_list.num_modes; i++) { | 167 for (i = 0; i < mode_list.num_modes; i++) { |
168 if (PgGetVideoModeInfo (mode_list.modes[i], &mode_info) < 0) { | 168 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0) { |
169 return 0; | 169 return 0; |
170 } | 170 } |
171 if ((mode_info.width == width) && (mode_info.height == height)) { | 171 if ((mode_info.width == width) && (mode_info.height == height)) { |
172 break; | 172 break; |
173 } | 173 } |
178 closest = i++; | 178 closest = i++; |
179 if (mode_info.bits_per_pixel == bpp) { | 179 if (mode_info.bits_per_pixel == bpp) { |
180 return mode_list.modes[closest]; | 180 return mode_list.modes[closest]; |
181 } | 181 } |
182 | 182 |
183 min_delta = abs (mode_info.bits_per_pixel - bpp); | 183 min_delta = abs(mode_info.bits_per_pixel - bpp); |
184 | 184 |
185 while (1) { | 185 while (1) { |
186 if (PgGetVideoModeInfo (mode_list.modes[i], &mode_info) < 0) { | 186 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0) { |
187 return 0; | 187 return 0; |
188 } | 188 } |
189 | 189 |
190 if ((mode_info.width != width) | 190 if ((mode_info.width != width) |
191 || (mode_info.height != height)) { | 191 || (mode_info.height != height)) { |
193 } else { | 193 } else { |
194 if (mode_info.bits_per_pixel == bpp) { | 194 if (mode_info.bits_per_pixel == bpp) { |
195 closest = i; | 195 closest = i; |
196 break; | 196 break; |
197 } else { | 197 } else { |
198 delta = abs (mode_info.bits_per_pixel - bpp); | 198 delta = abs(mode_info.bits_per_pixel - bpp); |
199 if (delta < min_delta) { | 199 if (delta < min_delta) { |
200 closest = i; | 200 closest = i; |
201 min_delta = delta; | 201 min_delta = delta; |
202 } | 202 } |
203 i++; | 203 i++; |
209 | 209 |
210 return 0; | 210 return 0; |
211 } | 211 } |
212 | 212 |
213 int | 213 int |
214 ph_ToggleFullScreen (_THIS, int on) | 214 ph_ToggleFullScreen(_THIS, int on) |
215 { | 215 { |
216 return -1; | 216 return -1; |
217 } | 217 } |
218 | 218 |
219 int | 219 int |
220 ph_EnterFullScreen (_THIS, SDL_Surface * screen, int fmode) | 220 ph_EnterFullScreen(_THIS, SDL_Surface * screen, int fmode) |
221 { | 221 { |
222 PgDisplaySettings_t settings; | 222 PgDisplaySettings_t settings; |
223 int mode; | 223 int mode; |
224 char *refreshrate; | 224 char *refreshrate; |
225 int refreshratenum; | 225 int refreshratenum; |
226 | 226 |
227 if (!currently_fullscreen) { | 227 if (!currently_fullscreen) { |
228 /* Get the video mode and set it */ | 228 /* Get the video mode and set it */ |
229 if (screen->flags & SDL_ANYFORMAT) { | 229 if (screen->flags & SDL_ANYFORMAT) { |
230 if ((mode = | 230 if ((mode = |
231 get_mode_any_format (screen->w, screen->h, | 231 get_mode_any_format(screen->w, screen->h, |
232 screen->format->BitsPerPixel)) == 0) { | 232 screen->format->BitsPerPixel)) == 0) { |
233 SDL_SetError | 233 SDL_SetError |
234 ("ph_EnterFullScreen(): can't find appropriate video mode !\n"); | 234 ("ph_EnterFullScreen(): can't find appropriate video mode !\n"); |
235 return 0; | 235 return 0; |
236 } | 236 } |
237 } else { | 237 } else { |
238 if ((mode = | 238 if ((mode = |
239 ph_GetVideoMode (screen->w, screen->h, | 239 ph_GetVideoMode(screen->w, screen->h, |
240 screen->format->BitsPerPixel)) == 0) { | 240 screen->format->BitsPerPixel)) == 0) { |
241 SDL_SetError | 241 SDL_SetError |
242 ("ph_EnterFullScreen(): can't find appropriate video mode !\n"); | 242 ("ph_EnterFullScreen(): can't find appropriate video mode !\n"); |
243 return 0; | 243 return 0; |
244 } | 244 } |
245 if (PgGetVideoModeInfo (mode, &mode_info) < 0) { | 245 if (PgGetVideoModeInfo(mode, &mode_info) < 0) { |
246 SDL_SetError | 246 SDL_SetError |
247 ("ph_EnterFullScreen(): can't get video mode capabilities !\n"); | 247 ("ph_EnterFullScreen(): can't get video mode capabilities !\n"); |
248 return 0; | 248 return 0; |
249 } | 249 } |
250 if (mode_info.height != screen->h) { | 250 if (mode_info.height != screen->h) { |
255 videomode_emulatemode = 0; | 255 videomode_emulatemode = 0; |
256 } | 256 } |
257 } | 257 } |
258 | 258 |
259 /* save old video mode caps */ | 259 /* save old video mode caps */ |
260 PgGetVideoMode (&settings); | 260 PgGetVideoMode(&settings); |
261 old_video_mode = settings.mode; | 261 old_video_mode = settings.mode; |
262 old_refresh_rate = settings.refresh; | 262 old_refresh_rate = settings.refresh; |
263 | 263 |
264 /* setup new video mode */ | 264 /* setup new video mode */ |
265 settings.mode = mode; | 265 settings.mode = mode; |
266 settings.refresh = 0; | 266 settings.refresh = 0; |
267 settings.flags = 0; | 267 settings.flags = 0; |
268 | 268 |
269 refreshrate = SDL_getenv ("SDL_PHOTON_FULLSCREEN_REFRESH"); | 269 refreshrate = SDL_getenv("SDL_PHOTON_FULLSCREEN_REFRESH"); |
270 if (refreshrate != NULL) { | 270 if (refreshrate != NULL) { |
271 if (SDL_sscanf (refreshrate, "%d", &refreshratenum) == 1) { | 271 if (SDL_sscanf(refreshrate, "%d", &refreshratenum) == 1) { |
272 settings.refresh = refreshratenum; | 272 settings.refresh = refreshratenum; |
273 } | 273 } |
274 } | 274 } |
275 | 275 |
276 if (PgSetVideoMode (&settings) < 0) { | 276 if (PgSetVideoMode(&settings) < 0) { |
277 SDL_SetError | 277 SDL_SetError |
278 ("ph_EnterFullScreen(): PgSetVideoMode() call failed !\n"); | 278 ("ph_EnterFullScreen(): PgSetVideoMode() call failed !\n"); |
279 return 0; | 279 return 0; |
280 } | 280 } |
281 | 281 |
288 } | 288 } |
289 | 289 |
290 if (fmode == 0) { | 290 if (fmode == 0) { |
291 if (OCImage.direct_context == NULL) { | 291 if (OCImage.direct_context == NULL) { |
292 OCImage.direct_context = | 292 OCImage.direct_context = |
293 (PdDirectContext_t *) PdCreateDirectContext (); | 293 (PdDirectContext_t *) PdCreateDirectContext(); |
294 if (!OCImage.direct_context) { | 294 if (!OCImage.direct_context) { |
295 SDL_SetError | 295 SDL_SetError |
296 ("ph_EnterFullScreen(): Can't create direct context !\n"); | 296 ("ph_EnterFullScreen(): Can't create direct context !\n"); |
297 ph_LeaveFullScreen (this); | 297 ph_LeaveFullScreen(this); |
298 return 0; | 298 return 0; |
299 } | 299 } |
300 } | 300 } |
301 OCImage.oldDC = PdDirectStart (OCImage.direct_context); | 301 OCImage.oldDC = PdDirectStart(OCImage.direct_context); |
302 } | 302 } |
303 | 303 |
304 currently_fullscreen = 1; | 304 currently_fullscreen = 1; |
305 } | 305 } |
306 PgFlush (); | 306 PgFlush(); |
307 | 307 |
308 return 1; | 308 return 1; |
309 } | 309 } |
310 | 310 |
311 int | 311 int |
312 ph_LeaveFullScreen (_THIS) | 312 ph_LeaveFullScreen(_THIS) |
313 { | 313 { |
314 PgDisplaySettings_t oldmode_settings; | 314 PgDisplaySettings_t oldmode_settings; |
315 | 315 |
316 if (currently_fullscreen) { | 316 if (currently_fullscreen) { |
317 if ((this->screen) && (this->screen->flags & SDL_INTERNALOPENGL)) { | 317 if ((this->screen) && (this->screen->flags & SDL_INTERNALOPENGL)) { |
321 } | 321 } |
322 | 322 |
323 /* release routines starts here */ | 323 /* release routines starts here */ |
324 { | 324 { |
325 if (OCImage.direct_context) { | 325 if (OCImage.direct_context) { |
326 PdDirectStop (OCImage.direct_context); | 326 PdDirectStop(OCImage.direct_context); |
327 PdReleaseDirectContext (OCImage.direct_context); | 327 PdReleaseDirectContext(OCImage.direct_context); |
328 OCImage.direct_context = NULL; | 328 OCImage.direct_context = NULL; |
329 } | 329 } |
330 if (OCImage.oldDC) { | 330 if (OCImage.oldDC) { |
331 PhDCSetCurrent (OCImage.oldDC); | 331 PhDCSetCurrent(OCImage.oldDC); |
332 OCImage.oldDC = NULL; | 332 OCImage.oldDC = NULL; |
333 } | 333 } |
334 | 334 |
335 currently_fullscreen = 0; | 335 currently_fullscreen = 0; |
336 | 336 |
338 if (old_video_mode != -1) { | 338 if (old_video_mode != -1) { |
339 oldmode_settings.mode = (unsigned short) old_video_mode; | 339 oldmode_settings.mode = (unsigned short) old_video_mode; |
340 oldmode_settings.refresh = (unsigned short) old_refresh_rate; | 340 oldmode_settings.refresh = (unsigned short) old_refresh_rate; |
341 oldmode_settings.flags = 0; | 341 oldmode_settings.flags = 0; |
342 | 342 |
343 if (PgSetVideoMode (&oldmode_settings) < 0) { | 343 if (PgSetVideoMode(&oldmode_settings) < 0) { |
344 SDL_SetError | 344 SDL_SetError |
345 ("Ph_LeaveFullScreen(): PgSetVideoMode() function failed !\n"); | 345 ("Ph_LeaveFullScreen(): PgSetVideoMode() function failed !\n"); |
346 return 0; | 346 return 0; |
347 } | 347 } |
348 } | 348 } |