diff options
author | Mikolaj Boc <mikolaj.boc@qt.io> | 2022-11-14 09:12:34 +0100 |
---|---|---|
committer | Mikolaj Boc <mikolaj.boc@qt.io> | 2022-11-26 11:23:13 +0100 |
commit | fa27a59ec3cfc173d5ff202feb23e8b6e398dac9 (patch) | |
tree | a34f7a199611118e826a029a5bebf93f9425b32d /src/plugins/platforms/wasm/qwasmintegration.cpp | |
parent | c675c1c56d3c00b3c1de5aee8c7c6f7eeeb70bc1 (diff) |
Use the browser compositor for drawing windows on WASM
Make the browser compositor draw the window non-client area (using css
+ html). Get rid of OpenGL usage in non-OpenGL windows and use canvas
2d context instead to blit the texture (QImage).
Also, as part of the change, remove the deprecated canvas element support
in QScreen.
Fixes: QTBUG-107116
Fixes: QTBUG-107219
Change-Id: I65f0d91831c806315685ca681ac0e416673f5cd5
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Reviewed-by: Aleksandr Reviakin <aleksandr.reviakin@qt.io>
Reviewed-by: David Skoland <david.skoland@qt.io>
Diffstat (limited to 'src/plugins/platforms/wasm/qwasmintegration.cpp')
-rw-r--r-- | src/plugins/platforms/wasm/qwasmintegration.cpp | 60 |
1 files changed, 23 insertions, 37 deletions
diff --git a/src/plugins/platforms/wasm/qwasmintegration.cpp b/src/plugins/platforms/wasm/qwasmintegration.cpp index 39eea05ad3..5eb5030e63 100644 --- a/src/plugins/platforms/wasm/qwasmintegration.cpp +++ b/src/plugins/platforms/wasm/qwasmintegration.cpp @@ -85,58 +85,44 @@ QWasmIntegration::QWasmIntegration() { s_instance = this; - touchPoints = emscripten::val::global("navigator")["maxTouchPoints"].as<int>(); + touchPoints = emscripten::val::global("navigator")["maxTouchPoints"].as<int>(); - // Create screens for container elements. Each container element can be a div element (preferred), - // or a canvas element (legacy). Qt versions prior to 6.x read the "qtCanvasElements" module property, - // which we continue to do to preserve compatibility. The preferred property is now "qtContainerElements". + // Create screens for container elements. Each container element will ultimately become a + // div element. Qt historically supported supplying canvas for screen elements - these elements + // will be transformed into divs and warnings about deprecation will be printed. See + // QWasmScreen ctor. emscripten::val qtContainerElements = val::module_property("qtContainerElements"); - emscripten::val qtCanvasElements = val::module_property("qtCanvasElements"); - if (!qtContainerElements.isUndefined()) { - emscripten::val length = qtContainerElements["length"]; - int count = length.as<int>(); - if (length.isUndefined()) - qWarning("qtContainerElements does not have the length property set. Qt expects an array of html elements (possibly containing one element only)"); - for (int i = 0; i < count; ++i) { + if (qtContainerElements.isArray()) { + for (int i = 0; i < qtContainerElements["length"].as<int>(); ++i) { emscripten::val element = qtContainerElements[i].as<emscripten::val>(); - if (element.isNull() ||element.isUndefined()) { - qWarning() << "Skipping null or undefined element in qtContainerElements"; - } else { + if (element.isNull() || element.isUndefined()) + qWarning() << "Skipping null or undefined element in qtContainerElements"; + else addScreen(element); - } } - } else if (!qtCanvasElements.isUndefined()) { - qWarning() << "The qtCanvaseElements property is deprecated. Qt will stop reading" - << "it in some future version, please use qtContainerElements instead"; - emscripten::val length = qtCanvasElements["length"]; - int count = length.as<int>(); - for (int i = 0; i < count; ++i) - addScreen(qtCanvasElements[i].as<emscripten::val>()); } else { // No screens, which may or may not be intended - qWarning() << "Note: The qtContainerElements module property was not set. Proceeding with no screens."; + qWarning() << "The qtContainerElements module property was not set or is invalid. " + "Proceeding with no screens."; } // install browser window resize handler - auto onWindowResize = [](int eventType, const EmscriptenUiEvent *e, void *userData) -> int { - Q_UNUSED(eventType); - Q_UNUSED(e); - Q_UNUSED(userData); - - // This resize event is called when the HTML window is resized. Depending - // on the page layout the canvas(es) might also have been resized, so we - // update the Qt screen sizes (and canvas render sizes). - if (QWasmIntegration *integration = QWasmIntegration::get()) - integration->resizeAllScreens(); - return 0; - }; - emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, nullptr, EM_TRUE, onWindowResize); + emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, nullptr, EM_TRUE, + [](int, const EmscriptenUiEvent *, void *) -> int { + // This resize event is called when the HTML window is + // resized. Depending on the page layout the elements might + // also have been resized, so we update the Qt screen sizes + // (and canvas render sizes). + if (QWasmIntegration *integration = QWasmIntegration::get()) + integration->resizeAllScreens(); + return 0; + }); // install visualViewport resize handler which picks up size and scale change on mobile. emscripten::val visualViewport = emscripten::val::global("window")["visualViewport"]; if (!visualViewport.isUndefined()) { visualViewport.call<void>("addEventListener", val("resize"), - val::module_property("qtResizeAllScreens")); + val::module_property("qtResizeAllScreens")); } m_drag = new QWasmDrag(); } |