Make customized version of get_video_size for OSX 10.7 and up to

avoid selector grabbing
This commit is contained in:
twinaphex 2021-01-17 05:39:03 +01:00
parent e42f2b552f
commit 6ac08ec123

View File

@ -224,6 +224,7 @@ void *get_chosen_screen(void)
return ((BRIDGE void*)[screens objectAtIndex:monitor_index]); return ((BRIDGE void*)[screens objectAtIndex:monitor_index]);
} }
/* NOTE: backingScaleFactor only available on MacOS X 10.7 and up. */
float get_backing_scale_factor(void) float get_backing_scale_factor(void)
{ {
static float static float
@ -461,28 +462,43 @@ static void cocoagl_gfx_ctx_input_driver(void *data,
*input_data = NULL; *input_data = NULL;
} }
static void cocoagl_gfx_ctx_get_video_size(void *data, #if MAC_OS_X_VERSION_10_7 && defined(OSX)
/* NOTE: convertRectToBacking only available on MacOS X 10.7 and up.
* Therefore, make specialized version of this function instead of
* going through a selector for every call. */
static void cocoagl_gfx_ctx_get_video_size_osx10_7_and_up(void *data,
unsigned* width, unsigned* height) unsigned* width, unsigned* height)
{ {
float screenscale = cocoagl_gfx_ctx_get_native_scale(); float screenscale = cocoagl_gfx_ctx_get_native_scale();
#ifdef OSX
CGRect size, cgrect;
GLsizei backingPixelWidth, backingPixelHeight;
#if defined(HAVE_COCOA_METAL) #if defined(HAVE_COCOA_METAL)
NSView *g_view = apple_platform.renderView; NSView *g_view = apple_platform.renderView;
#elif defined(HAVE_COCOA) #elif defined(HAVE_COCOA)
CocoaView *g_view = g_instance; CocoaView *g_view = g_instance;
#endif #endif
#if MAC_OS_X_VERSION_10_7 CGRect cgrect = NSRectToCGRect([g_view convertRectToBacking:[g_view bounds]]);
SEL selector = NSSelectorFromString(BOXSTRING("convertRectToBacking:")); GLsizei backingPixelWidth = CGRectGetWidth(cgrect);
if ([g_view respondsToSelector:selector]) GLsizei backingPixelHeight = CGRectGetHeight(cgrect);
cgrect = NSRectToCGRect([g_view convertRectToBacking:[g_view bounds]]); CGRect size = CGRectMake(0, 0, backingPixelWidth, backingPixelHeight);
else *width = CGRectGetWidth(size) * screenscale;
*height = CGRectGetHeight(size) * screenscale;
}
#endif #endif
cgrect = NSRectToCGRect([g_view frame]);
backingPixelWidth = CGRectGetWidth(cgrect); static void cocoagl_gfx_ctx_get_video_size(void *data,
backingPixelHeight = CGRectGetHeight(cgrect); unsigned* width, unsigned* height)
size = CGRectMake(0, 0, backingPixelWidth, backingPixelHeight); {
float screenscale = cocoagl_gfx_ctx_get_native_scale();
#ifdef OSX
#if defined(HAVE_COCOA_METAL)
NSView *g_view = apple_platform.renderView;
#elif defined(HAVE_COCOA)
CocoaView *g_view = g_instance;
#endif
CGRect cgrect = NSRectToCGRect([g_view frame]);
GLsizei backingPixelWidth = CGRectGetWidth(cgrect);
GLsizei backingPixelHeight = CGRectGetHeight(cgrect);
CGRect size = CGRectMake(0, 0, backingPixelWidth, backingPixelHeight);
#else #else
CGRect size = g_view.bounds; CGRect size = g_view.bounds;
#endif #endif
@ -554,7 +570,12 @@ static void cocoagl_gfx_ctx_check_window(void *data, bool *quit,
break; break;
} }
#if MAC_OS_X_VERSION_10_7 && defined(OSX)
cocoagl_gfx_ctx_get_video_size_osx10_7_and_up(data, &new_width, &new_height);
#else
cocoagl_gfx_ctx_get_video_size(data, &new_width, &new_height); cocoagl_gfx_ctx_get_video_size(data, &new_width, &new_height);
#endif
if (new_width != *width || new_height != *height) if (new_width != *width || new_height != *height)
{ {
*width = new_width; *width = new_width;
@ -897,7 +918,11 @@ const gfx_ctx_driver_t gfx_ctx_cocoagl = {
cocoagl_gfx_ctx_bind_api, cocoagl_gfx_ctx_bind_api,
cocoagl_gfx_ctx_swap_interval, cocoagl_gfx_ctx_swap_interval,
cocoagl_gfx_ctx_set_video_mode, cocoagl_gfx_ctx_set_video_mode,
#if MAC_OS_X_VERSION_10_7 && defined(OSX)
cocoagl_gfx_ctx_get_video_size_osx10_7_and_up,
#else
cocoagl_gfx_ctx_get_video_size, cocoagl_gfx_ctx_get_video_size,
#endif
NULL, /* get_refresh_rate */ NULL, /* get_refresh_rate */
NULL, /* get_video_output_size */ NULL, /* get_video_output_size */
NULL, /* get_video_output_prev */ NULL, /* get_video_output_prev */