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 +++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'src/plugins/platforms/wasm/qwasmbackingstore.cpp') 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()) { -- cgit v1.2.3