From 42b19c9749b5ccd0c9602e47e2f3d148d2163ab8 Mon Sep 17 00:00:00 2001
From: Alex Szpakowski <slime73@gmail.com>
Date: Sat, 30 Dec 2017 22:39:55 -0400
Subject: [PATCH] metal: Respect the vsync flag on macOS 10.13+.

---
 src/render/metal/SDL_render_metal.m | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/render/metal/SDL_render_metal.m b/src/render/metal/SDL_render_metal.m
index 33b217282..f993881f2 100644
--- a/src/render/metal/SDL_render_metal.m
+++ b/src/render/metal/SDL_render_metal.m
@@ -356,8 +356,14 @@ METAL_CreateRenderer(SDL_Window * window, Uint32 flags)
     renderer->info = METAL_RenderDriver.info;
     renderer->info.flags = (SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE);
 
-    // !!! FIXME: how do you control this in Metal?
-    renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
+#if defined(__MACOSX__) && defined(MAC_OS_X_VERSION_10_13)
+    if (@available(macOS 10.13, *)) {
+        layer.displaySyncEnabled = (flags & SDL_RENDERER_PRESENTVSYNC) != 0;
+    } else
+#endif
+    {
+        renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
+    }
 
     return renderer;
 }