Richard Hughes | b24e48e | 2013-05-09 20:31:09 +0100 | [diff] [blame] | 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 | |
Daniel Stone | c228e23 | 2013-05-22 18:03:19 +0300 | [diff] [blame] | 23 | #include "config.h" |
Richard Hughes | b24e48e | 2013-05-09 20:31:09 +0100 | [diff] [blame] | 24 | |
Richard Hughes | b24e48e | 2013-05-09 20:31:09 +0100 | [diff] [blame] | 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; |
Richard Hughes | b24e48e | 2013-05-09 20:31:09 +0100 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | static void |
| 38 | cms_output_created(struct cms_static *cms, struct weston_output *o) |
| 39 | { |
Richard Hughes | b24e48e | 2013-05-09 20:31:09 +0100 | [diff] [blame] | 40 | struct weston_color_profile *p; |
Kristian Høgsberg | 7bedae1 | 2013-05-23 16:06:56 -0400 | [diff] [blame] | 41 | struct weston_config_section *s; |
| 42 | char *profile; |
Richard Hughes | b24e48e | 2013-05-09 20:31:09 +0100 | [diff] [blame] | 43 | |
| 44 | weston_log("cms-static: output %i [%s] created\n", o->id, o->name); |
| 45 | |
Kristian Høgsberg | 115b0f7 | 2013-05-26 21:30:14 -0400 | [diff] [blame] | 46 | if (o->name == NULL) |
| 47 | return; |
Kristian Høgsberg | 7bedae1 | 2013-05-23 16:06:56 -0400 | [diff] [blame] | 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); |
Richard Hughes | b24e48e | 2013-05-09 20:31:09 +0100 | [diff] [blame] | 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; |
Kristian Høgsberg | d7ab5b8 | 2013-05-21 11:44:22 -0400 | [diff] [blame] | 68 | struct cms_static *cms = |
| 69 | container_of(listener, struct cms_static, output_created_listener); |
Richard Hughes | b24e48e | 2013-05-09 20:31:09 +0100 | [diff] [blame] | 70 | cms_output_created(cms, o); |
| 71 | } |
| 72 | |
| 73 | static void |
| 74 | cms_module_destroy(struct cms_static *cms) |
| 75 | { |
Richard Hughes | b24e48e | 2013-05-09 20:31:09 +0100 | [diff] [blame] | 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 | |
Richard Hughes | b24e48e | 2013-05-09 20:31:09 +0100 | [diff] [blame] | 86 | |
| 87 | WL_EXPORT int |
| 88 | module_init(struct weston_compositor *ec, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 89 | int *argc, char *argv[]) |
Richard Hughes | b24e48e | 2013-05-09 20:31:09 +0100 | [diff] [blame] | 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 */ |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame^] | 97 | cms = zalloc(sizeof *cms); |
Richard Hughes | b24e48e | 2013-05-09 20:31:09 +0100 | [diff] [blame] | 98 | if (cms == NULL) |
| 99 | return -1; |
Richard Hughes | b24e48e | 2013-05-09 20:31:09 +0100 | [diff] [blame] | 100 | |
Kristian Høgsberg | 7bedae1 | 2013-05-23 16:06:56 -0400 | [diff] [blame] | 101 | cms->ec = ec; |
Richard Hughes | b24e48e | 2013-05-09 20:31:09 +0100 | [diff] [blame] | 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 | } |