From 0efdf54a16d785598a2e310733a43e51d8a521b8 Mon Sep 17 00:00:00 2001 From: Alexandra Cherdantseva Date: Mon, 20 Jan 2020 17:10:26 +0300 Subject: wasm: fix texture leak when window is destroyed in a different context MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reproduce: Show first window in first canvas; Show second window in second canvas; After screens are rendered destroy first window in first canvas Change-Id: Ifbeb4824c1fdedecf24d5d20e58613d15c066420 Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/wasm/qwasmbackingstore.cpp | 27 +++++++++++++++++++----- src/plugins/platforms/wasm/qwasmcompositor.cpp | 7 ++++-- src/plugins/platforms/wasm/qwasmcompositor.h | 5 +++-- src/plugins/platforms/wasm/qwasmintegration.cpp | 5 +++++ src/plugins/platforms/wasm/qwasmintegration.h | 1 + 5 files changed, 36 insertions(+), 9 deletions(-) (limited to 'src/plugins/platforms/wasm') diff --git a/src/plugins/platforms/wasm/qwasmbackingstore.cpp b/src/plugins/platforms/wasm/qwasmbackingstore.cpp index 7e8a382512..6ac685083d 100644 --- a/src/plugins/platforms/wasm/qwasmbackingstore.cpp +++ b/src/plugins/platforms/wasm/qwasmbackingstore.cpp @@ -36,7 +36,7 @@ #include #include #include - +#include #include QT_BEGIN_NAMESPACE @@ -53,12 +53,29 @@ QWasmBackingStore::QWasmBackingStore(QWasmCompositor *compositor, QWindow *windo QWasmBackingStore::~QWasmBackingStore() { + auto window = this->window(); + QWasmIntegration::get()->removeBackingStore(window); + destroy(); + QWasmWindow *wasmWindow = static_cast(window->handle()); + if (wasmWindow) + wasmWindow->setBackingStore(nullptr); } void QWasmBackingStore::destroy() { - if (m_texture->isCreated()) - m_texture->destroy(); + if (m_texture->isCreated()) { + auto context = m_compositor->context(); + auto currentContext = QOpenGLContext::currentContext(); + if (!currentContext || !QOpenGLContext::areSharing(context, currentContext)) { + QOffscreenSurface offScreenSurface(m_compositor->screen()->screen()); + offScreenSurface.setFormat(context->format()); + offScreenSurface.create(); + context->makeCurrent(&offScreenSurface); + m_texture->destroy(); + } else { + m_texture->destroy(); + } + } } QPaintDevice *QWasmBackingStore::paintDevice() @@ -81,9 +98,9 @@ void QWasmBackingStore::updateTexture() if (m_dirty.isNull()) return; - if (m_recreateTexture && m_texture->isCreated()) { + if (m_recreateTexture) { m_recreateTexture = false; - m_texture->destroy(); + destroy(); } if (!m_texture->isCreated()) { diff --git a/src/plugins/platforms/wasm/qwasmcompositor.cpp b/src/plugins/platforms/wasm/qwasmcompositor.cpp index e9c4559971..2f0b0414d9 100644 --- a/src/plugins/platforms/wasm/qwasmcompositor.cpp +++ b/src/plugins/platforms/wasm/qwasmcompositor.cpp @@ -59,7 +59,6 @@ QWasmCompositedWindow::QWasmCompositedWindow() QWasmCompositor::QWasmCompositor(QWasmScreen *screen) :QObject(screen) - , m_frameBuffer(nullptr) , m_blitter(new QOpenGLTextureBlitter) , m_needComposit(false) , m_inFlush(false) @@ -71,7 +70,6 @@ QWasmCompositor::QWasmCompositor(QWasmScreen *screen) QWasmCompositor::~QWasmCompositor() { - delete m_frameBuffer; destroy(); } @@ -748,3 +746,8 @@ QWasmScreen *QWasmCompositor::screen() { return static_cast(parent()); } + +QOpenGLContext *QWasmCompositor::context() +{ + return m_context.data(); +} diff --git a/src/plugins/platforms/wasm/qwasmcompositor.h b/src/plugins/platforms/wasm/qwasmcompositor.h index 98f4a79b27..422f990175 100644 --- a/src/plugins/platforms/wasm/qwasmcompositor.h +++ b/src/plugins/platforms/wasm/qwasmcompositor.h @@ -125,11 +125,13 @@ public: static QWasmTitleBarOptions makeTitleBarOptions(const QWasmWindow *window); static QRect titlebarRect(QWasmTitleBarOptions tb, QWasmCompositor::SubControls subcontrol); + QWasmScreen *screen(); + QOpenGLContext *context(); + private slots: void frame(); private: - QWasmScreen *screen(); void notifyTopWindowChanged(QWasmWindow *window); void drawWindow(QOpenGLTextureBlitter *blitter, QWasmScreen *screen, QWasmWindow *window); void drawWindowContent(QOpenGLTextureBlitter *blitter, QWasmScreen *screen, QWasmWindow *window); @@ -138,7 +140,6 @@ private: void drawWindowDecorations(QOpenGLTextureBlitter *blitter, QWasmScreen *screen, QWasmWindow *window); void drwPanelButton(); - QImage *m_frameBuffer; QScopedPointer m_context; QScopedPointer m_blitter; diff --git a/src/plugins/platforms/wasm/qwasmintegration.cpp b/src/plugins/platforms/wasm/qwasmintegration.cpp index 9934f5ac19..f8eaa39f76 100644 --- a/src/plugins/platforms/wasm/qwasmintegration.cpp +++ b/src/plugins/platforms/wasm/qwasmintegration.cpp @@ -193,6 +193,11 @@ QPlatformBackingStore *QWasmIntegration::createPlatformBackingStore(QWindow *win #endif } +void QWasmIntegration::removeBackingStore(QWindow* window) +{ + m_backingStores.remove(window); +} + #ifndef QT_NO_OPENGL QPlatformOpenGLContext *QWasmIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const { diff --git a/src/plugins/platforms/wasm/qwasmintegration.h b/src/plugins/platforms/wasm/qwasmintegration.h index 2102f5c226..2eb64ed366 100644 --- a/src/plugins/platforms/wasm/qwasmintegration.h +++ b/src/plugins/platforms/wasm/qwasmintegration.h @@ -88,6 +88,7 @@ public: void resizeScreen(const QString &canvasId); void resizeAllScreens(); void updateDpi(); + void removeBackingStore(QWindow* window); private: mutable QWasmFontDatabase *m_fontDb; -- cgit v1.2.3