color: do not use NULL as stock sRGB color profile

Stop assuming that NULL represents the stock sRGB color profile. From
now on, query the stock sRGB color profile from the color manager.

This should be internal to libweston (core and the color plugins), and
users of the libweston public API should not be affected by this. They
are still allowed to set an output color profile to the stock sRGB using
NULL.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
This commit is contained in:
Leandro Ribeiro 2023-10-06 14:03:03 -03:00 committed by Pekka Paalanen
parent 0c1ab2ad76
commit cab1992b81
4 changed files with 32 additions and 13 deletions

View File

@ -304,13 +304,7 @@ cmlcms_create_output_color_outcome(struct weston_color_manager *cm_base,
if (!cmlcms_get_hdr_meta(output, &co->hdr_meta))
goto out_fail;
/*
* TODO: if output->color_profile is NULL, maybe manufacture a
* profile from weston_color_characteristics if it has enough
* information?
* Or let the frontend decide to call a "create a profile from
* characteristics" API?
*/
assert(output->color_profile);
/* TODO: take container color space into account */

View File

@ -146,8 +146,12 @@ cmnoop_get_surface_color_transform(struct weston_color_manager *cm_base,
struct weston_output *output,
struct weston_surface_color_transform *surf_xform)
{
/* TODO: Assert surface has no colorspace set */
assert(output->color_profile == NULL);
struct weston_color_manager_noop *cmnoop = get_cmnoop(cm_base);
/* TODO: Assert that, if the surface has a cprof, it is the stock one */
assert(output->color_profile &&
get_cprof(output->color_profile) == cmnoop->stock_cprof);
if (!check_output_eotf_mode(output))
return false;
@ -163,9 +167,11 @@ static struct weston_output_color_outcome *
cmnoop_create_output_color_outcome(struct weston_color_manager *cm_base,
struct weston_output *output)
{
struct weston_color_manager_noop *cmnoop = get_cmnoop(cm_base);
struct weston_output_color_outcome *co;
assert(output->color_profile == NULL);
assert(output->color_profile &&
get_cprof(output->color_profile) == cmnoop->stock_cprof);
if (!check_output_eotf_mode(output))
return NULL;

View File

@ -50,7 +50,6 @@
WL_EXPORT struct weston_color_profile *
weston_color_profile_ref(struct weston_color_profile *cprof)
{
/* NULL is a valid color space: sRGB */
if (!cprof)
return NULL;
@ -92,7 +91,7 @@ weston_color_profile_get_description(struct weston_color_profile *cprof)
if (cprof)
return cprof->description;
else
return "built-in default sRGB SDR profile";
return "(untagged)";
}
/**

View File

@ -7170,6 +7170,8 @@ weston_output_set_color_outcome(struct weston_output *output)
struct weston_color_manager *cm = output->compositor->color_manager;
struct weston_output_color_outcome *colorout;
assert(output->color_profile);
colorout = cm->create_output_color_outcome(cm, output);
if (!colorout) {
weston_log("Creating color transformation for output \"%s\" failed.\n",
@ -7412,11 +7414,17 @@ WL_EXPORT bool
weston_output_set_color_profile(struct weston_output *output,
struct weston_color_profile *cprof)
{
struct weston_color_manager *cm = output->compositor->color_manager;
struct weston_color_profile *old;
struct weston_paint_node *pnode;
old = output->color_profile;
output->color_profile = weston_color_profile_ref(cprof);
if (!cprof) {
output->color_profile = cm->get_stock_sRGB_color_profile(cm);
} else {
output->color_profile = weston_color_profile_ref(cprof);
}
if (output->enabled) {
if (!weston_output_set_color_outcome(output)) {
@ -7603,6 +7611,8 @@ weston_output_init(struct weston_output *output,
struct weston_compositor *compositor,
const char *name)
{
struct weston_color_manager *cm;
output->pos.c = weston_coord(0, 0);
output->compositor = compositor;
output->destroying = 0;
@ -7636,6 +7646,11 @@ weston_output_init(struct weston_output *output,
weston_plane_init(&output->primary_plane, compositor);
weston_compositor_stack_plane(compositor,
&output->primary_plane, NULL);
/* Set the stock sRGB color profile for the output. Libweston users are
* free to set the color profile to whatever they want later on. */
cm = compositor->color_manager;
output->color_profile = cm->get_stock_sRGB_color_profile(cm);
}
/** Adds weston_output object to pending output list.
@ -7949,7 +7964,12 @@ weston_output_release(struct weston_output *output)
if (output->enabled)
weston_compositor_remove_output(output);
/* We always have a color profile set, as weston_output_init() sets the
* output cprof to the stock sRGB one. */
assert(output->color_profile);
weston_color_profile_unref(output->color_profile);
output->color_profile = NULL;
assert(output->color_outcome == NULL);
pixman_region32_fini(&output->region);