Richard Hughes | b24e48e | 2013-05-09 20:31:09 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2013 Richard Hughes |
| 3 | * |
Bryce Harrington | a0bbfea | 2015-06-11 15:35:43 -0700 | [diff] [blame] | 4 | * 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 Hughes | b24e48e | 2013-05-09 20:31:09 +0100 | [diff] [blame] | 11 | * |
Bryce Harrington | a0bbfea | 2015-06-11 15:35:43 -0700 | [diff] [blame] | 12 | * 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 Hughes | b24e48e | 2013-05-09 20:31:09 +0100 | [diff] [blame] | 24 | */ |
| 25 | |
Daniel Stone | c228e23 | 2013-05-22 18:03:19 +0300 | [diff] [blame] | 26 | #include "config.h" |
Richard Hughes | b24e48e | 2013-05-09 20:31:09 +0100 | [diff] [blame] | 27 | |
Richard Hughes | b24e48e | 2013-05-09 20:31:09 +0100 | [diff] [blame] | 28 | #include <stdlib.h> |
| 29 | #include <string.h> |
| 30 | |
| 31 | #include "compositor.h" |
| 32 | #include "cms-helper.h" |
Jon Cruz | 867d50e | 2015-06-15 15:37:10 -0700 | [diff] [blame] | 33 | #include "shared/helpers.h" |
Richard Hughes | b24e48e | 2013-05-09 20:31:09 +0100 | [diff] [blame] | 34 | |
| 35 | struct cms_static { |
| 36 | struct weston_compositor *ec; |
| 37 | struct wl_listener destroy_listener; |
| 38 | struct wl_listener output_created_listener; |
Richard Hughes | b24e48e | 2013-05-09 20:31:09 +0100 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | static void |
| 42 | cms_output_created(struct cms_static *cms, struct weston_output *o) |
| 43 | { |
Richard Hughes | b24e48e | 2013-05-09 20:31:09 +0100 | [diff] [blame] | 44 | struct weston_color_profile *p; |
Kristian Høgsberg | 7bedae1 | 2013-05-23 16:06:56 -0400 | [diff] [blame] | 45 | struct weston_config_section *s; |
| 46 | char *profile; |
Richard Hughes | b24e48e | 2013-05-09 20:31:09 +0100 | [diff] [blame] | 47 | |
| 48 | weston_log("cms-static: output %i [%s] created\n", o->id, o->name); |
| 49 | |
Kristian Høgsberg | 115b0f7 | 2013-05-26 21:30:14 -0400 | [diff] [blame] | 50 | if (o->name == NULL) |
| 51 | return; |
Kristian Høgsberg | 7bedae1 | 2013-05-23 16:06:56 -0400 | [diff] [blame] | 52 | s = weston_config_get_section(cms->ec->config, |
| 53 | "output", "name", o->name); |
| 54 | if (s == NULL) |
| 55 | return; |
| 56 | if (weston_config_section_get_string(s, "icc_profile", &profile, NULL) < 0) |
| 57 | return; |
| 58 | p = weston_cms_load_profile(profile); |
Mario Kleiner | 7e07db9 | 2015-07-18 08:10:58 +0200 | [diff] [blame^] | 59 | if (p == NULL && strlen(profile) > 0) { |
Kristian Høgsberg | 7bedae1 | 2013-05-23 16:06:56 -0400 | [diff] [blame] | 60 | weston_log("cms-static: failed to load %s\n", profile); |
| 61 | } else { |
| 62 | weston_log("cms-static: loading %s for %s\n", |
Mario Kleiner | 7e07db9 | 2015-07-18 08:10:58 +0200 | [diff] [blame^] | 63 | (p != NULL) ? profile : "identity LUT", |
| 64 | o->name); |
Kristian Høgsberg | 7bedae1 | 2013-05-23 16:06:56 -0400 | [diff] [blame] | 65 | weston_cms_set_color_profile(o, p); |
Richard Hughes | b24e48e | 2013-05-09 20:31:09 +0100 | [diff] [blame] | 66 | } |
| 67 | } |
| 68 | |
| 69 | static void |
| 70 | cms_notifier_output_created(struct wl_listener *listener, void *data) |
| 71 | { |
| 72 | struct weston_output *o = (struct weston_output *) data; |
Kristian Høgsberg | d7ab5b8 | 2013-05-21 11:44:22 -0400 | [diff] [blame] | 73 | struct cms_static *cms = |
| 74 | container_of(listener, struct cms_static, output_created_listener); |
Richard Hughes | b24e48e | 2013-05-09 20:31:09 +0100 | [diff] [blame] | 75 | cms_output_created(cms, o); |
| 76 | } |
| 77 | |
| 78 | static void |
| 79 | cms_module_destroy(struct cms_static *cms) |
| 80 | { |
Richard Hughes | b24e48e | 2013-05-09 20:31:09 +0100 | [diff] [blame] | 81 | free(cms); |
| 82 | } |
| 83 | |
| 84 | static void |
| 85 | cms_notifier_destroy(struct wl_listener *listener, void *data) |
| 86 | { |
| 87 | struct cms_static *cms = container_of(listener, struct cms_static, destroy_listener); |
| 88 | cms_module_destroy(cms); |
| 89 | } |
| 90 | |
Richard Hughes | b24e48e | 2013-05-09 20:31:09 +0100 | [diff] [blame] | 91 | |
| 92 | WL_EXPORT int |
| 93 | module_init(struct weston_compositor *ec, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 94 | int *argc, char *argv[]) |
Richard Hughes | b24e48e | 2013-05-09 20:31:09 +0100 | [diff] [blame] | 95 | { |
| 96 | struct cms_static *cms; |
| 97 | struct weston_output *output; |
| 98 | |
| 99 | weston_log("cms-static: initialized\n"); |
| 100 | |
| 101 | /* create local state object */ |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 102 | cms = zalloc(sizeof *cms); |
Richard Hughes | b24e48e | 2013-05-09 20:31:09 +0100 | [diff] [blame] | 103 | if (cms == NULL) |
| 104 | return -1; |
Richard Hughes | b24e48e | 2013-05-09 20:31:09 +0100 | [diff] [blame] | 105 | |
Kristian Høgsberg | 7bedae1 | 2013-05-23 16:06:56 -0400 | [diff] [blame] | 106 | cms->ec = ec; |
Richard Hughes | b24e48e | 2013-05-09 20:31:09 +0100 | [diff] [blame] | 107 | cms->destroy_listener.notify = cms_notifier_destroy; |
| 108 | wl_signal_add(&ec->destroy_signal, &cms->destroy_listener); |
| 109 | |
| 110 | cms->output_created_listener.notify = cms_notifier_output_created; |
| 111 | wl_signal_add(&ec->output_created_signal, &cms->output_created_listener); |
| 112 | |
| 113 | /* discover outputs */ |
| 114 | wl_list_for_each(output, &ec->output_list, link) |
| 115 | cms_output_created(cms, output); |
| 116 | |
| 117 | return 0; |
| 118 | } |