f2195dddc451033fba687abfcdeacac46c4a8868
[AGL/meta-agl.git] /
1 From 372b9c4edd42b67827b75863b978091ba5cff5cd Mon Sep 17 00:00:00 2001
2 From: Marius Vlad <marius.vlad@collabora.com>
3 Date: Thu, 17 Oct 2024 17:25:41 +0300
4 Subject: [PATCH 1/2] backend/wayland_egl: Add a fallback eglConfig
5
6 This seems to aid flutter-auto at displaying an image on agl-rdp
7 with software rendering, and on agl-kvm with virgl.  Makes uses of a fallback
8 eGLConfig (< 24 bit) and tries to use that one rather than the default one (24-bit).
9
10 Bug-AGL: SPEC-5260
11 Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
12 ---
13  cmake/config_common.h.in         | 17 ++++++++++++++++-
14  shell/backend/wayland_egl/egl.cc | 23 ++++++++++++++++++++---
15  2 files changed, 36 insertions(+), 4 deletions(-)
16
17 diff --git a/cmake/config_common.h.in b/cmake/config_common.h.in
18 index 07ce9b7..2c54c67 100644
19 --- a/cmake/config_common.h.in
20 +++ b/cmake/config_common.h.in
21 @@ -155,6 +155,21 @@ static constexpr std::array<EGLint, 27> kEglConfigAttribs = {{
22      // clang-format on
23  }};
24  
25 +
26 +static constexpr std::array<EGLint, 27> kEglConfigAttribsFallBack = {{
27 +    // clang-format off
28 +    EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
29 +    EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
30 +
31 +    EGL_RED_SIZE, 1,
32 +    EGL_GREEN_SIZE, 1,
33 +    EGL_BLUE_SIZE, 1,
34 +    EGL_ALPHA_SIZE, 2,
35 +    EGL_NONE // termination sentinel
36 +    // clang-format on
37 +}};
38 +
39 +
40  // All vkCreate* functions take an optional allocator. For now, we select the
41  // default allocator by passing in a null pointer, and we highlight the argument
42  // by using the VKALLOC constant.
43 @@ -181,4 +196,4 @@ constexpr struct VkAllocationCallbacks* VKALLOC = nullptr;
44  #cmakedefine01 ENV32BIT
45  #cmakedefine01 ENV64BIT
46  
47 -#endif //CONFIG_COMMON_H_
48 \ No newline at end of file
49 +#endif //CONFIG_COMMON_H_
50 diff --git a/shell/backend/wayland_egl/egl.cc b/shell/backend/wayland_egl/egl.cc
51 index 99555d6..70164ba 100644
52 --- a/shell/backend/wayland_egl/egl.cc
53 +++ b/shell/backend/wayland_egl/egl.cc
54 @@ -62,11 +62,28 @@ Egl::Egl(void* native_display, int buffer_size, bool debug)
55        break;
56      }
57    }
58 -  free(configs);
59    if (m_config == nullptr) {
60 -    spdlog::critical("did not find config with buffer size {}", m_buffer_size);
61 -    assert(false);
62 +    // try with the fallback one
63 +    spdlog::critical("Could not use default EGLConfig trying with fallback.");
64 +    ret = eglChooseConfig(m_dpy, kEglConfigAttribsFallBack.data(), configs,
65 +                          count, &n);
66 +    assert(ret && n >= 1);
67 +
68 +    for (EGLint i = 0; i < n; i++) {
69 +      eglGetConfigAttrib(m_dpy, configs[i], EGL_BUFFER_SIZE, &size);
70 +      SPDLOG_DEBUG("Buffer size for config {} is {}", i, size);
71 +      if (m_buffer_size <= size) {
72 +        memcpy(&m_config, &configs[i], sizeof(EGLConfig));
73 +        break;
74 +      }
75 +    }
76 +    if (m_config == nullptr) {
77 +      spdlog::critical("did not find config with buffer size {}",
78 +                       m_buffer_size);
79 +      assert(false);
80 +    }
81    }
82 +  free(configs);
83  
84    m_context = eglCreateContext(m_dpy, m_config, EGL_NO_CONTEXT,
85                                 kEglContextAttribs.data());
86 -- 
87 2.43.0
88