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