3#if defined(QGC_HAS_GST_DMABUF_GPU_PATH) || defined(QGC_HAS_GST_AHARDWAREBUFFER_GPU_PATH)
5#include <QtCore/QByteArray>
7#include <QtCore/QMutex>
8#include <QtCore/QMutexLocker>
9#include <QtGui/QOpenGLContext>
10#include <QtGui/qopenglcontext_platform.h>
14namespace GstEglHelpers {
16EGLDisplay resolveEglDisplay(QOpenGLContext* qtCtx)
noexcept
19 if (
auto* egl = qtCtx->nativeInterface<QNativeInterface::QEGLContext>()) {
20 const EGLDisplay d = egl->display();
21 if (d != EGL_NO_DISPLAY)
25 return eglGetCurrentDisplay();
32QHash<std::pair<EGLDisplay, QByteArray>,
bool> s_extCache;
36bool displaySupportsExtension(EGLDisplay display,
const char* extension)
38 if (display == EGL_NO_DISPLAY || !extension)
41 const QByteArray extKey = QByteArray::fromRawData(extension,
static_cast<qsizetype
>(std::strlen(extension)));
43 QMutexLocker lock(&s_extMutex);
44 auto it = s_extCache.constFind(std::make_pair(display, extKey));
45 if (it != s_extCache.constEnd())
48 const char* exts = eglQueryString(display, EGL_EXTENSIONS);
51 bool supported =
false;
52 if (exts && extension) {
53 const std::size_t extLen = std::strlen(extension);
54 for (
const char* p = exts; (p = std::strstr(p, extension)) !=
nullptr; p += extLen) {
55 const char before = p == exts ?
' ' : *(p - 1);
56 const char after = *(p + extLen);
57 if ((before ==
' ' || before ==
'\0') && (after ==
' ' || after ==
'\0')) {
63 s_extCache.insert(std::make_pair(display, QByteArray(extension)), supported);
67void resetExtensionCache()
69 QMutexLocker lock(&s_extMutex);