comparison src/video/uikit/SDL_uikitvideo.m @ 4446:8b03a20b320f

Much improved multi-display support for iPad. Fixes most issues and limitations, I think.
author Ryan C. Gordon <icculus@icculus.org>
date Sun, 02 May 2010 05:08:12 -0400
parents 06becafcac89
children 8b7988f42fcb
comparison
equal deleted inserted replaced
4445:06becafcac89 4446:8b03a20b320f
47 static void UIKit_GetDisplayModes(_THIS, SDL_VideoDisplay * sdl_display); 47 static void UIKit_GetDisplayModes(_THIS, SDL_VideoDisplay * sdl_display);
48 static int UIKit_SetDisplayMode(_THIS, SDL_VideoDisplay * display, 48 static int UIKit_SetDisplayMode(_THIS, SDL_VideoDisplay * display,
49 SDL_DisplayMode * mode); 49 SDL_DisplayMode * mode);
50 static void UIKit_VideoQuit(_THIS); 50 static void UIKit_VideoQuit(_THIS);
51 51
52 static BOOL supports_multiple_displays = NO; 52 BOOL SDL_UIKit_supports_multiple_displays = NO;
53 53
54 /* DUMMY driver bootstrap functions */ 54 /* DUMMY driver bootstrap functions */
55 55
56 static int 56 static int
57 UIKit_Available(void) 57 UIKit_Available(void)
122 */ 122 */
123 123
124 static void 124 static void
125 UIKit_GetDisplayModes(_THIS, SDL_VideoDisplay * display) 125 UIKit_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
126 { 126 {
127 const UIScreen *screen = (UIScreen *) display->driverdata; 127 UIScreen *uiscreen = (UIScreen *) display->driverdata;
128 SDL_DisplayMode mode; 128 SDL_DisplayMode mode;
129 SDL_zero(mode); 129 SDL_zero(mode);
130 130
131 // availableModes showed up in 3.2 (the iPad and later). We should only 131 // availableModes showed up in 3.2 (the iPad and later). We should only
132 // land here for at least that version of the OS. 132 // land here for at least that version of the OS.
133 if (!supports_multiple_displays) { 133 if (!SDL_UIKit_supports_multiple_displays) {
134 const CGRect rect = [screen bounds]; 134 const CGRect rect = [uiscreen bounds];
135 mode.format = SDL_PIXELFORMAT_ABGR8888; 135 mode.format = SDL_PIXELFORMAT_ABGR8888;
136 mode.w = (int) rect.size.width; 136 mode.w = (int) rect.size.width;
137 mode.h = (int) rect.size.height; 137 mode.h = (int) rect.size.height;
138 mode.refresh_rate = 0; 138 mode.refresh_rate = 0;
139 mode.driverdata = NULL; 139 mode.driverdata = NULL;
140 SDL_AddDisplayMode(display, &mode); 140 SDL_AddDisplayMode(display, &mode);
141 return; 141 return;
142 } 142 }
143 143
144 const NSArray *modes = [screen availableModes]; 144 const NSArray *modes = [uiscreen availableModes];
145 const NSUInteger mode_count = [modes count]; 145 const NSUInteger mode_count = [modes count];
146 NSUInteger i; 146 NSUInteger i;
147 for (i = 0; i < mode_count; i++) { 147 for (i = 0; i < mode_count; i++) {
148 UIScreenMode *uimode = (UIScreenMode *) [modes objectAtIndex:i]; 148 UIScreenMode *uimode = (UIScreenMode *) [modes objectAtIndex:i];
149 const CGSize size = [uimode size]; 149 const CGSize size = [uimode size];
157 } 157 }
158 } 158 }
159 159
160 160
161 static void 161 static void
162 UIKit_AddDisplay(UIScreen *screen, int w, int h) 162 UIKit_AddDisplay(UIScreen *uiscreen, int w, int h)
163 { 163 {
164 SDL_VideoDisplay display; 164 SDL_VideoDisplay display;
165 SDL_DisplayMode mode; 165 SDL_DisplayMode mode;
166
167 SDL_zero(mode); 166 SDL_zero(mode);
168 mode.format = SDL_PIXELFORMAT_ABGR8888; 167 mode.format = SDL_PIXELFORMAT_ABGR8888;
169 mode.w = w; 168 mode.w = w;
170 mode.h = h; 169 mode.h = h;
171 mode.refresh_rate = 0; 170 mode.refresh_rate = 0;
172 171
173 SDL_zero(display); 172 SDL_zero(display);
174 display.desktop_mode = mode; 173 display.desktop_mode = mode;
175 display.current_mode = mode; 174 display.current_mode = mode;
176 display.driverdata = screen; 175
177 [screen retain]; 176 [uiscreen retain];
177 display.driverdata = uiscreen;
178 SDL_AddVideoDisplay(&display); 178 SDL_AddVideoDisplay(&display);
179 } 179 }
180 180
181 181
182 int 182 int
185 _this->gl_config.driver_loaded = 1; 185 _this->gl_config.driver_loaded = 1;
186 186
187 NSString *reqSysVer = @"3.2"; 187 NSString *reqSysVer = @"3.2";
188 NSString *currSysVer = [[UIDevice currentDevice] systemVersion]; 188 NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
189 if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending) 189 if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending)
190 supports_multiple_displays = YES; 190 SDL_UIKit_supports_multiple_displays = YES;
191 191
192 // If this is iPhoneOS < 3.2, all devices are one screen, 320x480 pixels. 192 // If this is iPhoneOS < 3.2, all devices are one screen, 320x480 pixels.
193 // The iPad added both a larger main screen and the ability to use 193 // The iPad added both a larger main screen and the ability to use
194 // external displays. 194 // external displays.
195 if (!supports_multiple_displays) { 195 if (!SDL_UIKit_supports_multiple_displays) {
196 // Just give 'em the whole main screen. 196 // Just give 'em the whole main screen.
197 UIScreen *screen = [UIScreen mainScreen]; 197 UIScreen *uiscreen = [UIScreen mainScreen];
198 const CGRect rect = [screen bounds]; 198 const CGRect rect = [uiscreen bounds];
199 UIKit_AddDisplay(screen, (int)rect.size.width, (int)rect.size.height); 199 UIKit_AddDisplay(uiscreen, (int)rect.size.width, (int)rect.size.height);
200 } else { 200 } else {
201 const NSArray *screens = [UIScreen screens]; 201 const NSArray *screens = [UIScreen screens];
202 const NSUInteger screen_count = [screens count]; 202 const NSUInteger screen_count = [screens count];
203 NSUInteger i; 203 NSUInteger i;
204 for (i = 0; i < screen_count; i++) { 204 for (i = 0; i < screen_count; i++) {
205 // the main screen is the first element in the array. 205 // the main screen is the first element in the array.
206 UIScreen *screen = (UIScreen *) [screens objectAtIndex:i]; 206 UIScreen *uiscreen = (UIScreen *) [screens objectAtIndex:i];
207 const CGSize size = [[screen currentMode] size]; 207 const CGSize size = [[uiscreen currentMode] size];
208 UIKit_AddDisplay(screen, (int) size.width, (int) size.height); 208 UIKit_AddDisplay(uiscreen, (int) size.width, (int) size.height);
209 } 209 }
210 } 210 }
211 211
212 /* We're done! */ 212 /* We're done! */
213 return 0; 213 return 0;
214 } 214 }
215 215
216 static int 216 static int
217 UIKit_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode) 217 UIKit_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
218 { 218 {
219 UIScreen *screen = (UIScreen *) display->driverdata; 219 UIScreen *uiscreen = (UIScreen *) display->driverdata;
220 if (!supports_multiple_displays) { 220 if (!SDL_UIKit_supports_multiple_displays) {
221 // Not on at least iPhoneOS 3.2 (versions prior to iPad). 221 // Not on at least iPhoneOS 3.2 (versions prior to iPad).
222 SDL_assert(mode->driverdata == NULL); 222 SDL_assert(mode->driverdata == NULL);
223 } else { 223 } else {
224 UIScreenMode *uimode = (UIScreenMode *) mode->driverdata; 224 UIScreenMode *uimode = (UIScreenMode *) mode->driverdata;
225 [screen setCurrentMode:uimode]; 225 [uiscreen setCurrentMode:uimode];
226 } 226 }
227 227
228 return 0; 228 return 0;
229 } 229 }
230 230
233 { 233 {
234 // Release Objective-C objects, so higher level doesn't free() them. 234 // Release Objective-C objects, so higher level doesn't free() them.
235 int i, j; 235 int i, j;
236 for (i = 0; i < _this->num_displays; i++) { 236 for (i = 0; i < _this->num_displays; i++) {
237 SDL_VideoDisplay *display = &_this->displays[i]; 237 SDL_VideoDisplay *display = &_this->displays[i];
238 UIScreen *screen = (UIScreen *) display->driverdata; 238 UIScreen *uiscreen = (UIScreen *) display->driverdata;
239 [((UIScreen *) display->driverdata) release]; 239 [uiscreen release];
240 display->driverdata = NULL; 240 display->driverdata = NULL;
241 for (j = 0; j < display->num_display_modes; j++) { 241 for (j = 0; j < display->num_display_modes; j++) {
242 SDL_DisplayMode *mode = &display->display_modes[j]; 242 SDL_DisplayMode *mode = &display->display_modes[j];
243 UIScreenMode *uimode = (UIScreenMode *) mode->driverdata; 243 UIScreenMode *uimode = (UIScreenMode *) mode->driverdata;
244 if (uimode) { 244 if (uimode) {