diff --git a/plugins/platforms/drm/egl_gbm_backend.cpp b/plugins/platforms/drm/egl_gbm_backend.cpp --- a/plugins/platforms/drm/egl_gbm_backend.cpp +++ b/plugins/platforms/drm/egl_gbm_backend.cpp @@ -176,7 +176,18 @@ qCCritical(KWIN_DRM) << "Create gbm surface failed"; return false; } - auto eglSurface = eglCreatePlatformWindowSurfaceEXT(eglDisplay(), config(), (void *)(gbmSurface->surface()), nullptr); + + const int attr[] = { + EGL_GL_COLORSPACE, EGL_GL_COLORSPACE_SRGB, + EGL_NONE + }; + + const bool hasEglColorspace = epoxy_egl_version(eglDisplay()) >= 15 || + hasExtension(QByteArrayLiteral("EGL_KHR_gl_colorspace")); + + auto eglSurface = eglCreatePlatformWindowSurfaceEXT(eglDisplay(), config(), + (void *)(gbmSurface->surface()), + !isOpenGLES() && hasEglColorspace ? attr : nullptr); if (eglSurface == EGL_NO_SURFACE) { qCCritical(KWIN_DRM) << "Create Window Surface failed"; return false; diff --git a/plugins/platforms/hwcomposer/egl_hwcomposer_backend.cpp b/plugins/platforms/hwcomposer/egl_hwcomposer_backend.cpp --- a/plugins/platforms/hwcomposer/egl_hwcomposer_backend.cpp +++ b/plugins/platforms/hwcomposer/egl_hwcomposer_backend.cpp @@ -107,8 +107,18 @@ return false; } + const int attr[] = { + EGL_GL_COLORSPACE, EGL_GL_COLORSPACE_SRGB, + EGL_NONE + }; + + const bool hasEglColorspace = epoxy_egl_version(eglDisplay()) >= 15 || + hasExtension(QByteArrayLiteral("EGL_KHR_gl_colorspace")); + m_nativeSurface = m_backend->createSurface(); - EGLSurface surface = eglCreateWindowSurface(eglDisplay(), config(), (EGLNativeWindowType)static_cast(m_nativeSurface), nullptr); + EGLSurface surface = eglCreateWindowSurface(eglDisplay(), config(), + (EGLNativeWindowType)static_cast(m_nativeSurface), + !isOpenGLES() && hasEglColorspace ? attr : nullptr); if (surface == EGL_NO_SURFACE) { qCCritical(KWIN_HWCOMPOSER) << "Create surface failed"; return false; diff --git a/plugins/platforms/wayland/egl_wayland_backend.cpp b/plugins/platforms/wayland/egl_wayland_backend.cpp --- a/plugins/platforms/wayland/egl_wayland_backend.cpp +++ b/plugins/platforms/wayland/egl_wayland_backend.cpp @@ -65,11 +65,25 @@ } m_overlay = overlay; + const int attr[] = { + EGL_GL_COLORSPACE, EGL_GL_COLORSPACE_SRGB, + EGL_NONE + }; + + const bool hasEglColorspace = epoxy_egl_version(backend->eglDisplay()) >= 15 || + backend->hasExtension(QByteArrayLiteral("EGL_KHR_gl_colorspace")); + + + EGLint clientType = EGL_NONE; + eglQueryContext(backend->eglDisplay(), backend->context(), EGL_CONTEXT_CLIENT_TYPE, &clientType); + EGLSurface eglSurface = EGL_NO_SURFACE; if (backend->havePlatformBase()) { - eglSurface = eglCreatePlatformWindowSurfaceEXT(backend->eglDisplay(), backend->config(), (void *) overlay, nullptr); + eglSurface = eglCreatePlatformWindowSurfaceEXT(backend->eglDisplay(), backend->config(), (void *) overlay, + clientType == EGL_OPENGL_API && hasEglColorspace ? attr : nullptr); } else { - eglSurface = eglCreateWindowSurface(backend->eglDisplay(), backend->config(), overlay, nullptr); + eglSurface = eglCreateWindowSurface(backend->eglDisplay(), backend->config(), overlay, + clientType == EGL_OPENGL_API && hasEglColorspace ? attr : nullptr); } if (eglSurface == EGL_NO_SURFACE) { qCCritical(KWIN_WAYLAND_BACKEND) << "Create Window Surface failed"; diff --git a/plugins/platforms/x11/common/eglonxbackend.cpp b/plugins/platforms/x11/common/eglonxbackend.cpp --- a/plugins/platforms/x11/common/eglonxbackend.cpp +++ b/plugins/platforms/x11/common/eglonxbackend.cpp @@ -264,15 +264,25 @@ return EGL_NO_SURFACE; } + const int attr[] = { + EGL_GL_COLORSPACE, EGL_GL_COLORSPACE_SRGB, + EGL_NONE + }; + + const bool hasEglColorspace = epoxy_egl_version(eglDisplay()) >= 15 || + hasExtension(QByteArrayLiteral("EGL_KHR_gl_colorspace")); + EGLSurface surface = EGL_NO_SURFACE; if (havePlatformBase()) { // Note: Window is 64 bits on a 64-bit architecture whereas xcb_window_t is // always 32 bits. eglCreatePlatformWindowSurfaceEXT() expects the // native_window parameter to be pointer to a Window, so this variable // cannot be an xcb_window_t. - surface = eglCreatePlatformWindowSurfaceEXT(eglDisplay(), config(), (void *) &window, nullptr); + surface = eglCreatePlatformWindowSurfaceEXT(eglDisplay(), config(), (void *) &window, + !isOpenGLES() && hasEglColorspace ? attr : nullptr); } else { - surface = eglCreateWindowSurface(eglDisplay(), config(), window, nullptr); + surface = eglCreateWindowSurface(eglDisplay(), config(), window, + !isOpenGLES() && hasEglColorspace ? attr : nullptr); } return surface;