(Apple/iOS) Come up with backwards compatible way of

accessing nativeScale
This commit is contained in:
Twinaphex 2015-02-24 05:26:41 +01:00
parent ebdf1ead54
commit 3b06c727b0
1 changed files with 28 additions and 4 deletions

View File

@ -226,12 +226,39 @@ static bool apple_gfx_ctx_set_video_mode(void *data, unsigned width, unsigned he
return true; return true;
} }
static CGFloat apple_gfx_ctx_get_native_scale(void)
{
SEL selector = NSSelectorFromString(BOXSTRING("scale"));
RAScreen *screen = (RAScreen*)get_chosen_screen();
if (!screen)
return 0.0f;
(void)selector;
#ifdef IOS
if ([screen respondsToSelector:@selector(nativeScale)])
{
float ret;
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:
[[[UIScreen mainScreen] class] instanceMethodSignatureForSelector:selector]];
[invocation setSelector:selector];
[invocation setTarget:[UIScreen mainScreen]];
[invocation invoke];
[invocation getReturnValue:&ret];
return ret;
}
#endif
return screen.scale;
}
static void apple_gfx_ctx_get_video_size(void *data, unsigned* width, unsigned* height) static void apple_gfx_ctx_get_video_size(void *data, unsigned* width, unsigned* height)
{ {
RAScreen *screen = (RAScreen*)get_chosen_screen(); RAScreen *screen = (RAScreen*)get_chosen_screen();
CGRect size = screen.bounds; CGRect size = screen.bounds;
gl_t *gl = (gl_t*)data; gl_t *gl = (gl_t*)data;
CGFloat screenscale = screen.scale; CGFloat screenscale = apple_gfx_ctx_get_native_scale();
if (gl) if (gl)
{ {
@ -243,9 +270,6 @@ static void apple_gfx_ctx_get_video_size(void *data, unsigned* width, unsigned*
#endif #endif
} }
if ([screen respondsToSelector:@selector(nativeScale)])
screenscale = screen.nativeScale;
*width = CGRectGetWidth(size) * screenscale; *width = CGRectGetWidth(size) * screenscale;
*height = CGRectGetHeight(size) * screenscale; *height = CGRectGetHeight(size) * screenscale;
} }