From 7781334c9881ea808fa5fd207ce9453de46e4806 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Wed, 8 Apr 2015 09:02:47 +0200 Subject: [PATCH] (OSX) Start implementing apple_gfx_ctx_get_metrics - not yet iOS-compatible --- apple/common/apple_cocoa_common.m | 35 ++++++++++++++++++++++++++++++- gfx/video_context_driver.h | 8 +++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/apple/common/apple_cocoa_common.m b/apple/common/apple_cocoa_common.m index f5263df0ad..4097f7d04d 100644 --- a/apple/common/apple_cocoa_common.m +++ b/apple/common/apple_cocoa_common.m @@ -24,6 +24,7 @@ #include "../../general.h" #include "../../runloop.h" #include "../../frontend/frontend.h" +#include "../../gfx/video_context_driver.h" #ifndef __has_feature /* Compatibility with non-Clang compilers. */ @@ -273,7 +274,7 @@ void apple_bind_game_view_fbo(void) static RAScreen* get_chosen_screen(void) { #if defined(OSX) && !defined(MAC_OS_X_VERSION_10_6) - return [NSScreen mainScreen]; + return [RAScreen mainScreen]; #else settings_t *settings = config_get_ptr(); if (settings->video.monitor_index >= RAScreen.screens.count) @@ -502,6 +503,38 @@ static void apple_gfx_ctx_update_window_title(void *data) rarch_main_msg_queue_push(buf_fps, 1, 1, false); } +static bool apple_gfx_ctx_get_metrics(void *data, enum display_metric_types type, + float *value) +{ +#ifdef OSX + RAScreen *screen = [RAScreen mainScreen]; + NSDictionary *description = [screen deviceDescription]; + NSSize displayPixelSize = [[description objectForKey:NSDeviceSize] sizeValue]; + CGSize displayPhysicalSize = CGDisplayScreenSize( + [[description objectForKey:@"NSScreenNumber"] unsignedIntValue]); + + switch (type) + { + case DISPLAY_METRIC_NONE: + return false; + case DISPLAY_METRIC_MM_WIDTH: + *value = displayPhysicalSize.width; + break; + case DISPLAY_METRIC_MM_HEIGHT: + *value = displayPhysicalSize.height; + break; + case DISPLAY_METRIC_DPI: + /* 25.4 mm in an inch. */ + *value = (displayPixelSize.width / displayPhysicalSize.width) * 25.4f; + break; + default: + return false; + } +#endif + + return true; +} + static bool apple_gfx_ctx_has_focus(void *data) { (void)data; diff --git a/gfx/video_context_driver.h b/gfx/video_context_driver.h index a4419c7c05..59250055a3 100644 --- a/gfx/video_context_driver.h +++ b/gfx/video_context_driver.h @@ -40,6 +40,14 @@ enum gfx_ctx_api GFX_CTX_DIRECT3D9_API, GFX_CTX_OPENVG_API }; + +enum display_metric_types +{ + DISPLAY_METRIC_NONE = 0, + DISPLAY_METRIC_MM_WIDTH, + DISPLAY_METRIC_MM_HEIGHT, + DISPLAY_METRIC_DPI, +}; typedef void (*gfx_ctx_proc_t)(void);