Changeset View
Changeset View
Standalone View
Standalone View
plugins/platforms/x11/standalone/glxbackend.cpp
Show All 19 Lines | |||||
20 | 20 | | |||
21 | You should have received a copy of the GNU General Public License | 21 | You should have received a copy of the GNU General Public License | ||
22 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 22 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
23 | *********************************************************************/ | 23 | *********************************************************************/ | ||
24 | 24 | | |||
25 | // own | 25 | // own | ||
26 | #include "glxbackend.h" | 26 | #include "glxbackend.h" | ||
27 | #include "logging.h" | 27 | #include "logging.h" | ||
28 | #include "glx_context_attribute_builder.h" | ||||
28 | // kwin | 29 | // kwin | ||
29 | #include "options.h" | 30 | #include "options.h" | ||
30 | #include "overlaywindow.h" | 31 | #include "overlaywindow.h" | ||
31 | #include "composite.h" | 32 | #include "composite.h" | ||
32 | #include "platform.h" | 33 | #include "platform.h" | ||
33 | #include "screens.h" | 34 | #include "screens.h" | ||
34 | #include "xcbutils.h" | 35 | #include "xcbutils.h" | ||
35 | // kwin libs | 36 | // kwin libs | ||
Show All 24 Lines | 54 | typedef struct xcb_glx_buffer_swap_complete_event_t { | |||
60 | uint32_t ust_hi; /**< */ | 61 | uint32_t ust_hi; /**< */ | ||
61 | uint32_t ust_lo; /**< */ | 62 | uint32_t ust_lo; /**< */ | ||
62 | uint32_t msc_hi; /**< */ | 63 | uint32_t msc_hi; /**< */ | ||
63 | uint32_t msc_lo; /**< */ | 64 | uint32_t msc_lo; /**< */ | ||
64 | uint32_t sbc; /**< */ | 65 | uint32_t sbc; /**< */ | ||
65 | } xcb_glx_buffer_swap_complete_event_t; | 66 | } xcb_glx_buffer_swap_complete_event_t; | ||
66 | #endif | 67 | #endif | ||
67 | 68 | | |||
68 | #ifndef GLX_GENERATE_RESET_ON_VIDEO_MEMORY_PURGE_NV | | |||
69 | #define GLX_GENERATE_RESET_ON_VIDEO_MEMORY_PURGE_NV 0x20F7 | | |||
70 | #endif | | |||
71 | | ||||
72 | #include <tuple> | 69 | #include <tuple> | ||
73 | #include <memory> | 70 | #include <memory> | ||
74 | 71 | | |||
75 | namespace KWin | 72 | namespace KWin | ||
76 | { | 73 | { | ||
77 | 74 | | |||
78 | SwapEventFilter::SwapEventFilter(xcb_drawable_t drawable, xcb_glx_drawable_t glxDrawable) | 75 | SwapEventFilter::SwapEventFilter(xcb_drawable_t drawable, xcb_glx_drawable_t glxDrawable) | ||
79 | : X11EventFilter(Xcb::Extensions::self()->glxEventBase() + XCB_GLX_BUFFER_SWAP_COMPLETE), | 76 | : X11EventFilter(Xcb::Extensions::self()->glxEventBase() + XCB_GLX_BUFFER_SWAP_COMPLETE), | ||
▲ Show 20 Lines • Show All 203 Lines • ▼ Show 20 Line(s) | |||||
283 | } | 280 | } | ||
284 | 281 | | |||
285 | bool GlxBackend::initRenderingContext() | 282 | bool GlxBackend::initRenderingContext() | ||
286 | { | 283 | { | ||
287 | const bool direct = true; | 284 | const bool direct = true; | ||
288 | 285 | | |||
289 | // Use glXCreateContextAttribsARB() when it's available | 286 | // Use glXCreateContextAttribsARB() when it's available | ||
290 | if (hasExtension(QByteArrayLiteral("GLX_ARB_create_context"))) { | 287 | if (hasExtension(QByteArrayLiteral("GLX_ARB_create_context"))) { | ||
291 | const int attribs_31_core_nv_robustness[] = { | | |||
292 | GLX_CONTEXT_MAJOR_VERSION_ARB, 3, | | |||
293 | GLX_CONTEXT_MINOR_VERSION_ARB, 1, | | |||
294 | GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB, | | |||
295 | GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, GLX_LOSE_CONTEXT_ON_RESET_ARB, | | |||
296 | GLX_GENERATE_RESET_ON_VIDEO_MEMORY_PURGE_NV, GL_TRUE, | | |||
297 | 0 | | |||
298 | }; | | |||
299 | | ||||
300 | const int attribs_31_core_robustness[] = { | | |||
301 | GLX_CONTEXT_MAJOR_VERSION_ARB, 3, | | |||
302 | GLX_CONTEXT_MINOR_VERSION_ARB, 1, | | |||
303 | GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB, | | |||
304 | GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, GLX_LOSE_CONTEXT_ON_RESET_ARB, | | |||
305 | 0 | | |||
306 | }; | | |||
307 | | ||||
308 | const int attribs_31_core[] = { | | |||
309 | GLX_CONTEXT_MAJOR_VERSION_ARB, 3, | | |||
310 | GLX_CONTEXT_MINOR_VERSION_ARB, 1, | | |||
311 | 0 | | |||
312 | }; | | |||
313 | | ||||
314 | const int attribs_legacy_nv_robustness[] = { | | |||
315 | GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB, | | |||
316 | GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, GLX_LOSE_CONTEXT_ON_RESET_ARB, | | |||
317 | GLX_GENERATE_RESET_ON_VIDEO_MEMORY_PURGE_NV, GL_TRUE, | | |||
318 | 0 | | |||
319 | }; | | |||
320 | | ||||
321 | const int attribs_legacy_robustness[] = { | | |||
322 | GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB, | | |||
323 | GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, GLX_LOSE_CONTEXT_ON_RESET_ARB, | | |||
324 | 0 | | |||
325 | }; | | |||
326 | | ||||
327 | const int attribs_legacy[] = { | | |||
328 | GLX_CONTEXT_MAJOR_VERSION_ARB, 2, | | |||
329 | GLX_CONTEXT_MINOR_VERSION_ARB, 1, | | |||
330 | 0 | | |||
331 | }; | | |||
332 | | ||||
333 | const bool have_robustness = hasExtension(QByteArrayLiteral("GLX_ARB_create_context_robustness")); | 288 | const bool have_robustness = hasExtension(QByteArrayLiteral("GLX_ARB_create_context_robustness")); | ||
334 | const bool haveVideoMemoryPurge = hasExtension(QByteArrayLiteral("GLX_NV_robustness_video_memory_purge")); | 289 | const bool haveVideoMemoryPurge = hasExtension(QByteArrayLiteral("GLX_NV_robustness_video_memory_purge")); | ||
335 | 290 | | |||
336 | // Try to create a 3.1 context first | 291 | std::vector<GlxContextAttributeBuilder> candidates; | ||
337 | if (options->glCoreProfile()) { | 292 | if (options->glCoreProfile()) { | ||
338 | if (have_robustness) { | 293 | if (have_robustness) { | ||
339 | if (haveVideoMemoryPurge) { | 294 | if (haveVideoMemoryPurge) { | ||
340 | ctx = glXCreateContextAttribsARB(display(), fbconfig, 0, direct, attribs_31_core_nv_robustness); | 295 | GlxContextAttributeBuilder purgeMemoryCore; | ||
341 | } | 296 | purgeMemoryCore.setVersion(3, 1); | ||
342 | if (!ctx) { | 297 | purgeMemoryCore.setRobust(true); | ||
343 | ctx = glXCreateContextAttribsARB(display(), fbconfig, 0, direct, attribs_31_core_robustness); | 298 | purgeMemoryCore.setResetOnVideoMemoryPurge(true); | ||
344 | } | 299 | candidates.emplace_back(std::move(purgeMemoryCore)); | ||
345 | } | 300 | } | ||
346 | 301 | GlxContextAttributeBuilder robustCore; | |||
347 | if (!ctx) | 302 | robustCore.setVersion(3, 1); | ||
348 | ctx = glXCreateContextAttribsARB(display(), fbconfig, 0, direct, attribs_31_core); | 303 | robustCore.setRobust(true); | ||
349 | } | 304 | candidates.emplace_back(std::move(robustCore)); | ||
350 | 305 | } | |||
351 | if (!ctx && have_robustness) { | 306 | GlxContextAttributeBuilder core; | ||
307 | core.setVersion(3, 1); | ||||
308 | candidates.emplace_back(std::move(core)); | ||||
309 | } else { | ||||
310 | if (have_robustness) { | ||||
352 | if (haveVideoMemoryPurge) { | 311 | if (haveVideoMemoryPurge) { | ||
353 | ctx = glXCreateContextAttribsARB(display(), fbconfig, 0, direct, attribs_legacy_nv_robustness); | 312 | GlxContextAttributeBuilder purgeMemoryLegacy; | ||
354 | } | 313 | purgeMemoryLegacy.setRobust(true); | ||
355 | if (!ctx) { | 314 | purgeMemoryLegacy.setResetOnVideoMemoryPurge(true); | ||
356 | ctx = glXCreateContextAttribsARB(display(), fbconfig, 0, direct, attribs_legacy_robustness); | 315 | candidates.emplace_back(std::move(purgeMemoryLegacy)); | ||
316 | } | ||||
317 | GlxContextAttributeBuilder robustLegacy; | ||||
318 | robustLegacy.setRobust(true); | ||||
319 | candidates.emplace_back(std::move(robustLegacy)); | ||||
320 | } | ||||
321 | GlxContextAttributeBuilder legacy; | ||||
322 | legacy.setVersion(2, 1); | ||||
323 | candidates.emplace_back(std::move(legacy)); | ||||
324 | } | ||||
325 | for (auto it = candidates.begin(); it != candidates.end(); it++) { | ||||
326 | const auto attribs = it->build(); | ||||
327 | ctx = glXCreateContextAttribsARB(display(), fbconfig, 0, true, attribs.data()); | ||||
328 | if (ctx) { | ||||
329 | qCDebug(KWIN_X11STANDALONE) << "Created GLX context with attributes:" << &(*it); | ||||
330 | break; | ||||
357 | } | 331 | } | ||
358 | } | 332 | } | ||
359 | | ||||
360 | if (!ctx) | | |||
361 | ctx = glXCreateContextAttribsARB(display(), fbconfig, 0, direct, attribs_legacy); | | |||
362 | } | 333 | } | ||
363 | 334 | | |||
364 | if (!ctx) | 335 | if (!ctx) | ||
365 | ctx = glXCreateNewContext(display(), fbconfig, GLX_RGBA_TYPE, NULL, direct); | 336 | ctx = glXCreateNewContext(display(), fbconfig, GLX_RGBA_TYPE, NULL, direct); | ||
366 | 337 | | |||
367 | if (!ctx) { | 338 | if (!ctx) { | ||
368 | qCDebug(KWIN_X11STANDALONE) << "Failed to create an OpenGL context."; | 339 | qCDebug(KWIN_X11STANDALONE) << "Failed to create an OpenGL context."; | ||
369 | return false; | 340 | return false; | ||
▲ Show 20 Lines • Show All 591 Lines • Show Last 20 Lines |