blob: ad54fd15bf9d7da8c0fbd93936b3f98e8da905f3 [file] [log] [blame]
Richard Hughesb24e48e2013-05-09 20:31:09 +01001/*
2 * Copyright © 2013 Richard Hughes
3 *
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.
13 *
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.
21 */
22
Daniel Stonec228e232013-05-22 18:03:19 +030023#include "config.h"
Richard Hughesb24e48e2013-05-09 20:31:09 +010024
Richard Hughesb24e48e2013-05-09 20:31:09 +010025#include <stdlib.h>
26#include <string.h>
27
28#include "compositor.h"
29#include "cms-helper.h"
30
31struct cms_static {
32 struct weston_compositor *ec;
33 struct wl_listener destroy_listener;
34 struct wl_listener output_created_listener;
Richard Hughesb24e48e2013-05-09 20:31:09 +010035};
36
37static void
38cms_output_created(struct cms_static *cms, struct weston_output *o)
39{
Richard Hughesb24e48e2013-05-09 20:31:09 +010040 struct weston_color_profile *p;
Kristian Høgsberg7bedae12013-05-23 16:06:56 -040041 struct weston_config_section *s;
42 char *profile;
Richard Hughesb24e48e2013-05-09 20:31:09 +010043
44 weston_log("cms-static: output %i [%s] created\n", o->id, o->name);
45
Kristian Høgsberg115b0f72013-05-26 21:30:14 -040046 if (o->name == NULL)
47 return;
Kristian Høgsberg7bedae12013-05-23 16:06:56 -040048 s = weston_config_get_section(cms->ec->config,
49 "output", "name", o->name);
50 if (s == NULL)
51 return;
52 if (weston_config_section_get_string(s, "icc_profile", &profile, NULL) < 0)
53 return;
54 p = weston_cms_load_profile(profile);
55 if (p == NULL) {
56 weston_log("cms-static: failed to load %s\n", profile);
57 } else {
58 weston_log("cms-static: loading %s for %s\n",
59 profile, o->name);
60 weston_cms_set_color_profile(o, p);
Richard Hughesb24e48e2013-05-09 20:31:09 +010061 }
62}
63
64static void
65cms_notifier_output_created(struct wl_listener *listener, void *data)
66{
67 struct weston_output *o = (struct weston_output *) data;
Kristian Høgsbergd7ab5b82013-05-21 11:44:22 -040068 struct cms_static *cms =
69 container_of(listener, struct cms_static, output_created_listener);
Richard Hughesb24e48e2013-05-09 20:31:09 +010070 cms_output_created(cms, o);
71}
72
73static void
74cms_module_destroy(struct cms_static *cms)
75{
Richard Hughesb24e48e2013-05-09 20:31:09 +010076 free(cms);
77}
78
79static void
80cms_notifier_destroy(struct wl_listener *listener, void *data)
81{
82 struct cms_static *cms = container_of(listener, struct cms_static, destroy_listener);
83 cms_module_destroy(cms);
84}
85
Richard Hughesb24e48e2013-05-09 20:31:09 +010086
87WL_EXPORT int
88module_init(struct weston_compositor *ec,
Ossama Othmana50e6e42013-05-14 09:48:26 -070089 int *argc, char *argv[])
Richard Hughesb24e48e2013-05-09 20:31:09 +010090{
91 struct cms_static *cms;
92 struct weston_output *output;
93
94 weston_log("cms-static: initialized\n");
95
96 /* create local state object */
Peter Huttererf3d62272013-08-08 11:57:05 +100097 cms = zalloc(sizeof *cms);
Richard Hughesb24e48e2013-05-09 20:31:09 +010098 if (cms == NULL)
99 return -1;
Richard Hughesb24e48e2013-05-09 20:31:09 +0100100
Kristian Høgsberg7bedae12013-05-23 16:06:56 -0400101 cms->ec = ec;
Richard Hughesb24e48e2013-05-09 20:31:09 +0100102 cms->destroy_listener.notify = cms_notifier_destroy;
103 wl_signal_add(&ec->destroy_signal, &cms->destroy_listener);
104
105 cms->output_created_listener.notify = cms_notifier_output_created;
106 wl_signal_add(&ec->output_created_signal, &cms->output_created_listener);
107
108 /* discover outputs */
109 wl_list_for_each(output, &ec->output_list, link)
110 cms_output_created(cms, output);
111
112 return 0;
113}