// Copyright (C) 2018 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QWASMCOMPOSITOR_H #define QWASMCOMPOSITOR_H #include "qwasmwindowstack.h" #include #include #include #include #include #include #include #include #include QT_BEGIN_NAMESPACE struct PointerEvent; class QWasmWindow; class QWasmScreen; class QOpenGLContext; class QOpenGLTexture; class QWasmEventTranslator; class QWasmCompositor final : public QObject { Q_OBJECT public: QWasmCompositor(QWasmScreen *screen); ~QWasmCompositor() final; void initEventHandlers(); struct QWasmFrameOptions { QRect rect; int lineWidth; QPalette palette; }; void addWindow(QWasmWindow *window); void removeWindow(QWasmWindow *window); void setVisible(QWasmWindow *window, bool visible); void raise(QWasmWindow *window); void lower(QWasmWindow *window); void onScreenDeleting(); QWindow *windowAt(QPoint globalPoint, int padding = 0) const; QWindow *keyWindow() const; QWasmScreen *screen(); enum UpdateRequestDeliveryType { ExposeEventDelivery, UpdateRequestDelivery }; void requestUpdateAllWindows(); void requestUpdateWindow(QWasmWindow *window, UpdateRequestDeliveryType updateType = ExposeEventDelivery); void setCapture(QWasmWindow *window); void releaseCapture(); void handleBackingStoreFlush(QWindow *window); private: void frame(bool all, const QList &windows); void onTopWindowChanged(); void deregisterEventHandlers(); void destroy(); void requestUpdate(); void deliverUpdateRequests(); void deliverUpdateRequest(QWasmWindow *window, UpdateRequestDeliveryType updateType); static int keyboard_cb(int eventType, const EmscriptenKeyboardEvent *keyEvent, void *userData); static int touchCallback(int eventType, const EmscriptenTouchEvent *ev, void *userData); bool processKeyboard(int eventType, const EmscriptenKeyboardEvent *keyEvent); bool processTouch(int eventType, const EmscriptenTouchEvent *touchEvent); void enterWindow(QWindow *window, const QPoint &localPoint, const QPoint &globalPoint); void leaveWindow(QWindow *window); void updateEnabledState(); QWasmWindowStack m_windowStack; bool m_isEnabled = true; QSize m_targetSize; qreal m_targetDevicePixelRatio = 1; QMap m_requestUpdateWindows; bool m_requestUpdateAllWindows = false; int m_requestAnimationFrameId = -1; bool m_inDeliverUpdateRequest = false; std::unique_ptr m_touchDevice; QMap m_pressedTouchIds; std::unique_ptr m_eventTranslator; }; QT_END_NAMESPACE #endif