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