summaryrefslogtreecommitdiff
path: root/Source/Core/Common/GL/GLInterface/EGLX11.cpp
blob: 1795ddd2ddf8075d092bb2309593d910356fcd70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// 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());
}