From d8fb7adcf041af7e958804b77c9a6669fbff4efd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Poisot?= Date: Sun, 17 Aug 2025 15:57:16 +0000 Subject: [PATCH] scene, render: use Gamma 2.2 TF as default --- include/wlr/render/pass.h | 5 +++-- render/vulkan/pass.c | 11 ++++------- types/scene/surface.c | 8 ++++---- types/scene/wlr_scene.c | 2 +- types/wlr_color_management_v1.c | 4 ++-- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/include/wlr/render/pass.h b/include/wlr/render/pass.h index 8e22bdf8f..1785ee562 100644 --- a/include/wlr/render/pass.h +++ b/include/wlr/render/pass.h @@ -31,8 +31,9 @@ struct wlr_render_timer; struct wlr_buffer_pass_options { /* Timer to measure the duration of the render pass */ struct wlr_render_timer *timer; - /* Color transform to apply to the output of the render pass, - * leave NULL to indicate sRGB/no custom transform */ + /* Color transform to apply to the output of the render pass. + * Leave NULL to indicate the default transform (Gamma 2.2 encoding for + * sRGB monitors) */ struct wlr_color_transform *color_transform; /** Primaries describing the color volume of the destination buffer */ const struct wlr_color_primaries *primaries; diff --git a/render/vulkan/pass.c b/render/vulkan/pass.c index 5555f1197..4cce62eb5 100644 --- a/render/vulkan/pass.c +++ b/render/vulkan/pass.c @@ -57,10 +57,7 @@ static void convert_pixman_box_to_vk_rect(const pixman_box32_t *box, VkRect2D *r } static float color_to_linear(float non_linear) { - // See https://www.w3.org/Graphics/Color/srgb - return (non_linear > 0.04045) ? - pow((non_linear + 0.055) / 1.055, 2.4) : - non_linear / 12.92; + return pow(non_linear, 2.2); } static float color_to_linear_premult(float non_linear, float alpha) { @@ -229,7 +226,7 @@ static bool render_pass_submit(struct wlr_render_pass *wlr_pass) { if (pass->color_transform && pass->color_transform->type != COLOR_TRANSFORM_INVERSE_EOTF) { pipeline = render_buffer->two_pass.render_setup->output_pipe_lut3d; } else { - enum wlr_color_transfer_function tf = WLR_COLOR_TRANSFER_FUNCTION_SRGB; + enum wlr_color_transfer_function tf = WLR_COLOR_TRANSFER_FUNCTION_GAMMA22; if (pass->color_transform && pass->color_transform->type == COLOR_TRANSFORM_INVERSE_EOTF) { struct wlr_color_transform_inverse_eotf *inverse_eotf = wlr_color_transform_inverse_eotf_from_base(pass->color_transform); @@ -779,7 +776,7 @@ static void render_pass_add_texture(struct wlr_render_pass *wlr_pass, enum wlr_color_transfer_function tf = options->transfer_function; if (tf == 0) { - tf = WLR_COLOR_TRANSFER_FUNCTION_SRGB; + tf = WLR_COLOR_TRANSFER_FUNCTION_GAMMA22; } bool srgb_image_view = false; @@ -1186,7 +1183,7 @@ struct wlr_vk_render_pass *vulkan_begin_render_pass(struct wlr_vk_renderer *rend } } else { // This is the default when unspecified - inv_eotf = WLR_COLOR_TRANSFER_FUNCTION_SRGB; + inv_eotf = WLR_COLOR_TRANSFER_FUNCTION_GAMMA22; } bool using_linear_pathway = inv_eotf == WLR_COLOR_TRANSFER_FUNCTION_EXT_LINEAR; diff --git a/types/scene/surface.c b/types/scene/surface.c index aebc00ea2..593537163 100644 --- a/types/scene/surface.c +++ b/types/scene/surface.c @@ -37,12 +37,12 @@ static struct wlr_output *get_surface_frame_pacing_output(struct wlr_surface *su static bool get_tf_preference(enum wlr_color_transfer_function tf) { switch (tf) { - case WLR_COLOR_TRANSFER_FUNCTION_SRGB: + case WLR_COLOR_TRANSFER_FUNCTION_GAMMA22: return 0; case WLR_COLOR_TRANSFER_FUNCTION_ST2084_PQ: return 1; + case WLR_COLOR_TRANSFER_FUNCTION_SRGB: case WLR_COLOR_TRANSFER_FUNCTION_EXT_LINEAR: - case WLR_COLOR_TRANSFER_FUNCTION_GAMMA22: return -1; } abort(); // unreachable @@ -61,7 +61,7 @@ static bool get_primaries_preference(enum wlr_color_named_primaries primaries) { static void get_surface_preferred_image_description(struct wlr_surface *surface, struct wlr_image_description_v1_data *out) { struct wlr_output_image_description preferred = { - .transfer_function = WLR_COLOR_TRANSFER_FUNCTION_SRGB, + .transfer_function = WLR_COLOR_TRANSFER_FUNCTION_GAMMA22, .primaries = WLR_COLOR_NAMED_PRIMARIES_SRGB, }; @@ -249,7 +249,7 @@ static void surface_reconfigure(struct wlr_scene_surface *scene_surface) { opacity = (float)alpha_modifier_state->multiplier; } - enum wlr_color_transfer_function tf = WLR_COLOR_TRANSFER_FUNCTION_SRGB; + enum wlr_color_transfer_function tf = WLR_COLOR_TRANSFER_FUNCTION_GAMMA22; enum wlr_color_named_primaries primaries = WLR_COLOR_NAMED_PRIMARIES_SRGB; const struct wlr_image_description_v1_data *img_desc = wlr_surface_get_image_description_v1_data(surface); diff --git a/types/scene/wlr_scene.c b/types/scene/wlr_scene.c index 9efbe58ad..3d9f96fac 100644 --- a/types/scene/wlr_scene.c +++ b/types/scene/wlr_scene.c @@ -1991,7 +1991,7 @@ static enum scene_direct_scanout_result scene_entry_try_direct_scanout( return SCANOUT_INELIGIBLE; } - if (buffer->transfer_function != 0 && buffer->transfer_function != WLR_COLOR_TRANSFER_FUNCTION_SRGB) { + if (buffer->transfer_function != 0 && buffer->transfer_function != WLR_COLOR_TRANSFER_FUNCTION_GAMMA22) { return SCANOUT_INELIGIBLE; } if (buffer->primaries != 0 && buffer->primaries != WLR_COLOR_NAMED_PRIMARIES_SRGB) { diff --git a/types/wlr_color_management_v1.c b/types/wlr_color_management_v1.c index 54c0a44af..80c357539 100644 --- a/types/wlr_color_management_v1.c +++ b/types/wlr_color_management_v1.c @@ -212,7 +212,7 @@ static void cm_output_handle_get_image_description(struct wl_client *client, } struct wlr_image_description_v1_data data = { - .tf_named = WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_SRGB, + .tf_named = WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_GAMMA22, .primaries_named = WP_COLOR_MANAGER_V1_PRIMARIES_SRGB, }; const struct wlr_output_image_description *image_desc = cm_output->output->image_description; @@ -777,7 +777,7 @@ static void manager_handle_get_surface_feedback(struct wl_client *client, surface_feedback->surface = surface; surface_feedback->data = (struct wlr_image_description_v1_data){ - .tf_named = WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_SRGB, + .tf_named = WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_GAMMA22, .primaries_named = WP_COLOR_MANAGER_V1_PRIMARIES_SRGB, };