annotate src/video/cocoa/SDL_cocoamodes.m @ 1956:ba0d62354872

Simplified driver window creation code. Implemented several Cocoa window functions
author Sam Lantinga <slouken@libsdl.org>
date Sat, 29 Jul 2006 21:51:00 +0000
parents 70139af5ac27
children 5d3724f64f2b
rev   line source
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3 Copyright (C) 1997-2006 Sam Lantinga
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 Lesser General Public License for more details.
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free Software
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 Sam Lantinga
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 slouken@libsdl.org
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 */
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 #include "SDL_config.h"
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 #include "SDL_cocoavideo.h"
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25
1934
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
26 static void
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
27 CG_SetError(const char *prefix, CGDisplayErr result)
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
28 {
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
29 const char *error;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
30
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
31 switch (result) {
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
32 case kCGErrorFailure:
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
33 error = "kCGErrorFailure";
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
34 break;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
35 case kCGErrorIllegalArgument:
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
36 error = "kCGErrorIllegalArgument";
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
37 break;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
38 case kCGErrorInvalidConnection:
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
39 error = "kCGErrorInvalidConnection";
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
40 break;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
41 case kCGErrorInvalidContext:
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
42 error = "kCGErrorInvalidContext";
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
43 break;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
44 case kCGErrorCannotComplete:
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
45 error = "kCGErrorCannotComplete";
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
46 break;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
47 case kCGErrorNameTooLong:
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
48 error = "kCGErrorNameTooLong";
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
49 break;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
50 case kCGErrorNotImplemented:
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
51 error = "kCGErrorNotImplemented";
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
52 break;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
53 case kCGErrorRangeCheck:
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
54 error = "kCGErrorRangeCheck";
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
55 break;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
56 case kCGErrorTypeCheck:
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
57 error = "kCGErrorTypeCheck";
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
58 break;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
59 case kCGErrorNoCurrentPoint:
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
60 error = "kCGErrorNoCurrentPoint";
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
61 break;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
62 case kCGErrorInvalidOperation:
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
63 error = "kCGErrorInvalidOperation";
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
64 break;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
65 case kCGErrorNoneAvailable:
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
66 error = "kCGErrorNoneAvailable";
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
67 break;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
68 default:
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
69 error = "Unknown Error";
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
70 break;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
71 }
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
72 SDL_SetError("%s: %s", prefix, error);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
73 }
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
74
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
75 static SDL_bool
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
76 GetDisplayMode(CFDictionaryRef moderef, SDL_DisplayMode *mode)
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
77 {
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
78 SDL_DisplayModeData *data;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
79 CFNumberRef number;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
80 long width, height, bpp, refreshRate;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
81
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
82 data = (SDL_DisplayModeData *) SDL_malloc(sizeof(*data));
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
83 if (!data) {
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
84 return SDL_FALSE;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
85 }
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
86 data->moderef = moderef;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
87
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
88 number = CFDictionaryGetValue(moderef, kCGDisplayWidth);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
89 CFNumberGetValue(number, kCFNumberLongType, &width);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
90 number = CFDictionaryGetValue(moderef, kCGDisplayHeight);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
91 CFNumberGetValue(number, kCFNumberLongType, &height);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
92 number = CFDictionaryGetValue(moderef, kCGDisplayBitsPerPixel);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
93 CFNumberGetValue(number, kCFNumberLongType, &bpp);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
94 number = CFDictionaryGetValue(moderef, kCGDisplayRefreshRate);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
95 CFNumberGetValue(number, kCFNumberLongType, &refreshRate);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
96
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
97 mode->format = SDL_PixelFormat_Unknown;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
98 switch (bpp) {
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
99 case 8:
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
100 mode->format = SDL_PixelFormat_Index8;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
101 break;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
102 case 16:
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
103 mode->format = SDL_PixelFormat_RGB555;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
104 break;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
105 case 32:
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
106 mode->format = SDL_PixelFormat_RGB888;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
107 break;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
108 }
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
109 mode->w = width;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
110 mode->h = height;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
111 mode->refresh_rate = refreshRate;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
112 mode->driverdata = data;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
113 return SDL_TRUE;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
114 }
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
116 void
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
117 Cocoa_InitModes(_THIS)
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
118 {
1934
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
119 CGDisplayErr result;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
120 CGDirectDisplayID *displays;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
121 CGDisplayCount numDisplays;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
122 int i;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
123
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
124 result = CGGetOnlineDisplayList(0, NULL, &numDisplays);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
125 if (result != kCGErrorSuccess) {
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
126 CG_SetError("CGGetOnlineDisplayList()", result);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
127 return;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
128 }
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
129 displays = SDL_stack_alloc(CGDirectDisplayID, numDisplays);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
130 result = CGGetOnlineDisplayList(numDisplays, displays, &numDisplays);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
131 if (result != kCGErrorSuccess) {
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
132 CG_SetError("CGGetOnlineDisplayList()", result);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
133 SDL_stack_free(displays);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
134 return;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
135 }
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
136
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
137 for (i = 0; i < numDisplays; ++i) {
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
138 SDL_VideoDisplay display;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
139 SDL_DisplayData *displaydata;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
140 SDL_DisplayMode mode;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
141 CFDictionaryRef moderef;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
142
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
143 if (CGDisplayIsInMirrorSet(displays[i])) {
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
144 continue;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
145 }
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
146 moderef = CGDisplayCurrentMode(displays[i]);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
147 if (!moderef) {
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
148 continue;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
149 }
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
150
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
151 displaydata = (SDL_DisplayData *) SDL_malloc(sizeof(*displaydata));
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
152 if (!displaydata) {
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
153 continue;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
154 }
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
155 displaydata->display = displays[i];
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
156
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
157 SDL_zero(display);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
158 if (!GetDisplayMode (moderef, &mode)) {
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
159 SDL_free(displaydata);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
160 continue;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
161 }
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
162 display.desktop_mode = mode;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
163 display.current_mode = mode;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
164 display.driverdata = displaydata;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
165 SDL_AddVideoDisplay(&display);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
166 }
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
167 }
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
168
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
169 static void
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
170 AddDisplayMode(const void *moderef, void *context)
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
171 {
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
172 SDL_VideoDevice *_this = (SDL_VideoDevice *) context;
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
173 SDL_DisplayMode mode;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
174
1934
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
175 if (GetDisplayMode(moderef, &mode)) {
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
176 SDL_AddDisplayMode(_this->current_display, &mode);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
177 }
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
178 }
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
179
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180 void
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181 Cocoa_GetDisplayModes(_THIS)
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
182 {
1934
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
183 SDL_DisplayData *data = (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
184 CFArrayRef modes;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
185 CFRange range;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
186
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
187 modes = CGDisplayAvailableModes(data->display);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
188 if (!modes) {
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
189 return;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
190 }
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
191 range.location = 0;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
192 range.length = CFArrayGetCount(modes);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
193 CFArrayApplyFunction(modes, range, AddDisplayMode, _this);
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
194 }
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
195
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
196 int
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
197 Cocoa_SetDisplayMode(_THIS, SDL_DisplayMode * mode)
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
198 {
1934
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
199 SDL_DisplayData *displaydata = (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
200 SDL_DisplayModeData *data = (SDL_DisplayModeData *) mode->driverdata;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
201 CGDisplayFadeReservationToken fade_token = kCGDisplayFadeReservationInvalidToken;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
202 CGError result;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
203
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
204 /* Fade to black to hide resolution-switching flicker */
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
205 if (CGAcquireDisplayFadeReservation(5, &fade_token) == kCGErrorSuccess) {
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
206 CGDisplayFade(fade_token, 0.3, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0.0, 0.0, 0.0, TRUE);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
207 }
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
208
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
209 /* Put up the blanking window (a window above all other windows) */
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
210 result = CGDisplayCapture(displaydata->display);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
211 if (result != kCGErrorSuccess) {
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
212 CG_SetError("CGDisplayCapture()", result);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
213 goto ERR_NO_CAPTURE;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
214 }
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
215
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
216 /* Do the physical switch */
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
217 result = CGDisplaySwitchToMode(displaydata->display, data->moderef);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
218 if (result != kCGErrorSuccess) {
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
219 CG_SetError("CGDisplaySwitchToMode()", result);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
220 goto ERR_NO_SWITCH;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
221 }
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
222
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
223 /* Fade in again (asynchronously) */
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
224 if (fade_token != kCGDisplayFadeReservationInvalidToken) {
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
225 CGDisplayFade(fade_token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0.0, 0.0, 0.0, FALSE);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
226 CGReleaseDisplayFadeReservation(fade_token);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
227 }
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
228 return 0;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
229
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
230 /* Since the blanking window covers *all* windows (even force quit) correct recovery is crucial */
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
231 ERR_NO_SWITCH:
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
232 CGDisplayRelease(displaydata->display);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
233 ERR_NO_CAPTURE:
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
234 if (fade_token != kCGDisplayFadeReservationInvalidToken) {
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
235 CGDisplayFade (fade_token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0.0, 0.0, 0.0, FALSE);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
236 CGReleaseDisplayFadeReservation(fade_token);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
237 }
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
238 return -1;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
239 }
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
240
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
241 void
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
242 Cocoa_QuitModes(_THIS)
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
243 {
1934
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
244 int i, saved_display;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
245
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
246 saved_display = _this->current_display;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
247 for (i = 0; i < _this->num_displays; ++i) {
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
248 SDL_VideoDisplay *display = &_this->displays[i];
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
249
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
250 if (display->current_mode.driverdata != display->desktop_mode.driverdata) {
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
251 _this->current_display = i;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
252 Cocoa_SetDisplayMode(_this, &display->desktop_mode);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
253 }
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
254 }
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
255 CGReleaseAllDisplays();
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
256 _this->current_display = saved_display;
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
257 }
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
258
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
259 /* vi: set ts=4 sw=4 expandtab: */