blob: 2a3ca75bc7dceada0334c15d7aa514cbb2e0b8b7 [file] [log] [blame]
Richard Hughesb24e48e2013-05-09 20:31:09 +01001/*
2 * Copyright © 2013 Richard Hughes
3 *
Bryce Harringtona0bbfea2015-06-11 15:35:43 -07004 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
Richard Hughesb24e48e2013-05-09 20:31:09 +010011 *
Bryce Harringtona0bbfea2015-06-11 15:35:43 -070012 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
Richard Hughesb24e48e2013-05-09 20:31:09 +010024 */
25
Daniel Stonec228e232013-05-22 18:03:19 +030026#include "config.h"
Richard Hughesb24e48e2013-05-09 20:31:09 +010027
Richard Hughesb24e48e2013-05-09 20:31:09 +010028#include <stdlib.h>
29#include <string.h>
30
31#include "compositor.h"
32#include "cms-helper.h"
33
34struct cms_static {
35 struct weston_compositor *ec;
36 struct wl_listener destroy_listener;
37 struct wl_listener output_created_listener;
Richard Hughesb24e48e2013-05-09 20:31:09 +010038};
39
40static void
41cms_output_created(struct cms_static *cms, struct weston_output *o)
42{
Richard Hughesb24e48e2013-05-09 20:31:09 +010043 struct weston_color_profile *p;
Kristian Høgsberg7bedae12013-05-23 16:06:56 -040044 struct weston_config_section *s;
45 char *profile;
Richard Hughesb24e48e2013-05-09 20:31:09 +010046
47 weston_log("cms-static: output %i [%s] created\n", o->id, o->name);
48
Kristian Høgsberg115b0f72013-05-26 21:30:14 -040049 if (o->name == NULL)
50 return;
Kristian Høgsberg7bedae12013-05-23 16:06:56 -040051 s = weston_config_get_section(cms->ec->config,
52 "output", "name", o->name);
53 if (s == NULL)
54 return;
55 if (weston_config_section_get_string(s, "icc_profile", &profile, NULL) < 0)
56 return;
57 p = weston_cms_load_profile(profile);
58 if (p == NULL) {
59 weston_log("cms-static: failed to load %s\n", profile);
60 } else {
61 weston_log("cms-static: loading %s for %s\n",
62 profile, o->name);
63 weston_cms_set_color_profile(o, p);
Richard Hughesb24e48e2013-05-09 20:31:09 +010064 }
65}
66
67static void
68cms_notifier_output_created(struct wl_listener *listener, void *data)
69{
70 struct weston_output *o = (struct weston_output *) data;
Kristian Høgsbergd7ab5b82013-05-21 11:44:22 -040071 struct cms_static *cms =
72 container_of(listener, struct cms_static, output_created_listener);
Richard Hughesb24e48e2013-05-09 20:31:09 +010073 cms_output_created(cms, o);
74}
75
76static void
77cms_module_destroy(struct cms_static *cms)
78{
Richard Hughesb24e48e2013-05-09 20:31:09 +010079 free(cms);
80}
81
82static void
83cms_notifier_destroy(struct wl_listener *listener, void *data)
84{
85 struct cms_static *cms = container_of(listener, struct cms_static, destroy_listener);
86 cms_module_destroy(cms);
87}
88
Richard Hughesb24e48e2013-05-09 20:31:09 +010089
90WL_EXPORT int
91module_init(struct weston_compositor *ec,
Ossama Othmana50e6e42013-05-14 09:48:26 -070092 int *argc, char *argv[])
Richard Hughesb24e48e2013-05-09 20:31:09 +010093{
94 struct cms_static *cms;
95 struct weston_output *output;
96
97 weston_log("cms-static: initialized\n");
98
99 /* create local state object */
Peter Huttererf3d62272013-08-08 11:57:05 +1000100 cms = zalloc(sizeof *cms);
Richard Hughesb24e48e2013-05-09 20:31:09 +0100101 if (cms == NULL)
102 return -1;
Richard Hughesb24e48e2013-05-09 20:31:09 +0100103
Kristian Høgsberg7bedae12013-05-23 16:06:56 -0400104 cms->ec = ec;
Richard Hughesb24e48e2013-05-09 20:31:09 +0100105 cms->destroy_listener.notify = cms_notifier_destroy;
106 wl_signal_add(&ec->destroy_signal, &cms->destroy_listener);
107
108 cms->output_created_listener.notify = cms_notifier_output_created;
109 wl_signal_add(&ec->output_created_signal, &cms->output_created_listener);
110
111 /* discover outputs */
112 wl_list_for_each(output, &ec->output_list, link)
113 cms_output_created(cms, output);
114
115 return 0;
116}