[PATCH 3/6] Attach output profiles and build corresponding LUTs

Niels Ole Salscheider niels_ole at salscheider-online.de
Mon Oct 13 10:40:48 PDT 2014


This patch allows to attach an ICC profile to each output.

Signed-off-by: Niels Ole Salscheider <niels_ole at salscheider-online.de>
---
 src/cms-colord.c |  4 +++-
 src/cms-helper.c | 16 +++++++++++++++-
 src/cms-helper.h |  3 ++-
 src/cms-static.c |  1 +
 src/compositor.c | 18 ++++++++++++++++++
 src/compositor.h |  2 ++
 6 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/src/cms-colord.c b/src/cms-colord.c
index 4ff3aac..5696ea3 100644
--- a/src/cms-colord.c
+++ b/src/cms-colord.c
@@ -155,8 +155,9 @@ colord_update_output_from_device (struct cms_output *ocms)
 	gint percentage;
 
 	/* old profile is no longer valid */
-	weston_cms_destroy_profile(ocms->p);
+	weston_cms_destroy_profile(ocms->o, ocms->p);
 	ocms->p = NULL;
+	wl_signal_emit(&ocms->o->profile_signal, ocms->o);
 
 	ret = cd_device_connect_sync(ocms->device, NULL, &error);
 	if (!ret) {
@@ -384,6 +385,7 @@ colord_dispatch_all_pending(int fd, uint32_t mask, void *data)
 		}
 
 		weston_cms_set_color_profile(ocms->o, ocms->p);
+		wl_signal_emit(&ocms->o->profile_signal, ocms->o);
 	}
 	g_list_free (cms->pending);
 	cms->pending = NULL;
diff --git a/src/cms-helper.c b/src/cms-helper.c
index c063c77..4e20f28 100644
--- a/src/cms-helper.c
+++ b/src/cms-helper.c
@@ -25,6 +25,8 @@
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
 
 #ifdef HAVE_LCMS
 #include <lcms2.h>
@@ -63,6 +65,13 @@ weston_cms_set_color_profile(struct weston_output *o,
 	uint16_t *red = NULL;
 	uint16_t *green = NULL;
 	uint16_t *blue = NULL;
+	int fd;
+
+	fd = open(p->filename, 0);
+	o->colorspace = weston_colorspace_from_fd(fd , 0, o->compositor);
+	close(fd);
+	if (o->colorspace == NULL)
+		o->colorspace = &o->compositor->srgb_colorspace;
 
 	if (!o->set_gamma)
 		return;
@@ -96,13 +105,18 @@ weston_cms_set_color_profile(struct weston_output *o,
 }
 
 void
-weston_cms_destroy_profile(struct weston_color_profile *p)
+weston_cms_destroy_profile(struct weston_output *o,
+			   struct weston_color_profile *p)
 {
 	if (!p)
 		return;
 #ifdef HAVE_LCMS
 	cmsCloseProfile(p->lcms_handle);
 #endif
+
+	weston_colorspace_destroy(o->colorspace);
+	o->colorspace = &o->compositor->srgb_colorspace;
+
 	free(p->filename);
 	free(p);
 }
diff --git a/src/cms-helper.h b/src/cms-helper.h
index 6e5594d..3fd17b3 100644
--- a/src/cms-helper.h
+++ b/src/cms-helper.h
@@ -67,6 +67,7 @@ weston_cms_create_profile(const char *filename,
 struct weston_color_profile *
 weston_cms_load_profile(const char *filename);
 void
-weston_cms_destroy_profile(struct weston_color_profile *p);
+weston_cms_destroy_profile(struct weston_output *o,
+			   struct weston_color_profile *p);
 
 #endif
diff --git a/src/cms-static.c b/src/cms-static.c
index ad54fd1..c7dce58 100644
--- a/src/cms-static.c
+++ b/src/cms-static.c
@@ -58,6 +58,7 @@ cms_output_created(struct cms_static *cms, struct weston_output *o)
 		weston_log("cms-static: loading %s for %s\n",
 			   profile, o->name);
 		weston_cms_set_color_profile(o, p);
+		wl_signal_emit(&o->profile_signal, o);
 	}
 }
 
diff --git a/src/compositor.c b/src/compositor.c
index 4f959a4..61b70e7 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -3516,6 +3516,20 @@ weston_compositor_remove_output(struct weston_compositor *compositor,
 	}
 }
 
+static void
+weston_output_notifier_profile(struct wl_listener *listener, void *data)
+{
+/* TODO:
+	struct weston_output *output = (struct weston_output *) data;
+	struct weston_compositor *ec = output->compositor;
+	struct weston_resource *resource;
+
+	for each wl_cms resource {
+	wl_cms_send_output_colorspace_changed(resource, output);
+	}
+*/
+}
+
 WL_EXPORT void
 weston_output_destroy(struct weston_output *output)
 {
@@ -3736,10 +3750,14 @@ weston_output_init(struct weston_output *output, struct weston_compositor *c,
 
 	wl_signal_init(&output->frame_signal);
 	wl_signal_init(&output->destroy_signal);
+	wl_signal_init(&output->profile_signal);
 	wl_list_init(&output->animation_list);
 	wl_list_init(&output->resource_list);
 	wl_list_init(&output->feedback_list);
 
+	output->profile_listener.notify = weston_output_notifier_profile;
+	wl_signal_add(&output->profile_signal, &output->profile_listener);
+
 	output->id = ffs(~output->compositor->output_id_pool) - 1;
 	output->compositor->output_id_pool |= 1 << output->id;
 
diff --git a/src/compositor.h b/src/compositor.h
index 5f198a9..419a56a 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -224,6 +224,8 @@ struct weston_output {
 	int dirty;
 	struct wl_signal frame_signal;
 	struct wl_signal destroy_signal;
+	struct wl_signal profile_signal;
+	struct wl_listener profile_listener;
 	int move_x, move_y;
 	uint32_t frame_time; /* presentation timestamp in milliseconds */
 	uint64_t msc;        /* media stream counter */
-- 
2.1.2



More information about the wayland-devel mailing list