blob: b3fbe5ef2666c60889cd48ca2a6b515ef6832656 [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
23#ifdef HAVE_CONFIG_H
24#include <config.h>
25#endif
26
27#define _GNU_SOURCE
28#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øgsberg7bedae12013-05-23 16:06:56 -040049 s = weston_config_get_section(cms->ec->config,
50 "output", "name", o->name);
51 if (s == NULL)
52 return;
53 if (weston_config_section_get_string(s, "icc_profile", &profile, NULL) < 0)
54 return;
55 p = weston_cms_load_profile(profile);
56 if (p == NULL) {
57 weston_log("cms-static: failed to load %s\n", profile);
58 } else {
59 weston_log("cms-static: loading %s for %s\n",
60 profile, o->name);
61 weston_cms_set_color_profile(o, p);
Richard Hughesb24e48e2013-05-09 20:31:09 +010062 }
63}
64
65static void
66cms_notifier_output_created(struct wl_listener *listener, void *data)
67{
68 struct weston_output *o = (struct weston_output *) data;
Kristian Høgsbergd7ab5b82013-05-21 11:44:22 -040069 struct cms_static *cms =
70 container_of(listener, struct cms_static, output_created_listener);
Richard Hughesb24e48e2013-05-09 20:31:09 +010071 cms_output_created(cms, o);
72}
73
74static void
75cms_module_destroy(struct cms_static *cms)
76{
Richard Hughesb24e48e2013-05-09 20:31:09 +010077 free(cms);
78}
79
80static void
81cms_notifier_destroy(struct wl_listener *listener, void *data)
82{
83 struct cms_static *cms = container_of(listener, struct cms_static, destroy_listener);
84 cms_module_destroy(cms);
85}
86
Richard Hughesb24e48e2013-05-09 20:31:09 +010087
88WL_EXPORT int
89module_init(struct weston_compositor *ec,
Ossama Othmana50e6e42013-05-14 09:48:26 -070090 int *argc, char *argv[])
Richard Hughesb24e48e2013-05-09 20:31:09 +010091{
92 struct cms_static *cms;
93 struct weston_output *output;
94
95 weston_log("cms-static: initialized\n");
96
97 /* create local state object */
98 cms = malloc(sizeof *cms);
99 if (cms == NULL)
100 return -1;
101 memset(cms, 0, sizeof *cms);
102
Kristian Høgsberg7bedae12013-05-23 16:06:56 -0400103 cms->ec = ec;
Richard Hughesb24e48e2013-05-09 20:31:09 +0100104 cms->destroy_listener.notify = cms_notifier_destroy;
105 wl_signal_add(&ec->destroy_signal, &cms->destroy_listener);
106
107 cms->output_created_listener.notify = cms_notifier_output_created;
108 wl_signal_add(&ec->output_created_signal, &cms->output_created_listener);
109
110 /* discover outputs */
111 wl_list_for_each(output, &ec->output_list, link)
112 cms_output_created(cms, output);
113
114 return 0;
115}