compositor-drm: Work around page flip not setting tiling mode on BYT
[platform/upstream/weston.git] / src / cms-static.c
1 /*
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 #include "config.h"
24
25 #include <stdlib.h>
26 #include <string.h>
27
28 #include "compositor.h"
29 #include "cms-helper.h"
30
31 struct cms_static {
32         struct weston_compositor        *ec;
33         struct wl_listener               destroy_listener;
34         struct wl_listener               output_created_listener;
35 };
36
37 static void
38 cms_output_created(struct cms_static *cms, struct weston_output *o)
39 {
40         struct weston_color_profile *p;
41         struct weston_config_section *s;
42         char *profile;
43
44         weston_log("cms-static: output %i [%s] created\n", o->id, o->name);
45
46         if (o->name == NULL)
47                 return;
48         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);
61         }
62 }
63
64 static void
65 cms_notifier_output_created(struct wl_listener *listener, void *data)
66 {
67         struct weston_output *o = (struct weston_output *) data;
68         struct cms_static *cms =
69                 container_of(listener, struct cms_static, output_created_listener);
70         cms_output_created(cms, o);
71 }
72
73 static void
74 cms_module_destroy(struct cms_static *cms)
75 {
76         free(cms);
77 }
78
79 static void
80 cms_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
86
87 WL_EXPORT int
88 module_init(struct weston_compositor *ec,
89             int *argc, char *argv[])
90 {
91         struct cms_static *cms;
92         struct weston_output *output;
93
94         weston_log("cms-static: initialized\n");
95
96         /* create local state object */
97         cms = zalloc(sizeof *cms);
98         if (cms == NULL)
99                 return -1;
100
101         cms->ec = ec;
102         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 }