Expose display refresh rate on iOS/tvOS 10.3+.
authorAlex Szpakowski <slime73@gmail.com>
Sat, 10 Jun 2017 21:29:37 -0300
changeset 110867b1c534105d5
parent 11085 d03a7de85bd5
child 11087 71ef4b78a753
Expose display refresh rate on iOS/tvOS 10.3+.
src/video/uikit/SDL_uikitmodes.m
     1.1 --- a/src/video/uikit/SDL_uikitmodes.m	Fri Jun 09 17:37:43 2017 -0400
     1.2 +++ b/src/video/uikit/SDL_uikitmodes.m	Sat Jun 10 21:29:37 2017 -0300
     1.3 @@ -68,21 +68,33 @@
     1.4      }
     1.5  }
     1.6  
     1.7 +static NSUInteger
     1.8 +UIKit_GetDisplayModeRefreshRate(UIScreen *uiscreen)
     1.9 +{
    1.10 +#ifdef __IPHONE_10_3
    1.11 +    if ([uiscreen respondsToSelector:@selector(maximumFramesPerSecond)]) {
    1.12 +        return uiscreen.maximumFramesPerSecond;
    1.13 +    }
    1.14 +#endif
    1.15 +    return 0;
    1.16 +}
    1.17 +
    1.18  static int
    1.19  UIKit_AddSingleDisplayMode(SDL_VideoDisplay * display, int w, int h,
    1.20 -    UIScreenMode * uiscreenmode)
    1.21 +    UIScreen * uiscreen, UIScreenMode * uiscreenmode)
    1.22  {
    1.23      SDL_DisplayMode mode;
    1.24      SDL_zero(mode);
    1.25  
    1.26 -    mode.format = SDL_PIXELFORMAT_ABGR8888;
    1.27 -    mode.refresh_rate = 0;
    1.28      if (UIKit_AllocateDisplayModeData(&mode, uiscreenmode) < 0) {
    1.29          return -1;
    1.30      }
    1.31  
    1.32 +    mode.format = SDL_PIXELFORMAT_ABGR8888;
    1.33 +    mode.refresh_rate = (int) UIKit_GetDisplayModeRefreshRate(uiscreen);
    1.34      mode.w = w;
    1.35      mode.h = h;
    1.36 +
    1.37      if (SDL_AddDisplayMode(display, &mode)) {
    1.38          return 0;
    1.39      } else {
    1.40 @@ -92,16 +104,16 @@
    1.41  }
    1.42  
    1.43  static int
    1.44 -UIKit_AddDisplayMode(SDL_VideoDisplay * display, int w, int h,
    1.45 +UIKit_AddDisplayMode(SDL_VideoDisplay * display, int w, int h, UIScreen * uiscreen,
    1.46                       UIScreenMode * uiscreenmode, SDL_bool addRotation)
    1.47  {
    1.48 -    if (UIKit_AddSingleDisplayMode(display, w, h, uiscreenmode) < 0) {
    1.49 +    if (UIKit_AddSingleDisplayMode(display, w, h, uiscreen, uiscreenmode) < 0) {
    1.50          return -1;
    1.51      }
    1.52  
    1.53      if (addRotation) {
    1.54          /* Add the rotated version */
    1.55 -        if (UIKit_AddSingleDisplayMode(display, h, w, uiscreenmode) < 0) {
    1.56 +        if (UIKit_AddSingleDisplayMode(display, h, w, uiscreen, uiscreenmode) < 0) {
    1.57              return -1;
    1.58          }
    1.59      }
    1.60 @@ -112,7 +124,11 @@
    1.61  static int
    1.62  UIKit_AddDisplay(UIScreen *uiscreen)
    1.63  {
    1.64 +    UIScreenMode *uiscreenmode = uiscreen.currentMode;
    1.65      CGSize size = uiscreen.bounds.size;
    1.66 +    SDL_VideoDisplay display;
    1.67 +    SDL_DisplayMode mode;
    1.68 +    SDL_zero(mode);
    1.69  
    1.70      /* Make sure the width/height are oriented correctly */
    1.71      if (UIKit_IsDisplayLandscape(uiscreen) != (size.width > size.height)) {
    1.72 @@ -121,15 +137,11 @@
    1.73          size.height = height;
    1.74      }
    1.75  
    1.76 -    SDL_VideoDisplay display;
    1.77 -    SDL_DisplayMode mode;
    1.78 -    SDL_zero(mode);
    1.79      mode.format = SDL_PIXELFORMAT_ABGR8888;
    1.80 +    mode.refresh_rate = (int) UIKit_GetDisplayModeRefreshRate(uiscreen);
    1.81      mode.w = (int) size.width;
    1.82      mode.h = (int) size.height;
    1.83  
    1.84 -    UIScreenMode *uiscreenmode = uiscreen.currentMode;
    1.85 -
    1.86      if (UIKit_AllocateDisplayModeData(&mode, uiscreenmode) < 0) {
    1.87          return -1;
    1.88      }
    1.89 @@ -220,7 +232,7 @@
    1.90                  h = tmp;
    1.91              }
    1.92  
    1.93 -            UIKit_AddDisplayMode(display, w, h, uimode, addRotation);
    1.94 +            UIKit_AddDisplayMode(display, w, h, data.uiscreen, uimode, addRotation);
    1.95          }
    1.96      }
    1.97  }