From 8fb23ed11086c2b8c34bfc42e19091ac5b29924e Mon Sep 17 00:00:00 2001 From: Pekka Paalanen Date: Tue, 23 Mar 2021 13:40:43 +0200 Subject: [PATCH] color: add from sRGB to blending color transformation This is needed when the compositor produces any content internally: - the lines in triangle fan debug - the censoring color fill (unmet HDCP requirements) Solid color surfaces do not need this special-casing because weston_surface is supposed to carry color space information, which will get used in gl_shader_config_init_for_view(). This makes sure the internally produced graphics fit in, e.g on a monitor in HDR mode. For now, just ensure there is an identity transformation. Actual implementations in GL-renderer will follow later. Signed-off-by: Pekka Paalanen --- include/libweston/libweston.h | 1 + libweston/color-noop.c | 15 +++++++++++++++ libweston/color.h | 16 ++++++++++++++++ libweston/compositor.c | 4 ++++ libweston/renderer-gl/gl-renderer.c | 3 +++ 5 files changed, 39 insertions(+) diff --git a/include/libweston/libweston.h b/include/libweston/libweston.h index d7c0ec15..1173950a 100644 --- a/include/libweston/libweston.h +++ b/include/libweston/libweston.h @@ -375,6 +375,7 @@ struct weston_output { bool use_renderer_shadow_buffer; struct weston_color_transform *from_sRGB_to_output; + struct weston_color_transform *from_sRGB_to_blend; struct weston_color_transform *from_blend_to_output; bool from_blend_to_output_by_backend; diff --git a/libweston/color-noop.c b/libweston/color-noop.c index 6726ed8e..aa73d42e 100644 --- a/libweston/color-noop.c +++ b/libweston/color-noop.c @@ -88,6 +88,19 @@ cmnoop_get_sRGB_to_output_color_transform(struct weston_color_manager *cm_base, return true; } +static bool +cmnoop_get_sRGB_to_blend_color_transform(struct weston_color_manager *cm_base, + struct weston_output *output, + struct weston_color_transform **xform_out) +{ + /* TODO: Assert output has no colorspace set */ + + /* Identity transform */ + *xform_out = NULL; + + return true; +} + static bool cmnoop_init(struct weston_color_manager *cm_base) { @@ -124,6 +137,8 @@ weston_color_manager_noop_create(struct weston_compositor *compositor) cm->base.get_output_color_transform = cmnoop_get_output_color_transform; cm->base.get_sRGB_to_output_color_transform = cmnoop_get_sRGB_to_output_color_transform; + cm->base.get_sRGB_to_blend_color_transform = + cmnoop_get_sRGB_to_blend_color_transform; return &cm->base; } diff --git a/libweston/color.h b/libweston/color.h index c13d20cd..18f8e4a3 100644 --- a/libweston/color.h +++ b/libweston/color.h @@ -192,6 +192,22 @@ struct weston_color_manager { (*get_sRGB_to_output_color_transform)(struct weston_color_manager *cm, struct weston_output *output, struct weston_color_transform **xform_out); + + /** Get sRGB to output's blending space transformation + * + * \param cm The color manager. + * \param output The output for the destination blending color space. + * \param xform_out Pointer for storing the weston_color_transform. + * \return True on success, false on failure. + * + * The callee is responsible for increasing the reference count on the + * weston_color_transform it stores via xform_out. On failure, xform_out + * is untouched. + */ + bool + (*get_sRGB_to_blend_color_transform)(struct weston_color_manager *cm, + struct weston_output *output, + struct weston_color_transform **xform_out); }; struct weston_color_transform * diff --git a/libweston/compositor.c b/libweston/compositor.c index 3f4f4b0b..e5fcac3a 100644 --- a/libweston/compositor.c +++ b/libweston/compositor.c @@ -6274,6 +6274,8 @@ weston_output_reset_color_transforms(struct weston_output *output) { weston_color_transform_unref(output->from_sRGB_to_output); output->from_sRGB_to_output = NULL; + weston_color_transform_unref(output->from_sRGB_to_blend); + output->from_sRGB_to_blend = NULL; weston_color_transform_unref(output->from_blend_to_output); output->from_blend_to_output = NULL; } @@ -6691,6 +6693,8 @@ weston_output_enable(struct weston_output *output) &output->from_blend_to_output); ok = ok && cm->get_sRGB_to_output_color_transform(cm, output, &output->from_sRGB_to_output); + ok = ok && cm->get_sRGB_to_blend_color_transform(cm, output, + &output->from_sRGB_to_blend); if (!ok) { weston_log("Creating color transformation for output \"%s\" failed.\n", output->name); diff --git a/libweston/renderer-gl/gl-renderer.c b/libweston/renderer-gl/gl-renderer.c index ec320dbd..b3611a65 100644 --- a/libweston/renderer-gl/gl-renderer.c +++ b/libweston/renderer-gl/gl-renderer.c @@ -1034,6 +1034,9 @@ draw_paint_node(struct weston_paint_node *pnode, else filter = GL_NEAREST; + /* for triangle_fan_debug(), maybe_censor_override() */ + assert(pnode->output->from_sRGB_to_blend == NULL); + if (!gl_shader_config_init_for_paint_node(&sconf, pnode, filter)) goto out;