Files
dolphin/Source/Core/Common/GL/GLInterface/EGLX11.cpp
T
2026-07-31 10:34:00 +02:00

67 lines
2.1 KiB
C++

// Copyright 2014 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "Common/GL/GLInterface/EGLX11.h"
#include <cstdlib>
#include "Common/StringUtil.h"
GLContextEGLX11::GLContextEGLX11()
{
// HACK: If EGL_PLATFORM is set to "wayland", Dolphin will still use GLContextEGLX11 due to our
// lack of proper Wayland support, and crash.
// Some distros have started aggressively setting that environment variable, bypassing the usual
// runtime detection. Thus, clear that environment variable if it forces wayland.
const char* current_egl_platform = getenv("EGL_PLATFORM");
const bool replace_egl_platform =
current_egl_platform != nullptr &&
Common::CaseInsensitiveContains(current_egl_platform, "wayland");
setenv("EGL_PLATFORM", "", replace_egl_platform);
}
GLContextEGLX11::~GLContextEGLX11()
{
// The context must be destroyed before the window.
DestroyWindowSurface();
DestroyContext();
m_render_window.reset();
}
void GLContextEGLX11::Update()
{
m_render_window->UpdateDimensions();
m_backbuffer_width = m_render_window->GetWidth();
m_backbuffer_height = m_render_window->GetHeight();
}
EGLDisplay GLContextEGLX11::OpenEGLDisplay()
{
return eglGetDisplay(static_cast<Display*>(m_wsi.display_connection));
}
EGLNativeWindowType GLContextEGLX11::GetEGLNativeWindow(EGLConfig config)
{
EGLint vid;
eglGetConfigAttrib(m_egl_display, config, EGL_NATIVE_VISUAL_ID, &vid);
XVisualInfo visTemplate = {};
visTemplate.visualid = vid;
int nVisuals;
XVisualInfo* vi = XGetVisualInfo(static_cast<Display*>(m_wsi.display_connection), VisualIDMask,
&visTemplate, &nVisuals);
if (m_render_window)
m_render_window.reset();
m_render_window = GLX11Window::Create(static_cast<Display*>(m_wsi.display_connection),
reinterpret_cast<Window>(m_wsi.render_surface), vi);
m_backbuffer_width = m_render_window->GetWidth();
m_backbuffer_height = m_render_window->GetHeight();
XFree(vi);
return reinterpret_cast<EGLNativeWindowType>(m_render_window->GetWindow());
}