diff --git a/src/core/host_display.h b/src/core/host_display.h index 961844555..758f5bd31 100644 --- a/src/core/host_display.h +++ b/src/core/host_display.h @@ -304,6 +304,8 @@ protected: extern std::unique_ptr g_host_display; namespace Host { +std::unique_ptr CreateDisplayForAPI(HostDisplay::RenderAPI api); + /// Creates the host display. This may create a new window. The API used depends on the current configuration. bool AcquireHostDisplay(HostDisplay::RenderAPI api); diff --git a/src/duckstation-qt/qthost.cpp b/src/duckstation-qt/qthost.cpp index c6aad170b..2cecdbba8 100644 --- a/src/duckstation-qt/qthost.cpp +++ b/src/duckstation-qt/qthost.cpp @@ -48,19 +48,9 @@ Log_SetChannel(EmuThread); #ifdef _WIN32 #include "common/windows_headers.h" -#include "frontend-common/d3d11_host_display.h" -#include "frontend-common/d3d12_host_display.h" #include #endif -#ifdef WITH_OPENGL -#include "frontend-common/opengl_host_display.h" -#endif - -#ifdef WITH_VULKAN -#include "frontend-common/vulkan_host_display.h" -#endif - #ifdef WITH_CHEEVOS #include "frontend-common/achievements.h" #endif @@ -723,43 +713,9 @@ bool EmuThread::acquireHostDisplay(HostDisplay::RenderAPI api) releaseHostDisplay(); } - switch (api) - { -#ifdef WITH_VULKAN - case HostDisplay::RenderAPI::Vulkan: - g_host_display = std::make_unique(); - break; -#endif - -#ifdef WITH_OPENGL - case HostDisplay::RenderAPI::OpenGL: - case HostDisplay::RenderAPI::OpenGLES: - g_host_display = std::make_unique(); - break; -#endif - -#ifdef _WIN32 - case HostDisplay::RenderAPI::D3D12: - g_host_display = std::make_unique(); - break; - - case HostDisplay::RenderAPI::D3D11: - g_host_display = std::make_unique(); - break; -#endif - - default: -#if defined(_WIN32) && defined(_M_ARM64) - g_host_display = std::make_unique(); -#elif defined(_WIN32) - g_host_display = std::make_unique(); -#elif defined(WITH_OPENGL) - g_host_display = std::make_unique(); -#elif defined(WITH_VULKAN) - g_host_display = std::make_unique(); -#endif - break; - } + g_host_display = Host::CreateDisplayForAPI(api); + if (!g_host_display) + return false; if (!createDisplayRequested(m_is_fullscreen, m_is_rendering_to_main)) { diff --git a/src/frontend-common/common_host.cpp b/src/frontend-common/common_host.cpp index ef20ed0d9..2b5eed923 100644 --- a/src/frontend-common/common_host.cpp +++ b/src/frontend-common/common_host.cpp @@ -52,11 +52,21 @@ #ifdef _WIN32 #include "common/windows_headers.h" +#include "frontend-common/d3d11_host_display.h" +#include "frontend-common/d3d12_host_display.h" #include #include #include #endif +#ifdef WITH_OPENGL +#include "frontend-common/opengl_host_display.h" +#endif + +#ifdef WITH_VULKAN +#include "frontend-common/vulkan_host_display.h" +#endif + Log_SetChannel(CommonHostInterface); namespace CommonHost { @@ -121,6 +131,44 @@ void CommonHost::PumpMessagesOnCPUThread() #endif } +std::unique_ptr Host::CreateDisplayForAPI(HostDisplay::RenderAPI api) +{ + switch (api) + { +#ifdef WITH_VULKAN + case HostDisplay::RenderAPI::Vulkan: + return std::make_unique(); +#endif + +#ifdef WITH_OPENGL + case HostDisplay::RenderAPI::OpenGL: + case HostDisplay::RenderAPI::OpenGLES: + return std::make_unique(); +#endif + +#ifdef _WIN32 + case HostDisplay::RenderAPI::D3D12: + return std::make_unique(); + + case HostDisplay::RenderAPI::D3D11: + return std::make_unique(); +#endif + + default: +#if defined(_WIN32) && defined(_M_ARM64) + return std::make_unique(); +#elif defined(_WIN32) + return std::make_unique(); +#elif defined(WITH_OPENGL) + return std::make_unique(); +#elif defined(WITH_VULKAN) + return std::make_unique(); +#else + return {}; +#endif + } +} + bool CommonHost::CreateHostDisplayResources() { return true;