From 763127605e558395f02f568b9ab7883b0e981b35 Mon Sep 17 00:00:00 2001 From: Steveice10 <1269164+Steveice10@users.noreply.github.com> Date: Thu, 3 Nov 2022 01:47:10 -0700 Subject: [PATCH] qt: Extract CAMetalLayer from NSView to pass to MoltenVK. --- src/citra_qt/CMakeLists.txt | 2 ++ src/citra_qt/applesurfacehelper.h | 11 +++++++++++ src/citra_qt/applesurfacehelper.mm | 16 ++++++++++++++++ src/citra_qt/bootmanager.cpp | 8 +++++++- 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/citra_qt/applesurfacehelper.h create mode 100644 src/citra_qt/applesurfacehelper.mm diff --git a/src/citra_qt/CMakeLists.txt b/src/citra_qt/CMakeLists.txt index d139594f0..48c7e9d4f 100644 --- a/src/citra_qt/CMakeLists.txt +++ b/src/citra_qt/CMakeLists.txt @@ -250,6 +250,8 @@ if (APPLE) set_target_properties(citra-qt PROPERTIES MACOSX_BUNDLE TRUE) set_target_properties(citra-qt PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist) target_sources(citra-qt PRIVATE + applesurfacehelper.h + applesurfacehelper.mm macos_authorization.h macos_authorization.mm ) diff --git a/src/citra_qt/applesurfacehelper.h b/src/citra_qt/applesurfacehelper.h new file mode 100644 index 000000000..4839747d4 --- /dev/null +++ b/src/citra_qt/applesurfacehelper.h @@ -0,0 +1,11 @@ +// Copyright 2022 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +namespace AppleSurfaceHelper { + +void* GetSurfaceLayer(void* surface); + +} // namespace AppleSurfaceHelper diff --git a/src/citra_qt/applesurfacehelper.mm b/src/citra_qt/applesurfacehelper.mm new file mode 100644 index 000000000..f67e0e230 --- /dev/null +++ b/src/citra_qt/applesurfacehelper.mm @@ -0,0 +1,16 @@ +// Copyright 2022 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#import + +#include "citra_qt/applesurfacehelper.h" + +namespace AppleSurfaceHelper { + +void* GetSurfaceLayer(void* surface) { + NSView* view = static_cast(surface); + return view.layer; +} + +} // AppleSurfaceHelper diff --git a/src/citra_qt/bootmanager.cpp b/src/citra_qt/bootmanager.cpp index ab13c5cb8..a34c3e378 100644 --- a/src/citra_qt/bootmanager.cpp +++ b/src/citra_qt/bootmanager.cpp @@ -24,6 +24,10 @@ #include "video_core/renderer_base.h" #include "video_core/video_core.h" +#if defined(__APPLE__) +#include "citra_qt/applesurfacehelper.h" +#endif + #if !defined(WIN32) #include #endif @@ -334,8 +338,10 @@ static Frontend::EmuWindow::WindowSystemInfo GetWindowSystemInfo(QWindow* window wsi.type = GetWindowSystemType(); // Our Win32 Qt external doesn't have the private API. -#if defined(WIN32) || defined(__APPLE__) +#if defined(WIN32) wsi.render_surface = window ? reinterpret_cast(window->winId()) : nullptr; +#elif defined(__APPLE__) + wsi.render_surface = window ? AppleSurfaceHelper::GetSurfaceLayer(reinterpret_cast(window->winId())) : nullptr; #else QPlatformNativeInterface* pni = QGuiApplication::platformNativeInterface(); wsi.display_connection = pni->nativeResourceForWindow("display", window);