Don't tie compositor's enabled state to last added window

Currently, the compositor gets enabled/disabled based on the last
constructed window's surface type. This causes non-OpenGL windows not to
be displayed if any OpenGL window is created last.

The compositor should scan for any non-openGL windows on any change
to the window set to decide if it needs to be disabled or not.

Change-Id: I037470e39a3fbae50fd3a4e29cb6615130d7b114
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This commit is contained in:
Mikolaj Boc 2022-11-28 15:24:58 +01:00
parent a9005a70d5
commit a812d1eb66
3 changed files with 15 additions and 11 deletions

View File

@ -149,11 +149,6 @@ void QWasmCompositor::initEventHandlers()
emscripten::val(quintptr(reinterpret_cast<void *>(screen())))); emscripten::val(quintptr(reinterpret_cast<void *>(screen()))));
} }
void QWasmCompositor::setEnabled(bool enabled)
{
m_isEnabled = enabled;
}
void QWasmCompositor::startResize(Qt::Edges edges) void QWasmCompositor::startResize(Qt::Edges edges)
{ {
m_windowManipulation.startResize(edges); m_windowManipulation.startResize(edges);
@ -163,6 +158,8 @@ void QWasmCompositor::addWindow(QWasmWindow *window)
{ {
m_windowStack.pushWindow(window); m_windowStack.pushWindow(window);
m_windowStack.topWindow()->requestActivateWindow(); m_windowStack.topWindow()->requestActivateWindow();
updateEnabledState();
} }
void QWasmCompositor::removeWindow(QWasmWindow *window) void QWasmCompositor::removeWindow(QWasmWindow *window)
@ -171,6 +168,15 @@ void QWasmCompositor::removeWindow(QWasmWindow *window)
m_windowStack.removeWindow(window); m_windowStack.removeWindow(window);
if (m_windowStack.topWindow()) if (m_windowStack.topWindow())
m_windowStack.topWindow()->requestActivateWindow(); m_windowStack.topWindow()->requestActivateWindow();
updateEnabledState();
}
void QWasmCompositor::updateEnabledState()
{
m_isEnabled = std::any_of(m_windowStack.begin(), m_windowStack.end(), [](QWasmWindow *window) {
return !window->context2d().isUndefined();
});
} }
void QWasmCompositor::raise(QWasmWindow *window) void QWasmCompositor::raise(QWasmWindow *window)

View File

@ -43,7 +43,6 @@ public:
QPalette palette; QPalette palette;
}; };
void setEnabled(bool enabled);
void startResize(Qt::Edges edges); void startResize(Qt::Edges edges);
void addWindow(QWasmWindow *window); void addWindow(QWasmWindow *window);
@ -146,6 +145,8 @@ private:
void enterWindow(QWindow *window, const QPoint &localPoint, const QPoint &globalPoint); void enterWindow(QWindow *window, const QPoint &localPoint, const QPoint &globalPoint);
void leaveWindow(QWindow *window); void leaveWindow(QWindow *window);
void updateEnabledState();
WindowManipulation m_windowManipulation; WindowManipulation m_windowManipulation;
QWasmWindowStack m_windowStack; QWasmWindowStack m_windowStack;

View File

@ -232,8 +232,8 @@ QWasmWindow::QWasmWindow(QWindow *w, QWasmCompositor *compositor, QWasmBackingSt
compositor->screen()->element().call<void>("appendChild", m_qtWindow); compositor->screen()->element().call<void>("appendChild", m_qtWindow);
m_needsCompositor = w->surfaceType() != QSurface::OpenGLSurface; const bool rendersTo2dContext = w->surfaceType() != QSurface::OpenGLSurface;
if (m_needsCompositor) if (rendersTo2dContext)
m_context2d = m_canvas.call<emscripten::val>("getContext", emscripten::val("2d")); m_context2d = m_canvas.call<emscripten::val>("getContext", emscripten::val("2d"));
static int serialNo = 0; static int serialNo = 0;
m_winId = ++serialNo; m_winId = ++serialNo;
@ -241,9 +241,6 @@ QWasmWindow::QWasmWindow(QWindow *w, QWasmCompositor *compositor, QWasmBackingSt
emscripten::val::module_property("specialHTMLTargets").set(canvasSelector(), m_canvas); emscripten::val::module_property("specialHTMLTargets").set(canvasSelector(), m_canvas);
m_compositor->addWindow(this); m_compositor->addWindow(this);
// Pure OpenGL windows draw directly using egl, disable the compositor.
m_compositor->setEnabled(w->surfaceType() != QSurface::OpenGLSurface);
} }
QWasmWindow::~QWasmWindow() QWasmWindow::~QWasmWindow()