diff --git a/libkwineffects/kwineffectquickview.h b/libkwineffects/kwineffectquickview.h --- a/libkwineffects/kwineffectquickview.h +++ b/libkwineffects/kwineffectquickview.h @@ -60,7 +60,7 @@ Q_OBJECT public: - static void setShareContext(std::unique_ptr context); + static void setUsingShareContexts(bool); enum class ExportMode { /** The contents will be available as a texture in the shared contexts. Image will be blank*/ diff --git a/libkwineffects/kwineffectquickview.cpp b/libkwineffects/kwineffectquickview.cpp --- a/libkwineffects/kwineffectquickview.cpp +++ b/libkwineffects/kwineffectquickview.cpp @@ -41,7 +41,7 @@ using namespace KWin; -static std::unique_ptr s_shareContext; +static bool s_usingShareContexts = false; class Q_DECL_HIDDEN EffectQuickView::Private { @@ -100,7 +100,7 @@ format.setStencilBufferSize(8); d->m_glcontext.reset(new QOpenGLContext); - d->m_glcontext->setShareContext(s_shareContext.get()); + d->m_glcontext->setShareContext(QOpenGLContext::globalShareContext()); d->m_glcontext->setFormat(format); d->m_glcontext->create(); @@ -113,14 +113,8 @@ d->m_renderControl->initialize(d->m_glcontext.data()); d->m_glcontext->doneCurrent(); - if (!d->m_glcontext->shareContext()) { - qCDebug(LIBKWINEFFECTS) << "Failed to create a shared context, falling back to raster rendering"; - qCDebug(LIBKWINEFFECTS) << "Extra debug:"; - qCDebug(LIBKWINEFFECTS) << "our context:" << d->m_glcontext.data(); - qCDebug(LIBKWINEFFECTS) << "share context:" << s_shareContext.get(); - - // still render via GL, but blit for presentation + if (!s_usingShareContexts) { d->m_useBlit = true; } } @@ -249,9 +243,9 @@ QCoreApplication::sendEvent(d->m_view, keyEvent); } -void EffectQuickView::setShareContext(std::unique_ptr context) +void EffectQuickView::setUsingShareContexts(bool usingShare) { - s_shareContext = std::move(context); + s_usingShareContexts = usingShare; } QRect EffectQuickView::geometry() const diff --git a/main_x11.cpp b/main_x11.cpp --- a/main_x11.cpp +++ b/main_x11.cpp @@ -421,6 +421,7 @@ qunsetenv("QT_DEVICE_PIXEL_RATIO"); qunsetenv("QT_SCALE_FACTOR"); QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling); + QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts); KWin::ApplicationX11 a(argc, argv); a.setupTranslator(); diff --git a/plugins/platforms/x11/standalone/glxbackend.cpp b/plugins/platforms/x11/standalone/glxbackend.cpp --- a/plugins/platforms/x11/standalone/glxbackend.cpp +++ b/plugins/platforms/x11/standalone/glxbackend.cpp @@ -130,7 +130,7 @@ // do cleanup after initBuffer() cleanupGL(); doneCurrent(); - EffectQuickView::setShareContext(nullptr); + EffectQuickView::setUsingShareContexts(false); if (ctx) glXDestroyContext(display(), ctx); @@ -260,6 +260,7 @@ bool GlxBackend::initRenderingContext() { const bool direct = true; + bool usingSharedContext = false; // Use glXCreateContextAttribsARB() when it's available if (hasExtension(QByteArrayLiteral("GLX_ARB_create_context"))) { @@ -302,9 +303,16 @@ } for (auto it = candidates.begin(); it != candidates.end(); it++) { const auto attribs = it->build(); - ctx = glXCreateContextAttribsARB(display(), fbconfig, nullptr, true, attribs.data()); + + auto share = QOpenGLContext::globalShareContext(); + GLXContext shareHandle = nullptr; + if (QOpenGLContext::globalShareContext()) { + shareHandle = QOpenGLContext::globalShareContext()->nativeHandle().value().context(); + } + ctx = glXCreateContextAttribsARB(display(), fbconfig, shareHandle, true, attribs.data()); if (ctx) { qCDebug(KWIN_X11STANDALONE) << "Created GLX context with attributes:" << &(*it); + usingSharedContext = shareHandle != nullptr; break; } } @@ -325,11 +333,7 @@ return false; } - auto qtContext = new QOpenGLContext; - QGLXNativeContext native(ctx, display()); - qtContext->setNativeHandle(QVariant::fromValue(native)); - qtContext->create(); - EffectQuickView::setShareContext(std::unique_ptr(qtContext)); + EffectQuickView::setUsingShareContexts(usingSharedContext); return true; }