From ebf24c2bda7fdb55ded6b4c12265a2ed6ba67ef0 Mon Sep 17 00:00:00 2001 From: David Turner Date: Thu, 8 May 2025 10:49:02 +0100 Subject: [PATCH] render/egl: Always use BT.709 hint for YUV Always set the BT.709 hint in an attempt to get the gles2 renderer to consistently use this color encoding when converting YUV to RGB. In addition to being consistent across drivers, this is consistent with DRM so should avoid color shifts when enabling/disabling direct scanout. --- render/egl.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/render/egl.c b/render/egl.c index 07d3a1425..f35481393 100644 --- a/render/egl.c +++ b/render/egl.c @@ -745,7 +745,7 @@ EGLImageKHR wlr_egl_create_image_from_dmabuf(struct wlr_egl *egl, } unsigned int atti = 0; - EGLint attribs[50]; + EGLint attribs[52]; attribs[atti++] = EGL_WIDTH; attribs[atti++] = attributes->width; attribs[atti++] = EGL_HEIGHT; @@ -803,6 +803,13 @@ EGLImageKHR wlr_egl_create_image_from_dmabuf(struct wlr_egl *egl, } } + // Always convert YUV to RGB using BT.709 color encoding. This is to + // attempt to be consistent across GL drivers, and also to be + // consistent with DRM scanout so there's no color-shift when direct + // scanout is enabled/disabled. + attribs[atti++] = EGL_YUV_COLOR_SPACE_HINT_EXT; + attribs[atti++] = EGL_ITU_REC709_EXT; + // Our clients don't expect our usage to trash the buffer contents attribs[atti++] = EGL_IMAGE_PRESERVED_KHR; attribs[atti++] = EGL_TRUE;