Changeset View
Changeset View
Standalone View
Standalone View
plugins/platforms/x11/standalone/glxbackend.cpp
Show First 20 Lines • Show All 124 Lines • ▼ Show 20 Line(s) | |||||
125 | { | 125 | { | ||
126 | if (isFailed()) { | 126 | if (isFailed()) { | ||
127 | m_overlayWindow->destroy(); | 127 | m_overlayWindow->destroy(); | ||
128 | } | 128 | } | ||
129 | // TODO: cleanup in error case | 129 | // TODO: cleanup in error case | ||
130 | // do cleanup after initBuffer() | 130 | // do cleanup after initBuffer() | ||
131 | cleanupGL(); | 131 | cleanupGL(); | ||
132 | doneCurrent(); | 132 | doneCurrent(); | ||
133 | EffectQuickView::setShareContext(nullptr); | 133 | EffectQuickView::setUsingShareContexts(false); | ||
134 | 134 | | |||
135 | if (ctx) | 135 | if (ctx) | ||
136 | glXDestroyContext(display(), ctx); | 136 | glXDestroyContext(display(), ctx); | ||
137 | 137 | | |||
138 | if (glxWindow) | 138 | if (glxWindow) | ||
139 | glXDestroyWindow(display(), glxWindow); | 139 | glXDestroyWindow(display(), glxWindow); | ||
140 | 140 | | |||
141 | if (window) | 141 | if (window) | ||
▲ Show 20 Lines • Show All 113 Lines • ▼ Show 20 Line(s) | |||||
255 | { | 255 | { | ||
256 | const QByteArray string = (const char *) glXQueryExtensionsString(display(), QX11Info::appScreen()); | 256 | const QByteArray string = (const char *) glXQueryExtensionsString(display(), QX11Info::appScreen()); | ||
257 | setExtensions(string.split(' ')); | 257 | setExtensions(string.split(' ')); | ||
258 | } | 258 | } | ||
259 | 259 | | |||
260 | bool GlxBackend::initRenderingContext() | 260 | bool GlxBackend::initRenderingContext() | ||
261 | { | 261 | { | ||
262 | const bool direct = true; | 262 | const bool direct = true; | ||
263 | bool usingSharedContext = false; | ||||
263 | 264 | | |||
264 | // Use glXCreateContextAttribsARB() when it's available | 265 | // Use glXCreateContextAttribsARB() when it's available | ||
265 | if (hasExtension(QByteArrayLiteral("GLX_ARB_create_context"))) { | 266 | if (hasExtension(QByteArrayLiteral("GLX_ARB_create_context"))) { | ||
266 | const bool have_robustness = hasExtension(QByteArrayLiteral("GLX_ARB_create_context_robustness")); | 267 | const bool have_robustness = hasExtension(QByteArrayLiteral("GLX_ARB_create_context_robustness")); | ||
267 | const bool haveVideoMemoryPurge = hasExtension(QByteArrayLiteral("GLX_NV_robustness_video_memory_purge")); | 268 | const bool haveVideoMemoryPurge = hasExtension(QByteArrayLiteral("GLX_NV_robustness_video_memory_purge")); | ||
268 | 269 | | |||
269 | std::vector<GlxContextAttributeBuilder> candidates; | 270 | std::vector<GlxContextAttributeBuilder> candidates; | ||
270 | if (options->glCoreProfile()) { | 271 | if (options->glCoreProfile()) { | ||
Show All 26 Lines | 289 | if (have_robustness) { | |||
297 | candidates.emplace_back(std::move(robustLegacy)); | 298 | candidates.emplace_back(std::move(robustLegacy)); | ||
298 | } | 299 | } | ||
299 | GlxContextAttributeBuilder legacy; | 300 | GlxContextAttributeBuilder legacy; | ||
300 | legacy.setVersion(2, 1); | 301 | legacy.setVersion(2, 1); | ||
301 | candidates.emplace_back(std::move(legacy)); | 302 | candidates.emplace_back(std::move(legacy)); | ||
302 | } | 303 | } | ||
303 | for (auto it = candidates.begin(); it != candidates.end(); it++) { | 304 | for (auto it = candidates.begin(); it != candidates.end(); it++) { | ||
304 | const auto attribs = it->build(); | 305 | const auto attribs = it->build(); | ||
305 | ctx = glXCreateContextAttribsARB(display(), fbconfig, nullptr, true, attribs.data()); | 306 | | ||
307 | auto share = QOpenGLContext::globalShareContext(); | ||||
308 | GLXContext shareHandle = nullptr; | ||||
309 | if (QOpenGLContext::globalShareContext()) { | ||||
310 | shareHandle = QOpenGLContext::globalShareContext()->nativeHandle().value<QGLXNativeContext>().context(); | ||||
311 | } | ||||
312 | ctx = glXCreateContextAttribsARB(display(), fbconfig, shareHandle, true, attribs.data()); | ||||
306 | if (ctx) { | 313 | if (ctx) { | ||
307 | qCDebug(KWIN_X11STANDALONE) << "Created GLX context with attributes:" << &(*it); | 314 | qCDebug(KWIN_X11STANDALONE) << "Created GLX context with attributes:" << &(*it); | ||
315 | usingSharedContext = shareHandle != nullptr; | ||||
308 | break; | 316 | break; | ||
309 | } | 317 | } | ||
310 | } | 318 | } | ||
311 | } | 319 | } | ||
312 | 320 | | |||
313 | if (!ctx) | 321 | if (!ctx) | ||
314 | ctx = glXCreateNewContext(display(), fbconfig, GLX_RGBA_TYPE, nullptr, direct); | 322 | ctx = glXCreateNewContext(display(), fbconfig, GLX_RGBA_TYPE, nullptr, direct); | ||
315 | 323 | | |||
316 | if (!ctx) { | 324 | if (!ctx) { | ||
317 | qCDebug(KWIN_X11STANDALONE) << "Failed to create an OpenGL context."; | 325 | qCDebug(KWIN_X11STANDALONE) << "Failed to create an OpenGL context."; | ||
318 | return false; | 326 | return false; | ||
319 | } | 327 | } | ||
320 | 328 | | |||
321 | if (!glXMakeCurrent(display(), glxWindow, ctx)) { | 329 | if (!glXMakeCurrent(display(), glxWindow, ctx)) { | ||
322 | qCDebug(KWIN_X11STANDALONE) << "Failed to make the OpenGL context current."; | 330 | qCDebug(KWIN_X11STANDALONE) << "Failed to make the OpenGL context current."; | ||
323 | glXDestroyContext(display(), ctx); | 331 | glXDestroyContext(display(), ctx); | ||
romangg: Would we here destroy Qt's context as well? In general what happens when compositing is… | |||||
324 | ctx = nullptr; | 332 | ctx = nullptr; | ||
325 | return false; | 333 | return false; | ||
326 | } | 334 | } | ||
327 | 335 | | |||
328 | auto qtContext = new QOpenGLContext; | 336 | EffectQuickView::setUsingShareContexts(usingSharedContext); | ||
329 | QGLXNativeContext native(ctx, display()); | | |||
330 | qtContext->setNativeHandle(QVariant::fromValue(native)); | | |||
331 | qtContext->create(); | | |||
332 | EffectQuickView::setShareContext(std::unique_ptr<QOpenGLContext>(qtContext)); | | |||
333 | 337 | | |||
334 | return true; | 338 | return true; | ||
335 | } | 339 | } | ||
336 | 340 | | |||
337 | bool GlxBackend::initBuffer() | 341 | bool GlxBackend::initBuffer() | ||
338 | { | 342 | { | ||
339 | if (!initFbConfig()) | 343 | if (!initFbConfig()) | ||
340 | return false; | 344 | return false; | ||
▲ Show 20 Lines • Show All 532 Lines • Show Last 20 Lines |
Would we here destroy Qt's context as well? In general what happens when compositing is switched off, does the Qt context just continue to exist without issues?