Skip to content

Commit

Permalink
Expose display refresh rate on iOS/tvOS 10.3+.
Browse files Browse the repository at this point in the history
  • Loading branch information
slime73 committed Jun 11, 2017
1 parent 325330e commit bb100d3
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions src/video/uikit/SDL_uikitmodes.m
Expand Up @@ -68,21 +68,33 @@ @implementation SDL_DisplayModeData
}
}

static NSUInteger
UIKit_GetDisplayModeRefreshRate(UIScreen *uiscreen)
{
#ifdef __IPHONE_10_3
if ([uiscreen respondsToSelector:@selector(maximumFramesPerSecond)]) {
return uiscreen.maximumFramesPerSecond;
}
#endif
return 0;
}

static int
UIKit_AddSingleDisplayMode(SDL_VideoDisplay * display, int w, int h,
UIScreenMode * uiscreenmode)
UIScreen * uiscreen, UIScreenMode * uiscreenmode)
{
SDL_DisplayMode mode;
SDL_zero(mode);

mode.format = SDL_PIXELFORMAT_ABGR8888;
mode.refresh_rate = 0;
if (UIKit_AllocateDisplayModeData(&mode, uiscreenmode) < 0) {
return -1;
}

mode.format = SDL_PIXELFORMAT_ABGR8888;
mode.refresh_rate = (int) UIKit_GetDisplayModeRefreshRate(uiscreen);
mode.w = w;
mode.h = h;

if (SDL_AddDisplayMode(display, &mode)) {
return 0;
} else {
Expand All @@ -92,16 +104,16 @@ @implementation SDL_DisplayModeData
}

static int
UIKit_AddDisplayMode(SDL_VideoDisplay * display, int w, int h,
UIKit_AddDisplayMode(SDL_VideoDisplay * display, int w, int h, UIScreen * uiscreen,
UIScreenMode * uiscreenmode, SDL_bool addRotation)
{
if (UIKit_AddSingleDisplayMode(display, w, h, uiscreenmode) < 0) {
if (UIKit_AddSingleDisplayMode(display, w, h, uiscreen, uiscreenmode) < 0) {
return -1;
}

if (addRotation) {
/* Add the rotated version */
if (UIKit_AddSingleDisplayMode(display, h, w, uiscreenmode) < 0) {
if (UIKit_AddSingleDisplayMode(display, h, w, uiscreen, uiscreenmode) < 0) {
return -1;
}
}
Expand All @@ -112,7 +124,11 @@ @implementation SDL_DisplayModeData
static int
UIKit_AddDisplay(UIScreen *uiscreen)
{
UIScreenMode *uiscreenmode = uiscreen.currentMode;
CGSize size = uiscreen.bounds.size;
SDL_VideoDisplay display;
SDL_DisplayMode mode;
SDL_zero(mode);

/* Make sure the width/height are oriented correctly */
if (UIKit_IsDisplayLandscape(uiscreen) != (size.width > size.height)) {
Expand All @@ -121,15 +137,11 @@ @implementation SDL_DisplayModeData
size.height = height;
}

SDL_VideoDisplay display;
SDL_DisplayMode mode;
SDL_zero(mode);
mode.format = SDL_PIXELFORMAT_ABGR8888;
mode.refresh_rate = (int) UIKit_GetDisplayModeRefreshRate(uiscreen);
mode.w = (int) size.width;
mode.h = (int) size.height;

UIScreenMode *uiscreenmode = uiscreen.currentMode;

if (UIKit_AllocateDisplayModeData(&mode, uiscreenmode) < 0) {
return -1;
}
Expand Down Expand Up @@ -220,7 +232,7 @@ @implementation SDL_DisplayModeData
h = tmp;
}

UIKit_AddDisplayMode(display, w, h, uimode, addRotation);
UIKit_AddDisplayMode(display, w, h, data.uiscreen, uimode, addRotation);
}
}
}
Expand Down

0 comments on commit bb100d3

Please sign in to comment.