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 =
77 container_of(listener, struct cms_static, output_created_listener);
78 cms_output_created(cms, o);
82 cms_module_destroy(struct cms_static *cms)
84 struct cms_configured_output *configured_output, *next_co;
86 wl_list_for_each_safe(configured_output, next_co,
87 &cms->configured_output_list, link) {
88 free(configured_output->name);
89 free(configured_output->icc_profile);
90 free(configured_output);
96 cms_notifier_destroy(struct wl_listener *listener, void *data)
98 struct cms_static *cms = container_of(listener, struct cms_static, destroy_listener);
99 cms_module_destroy(cms);
102 static char *output_icc_profile;
103 static char *output_name;
106 output_section_done(void *data)
108 struct cms_configured_output *configured_output;
109 struct cms_static *cms = (struct cms_static *) data;
111 if (output_name == NULL || output_icc_profile == NULL) {
113 free(output_icc_profile);
115 output_icc_profile = NULL;
119 weston_log("cms-static: output %s profile configured as %s\n",
120 output_name, output_icc_profile);
122 /* create an object used to store name<->profile data to avoid parsing
123 * the config file every time a new output is added */
124 configured_output = malloc(sizeof *configured_output);
125 memset(configured_output, 0, sizeof *configured_output);
126 configured_output->name = output_name;
127 configured_output->icc_profile = output_icc_profile;
128 wl_list_insert(&cms->configured_output_list, &configured_output->link);
130 output_icc_profile = NULL;
134 module_init(struct weston_compositor *ec,
135 int *argc, char *argv[])
137 struct cms_static *cms;
138 struct weston_output *output;
140 weston_log("cms-static: initialized\n");
142 /* create local state object */
143 cms = malloc(sizeof *cms);
146 memset(cms, 0, sizeof *cms);
148 wl_list_init(&cms->configured_output_list);
150 /* parse config file */
151 const struct config_key drm_config_keys[] = {
152 { "name", CONFIG_KEY_STRING, &output_name },
153 { "icc_profile", CONFIG_KEY_STRING, &output_icc_profile },
156 const struct config_section config_section[] = {
157 { "output", drm_config_keys,
158 ARRAY_LENGTH(drm_config_keys), output_section_done },
161 parse_config_file(ec->config_fd, config_section,
162 ARRAY_LENGTH(config_section), cms);
164 cms->destroy_listener.notify = cms_notifier_destroy;
165 wl_signal_add(&ec->destroy_signal, &cms->destroy_listener);
167 cms->output_created_listener.notify = cms_notifier_output_created;
168 wl_signal_add(&ec->output_created_signal, &cms->output_created_listener);
170 /* discover outputs */
171 wl_list_for_each(output, &ec->output_list, link)
172 cms_output_created(cms, output);