diff options
| author | Kaido Kert <kaidokert@gmail.com> | 2024-11-29 04:47:25 +0000 |
|---|---|---|
| committer | Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> | 2024-12-09 12:35:38 +0200 |
| commit | aaab406251540429522c5ef7808ee049c65a06d2 (patch) | |
| tree | 65b6681f3dab077e5341d9cb386f2e71220d12af /kmscube/cube-egl.cpp | |
| parent | 6cf6e88715ac034f568603bce9a1b8f4a30c12ce (diff) | |
Implement native visual matching
Implement matching GBM buffer format to EGL NATIVE_VISUAL_ID.
eglChooseConfig cannot match on NATIVE_VISUAL_ID, but GBM/EGL
requires matching formats. Similar logic is implemented in
kmscube code in match_config_to_visual.
X11, Wayland and Null cube demos remain unchanged.
Tested on Raspi-4 and VirtualBox/Ubuntu
Diffstat (limited to 'kmscube/cube-egl.cpp')
| -rw-r--r-- | kmscube/cube-egl.cpp | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/kmscube/cube-egl.cpp b/kmscube/cube-egl.cpp index 9551793..372c978 100644 --- a/kmscube/cube-egl.cpp +++ b/kmscube/cube-egl.cpp @@ -22,7 +22,10 @@ static void print_egl_config(EGLDisplay dpy, EGLConfig cfg) getconf(EGL_NATIVE_VISUAL_TYPE)); } -EglState::EglState(void* native_display) +EglState::EglState(void* native_display) : EglState(native_display, 0) {} + +EglState::EglState(void* native_display, EGLint native_visual_id) + : m_native_visual_id(native_visual_id) { EGLBoolean b; EGLint major, minor, n; @@ -60,11 +63,11 @@ EglState::EglState(void* native_display) b = eglBindAPI(EGL_OPENGL_ES_API); FAIL_IF(!b, "failed to bind api EGL_OPENGL_ES_API"); - if (s_verbose) { - EGLint numConfigs; - b = eglGetConfigs(m_display, nullptr, 0, &numConfigs); - FAIL_IF(!b, "failed to get number of configs"); + EGLint numConfigs; + b = eglGetConfigs(m_display, nullptr, 0, &numConfigs); + FAIL_IF(!b, "failed to get number of configs"); + if (s_verbose) { EGLConfig configs[numConfigs]; b = eglGetConfigs(m_display, configs, numConfigs, &numConfigs); FAIL_IF(!b, "failed to get configs"); @@ -75,8 +78,25 @@ EglState::EglState(void* native_display) print_egl_config(m_display, configs[i]); } - b = eglChooseConfig(m_display, config_attribs, &m_config, 1, &n); - FAIL_IF(!b || n != 1, "failed to choose config"); + std::vector<EGLConfig> configs(numConfigs); + b = eglChooseConfig(m_display, config_attribs, configs.data(), numConfigs, &n); + FAIL_IF(!b || n < 1, "failed to choose config"); + + // elgChooseConfig does implement matching by EGL_NATIVE_VISUAL_ID, do a manual + // loop. Picks the first returned if native_visual_id is not set. + for (const auto& config : configs) { + EGLint id; + b = eglGetConfigAttrib(m_display, config, EGL_NATIVE_VISUAL_ID, &id); + if (!b) { + printf("failed to get native visual id\n"); + continue; + } + + if (id == native_visual_id || !native_visual_id) { + m_config = config; + break; + } + } if (s_verbose) { printf("Chosen config:\n"); |
