diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2022-04-26 03:57:12 -0700 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2022-04-27 06:13:13 -0700 |
commit | 8161726619b71fb5bd8f77c7fd020d53d5ac7c9e (patch) | |
tree | 7dfd7bf41a5ba821dab0c304d244d49e8b4653fe /src/opengl | |
parent | 9861fd09cba4fe220f668585c78a7324d069ef94 (diff) |
Revive eglfs' raster window support
A number of consequences of the new rhi-based backingstore
composition were not handled. Most importantly, the fact
that RasterGLSurface is not a thing anymore in practice
causes challenges because we can no longer decide just
based on the surfaceType what a QWindow with OpenGLSurface
would be. (a plain GL window or a GL window with a backing
store?) Also, the backingstore needs to be able to initialize
its backing QRhi by itself, because with eglfs going through
OpenGL is the only way.
Amends 68a4c5da9a080101cccd8a3b2edb1c908da0ca8e
Fixes: QTBUG-102750
Change-Id: Ia1ca59d01e3012264a76b50e591612fdcc2a0bd6
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Diffstat (limited to 'src/opengl')
-rw-r--r-- | src/opengl/qopenglcompositor.cpp | 9 | ||||
-rw-r--r-- | src/opengl/qopenglcompositor_p.h | 3 | ||||
-rw-r--r-- | src/opengl/qopenglcompositorbackingstore.cpp | 64 | ||||
-rw-r--r-- | src/opengl/qopenglvertexarrayobject.cpp | 2 |
4 files changed, 41 insertions, 37 deletions
diff --git a/src/opengl/qopenglcompositor.cpp b/src/opengl/qopenglcompositor.cpp index a5fe4dda30..9f661510ad 100644 --- a/src/opengl/qopenglcompositor.cpp +++ b/src/opengl/qopenglcompositor.cpp @@ -94,14 +94,17 @@ QOpenGLCompositor::~QOpenGLCompositor() compositor = 0; } -void QOpenGLCompositor::setTarget(QOpenGLContext *context, QWindow *targetWindow, - const QRect &nativeTargetGeometry) +void QOpenGLCompositor::setTargetWindow(QWindow *targetWindow, const QRect &nativeTargetGeometry) { - m_context = context; m_targetWindow = targetWindow; m_nativeTargetGeometry = nativeTargetGeometry; } +void QOpenGLCompositor::setTargetContext(QOpenGLContext *context) +{ + m_context = context; +} + void QOpenGLCompositor::setRotation(int degrees) { m_rotation = degrees; diff --git a/src/opengl/qopenglcompositor_p.h b/src/opengl/qopenglcompositor_p.h index 27ede567a8..05b956c9c1 100644 --- a/src/opengl/qopenglcompositor_p.h +++ b/src/opengl/qopenglcompositor_p.h @@ -83,7 +83,8 @@ public: static QOpenGLCompositor *instance(); static void destroy(); - void setTarget(QOpenGLContext *context, QWindow *window, const QRect &nativeTargetGeometry); + void setTargetWindow(QWindow *window, const QRect &nativeTargetGeometry); + void setTargetContext(QOpenGLContext *context); void setRotation(int degrees); QOpenGLContext *context() const { return m_context; } QWindow *targetWindow() const { return m_targetWindow; } diff --git a/src/opengl/qopenglcompositorbackingstore.cpp b/src/opengl/qopenglcompositorbackingstore.cpp index ed4a0ffb3c..df3a9e2525 100644 --- a/src/opengl/qopenglcompositorbackingstore.cpp +++ b/src/opengl/qopenglcompositorbackingstore.cpp @@ -40,7 +40,6 @@ #include <QtGui/QOpenGLContext> #include <QtGui/QWindow> #include <QtGui/QPainter> -#include <QtGui/QOffscreenSurface> #include <qpa/qplatformbackingstore.h> #include <private/qwindow_p.h> #include <private/qrhi_p.h> @@ -90,31 +89,12 @@ QOpenGLCompositorBackingStore::QOpenGLCompositorBackingStore(QWindow *window) QOpenGLCompositorBackingStore::~QOpenGLCompositorBackingStore() { - if (m_bsTexture) { - QOpenGLContext *ctx = QOpenGLContext::currentContext(); - // With render-to-texture-widgets QWidget makes sure the TLW's shareContext() is - // made current before destroying backingstores. That is however not the case for - // windows with regular widgets only. - QScopedPointer<QOffscreenSurface> tempSurface; - if (!ctx) { - ctx = QOpenGLCompositor::instance()->context(); - if (ctx) { - tempSurface.reset(new QOffscreenSurface); - tempSurface->setFormat(ctx->format()); - tempSurface->create(); - ctx->makeCurrent(tempSurface.data()); - } - } - - if (m_bsTextureContext && ctx && ctx->shareGroup() == m_bsTextureContext->shareGroup()) { - delete m_bsTextureWrapper; - glDeleteTextures(1, &m_bsTexture); - } else { - qWarning("QOpenGLCompositorBackingStore: Texture is not valid in the current context"); - } - - if (tempSurface && ctx) - ctx->doneCurrent(); + if (m_bsTexture && m_rhi) { + delete m_bsTextureWrapper; + // Contexts are sharing resources, won't matter which one is + // current here, use the rhi's shortcut. + m_rhi->makeThreadLocalNativeContextCurrent(); + glDeleteTextures(1, &m_bsTexture); } delete m_textures; // this does not actually own any GL resources @@ -137,8 +117,6 @@ void QOpenGLCompositorBackingStore::updateTexture() glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_image.width(), m_image.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); - m_bsTextureWrapper = m_rhi->newTexture(QRhiTexture::RGBA8, m_image.size()); - m_bsTextureWrapper->createFrom({m_bsTexture, 0}); } else { glBindTexture(GL_TEXTURE_2D, m_bsTexture); } @@ -185,6 +163,11 @@ void QOpenGLCompositorBackingStore::updateTexture() m_dirty = QRegion(); } + + if (!m_bsTextureWrapper) { + m_bsTextureWrapper = m_rhi->newTexture(QRhiTexture::RGBA8, m_image.size()); + m_bsTextureWrapper->createFrom({m_bsTexture, 0}); + } } void QOpenGLCompositorBackingStore::flush(QWindow *window, const QRegion ®ion, const QPoint &offset) @@ -194,15 +177,25 @@ void QOpenGLCompositorBackingStore::flush(QWindow *window, const QRegion ®ion Q_UNUSED(region); Q_UNUSED(offset); + m_rhi = rhi(); + if (!m_rhi) { + setRhiConfig(QPlatformBackingStoreRhiConfig(QPlatformBackingStoreRhiConfig::OpenGL)); + m_rhi = rhi(); + } + Q_ASSERT(m_rhi); + QOpenGLCompositor *compositor = QOpenGLCompositor::instance(); QOpenGLContext *dstCtx = compositor->context(); - Q_ASSERT(dstCtx); + if (!dstCtx) + return; QWindow *dstWin = compositor->targetWindow(); if (!dstWin) return; - dstCtx->makeCurrent(dstWin); + if (!dstCtx->makeCurrent(dstWin)) + return; + updateTexture(); m_textures->clear(); m_textures->appendTexture(nullptr, m_bsTextureWrapper, window->geometry()); @@ -223,16 +216,23 @@ QPlatformBackingStore::FlushResult QOpenGLCompositorBackingStore::rhiFlush(QWind Q_UNUSED(translucentBackground); m_rhi = rhi(); + if (!m_rhi) { + setRhiConfig(QPlatformBackingStoreRhiConfig(QPlatformBackingStoreRhiConfig::OpenGL)); + m_rhi = rhi(); + } + Q_ASSERT(m_rhi); QOpenGLCompositor *compositor = QOpenGLCompositor::instance(); QOpenGLContext *dstCtx = compositor->context(); - Q_ASSERT(dstCtx); // setTarget() must have been called before, e.g. from QEGLFSWindow + if (!dstCtx) + return FlushFailed; QWindow *dstWin = compositor->targetWindow(); if (!dstWin) return FlushFailed; - dstCtx->makeCurrent(dstWin); + if (!dstCtx->makeCurrent(dstWin)) + return FlushFailed; QWindowPrivate::get(window)->lastComposeTime.start(); diff --git a/src/opengl/qopenglvertexarrayobject.cpp b/src/opengl/qopenglvertexarrayobject.cpp index 63e37727f9..9df48a3ddc 100644 --- a/src/opengl/qopenglvertexarrayobject.cpp +++ b/src/opengl/qopenglvertexarrayobject.cpp @@ -274,7 +274,7 @@ void QOpenGLVertexArrayObjectPrivate::destroy() vao = 0; } - if (oldContext && oldContextSurface) { + if (oldContext && oldContextSurface && oldContextSurface->surfaceHandle()) { if (!oldContext->makeCurrent(oldContextSurface)) qWarning("QOpenGLVertexArrayObject::destroy() failed to restore current context"); } |