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 #else
60  (void)m_context;
61 #endif
62  return false;
63 }
64 
65 bool MythEGL::HasEGLExtension(QString Extension)
66 {
67 #ifdef USING_EGL
68  OpenGLLocker locker(m_context);
69  if (m_eglDisplay)
70  {
71  QByteArray extensions = QByteArray(eglQueryString(m_eglDisplay, EGL_EXTENSIONS));
72  return extensions.contains(Extension.data()->toLatin1());
73  }
74 #else
75  (void)Extension;
76 #endif
77  return false;
78 }
79 
81 {
82  return m_eglDisplay;
83 }
84 
85 QString MythEGL::GetEGLVendor(void)
86 {
87 #ifdef USING_EGL
88  auto CheckDisplay = [](EGLDisplay EglDisplay)
89  {
90  if (EglDisplay == EGL_NO_DISPLAY)
91  return QString();
92  int major = 1;
93  int minor = 4;
94  if (!eglInitialize(EglDisplay, &major, &minor))
95  return QString();
96  QString vendor = eglQueryString(EglDisplay, EGL_VENDOR);
97  QString apis = eglQueryString(EglDisplay, EGL_CLIENT_APIS);
98  QString version = eglQueryString(EglDisplay, EGL_VERSION);
99  eglTerminate(EglDisplay);
100  if (!apis.contains("opengl", Qt::CaseInsensitive) || (major < 1 || minor < 2))
101  return QString();
102  return QString("%1, %2").arg(vendor, version);
103  };
104 
105  QString extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
106  if (extensions.contains("EGL_EXT_platform_base"))
107  {
108  QString vendor;
109  auto getdisp =
110  reinterpret_cast<MYTH_EGLGETPLATFORMDISPLAY>(eglGetProcAddress("eglGetPlatformDisplay"));
111  if (getdisp && extensions.contains("platform_x11"))
112  {
113  vendor = CheckDisplay(getdisp(EGL_PLATFORM_X11_EXT, EGL_DEFAULT_DISPLAY, nullptr));
114  if (!vendor.isEmpty())
115  return vendor;
116  }
117  if (getdisp && extensions.contains("platform_wayland"))
118  {
119  vendor = CheckDisplay(getdisp(EGL_PLATFORM_WAYLAND_EXT, EGL_DEFAULT_DISPLAY, nullptr));
120  if (!vendor.isEmpty())
121  return vendor;
122  }
123  if (getdisp && extensions.contains("platform_device"))
124  {
125  vendor = CheckDisplay(getdisp(EGL_PLATFORM_DEVICE_EXT, EGL_DEFAULT_DISPLAY, nullptr));
126  if (!vendor.isEmpty())
127  return vendor;
128  }
129  }
130 
131  return CheckDisplay(eglGetDisplay(EGL_DEFAULT_DISPLAY));
132 #else
133  return QString();
134 #endif
135 }
136 
138 {
139 #ifdef USING_EGL
140  return static_cast<qint32>(eglGetError());
141 #else
142  return 0; // EGL_FALSE
143 #endif
144 }
145 
146 void MythEGL::eglImageTargetTexture2DOES(GLenum Target, void *Image)
147 {
150 }
151 
152 void* MythEGL::eglCreateImageKHR(void *Disp, void *Context, unsigned int Target,
153  void *Buffer, const int32_t *Attributes)
154 {
156  return m_eglCreateImageKHR(Disp, Context, Target, Buffer, Attributes);
157  return nullptr;
158 }
159 
160 void MythEGL::eglDestroyImageKHR(void *Disp, void *Image)
161 {
164 }
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:80
MythEGL::m_eglDestroyImageKHR
MYTH_EGLDESTROYIMAGE m_eglDestroyImageKHR
Definition: mythegl.h:41
MythEGL::eglImageTargetTexture2DOES
void eglImageTargetTexture2DOES(GLenum Target, void *Image)
Definition: mythegl.cpp:146
Context
QHash< QString, Action * > Context
Definition: action.h:77
MYTH_EGLGETPLATFORMDISPLAY
void *(*)(GLenum, void *, const intptr_t *) MYTH_EGLGETPLATFORMDISPLAY
Definition: mythegl.h:13
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
MYTH_EGLCREATEIMAGE
void *(*)(void *, void *, unsigned int, void *, const int32_t *) MYTH_EGLCREATEIMAGE
Definition: mythegl.h:11
Image
Definition: image.h:31
MythEGL::eglDestroyImageKHR
void eglDestroyImageKHR(void *Disp, void *Image)
Definition: mythegl.cpp:160
MYTH_EGLDESTROYIMAGE
void(*)(void *, void *) MYTH_EGLDESTROYIMAGE
Definition: mythegl.h:12
mythrenderopengl.h
MythEGL::GetEGLVendor
static QString GetEGLVendor(void)
Definition: mythegl.cpp:85
minor
#define minor(X)
Definition: compat.h:138
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:137
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:98
Buffer
Definition: MythExternControl.h:37
MythEGL::eglCreateImageKHR
void * eglCreateImageKHR(void *Disp, void *Context, unsigned int Target, void *Buffer, const int32_t *Attributes)
Definition: mythegl.cpp:152
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:81
MythEGL::HasEGLExtension
bool HasEGLExtension(QString Extension)
Definition: mythegl.cpp:65
LOC
#define LOC
Definition: mythegl.cpp:5
OpenGLLocker
Definition: mythrenderopengl.h:256