eglfs: change the condition to destroy the openglcompositor

With an openglcompositor, only first QEglFSWindow is set
with a flag, HasNativeWindow and when it is destroyed,
the openglcompositor is destroyed, too.
For now, when using openglcompositor, Qt will not check
HasNativeWindow for its nativeWindow because it is not
possible to add a HasNativeWindow flag in an existing
window. And the openglcompositor will be destroyed after
the all the QEglFSWindows are closed.

Fixes: QTBUG-129576
Pick-to: 6.8 6.5
Change-Id: I620a904a03d29e8db1738d9392f716b3ebf5b553
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
This commit is contained in:
Inho Lee 2024-10-07 13:38:16 +02:00
parent e54d4eabbe
commit 39bcd4287a
2 changed files with 28 additions and 16 deletions

View File

@ -273,9 +273,9 @@ void QOpenGLCompositor::addWindow(QOpenGLCompositorWindow *window)
void QOpenGLCompositor::removeWindow(QOpenGLCompositorWindow *window)
{
m_windows.removeOne(window);
if (!m_windows.isEmpty())
emit topWindowChanged(m_windows.last());
bool couldChangeTopWindow = (m_windows.size() > 1) ? (window == m_windows.constLast()) : false;
if (m_windows.removeOne(window) && couldChangeTopWindow)
emit topWindowChanged(m_windows.constLast());
}
void QOpenGLCompositor::moveToTop(QOpenGLCompositorWindow *window)

View File

@ -129,29 +129,42 @@ void QEglFSWindow::destroy()
if (!m_flags.testFlag(Created))
return; // already destroyed
#ifndef QT_NO_OPENGL
QOpenGLCompositor::instance()->removeWindow(this);
#endif
QEglFSScreen *screen = this->screen();
if (m_flags.testFlag(HasNativeWindow)) {
#ifndef QT_NO_OPENGL
QOpenGLCompositor *compositor = QOpenGLCompositor::instance();
compositor->removeWindow(this);
if (compositor->targetWindow() == window()) {
QEglFSCursor *cursor = qobject_cast<QEglFSCursor *>(screen->cursor());
if (cursor)
cursor->resetResources();
#endif
if (screen->primarySurface() == m_surface)
screen->setPrimarySurface(EGL_NO_SURFACE);
invalidateSurface();
#ifndef QT_NO_OPENGL
QOpenGLCompositor::destroy();
if (qt_gl_global_share_context() == m_rasterCompositingContext)
qt_gl_set_global_share_context(nullptr);
delete m_rasterCompositingContext;
#endif
if (compositor->windows().isEmpty()) {
compositor->destroy();
if (qt_gl_global_share_context() == m_rasterCompositingContext)
qt_gl_set_global_share_context(nullptr);
delete m_rasterCompositingContext;
} else {
auto topWindow = static_cast<QEglFSWindow *>(compositor->windows().last());
// Make fullscreen
topWindow->setGeometry(screen->rawGeometry());
topWindow->resetSurface();
screen->setPrimarySurface(topWindow->surface());
compositor->setTargetWindow(topWindow->sourceWindow(), screen->rawGeometry());
}
}
#else
if (m_flags.testFlag(HasNativeWindow)) {
if (screen->primarySurface() == m_surface)
screen->setPrimarySurface(EGL_NO_SURFACE);
invalidateSurface();
}
#endif
m_flags = { };
}
@ -179,7 +192,6 @@ void QEglFSWindow::invalidateSurface()
if (screen()->primarySurface() == m_surface)
screen()->setPrimarySurface(EGL_NO_SURFACE);
m_surface = EGL_NO_SURFACE;
m_flags = m_flags & ~Created;
}