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.
This commit is contained in:
Sam Lantinga 2014-06-21 12:43:57 -07:00
parent e8f8e6727a
commit d7924c73d6
7 changed files with 63 additions and 132 deletions

View File

@ -134,6 +134,7 @@
#define SDL_VIDEO_DRIVER_DUMMY 1 #define SDL_VIDEO_DRIVER_DUMMY 1
/* enable OpenGL ES */ /* enable OpenGL ES */
#define SDL_VIDEO_OPENGL_ES2 1
#define SDL_VIDEO_OPENGL_ES 1 #define SDL_VIDEO_OPENGL_ES 1
#define SDL_VIDEO_RENDER_OGL_ES 1 #define SDL_VIDEO_RENDER_OGL_ES 1
#define SDL_VIDEO_RENDER_OGL_ES2 1 #define SDL_VIDEO_RENDER_OGL_ES2 1

View File

@ -37,8 +37,6 @@ typedef struct
CGFloat scale; CGFloat scale;
} SDL_DisplayModeData; } SDL_DisplayModeData;
extern BOOL SDL_UIKit_supports_multiple_displays;
extern SDL_bool UIKit_IsDisplayLandscape(UIScreen *uiscreen); extern SDL_bool UIKit_IsDisplayLandscape(UIScreen *uiscreen);
extern int UIKit_InitModes(_THIS); extern int UIKit_InitModes(_THIS);

View File

