Commit 09e8d69b authored by Laszlo Agocs's avatar Laszlo Agocs
Browse files

eglfs: Sanitize the widget compositor's context handling


createPlatformOpenGLContext() used to silently set the widget
compositor's context as the context to share resources with.

This works mostly, but is the wrong level to enforce the resource
sharing.  For example, QOpenGLContext::shareGroup() becomes
inconsistent since from QOpenGLContext's view there was no
shareContext specified.

The inability to test via shareGroup() is the reason eglfs started to
show warnings when exiting applications. The resource sharing was in
place on EGL level but QOpenGLContext knew nothing about it.

Therefore, let's switch over to the way other components, f.ex. Web
Engine use: set the internal global share context pointer to the
widget compositor's context. This way everything remains consistent:
the widget compositor's context is stored upon creating the main
QEGLFSWindow, QWidget::shareContext() picks this up then, and as a
result we have sharing set up on QOpenGLContext's level instead of
sneaking it in in the QPlatformOpenGLContext implementation.

Task-number: QTBUG-50707
Change-Id: I5fc1dec58c69c46aa83c7b4cab1eadce6fa633ce
Reviewed-by: default avatarPaul Olav Tvete <paul.tvete@theqtcompany.com>
Showing with 18 additions and 5 deletions
......@@ -57,7 +57,7 @@ QT_BEGIN_NAMESPACE
It is up to the platform plugin to manage the lifetime of the
compositor (instance(), destroy()), set the correct destination
context and window as early as possible (setTargetWindow()),
context and window as early as possible (setTarget()),
register the composited windows as they are shown, activated,
raised and lowered (addWindow(), moveToTop(), etc.), and to
schedule repaints (update()).
......
......@@ -184,6 +184,8 @@ void QOpenGLCompositorBackingStore::flush(QWindow *window, const QRegion &region
QOpenGLCompositor *compositor = QOpenGLCompositor::instance();
QOpenGLContext *dstCtx = compositor->context();
Q_ASSERT(dstCtx);
QWindow *dstWin = compositor->targetWindow();
if (!dstWin)
return;
......@@ -209,6 +211,12 @@ void QOpenGLCompositorBackingStore::composeAndFlush(QWindow *window, const QRegi
QOpenGLCompositor *compositor = QOpenGLCompositor::instance();
QOpenGLContext *dstCtx = compositor->context();
Q_ASSERT(dstCtx); // setTarget() must have been called before, e.g. from QEGLFSWindow
// The compositor's context and the context to which QOpenGLWidget/QQuickWidget
// textures belong are not the same. They share resources, though.
Q_ASSERT(context->shareGroup() == dstCtx->shareGroup());
QWindow *dstWin = compositor->targetWindow();
if (!dstWin)
return;
......
......@@ -188,11 +188,8 @@ QPlatformWindow *QEglFSIntegration::createPlatformWindow(QWindow *window) const
QPlatformOpenGLContext *QEglFSIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const
{
// If there is a "root" window into which raster and QOpenGLWidget content is
// composited, all other contexts must share with its context.
QOpenGLContext *compositingContext = QOpenGLCompositor::instance()->context();
EGLDisplay dpy = context->screen() ? static_cast<QEglFSScreen *>(context->screen()->handle())->display() : display();
QPlatformOpenGLContext *share = compositingContext ? compositingContext->handle() : context->shareHandle();
QPlatformOpenGLContext *share = context->shareHandle();
QVariant nativeHandle = context->nativeHandle();
QEglFSContext *ctx;
......
......@@ -138,6 +138,14 @@ void QEglFSWindow::create()
if (!context->create())
qFatal("EGLFS: Failed to create compositing context");
compositor->setTarget(context, window());
// If there is a "root" window into which raster and QOpenGLWidget content is
// composited, all other contexts must share with its context.
if (!qt_gl_global_share_context()) {
qt_gl_set_global_share_context(context);
// What we set up here is in effect equivalent to the application setting
// AA_ShareOpenGLContexts. Set the attribute to be fully consistent.
QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment