NoGUI: Move DRM display to GL context

We don't use it for Vulkan.
This commit is contained in:
Connor McLaughlin 2021-02-04 19:32:47 +10:00
parent 8f9bbb0bba
commit 3e9fdf22bf
8 changed files with 31 additions and 39 deletions

View file

@ -109,7 +109,7 @@ std::unique_ptr<GL::Context> Context::Create(const WindowInfo& wi, const Version
#endif #endif
#if defined(USE_GBM) #if defined(USE_GBM)
if (wi.type == WindowInfo::Type::DRM) if (wi.type == WindowInfo::Type::Display)
context = ContextEGLGBM::Create(wi, versions_to_try, num_versions_to_try); context = ContextEGLGBM::Create(wi, versions_to_try, num_versions_to_try);
#endif #endif

View file

@ -29,7 +29,7 @@ ContextEGLGBM::~ContextEGLGBM()
while (m_num_buffers > 0) while (m_num_buffers > 0)
{ {
Buffer& buffer = m_buffers[--m_num_buffers]; Buffer& buffer = m_buffers[--m_num_buffers];
GetDisplay()->RemoveBuffer(buffer.fb_id); m_drm_display.RemoveBuffer(buffer.fb_id);
} }
if (m_fb_surface) if (m_fb_surface)
@ -43,8 +43,11 @@ std::unique_ptr<Context> ContextEGLGBM::Create(const WindowInfo& wi, const Versi
size_t num_versions_to_try) size_t num_versions_to_try)
{ {
std::unique_ptr<ContextEGLGBM> context = std::make_unique<ContextEGLGBM>(wi); std::unique_ptr<ContextEGLGBM> context = std::make_unique<ContextEGLGBM>(wi);
if (!context->CreateGBMDevice() || !context->Initialize(versions_to_try, num_versions_to_try)) if (!context->CreateDisplay(wi) || !context->CreateGBMDevice() ||
!context->Initialize(versions_to_try, num_versions_to_try))
{
return nullptr; return nullptr;
}
return context; return context;
} }
@ -68,7 +71,7 @@ void ContextEGLGBM::ResizeSurface(u32 new_surface_width, u32 new_surface_height)
bool ContextEGLGBM::CreateGBMDevice() bool ContextEGLGBM::CreateGBMDevice()
{ {
Assert(!m_gbm_device); Assert(!m_gbm_device);
m_gbm_device = gbm_create_device(GetDisplay()->GetCardFD()); m_gbm_device = gbm_create_device(m_drm_display.GetCardFD());
if (!m_gbm_device) if (!m_gbm_device)
{ {
Log_ErrorPrintf("gbm_create_device() failed: %d", errno); Log_ErrorPrintf("gbm_create_device() failed: %d", errno);
@ -78,6 +81,11 @@ bool ContextEGLGBM::CreateGBMDevice()
return true; return true;
} }
bool ContextEGLGBM::CreateDisplay(const WindowInfo& wi)
{
return m_drm_display.Initialize();
}
bool ContextEGLGBM::SetDisplay() bool ContextEGLGBM::SetDisplay()
{ {
if (!eglGetPlatformDisplayEXT) if (!eglGetPlatformDisplayEXT)
@ -102,7 +110,7 @@ EGLNativeWindowType ContextEGLGBM::GetNativeWindow(EGLConfig config)
eglGetConfigAttrib(m_display, config, EGL_NATIVE_VISUAL_ID, &visual_id); eglGetConfigAttrib(m_display, config, EGL_NATIVE_VISUAL_ID, &visual_id);
Assert(!m_fb_surface); Assert(!m_fb_surface);
m_fb_surface = gbm_surface_create(m_gbm_device, GetDisplay()->GetWidth(), GetDisplay()->GetHeight(), m_fb_surface = gbm_surface_create(m_gbm_device, m_drm_display.GetWidth(), m_drm_display.GetHeight(),
static_cast<u32>(visual_id), GBM_BO_USE_RENDERING | GBM_BO_USE_SCANOUT); static_cast<u32>(visual_id), GBM_BO_USE_RENDERING | GBM_BO_USE_SCANOUT);
if (!m_fb_surface) if (!m_fb_surface)
{ {
@ -138,7 +146,7 @@ ContextEGLGBM::Buffer* ContextEGLGBM::LockFrontBuffer()
const u32 format = gbm_bo_get_format(bo); const u32 format = gbm_bo_get_format(bo);
const u32 handle = gbm_bo_get_handle(bo).u32; const u32 handle = gbm_bo_get_handle(bo).u32;
std::optional<u32> fb_id = GetDisplay()->AddBuffer(width, height, format, handle, stride, 0); std::optional<u32> fb_id = m_drm_display.AddBuffer(width, height, format, handle, stride, 0);
if (!fb_id.has_value()) if (!fb_id.has_value())
return nullptr; return nullptr;
@ -158,7 +166,7 @@ void ContextEGLGBM::ReleaseBuffer(Buffer* buffer)
void ContextEGLGBM::PresentBuffer(Buffer* buffer, bool wait_for_vsync) void ContextEGLGBM::PresentBuffer(Buffer* buffer, bool wait_for_vsync)
{ {
GetDisplay()->PresentBuffer(buffer->fb_id, wait_for_vsync); m_drm_display.PresentBuffer(buffer->fb_id, wait_for_vsync);
} }
bool ContextEGLGBM::SwapBuffers() bool ContextEGLGBM::SwapBuffers()

View file

@ -42,7 +42,7 @@ private:
u32 fb_id; u32 fb_id;
}; };
DRMDisplay* GetDisplay() { return static_cast<DRMDisplay*>(m_wi.display_connection); } bool CreateDisplay(const WindowInfo& wi);
bool CreateGBMDevice(); bool CreateGBMDevice();
Buffer* LockFrontBuffer(); Buffer* LockFrontBuffer();
@ -53,10 +53,10 @@ private:
void StopPresentThread(); void StopPresentThread();
void PresentThread(); void PresentThread();
bool m_vsync = true; DRMDisplay m_drm_display;
struct gbm_device* m_gbm_device = nullptr; struct gbm_device* m_gbm_device = nullptr;
struct gbm_surface* m_fb_surface = nullptr; struct gbm_surface* m_fb_surface = nullptr;
bool m_vsync = true;
#ifdef CONTEXT_EGL_GBM_USE_PRESENT_THREAD #ifdef CONTEXT_EGL_GBM_USE_PRESENT_THREAD
std::thread m_present_thread; std::thread m_present_thread;

View file

@ -205,10 +205,9 @@ bool Context::SelectInstanceExtensions(ExtensionList* extension_list, const Wind
if (wi && wi->type == WindowInfo::Type::MacOS && !SupportsExtension(VK_EXT_METAL_SURFACE_EXTENSION_NAME, true)) if (wi && wi->type == WindowInfo::Type::MacOS && !SupportsExtension(VK_EXT_METAL_SURFACE_EXTENSION_NAME, true))
return false; return false;
#endif #endif
#ifndef _WIN32
if (wi && wi->type == WindowInfo::Type::DRM && !SupportsExtension(VK_KHR_DISPLAY_EXTENSION_NAME, true)) if (wi && wi->type == WindowInfo::Type::Display && !SupportsExtension(VK_KHR_DISPLAY_EXTENSION_NAME, true))
return false; return false;
#endif
// VK_EXT_debug_report // VK_EXT_debug_report
if (enable_debug_report && !SupportsExtension(VK_EXT_DEBUG_REPORT_EXTENSION_NAME, false)) if (enable_debug_report && !SupportsExtension(VK_EXT_DEBUG_REPORT_EXTENSION_NAME, false))

View file

@ -87,8 +87,6 @@ SwapChain::~SwapChain()
DestroySurface(); DestroySurface();
} }
#ifndef _WIN32
static VkSurfaceKHR CreateDisplaySurface(VkInstance instance, VkPhysicalDevice physical_device, const WindowInfo& wi) static VkSurfaceKHR CreateDisplaySurface(VkInstance instance, VkPhysicalDevice physical_device, const WindowInfo& wi)
{ {
Log_InfoPrintf("Trying to create a VK_KHR_display surface of %ux%u", wi.surface_width, wi.surface_height); Log_InfoPrintf("Trying to create a VK_KHR_display surface of %ux%u", wi.surface_width, wi.surface_height);
@ -135,8 +133,8 @@ static VkSurfaceKHR CreateDisplaySurface(VkInstance instance, VkPhysicalDevice p
{ {
Log_DevPrintf(" Mode %ux%u @ %u", mode.parameters.visibleRegion.width, mode.parameters.visibleRegion.height, Log_DevPrintf(" Mode %ux%u @ %u", mode.parameters.visibleRegion.width, mode.parameters.visibleRegion.height,
mode.parameters.refreshRate); mode.parameters.refreshRate);
if (!matched_mode && mode.parameters.visibleRegion.width == wi.surface_width && if (!matched_mode && (wi.surface_width == 0 && wi.surface_height == 0) ||
mode.parameters.visibleRegion.height) (mode.parameters.visibleRegion.width == wi.surface_width && mode.parameters.visibleRegion.height))
{ {
matched_mode = &mode; matched_mode = &mode;
} }
@ -218,9 +216,9 @@ static VkSurfaceKHR CreateDisplaySurface(VkInstance instance, VkPhysicalDevice p
return surface; return surface;
} }
}
#endif return VK_NULL_HANDLE;
}
VkSurfaceKHR SwapChain::CreateVulkanSurface(VkInstance instance, VkPhysicalDevice physical_device, WindowInfo& wi) VkSurfaceKHR SwapChain::CreateVulkanSurface(VkInstance instance, VkPhysicalDevice physical_device, WindowInfo& wi)
{ {
@ -348,10 +346,8 @@ VkSurfaceKHR SwapChain::CreateVulkanSurface(VkInstance instance, VkPhysicalDevic
} }
#endif #endif
#ifndef _WIN32 if (wi.type == WindowInfo::Type::Display)
if (wi.type == WindowInfo::Type::DRM)
return CreateDisplaySurface(instance, physical_device, wi); return CreateDisplaySurface(instance, physical_device, wi);
#endif
return VK_NULL_HANDLE; return VK_NULL_HANDLE;
} }

View file

@ -12,7 +12,7 @@ struct WindowInfo
Wayland, Wayland,
MacOS, MacOS,
Android, Android,
DRM, Display,
}; };
enum class SurfaceFormat enum class SurfaceFormat

View file

@ -60,30 +60,22 @@ void DRMHostInterface::FixIncompatibleSettings(bool display_osd_messages)
bool DRMHostInterface::CreatePlatformWindow(bool fullscreen) bool DRMHostInterface::CreatePlatformWindow(bool fullscreen)
{ {
Assert(!m_drm_display);
m_drm_display = std::make_unique<DRMDisplay>();
if (!m_drm_display->Initialize())
{
m_drm_display.reset();
return false;
}
SetImGuiKeyMap(); SetImGuiKeyMap();
return true; return true;
} }
void DRMHostInterface::DestroyPlatformWindow() void DRMHostInterface::DestroyPlatformWindow()
{ {
m_drm_display.reset(); // nothing to destroy, it's all in the context
} }
std::optional<WindowInfo> DRMHostInterface::GetPlatformWindowInfo() std::optional<WindowInfo> DRMHostInterface::GetPlatformWindowInfo()
{ {
// TODO: Set fullscreen resolution.
WindowInfo wi; WindowInfo wi;
wi.type = WindowInfo::Type::DRM; wi.type = WindowInfo::Type::Display;
wi.display_connection = m_drm_display.get(); wi.surface_width = 0;
wi.surface_width = m_drm_display->GetWidth(); wi.surface_height = 0;
wi.surface_height = m_drm_display->GetHeight();
wi.surface_format = WindowInfo::SurfaceFormat::Auto; wi.surface_format = WindowInfo::SurfaceFormat::Auto;
return wi; return wi;
} }

View file

@ -1,5 +1,4 @@
#pragma once #pragma once
#include "common/drm_display.h"
#include "nogui_host_interface.h" #include "nogui_host_interface.h"
#include <memory> #include <memory>
#include <vector> #include <vector>
@ -38,8 +37,6 @@ private:
void PollEvDevKeyboards(); void PollEvDevKeyboards();
void SetImGuiKeyMap(); void SetImGuiKeyMap();
std::unique_ptr<DRMDisplay> m_drm_display;
struct EvDevKeyboard struct EvDevKeyboard
{ {
struct libevdev* obj; struct libevdev* obj;