slouken@1931
|
1 |
/*
|
slouken@5535
|
2 |
Simple DirectMedia Layer
|
slouken@5535
|
3 |
Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
|
slouken@1931
|
4 |
|
slouken@5535
|
5 |
This software is provided 'as-is', without any express or implied
|
slouken@5535
|
6 |
warranty. In no event will the authors be held liable for any damages
|
slouken@5535
|
7 |
arising from the use of this software.
|
slouken@1931
|
8 |
|
slouken@5535
|
9 |
Permission is granted to anyone to use this software for any purpose,
|
slouken@5535
|
10 |
including commercial applications, and to alter it and redistribute it
|
slouken@5535
|
11 |
freely, subject to the following restrictions:
|
slouken@1931
|
12 |
|
slouken@5535
|
13 |
1. The origin of this software must not be misrepresented; you must not
|
slouken@5535
|
14 |
claim that you wrote the original software. If you use this software
|
slouken@5535
|
15 |
in a product, an acknowledgment in the product documentation would be
|
slouken@5535
|
16 |
appreciated but is not required.
|
slouken@5535
|
17 |
2. Altered source versions must be plainly marked as such, and must not be
|
slouken@5535
|
18 |
misrepresented as being the original software.
|
slouken@5535
|
19 |
3. This notice may not be removed or altered from any source distribution.
|
slouken@1931
|
20 |
*/
|
slouken@1931
|
21 |
#include "SDL_config.h"
|
slouken@1931
|
22 |
|
slouken@6044
|
23 |
#if SDL_VIDEO_DRIVER_COCOA
|
slouken@6044
|
24 |
|
slouken@1931
|
25 |
#include "SDL_cocoavideo.h"
|
slouken@1931
|
26 |
|
icculus@6104
|
27 |
/* we need this for ShowMenuBar() and HideMenuBar(). */
|
icculus@6104
|
28 |
#include <Carbon/Carbon.h>
|
aschiffler@6101
|
29 |
|
icculus@6105
|
30 |
static inline void Cocoa_ToggleMenuBar(const BOOL show)
|
icculus@6105
|
31 |
{
|
icculus@6105
|
32 |
/* !!! FIXME: keep an eye on this.
|
icculus@6105
|
33 |
* ShowMenuBar/HideMenuBar is officially unavailable for 64-bit binaries.
|
icculus@6105
|
34 |
* It happens to work, as of 10.7, but we're going to see if
|
icculus@6105
|
35 |
* we can just simply do without it on newer OSes...
|
icculus@6105
|
36 |
*/
|
icculus@6105
|
37 |
#if (MAC_OS_X_VERSION_MIN_REQUIRED < 1070) && !defined(__LP64__)
|
icculus@6105
|
38 |
if (show)
|
icculus@6105
|
39 |
ShowMenuBar();
|
icculus@6105
|
40 |
else
|
icculus@6105
|
41 |
HideMenuBar();
|
icculus@6105
|
42 |
#endif
|
icculus@6105
|
43 |
}
|
icculus@6105
|
44 |
|
icculus@6105
|
45 |
|
icculus@5643
|
46 |
/* !!! FIXME: clean out the pre-10.6 code when it makes sense to do so. */
|
icculus@5643
|
47 |
#define FORCE_OLD_API 0 || (MAC_OS_X_VERSION_MAX_ALLOWED < 1060)
|
icculus@5643
|
48 |
|
icculus@5643
|
49 |
#if FORCE_OLD_API
|
icculus@5643
|
50 |
#undef MAC_OS_X_VERSION_MIN_REQUIRED
|
icculus@5646
|
51 |
#define MAC_OS_X_VERSION_MIN_REQUIRED 1050
|
icculus@5643
|
52 |
#endif
|
icculus@5643
|
53 |
|
icculus@5646
|
54 |
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1050
|
slouken@1973
|
55 |
/*
|
slouken@1973
|
56 |
Add methods to get at private members of NSScreen.
|
slouken@1973
|
57 |
Since there is a bug in Apple's screen switching code
|
slouken@1973
|
58 |
that does not update this variable when switching
|
slouken@1973
|
59 |
to fullscreen, we'll set it manually (but only for the
|
slouken@1973
|
60 |
main screen).
|
slouken@1973
|
61 |
*/
|
slouken@1973
|
62 |
@interface NSScreen (NSScreenAccess)
|
slouken@1973
|
63 |
- (void) setFrame:(NSRect)frame;
|
slouken@1973
|
64 |
@end
|
slouken@1973
|
65 |
|
slouken@1973
|
66 |
@implementation NSScreen (NSScreenAccess)
|
slouken@1973
|
67 |
- (void) setFrame:(NSRect)frame;
|
slouken@1973
|
68 |
{
|
slouken@1973
|
69 |
_frame = frame;
|
slouken@1973
|
70 |
}
|
slouken@1973
|
71 |
@end
|
slouken@3246
|
72 |
#endif
|
slouken@1973
|
73 |
|
icculus@5643
|
74 |
static inline BOOL
|
icculus@5643
|
75 |
IS_SNOW_LEOPARD_OR_LATER(_THIS)
|
icculus@5643
|
76 |
{
|
icculus@5643
|
77 |
#if FORCE_OLD_API
|
icculus@5643
|
78 |
return NO;
|
icculus@5643
|
79 |
#else
|
icculus@5643
|
80 |
return ((((SDL_VideoData *) _this->driverdata))->osversion >= 0x1060);
|
icculus@5643
|
81 |
#endif
|
icculus@5643
|
82 |
}
|
icculus@5643
|
83 |
|
slouken@1934
|
84 |
static void
|
slouken@1934
|
85 |
CG_SetError(const char *prefix, CGDisplayErr result)
|
slouken@1934
|
86 |
{
|
slouken@1934
|
87 |
const char *error;
|
slouken@1934
|
88 |
|
slouken@1934
|
89 |
switch (result) {
|
slouken@1934
|
90 |
case kCGErrorFailure:
|
slouken@1934
|
91 |
error = "kCGErrorFailure";
|
slouken@1934
|
92 |
break;
|
slouken@1934
|
93 |
case kCGErrorIllegalArgument:
|
slouken@1934
|
94 |
error = "kCGErrorIllegalArgument";
|
slouken@1934
|
95 |
break;
|
slouken@1934
|
96 |
case kCGErrorInvalidConnection:
|
slouken@1934
|
97 |
error = "kCGErrorInvalidConnection";
|
slouken@1934
|
98 |
break;
|
slouken@1934
|
99 |
case kCGErrorInvalidContext:
|
slouken@1934
|
100 |
error = "kCGErrorInvalidContext";
|
slouken@1934
|
101 |
break;
|
slouken@1934
|
102 |
case kCGErrorCannotComplete:
|
slouken@1934
|
103 |
error = "kCGErrorCannotComplete";
|
slouken@1934
|
104 |
break;
|
slouken@1934
|
105 |
case kCGErrorNameTooLong:
|
slouken@1934
|
106 |
error = "kCGErrorNameTooLong";
|
slouken@1934
|
107 |
break;
|
slouken@1934
|
108 |
case kCGErrorNotImplemented:
|
slouken@1934
|
109 |
error = "kCGErrorNotImplemented";
|
slouken@1934
|
110 |
break;
|
slouken@1934
|
111 |
case kCGErrorRangeCheck:
|
slouken@1934
|
112 |
error = "kCGErrorRangeCheck";
|
slouken@1934
|
113 |
break;
|
slouken@1934
|
114 |
case kCGErrorTypeCheck:
|
slouken@1934
|
115 |
error = "kCGErrorTypeCheck";
|
slouken@1934
|
116 |
break;
|
slouken@1934
|
117 |
case kCGErrorNoCurrentPoint:
|
slouken@1934
|
118 |
error = "kCGErrorNoCurrentPoint";
|
slouken@1934
|
119 |
break;
|
slouken@1934
|
120 |
case kCGErrorInvalidOperation:
|
slouken@1934
|
121 |
error = "kCGErrorInvalidOperation";
|
slouken@1934
|
122 |
break;
|
slouken@1934
|
123 |
case kCGErrorNoneAvailable:
|
slouken@1934
|
124 |
error = "kCGErrorNoneAvailable";
|
slouken@1934
|
125 |
break;
|
slouken@1934
|
126 |
default:
|
slouken@1934
|
127 |
error = "Unknown Error";
|
slouken@1934
|
128 |
break;
|
slouken@1934
|
129 |
}
|
slouken@1934
|
130 |
SDL_SetError("%s: %s", prefix, error);
|
slouken@1934
|
131 |
}
|
slouken@1934
|
132 |
|
slouken@1934
|
133 |
static SDL_bool
|
icculus@5643
|
134 |
GetDisplayMode(_THIS, const void *moderef, SDL_DisplayMode *mode)
|
slouken@1934
|
135 |
{
|
slouken@1934
|
136 |
SDL_DisplayModeData *data;
|
icculus@6072
|
137 |
long width = 0;
|
icculus@6072
|
138 |
long height = 0;
|
icculus@6072
|
139 |
long bpp = 0;
|
icculus@6072
|
140 |
long refreshRate = 0;
|
slouken@1934
|
141 |
|
slouken@1934
|
142 |
data = (SDL_DisplayModeData *) SDL_malloc(sizeof(*data));
|
slouken@1934
|
143 |
if (!data) {
|
slouken@1934
|
144 |
return SDL_FALSE;
|
slouken@1934
|
145 |
}
|
slouken@1934
|
146 |
data->moderef = moderef;
|
slouken@1934
|
147 |
|
icculus@5646
|
148 |
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
|
icculus@5643
|
149 |
if (IS_SNOW_LEOPARD_OR_LATER(_this)) {
|
icculus@5643
|
150 |
CGDisplayModeRef vidmode = (CGDisplayModeRef) moderef;
|
icculus@5643
|
151 |
CFStringRef fmt = CGDisplayModeCopyPixelEncoding(vidmode);
|
icculus@5643
|
152 |
width = (long) CGDisplayModeGetWidth(vidmode);
|
icculus@5643
|
153 |
height = (long) CGDisplayModeGetHeight(vidmode);
|
icculus@5643
|
154 |
refreshRate = (long) CGDisplayModeGetRefreshRate(vidmode);
|
icculus@5643
|
155 |
|
icculus@5643
|
156 |
if (CFStringCompare(fmt, CFSTR(IO32BitDirectPixels),
|
icculus@5643
|
157 |
kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
|
icculus@5643
|
158 |
bpp = 32;
|
icculus@5643
|
159 |
} else if (CFStringCompare(fmt, CFSTR(IO16BitDirectPixels),
|
icculus@5643
|
160 |
kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
|
icculus@5643
|
161 |
bpp = 16;
|
icculus@5643
|
162 |
} else {
|
icculus@5643
|
163 |
bpp = 0; /* ignore 8-bit and such for now. */
|
icculus@5643
|
164 |
}
|
icculus@5643
|
165 |
|
icculus@5643
|
166 |
CFRelease(fmt);
|
icculus@5643
|
167 |
}
|
icculus@5643
|
168 |
#endif
|
icculus@5643
|
169 |
|
icculus@5646
|
170 |
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
|
icculus@5643
|
171 |
if (!IS_SNOW_LEOPARD_OR_LATER(_this)) {
|
slouken@6044
|
172 |
CFNumberRef number;
|
icculus@5643
|
173 |
CFDictionaryRef vidmode = (CFDictionaryRef) moderef;
|
icculus@5643
|
174 |
number = CFDictionaryGetValue(vidmode, kCGDisplayWidth);
|
icculus@5643
|
175 |
CFNumberGetValue(number, kCFNumberLongType, &width);
|
icculus@5643
|
176 |
number = CFDictionaryGetValue(vidmode, kCGDisplayHeight);
|
icculus@5643
|
177 |
CFNumberGetValue(number, kCFNumberLongType, &height);
|
icculus@5643
|
178 |
number = CFDictionaryGetValue(vidmode, kCGDisplayBitsPerPixel);
|
icculus@5643
|
179 |
CFNumberGetValue(number, kCFNumberLongType, &bpp);
|
icculus@5643
|
180 |
number = CFDictionaryGetValue(vidmode, kCGDisplayRefreshRate);
|
icculus@5643
|
181 |
CFNumberGetValue(number, kCFNumberLongType, &refreshRate);
|
icculus@5643
|
182 |
}
|
icculus@5643
|
183 |
#endif
|
slouken@1934
|
184 |
|
slouken@1969
|
185 |
mode->format = SDL_PIXELFORMAT_UNKNOWN;
|
slouken@1934
|
186 |
switch (bpp) {
|
slouken@1934
|
187 |
case 16:
|
slouken@2237
|
188 |
mode->format = SDL_PIXELFORMAT_ARGB1555;
|
slouken@1934
|
189 |
break;
|
slouken@1934
|
190 |
case 32:
|
slouken@2237
|
191 |
mode->format = SDL_PIXELFORMAT_ARGB8888;
|
slouken@1934
|
192 |
break;
|
icculus@5643
|
193 |
case 8: /* We don't support palettized modes now */
|
icculus@5643
|
194 |
default: /* Totally unrecognizable bit depth. */
|
icculus@5643
|
195 |
return SDL_FALSE;
|
slouken@1934
|
196 |
}
|
slouken@1934
|
197 |
mode->w = width;
|
slouken@1934
|
198 |
mode->h = height;
|
slouken@1934
|
199 |
mode->refresh_rate = refreshRate;
|
slouken@1934
|
200 |
mode->driverdata = data;
|
slouken@1934
|
201 |
return SDL_TRUE;
|
slouken@1934
|
202 |
}
|
slouken@1931
|
203 |
|
icculus@5643
|
204 |
static inline void
|
icculus@5643
|
205 |
Cocoa_ReleaseDisplayMode(_THIS, const void *moderef)
|
icculus@5643
|
206 |
{
|
icculus@5643
|
207 |
/* We don't own moderef unless we use the 10.6+ APIs. */
|
icculus@5646
|
208 |
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
|
icculus@5643
|
209 |
if (IS_SNOW_LEOPARD_OR_LATER(_this)) {
|
icculus@5643
|
210 |
CGDisplayModeRelease((CGDisplayModeRef) moderef); /* NULL is ok */
|
icculus@5643
|
211 |
}
|
icculus@5643
|
212 |
#endif
|
icculus@5643
|
213 |
}
|
icculus@5643
|
214 |
|
icculus@5643
|
215 |
static inline void
|
icculus@5643
|
216 |
Cocoa_ReleaseDisplayModeList(_THIS, CFArrayRef modelist)
|
icculus@5643
|
217 |
{
|
icculus@5643
|
218 |
/* We don't own modelis unless we use the 10.6+ APIs. */
|
icculus@5646
|
219 |
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
|
icculus@5643
|
220 |
if (IS_SNOW_LEOPARD_OR_LATER(_this)) {
|
icculus@5643
|
221 |
CFRelease(modelist); /* NULL is ok */
|
icculus@5643
|
222 |
}
|
icculus@5643
|
223 |
#endif
|
icculus@5643
|
224 |
}
|
icculus@5643
|
225 |
|
slouken@1931
|
226 |
void
|
slouken@1931
|
227 |
Cocoa_InitModes(_THIS)
|
slouken@1931
|
228 |
{
|
slouken@1934
|
229 |
CGDisplayErr result;
|
slouken@1934
|
230 |
CGDirectDisplayID *displays;
|
slouken@1934
|
231 |
CGDisplayCount numDisplays;
|
slouken@3505
|
232 |
int pass, i;
|
slouken@1934
|
233 |
|
slouken@1934
|
234 |
result = CGGetOnlineDisplayList(0, NULL, &numDisplays);
|
slouken@1934
|
235 |
if (result != kCGErrorSuccess) {
|
slouken@1934
|
236 |
CG_SetError("CGGetOnlineDisplayList()", result);
|
slouken@1934
|
237 |
return;
|
slouken@1934
|
238 |
}
|
slouken@1934
|
239 |
displays = SDL_stack_alloc(CGDirectDisplayID, numDisplays);
|
slouken@1934
|
240 |
result = CGGetOnlineDisplayList(numDisplays, displays, &numDisplays);
|
slouken@1934
|
241 |
if (result != kCGErrorSuccess) {
|
slouken@1934
|
242 |
CG_SetError("CGGetOnlineDisplayList()", result);
|
slouken@1934
|
243 |
SDL_stack_free(displays);
|
slouken@1934
|
244 |
return;
|
slouken@1934
|
245 |
}
|
slouken@1934
|
246 |
|
slouken@3505
|
247 |
/* Pick up the primary display in the first pass, then get the rest */
|
slouken@3505
|
248 |
for (pass = 0; pass < 2; ++pass) {
|
slouken@3505
|
249 |
for (i = 0; i < numDisplays; ++i) {
|
slouken@3505
|
250 |
SDL_VideoDisplay display;
|
slouken@3505
|
251 |
SDL_DisplayData *displaydata;
|
slouken@3505
|
252 |
SDL_DisplayMode mode;
|
icculus@5643
|
253 |
const void *moderef = NULL;
|
slouken@1934
|
254 |
|
slouken@3505
|
255 |
if (pass == 0) {
|
slouken@3505
|
256 |
if (!CGDisplayIsMain(displays[i])) {
|
slouken@3505
|
257 |
continue;
|
slouken@3505
|
258 |
}
|
slouken@3505
|
259 |
} else {
|
slouken@3505
|
260 |
if (CGDisplayIsMain(displays[i])) {
|
slouken@3505
|
261 |
continue;
|
slouken@3505
|
262 |
}
|
slouken@3505
|
263 |
}
|
slouken@1934
|
264 |
|
slouken@3505
|
265 |
if (CGDisplayMirrorsDisplay(displays[i]) != kCGNullDirectDisplay) {
|
slouken@3505
|
266 |
continue;
|
slouken@3505
|
267 |
}
|
icculus@5643
|
268 |
|
icculus@5646
|
269 |
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
|
icculus@5643
|
270 |
if (IS_SNOW_LEOPARD_OR_LATER(_this)) {
|
icculus@5643
|
271 |
moderef = CGDisplayCopyDisplayMode(displays[i]);
|
icculus@5643
|
272 |
}
|
icculus@5643
|
273 |
#endif
|
icculus@5643
|
274 |
|
icculus@5646
|
275 |
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
|
icculus@5643
|
276 |
if (!IS_SNOW_LEOPARD_OR_LATER(_this)) {
|
icculus@5643
|
277 |
moderef = CGDisplayCurrentMode(displays[i]);
|
icculus@5643
|
278 |
}
|
icculus@5643
|
279 |
#endif
|
icculus@5643
|
280 |
|
slouken@3505
|
281 |
if (!moderef) {
|
slouken@3505
|
282 |
continue;
|
slouken@3505
|
283 |
}
|
slouken@1934
|
284 |
|
slouken@3505
|
285 |
displaydata = (SDL_DisplayData *) SDL_malloc(sizeof(*displaydata));
|
slouken@3505
|
286 |
if (!displaydata) {
|
icculus@5643
|
287 |
Cocoa_ReleaseDisplayMode(_this, moderef);
|
slouken@3505
|
288 |
continue;
|
slouken@3505
|
289 |
}
|
slouken@3505
|
290 |
displaydata->display = displays[i];
|
slouken@3505
|
291 |
|
slouken@3505
|
292 |
SDL_zero(display);
|
icculus@5643
|
293 |
if (!GetDisplayMode (_this, moderef, &mode)) {
|
icculus@5643
|
294 |
Cocoa_ReleaseDisplayMode(_this, moderef);
|
slouken@3505
|
295 |
SDL_free(displaydata);
|
slouken@3505
|
296 |
continue;
|
slouken@3505
|
297 |
}
|
icculus@5643
|
298 |
|
slouken@3505
|
299 |
display.desktop_mode = mode;
|
slouken@3505
|
300 |
display.current_mode = mode;
|
slouken@3505
|
301 |
display.driverdata = displaydata;
|
slouken@3505
|
302 |
SDL_AddVideoDisplay(&display);
|
slouken@1934
|
303 |
}
|
slouken@1934
|
304 |
}
|
slouken@1973
|
305 |
SDL_stack_free(displays);
|
slouken@1934
|
306 |
}
|
slouken@1934
|
307 |
|
slouken@3528
|
308 |
int
|
slouken@3528
|
309 |
Cocoa_GetDisplayBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect)
|
slouken@3525
|
310 |
{
|
slouken@3528
|
311 |
SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
|
slouken@3525
|
312 |
CGRect cgrect;
|
slouken@3525
|
313 |
|
slouken@3528
|
314 |
cgrect = CGDisplayBounds(displaydata->display);
|
slouken@3528
|
315 |
rect->x = (int)cgrect.origin.x;
|
slouken@3528
|
316 |
rect->y = (int)cgrect.origin.y;
|
slouken@3528
|
317 |
rect->w = (int)cgrect.size.width;
|
slouken@3528
|
318 |
rect->h = (int)cgrect.size.height;
|
slouken@3528
|
319 |
return 0;
|
slouken@3525
|
320 |
}
|
slouken@3525
|
321 |
|
slouken@1931
|
322 |
void
|
slouken@3500
|
323 |
Cocoa_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
|
slouken@1931
|
324 |
{
|
slouken@3500
|
325 |
SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
|
icculus@5643
|
326 |
CFArrayRef modes = NULL;
|
icculus@5643
|
327 |
|
icculus@5646
|
328 |
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
|
icculus@5643
|
329 |
if (IS_SNOW_LEOPARD_OR_LATER(_this)) {
|
icculus@5643
|
330 |
modes = CGDisplayCopyAllDisplayModes(data->display, NULL);
|
icculus@5643
|
331 |
}
|
icculus@5643
|
332 |
#endif
|
icculus@5643
|
333 |
|
icculus@5646
|
334 |
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
|
icculus@5643
|
335 |
if (!IS_SNOW_LEOPARD_OR_LATER(_this)) {
|
icculus@5643
|
336 |
modes = CGDisplayAvailableModes(data->display);
|
icculus@5643
|
337 |
}
|
icculus@5643
|
338 |
#endif
|
icculus@5643
|
339 |
|
icculus@5643
|
340 |
if (modes) {
|
icculus@5643
|
341 |
const CFIndex count = CFArrayGetCount(modes);
|
icculus@5643
|
342 |
CFIndex i;
|
slouken@1934
|
343 |
|
icculus@5643
|
344 |
for (i = 0; i < count; i++) {
|
icculus@5643
|
345 |
const void *moderef = CFArrayGetValueAtIndex(modes, i);
|
icculus@5643
|
346 |
SDL_DisplayMode mode;
|
icculus@5643
|
347 |
if (GetDisplayMode(_this, moderef, &mode)) {
|
icculus@5646
|
348 |
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
|
icculus@5643
|
349 |
if (IS_SNOW_LEOPARD_OR_LATER(_this)) {
|
icculus@5643
|
350 |
CGDisplayModeRetain((CGDisplayModeRef) moderef);
|
icculus@5643
|
351 |
}
|
icculus@5643
|
352 |
#endif
|
icculus@5643
|
353 |
SDL_AddDisplayMode(display, &mode);
|
icculus@5643
|
354 |
}
|
icculus@5643
|
355 |
}
|
icculus@5643
|
356 |
|
icculus@5643
|
357 |
Cocoa_ReleaseDisplayModeList(_this, modes);
|
slouken@1934
|
358 |
}
|
icculus@5643
|
359 |
}
|
icculus@5643
|
360 |
|
icculus@5643
|
361 |
static CGError
|
icculus@5643
|
362 |
Cocoa_SwitchMode(_THIS, CGDirectDisplayID display, const void *mode)
|
icculus@5643
|
363 |
{
|
icculus@5646
|
364 |
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
|
icculus@5643
|
365 |
if (IS_SNOW_LEOPARD_OR_LATER(_this)) {
|
icculus@5643
|
366 |
return CGDisplaySetDisplayMode(display, (CGDisplayModeRef) mode, NULL);
|
icculus@5643
|
367 |
}
|
icculus@5643
|
368 |
#endif
|
icculus@5643
|
369 |
|
icculus@5646
|
370 |
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
|
icculus@5643
|
371 |
if (!IS_SNOW_LEOPARD_OR_LATER(_this)) {
|
icculus@5643
|
372 |
return CGDisplaySwitchToMode(display, (CFDictionaryRef) mode);
|
icculus@5643
|
373 |
}
|
icculus@5643
|
374 |
#endif
|
icculus@5643
|
375 |
|
icculus@5643
|
376 |
return kCGErrorFailure;
|
slouken@1931
|
377 |
}
|
slouken@1931
|
378 |
|
slouken@1931
|
379 |
int
|
slouken@3500
|
380 |
Cocoa_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
|
slouken@1931
|
381 |
{
|
slouken@3500
|
382 |
SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
|
slouken@1934
|
383 |
SDL_DisplayModeData *data = (SDL_DisplayModeData *) mode->driverdata;
|
slouken@1934
|
384 |
CGDisplayFadeReservationToken fade_token = kCGDisplayFadeReservationInvalidToken;
|
slouken@1934
|
385 |
CGError result;
|
slouken@4939
|
386 |
|
slouken@1934
|
387 |
/* Fade to black to hide resolution-switching flicker */
|
slouken@1934
|
388 |
if (CGAcquireDisplayFadeReservation(5, &fade_token) == kCGErrorSuccess) {
|
slouken@1934
|
389 |
CGDisplayFade(fade_token, 0.3, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0.0, 0.0, 0.0, TRUE);
|
slouken@1934
|
390 |
}
|
slouken@1934
|
391 |
|
slouken@3513
|
392 |
if (data == display->desktop_mode.driverdata) {
|
slouken@3513
|
393 |
/* Restoring desktop mode */
|
icculus@5643
|
394 |
Cocoa_SwitchMode(_this, displaydata->display, data->moderef);
|
slouken@4939
|
395 |
|
slouken@5248
|
396 |
if (CGDisplayIsMain(displaydata->display)) {
|
slouken@5248
|
397 |
CGReleaseAllDisplays();
|
slouken@5248
|
398 |
} else {
|
slouken@5248
|
399 |
CGDisplayRelease(displaydata->display);
|
slouken@5248
|
400 |
}
|
slouken@1934
|
401 |
|
slouken@3513
|
402 |
if (CGDisplayIsMain(displaydata->display)) {
|
icculus@6105
|
403 |
Cocoa_ToggleMenuBar(YES);
|
slouken@3513
|
404 |
}
|
slouken@3513
|
405 |
} else {
|
slouken@4939
|
406 |
/* Put up the blanking window (a window above all other windows) */
|
slouken@5248
|
407 |
if (CGDisplayIsMain(displaydata->display)) {
|
slouken@5248
|
408 |
/* If we don't capture all displays, Cocoa tries to rearrange windows... *sigh* */
|
slouken@5248
|
409 |
result = CGCaptureAllDisplays();
|
slouken@5248
|
410 |
} else {
|
slouken@5248
|
411 |
result = CGDisplayCapture(displaydata->display);
|
slouken@5248
|
412 |
}
|
slouken@4939
|
413 |
if (result != kCGErrorSuccess) {
|
slouken@4939
|
414 |
CG_SetError("CGDisplayCapture()", result);
|
slouken@4939
|
415 |
goto ERR_NO_CAPTURE;
|
slouken@4939
|
416 |
}
|
slouken@4939
|
417 |
|
slouken@3513
|
418 |
/* Do the physical switch */
|
icculus@5643
|
419 |
result = Cocoa_SwitchMode(_this, displaydata->display, data->moderef);
|
slouken@3513
|
420 |
if (result != kCGErrorSuccess) {
|
slouken@3513
|
421 |
CG_SetError("CGDisplaySwitchToMode()", result);
|
slouken@3513
|
422 |
goto ERR_NO_SWITCH;
|
slouken@3513
|
423 |
}
|
slouken@3513
|
424 |
|
slouken@3513
|
425 |
/* Hide the menu bar so it doesn't intercept events */
|
slouken@3513
|
426 |
if (CGDisplayIsMain(displaydata->display)) {
|
icculus@6105
|
427 |
Cocoa_ToggleMenuBar(NO);
|
slouken@3513
|
428 |
}
|
slouken@3510
|
429 |
}
|
slouken@1973
|
430 |
|
slouken@1934
|
431 |
/* Fade in again (asynchronously) */
|
slouken@1934
|
432 |
if (fade_token != kCGDisplayFadeReservationInvalidToken) {
|
slouken@1934
|
433 |
CGDisplayFade(fade_token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0.0, 0.0, 0.0, FALSE);
|
slouken@1934
|
434 |
CGReleaseDisplayFadeReservation(fade_token);
|
slouken@1934
|
435 |
}
|
slouken@1973
|
436 |
|
slouken@1934
|
437 |
return 0;
|
slouken@1934
|
438 |
|
slouken@1934
|
439 |
/* Since the blanking window covers *all* windows (even force quit) correct recovery is crucial */
|
slouken@1934
|
440 |
ERR_NO_SWITCH:
|
slouken@1934
|
441 |
CGDisplayRelease(displaydata->display);
|
slouken@1934
|
442 |
ERR_NO_CAPTURE:
|
slouken@1934
|
443 |
if (fade_token != kCGDisplayFadeReservationInvalidToken) {
|
slouken@1934
|
444 |
CGDisplayFade (fade_token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0.0, 0.0, 0.0, FALSE);
|
slouken@1934
|
445 |
CGReleaseDisplayFadeReservation(fade_token);
|
slouken@1934
|
446 |
}
|
slouken@1931
|
447 |
return -1;
|
slouken@1931
|
448 |
}
|
slouken@1931
|
449 |
|
slouken@1931
|
450 |
void
|
slouken@1931
|
451 |
Cocoa_QuitModes(_THIS)
|
slouken@1931
|
452 |
{
|
icculus@5643
|
453 |
int i, j;
|
slouken@1934
|
454 |
|
slouken@1934
|
455 |
for (i = 0; i < _this->num_displays; ++i) {
|
slouken@1934
|
456 |
SDL_VideoDisplay *display = &_this->displays[i];
|
icculus@5643
|
457 |
SDL_DisplayModeData *mode;
|
slouken@1934
|
458 |
|
slouken@1934
|
459 |
if (display->current_mode.driverdata != display->desktop_mode.driverdata) {
|
slouken@3500
|
460 |
Cocoa_SetDisplayMode(_this, display, &display->desktop_mode);
|
slouken@1934
|
461 |
}
|
icculus@5643
|
462 |
|
icculus@5643
|
463 |
mode = (SDL_DisplayModeData *) display->desktop_mode.driverdata;
|
icculus@5643
|
464 |
Cocoa_ReleaseDisplayMode(_this, mode->moderef);
|
icculus@5643
|
465 |
|
icculus@5643
|
466 |
for (j = 0; j < display->num_display_modes; j++) {
|
icculus@5643
|
467 |
mode = (SDL_DisplayModeData*) display->display_modes[j].driverdata;
|
icculus@5643
|
468 |
Cocoa_ReleaseDisplayMode(_this, mode->moderef);
|
icculus@5643
|
469 |
}
|
icculus@5643
|
470 |
|
slouken@1934
|
471 |
}
|
icculus@6105
|
472 |
Cocoa_ToggleMenuBar(YES);
|
slouken@1931
|
473 |
}
|
slouken@1931
|
474 |
|
slouken@6044
|
475 |
#endif /* SDL_VIDEO_DRIVER_COCOA */
|
slouken@6044
|
476 |
|
slouken@1931
|
477 |
/* vi: set ts=4 sw=4 expandtab: */
|