@ -26,9 +26,6 @@
#include "SDL_uikitmodes.h" #include "SDL_uikitmodes.h"
BOOL SDL_UIKit_supports_multiple_displays = NO;
static int static int
UIKit_AllocateDisplayModeData(SDL_DisplayMode * mode, UIKit_AllocateDisplayModeData(SDL_DisplayMode * mode,
UIScreenMode * uiscreenmode, CGFloat scale) UIScreenMode * uiscreenmode, CGFloat scale)
@ -56,10 +53,7 @@ UIKit_AllocateDisplayModeData(SDL_DisplayMode * mode,
static void static void
UIKit_FreeDisplayModeData(SDL_DisplayMode * mode) UIKit_FreeDisplayModeData(SDL_DisplayMode * mode)
{ {
if (!SDL_UIKit_supports_multiple_displays) { if (mode->driverdata != NULL) {
/* Not on at least iPhoneOS 3.2 (versions prior to iPad). */
SDL_assert(mode->driverdata == NULL);
} else if (mode->driverdata != NULL) {
SDL_DisplayModeData *data = (SDL_DisplayModeData *)mode->driverdata; SDL_DisplayModeData *data = (SDL_DisplayModeData *)mode->driverdata;
[data->uiscreenmode release]; [data->uiscreenmode release];
SDL_free(data); SDL_free(data);
@ -121,19 +115,12 @@ UIKit_AddDisplay(UIScreen *uiscreen)
} }
/* When dealing with UIKit all coordinates are specified in terms of /* When dealing with UIKit all coordinates are specified in terms of
* what Apple refers to as points. On earlier devices without the * what Apple refers to as points. [UIScreen scale] indicates the
* so called "Retina" display, there is a one to one mapping between
* points and pixels. In other cases [UIScreen scale] indicates the
* relationship between points and pixels. Since SDL has no notion * relationship between points and pixels. Since SDL has no notion
* of points, we must compensate in all cases where dealing with such * of points, we must compensate in all cases where dealing with such
* units. * units.
*/ */
CGFloat scale; CGFloat scale = [uiscreen scale];
if ([UIScreen instancesRespondToSelector:@selector(scale)]) {
scale = [uiscreen scale]; /* iOS >= 4.0 */
} else {
scale = 1.0f; /* iOS < 4.0 */
}
SDL_VideoDisplay display; SDL_VideoDisplay display;
SDL_DisplayMode mode; SDL_DisplayMode mode;
@ -142,13 +129,7 @@ UIKit_AddDisplay(UIScreen *uiscreen)
mode.w = (int)(size.width * scale); mode.w = (int)(size.width * scale);
mode.h = (int)(size.height * scale); mode.h = (int)(size.height * scale);
UIScreenMode * uiscreenmode = nil; UIScreenMode * uiscreenmode = [uiscreen currentMode];
/* 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];
}
if (UIKit_AllocateDisplayModeData(&mode, uiscreenmode, scale) < 0) { if (UIKit_AllocateDisplayModeData(&mode, uiscreenmode, scale) < 0) {
return -1; return -1;
@ -189,30 +170,12 @@ UIKit_IsDisplayLandscape(UIScreen *uiscreen)
int int
UIKit_InitModes(_THIS) UIKit_InitModes(_THIS)
{ {
/* this tells us whether we are running on ios >= 3.2 */ for (UIScreen *uiscreen in [UIScreen screens]) {
SDL_UIKit_supports_multiple_displays = [UIScreen instancesRespondToSelector:@selector(currentMode)]; if (UIKit_AddDisplay(uiscreen) < 0) {
return -1;
/* 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;
}
}
} }
} }
/* We're done! */
return 0; return 0;
} }
@ -224,37 +187,8 @@ UIKit_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
SDL_bool isLandscape = UIKit_IsDisplayLandscape(data->uiscreen); SDL_bool isLandscape = UIKit_IsDisplayLandscape(data->uiscreen);
SDL_bool addRotation = (data->uiscreen == [UIScreen mainScreen]); SDL_bool addRotation = (data->uiscreen == [UIScreen mainScreen]);
if (SDL_UIKit_supports_multiple_displays) { for (UIScreenMode *uimode in [data->uiscreen availableModes]) {
/* availableModes showed up in 3.2 (the iPad and later). We should only CGSize size = [uimode size];
* 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;
int w = (int)size.width; int w = (int)size.width;
int h = (int)size.height; int h = (int)size.height;
@ -265,7 +199,18 @@ UIKit_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
h = tmp; 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) UIKit_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
{ {
SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata; SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
SDL_DisplayModeData *modedata = (SDL_DisplayModeData *)mode->driverdata;
if (!SDL_UIKit_supports_multiple_displays) { [data->uiscreen setCurrentMode:modedata->uiscreenmode];
/* 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 (data->uiscreen == [UIScreen mainScreen]) {
if (mode->w > mode->h) { if (mode->w > mode->h) {
if (!UIKit_IsDisplayLandscape(data->uiscreen)) { if (!UIKit_IsDisplayLandscape(data->uiscreen)) {
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO]; [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
} }
} else if (mode->w < mode->h) { } else if (mode->w < mode->h) {
if (UIKit_IsDisplayLandscape(data->uiscreen)) { if (UIKit_IsDisplayLandscape(data->uiscreen)) {
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO]; [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
}
} }
} }
} }
return 0; return 0;
} }

View File

@ -79,7 +79,7 @@
- (void)startAnimation; - (void)startAnimation;
- (void)stopAnimation; - (void)stopAnimation;
- (void)doLoop:(id)sender; - (void)doLoop:(CADisplayLink*)sender;
@end @end

View File

@ -84,8 +84,7 @@
} }
/* Set the appropriate scale (for retina display support) */ /* Set the appropriate scale (for retina display support) */
if ([self respondsToSelector:@selector(contentScaleFactor)]) self.contentScaleFactor = scale;
self.contentScaleFactor = scale;
/* create the buffers */ /* create the buffers */
glGenFramebuffersOES(1, &viewFramebuffer); glGenFramebuffersOES(1, &viewFramebuffer);
@ -171,11 +170,7 @@
- (void)startAnimation - (void)startAnimation
{ {
/* CADisplayLink is API new to iPhone SDK 3.1. displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(doLoop:)];
* 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 setFrameInterval:animationInterval]; [displayLink setFrameInterval:animationInterval];
[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
} }
@ -186,7 +181,7 @@
displayLink = nil; displayLink = nil;
} }
- (void)doLoop:(id)sender - (void)doLoop:(CADisplayLink*)sender
{ {
/* Don't run the game loop while a messagebox is up */ /* Don't run the game loop while a messagebox is up */
if (!UIKit_ShowingMessageBox()) { if (!UIKit_ShowingMessageBox()) {

View File

@ -372,6 +372,7 @@ void _uikit_keyboard_update() {
int height = view.keyboardHeight; int height = view.keyboardHeight;
int offsetx = 0; int offsetx = 0;
int offsety = 0; int offsety = 0;
float scale = [UIScreen mainScreen].scale;
if (height) { if (height) {
int sw,sh; int sw,sh;
SDL_GetWindowSize(window,&sw,&sh); SDL_GetWindowSize(window,&sw,&sh);
@ -392,11 +393,10 @@ void _uikit_keyboard_update() {
if (ui_orient == UIInterfaceOrientationPortraitUpsideDown) { if (ui_orient == UIInterfaceOrientationPortraitUpsideDown) {
offsety = -offsety; offsety = -offsety;
} }
if ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)]) {
float scale = [UIScreen mainScreen].scale; offsetx /= scale;
offsetx /= scale; offsety /= scale;
offsety /= scale;
}
view.frame = CGRectMake(offsetx,offsety,view.frame.size.width,view.frame.size.height); 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) { if (ui_orient == UIInterfaceOrientationLandscapeRight || ui_orient == UIInterfaceOrientationLandscapeLeft) {
height = keyboardSize.width; height = keyboardSize.width;
} }
if ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)]) { height *= [UIScreen mainScreen].scale;
height *= [UIScreen mainScreen].scale;
}
_uikit_keyboard_set_height(height); _uikit_keyboard_set_height(height);
} }
]; ];

View File

@ -130,6 +130,7 @@ UIKit_CreateWindow(_THIS, SDL_Window *window)
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata; SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
const BOOL external = ([UIScreen mainScreen] != data->uiscreen); 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 currently puts this window at the start of display's linked list. We rely on this. */
SDL_assert(_this->windows == window); 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 * user, so it's in standby), try to force the display to a resolution
* that most closely matches the desired window size. * that most closely matches the desired window size.
*/ */
if (SDL_UIKit_supports_multiple_displays) { if ((origsize.width == 0.0f) && (origsize.height == 0.0f)) {
const CGSize origsize = [[data->uiscreen currentMode] size]; if (display->num_display_modes == 0) {
if ((origsize.width == 0.0f) && (origsize.height == 0.0f)) { _this->GetDisplayModes(_this, display);
if (display->num_display_modes == 0) { }
_this->GetDisplayModes(_this, display);
}
int i; int i;
const SDL_DisplayMode *bestmode = NULL; const SDL_DisplayMode *bestmode = NULL;
for (i = display->num_display_modes; i >= 0; i--) { for (i = display->num_display_modes; i >= 0; i--) {
const SDL_DisplayMode *mode = &display->display_modes[i]; const SDL_DisplayMode *mode = &display->display_modes[i];
if ((mode->w >= window->w) && (mode->h >= window->h)) if ((mode->w >= window->w) && (mode->h >= window->h))
bestmode = mode; bestmode = mode;
} }
if (bestmode) { if (bestmode) {
SDL_DisplayModeData *modedata = (SDL_DisplayModeData *)bestmode->driverdata; SDL_DisplayModeData *modedata = (SDL_DisplayModeData *)bestmode->driverdata;
[data->uiscreen setCurrentMode:modedata->uiscreenmode]; [data->uiscreen setCurrentMode:modedata->uiscreenmode];
/* desktop_mode doesn't change here (the higher level will /* desktop_mode doesn't change here (the higher level will
* use it to set all the screens back to their defaults * use it to set all the screens back to their defaults
* upon window destruction, SDL_Quit(), etc. * upon window destruction, SDL_Quit(), etc.
*/ */
display->current_mode = *bestmode; display->current_mode = *bestmode;
}
} }
} }