libweston: add weston_output::color_profile
Add API to set an output's color profile. This new function can also be
called while the output is enabled. This allows changing the output
color profile even at runtime if desired.
color-noop has no way of creating weston_color_profile objects, so it
just asserts that no color profile is set.
color-lcms does not yet implement taking the output color profile into
account, so for now it just fails everything if a profile is set.
weston_surface_color_transform_fini() was previously used only prior to
freeing the struct, but now it is used also to just clear the struct,
hence it needs to reset the fields.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
diff --git a/libweston/compositor.c b/libweston/compositor.c
index d747e31..42984f9 100644
--- a/libweston/compositor.c
+++ b/libweston/compositor.c
@@ -6303,6 +6303,9 @@
output->from_sRGB_to_output = sRGB_to_output;
output->from_sRGB_to_blend = sRGB_to_blend;
+ weston_log("Output '%s' using color profile: %s\n", output->name,
+ weston_color_profile_get_description(output->color_profile));
+
return true;
}
@@ -6490,6 +6493,52 @@
}
}
+/** Set output's color profile
+ *
+ * \param output The output to change.
+ * \param cprof The color profile to set. Can be NULL for default sRGB profile.
+ * \return True on success, or false on failure.
+ *
+ * Calling this function changes the color profile of the output. This causes
+ * all existing weston_color_transform objects related to this output via
+ * paint nodes to be unreferenced and later re-created on demand.
+ *
+ * This function may not be called from within weston_output_repaint().
+ *
+ * On failure, nothing is changed.
+ *
+ * \ingroup output
+ */
+WL_EXPORT bool
+weston_output_set_color_profile(struct weston_output *output,
+ struct weston_color_profile *cprof)
+{
+ struct weston_color_profile *old;
+ struct weston_paint_node *pnode;
+
+ old = output->color_profile;
+ output->color_profile = weston_color_profile_ref(cprof);
+
+ if (output->enabled) {
+ if (!weston_output_set_color_transforms(output)) {
+ /* Failed, roll back */
+ weston_color_profile_unref(output->color_profile);
+ output->color_profile = old;
+ return false;
+ }
+
+ /* Remove outdated cached color transformations */
+ wl_list_for_each(pnode, &output->paint_node_list, output_link) {
+ weston_surface_color_transform_fini(&pnode->surf_xform);
+ pnode->surf_xform_valid = false;
+ }
+ }
+
+ weston_color_profile_unref(old);
+
+ return true;
+}
+
/** Initializes a weston_output object with enough data so
** an output can be configured.
*
@@ -6848,6 +6897,8 @@
if (output->enabled)
weston_compositor_remove_output(output);
+ weston_color_profile_unref(output->color_profile);
+
pixman_region32_fini(&output->region);
wl_list_remove(&output->link);