Mercurial > sdl-ios-xcode
comparison src/video/photon/SDL_ph_modes.c @ 1662:782fd950bd46 SDL-1.3
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid.
The code is now run through a consistent indent format:
indent -i4 -nut -nsc -br -ce
The headers are being converted to automatically generate doxygen documentation.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 28 May 2006 13:04:16 +0000 |
parents | e49147870aac |
children | 4da1ee79c9af |
comparison
equal
deleted
inserted
replaced
1661:281d3f4870e5 | 1662:782fd950bd46 |
---|---|
25 | 25 |
26 static PgVideoModeInfo_t mode_info; | 26 static PgVideoModeInfo_t mode_info; |
27 static PgVideoModes_t mode_list; | 27 static PgVideoModes_t mode_list; |
28 | 28 |
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 compare_modes_by_res(const void* mode1, const void* mode2) | 33 static int |
34 compare_modes_by_res (const void *mode1, const void *mode2) | |
34 { | 35 { |
35 PgVideoModeInfo_t mode1_info; | 36 PgVideoModeInfo_t mode1_info; |
36 PgVideoModeInfo_t mode2_info; | 37 PgVideoModeInfo_t mode2_info; |
37 | 38 |
38 if (PgGetVideoModeInfo(*(unsigned short*)mode1, &mode1_info) < 0) | 39 if (PgGetVideoModeInfo (*(unsigned short *) mode1, &mode1_info) < 0) { |
39 { | |
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 { | |
45 return 0; | 44 return 0; |
46 } | 45 } |
47 | 46 |
48 if (mode1_info.width == mode2_info.width) | 47 if (mode1_info.width == mode2_info.width) { |
49 { | |
50 return mode2_info.height - mode1_info.height; | 48 return mode2_info.height - mode1_info.height; |
51 } | 49 } else { |
52 else | |
53 { | |
54 return mode2_info.width - mode1_info.width; | 50 return mode2_info.width - mode1_info.width; |
55 } | 51 } |
56 } | 52 } |
57 | 53 |
58 SDL_Rect **ph_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) | 54 SDL_Rect ** |
55 ph_ListModes (_THIS, SDL_PixelFormat * format, Uint32 flags) | |
59 { | 56 { |
60 int i = 0; | 57 int i = 0; |
61 int j = 0; | 58 int j = 0; |
62 SDL_Rect Amodelist[PH_MAX_VIDEOMODES]; | 59 SDL_Rect Amodelist[PH_MAX_VIDEOMODES]; |
63 | 60 |
64 for (i=0; i<PH_MAX_VIDEOMODES; i++) | 61 for (i = 0; i < PH_MAX_VIDEOMODES; i++) { |
65 { | 62 SDL_modearray[i] = &SDL_modelist[i]; |
66 SDL_modearray[i]=&SDL_modelist[i]; | 63 } |
67 } | 64 |
68 | 65 if (PgGetVideoModeList (&mode_list) < 0) { |
69 if (PgGetVideoModeList(&mode_list) < 0) | 66 SDL_SetError |
70 { | 67 ("ph_ListModes(): PgGetVideoModeList() function failed !\n"); |
71 SDL_SetError("ph_ListModes(): PgGetVideoModeList() function failed !\n"); | 68 return NULL; |
72 return NULL; | |
73 } | 69 } |
74 | 70 |
75 mode_info.bits_per_pixel = 0; | 71 mode_info.bits_per_pixel = 0; |
76 | 72 |
77 for (i=0; i < mode_list.num_modes; i++) | 73 for (i = 0; i < mode_list.num_modes; i++) { |
78 { | 74 if (PgGetVideoModeInfo (mode_list.modes[i], &mode_info) < 0) { |
79 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0) | 75 SDL_SetError |
80 { | 76 ("ph_ListModes(): PgGetVideoModeInfo() function failed on mode: 0x%X.\n", |
81 SDL_SetError("ph_ListModes(): PgGetVideoModeInfo() function failed on mode: 0x%X.\n", mode_list.modes[i]); | 77 mode_list.modes[i]); |
82 return NULL; | 78 return NULL; |
83 } | 79 } |
84 if(mode_info.bits_per_pixel == format->BitsPerPixel) | 80 if (mode_info.bits_per_pixel == format->BitsPerPixel) { |
85 { | |
86 Amodelist[j].w = mode_info.width; | 81 Amodelist[j].w = mode_info.width; |
87 Amodelist[j].h = mode_info.height; | 82 Amodelist[j].h = mode_info.height; |
88 Amodelist[j].x = 0; | 83 Amodelist[j].x = 0; |
89 Amodelist[j].y = 0; | 84 Amodelist[j].y = 0; |
90 j++; | 85 j++; |
91 } | 86 } |
92 } | 87 } |
93 | 88 |
94 /* reorder biggest for smallest, assume width dominates */ | 89 /* reorder biggest for smallest, assume width dominates */ |
95 | 90 |
96 for(i=0; i<j; i++) | 91 for (i = 0; i < j; i++) { |
97 { | |
98 SDL_modelist[i].w = Amodelist[j - i - 1].w; | 92 SDL_modelist[i].w = Amodelist[j - i - 1].w; |
99 SDL_modelist[i].h = Amodelist[j - i - 1].h; | 93 SDL_modelist[i].h = Amodelist[j - i - 1].h; |
100 SDL_modelist[i].x = Amodelist[j - i - 1].x; | 94 SDL_modelist[i].x = Amodelist[j - i - 1].x; |
101 SDL_modelist[i].y = Amodelist[j - i - 1].y; | 95 SDL_modelist[i].y = Amodelist[j - i - 1].y; |
102 } | 96 } |
103 SDL_modearray[j]=NULL; | 97 SDL_modearray[j] = NULL; |
104 | 98 |
105 return SDL_modearray; | 99 return SDL_modearray; |
106 } | 100 } |
107 | 101 |
108 void ph_FreeVideoModes(_THIS) | 102 void |
109 { | 103 ph_FreeVideoModes (_THIS) |
110 return; | 104 { |
105 return; | |
111 } | 106 } |
112 | 107 |
113 /* return the mode associated with width, height and bpp */ | 108 /* return the mode associated with width, height and bpp */ |
114 /* if there is no mode then zero is returned */ | 109 /* if there is no mode then zero is returned */ |
115 int ph_GetVideoMode(int width, int height, int bpp) | 110 int |
111 ph_GetVideoMode (int width, int height, int bpp) | |
116 { | 112 { |
117 int i; | 113 int i; |
118 int modestage=0; | 114 int modestage = 0; |
119 int closestmode=0; | 115 int closestmode = 0; |
120 | 116 |
121 if (PgGetVideoModeList(&mode_list) < 0) | 117 if (PgGetVideoModeList (&mode_list) < 0) { |
122 { | |
123 return -1; | 118 return -1; |
124 } | 119 } |
125 | 120 |
126 /* special case for the double-sized 320x200 mode */ | 121 /* special case for the double-sized 320x200 mode */ |
127 if ((width==640) && (height==400)) | 122 if ((width == 640) && (height == 400)) { |
128 { | 123 modestage = 1; |
129 modestage=1; | |
130 } | 124 } |
131 | 125 |
132 /* search list for exact match */ | 126 /* search list for exact match */ |
133 for (i=0; i<mode_list.num_modes; i++) | 127 for (i = 0; i < mode_list.num_modes; i++) { |
134 { | 128 if (PgGetVideoModeInfo (mode_list.modes[i], &mode_info) < 0) { |
135 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0) | |
136 { | |
137 return 0; | 129 return 0; |
138 } | 130 } |
139 | 131 |
140 if ((mode_info.width == width) && (mode_info.height == height) && | 132 if ((mode_info.width == width) && (mode_info.height == height) && |
141 (mode_info.bits_per_pixel == bpp)) | 133 (mode_info.bits_per_pixel == bpp)) { |
142 { | |
143 return mode_list.modes[i]; | 134 return mode_list.modes[i]; |
144 } | 135 } else { |
145 else | 136 if ((modestage) && (mode_info.width == width) |
146 { | 137 && (mode_info.height == height + 80) |
147 if ((modestage) && (mode_info.width == width) && (mode_info.height == height+80) && | 138 && (mode_info.bits_per_pixel == bpp)) { |
148 (mode_info.bits_per_pixel == bpp)) | 139 modestage = 2; |
149 { | 140 closestmode = mode_list.modes[i]; |
150 modestage=2; | 141 } |
151 closestmode=mode_list.modes[i]; | |
152 } | |
153 } | 142 } |
154 } | 143 } |
155 | 144 |
156 /* if we are here, then no 640x400xbpp mode found and we'll emulate it via 640x480xbpp mode */ | 145 /* if we are here, then no 640x400xbpp mode found and we'll emulate it via 640x480xbpp mode */ |
157 if (modestage==2) | 146 if (modestage == 2) { |
158 { | 147 return closestmode; |
159 return closestmode; | |
160 } | 148 } |
161 | 149 |
162 return (i == mode_list.num_modes) ? 0 : mode_list.modes[i]; | 150 return (i == mode_list.num_modes) ? 0 : mode_list.modes[i]; |
163 } | 151 } |
164 | 152 |
165 /* return the mode associated with width, height and bpp */ | 153 /* return the mode associated with width, height and bpp */ |
166 /* 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 */ |
167 int get_mode_any_format(int width, int height, int bpp) | 155 int |
156 get_mode_any_format (int width, int height, int bpp) | |
168 { | 157 { |
169 int i, closest, delta, min_delta; | 158 int i, closest, delta, min_delta; |
170 | 159 |
171 if (PgGetVideoModeList(&mode_list) < 0) | 160 if (PgGetVideoModeList (&mode_list) < 0) { |
172 { | |
173 return -1; | 161 return -1; |
174 } | 162 } |
175 | 163 |
176 SDL_qsort(mode_list.modes, mode_list.num_modes, sizeof(unsigned short), compare_modes_by_res); | 164 SDL_qsort (mode_list.modes, mode_list.num_modes, sizeof (unsigned short), |
177 | 165 compare_modes_by_res); |
178 for(i=0;i<mode_list.num_modes;i++) | 166 |
179 { | 167 for (i = 0; i < mode_list.num_modes; i++) { |
180 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0) | 168 if (PgGetVideoModeInfo (mode_list.modes[i], &mode_info) < 0) { |
181 { | |
182 return 0; | 169 return 0; |
183 } | 170 } |
184 if ((mode_info.width == width) && (mode_info.height == height)) | 171 if ((mode_info.width == width) && (mode_info.height == height)) { |
185 { | 172 break; |
186 break; | 173 } |
187 } | 174 } |
188 } | 175 |
189 | 176 if (i < mode_list.num_modes) { |
190 if (i<mode_list.num_modes) | |
191 { | |
192 /* get closest bpp */ | 177 /* get closest bpp */ |
193 closest = i++; | 178 closest = i++; |
194 if (mode_info.bits_per_pixel == bpp) | 179 if (mode_info.bits_per_pixel == bpp) { |
195 { | |
196 return mode_list.modes[closest]; | 180 return mode_list.modes[closest]; |
197 } | 181 } |
198 | 182 |
199 min_delta = abs(mode_info.bits_per_pixel - bpp); | 183 min_delta = abs (mode_info.bits_per_pixel - bpp); |
200 | 184 |
201 while(1) | 185 while (1) { |
202 { | 186 if (PgGetVideoModeInfo (mode_list.modes[i], &mode_info) < 0) { |
203 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0) | |
204 { | |
205 return 0; | 187 return 0; |
206 } | 188 } |
207 | 189 |
208 if ((mode_info.width != width) || (mode_info.height != height)) | 190 if ((mode_info.width != width) |
209 { | 191 || (mode_info.height != height)) { |
210 break; | 192 break; |
211 } | 193 } else { |
212 else | 194 if (mode_info.bits_per_pixel == bpp) { |
213 { | |
214 if (mode_info.bits_per_pixel == bpp) | |
215 { | |
216 closest = i; | 195 closest = i; |
217 break; | 196 break; |
218 } | 197 } else { |
219 else | 198 delta = abs (mode_info.bits_per_pixel - bpp); |
220 { | 199 if (delta < min_delta) { |
221 delta = abs(mode_info.bits_per_pixel - bpp); | |
222 if (delta < min_delta) | |
223 { | |
224 closest = i; | 200 closest = i; |
225 min_delta = delta; | 201 min_delta = delta; |
226 } | 202 } |
227 i++; | 203 i++; |
228 } | 204 } |
232 } | 208 } |
233 | 209 |
234 return 0; | 210 return 0; |
235 } | 211 } |
236 | 212 |
237 int ph_ToggleFullScreen(_THIS, int on) | 213 int |
214 ph_ToggleFullScreen (_THIS, int on) | |
238 { | 215 { |
239 return -1; | 216 return -1; |
240 } | 217 } |
241 | 218 |
242 int ph_EnterFullScreen(_THIS, SDL_Surface* screen, int fmode) | 219 int |
220 ph_EnterFullScreen (_THIS, SDL_Surface * screen, int fmode) | |
243 { | 221 { |
244 PgDisplaySettings_t settings; | 222 PgDisplaySettings_t settings; |
245 int mode; | 223 int mode; |
246 char* refreshrate; | 224 char *refreshrate; |
247 int refreshratenum; | 225 int refreshratenum; |
248 | 226 |
249 if (!currently_fullscreen) | 227 if (!currently_fullscreen) { |
250 { | |
251 /* Get the video mode and set it */ | 228 /* Get the video mode and set it */ |
252 if (screen->flags & SDL_ANYFORMAT) | 229 if (screen->flags & SDL_ANYFORMAT) { |
253 { | 230 if ((mode = |
254 if ((mode = get_mode_any_format(screen->w, screen->h, screen->format->BitsPerPixel)) == 0) | 231 get_mode_any_format (screen->w, screen->h, |
255 { | 232 screen->format->BitsPerPixel)) == 0) { |
256 SDL_SetError("ph_EnterFullScreen(): can't find appropriate video mode !\n"); | 233 SDL_SetError |
234 ("ph_EnterFullScreen(): can't find appropriate video mode !\n"); | |
257 return 0; | 235 return 0; |
258 } | 236 } |
259 } | 237 } else { |
260 else | 238 if ((mode = |
261 { | 239 ph_GetVideoMode (screen->w, screen->h, |
262 if ((mode = ph_GetVideoMode(screen->w, screen->h, screen->format->BitsPerPixel)) == 0) | 240 screen->format->BitsPerPixel)) == 0) { |
263 { | 241 SDL_SetError |
264 SDL_SetError("ph_EnterFullScreen(): can't find appropriate video mode !\n"); | 242 ("ph_EnterFullScreen(): can't find appropriate video mode !\n"); |
265 return 0; | 243 return 0; |
266 } | 244 } |
267 if (PgGetVideoModeInfo(mode, &mode_info) < 0) | 245 if (PgGetVideoModeInfo (mode, &mode_info) < 0) { |
268 { | 246 SDL_SetError |
269 SDL_SetError("ph_EnterFullScreen(): can't get video mode capabilities !\n"); | 247 ("ph_EnterFullScreen(): can't get video mode capabilities !\n"); |
270 return 0; | 248 return 0; |
271 } | 249 } |
272 if (mode_info.height != screen->h) | 250 if (mode_info.height != screen->h) { |
273 { | 251 if ((mode_info.height == 480) && (screen->h == 400)) { |
274 if ((mode_info.height==480) && (screen->h==400)) | 252 videomode_emulatemode = 1; |
275 { | 253 } |
276 videomode_emulatemode=1; | 254 } else { |
277 } | 255 videomode_emulatemode = 0; |
278 } | |
279 else | |
280 { | |
281 videomode_emulatemode=0; | |
282 } | 256 } |
283 } | 257 } |
284 | 258 |
285 /* save old video mode caps */ | 259 /* save old video mode caps */ |
286 PgGetVideoMode(&settings); | 260 PgGetVideoMode (&settings); |
287 old_video_mode=settings.mode; | 261 old_video_mode = settings.mode; |
288 old_refresh_rate=settings.refresh; | 262 old_refresh_rate = settings.refresh; |
289 | 263 |
290 /* setup new video mode */ | 264 /* setup new video mode */ |
291 settings.mode = mode; | 265 settings.mode = mode; |
292 settings.refresh = 0; | 266 settings.refresh = 0; |
293 settings.flags = 0; | 267 settings.flags = 0; |
294 | 268 |
295 refreshrate=SDL_getenv("SDL_PHOTON_FULLSCREEN_REFRESH"); | 269 refreshrate = SDL_getenv ("SDL_PHOTON_FULLSCREEN_REFRESH"); |
296 if (refreshrate!=NULL) | 270 if (refreshrate != NULL) { |
297 { | 271 if (SDL_sscanf (refreshrate, "%d", &refreshratenum) == 1) { |
298 if (SDL_sscanf(refreshrate, "%d", &refreshratenum)==1) | 272 settings.refresh = refreshratenum; |
299 { | 273 } |
300 settings.refresh = refreshratenum; | 274 } |
301 } | 275 |
302 } | 276 if (PgSetVideoMode (&settings) < 0) { |
303 | 277 SDL_SetError |
304 if (PgSetVideoMode(&settings) < 0) | 278 ("ph_EnterFullScreen(): PgSetVideoMode() call failed !\n"); |
305 { | |
306 SDL_SetError("ph_EnterFullScreen(): PgSetVideoMode() call failed !\n"); | |
307 return 0; | 279 return 0; |
308 } | 280 } |
309 | 281 |
310 if (this->screen) | 282 if (this->screen) { |
311 { | 283 if (this->screen->flags & SDL_INTERNALOPENGL) { |
312 if (this->screen->flags & SDL_INTERNALOPENGL) | |
313 { | |
314 #if !SDL_VIDEO_OPENGL || (_NTO_VERSION < 630) | 284 #if !SDL_VIDEO_OPENGL || (_NTO_VERSION < 630) |
315 return 0; /* 6.3.0 */ | 285 return 0; /* 6.3.0 */ |
316 #endif | 286 #endif |
317 } | 287 } |
318 } | 288 } |
319 | 289 |
320 if (fmode==0) | 290 if (fmode == 0) { |
321 { | 291 if (OCImage.direct_context == NULL) { |
322 if (OCImage.direct_context==NULL) | 292 OCImage.direct_context = |
323 { | 293 (PdDirectContext_t *) PdCreateDirectContext (); |
324 OCImage.direct_context=(PdDirectContext_t*)PdCreateDirectContext(); | 294 if (!OCImage.direct_context) { |
325 if (!OCImage.direct_context) | 295 SDL_SetError |
326 { | 296 ("ph_EnterFullScreen(): Can't create direct context !\n"); |
327 SDL_SetError("ph_EnterFullScreen(): Can't create direct context !\n"); | 297 ph_LeaveFullScreen (this); |
328 ph_LeaveFullScreen(this); | |
329 return 0; | 298 return 0; |
330 } | 299 } |
331 } | 300 } |
332 OCImage.oldDC=PdDirectStart(OCImage.direct_context); | 301 OCImage.oldDC = PdDirectStart (OCImage.direct_context); |
333 } | 302 } |
334 | 303 |
335 currently_fullscreen = 1; | 304 currently_fullscreen = 1; |
336 } | 305 } |
337 PgFlush(); | 306 PgFlush (); |
338 | 307 |
339 return 1; | 308 return 1; |
340 } | 309 } |
341 | 310 |
342 int ph_LeaveFullScreen(_THIS) | 311 int |
312 ph_LeaveFullScreen (_THIS) | |
343 { | 313 { |
344 PgDisplaySettings_t oldmode_settings; | 314 PgDisplaySettings_t oldmode_settings; |
345 | 315 |
346 if (currently_fullscreen) | 316 if (currently_fullscreen) { |
347 { | 317 if ((this->screen) && (this->screen->flags & SDL_INTERNALOPENGL)) { |
348 if ((this->screen) && (this->screen->flags & SDL_INTERNALOPENGL)) | |
349 { | |
350 #if !SDL_VIDEO_OPENGL || (_NTO_VERSION < 630) | 318 #if !SDL_VIDEO_OPENGL || (_NTO_VERSION < 630) |
351 return 0; | 319 return 0; |
352 #endif | 320 #endif |
353 } | 321 } |
354 | 322 |
355 /* release routines starts here */ | 323 /* release routines starts here */ |
356 { | 324 { |
357 if (OCImage.direct_context) | 325 if (OCImage.direct_context) { |
358 { | 326 PdDirectStop (OCImage.direct_context); |
359 PdDirectStop(OCImage.direct_context); | 327 PdReleaseDirectContext (OCImage.direct_context); |
360 PdReleaseDirectContext(OCImage.direct_context); | 328 OCImage.direct_context = NULL; |
361 OCImage.direct_context=NULL; | 329 } |
362 } | 330 if (OCImage.oldDC) { |
363 if (OCImage.oldDC) | 331 PhDCSetCurrent (OCImage.oldDC); |
364 { | 332 OCImage.oldDC = NULL; |
365 PhDCSetCurrent(OCImage.oldDC); | 333 } |
366 OCImage.oldDC=NULL; | 334 |
367 } | 335 currently_fullscreen = 0; |
368 | |
369 currently_fullscreen=0; | |
370 | 336 |
371 /* Restore old video mode */ | 337 /* Restore old video mode */ |
372 if (old_video_mode != -1) | 338 if (old_video_mode != -1) { |
373 { | |
374 oldmode_settings.mode = (unsigned short) old_video_mode; | 339 oldmode_settings.mode = (unsigned short) old_video_mode; |
375 oldmode_settings.refresh = (unsigned short) old_refresh_rate; | 340 oldmode_settings.refresh = (unsigned short) old_refresh_rate; |
376 oldmode_settings.flags = 0; | 341 oldmode_settings.flags = 0; |
377 | 342 |
378 if (PgSetVideoMode(&oldmode_settings) < 0) | 343 if (PgSetVideoMode (&oldmode_settings) < 0) { |
379 { | 344 SDL_SetError |
380 SDL_SetError("Ph_LeaveFullScreen(): PgSetVideoMode() function failed !\n"); | 345 ("Ph_LeaveFullScreen(): PgSetVideoMode() function failed !\n"); |
381 return 0; | 346 return 0; |
382 } | 347 } |
383 } | 348 } |
384 | 349 |
385 old_video_mode=-1; | 350 old_video_mode = -1; |
386 old_refresh_rate=-1; | 351 old_refresh_rate = -1; |
387 } | 352 } |
388 } | 353 } |
389 return 1; | 354 return 1; |
390 } | 355 } |
356 | |
357 /* vi: set ts=4 sw=4 expandtab: */ |