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