Remove dead code & cull public API in WASM compositor

- Remove the manual destroy methods - destructor should handle
destruction
- Remove the unused enum QWasmStateFlag
- Make public API private where possible
- Adjust handleTouch->processTouch to keep consistency with other
process methods
- Remove dead fields in compositor
- Don't keep a dead screen entry in m_screens in qwasmintegration

Change-Id: I98caf4dbdda5ebd25c4a9c22a40140c7ed1d7aa7
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This commit is contained in:
Mikolaj Boc 2022-08-17 08:38:54 +02:00
parent b9887d51c3
commit 9bf689e875
5 changed files with 30 additions and 44 deletions

View File

@ -199,8 +199,6 @@ void QWasmCompositor::setVisible(QWasmWindow *window, bool visible)
return;
m_windowVisibility[window] = visible;
if (!visible)
m_globalDamage = window->window()->geometry(); // repaint previously covered area.
requestUpdateWindow(window, QWasmCompositor::ExposeEventDelivery);
}
@ -212,15 +210,9 @@ void QWasmCompositor::raise(QWasmWindow *window)
void QWasmCompositor::lower(QWasmWindow *window)
{
m_globalDamage = window->window()->geometry(); // repaint previously covered area.
m_windowStack.lower(window);
}
int QWasmCompositor::windowCount() const
{
return m_windowStack.size();
}
QWindow *QWasmCompositor::windowAt(QPoint targetPointInScreenCoords, int padding) const
{
const auto found = std::find_if(
@ -578,7 +570,7 @@ int QWasmCompositor::wheel_cb(int eventType, const EmscriptenWheelEvent *wheelEv
int QWasmCompositor::touchCallback(int eventType, const EmscriptenTouchEvent *touchEvent, void *userData)
{
auto compositor = reinterpret_cast<QWasmCompositor*>(userData);
return static_cast<int>(compositor->handleTouch(eventType, touchEvent));
return static_cast<int>(compositor->processTouch(eventType, touchEvent));
}
bool QWasmCompositor::processPointer(const PointerEvent& event)
@ -936,7 +928,7 @@ bool QWasmCompositor::processWheel(int eventType, const EmscriptenWheelEvent *wh
return accepted;
}
int QWasmCompositor::handleTouch(int eventType, const EmscriptenTouchEvent *touchEvent)
bool QWasmCompositor::processTouch(int eventType, const EmscriptenTouchEvent *touchEvent)
{
QList<QWindowSystemInterface::TouchPoint> touchPointList;
touchPointList.reserve(touchEvent->numTouches);

View File

@ -32,23 +32,14 @@ class QOpenGLContext;
class QOpenGLTexture;
class QWasmEventTranslator;
class QWasmCompositor : public QObject
class QWasmCompositor final : public QObject
{
Q_OBJECT
public:
QWasmCompositor(QWasmScreen *screen);
~QWasmCompositor();
void initEventHandlers();
void deregisterEventHandlers();
void destroy();
~QWasmCompositor() final;
enum QWasmStateFlag {
State_None = 0x00000000,
State_Enabled = 0x00000001,
State_Raised = 0x00000002,
State_Sunken = 0x00000004
};
Q_DECLARE_FLAGS(StateFlags, QWasmStateFlag)
void initEventHandlers();
struct QWasmFrameOptions {
QRect rect;
@ -66,8 +57,6 @@ public:
void raise(QWasmWindow *window);
void lower(QWasmWindow *window);
int windowCount() const;
QWindow *windowAt(QPoint globalPoint, int padding = 0) const;
QWindow *keyWindow() const;
@ -77,20 +66,11 @@ public:
enum UpdateRequestDeliveryType { ExposeEventDelivery, UpdateRequestDelivery };
void requestUpdateAllWindows();
void requestUpdateWindow(QWasmWindow *window, UpdateRequestDeliveryType updateType = ExposeEventDelivery);
void requestUpdate();
void deliverUpdateRequests();
void deliverUpdateRequest(QWasmWindow *window, UpdateRequestDeliveryType updateType);
void handleBackingStoreFlush();
bool processKeyboard(int eventType, const EmscriptenKeyboardEvent *keyEvent);
bool processWheel(int eventType, const EmscriptenWheelEvent *wheelEvent);
int handleTouch(int eventType, const EmscriptenTouchEvent *touchEvent);
void setCapture(QWasmWindow *window);
void releaseCapture();
bool processMouseEnter(const EmscriptenMouseEvent *mouseEvent);
bool processMouseLeave();
void enterWindow(QWindow* window, const QPoint &localPoint, const QPoint &globalPoint);
void leaveWindow(QWindow* window);
void handleBackingStoreFlush();
private slots:
void frame();
@ -146,6 +126,13 @@ private:
};
void onTopWindowChanged();
void deregisterEventHandlers();
void destroy();
void requestUpdate();
void deliverUpdateRequests();
void deliverUpdateRequest(QWasmWindow *window, UpdateRequestDeliveryType updateType);
void drawWindow(QOpenGLTextureBlitter *blitter, QWasmScreen *screen, const QWasmWindow *window);
void drawWindowContent(QOpenGLTextureBlitter *blitter, QWasmScreen *screen,
const QWasmWindow *window);
@ -165,6 +152,15 @@ private:
static int touchCallback(int eventType, const EmscriptenTouchEvent *ev, void *userData);
bool processKeyboard(int eventType, const EmscriptenKeyboardEvent *keyEvent);
bool processWheel(int eventType, const EmscriptenWheelEvent *wheelEvent);
bool processMouseEnter(const EmscriptenMouseEvent *mouseEvent);
bool processMouseLeave();
bool processTouch(int eventType, const EmscriptenTouchEvent *touchEvent);
void enterWindow(QWindow *window, const QPoint &localPoint, const QPoint &globalPoint);
void leaveWindow(QWindow *window);
WindowManipulation m_windowManipulation;
QWasmWasmWindowStack m_windowStack;
@ -172,9 +168,6 @@ private:
QScopedPointer<QOpenGLTextureBlitter> m_blitter;
QHash<const QWasmWindow *, bool> m_windowVisibility;
QRegion m_globalDamage; // damage caused by expose, window close, etc.
bool m_needComposit = false;
bool m_inFlush = false;
bool m_isEnabled = true;
QSize m_targetSize;
qreal m_targetDevicePixelRatio = 1;

View File

@ -311,6 +311,7 @@ void QWasmIntegration::removeScreen(const emscripten::val &element)
return;
}
it->second->deleteScreen();
m_screens.erase(it);
}
void QWasmIntegration::resizeScreen(const emscripten::val &element)

View File

@ -100,10 +100,7 @@ QWasmScreen::QWasmScreen(const emscripten::val &containerOrCanvas)
QWasmScreen::~QWasmScreen()
{
// Delete the compositor before removing the screen from specialHTMLTargets,
// since its destructor needs to look up the target when deregistering
// event handlers.
m_compositor = nullptr;
Q_ASSERT(!m_compositor); // deleteScreen should have been called to remove this screen
if (hasSpecialHtmlTargets())
emscripten::val::module_property("specialHTMLTargets")
@ -114,7 +111,10 @@ QWasmScreen::~QWasmScreen()
void QWasmScreen::deleteScreen()
{
m_compositor->destroy();
// Delete the compositor before removing the screen, since its destruction routine needs to use
// the fully operational screen.
m_compositor.reset();
// Deletes |this|!
QWindowSystemInterface::handleScreenRemoved(this);
}

View File

@ -156,7 +156,7 @@ void QWasmWindow::setGeometry(const QRect &rect)
if (shouldInvalidate)
invalidate();
else
m_compositor->requestUpdate();
m_compositor->requestUpdateWindow(this);
}
void QWasmWindow::setVisible(bool visible)