Fixed bug 2563 - Remove obsolete code for supporting iOS < 5
authorSam Lantinga <slouken@libsdl.org>
Sat, 21 Jun 2014 12:43:57 -0700
changeset 88917b6472f1b7ba
parent 8890 d9a2fa86cd97
child 8892 2c4d3823fdbb
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.
include/SDL_config_iphoneos.h
src/video/uikit/SDL_uikitmodes.h
src/video/uikit/SDL_uikitmodes.m
src/video/uikit/SDL_uikitopenglview.h
src/video/uikit/SDL_uikitopenglview.m
src/video/uikit/SDL_uikitview.m
src/video/uikit/SDL_uikitwindow.m
     1.1 --- a/include/SDL_config_iphoneos.h	Sat Jun 21 12:38:46 2014 -0700
     1.2 +++ b/include/SDL_config_iphoneos.h	Sat Jun 21 12:43:57 2014 -0700
     1.3 @@ -134,6 +134,7 @@
     1.4  #define SDL_VIDEO_DRIVER_DUMMY  1
     1.5  
     1.6  /* enable OpenGL ES */
     1.7 +#define SDL_VIDEO_OPENGL_ES2 1
     1.8  #define SDL_VIDEO_OPENGL_ES 1
     1.9  #define SDL_VIDEO_RENDER_OGL_ES 1
    1.10  #define SDL_VIDEO_RENDER_OGL_ES2    1
     2.1 --- a/src/video/uikit/SDL_uikitmodes.h	Sat Jun 21 12:38:46 2014 -0700
     2.2 +++ b/src/video/uikit/SDL_uikitmodes.h	Sat Jun 21 12:43:57 2014 -0700
     2.3 @@ -37,8 +37,6 @@
     2.4      CGFloat scale;
     2.5  } SDL_DisplayModeData;
     2.6  
     2.7 -extern BOOL SDL_UIKit_supports_multiple_displays;
     2.8 -
     2.9  extern SDL_bool UIKit_IsDisplayLandscape(UIScreen *uiscreen);
    2.10  
    2.11  extern int UIKit_InitModes(_THIS);
     3.1 --- a/src/video/uikit/SDL_uikitmodes.m	Sat Jun 21 12:38:46 2014 -0700
     3.2 +++ b/src/video/uikit/SDL_uikitmodes.m	Sat Jun 21 12:43:57 2014 -0700
     3.3 @@ -26,9 +26,6 @@
     3.4  #include "SDL_uikitmodes.h"
     3.5  
     3.6  
     3.7 -BOOL SDL_UIKit_supports_multiple_displays = NO;
     3.8 -
     3.9 -
    3.10  static int
    3.11  UIKit_AllocateDisplayModeData(SDL_DisplayMode * mode,
    3.12      UIScreenMode * uiscreenmode, CGFloat scale)
    3.13 @@ -56,10 +53,7 @@
    3.14  static void
    3.15  UIKit_FreeDisplayModeData(SDL_DisplayMode * mode)
    3.16  {
    3.17 -    if (!SDL_UIKit_supports_multiple_displays) {
    3.18 -        /* Not on at least iPhoneOS 3.2 (versions prior to iPad). */
    3.19 -        SDL_assert(mode->driverdata == NULL);
    3.20 -    } else if (mode->driverdata != NULL) {
    3.21 +    if (mode->driverdata != NULL) {
    3.22          SDL_DisplayModeData *data = (SDL_DisplayModeData *)mode->driverdata;
    3.23          [data->uiscreenmode release];
    3.24          SDL_free(data);
    3.25 @@ -121,19 +115,12 @@
    3.26      }
    3.27  
    3.28      /* When dealing with UIKit all coordinates are specified in terms of
    3.29 -     * what Apple refers to as points. On earlier devices without the
    3.30 -     * so called "Retina" display, there is a one to one mapping between
    3.31 -     * points and pixels. In other cases [UIScreen scale] indicates the
    3.32 +     * what Apple refers to as points. [UIScreen scale] indicates the
    3.33       * relationship between points and pixels. Since SDL has no notion
    3.34       * of points, we must compensate in all cases where dealing with such
    3.35       * units.
    3.36       */
    3.37 -    CGFloat scale;
    3.38 -    if ([UIScreen instancesRespondToSelector:@selector(scale)]) {
    3.39 -        scale = [uiscreen scale]; /* iOS >= 4.0 */
    3.40 -    } else {
    3.41 -        scale = 1.0f; /* iOS < 4.0 */
    3.42 -    }
    3.43 +    CGFloat scale = [uiscreen scale];
    3.44  
    3.45      SDL_VideoDisplay display;
    3.46      SDL_DisplayMode mode;
    3.47 @@ -142,13 +129,7 @@
    3.48      mode.w = (int)(size.width * scale);
    3.49      mode.h = (int)(size.height * scale);
    3.50  
    3.51 -    UIScreenMode * uiscreenmode = nil;
    3.52 -    /* UIScreenMode showed up in 3.2 (the iPad and later). We're
    3.53 -     * misusing this supports_multiple_displays flag here for that.
    3.54 -     */
    3.55 -    if (SDL_UIKit_supports_multiple_displays) {
    3.56 -        uiscreenmode = [uiscreen currentMode];
    3.57 -    }
    3.58 +    UIScreenMode * uiscreenmode = [uiscreen currentMode];
    3.59  
    3.60      if (UIKit_AllocateDisplayModeData(&mode, uiscreenmode, scale) < 0) {
    3.61          return -1;
    3.62 @@ -189,30 +170,12 @@
    3.63  int
    3.64  UIKit_InitModes(_THIS)
    3.65  {
    3.66 -    /* this tells us whether we are running on ios >= 3.2 */
    3.67 -    SDL_UIKit_supports_multiple_displays = [UIScreen instancesRespondToSelector:@selector(currentMode)];
    3.68 -
    3.69 -    /* Add the main screen. */
    3.70 -    if (UIKit_AddDisplay([UIScreen mainScreen]) < 0) {
    3.71 -        return -1;
    3.72 -    }
    3.73 -
    3.74 -    /* If this is iPhoneOS < 3.2, all devices are one screen, 320x480 pixels. */
    3.75 -    /*  The iPad added both a larger main screen and the ability to use
    3.76 -     *  external displays. So, add the other displays (screens in UI speak).
    3.77 -     */
    3.78 -    if (SDL_UIKit_supports_multiple_displays) {
    3.79 -        for (UIScreen *uiscreen in [UIScreen screens]) {
    3.80 -            /* Only add the other screens */
    3.81 -            if (uiscreen != [UIScreen mainScreen]) {
    3.82 -                if (UIKit_AddDisplay(uiscreen) < 0) {
    3.83 -                    return -1;
    3.84 -                }
    3.85 -            }
    3.86 +    for (UIScreen *uiscreen in [UIScreen screens]) {
    3.87 +        if (UIKit_AddDisplay(uiscreen) < 0) {
    3.88 +            return -1;
    3.89          }
    3.90      }
    3.91  
    3.92 -    /* We're done! */
    3.93      return 0;
    3.94  }
    3.95  
    3.96 @@ -224,37 +187,8 @@
    3.97      SDL_bool isLandscape = UIKit_IsDisplayLandscape(data->uiscreen);
    3.98      SDL_bool addRotation = (data->uiscreen == [UIScreen mainScreen]);
    3.99  
   3.100 -    if (SDL_UIKit_supports_multiple_displays) {
   3.101 -        /* availableModes showed up in 3.2 (the iPad and later). We should only
   3.102 -         * land here for at least that version of the OS.
   3.103 -         */
   3.104 -        for (UIScreenMode *uimode in [data->uiscreen availableModes]) {
   3.105 -            CGSize size = [uimode size];
   3.106 -            int w = (int)size.width;
   3.107 -            int h = (int)size.height;
   3.108 -
   3.109 -            /* Make sure the width/height are oriented correctly */
   3.110 -            if (isLandscape != (w > h)) {
   3.111 -                int tmp = w;
   3.112 -                w = h;
   3.113 -                h = tmp;
   3.114 -            }
   3.115 -
   3.116 -            /* Add the native screen resolution. */
   3.117 -            UIKit_AddDisplayMode(display, w, h, data->scale, uimode, addRotation);
   3.118 -
   3.119 -            if (data->scale != 1.0f) {
   3.120 -                /* Add the native screen resolution divided by its scale.
   3.121 -                 * This is so devices capable of e.g. 640x960 also advertise 320x480.
   3.122 -                 */
   3.123 -                UIKit_AddDisplayMode(display,
   3.124 -                    (int)(size.width / data->scale),
   3.125 -                    (int)(size.height / data->scale),
   3.126 -                    1.0f, uimode, addRotation);
   3.127 -            }
   3.128 -        }
   3.129 -    } else {
   3.130 -        const CGSize size = [data->uiscreen bounds].size;
   3.131 +    for (UIScreenMode *uimode in [data->uiscreen availableModes]) {
   3.132 +        CGSize size = [uimode size];
   3.133          int w = (int)size.width;
   3.134          int h = (int)size.height;
   3.135  
   3.136 @@ -265,7 +199,18 @@
   3.137              h = tmp;
   3.138          }
   3.139  
   3.140 -        UIKit_AddDisplayMode(display, w, h, 1.0f, nil, addRotation);
   3.141 +        /* Add the native screen resolution. */
   3.142 +        UIKit_AddDisplayMode(display, w, h, data->scale, uimode, addRotation);
   3.143 +
   3.144 +        if (data->scale != 1.0f) {
   3.145 +            /* Add the native screen resolution divided by its scale.
   3.146 +             * This is so devices capable of e.g. 640x960 also advertise 320x480.
   3.147 +             */
   3.148 +            UIKit_AddDisplayMode(display,
   3.149 +                (int)(size.width / data->scale),
   3.150 +                (int)(size.height / data->scale),
   3.151 +                1.0f, uimode, addRotation);
   3.152 +        }
   3.153      }
   3.154  }
   3.155  
   3.156 @@ -273,26 +218,22 @@
   3.157  UIKit_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
   3.158  {
   3.159      SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
   3.160 +    SDL_DisplayModeData *modedata = (SDL_DisplayModeData *)mode->driverdata;
   3.161  
   3.162 -    if (!SDL_UIKit_supports_multiple_displays) {
   3.163 -        /* Not on at least iPhoneOS 3.2 (versions prior to iPad). */
   3.164 -        SDL_assert(mode->driverdata == NULL);
   3.165 -    } else {
   3.166 -        SDL_DisplayModeData *modedata = (SDL_DisplayModeData *)mode->driverdata;
   3.167 -        [data->uiscreen setCurrentMode:modedata->uiscreenmode];
   3.168 +    [data->uiscreen setCurrentMode:modedata->uiscreenmode];
   3.169  
   3.170 -        if (data->uiscreen == [UIScreen mainScreen]) {
   3.171 -            if (mode->w > mode->h) {
   3.172 -                if (!UIKit_IsDisplayLandscape(data->uiscreen)) {
   3.173 -                    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
   3.174 -                }
   3.175 -            } else if (mode->w < mode->h) {
   3.176 -                if (UIKit_IsDisplayLandscape(data->uiscreen)) {
   3.177 -                    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
   3.178 -                }
   3.179 +    if (data->uiscreen == [UIScreen mainScreen]) {
   3.180 +        if (mode->w > mode->h) {
   3.181 +            if (!UIKit_IsDisplayLandscape(data->uiscreen)) {
   3.182 +                [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
   3.183 +            }
   3.184 +        } else if (mode->w < mode->h) {
   3.185 +            if (UIKit_IsDisplayLandscape(data->uiscreen)) {
   3.186 +                [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
   3.187              }
   3.188          }
   3.189      }
   3.190 +
   3.191      return 0;
   3.192  }
   3.193  
     4.1 --- a/src/video/uikit/SDL_uikitopenglview.h	Sat Jun 21 12:38:46 2014 -0700
     4.2 +++ b/src/video/uikit/SDL_uikitopenglview.h	Sat Jun 21 12:43:57 2014 -0700
     4.3 @@ -79,7 +79,7 @@
     4.4  - (void)startAnimation;
     4.5  - (void)stopAnimation;
     4.6  
     4.7 -- (void)doLoop:(id)sender;
     4.8 +- (void)doLoop:(CADisplayLink*)sender;
     4.9  
    4.10  @end
    4.11  
     5.1 --- a/src/video/uikit/SDL_uikitopenglview.m	Sat Jun 21 12:38:46 2014 -0700
     5.2 +++ b/src/video/uikit/SDL_uikitopenglview.m	Sat Jun 21 12:43:57 2014 -0700
     5.3 @@ -84,8 +84,7 @@
     5.4          }
     5.5  
     5.6          /* Set the appropriate scale (for retina display support) */
     5.7 -        if ([self respondsToSelector:@selector(contentScaleFactor)])
     5.8 -            self.contentScaleFactor = scale;
     5.9 +        self.contentScaleFactor = scale;
    5.10  
    5.11          /* create the buffers */
    5.12          glGenFramebuffersOES(1, &viewFramebuffer);
    5.13 @@ -171,11 +170,7 @@
    5.14  
    5.15  - (void)startAnimation
    5.16  {
    5.17 -    /* CADisplayLink is API new to iPhone SDK 3.1.
    5.18 -     * Compiling against earlier versions will result in a warning, but can be dismissed
    5.19 -     * if the system version runtime check for CADisplayLink exists in -initWithCoder:.
    5.20 -     */
    5.21 -    displayLink = [NSClassFromString(@"CADisplayLink") displayLinkWithTarget:self selector:@selector(doLoop:)];
    5.22 +    displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(doLoop:)];
    5.23      [displayLink setFrameInterval:animationInterval];
    5.24      [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
    5.25  }
    5.26 @@ -186,7 +181,7 @@
    5.27      displayLink = nil;
    5.28  }
    5.29  
    5.30 -- (void)doLoop:(id)sender
    5.31 +- (void)doLoop:(CADisplayLink*)sender
    5.32  {
    5.33      /* Don't run the game loop while a messagebox is up */
    5.34      if (!UIKit_ShowingMessageBox()) {
     6.1 --- a/src/video/uikit/SDL_uikitview.m	Sat Jun 21 12:38:46 2014 -0700
     6.2 +++ b/src/video/uikit/SDL_uikitview.m	Sat Jun 21 12:43:57 2014 -0700
     6.3 @@ -372,6 +372,7 @@
     6.4      int height = view.keyboardHeight;
     6.5      int offsetx = 0;
     6.6      int offsety = 0;
     6.7 +    float scale = [UIScreen mainScreen].scale;
     6.8      if (height) {
     6.9          int sw,sh;
    6.10          SDL_GetWindowSize(window,&sw,&sh);
    6.11 @@ -392,11 +393,10 @@
    6.12      if (ui_orient == UIInterfaceOrientationPortraitUpsideDown) {
    6.13          offsety = -offsety;
    6.14      }
    6.15 -    if ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)]) {
    6.16 -        float scale = [UIScreen mainScreen].scale;
    6.17 -        offsetx /= scale;
    6.18 -        offsety /= scale;
    6.19 -    }
    6.20 +
    6.21 +    offsetx /= scale;
    6.22 +    offsety /= scale;
    6.23 +
    6.24      view.frame = CGRectMake(offsetx,offsety,view.frame.size.width,view.frame.size.height);
    6.25  }
    6.26  
    6.27 @@ -424,9 +424,7 @@
    6.28                          if (ui_orient == UIInterfaceOrientationLandscapeRight || ui_orient == UIInterfaceOrientationLandscapeLeft) {
    6.29                              height = keyboardSize.width;
    6.30                          }
    6.31 -                        if ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)]) {
    6.32 -                            height *= [UIScreen mainScreen].scale;
    6.33 -                        }
    6.34 +                        height *= [UIScreen mainScreen].scale;
    6.35                          _uikit_keyboard_set_height(height);
    6.36                      }
    6.37       ];
     7.1 --- a/src/video/uikit/SDL_uikitwindow.m	Sat Jun 21 12:38:46 2014 -0700
     7.2 +++ b/src/video/uikit/SDL_uikitwindow.m	Sat Jun 21 12:43:57 2014 -0700
     7.3 @@ -130,6 +130,7 @@
     7.4      SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
     7.5      SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
     7.6      const BOOL external = ([UIScreen mainScreen] != data->uiscreen);
     7.7 +    const CGSize origsize = [[data->uiscreen currentMode] size];
     7.8  
     7.9      /* SDL currently puts this window at the start of display's linked list. We rely on this. */
    7.10      SDL_assert(_this->windows == window);
    7.11 @@ -143,31 +144,28 @@
    7.12       * user, so it's in standby), try to force the display to a resolution
    7.13       * that most closely matches the desired window size.
    7.14       */
    7.15 -    if (SDL_UIKit_supports_multiple_displays) {
    7.16 -        const CGSize origsize = [[data->uiscreen currentMode] size];
    7.17 -        if ((origsize.width == 0.0f) && (origsize.height == 0.0f)) {
    7.18 -            if (display->num_display_modes == 0) {
    7.19 -                _this->GetDisplayModes(_this, display);
    7.20 -            }
    7.21 +    if ((origsize.width == 0.0f) && (origsize.height == 0.0f)) {
    7.22 +        if (display->num_display_modes == 0) {
    7.23 +            _this->GetDisplayModes(_this, display);
    7.24 +        }
    7.25  
    7.26 -            int i;
    7.27 -            const SDL_DisplayMode *bestmode = NULL;
    7.28 -            for (i = display->num_display_modes; i >= 0; i--) {
    7.29 -                const SDL_DisplayMode *mode = &display->display_modes[i];
    7.30 -                if ((mode->w >= window->w) && (mode->h >= window->h))
    7.31 -                    bestmode = mode;
    7.32 -            }
    7.33 +        int i;
    7.34 +        const SDL_DisplayMode *bestmode = NULL;
    7.35 +        for (i = display->num_display_modes; i >= 0; i--) {
    7.36 +            const SDL_DisplayMode *mode = &display->display_modes[i];
    7.37 +            if ((mode->w >= window->w) && (mode->h >= window->h))
    7.38 +                bestmode = mode;
    7.39 +        }
    7.40  
    7.41 -            if (bestmode) {
    7.42 -                SDL_DisplayModeData *modedata = (SDL_DisplayModeData *)bestmode->driverdata;
    7.43 -                [data->uiscreen setCurrentMode:modedata->uiscreenmode];
    7.44 +        if (bestmode) {
    7.45 +            SDL_DisplayModeData *modedata = (SDL_DisplayModeData *)bestmode->driverdata;
    7.46 +            [data->uiscreen setCurrentMode:modedata->uiscreenmode];
    7.47  
    7.48 -                /* desktop_mode doesn't change here (the higher level will
    7.49 -                 * use it to set all the screens back to their defaults
    7.50 -                 * upon window destruction, SDL_Quit(), etc.
    7.51 -                 */
    7.52 -                display->current_mode = *bestmode;
    7.53 -            }
    7.54 +            /* desktop_mode doesn't change here (the higher level will
    7.55 +             * use it to set all the screens back to their defaults
    7.56 +             * upon window destruction, SDL_Quit(), etc.
    7.57 +             */
    7.58 +            display->current_mode = *bestmode;
    7.59          }
    7.60      }
    7.61