From 94ac8d235bcb75a53593d3f3b69c9f10a44557e8 Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Mon, 20 Mar 2023 16:55:49 +0100 Subject: [PATCH] platformsupport: remove initBufferConfigs Instead, rely on EGL_KHR_no_config_context everywhere except the standalone x11 backend --- src/backends/drm/drm_egl_backend.cpp | 10 +++--- src/backends/drm/drm_egl_backend.h | 2 +- src/backends/virtual/virtual_egl_backend.cpp | 6 +--- src/backends/wayland/wayland_egl_backend.cpp | 2 +- .../standalone/x11_standalone_egl_backend.cpp | 4 +-- .../standalone/x11_standalone_egl_backend.h | 2 +- .../x11/windowed/x11_windowed_egl_backend.cpp | 2 +- .../scenes/opengl/abstract_egl_backend.cpp | 33 ------------------- .../scenes/opengl/abstract_egl_backend.h | 1 - 9 files changed, 12 insertions(+), 50 deletions(-) diff --git a/src/backends/drm/drm_egl_backend.cpp b/src/backends/drm/drm_egl_backend.cpp index 62c35ead82..6aca35dfde 100644 --- a/src/backends/drm/drm_egl_backend.cpp +++ b/src/backends/drm/drm_egl_backend.cpp @@ -107,10 +107,10 @@ void EglGbmBackend::init() bool EglGbmBackend::initRenderingContext() { - return createContext(initBufferConfigs()) && makeCurrent(); + return initBufferConfigs() && createContext(EGL_NO_CONFIG_KHR) && makeCurrent(); } -EGLConfig EglGbmBackend::initBufferConfigs() +bool EglGbmBackend::initBufferConfigs() { const EGLint config_attribs[] = { EGL_SURFACE_TYPE, @@ -136,7 +136,7 @@ EGLConfig EglGbmBackend::initBufferConfigs() sizeof(configs) / sizeof(EGLConfig), &count)) { qCCritical(KWIN_DRM) << "eglChooseConfig failed:" << getEglErrorString(); - return EGL_NO_CONFIG_KHR; + return false; } // Loop through all configs, choosing the first one that has suitable format. @@ -159,7 +159,7 @@ EGLConfig EglGbmBackend::initBufferConfigs() m_formats[gbmFormat] = format; } if (!m_formats.isEmpty()) { - return EGL_NO_CONFIG_KHR; + return true; } qCCritical(KWIN_DRM, "Choosing EGL config did not return a supported config. There were %u configs", count); @@ -174,7 +174,7 @@ EGLConfig EglGbmBackend::initBufferConfigs() gbm_format_get_name(gbmFormat, &name); qCCritical(KWIN_DRM, "EGL config %d has format %s with %d,%d,%d,%d bits for r,g,b,a", i, name.name, redSize, greenSize, blueSize, alphaSize); } - return EGL_NO_CONFIG_KHR; + return false; } std::unique_ptr EglGbmBackend::createSurfaceTextureInternal(SurfacePixmapInternal *pixmap) diff --git a/src/backends/drm/drm_egl_backend.h b/src/backends/drm/drm_egl_backend.h index 4c9e4f81fc..6c361aec84 100644 --- a/src/backends/drm/drm_egl_backend.h +++ b/src/backends/drm/drm_egl_backend.h @@ -82,7 +82,7 @@ public: private: bool initializeEgl(); - EGLConfig initBufferConfigs() override; + bool initBufferConfigs(); bool initRenderingContext(); DrmBackend *m_backend; diff --git a/src/backends/virtual/virtual_egl_backend.cpp b/src/backends/virtual/virtual_egl_backend.cpp index fbed701810..d19d18073e 100644 --- a/src/backends/virtual/virtual_egl_backend.cpp +++ b/src/backends/virtual/virtual_egl_backend.cpp @@ -137,11 +137,7 @@ void VirtualEglBackend::init() bool VirtualEglBackend::initRenderingContext() { - if (!createContext(initBufferConfigs())) { - return false; - } - - return makeCurrent(); + return createContext(EGL_NO_CONFIG_KHR) && makeCurrent(); } void VirtualEglBackend::addOutput(Output *output) diff --git a/src/backends/wayland/wayland_egl_backend.cpp b/src/backends/wayland/wayland_egl_backend.cpp index 583e06f5dc..f22fa4dad5 100644 --- a/src/backends/wayland/wayland_egl_backend.cpp +++ b/src/backends/wayland/wayland_egl_backend.cpp @@ -382,7 +382,7 @@ void WaylandEglBackend::init() bool WaylandEglBackend::initRenderingContext() { - if (!createContext(initBufferConfigs())) { + if (!createContext(EGL_NO_CONFIG_KHR)) { return false; } diff --git a/src/backends/x11/standalone/x11_standalone_egl_backend.cpp b/src/backends/x11/standalone/x11_standalone_egl_backend.cpp index 0837d0b46b..d04a4c8d75 100644 --- a/src/backends/x11/standalone/x11_standalone_egl_backend.cpp +++ b/src/backends/x11/standalone/x11_standalone_egl_backend.cpp @@ -199,7 +199,7 @@ bool EglBackend::initRenderingContext() setEglDisplay(display); - if (!createContext(initBufferConfigs())) { + if (!createContext(chooseBufferConfig())) { qCCritical(KWIN_CORE) << "Create OpenGL context failed"; return false; } @@ -256,7 +256,7 @@ EGLSurface EglBackend::createSurface(xcb_window_t window) return surface; } -EGLConfig EglBackend::initBufferConfigs() +EGLConfig EglBackend::chooseBufferConfig() { const EGLint config_attribs[] = { EGL_SURFACE_TYPE, diff --git a/src/backends/x11/standalone/x11_standalone_egl_backend.h b/src/backends/x11/standalone/x11_standalone_egl_backend.h index 76ce0044e6..09b65f1e2d 100644 --- a/src/backends/x11/standalone/x11_standalone_egl_backend.h +++ b/src/backends/x11/standalone/x11_standalone_egl_backend.h @@ -53,7 +53,7 @@ public: OutputLayer *primaryLayer(Output *output) override; protected: - EGLConfig initBufferConfigs() override; + EGLConfig chooseBufferConfig(); bool initRenderingContext(); private: diff --git a/src/backends/x11/windowed/x11_windowed_egl_backend.cpp b/src/backends/x11/windowed/x11_windowed_egl_backend.cpp index fab1859931..09994406be 100644 --- a/src/backends/x11/windowed/x11_windowed_egl_backend.cpp +++ b/src/backends/x11/windowed/x11_windowed_egl_backend.cpp @@ -305,7 +305,7 @@ bool X11WindowedEglBackend::initializeEgl() bool X11WindowedEglBackend::initRenderingContext() { - if (!createContext(initBufferConfigs())) { + if (!createContext(EGL_NO_CONFIG_KHR)) { return false; } diff --git a/src/platformsupport/scenes/opengl/abstract_egl_backend.cpp b/src/platformsupport/scenes/opengl/abstract_egl_backend.cpp index 365b99df59..575526fa30 100644 --- a/src/platformsupport/scenes/opengl/abstract_egl_backend.cpp +++ b/src/platformsupport/scenes/opengl/abstract_egl_backend.cpp @@ -356,39 +356,6 @@ QHash> AbstractEglBackend::supportedFormats() const return m_supportedFormats; } -EGLConfig AbstractEglBackend::initBufferConfigs() -{ - const EGLint config_attribs[] = { - EGL_SURFACE_TYPE, - EGL_WINDOW_BIT, - EGL_RED_SIZE, - 1, - EGL_GREEN_SIZE, - 1, - EGL_BLUE_SIZE, - 1, - EGL_ALPHA_SIZE, - 0, - EGL_RENDERABLE_TYPE, - isOpenGLES() ? EGL_OPENGL_ES2_BIT : EGL_OPENGL_BIT, - EGL_CONFIG_CAVEAT, - EGL_NONE, - EGL_NONE, - }; - - EGLint count; - EGLConfig configs[1024]; - if (eglChooseConfig(eglDisplay(), config_attribs, configs, 1, &count) == EGL_FALSE) { - qCCritical(KWIN_OPENGL) << "choose config failed"; - return EGL_NO_CONFIG_KHR; - } - if (count != 1) { - qCCritical(KWIN_OPENGL) << "choose config did not return a config" << count; - return EGL_NO_CONFIG_KHR; - } - return configs[0]; -} - ::EGLDisplay AbstractEglBackend::eglDisplay() const { return m_display->handle(); diff --git a/src/platformsupport/scenes/opengl/abstract_egl_backend.h b/src/platformsupport/scenes/opengl/abstract_egl_backend.h index 9727639b15..cafcc15fd6 100644 --- a/src/platformsupport/scenes/opengl/abstract_egl_backend.h +++ b/src/platformsupport/scenes/opengl/abstract_egl_backend.h @@ -77,7 +77,6 @@ protected: bool hasClientExtension(const QByteArray &ext) const; bool isOpenGLES() const; bool createContext(EGLConfig config); - virtual EGLConfig initBufferConfigs(); private: bool ensureGlobalShareContext(EGLConfig config);