Host: Move CreateDisplayForAPI() into common code

This commit is contained in:
Connor McLaughlin 2022-08-24 19:12:09 +10:00
parent 4f2da4213d
commit 7277d29ff9
3 changed files with 53 additions and 47 deletions

View file

@ -304,6 +304,8 @@ protected:
extern std::unique_ptr<HostDisplay> g_host_display; extern std::unique_ptr<HostDisplay> g_host_display;
namespace Host { namespace Host {
std::unique_ptr<HostDisplay> CreateDisplayForAPI(HostDisplay::RenderAPI api);
/// Creates the host display. This may create a new window. The API used depends on the current configuration. /// Creates the host display. This may create a new window. The API used depends on the current configuration.
bool AcquireHostDisplay(HostDisplay::RenderAPI api); bool AcquireHostDisplay(HostDisplay::RenderAPI api);

View file

@ -48,19 +48,9 @@ Log_SetChannel(EmuThread);
#ifdef _WIN32 #ifdef _WIN32
#include "common/windows_headers.h" #include "common/windows_headers.h"
#include "frontend-common/d3d11_host_display.h"
#include "frontend-common/d3d12_host_display.h"
#include <ShlObj.h> #include <ShlObj.h>
#endif #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 #ifdef WITH_CHEEVOS
#include "frontend-common/achievements.h" #include "frontend-common/achievements.h"
#endif #endif
@ -723,43 +713,9 @@ bool EmuThread::acquireHostDisplay(HostDisplay::RenderAPI api)
releaseHostDisplay(); releaseHostDisplay();
} }
switch (api) g_host_display = Host::CreateDisplayForAPI(api);
{ if (!g_host_display)
#ifdef WITH_VULKAN return false;
case HostDisplay::RenderAPI::Vulkan:
g_host_display = std::make_unique<FrontendCommon::VulkanHostDisplay>();
break;
#endif
#ifdef WITH_OPENGL
case HostDisplay::RenderAPI::OpenGL:
case HostDisplay::RenderAPI::OpenGLES:
g_host_display = std::make_unique<FrontendCommon::OpenGLHostDisplay>();
break;
#endif
#ifdef _WIN32
case HostDisplay::RenderAPI::D3D12:
g_host_display = std::make_unique<FrontendCommon::D3D12HostDisplay>();
break;
case HostDisplay::RenderAPI::D3D11:
g_host_display = std::make_unique<FrontendCommon::D3D11HostDisplay>();
break;
#endif
default:
#if defined(_WIN32) && defined(_M_ARM64)
g_host_display = std::make_unique<FrontendCommon::D3D12HostDisplay>();
#elif defined(_WIN32)
g_host_display = std::make_unique<FrontendCommon::D3D11HostDisplay>();
#elif defined(WITH_OPENGL)
g_host_display = std::make_unique<FrontendCommon::OpenGLHostDisplay>();
#elif defined(WITH_VULKAN)
g_host_display = std::make_unique<FrontendCommon::VulkanHostDisplay>();
#endif
break;
}
if (!createDisplayRequested(m_is_fullscreen, m_is_rendering_to_main)) if (!createDisplayRequested(m_is_fullscreen, m_is_rendering_to_main))
{ {

View file

@ -52,11 +52,21 @@
#ifdef _WIN32 #ifdef _WIN32
#include "common/windows_headers.h" #include "common/windows_headers.h"
#include "frontend-common/d3d11_host_display.h"
#include "frontend-common/d3d12_host_display.h"
#include <KnownFolders.h> #include <KnownFolders.h>
#include <ShlObj.h> #include <ShlObj.h>
#include <mmsystem.h> #include <mmsystem.h>
#endif #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); Log_SetChannel(CommonHostInterface);
namespace CommonHost { namespace CommonHost {
@ -121,6 +131,44 @@ void CommonHost::PumpMessagesOnCPUThread()
#endif #endif
} }
std::unique_ptr<HostDisplay> Host::CreateDisplayForAPI(HostDisplay::RenderAPI api)
{
switch (api)
{
#ifdef WITH_VULKAN
case HostDisplay::RenderAPI::Vulkan:
return std::make_unique<FrontendCommon::VulkanHostDisplay>();
#endif
#ifdef WITH_OPENGL
case HostDisplay::RenderAPI::OpenGL:
case HostDisplay::RenderAPI::OpenGLES:
return std::make_unique<FrontendCommon::OpenGLHostDisplay>();
#endif
#ifdef _WIN32
case HostDisplay::RenderAPI::D3D12:
return std::make_unique<FrontendCommon::D3D12HostDisplay>();
case HostDisplay::RenderAPI::D3D11:
return std::make_unique<FrontendCommon::D3D11HostDisplay>();
#endif
default:
#if defined(_WIN32) && defined(_M_ARM64)
return std::make_unique<FrontendCommon::D3D12HostDisplay>();
#elif defined(_WIN32)
return std::make_unique<FrontendCommon::D3D11HostDisplay>();
#elif defined(WITH_OPENGL)
return std::make_unique<FrontendCommon::OpenGLHostDisplay>();
#elif defined(WITH_VULKAN)
return std::make_unique<FrontendCommon::VulkanHostDisplay>();
#else
return {};
#endif
}
}
bool CommonHost::CreateHostDisplayResources() bool CommonHost::CreateHostDisplayResources()
{ {
return true; return true;