MythTV master
mythegl.cpp
Go to the documentation of this file.
1// MythTV
3#include "mythrenderopengl.h"
4#include "mythegl.h"
5
6#define LOC QString("EGL: ")
7
8#if CONFIG_EGL
9#include <EGL/egl.h>
10#include <EGL/eglext.h>
11#endif
12
13#ifndef EGL_EXT_platform_device
14#define EGL_PLATFORM_DEVICE_EXT 0x313F
15#endif
16
17#ifndef EGL_EXT_platform_wayland
18#define EGL_PLATFORM_WAYLAND_EXT 0x31D8
19#endif
20
21#ifndef EGL_EXT_platform_x11
22#define EGL_PLATFORM_X11_EXT 0x31D5
23#endif
24
25MythEGL::MythEGL([[maybe_unused]] MythRenderOpenGL* Context)
26#if CONFIG_EGL
27 : m_context(Context)
28#endif
29{
30}
31
33{
34 return InitEGL();
35}
36
37// NOLINTNEXTLINE(readability-convert-member-functions-to-static)
39{
40 // N.B. Strictly speaking this reports both whether EGL is in use and whether
41 // EGL_KHR_image functionality is present - which is currently the only thing
42 // we are interested in.
43#if CONFIG_EGL
45 return true;
46
47 if (!m_context)
48 return false;
49
50 OpenGLLocker locker(m_context);
51 m_eglDisplay = eglGetCurrentDisplay();
52 if (!m_eglDisplay)
53 return false;
54
55 m_eglImageTargetTexture2DOES = reinterpret_cast<MYTH_EGLIMAGETARGET>(eglGetProcAddress("glEGLImageTargetTexture2DOES"));
56 m_eglCreateImageKHR = reinterpret_cast<MYTH_EGLCREATEIMAGE>(eglGetProcAddress("eglCreateImageKHR"));
57 m_eglDestroyImageKHR = reinterpret_cast<MYTH_EGLDESTROYIMAGE>(eglGetProcAddress("eglDestroyImageKHR"));
58
60 return true;
61
62 LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to resolve EGL functions");
63#endif
64 return false;
65}
66
67// NOLINTNEXTLINE(readability-convert-member-functions-to-static)
68bool MythEGL::HasEGLExtension([[maybe_unused]] const QString& Extension)
69{
70#if CONFIG_EGL
71 OpenGLLocker locker(m_context);
72 if (m_eglDisplay)
73 {
74 QByteArray extensions = QByteArray(eglQueryString(m_eglDisplay, EGL_EXTENSIONS));
75 return extensions.contains(Extension.data()->toLatin1());
76 }
77#endif
78 return false;
79}
80
82{
83 return m_eglDisplay;
84}
85
87{
88#if CONFIG_EGL
89 auto CheckDisplay = [](EGLDisplay EglDisplay)
90 {
91 if (EglDisplay == EGL_NO_DISPLAY)
92 return QString();
93 int major = 1;
94 int minor = 4;
95 if (!eglInitialize(EglDisplay, &major, &minor))
96 return QString();
97 QString vendor = eglQueryString(EglDisplay, EGL_VENDOR);
98 QString apis = eglQueryString(EglDisplay, EGL_CLIENT_APIS);
99 QString version = eglQueryString(EglDisplay, EGL_VERSION);
100 eglTerminate(EglDisplay);
101 if (!apis.contains("opengl", Qt::CaseInsensitive) || (major < 1 || minor < 2))
102 return QString();
103 return QString("%1, %2").arg(vendor, version);
104 };
105
106 QString extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
107 if (extensions.contains("EGL_EXT_platform_base"))
108 {
109 QString vendor;
110 auto getdisp =
111 reinterpret_cast<MYTH_EGLGETPLATFORMDISPLAY>(eglGetProcAddress("eglGetPlatformDisplay"));
112 if (getdisp && extensions.contains("platform_x11"))
113 {
114 vendor = CheckDisplay(getdisp(EGL_PLATFORM_X11_EXT, EGL_DEFAULT_DISPLAY, nullptr));
115 if (!vendor.isEmpty())
116 return vendor;
117 }
118 if (getdisp && extensions.contains("platform_wayland"))
119 {
120 vendor = CheckDisplay(getdisp(EGL_PLATFORM_WAYLAND_EXT, EGL_DEFAULT_DISPLAY, nullptr));
121 if (!vendor.isEmpty())
122 return vendor;
123 }
124 if (getdisp && extensions.contains("platform_device"))
125 {
126 vendor = CheckDisplay(getdisp(EGL_PLATFORM_DEVICE_EXT, EGL_DEFAULT_DISPLAY, nullptr));
127 if (!vendor.isEmpty())
128 return vendor;
129 }
130 }
131
132 return CheckDisplay(eglGetDisplay(EGL_DEFAULT_DISPLAY));
133#else
134 return {};
135#endif
136}
137
139{
140#if CONFIG_EGL
141 return static_cast<qint32>(eglGetError());
142#else
143 return 0; // EGL_FALSE
144#endif
145}
146
147void MythEGL::eglImageTargetTexture2DOES(GLenum Target, void *Image)
148{
150 m_eglImageTargetTexture2DOES(Target, Image);
151}
152
153void* MythEGL::eglCreateImageKHR(void *Disp, void *Context, unsigned int Target,
154 void *Buffer, const int32_t *Attributes)
155{
157 return m_eglCreateImageKHR(Disp, Context, Target, Buffer, Attributes);
158 return nullptr;
159}
160
161void MythEGL::eglDestroyImageKHR(void *Disp, void *Image)
162{
164 m_eglDestroyImageKHR(Disp, Image);
165}
void * GetEGLDisplay(void)
Definition: mythegl.cpp:81
void eglImageTargetTexture2DOES(GLenum Target, void *Image)
Definition: mythegl.cpp:147
static QString GetEGLVendor(void)
Definition: mythegl.cpp:86
bool IsEGL(void)
Definition: mythegl.cpp:32
MythEGL(MythRenderOpenGL *Context)
Definition: mythegl.cpp:25
bool HasEGLExtension(const QString &Extension)
Definition: mythegl.cpp:68
bool InitEGL(void)
Definition: mythegl.cpp:38
void eglDestroyImageKHR(void *Disp, void *Image)
Definition: mythegl.cpp:161
MYTH_EGLDESTROYIMAGE m_eglDestroyImageKHR
Definition: mythegl.h:48
void * m_eglDisplay
Definition: mythegl.h:45
static qint32 GetEGLError(void)
Definition: mythegl.cpp:138
MYTH_EGLIMAGETARGET m_eglImageTargetTexture2DOES
Definition: mythegl.h:46
void * eglCreateImageKHR(void *Disp, void *Context, unsigned int Target, void *Buffer, const int32_t *Attributes)
Definition: mythegl.cpp:153
MYTH_EGLCREATEIMAGE m_eglCreateImageKHR
Definition: mythegl.h:47
#define minor(X)
Definition: compat.h:58
#define LOC
Definition: mythegl.cpp:6
#define EGL_PLATFORM_X11_EXT
Definition: mythegl.cpp:22
#define EGL_PLATFORM_WAYLAND_EXT
Definition: mythegl.cpp:18
#define EGL_PLATFORM_DEVICE_EXT
Definition: mythegl.cpp:14
void(*)(GLenum, void *) MYTH_EGLIMAGETARGET
Definition: mythegl.h:11
void(*)(void *, void *) MYTH_EGLDESTROYIMAGE
Definition: mythegl.h:13
void *(*)(void *, void *, unsigned int, void *, const int32_t *) MYTH_EGLCREATEIMAGE
Definition: mythegl.h:12
void *(*)(GLenum, void *, const intptr_t *) MYTH_EGLGETPLATFORMDISPLAY
Definition: mythegl.h:17
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
string version
Definition: giantbomb.py:185