summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends/Vulkan/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Core/VideoBackends/Vulkan/main.cpp')
-rw-r--r--Source/Core/VideoBackends/Vulkan/main.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/Source/Core/VideoBackends/Vulkan/main.cpp b/Source/Core/VideoBackends/Vulkan/main.cpp
index 40798934e7..63d61c9d01 100644
--- a/Source/Core/VideoBackends/Vulkan/main.cpp
+++ b/Source/Core/VideoBackends/Vulkan/main.cpp
@@ -24,6 +24,10 @@
#include "VideoCommon/VideoBackendBase.h"
#include "VideoCommon/VideoConfig.h"
+#if defined(VK_USE_PLATFORM_MACOS_MVK)
+#include <objc/message.h>
+#endif
+
namespace Vulkan
{
void VideoBackend::InitBackendInfo()
@@ -272,4 +276,33 @@ void VideoBackend::Shutdown()
ShutdownShared();
UnloadVulkanLibrary();
}
+
+void VideoBackend::PrepareWindow(const WindowSystemInfo& wsi)
+{
+#if defined(VK_USE_PLATFORM_MACOS_MVK)
+ // This is kinda messy, but it avoids having to write Objective C++ just to create a metal layer.
+ id view = reinterpret_cast<id>(wsi.render_surface);
+ Class clsCAMetalLayer = objc_getClass("CAMetalLayer");
+ if (!clsCAMetalLayer)
+ {
+ ERROR_LOG(VIDEO, "Failed to get CAMetalLayer class.");
+ return;
+ }
+
+ // [CAMetalLayer layer]
+ id layer = reinterpret_cast<id (*)(Class, SEL)>(objc_msgSend)(objc_getClass("CAMetalLayer"),
+ sel_getUid("layer"));
+ if (!layer)
+ {
+ ERROR_LOG(VIDEO, "Failed to create Metal layer.");
+ return;
+ }
+
+ // [view setWantsLayer:YES]
+ reinterpret_cast<void (*)(id, SEL, BOOL)>(objc_msgSend)(view, sel_getUid("setWantsLayer:"), YES);
+
+ // [view setLayer:layer]
+ reinterpret_cast<void (*)(id, SEL, id)>(objc_msgSend)(view, sel_getUid("setLayer:"), layer);
+#endif
+}
} // namespace Vulkan