(OSX) Create get_backing_scale_factor

This commit is contained in:
twinaphex 2016-01-15 22:15:23 +01:00
parent 85575f4acc
commit 09a183df3f
2 changed files with 22 additions and 19 deletions

View File

@ -152,6 +152,22 @@ void *get_chosen_screen(void)
#endif
}
float get_backing_scale_factor(void)
{
#if __has_feature(objc_arc)
RAScreen *screen = (__bridge RAScreen*)get_chosen_screen();
#else
RAScreen *screen = (RAScreen*)get_chosen_screen();
#endif
if (!screen)
return 0.0;
#if MAC_OS_X_VERSION_10_7
return screen.backingScaleFactor;
#else
return 1.0f;
#endif
}
void cocoagl_gfx_ctx_update(void)
{
#if defined(HAVE_COCOA)
@ -419,11 +435,7 @@ static bool cocoagl_gfx_ctx_get_metrics(void *data, enum display_metric_types ty
float display_height = display_pixel_size.height;
float physical_width = display_physical_size.width;
float physical_height = display_physical_size.height;
#if MAC_OS_X_VERSION_10_7
float scale = screen.backingScaleFactor;
#else
float scale = 1.0f;
#endif
float scale = get_backing_scale_factor();
float dpi = (display_width/ physical_width) * 25.4f * scale;
#elif defined(HAVE_COCOATOUCH)
float scale = cocoagl_gfx_ctx_get_native_scale();

View File

@ -33,7 +33,8 @@
static id apple_platform;
void *get_chosen_screen(void);
extern void *get_chosen_screen(void);
extern float get_backing_scale_factor(void)
void apple_rarch_exited(void)
{
@ -108,25 +109,15 @@ void apple_rarch_exited(void)
NSPoint pos;
NSPoint mouse_pos;
CGFloat backing_scale_factor = 1.0f;
#if __has_feature(objc_arc)
RAScreen *screen = (__bridge RAScreen*)get_chosen_screen();
#else
RAScreen *screen = (RAScreen*)get_chosen_screen();
#endif
apple = (cocoa_input_data_t*)input_driver_get_data();
if (!apple || !screen)
apple = (cocoa_input_data_t*)input_driver_get_data();
float backing_scale_factor = get_backing_scale_factor();
if (!apple || (backing_scale_factor == 0.0)
return;
/* Relative */
apple->mouse_rel_x = event.deltaX;
apple->mouse_rel_y = event.deltaY;
#if MAC_OS_X_VERSION_10_7
backing_scale_factor = screen.backingScaleFactor;
#endif
/* Absolute */
pos = [[CocoaView get] convertPoint:[event locationInWindow] fromView:nil];
apple->touches[0].screen_x = pos.x * backing_scale_factor;