7#include <private/qeventdispatcher_wasm_p.h>
8#include <private/qwasmsuspendresumecontrol_p.h>
10#include <qpa/qwindowsysteminterface.h>
12#include <emscripten/html5.h>
14using namespace emscripten;
20, m_animationFrameHandler(QWasmAnimationFrameHandler([
this](
double frametime){
22 this->m_requestAnimationFrameId = -1;
23 this->deliverUpdateRequests();
26 QWindowSystemInterface::setSynchronousWindowSystemEvents(
true);
31 if (m_requestAnimationFrameId != -1)
42 auto allWindows =
screen()->allWindows();
43 setEnabled(std::any_of(allWindows.begin(), allWindows.end(), [](QWasmWindow *element) {
44 return !element->context2d().isUndefined();
46 if (changeType == QWasmWindowTreeNodeChangeType::NodeRemoval)
47 m_requestUpdateWindows.remove(window);
52 m_isEnabled = enabled;
60 const bool wasEnabled = m_requestUpdateHoldEnabled;
61 m_requestUpdateHoldEnabled =
false;
67 auto it = m_requestUpdateWindows.find(window);
68 if (it == m_requestUpdateWindows.end()) {
69 m_requestUpdateWindows.insert(window, std::make_tuple(updateRect, updateType));
73 if (
std::get<0>(it.value()) != updateRect) {
75 region |=
std::get<0>(it.value());
77 std::get<0>(it.value()) = region.boundingRect();
90 if (m_requestAnimationFrameId != -1)
93 if (m_requestUpdateHoldEnabled)
104 auto requestUpdateWindows = m_requestUpdateWindows;
105 m_requestUpdateWindows.clear();
110 m_inDeliverUpdateRequest =
true;
111 for (
auto it = requestUpdateWindows.constBegin(); it != requestUpdateWindows.constEnd(); ++it) {
112 auto *window = it.key();
114 const QRect updateRect = std::get<0>(it.value());
116 deliverUpdateRequest(window, updateRect, updateType);
119 m_inDeliverUpdateRequest =
false;
120 frame(requestUpdateWindows.keys());
125 const QRect &updateRect,
128 QWindow *qwindow = window->window();
132 QWindowSystemInterface::handleWindowDevicePixelRatioChanged(qwindow);
139 if (qwindow->isExposed() ==
false)
140 QWindowSystemInterface::handleExposeEvent(qwindow, updateRect);
141 window->deliverUpdateRequest();
143 QWindowSystemInterface::handleExposeEvent(qwindow, updateRect);
147void QWasmCompositor::handleBackingStoreFlush(QWindow *window,
const QRect &updateRect)
151 if (!m_inDeliverUpdateRequest)
152 requestUpdateWindow(
static_cast<QWasmWindow *>(window->handle()), updateRect);
160 for (QWasmWindow *window : windows)
171 auto argCastWrapper = [handler](val arg){ handler(arg.as<
double>()); };
172 m_handlerIndex = QWasmSuspendResumeControl::get()->registerEventHandler(argCastWrapper);
177 QWasmSuspendResumeControl::get()->removeEventHandler(m_handlerIndex);
182 using ReturnType =
double;
183 val handler = QWasmSuspendResumeControl::get()->jsEventHandlerAt(m_handlerIndex);
184 return int64_t(val::global(
"window").call<ReturnType>(
"requestAnimationFrame", handler));
189 val::global(
"window").call<
void>(
"cancelAnimationFrame",
double(id));
void cancelAnimationFrame(int64_t id)
~QWasmAnimationFrameHandler()
int64_t requestAnimationFrame()
void onWindowTreeChanged(QWasmWindowTreeNodeChangeType changeType, QWasmWindow *window)
static bool releaseRequestUpdateHold()
void setEnabled(bool enabled)
UpdateRequestDeliveryType
QWasmCompositor(QWasmScreen *screen)
friend class QWasmCompositor
QWasmWindowTreeNodeChangeType