From ffc5f5b503b794e76c0bfad5e1907f8d767dd339 Mon Sep 17 00:00:00 2001 From: Carlos Aragones <> Date: Wed, 28 Apr 2021 14:11:13 +0200 Subject: [PATCH] MacOS Mojave test and fix --- src/MiniFB_internal.c | 2 +- src/macosx/MacMiniFB.m | 5 +++++ src/macosx/OSXViewDelegate.m | 15 +++++++++++++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/MiniFB_internal.c b/src/MiniFB_internal.c index 9a721a7..a34a734 100644 --- a/src/MiniFB_internal.c +++ b/src/MiniFB_internal.c @@ -103,7 +103,7 @@ resize_dst(SWindowData *window_data, uint32_t width, uint32_t height) { window_data->dst_height = (uint32_t) (height * window_data->factor_height); } -#if !defined(USE_OPENGL_API) +#if !defined(USE_OPENGL_API) && !defined(USE_METAL_API) //------------------------------------- void diff --git a/src/macosx/MacMiniFB.m b/src/macosx/MacMiniFB.m index 7e40040..581e354 100644 --- a/src/macosx/MacMiniFB.m +++ b/src/macosx/MacMiniFB.m @@ -297,6 +297,7 @@ mfb_update_events(struct mfb_window *window) { //------------------------------------- extern double g_time_for_frame; +extern bool g_use_hardware_sync; bool mfb_wait_sync(struct mfb_window *window) { @@ -312,6 +313,10 @@ mfb_wait_sync(struct mfb_window *window) { return false; } + if(g_use_hardware_sync) { + return true; + } + @autoreleasepool { SWindowData_OSX *window_data_osx = (SWindowData_OSX *) window_data->specific; if(window_data_osx == 0x0) { diff --git a/src/macosx/OSXViewDelegate.m b/src/macosx/OSXViewDelegate.m index 9a2f933..9102ce0 100644 --- a/src/macosx/OSXViewDelegate.m +++ b/src/macosx/OSXViewDelegate.m @@ -80,6 +80,10 @@ NSString *g_shader_src = kShader( // Setup command queue command_queue = [metal_device newCommandQueue]; + id commandBuffer = [command_queue commandBuffer]; + if ([commandBuffer respondsToSelector:@selector(presentDrawable:afterMinimumDuration:)]) { + g_use_hardware_sync = true; + } [self _createShaders]; [self _createAssets]; @@ -169,9 +173,16 @@ NSString *g_shader_src = kShader( //------------------------------------- - (void) drawInMTKView:(nonnull MTKView *) view { if (g_target_fps_changed) { - view.preferredFramesPerSecond = (int) (1.0 / g_time_for_frame); + // MacOS is ignoring this :() + if (g_time_for_frame == 0) { + // Contrary to what is stated in the documentation, + // 0 means that it does not update. + view.preferredFramesPerSecond = 9999; + } + else { + view.preferredFramesPerSecond = (int) (1.0 / g_time_for_frame); + } g_target_fps_changed = false; - g_use_hardware_sync = true; } // Wait to ensure only MaxBuffersInFlight number of frames are getting proccessed