libkwineffects: Avoid accessing effects in EffectQuickView

EffectQuickView is used by Aurorae. As long as Aurorae decorations are
rendered by kwin, it's not a problem. However, kde-gtk-config kded
module can also render them. This creates a problem. If effects object
is not created, accessing any of its getters or setters will result in a
segmentation fault.

This change rewrites the share context check so the effects object is
not accessed anymore.

One could argue that kde-gtk-config has to provide a dummy EffectsHandler
but it doesn't use effects and libkwineffects is not a dependency of
KDecoration2. So, providing a dummy EffectsHandler makes no sense.

In hindsight, we need to revisit the usage of EffectQuickView in Aurorae
as accessing the EffectsHandler in EffectQuickView is a totally valid
usecase and integration of QOpenGLContext.

BUG: 441585
This commit is contained in:
Vlad Zahorodnii 2021-09-22 11:46:45 +03:00
parent 0b95979751
commit 1b215e6c06

View file

@ -120,8 +120,9 @@ EffectQuickView::EffectQuickView(QObject *parent, QWindow *renderWindow, ExportM
format.setDepthBufferSize(16);
format.setStencilBufferSize(8);
auto shareContext = QOpenGLContext::globalShareContext();
d->m_glcontext.reset(new QOpenGLContext);
d->m_glcontext->setShareContext(QOpenGLContext::globalShareContext());
d->m_glcontext->setShareContext(shareContext);
d->m_glcontext->setFormat(format);
d->m_glcontext->create();
@ -134,8 +135,8 @@ EffectQuickView::EffectQuickView(QObject *parent, QWindow *renderWindow, ExportM
d->m_renderControl->initialize(d->m_glcontext.data());
d->m_glcontext->doneCurrent();
// On Wayland, opengl contexts are implicitly shared.
if (!effects->waylandDisplay() && !d->m_glcontext->shareContext()) {
// On Wayland, contexts are implicitly shared and QOpenGLContext::globalShareContext() is null.
if (shareContext && !d->m_glcontext->shareContext()) {
qCDebug(LIBKWINEFFECTS) << "Failed to create a shared context, falling back to raster rendering";
// still render via GL, but blit for presentation
d->m_useBlit = true;