2 * Copyright © 2013 Richard Hughes
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of the copyright holders not be used in
9 * advertising or publicity pertaining to distribution of the software
10 * without specific, written prior permission. The copyright holders make
11 * no representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
31 #include "compositor.h"
32 #include "cms-helper.h"
35 struct weston_compositor *ec;
36 struct wl_listener destroy_listener;
37 struct wl_listener output_created_listener;
38 struct wl_list configured_output_list;
41 struct cms_configured_output {
48 cms_output_created(struct cms_static *cms, struct weston_output *o)
50 struct cms_configured_output *configured_output;
51 struct weston_color_profile *p;
53 weston_log("cms-static: output %i [%s] created\n", o->id, o->name);
55 /* find profile from configured list */
56 wl_list_for_each(configured_output, &cms->configured_output_list, link) {
57 if (strcmp (o->name, configured_output->name) == 0) {
58 p = weston_cms_load_profile(configured_output->icc_profile);
60 weston_log("cms-static: failed to load %s\n",
61 configured_output->icc_profile);
63 weston_log("cms-static: loading %s for %s\n",
64 configured_output->icc_profile, o->name);
65 weston_cms_set_color_profile(o, p);
73 cms_notifier_output_created(struct wl_listener *listener, void *data)
75 struct weston_output *o = (struct weston_output *) data;
76 struct cms_static *cms = container_of(listener, struct cms_static, destroy_listener);
77 cms_output_created(cms, o);
81 cms_module_destroy(struct cms_static *cms)
83 struct cms_configured_output *configured_output, *next_co;
85 wl_list_for_each_safe(configured_output, next_co,
86 &cms->configured_output_list, link) {
87 free(configured_output->name);
88 free(configured_output->icc_profile);
89 free(configured_output);
95 cms_notifier_destroy(struct wl_listener *listener, void *data)
97 struct cms_static *cms = container_of(listener, struct cms_static, destroy_listener);
98 cms_module_destroy(cms);
101 static char *output_icc_profile;
102 static char *output_name;
105 output_section_done(void *data)
107 struct cms_configured_output *configured_output;
108 struct cms_static *cms = (struct cms_static *) data;
110 if (output_name == NULL || output_icc_profile == NULL) {
112 free(output_icc_profile);
114 output_icc_profile = NULL;
118 weston_log("cms-static: output %s profile configured as %s\n",
119 output_name, output_icc_profile);
121 /* create an object used to store name<->profile data to avoid parsing
122 * the config file every time a new output is added */
123 configured_output = malloc(sizeof *configured_output);
124 memset(configured_output, 0, sizeof *configured_output);
125 configured_output->name = output_name;
126 configured_output->icc_profile = output_icc_profile;
127 wl_list_insert(&cms->configured_output_list, &configured_output->link);
129 output_icc_profile = NULL;
133 module_init(struct weston_compositor *ec,
134 int *argc, char *argv[])
136 struct cms_static *cms;
137 struct weston_output *output;
139 weston_log("cms-static: initialized\n");
141 /* create local state object */
142 cms = malloc(sizeof *cms);
145 memset(cms, 0, sizeof *cms);
147 wl_list_init(&cms->configured_output_list);
149 /* parse config file */
150 const struct config_key drm_config_keys[] = {
151 { "name", CONFIG_KEY_STRING, &output_name },
152 { "icc_profile", CONFIG_KEY_STRING, &output_icc_profile },
155 const struct config_section config_section[] = {
156 { "output", drm_config_keys,
157 ARRAY_LENGTH(drm_config_keys), output_section_done },
160 parse_config_file(ec->config_fd, config_section,
161 ARRAY_LENGTH(config_section), cms);
163 cms->destroy_listener.notify = cms_notifier_destroy;
164 wl_signal_add(&ec->destroy_signal, &cms->destroy_listener);
166 cms->output_created_listener.notify = cms_notifier_output_created;
167 wl_signal_add(&ec->output_created_signal, &cms->output_created_listener);
169 /* discover outputs */
170 wl_list_for_each(output, &ec->output_list, link)
171 cms_output_created(cms, output);