3#if defined(QGC_HAS_GST_DMABUF_GPU_PATH) || defined(QGC_HAS_GST_AHARDWAREBUFFER_GPU_PATH)
7#include <rhi/qrhi_platform.h>
10#include <QtCore/QByteArray>
11#include <QtCore/QHash>
12#include <QtCore/QMutex>
13#include <QtCore/QMutexLocker>
14#include <QtGui/QOpenGLContext>
15#include <QtGui/qopenglcontext_platform.h>
17namespace GstEglHelpers {
22EGLDisplay resolveEglDisplay(QOpenGLContext* qtCtx)
25 if (
auto* egl = qtCtx->nativeInterface<QNativeInterface::QEGLContext>()) {
26 const EGLDisplay d = egl->display();
27 if (d != EGL_NO_DISPLAY)
31 return eglGetCurrentDisplay();
36QOpenGLContext* bindRhiContext(QRhi& rhi)
38 if (!rhi.makeThreadLocalNativeContextCurrent()) {
41 const auto* handles =
static_cast<const QRhiGles2NativeHandles*
>(rhi.nativeHandles());
42 return handles ? handles->context :
nullptr;
45EGLDisplay renderDisplay(QOpenGLContext* qtCtx, EGLDisplay fallback)
47 const EGLDisplay display = resolveEglDisplay(qtCtx);
48 return display != EGL_NO_DISPLAY ? display : fallback;
55QHash<std::pair<EGLDisplay, QByteArray>,
bool> s_extCache;
59bool displaySupportsExtension(EGLDisplay display,
const char* extension)
61 if (display == EGL_NO_DISPLAY || !extension)
64 const QByteArray extKey = QByteArray::fromRawData(extension,
static_cast<qsizetype
>(std::strlen(extension)));
66 QMutexLocker lock(&s_extMutex);
67 auto it = s_extCache.constFind(std::make_pair(display, extKey));
68 if (it != s_extCache.constEnd())
71 const char* exts = eglQueryString(display, EGL_EXTENSIONS);
74 bool supported =
false;
75 if (exts && extension) {
76 const std::size_t extLen = std::strlen(extension);
77 for (
const char* p = exts; (p = std::strstr(p, extension)) !=
nullptr; p += extLen) {
78 const char before = p == exts ?
' ' : *(p - 1);
79 const char after = *(p + extLen);
80 if ((before ==
' ' || before ==
'\0') && (after ==
' ' || after ==
'\0')) {
86 s_extCache.insert(std::make_pair(display, QByteArray(extension)), supported);
90void resetExtensionCache()
92 QMutexLocker lock(&s_extMutex);
96PFNGLEGLIMAGETARGETTEXTURE2DOESPROC imageTargetTexture2D() noexcept
98 static const auto fn =
99 reinterpret_cast<PFNGLEGLIMAGETARGETTEXTURE2DOESPROC
>(eglGetProcAddress(
"glEGLImageTargetTexture2DOES"));
103PFNEGLDESTROYIMAGEKHRPROC destroyImageKHR() noexcept
105 static const auto fn =
reinterpret_cast<PFNEGLDESTROYIMAGEKHRPROC
>(eglGetProcAddress(
"eglDestroyImageKHR"));