color: simplify color manager API with weston_output_color_outcome

I am going to need to add yet another output property to be set by a
color manager: HDR Static Metadata Type 1. With the old color manager
API design, I would have needed to add the fourth function pointer to be
called always in the same group as the previous three. This seemed more
convoluted than it needs to be.

Therefore collapse the three existing function pointers in the API into
just one that is resposible for setting up all three things.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
dev
Pekka Paalanen 3 years ago committed by Pekka Paalanen
parent 6c0524fd80
commit dfba19abde
  1. 3
      include/libweston/libweston.h
  2. 52
      libweston/color-lcms/color-lcms.c
  3. 60
      libweston/color-noop.c
  4. 52
      libweston/color.h
  5. 37
      libweston/compositor.c

@ -415,9 +415,6 @@ struct weston_output {
bool from_blend_to_output_by_backend; bool from_blend_to_output_by_backend;
enum weston_eotf_mode eotf_mode; enum weston_eotf_mode eotf_mode;
/* XXX: temporary allocation to be removed in the next commit */
struct weston_output_color_outcome colorout_;
struct weston_output_color_outcome *color_outcome; struct weston_output_color_outcome *color_outcome;
int (*enable)(struct weston_output *output); int (*enable)(struct weston_output *output);

@ -126,11 +126,10 @@ cmlcms_get_surface_color_transform(struct weston_color_manager *cm_base,
} }
static bool static bool
cmlcms_get_output_color_transform(struct weston_color_manager *cm_base, cmlcms_get_blend_to_output_color_transform(struct weston_color_manager_lcms *cm,
struct weston_output *output, struct weston_output *output,
struct weston_color_transform **xform_out) struct weston_color_transform **xform_out)
{ {
struct weston_color_manager_lcms *cm = get_cmlcms(cm_base);
struct cmlcms_color_transform_search_param param = {}; struct cmlcms_color_transform_search_param param = {};
struct cmlcms_color_transform *xform; struct cmlcms_color_transform *xform;
@ -148,11 +147,10 @@ cmlcms_get_output_color_transform(struct weston_color_manager *cm_base,
} }
static bool static bool
cmlcms_get_sRGB_to_output_color_transform(struct weston_color_manager *cm_base, cmlcms_get_sRGB_to_output_color_transform(struct weston_color_manager_lcms *cm,
struct weston_output *output, struct weston_output *output,
struct weston_color_transform **xform_out) struct weston_color_transform **xform_out)
{ {
struct weston_color_manager_lcms *cm = get_cmlcms(cm_base);
struct cmlcms_color_transform_search_param param = {}; struct cmlcms_color_transform_search_param param = {};
struct cmlcms_color_transform *xform; struct cmlcms_color_transform *xform;
@ -177,11 +175,10 @@ cmlcms_get_sRGB_to_output_color_transform(struct weston_color_manager *cm_base,
} }
static bool static bool
cmlcms_get_sRGB_to_blend_color_transform(struct weston_color_manager *cm_base, cmlcms_get_sRGB_to_blend_color_transform(struct weston_color_manager_lcms *cm,
struct weston_output *output, struct weston_output *output,
struct weston_color_transform **xform_out) struct weston_color_transform **xform_out)
{ {
struct weston_color_manager_lcms *cm = get_cmlcms(cm_base);
struct cmlcms_color_transform_search_param param = {}; struct cmlcms_color_transform_search_param param = {};
struct cmlcms_color_transform *xform; struct cmlcms_color_transform *xform;
@ -198,6 +195,36 @@ cmlcms_get_sRGB_to_blend_color_transform(struct weston_color_manager *cm_base,
return true; return true;
} }
static struct weston_output_color_outcome *
cmlcms_create_output_color_outcome(struct weston_color_manager *cm_base,
struct weston_output *output)
{
struct weston_color_manager_lcms *cm = get_cmlcms(cm_base);
struct weston_output_color_outcome *co;
co = zalloc(sizeof *co);
if (!co)
return NULL;
if (!cmlcms_get_blend_to_output_color_transform(cm, output,
&co->from_blend_to_output))
goto out_fail;
if (!cmlcms_get_sRGB_to_blend_color_transform(cm, output,
&co->from_sRGB_to_blend))
goto out_fail;
if (!cmlcms_get_sRGB_to_output_color_transform(cm, output,
&co->from_sRGB_to_output))
goto out_fail;
return co;
out_fail:
weston_output_color_outcome_destroy(&co);
return NULL;
}
static void static void
lcms_error_logger(cmsContext context_id, lcms_error_logger(cmsContext context_id,
cmsUInt32Number error_code, cmsUInt32Number error_code,
@ -264,13 +291,8 @@ weston_color_manager_create(struct weston_compositor *compositor)
cm->base.destroy_color_profile = cmlcms_destroy_color_profile; cm->base.destroy_color_profile = cmlcms_destroy_color_profile;
cm->base.get_color_profile_from_icc = cmlcms_get_color_profile_from_icc; cm->base.get_color_profile_from_icc = cmlcms_get_color_profile_from_icc;
cm->base.destroy_color_transform = cmlcms_destroy_color_transform; cm->base.destroy_color_transform = cmlcms_destroy_color_transform;
cm->base.get_surface_color_transform = cm->base.get_surface_color_transform = cmlcms_get_surface_color_transform;
cmlcms_get_surface_color_transform; cm->base.create_output_color_outcome = cmlcms_create_output_color_outcome;
cm->base.get_output_color_transform = cmlcms_get_output_color_transform;
cm->base.get_sRGB_to_output_color_transform =
cmlcms_get_sRGB_to_output_color_transform;
cm->base.get_sRGB_to_blend_color_transform =
cmlcms_get_sRGB_to_blend_color_transform;
wl_list_init(&cm->color_transform_list); wl_list_init(&cm->color_transform_list);
wl_list_init(&cm->color_profile_list); wl_list_init(&cm->color_profile_list);

@ -96,52 +96,27 @@ cmnoop_get_surface_color_transform(struct weston_color_manager *cm_base,
return true; return true;
} }
static bool static struct weston_output_color_outcome *
cmnoop_get_output_color_transform(struct weston_color_manager *cm_base, cmnoop_create_output_color_outcome(struct weston_color_manager *cm_base,
struct weston_output *output, struct weston_output *output)
struct weston_color_transform **xform_out)
{ {
assert(output->color_profile == NULL); struct weston_output_color_outcome *co;
if (!check_output_eotf_mode(output))
return false;
/* Identity transform */
*xform_out = NULL;
return true;
}
static bool
cmnoop_get_sRGB_to_output_color_transform(struct weston_color_manager *cm_base,
struct weston_output *output,
struct weston_color_transform **xform_out)
{
assert(output->color_profile == NULL); assert(output->color_profile == NULL);
if (!check_output_eotf_mode(output)) if (!check_output_eotf_mode(output))
return false; return NULL;
/* Identity transform */
*xform_out = NULL;
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)
{
assert(output->color_profile == NULL);
if (!check_output_eotf_mode(output)) co = zalloc(sizeof *co);
return false; if (!co)
return NULL;
/* Identity transform */ /* Identity transform on everything */
*xform_out = NULL; co->from_blend_to_output = NULL;
co->from_sRGB_to_blend = NULL;
co->from_sRGB_to_output = NULL;
return true; return co;
} }
static bool static bool
@ -177,13 +152,8 @@ weston_color_manager_noop_create(struct weston_compositor *compositor)
cm->base.destroy_color_profile = cmnoop_destroy_color_profile; cm->base.destroy_color_profile = cmnoop_destroy_color_profile;
cm->base.get_color_profile_from_icc = cmnoop_get_color_profile_from_icc; cm->base.get_color_profile_from_icc = cmnoop_get_color_profile_from_icc;
cm->base.destroy_color_transform = cmnoop_destroy_color_transform; cm->base.destroy_color_transform = cmnoop_destroy_color_transform;
cm->base.get_surface_color_transform = cm->base.get_surface_color_transform = cmnoop_get_surface_color_transform;
cmnoop_get_surface_color_transform; cm->base.create_output_color_outcome = cmnoop_create_output_color_outcome;
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; return &cm->base;
} }

@ -297,53 +297,19 @@ struct weston_color_manager {
struct weston_output *output, struct weston_output *output,
struct weston_surface_color_transform *surf_xform); struct weston_surface_color_transform *surf_xform);
/** Get output's blending space to output transformation /** Compute derived color properties for an output
* *
* \param cm The color manager. * \param cm The color manager.
* \param output The output for the destination color space. * \param output The output.
* \param xform_out Pointer for storing the weston_color_transform. * \return A new color_outcome object on success, NULL on failure.
* \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_output_color_transform)(struct weston_color_manager *cm,
struct weston_output *output,
struct weston_color_transform **xform_out);
/** Get sRGB to output transformation
*
* \param cm The color manager.
* \param output The output for the destination 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_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 * The callee (color manager) must inspect the weston_output (color
* weston_color_transform it stores via xform_out. On failure, xform_out * profile, EOTF mode, etc.) and create a fully populated
* is untouched. * weston_output_color_outcome object.
*/ */
bool struct weston_output_color_outcome *
(*get_sRGB_to_blend_color_transform)(struct weston_color_manager *cm, (*create_output_color_outcome)(struct weston_color_manager *cm,
struct weston_output *output, struct weston_output *output);
struct weston_color_transform **xform_out);
}; };
void void

