VideoBackends:OGL: Wayland support

This commit is contained in:
TellowKrinkle 2023-06-25 22:37:15 -05:00 committed by BeezBumba
parent fe74d85daf
commit 4fb515a86d
4 changed files with 92 additions and 0 deletions

View File

@ -308,6 +308,13 @@ if(ENABLE_EGL AND EGL_FOUND)
target_link_libraries(common PUBLIC ${EGL_LIBRARIES})
endif()
if(ENABLE_WAYLAND)
target_sources(common PRIVATE
GL/GLInterface/EGLWayland.cpp
GL/GLInterface/EGLWayland.h
)
endif()
if(WIN32)
target_sources(common PRIVATE
CompatPatches.cpp

View File

@ -19,6 +19,9 @@
#if HAVE_X11
#include "Common/GL/GLInterface/EGLX11.h"
#endif
#if HAVE_WAYLAND
#include "Common/GL/GLInterface/EGLWayland.h"
#endif
#if defined(ANDROID)
#include "Common/GL/GLInterface/EGLAndroid.h"
#endif
@ -103,6 +106,13 @@ std::unique_ptr<GLContext> GLContext::Create(const WindowSystemInfo& wsi, bool s
if (wsi.type == WindowSystemType::X11)
context = std::make_unique<GLContextEGLX11>();
#endif
#endif
#if HAVE_WAYLAND && HAVE_EGL
if (wsi.type == WindowSystemType::Wayland)
context = std::make_unique<GLContextEGLWayland>();
#endif
#if HAVE_EGL
if (wsi.type == WindowSystemType::Headless || wsi.type == WindowSystemType::FBDev)
context = std::make_unique<GLContextEGL>();
#endif

View File

@ -0,0 +1,47 @@
// Copyright 2023 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "Common/GL/GLInterface/EGLWayland.h"
#include "Common/MsgHandler.h"
GLContextEGLWayland::~GLContextEGLWayland()
{
if (m_window)
m_wl_egl_window_destroy(m_window);
}
void GLContextEGLWayland::Update(u32 width, u32 height)
{
GLContext::Update(width, height);
if (m_window)
m_wl_egl_window_resize(m_window, width, height, 0, 0);
}
EGLDisplay GLContextEGLWayland::OpenEGLDisplay()
{
return eglGetDisplay(static_cast<EGLNativeDisplayType>(m_wsi.display_connection));
}
EGLNativeWindowType GLContextEGLWayland::GetEGLNativeWindow(EGLConfig config)
{
if (!m_wayland_lib.IsOpen())
{
std::string name = Common::DynamicLibrary::GetVersionedFilename("wayland-egl", 1);
m_wayland_lib.Open(name.c_str());
if (!m_wayland_lib.IsOpen())
{
PanicAlertFmt("Failed to load {}", name);
return reinterpret_cast<EGLNativeWindowType>(m_window);
}
#define LOAD(x) m_wayland_lib.GetSymbol(#x, &m_##x)
LOAD(wl_egl_window_create);
LOAD(wl_egl_window_destroy);
LOAD(wl_egl_window_resize);
#undef LOAD
}
if (m_window)
m_wl_egl_window_destroy(m_window);
m_window = m_wl_egl_window_create(static_cast<wl_surface*>(m_wsi.render_surface),
m_wsi.render_surface_width, m_wsi.render_surface_height);
return reinterpret_cast<EGLNativeWindowType>(m_window);
}

View File

@ -0,0 +1,28 @@
// Copyright 2023 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <wayland-client-protocol.h>
#include "Common/DynamicLibrary.h"
#include "Common/GL/GLInterface/EGL.h"
struct wl_egl_window;
struct wl_surface;
class GLContextEGLWayland final : public GLContextEGL
{
public:
~GLContextEGLWayland() override;
void Update(u32 width, u32 height) override;
protected:
EGLDisplay OpenEGLDisplay() override;
EGLNativeWindowType GetEGLNativeWindow(EGLConfig config) override;
Common::DynamicLibrary m_wayland_lib;
wl_egl_window* (*m_wl_egl_window_create)(wl_surface* surface, int width, int height);
void (*m_wl_egl_window_destroy)(wl_egl_window* window);
void (*m_wl_egl_window_resize)(wl_egl_window* window, int width, int height, int dx, int dy);
wl_egl_window* m_window = nullptr;
};