summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/wasm/qwasmoffscreensurface.cpp
diff options
context:
space:
mode:
authorMikolaj Boc <mikolaj.boc@qt.io>2022-11-28 16:35:24 +0100
committerMikolaj Boc <mikolaj.boc@qt.io>2023-01-30 20:10:25 +0100
commit0eea2238f37a5eaa83ada6cd262eceaed20e415c (patch)
tree02f88e6033c5bb4ef08ebe4bc88b932725a576f4 /src/plugins/platforms/wasm/qwasmoffscreensurface.cpp
parent39daa368d47bc676efb19a8e7478ef1c270ae959 (diff)
Quasi-support for offscreen surface on WASM
Since context sharing is not currently supported with WebGL, offscreen contexts have a limited usability on Qt for WASM. If a context is shared, use the same underlaying WebGL context so that the two can actually share resources. This is not full-blown context sharing by any means but it makes e.g. the Open GL widget work as the readback texture for it is 'shared' between the virtual Qt contexts. If no sharing is desired, we use an OffscreenCanvas and actually create a separate WebGL context. Fixes: QTBUG-107558 Pick-to: 6.5 Change-Id: If57e44739ddb57c167d5f8881a74d8dee52531f6 Reviewed-by: MikoĊ‚aj Boc <Mikolaj.Boc@qt.io>
Diffstat (limited to 'src/plugins/platforms/wasm/qwasmoffscreensurface.cpp')
-rw-r--r--src/plugins/platforms/wasm/qwasmoffscreensurface.cpp19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/plugins/platforms/wasm/qwasmoffscreensurface.cpp b/src/plugins/platforms/wasm/qwasmoffscreensurface.cpp
index 31adc73cf5f..0191e0b2165 100644
--- a/src/plugins/platforms/wasm/qwasmoffscreensurface.cpp
+++ b/src/plugins/platforms/wasm/qwasmoffscreensurface.cpp
@@ -6,10 +6,25 @@
QT_BEGIN_NAMESPACE
QWasmOffscreenSurface::QWasmOffscreenSurface(QOffscreenSurface *offscreenSurface)
- :QPlatformOffscreenSurface(offscreenSurface)
+ : QPlatformOffscreenSurface(offscreenSurface), m_offscreenCanvas(emscripten::val::undefined())
{
+ const auto offscreenCanvasClass = emscripten::val::global("OffscreenCanvas");
+ // The OffscreenCanvas is not supported on some browsers, most notably on Safari.
+ if (!offscreenCanvasClass)
+ return;
+
+ m_offscreenCanvas = offscreenCanvasClass.new_(offscreenSurface->size().width(),
+ offscreenSurface->size().height());
+
+ m_specialTargetId = std::string("!qtoffscreen_") + std::to_string(uintptr_t(this));
+
+ emscripten::val::module_property("specialHTMLTargets")
+ .set(m_specialTargetId, m_offscreenCanvas);
}
-QWasmOffscreenSurface::~QWasmOffscreenSurface() = default;
+QWasmOffscreenSurface::~QWasmOffscreenSurface()
+{
+ emscripten::val::module_property("specialHTMLTargets").delete_(m_specialTargetId);
+}
QT_END_NAMESPACE