@ -6472,49 +6472,30 @@ weston_output_color_outcome_destroy(struct weston_output_color_outcome **pco)
return; return;
weston_color_transform_unref(co->from_sRGB_to_output); weston_color_transform_unref(co->from_sRGB_to_output);
co->from_sRGB_to_output = NULL;
weston_color_transform_unref(co->from_sRGB_to_blend); weston_color_transform_unref(co->from_sRGB_to_blend);
co->from_sRGB_to_blend = NULL;
weston_color_transform_unref(co->from_blend_to_output); weston_color_transform_unref(co->from_blend_to_output);
co->from_blend_to_output = NULL;
/* XXX: added in the next commit */ free(co);
/* free(co); */
*pco = NULL; *pco = NULL;
} }
static bool static bool
weston_output_set_color_transforms(struct weston_output *output) weston_output_set_color_outcome(struct weston_output *output)
{ {
struct weston_color_manager *cm = output->compositor->color_manager; struct weston_color_manager *cm = output->compositor->color_manager;
struct weston_color_transform *blend_to_output = NULL; struct weston_output_color_outcome *colorout;
struct weston_color_transform *sRGB_to_output = NULL;
struct weston_color_transform *sRGB_to_blend = NULL; colorout = cm->create_output_color_outcome(cm, output);
bool ok; if (!colorout) {
ok = cm->get_output_color_transform(cm, output, &blend_to_output);
ok = ok && cm->get_sRGB_to_output_color_transform(cm, output,
&sRGB_to_output);
ok = ok && cm->get_sRGB_to_blend_color_transform(cm, output,
&sRGB_to_blend);
if (!ok) {
weston_log("Creating color transformation for output \"%s\" failed.\n", weston_log("Creating color transformation for output \"%s\" failed.\n",
output->name); output->name);
weston_color_transform_unref(blend_to_output);
weston_color_transform_unref(sRGB_to_output);
weston_color_transform_unref(sRGB_to_blend);
return false; return false;
} }
weston_output_color_outcome_destroy(&output->color_outcome); weston_output_color_outcome_destroy(&output->color_outcome);
output->color_outcome = colorout;
/* XXX: temporary allocation to be removed in the next commit */
output->color_outcome = &output->colorout_;
output->color_outcome->from_blend_to_output = blend_to_output;
output->color_outcome->from_sRGB_to_output = sRGB_to_output;
output->color_outcome->from_sRGB_to_blend = sRGB_to_blend;
output->from_blend_to_output_by_backend = false; output->from_blend_to_output_by_backend = false;
weston_log("Output '%s' using color profile: %s\n", output->name, weston_log("Output '%s' using color profile: %s\n", output->name,
@ -6734,7 +6715,7 @@ weston_output_set_color_profile(struct weston_output *output,
output->color_profile = weston_color_profile_ref(cprof); output->color_profile = weston_color_profile_ref(cprof);
if (output->enabled) { if (output->enabled) {
if (!weston_output_set_color_transforms(output)) { if (!weston_output_set_color_outcome(output)) {
/* Failed, roll back */ /* Failed, roll back */
weston_color_profile_unref(output->color_profile); weston_color_profile_unref(output->color_profile);
output->color_profile = old; output->color_profile = old;
@ -6990,7 +6971,7 @@ weston_output_enable(struct weston_output *output)
weston_log("Output '%s' attempts EOTF mode: %s\n", output->name, weston_log("Output '%s' attempts EOTF mode: %s\n", output->name,
weston_eotf_mode_to_str(output->eotf_mode)); weston_eotf_mode_to_str(output->eotf_mode));
if (!weston_output_set_color_transforms(output)) if (!weston_output_set_color_outcome(output))
return -1; return -1;
/* Enable the output (set up the crtc or create a /* Enable the output (set up the crtc or create a

Loading…
Cancel
Save