MCPcopy Create free account
hub / github.com/SFML/SFML / selectBestVisual

Method selectBestVisual

src/SFML/Window/EglContext.cpp:371–412  ·  view source on GitHub ↗

///////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

369#if defined(SFML_SYSTEM_LINUX) && !defined(SFML_USE_DRM)
370////////////////////////////////////////////////////////////
371XVisualInfo EglContext::selectBestVisual(::Display* xDisplay, unsigned int bitsPerPixel, const ContextSettings& settings)
372{
373 EglContextImpl::ensureInit();
374
375 // Get the initialized EGL display
376 EGLDisplay display = EglContextImpl::getInitializedDisplay();
377
378 // Get the best EGL config matching the default video settings
379 EGLConfig config = getBestConfig(display, bitsPerPixel, settings);
380
381 // Retrieve the visual id associated with this EGL config
382 EGLint nativeVisualId = 0;
383
384 eglCheck(eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &nativeVisualId));
385
386 if (nativeVisualId == 0)
387 {
388 // Should never happen...
389 err() << "No EGL visual found. You should check your graphics driver" << std::endl;
390
391 return {};
392 }
393
394 XVisualInfo vTemplate;
395 vTemplate.visualid = static_cast<VisualID>(nativeVisualId);
396
397 // Get X11 visuals compatible with this EGL config
398 int visualCount = 0;
399 // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays)
400 const auto availableVisuals = X11Ptr<XVisualInfo[]>(XGetVisualInfo(xDisplay, VisualIDMask, &vTemplate, &visualCount));
401
402 if (visualCount == 0)
403 {
404 // Can't happen...
405 err() << "No X11 visual found. Bug in your EGL implementation ?" << std::endl;
406
407 return {};
408 }
409
410 // Pick up the best one
411 return availableVisuals[0];
412}
413#endif
414
415} // namespace sf::priv

Callers

nothing calls this directly

Calls 2

ensureInitFunction · 0.70
getInitializedDisplayFunction · 0.70

Tested by

no test coverage detected