NoGUI: Move DRM display to GL context
We don't use it for Vulkan.
This commit is contained in:
parent
8f9bbb0bba
commit
3e9fdf22bf
|
@ -109,7 +109,7 @@ std::unique_ptr<GL::Context> Context::Create(const WindowInfo& wi, const Version
|
|||
#endif
|
||||
|
||||
#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);
|
||||
#endif
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ ContextEGLGBM::~ContextEGLGBM()
|
|||
while (m_num_buffers > 0)
|
||||
{
|
||||
Buffer& buffer = m_buffers[--m_num_buffers];
|
||||
GetDisplay()->RemoveBuffer(buffer.fb_id);
|
||||
m_drm_display.RemoveBuffer(buffer.fb_id);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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 context;
|
||||
}
|
||||
|
@ -68,7 +71,7 @@ void ContextEGLGBM::ResizeSurface(u32 new_surface_width, u32 new_surface_height)
|
|||
bool ContextEGLGBM::CreateGBMDevice()
|
||||
{
|
||||
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)
|
||||
{
|
||||
Log_ErrorPrintf("gbm_create_device() failed: %d", errno);
|
||||
|
@ -78,6 +81,11 @@ bool ContextEGLGBM::CreateGBMDevice()
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ContextEGLGBM::CreateDisplay(const WindowInfo& wi)
|
||||
{
|
||||
return m_drm_display.Initialize();
|
||||
}
|
||||
|
||||
bool ContextEGLGBM::SetDisplay()
|
||||
{
|
||||
if (!eglGetPlatformDisplayEXT)
|
||||
|
@ -102,7 +110,7 @@ EGLNativeWindowType ContextEGLGBM::GetNativeWindow(EGLConfig config)
|
|||
eglGetConfigAttrib(m_display, config, EGL_NATIVE_VISUAL_ID, &visual_id);
|
||||
|
||||
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);
|
||||
if (!m_fb_surface)
|
||||
{
|
||||
|
@ -138,7 +146,7 @@ ContextEGLGBM::Buffer* ContextEGLGBM::LockFrontBuffer()
|
|||
const u32 format = gbm_bo_get_format(bo);
|
||||
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())
|
||||
return nullptr;
|
||||
|
||||
|
@ -158,7 +166,7 @@ void ContextEGLGBM::ReleaseBuffer(Buffer* buffer)
|
|||
|
||||
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()
|
||||
|
|
|
@ -42,7 +42,7 @@ private:
|
|||
u32 fb_id;
|
||||
};
|
||||
|
||||
DRMDisplay* GetDisplay() { return static_cast<DRMDisplay*>(m_wi.display_connection); }
|
||||
bool CreateDisplay(const WindowInfo& wi);
|
||||
|
||||
bool CreateGBMDevice();
|
||||
Buffer* LockFrontBuffer();
|
||||
|
@ -53,10 +53,10 @@ private:
|
|||
void StopPresentThread();
|
||||
void PresentThread();
|
||||
|
||||
bool m_vsync = true;
|
||||
|
||||
DRMDisplay m_drm_display;
|
||||
struct gbm_device* m_gbm_device = nullptr;
|
||||
struct gbm_surface* m_fb_surface = nullptr;
|
||||
bool m_vsync = true;
|
||||
|
||||
#ifdef CONTEXT_EGL_GBM_USE_PRESENT_THREAD
|
||||
std::thread m_present_thread;
|
||||
|
|
|
@ -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))
|
||||
return false;
|
||||
#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;
|
||||
#endif
|
||||
|
||||
// VK_EXT_debug_report
|
||||
if (enable_debug_report && !SupportsExtension(VK_EXT_DEBUG_REPORT_EXTENSION_NAME, false))
|
||||
|
|
|
@ -87,8 +87,6 @@ SwapChain::~SwapChain()
|
|||
DestroySurface();
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
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);
|
||||
|
@ -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,
|
||||
mode.parameters.refreshRate);
|
||||
if (!matched_mode && mode.parameters.visibleRegion.width == wi.surface_width &&
|
||||
mode.parameters.visibleRegion.height)
|
||||
if (!matched_mode && (wi.surface_width == 0 && wi.surface_height == 0) ||
|
||||
(mode.parameters.visibleRegion.width == wi.surface_width && mode.parameters.visibleRegion.height))
|
||||
{
|
||||
matched_mode = &mode;
|
||||
}
|
||||
|
@ -218,9 +216,9 @@ static VkSurfaceKHR CreateDisplaySurface(VkInstance instance, VkPhysicalDevice p
|
|||
|
||||
return surface;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
return VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
VkSurfaceKHR SwapChain::CreateVulkanSurface(VkInstance instance, VkPhysicalDevice physical_device, WindowInfo& wi)
|
||||
{
|
||||
|
@ -348,10 +346,8 @@ VkSurfaceKHR SwapChain::CreateVulkanSurface(VkInstance instance, VkPhysicalDevic
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
if (wi.type == WindowInfo::Type::DRM)
|
||||
if (wi.type == WindowInfo::Type::Display)
|
||||
return CreateDisplaySurface(instance, physical_device, wi);
|
||||
#endif
|
||||
|
||||
return VK_NULL_HANDLE;
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ struct WindowInfo
|
|||
Wayland,
|
||||
MacOS,
|
||||
Android,
|
||||
DRM,
|
||||
Display,
|
||||
};
|
||||
|
||||
enum class SurfaceFormat
|
||||
|
|
|
@ -60,30 +60,22 @@ void DRMHostInterface::FixIncompatibleSettings(bool display_osd_messages)
|
|||
|
||||
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();
|
||||
return true;
|
||||
}
|
||||
|
||||
void DRMHostInterface::DestroyPlatformWindow()
|
||||
{
|
||||
m_drm_display.reset();
|
||||
// nothing to destroy, it's all in the context
|
||||
}
|
||||
|
||||
std::optional<WindowInfo> DRMHostInterface::GetPlatformWindowInfo()
|
||||
{
|
||||
// TODO: Set fullscreen resolution.
|
||||
WindowInfo wi;
|
||||
wi.type = WindowInfo::Type::DRM;
|
||||
wi.display_connection = m_drm_display.get();
|
||||
wi.surface_width = m_drm_display->GetWidth();
|
||||
wi.surface_height = m_drm_display->GetHeight();
|
||||
wi.type = WindowInfo::Type::Display;
|
||||
wi.surface_width = 0;
|
||||
wi.surface_height = 0;
|
||||
wi.surface_format = WindowInfo::SurfaceFormat::Auto;
|
||||
return wi;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#pragma once
|
||||
#include "common/drm_display.h"
|
||||
#include "nogui_host_interface.h"
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
@ -38,8 +37,6 @@ private:
|
|||
void PollEvDevKeyboards();
|
||||
void SetImGuiKeyMap();
|
||||
|
||||
std::unique_ptr<DRMDisplay> m_drm_display;
|
||||
|
||||
struct EvDevKeyboard
|
||||
{
|
||||
struct libevdev* obj;
|
||||
|
|
Loading…
Reference in New Issue