diff options
Diffstat (limited to 'src/platformsupport')
4 files changed, 44 insertions, 43 deletions
diff --git a/src/platformsupport/eglconvenience/CMakeLists.txt b/src/platformsupport/eglconvenience/CMakeLists.txt index 1858dc7e90..4b709161fd 100644 --- a/src/platformsupport/eglconvenience/CMakeLists.txt +++ b/src/platformsupport/eglconvenience/CMakeLists.txt @@ -48,6 +48,6 @@ qt_extend_target(EglSupport CONDITION NOT QT_FEATURE_egl_x11 ) qt_extend_target(EglSupport CONDITION QT_FEATURE_dlopen - PUBLIC_LIBRARIES + LIBRARIES ${CMAKE_DL_LIBS} ) diff --git a/src/platformsupport/eglconvenience/eglconvenience.pro b/src/platformsupport/eglconvenience/eglconvenience.pro index df21f14697..e9ee52b53b 100644 --- a/src/platformsupport/eglconvenience/eglconvenience.pro +++ b/src/platformsupport/eglconvenience/eglconvenience.pro @@ -38,6 +38,6 @@ qtConfig(egl_x11) { } CONFIG += egl -qtConfig(dlopen): QMAKE_USE += libdl +qtConfig(dlopen): QMAKE_USE_PRIVATE += libdl load(qt_module) diff --git a/src/platformsupport/eglconvenience/qeglplatformcontext.cpp b/src/platformsupport/eglconvenience/qeglplatformcontext.cpp index d38a850065..c82473ebbb 100644 --- a/src/platformsupport/eglconvenience/qeglplatformcontext.cpp +++ b/src/platformsupport/eglconvenience/qeglplatformcontext.cpp @@ -42,7 +42,6 @@ #include "qeglpbuffer_p.h" #include <qpa/qplatformwindow.h> #include <QOpenGLContext> -#include <QtPlatformHeaders/QEGLNativeContext> #include <QDebug> #if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED) @@ -115,25 +114,13 @@ QT_BEGIN_NAMESPACE #endif QEGLPlatformContext::QEGLPlatformContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share, EGLDisplay display, - EGLConfig *config, const QVariant &nativeHandle, Flags flags) + EGLConfig *config, Flags flags) : m_eglDisplay(display) - , m_swapInterval(-1) - , m_swapIntervalEnvChecked(false) - , m_swapIntervalFromEnv(-1) , m_flags(flags) + , m_ownsContext(true) { - if (nativeHandle.isNull()) { - m_eglConfig = config ? *config : q_configFromGLFormat(display, format); - m_ownsContext = true; - init(format, share); - } else { - m_ownsContext = false; - adopt(nativeHandle, share); - } -} + m_eglConfig = config ? *config : q_configFromGLFormat(display, format); -void QEGLPlatformContext::init(const QSurfaceFormat &format, QPlatformOpenGLContext *share) -{ m_format = q_glFormatFromConfig(m_eglDisplay, m_eglConfig, format); // m_format now has the renderableType() resolved (it cannot be Default anymore) // but does not yet contain version, profile, options. @@ -212,24 +199,11 @@ void QEGLPlatformContext::init(const QSurfaceFormat &format, QPlatformOpenGLCont // Cannot just call updateFormatFromGL() since it relies on virtuals. Defer it to initialize(). } -void QEGLPlatformContext::adopt(const QVariant &nativeHandle, QPlatformOpenGLContext *share) +void QEGLPlatformContext::adopt(EGLContext context, EGLDisplay display, QPlatformOpenGLContext *share) { - if (!nativeHandle.canConvert<QEGLNativeContext>()) { - qWarning("QEGLPlatformContext: Requires a QEGLNativeContext"); - return; - } - QEGLNativeContext handle = qvariant_cast<QEGLNativeContext>(nativeHandle); - EGLContext context = handle.context(); - if (!context) { - qWarning("QEGLPlatformContext: No EGLContext given"); - return; - } + Q_ASSERT(!m_ownsContext); - // A context belonging to a given EGLDisplay cannot be used with another one. - if (handle.display() != m_eglDisplay) { - qWarning("QEGLPlatformContext: Cannot adopt context from different display"); - return; - } + m_eglDisplay = display; // Figure out the EGLConfig. EGLint value = 0; diff --git a/src/platformsupport/eglconvenience/qeglplatformcontext_p.h b/src/platformsupport/eglconvenience/qeglplatformcontext_p.h index f0388cd29c..610588568e 100644 --- a/src/platformsupport/eglconvenience/qeglplatformcontext_p.h +++ b/src/platformsupport/eglconvenience/qeglplatformcontext_p.h @@ -56,10 +56,12 @@ #include <qpa/qplatformopenglcontext.h> #include <QtCore/QVariant> #include <QtEglSupport/private/qt_egl_p.h> +#include <QtGui/private/qopenglcontext_p.h> QT_BEGIN_NAMESPACE -class QEGLPlatformContext : public QPlatformOpenGLContext +class QEGLPlatformContext : public QPlatformOpenGLContext, + public QPlatformInterface::QEGLContext { public: enum Flag { @@ -68,8 +70,31 @@ public: Q_DECLARE_FLAGS(Flags, Flag) QEGLPlatformContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share, EGLDisplay display, - EGLConfig *config = nullptr, const QVariant &nativeHandle = QVariant(), - Flags flags = { }); + EGLConfig *config = nullptr, Flags flags = { }); + + template <typename T> + static QOpenGLContext *createFrom(EGLContext context, EGLDisplay contextDisplay, + EGLDisplay platformDisplay, QOpenGLContext *shareContext) + { + if (!context) + return nullptr; + + // A context belonging to a given EGLDisplay cannot be used with another one + if (contextDisplay != platformDisplay) { + qWarning("QEGLPlatformContext: Cannot adopt context from different display"); + return nullptr; + } + + QPlatformOpenGLContext *shareHandle = shareContext ? shareContext->handle() : nullptr; + + auto *resultingContext = new QOpenGLContext; + auto *contextPrivate = QOpenGLContextPrivate::get(resultingContext); + auto *platformContext = new T; + platformContext->adopt(context, contextDisplay, shareHandle); + contextPrivate->adopt(platformContext); + return resultingContext; + } + ~QEGLPlatformContext(); void initialize() override; @@ -82,19 +107,21 @@ public: bool isSharing() const override { return m_shareContext != EGL_NO_CONTEXT; } bool isValid() const override { return m_eglContext != EGL_NO_CONTEXT; } + EGLContext nativeContext() const override { return eglContext(); } + EGLContext eglContext() const; EGLDisplay eglDisplay() const; EGLConfig eglConfig() const; protected: + QEGLPlatformContext() {} // For adoption virtual EGLSurface eglSurfaceForPlatformSurface(QPlatformSurface *surface) = 0; virtual EGLSurface createTemporaryOffscreenSurface(); virtual void destroyTemporaryOffscreenSurface(EGLSurface surface); virtual void runGLChecks(); private: - void init(const QSurfaceFormat &format, QPlatformOpenGLContext *share); - void adopt(const QVariant &nativeHandle, QPlatformOpenGLContext *share); + void adopt(EGLContext context, EGLDisplay display, QPlatformOpenGLContext *shareContext); void updateFormatFromGL(); EGLContext m_eglContext; @@ -103,11 +130,11 @@ private: EGLConfig m_eglConfig; QSurfaceFormat m_format; EGLenum m_api; - int m_swapInterval; - bool m_swapIntervalEnvChecked; - int m_swapIntervalFromEnv; + int m_swapInterval = -1; + bool m_swapIntervalEnvChecked = false; + int m_swapIntervalFromEnv = -1; Flags m_flags; - bool m_ownsContext; + bool m_ownsContext = false; QVector<EGLint> m_contextAttrs; }; |