From 08733dff582e220ba381939e74c623a5321fb9a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Sat, 27 Nov 2021 23:56:40 +0100 Subject: =?UTF-8?q?wasm:=20use=20=E2=80=9CspecialHtmlTargets=E2=80=9D=20fo?= =?UTF-8?q?r=20canvas=20lookup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We’d like to support use cases which require using multiple html documents, for example when displaying application content using more than one browser window. Normally Emscripten uses the primary html document when looking up elements by id, which means that targeting elements on secondary documents is not possible. Emscripten does provide a workaround: the application can create custom id mappings to any html element on the “specialHtmlTargets” object, and then use the “!id” syntax instead of normal “#id” lookup. Change-Id: I4dda920868cfbc6f8991425daf8933144c0ffad8 Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/wasm/qwasmopenglcontext.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/plugins/platforms/wasm/qwasmopenglcontext.cpp') diff --git a/src/plugins/platforms/wasm/qwasmopenglcontext.cpp b/src/plugins/platforms/wasm/qwasmopenglcontext.cpp index c122335a575..4462e55524a 100644 --- a/src/plugins/platforms/wasm/qwasmopenglcontext.cpp +++ b/src/plugins/platforms/wasm/qwasmopenglcontext.cpp @@ -87,13 +87,12 @@ bool QWasmOpenGLContext::maybeCreateEmscriptenContext(QPlatformSurface *surface) if (m_context) return m_screen == screen; - QString canvasId = QWasmScreen::get(screen)->canvasId(); - m_context = createEmscriptenContext(canvasId, m_requestedFormat); + m_context = createEmscriptenContext(QWasmScreen::get(screen)->canvasTargetId(), m_requestedFormat); m_screen = screen; return true; } -EMSCRIPTEN_WEBGL_CONTEXT_HANDLE QWasmOpenGLContext::createEmscriptenContext(const QString &canvasId, QSurfaceFormat format) +EMSCRIPTEN_WEBGL_CONTEXT_HANDLE QWasmOpenGLContext::createEmscriptenContext(const QString &canvasTargetId, QSurfaceFormat format) { EmscriptenWebGLContextAttributes attributes; emscripten_webgl_init_context_attributes(&attributes); // Populate with default attributes @@ -114,7 +113,7 @@ EMSCRIPTEN_WEBGL_CONTEXT_HANDLE QWasmOpenGLContext::createEmscriptenContext(cons attributes.depth = useDepthStencil; attributes.stencil = useDepthStencil; - QByteArray convasSelector = "#" + canvasId.toUtf8(); + QByteArray convasSelector = canvasTargetId.toUtf8(); EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context = emscripten_webgl_create_context(convasSelector.constData(), &attributes); return context; -- cgit v1.2.3