Skip to content

Latest commit

 

History

History
314 lines (266 loc) · 7.62 KB

SDL_ph_modes.c

File metadata and controls

314 lines (266 loc) · 7.62 KB
 
Apr 26, 2001
Apr 26, 2001
1
2
/*
SDL - Simple DirectMedia Layer
Mar 6, 2002
Mar 6, 2002
3
Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga
Apr 26, 2001
Apr 26, 2001
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
Dec 14, 2001
Dec 14, 2001
20
slouken@libsdl.org
Apr 26, 2001
Apr 26, 2001
21
22
23
24
25
26
27
28
29
30
31
32
*/
#ifdef SAVE_RCSID
static char rcsid =
"@(#) $Id$";
#endif
#include "SDL_ph_modes_c.h"
static unsigned long key1, key2;
static PgVideoModeInfo_t mode_info;
static PgVideoModes_t mode_list;
Jan 18, 2002
Jan 18, 2002
33
Jan 20, 2003
Jan 20, 2003
34
/* The current list of available video modes */
Jan 18, 2002
Jan 18, 2002
35
36
SDL_Rect SDL_modelist[PH_MAX_VIDEOMODES];
SDL_Rect* SDL_modearray[PH_MAX_VIDEOMODES];
Apr 26, 2001
Apr 26, 2001
37
38
39
static int compare_modes_by_res(const void* mode1, const void* mode2)
{
Jan 20, 2003
Jan 20, 2003
40
41
42
43
44
45
if (PgGetVideoModeInfo(*(unsigned short*)mode1, &mode_info) < 0)
{
fprintf(stderr,"error: In compare_modes_by_res PgGetVideoModeInfo failed on mode: 0x%x\n",
*(unsigned short*)mode1);
return 0;
}
Apr 26, 2001
Apr 26, 2001
46
Jan 20, 2003
Jan 20, 2003
47
key1 = mode_info.width * mode_info.height;
Apr 26, 2001
Apr 26, 2001
48
Jan 20, 2003
Jan 20, 2003
49
50
51
52
53
54
if (PgGetVideoModeInfo(*(unsigned short*)mode2, &mode_info) < 0)
{
fprintf(stderr,"error: In compare_modes_by_res PgGetVideoModeInfo failed on mode: 0x%x\n",
*(unsigned short*)mode2);
return 0;
}
Apr 26, 2001
Apr 26, 2001
55
Jan 20, 2003
Jan 20, 2003
56
57
58
59
60
61
62
63
key2 = mode_info.width * mode_info.height;
if (key1 > key2)
return 1;
else if (key1 == key2)
return 0;
else
return -1;
Apr 26, 2001
Apr 26, 2001
64
65
}
Jan 18, 2002
Jan 18, 2002
66
SDL_Rect **ph_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
Apr 26, 2001
Apr 26, 2001
67
{
Mar 11, 2002
Mar 11, 2002
68
69
70
int i = 0;
int j = 0;
SDL_Rect Amodelist[PH_MAX_VIDEOMODES];
Apr 26, 2001
Apr 26, 2001
71
Mar 11, 2002
Mar 11, 2002
72
73
74
75
for (i=0; i<PH_MAX_VIDEOMODES; i++)
{
SDL_modearray[i]=&SDL_modelist[i];
}
Apr 26, 2001
Apr 26, 2001
76
Mar 11, 2002
Mar 11, 2002
77
78
79
80
81
if (PgGetVideoModeList( &mode_list ) < 0)
{
fprintf(stderr,"error: PgGetVideoModeList failed\n");
return NULL;
}
Apr 26, 2001
Apr 26, 2001
82
Mar 11, 2002
Mar 11, 2002
83
mode_info.bits_per_pixel = 0;
Jan 18, 2002
Jan 18, 2002
84
Mar 11, 2002
Mar 11, 2002
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
for (i=0; i < mode_list.num_modes; i++)
{
if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0)
{
fprintf(stderr,"error: PgGetVideoModeInfo failed on mode: 0x%x\n", mode_list.modes[i]);
return NULL;
}
if(mode_info.bits_per_pixel == format->BitsPerPixel)
{
Amodelist[j].w = mode_info.width;
Amodelist[j].h = mode_info.height;
Amodelist[j].x = 0;
Amodelist[j].y = 0;
j++;
}
}
Apr 26, 2001
Apr 26, 2001
101
Mar 11, 2002
Mar 11, 2002
102
/* reorder biggest for smallest, assume width dominates */
Apr 26, 2001
Apr 26, 2001
103
Mar 11, 2002
Mar 11, 2002
104
105
106
107
108
109
110
111
for(i=0; i<j; i++)
{
SDL_modelist[i].w = Amodelist[j - i -1].w;
SDL_modelist[i].h = Amodelist[j - i -1].h;
SDL_modelist[i].x = Amodelist[j - i -1].x;
SDL_modelist[i].y = Amodelist[j - i -1].y;
}
SDL_modearray[j]=NULL;
Jan 18, 2002
Jan 18, 2002
112
Mar 11, 2002
Mar 11, 2002
113
return SDL_modearray;
Apr 26, 2001
Apr 26, 2001
114
115
116
117
}
void ph_FreeVideoModes(_THIS)
{
Jan 18, 2002
Jan 18, 2002
118
return;
Apr 26, 2001
Apr 26, 2001
119
120
121
}
/* return the mode associated with width, height and bpp */
Mar 11, 2002
Mar 11, 2002
122
123
/* if there is no mode then zero is returned */
int get_mode(int width, int height, int bpp)
Apr 26, 2001
Apr 26, 2001
124
{
Mar 11, 2002
Mar 11, 2002
125
int i;
Apr 26, 2001
Apr 26, 2001
126
Mar 11, 2002
Mar 11, 2002
127
128
129
130
131
132
133
134
if(width<640)
{
width=640;
}
if(height<480)
{
height=480;
}
Apr 26, 2001
Apr 26, 2001
135
Mar 11, 2002
Mar 11, 2002
136
137
138
139
140
if (PgGetVideoModeList(&mode_list) < 0)
{
fprintf(stderr,"error: PgGetVideoModeList failed\n");
return -1;
}
Apr 26, 2001
Apr 26, 2001
141
Mar 11, 2002
Mar 11, 2002
142
143
144
145
146
147
148
149
/* search list for exact match */
for (i=0;i<mode_list.num_modes;i++)
{
if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0)
{
fprintf(stderr,"error: PgGetVideoModeInfo failed\n");
return 0;
}
Apr 26, 2001
Apr 26, 2001
150
Mar 11, 2002
Mar 11, 2002
151
152
153
154
155
156
157
if ((mode_info.width == width) &&
(mode_info.height == height) &&
(mode_info.bits_per_pixel == bpp))
{
return mode_list.modes[i];
}
}
Apr 26, 2001
Apr 26, 2001
158
Mar 11, 2002
Mar 11, 2002
159
return (i == mode_list.num_modes) ? 0 : mode_list.modes[i];
Apr 26, 2001
Apr 26, 2001
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
}
int get_mode_any_format(int width, int height, int bpp)
/* return the mode associated with width, height and bpp */
/* if requested bpp is not found the mode with closest bpp is returned */
{
int i, closest, delta, min_delta;
if (PgGetVideoModeList( &mode_list ) < 0)
{
fprintf(stderr,"error: PgGetVideoModeList failed\n");
return -1;
}
qsort(mode_list.modes, mode_list.num_modes, sizeof(unsigned short), compare_modes_by_res);
for(i=0;i<mode_list.num_modes;i++)
{
if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0)
{
fprintf(stderr,"error: PgGetVideoModeInfo failed\n");
return 0;
}
if ((mode_info.width == width) &&
(mode_info.height == height))
break;
}
if (i<mode_list.num_modes)
{
Mar 23, 2002
Mar 23, 2002
188
/* get closest bpp */
Apr 26, 2001
Apr 26, 2001
189
190
closest = i++;
if (mode_info.bits_per_pixel == bpp)
Jan 20, 2003
Jan 20, 2003
191
return mode_list.modes[closest];
Apr 26, 2001
Apr 26, 2001
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
min_delta = abs(mode_info.bits_per_pixel - bpp);
while(1)
{
if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0)
{
fprintf(stderr,"error: PgGetVideoModeInfo failed\n");
return 0;
}
if ((mode_info.width != width) ||
(mode_info.height != height))
break;
else if (mode_info.bits_per_pixel == bpp)
{
closest = i;
break;
}
else
{
delta = abs(mode_info.bits_per_pixel - bpp);
if (delta < min_delta)
{
closest = i;
min_delta = delta;
}
i++;
}
}
Jan 20, 2003
Jan 20, 2003
221
return mode_list.modes[closest];
Apr 26, 2001
Apr 26, 2001
222
223
}
else
Mar 11, 2002
Mar 11, 2002
224
return 0;
Apr 26, 2001
Apr 26, 2001
225
226
227
228
}
int ph_ToggleFullScreen(_THIS, int on)
{
Mar 11, 2002
Mar 11, 2002
229
230
231
232
233
234
235
236
if (currently_fullscreen)
{
return ph_LeaveFullScreen(this);
}
else
{
return ph_EnterFullScreen(this);
}
Apr 26, 2001
Apr 26, 2001
237
Mar 11, 2002
Mar 11, 2002
238
return 0;
Apr 26, 2001
Apr 26, 2001
239
240
241
242
}
int ph_EnterFullScreen(_THIS)
{
Mar 11, 2002
Mar 11, 2002
243
244
if (!currently_fullscreen)
{
Mar 23, 2002
Mar 23, 2002
245
if (this->screen)
Mar 11, 2002
Mar 11, 2002
246
{
Mar 23, 2002
Mar 23, 2002
247
248
if ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL)
{
Mar 11, 2002
Mar 11, 2002
249
250
#ifdef HAVE_OPENGL
#endif /* HAVE_OPENGL */
Mar 23, 2002
Mar 23, 2002
251
252
return 0;
}
Mar 11, 2002
Mar 11, 2002
253
}
Mar 23, 2002
Mar 23, 2002
254
Jan 20, 2003
Jan 20, 2003
255
if (OCImage.direct_context==NULL)
Mar 11, 2002
Mar 11, 2002
256
{
Mar 23, 2002
Mar 23, 2002
257
258
OCImage.direct_context=(PdDirectContext_t*)PdCreateDirectContext();
}
Apr 26, 2001
Apr 26, 2001
259
Mar 23, 2002
Mar 23, 2002
260
261
if (!OCImage.direct_context)
{
Jan 20, 2003
Jan 20, 2003
262
263
fprintf(stderr, "ph_EnterFullScreen(): Can't create direct context !\n");
return 0;
Mar 23, 2002
Mar 23, 2002
264
}
Apr 26, 2001
Apr 26, 2001
265
Jan 20, 2003
Jan 20, 2003
266
OCImage.oldDC=PdDirectStart(OCImage.direct_context);
Apr 26, 2001
Apr 26, 2001
267
Mar 23, 2002
Mar 23, 2002
268
currently_fullscreen = 1;
Mar 11, 2002
Mar 11, 2002
269
}
Apr 26, 2001
Apr 26, 2001
270
Mar 11, 2002
Mar 11, 2002
271
return 1;
Apr 26, 2001
Apr 26, 2001
272
273
}
Mar 23, 2002
Mar 23, 2002
274
int ph_LeaveFullScreen(_THIS)
Apr 26, 2001
Apr 26, 2001
275
{
Mar 11, 2002
Mar 11, 2002
276
PgDisplaySettings_t mymode_settings;
Apr 26, 2001
Apr 26, 2001
277
Mar 11, 2002
Mar 11, 2002
278
279
280
281
282
283
284
285
286
287
288
289
if (currently_fullscreen)
{
if ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL)
{
#ifdef HAVE_OPENGL
#endif /* HAVE_OPENGL */
return 0;
}
else
{
PdDirectStop(OCImage.direct_context);
PdReleaseDirectContext(OCImage.direct_context);
Jan 20, 2003
Jan 20, 2003
290
291
PhDCSetCurrent(OCImage.oldDC);
Mar 23, 2002
Mar 23, 2002
292
currently_fullscreen=0;
Apr 26, 2001
Apr 26, 2001
293
Mar 11, 2002
Mar 11, 2002
294
295
296
297
298
/* Restore old video mode */
if (old_video_mode != -1)
{
mymode_settings.mode= (unsigned short) old_video_mode;
mymode_settings.refresh= (unsigned short) old_refresh_rate;
Mar 23, 2002
Mar 23, 2002
299
300
mymode_settings.flags= 0;
Mar 11, 2002
Mar 11, 2002
301
302
if (PgSetVideoMode(&mymode_settings) < 0)
{
Jan 20, 2003
Jan 20, 2003
303
304
fprintf(stderr, "Ph_LeaveFullScreen(): PgSetVideoMode failed !\n");
return 0;
Mar 11, 2002
Mar 11, 2002
305
306
307
308
}
}
old_video_mode=-1;
Mar 23, 2002
Mar 23, 2002
309
old_refresh_rate=-1;
Mar 11, 2002
Mar 11, 2002
310
311
312
313
}
}
return 1;
Apr 26, 2001
Apr 26, 2001
314
}