Fixed bug 2563 - Remove obsolete code for supporting iOS < 5 Alex Szpakowski Now that SDL for iOS requires at least iOS 5.1 at runtime, there are several old codepaths in the UIKit backend which can be removed. I've attached a patch which does so.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 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 188 189 190 191 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 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
diff --git a/include/SDL_config_iphoneos.h b/include/SDL_config_iphoneos.h
index 8b268b7..7ffb1c5 100644
--- a/include/SDL_config_iphoneos.h
+++ b/include/SDL_config_iphoneos.h
@@ -134,6 +134,7 @@
#define SDL_VIDEO_DRIVER_DUMMY 1
/* enable OpenGL ES */
+#define SDL_VIDEO_OPENGL_ES2 1
#define SDL_VIDEO_OPENGL_ES 1
#define SDL_VIDEO_RENDER_OGL_ES 1
#define SDL_VIDEO_RENDER_OGL_ES2 1
diff --git a/src/video/uikit/SDL_uikitmodes.h b/src/video/uikit/SDL_uikitmodes.h
index ae9ced6..9f2e9dd 100644
--- a/src/video/uikit/SDL_uikitmodes.h
+++ b/src/video/uikit/SDL_uikitmodes.h
@@ -37,8 +37,6 @@ typedef struct
CGFloat scale;
} SDL_DisplayModeData;
-extern BOOL SDL_UIKit_supports_multiple_displays;
-
extern SDL_bool UIKit_IsDisplayLandscape(UIScreen *uiscreen);
extern int UIKit_InitModes(_THIS);
diff --git a/src/video/uikit/SDL_uikitmodes.m b/src/video/uikit/SDL_uikitmodes.m
index dddb2f1..05e33d9 100644
--- a/src/video/uikit/SDL_uikitmodes.m
+++ b/src/video/uikit/SDL_uikitmodes.m
@@ -26,9 +26,6 @@
#include "SDL_uikitmodes.h"
-BOOL SDL_UIKit_supports_multiple_displays = NO;
-
-
static int
UIKit_AllocateDisplayModeData(SDL_DisplayMode * mode,
UIScreenMode * uiscreenmode, CGFloat scale)
@@ -56,10 +53,7 @@ UIKit_AllocateDisplayModeData(SDL_DisplayMode * mode,
static void
UIKit_FreeDisplayModeData(SDL_DisplayMode * mode)
{
- if (!SDL_UIKit_supports_multiple_displays) {
- /* Not on at least iPhoneOS 3.2 (versions prior to iPad). */
- SDL_assert(mode->driverdata == NULL);
- } else if (mode->driverdata != NULL) {
+ if (mode->driverdata != NULL) {
SDL_DisplayModeData *data = (SDL_DisplayModeData *)mode->driverdata;
[data->uiscreenmode release];
SDL_free(data);
@@ -121,19 +115,12 @@ UIKit_AddDisplay(UIScreen *uiscreen)
}
/* When dealing with UIKit all coordinates are specified in terms of
- * what Apple refers to as points. On earlier devices without the
- * so called "Retina" display, there is a one to one mapping between
- * points and pixels. In other cases [UIScreen scale] indicates the
+ * what Apple refers to as points. [UIScreen scale] indicates the
* relationship between points and pixels. Since SDL has no notion
* of points, we must compensate in all cases where dealing with such
* units.
*/
- CGFloat scale;
- if ([UIScreen instancesRespondToSelector:@selector(scale)]) {
- scale = [uiscreen scale]; /* iOS >= 4.0 */
- } else {
- scale = 1.0f; /* iOS < 4.0 */
- }
+ CGFloat scale = [uiscreen scale];
SDL_VideoDisplay display;
SDL_DisplayMode mode;
@@ -142,13 +129,7 @@ UIKit_AddDisplay(UIScreen *uiscreen)
mode.w = (int)(size.width * scale);
mode.h = (int)(size.height * scale);
- UIScreenMode * uiscreenmode = nil;
- /* UIScreenMode showed up in 3.2 (the iPad and later). We're
- * misusing this supports_multiple_displays flag here for that.
- */
- if (SDL_UIKit_supports_multiple_displays) {
- uiscreenmode = [uiscreen currentMode];
- }
+ UIScreenMode * uiscreenmode = [uiscreen currentMode];
if (UIKit_AllocateDisplayModeData(&mode, uiscreenmode, scale) < 0) {
return -1;
@@ -189,30 +170,12 @@ UIKit_IsDisplayLandscape(UIScreen *uiscreen)
int
UIKit_InitModes(_THIS)
{
- /* this tells us whether we are running on ios >= 3.2 */
- SDL_UIKit_supports_multiple_displays = [UIScreen instancesRespondToSelector:@selector(currentMode)];
-
- /* Add the main screen. */
- if (UIKit_AddDisplay([UIScreen mainScreen]) < 0) {
- return -1;
- }
-
- /* If this is iPhoneOS < 3.2, all devices are one screen, 320x480 pixels. */
- /* The iPad added both a larger main screen and the ability to use
- * external displays. So, add the other displays (screens in UI speak).
- */
- if (SDL_UIKit_supports_multiple_displays) {
- for (UIScreen *uiscreen in [UIScreen screens]) {
- /* Only add the other screens */
- if (uiscreen != [UIScreen mainScreen]) {
- if (UIKit_AddDisplay(uiscreen) < 0) {
- return -1;
- }
- }
+ for (UIScreen *uiscreen in [UIScreen screens]) {
+ if (UIKit_AddDisplay(uiscreen) < 0) {
+ return -1;
}
}
- /* We're done! */
return 0;
}
@@ -224,37 +187,8 @@ UIKit_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
SDL_bool isLandscape = UIKit_IsDisplayLandscape(data->uiscreen);
SDL_bool addRotation = (data->uiscreen == [UIScreen mainScreen]);
- if (SDL_UIKit_supports_multiple_displays) {
- /* availableModes showed up in 3.2 (the iPad and later). We should only
- * land here for at least that version of the OS.
- */
- for (UIScreenMode *uimode in [data->uiscreen availableModes]) {
- CGSize size = [uimode size];
- int w = (int)size.width;
- int h = (int)size.height;
-
- /* Make sure the width/height are oriented correctly */
- if (isLandscape != (w > h)) {
- int tmp = w;
- w = h;
- h = tmp;
- }
-
- /* Add the native screen resolution. */
- UIKit_AddDisplayMode(display, w, h, data->scale, uimode, addRotation);
-
- if (data->scale != 1.0f) {
- /* Add the native screen resolution divided by its scale.
- * This is so devices capable of e.g. 640x960 also advertise 320x480.
- */
- UIKit_AddDisplayMode(display,
- (int)(size.width / data->scale),
- (int)(size.height / data->scale),
- 1.0f, uimode, addRotation);
- }
- }
- } else {
- const CGSize size = [data->uiscreen bounds].size;
+ for (UIScreenMode *uimode in [data->uiscreen availableModes]) {
+ CGSize size = [uimode size];
int w = (int)size.width;
int h = (int)size.height;
@@ -265,7 +199,18 @@ UIKit_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
h = tmp;
}
- UIKit_AddDisplayMode(display, w, h, 1.0f, nil, addRotation);
+ /* Add the native screen resolution. */
+ UIKit_AddDisplayMode(display, w, h, data->scale, uimode, addRotation);
+
+ if (data->scale != 1.0f) {
+ /* Add the native screen resolution divided by its scale.
+ * This is so devices capable of e.g. 640x960 also advertise 320x480.
+ */
+ UIKit_AddDisplayMode(display,
+ (int)(size.width / data->scale),
+ (int)(size.height / data->scale),
+ 1.0f, uimode, addRotation);
+ }
}
}
@@ -273,26 +218,22 @@ int
UIKit_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
{
SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
+ SDL_DisplayModeData *modedata = (SDL_DisplayModeData *)mode->driverdata;
- if (!SDL_UIKit_supports_multiple_displays) {
- /* Not on at least iPhoneOS 3.2 (versions prior to iPad). */
- SDL_assert(mode->driverdata == NULL);
- } else {
- SDL_DisplayModeData *modedata = (SDL_DisplayModeData *)mode->driverdata;
- [data->uiscreen setCurrentMode:modedata->uiscreenmode];
-
- if (data->uiscreen == [UIScreen mainScreen]) {
- if (mode->w > mode->h) {
- if (!UIKit_IsDisplayLandscape(data->uiscreen)) {
- [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
- }
- } else if (mode->w < mode->h) {
- if (UIKit_IsDisplayLandscape(data->uiscreen)) {
- [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
- }
+ [data->uiscreen setCurrentMode:modedata->uiscreenmode];
+
+ if (data->uiscreen == [UIScreen mainScreen]) {
+ if (mode->w > mode->h) {
+ if (!UIKit_IsDisplayLandscape(data->uiscreen)) {
+ [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
+ }
+ } else if (mode->w < mode->h) {
+ if (UIKit_IsDisplayLandscape(data->uiscreen)) {
+ [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
}
}
}
+
return 0;
}
diff --git a/src/video/uikit/SDL_uikitopenglview.h b/src/video/uikit/SDL_uikitopenglview.h
index f04b5b0..eed2e5b 100644
--- a/src/video/uikit/SDL_uikitopenglview.h
+++ b/src/video/uikit/SDL_uikitopenglview.h
@@ -79,7 +79,7 @@
- (void)startAnimation;
- (void)stopAnimation;
-- (void)doLoop:(id)sender;
+- (void)doLoop:(CADisplayLink*)sender;
@end
diff --git a/src/video/uikit/SDL_uikitopenglview.m b/src/video/uikit/SDL_uikitopenglview.m
index 5c163c9..144100b 100644
--- a/src/video/uikit/SDL_uikitopenglview.m
+++ b/src/video/uikit/SDL_uikitopenglview.m
@@ -84,8 +84,7 @@
}
/* Set the appropriate scale (for retina display support) */
- if ([self respondsToSelector:@selector(contentScaleFactor)])
- self.contentScaleFactor = scale;
+ self.contentScaleFactor = scale;
/* create the buffers */
glGenFramebuffersOES(1, &viewFramebuffer);
@@ -171,11 +170,7 @@
- (void)startAnimation
{
- /* CADisplayLink is API new to iPhone SDK 3.1.
- * Compiling against earlier versions will result in a warning, but can be dismissed
- * if the system version runtime check for CADisplayLink exists in -initWithCoder:.
- */
- displayLink = [NSClassFromString(@"CADisplayLink") displayLinkWithTarget:self selector:@selector(doLoop:)];
+ displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(doLoop:)];
[displayLink setFrameInterval:animationInterval];
[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
}
@@ -186,7 +181,7 @@
displayLink = nil;
}
-- (void)doLoop:(id)sender
+- (void)doLoop:(CADisplayLink*)sender
{
/* Don't run the game loop while a messagebox is up */
if (!UIKit_ShowingMessageBox()) {
diff --git a/src/video/uikit/SDL_uikitview.m b/src/video/uikit/SDL_uikitview.m
index f890b7a..bee5a58 100644
--- a/src/video/uikit/SDL_uikitview.m
+++ b/src/video/uikit/SDL_uikitview.m
@@ -372,6 +372,7 @@ void _uikit_keyboard_update() {
int height = view.keyboardHeight;
int offsetx = 0;
int offsety = 0;
+ float scale = [UIScreen mainScreen].scale;
if (height) {
int sw,sh;
SDL_GetWindowSize(window,&sw,&sh);
@@ -392,11 +393,10 @@ void _uikit_keyboard_update() {
if (ui_orient == UIInterfaceOrientationPortraitUpsideDown) {
offsety = -offsety;
}
- if ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)]) {
- float scale = [UIScreen mainScreen].scale;
- offsetx /= scale;
- offsety /= scale;
- }
+
+ offsetx /= scale;
+ offsety /= scale;
+
view.frame = CGRectMake(offsetx,offsety,view.frame.size.width,view.frame.size.height);
}
@@ -424,9 +424,7 @@ void _uikit_keyboard_init() {
if (ui_orient == UIInterfaceOrientationLandscapeRight || ui_orient == UIInterfaceOrientationLandscapeLeft) {
height = keyboardSize.width;
}
- if ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)]) {
- height *= [UIScreen mainScreen].scale;
- }
+ height *= [UIScreen mainScreen].scale;
_uikit_keyboard_set_height(height);
}
];
diff --git a/src/video/uikit/SDL_uikitwindow.m b/src/video/uikit/SDL_uikitwindow.m
index a1dd1a9..a805227 100644
--- a/src/video/uikit/SDL_uikitwindow.m
+++ b/src/video/uikit/SDL_uikitwindow.m
@@ -130,6 +130,7 @@ UIKit_CreateWindow(_THIS, SDL_Window *window)
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
const BOOL external = ([UIScreen mainScreen] != data->uiscreen);
+ const CGSize origsize = [[data->uiscreen currentMode] size];
/* SDL currently puts this window at the start of display's linked list. We rely on this. */
SDL_assert(_this->windows == window);
@@ -143,31 +144,28 @@ UIKit_CreateWindow(_THIS, SDL_Window *window)
* user, so it's in standby), try to force the display to a resolution
* that most closely matches the desired window size.
*/
- if (SDL_UIKit_supports_multiple_displays) {
- const CGSize origsize = [[data->uiscreen currentMode] size];
- if ((origsize.width == 0.0f) && (origsize.height == 0.0f)) {
- if (display->num_display_modes == 0) {
- _this->GetDisplayModes(_this, display);
- }
+ if ((origsize.width == 0.0f) && (origsize.height == 0.0f)) {
+ if (display->num_display_modes == 0) {
+ _this->GetDisplayModes(_this, display);
+ }
- int i;
- const SDL_DisplayMode *bestmode = NULL;
- for (i = display->num_display_modes; i >= 0; i--) {
- const SDL_DisplayMode *mode = &display->display_modes[i];
- if ((mode->w >= window->w) && (mode->h >= window->h))
- bestmode = mode;
- }
+ int i;
+ const SDL_DisplayMode *bestmode = NULL;
+ for (i = display->num_display_modes; i >= 0; i--) {
+ const SDL_DisplayMode *mode = &display->display_modes[i];
+ if ((mode->w >= window->w) && (mode->h >= window->h))
+ bestmode = mode;
+ }
- if (bestmode) {
- SDL_DisplayModeData *modedata = (SDL_DisplayModeData *)bestmode->driverdata;
- [data->uiscreen setCurrentMode:modedata->uiscreenmode];
+ if (bestmode) {
+ SDL_DisplayModeData *modedata = (SDL_DisplayModeData *)bestmode->driverdata;
+ [data->uiscreen setCurrentMode:modedata->uiscreenmode];
- /* desktop_mode doesn't change here (the higher level will
- * use it to set all the screens back to their defaults
- * upon window destruction, SDL_Quit(), etc.
- */
- display->current_mode = *bestmode;
- }
+ /* desktop_mode doesn't change here (the higher level will
+ * use it to set all the screens back to their defaults
+ * upon window destruction, SDL_Quit(), etc.
+ */
+ display->current_mode = *bestmode;
}
}