From 5e79dd4892e66e04c839f15ea1548c1a9c627595 Mon Sep 17 00:00:00 2001 From: Pekka Paalanen Date: Mon, 29 Mar 2021 14:11:49 +0300 Subject: [PATCH] libweston: begin color-lcms plugin This creates the color-lcms plugin that in the future will be using Little CMS as the color matching module, processing ICC profiles, and producing HDR tone mappings. Right now, this new plugin is functionally equivalent to the no-op color manager, except it already links to lcms2 and checks that the renderer supports color operations. Color-lcms is a libweston plugin that is loaded with explicit weston_compositor API. This does not currently allow loading alternative color manager plugins. External color manager plugins might be considered in the future when the libweston APIs around color management stabilize. This libweston plugin uses the same build option as the old cms-static Weston plugins, as they both need lcms2. The minimum version for lcms2 was chosen by what Debian Buster provides today and for no other reason. This plugin intends to support the Wayland CM&HDR protocol extension and hence sets supports_client_protocol to true. This will expose the protocol extension to clients when it gets implemented. Signed-off-by: Pekka Paalanen --- include/libweston/libweston.h | 3 + libweston/color-lcms/color-lcms.c | 130 ++++++++++++++++++++++++++++++ libweston/color-lcms/color-lcms.h | 44 ++++++++++ libweston/color-lcms/meson.build | 29 +++++++ libweston/color.h | 4 + libweston/compositor.c | 35 ++++++++ libweston/meson.build | 1 + meson_options.txt | 2 +- 8 files changed, 247 insertions(+), 1 deletion(-) create mode 100644 libweston/color-lcms/color-lcms.c create mode 100644 libweston/color-lcms/color-lcms.h create mode 100644 libweston/color-lcms/meson.build diff --git a/include/libweston/libweston.h b/include/libweston/libweston.h index 1173950a..5ee0da8c 100644 --- a/include/libweston/libweston.h +++ b/include/libweston/libweston.h @@ -2001,6 +2001,9 @@ weston_keyboard_send_keymap(struct weston_keyboard *kbd, int weston_compositor_load_xwayland(struct weston_compositor *compositor); +int +weston_compositor_load_color_manager(struct weston_compositor *compositor); + bool weston_head_is_connected(struct weston_head *head); diff --git a/libweston/color-lcms/color-lcms.c b/libweston/color-lcms/color-lcms.c new file mode 100644 index 00000000..efb44d97 --- /dev/null +++ b/libweston/color-lcms/color-lcms.c @@ -0,0 +1,130 @@ +/* + * Copyright 2021 Collabora, Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "config.h" + +#include + +#include + +#include "color.h" +#include "color-lcms.h" +#include "shared/helpers.h" + +static void +cmlcms_destroy_color_transform(struct weston_color_transform *xform_base) +{ +} + +static bool +cmlcms_get_surface_color_transform(struct weston_color_manager *cm_base, + struct weston_surface *surface, + struct weston_output *output, + struct weston_surface_color_transform *surf_xform) +{ + /* Identity transform */ + surf_xform->transform = NULL; + surf_xform->identity_pipeline = true; + + return true; +} + +static bool +cmlcms_get_output_color_transform(struct weston_color_manager *cm_base, + struct weston_output *output, + struct weston_color_transform **xform_out) +{ + /* Identity transform */ + *xform_out = NULL; + + return true; +} + +static bool +cmlcms_get_sRGB_to_output_color_transform(struct weston_color_manager *cm_base, + struct weston_output *output, + struct weston_color_transform **xform_out) +{ + /* Identity transform */ + *xform_out = NULL; + + return true; +} + +static bool +cmlcms_get_sRGB_to_blend_color_transform(struct weston_color_manager *cm_base, + struct weston_output *output, + struct weston_color_transform **xform_out) +{ + /* Identity transform */ + *xform_out = NULL; + + return true; +} + +static bool +cmlcms_init(struct weston_color_manager *cm_base) +{ + if (!(cm_base->compositor->capabilities & WESTON_CAP_COLOR_OPS)) { + weston_log("color-lcms: error: color operations capability missing. Is GL-renderer not in use?\n"); + return false; + } + + return true; +} + +static void +cmlcms_destroy(struct weston_color_manager *cm_base) +{ + struct weston_color_manager_lcms *cmlcms = get_cmlcms(cm_base); + + free(cmlcms); +} + +WL_EXPORT struct weston_color_manager * +weston_color_manager_create(struct weston_compositor *compositor) +{ + struct weston_color_manager_lcms *cm; + + cm = zalloc(sizeof *cm); + if (!cm) + return NULL; + + cm->base.name = "work-in-progress"; + cm->base.compositor = compositor; + cm->base.supports_client_protocol = true; + cm->base.init = cmlcms_init; + cm->base.destroy = cmlcms_destroy; + cm->base.destroy_color_transform = cmlcms_destroy_color_transform; + cm->base.get_surface_color_transform = + cmlcms_get_surface_color_transform; + cm->base.get_output_color_transform = cmlcms_get_output_color_transform; + cm->base.get_sRGB_to_output_color_transform = + cmlcms_get_sRGB_to_output_color_transform; + cm->base.get_sRGB_to_blend_color_transform = + cmlcms_get_sRGB_to_blend_color_transform; + + return &cm->base; +} diff --git a/libweston/color-lcms/color-lcms.h b/libweston/color-lcms/color-lcms.h new file mode 100644 index 00000000..584557c0 --- /dev/null +++ b/libweston/color-lcms/color-lcms.h @@ -0,0 +1,44 @@ +/* + * Copyright 2021 Collabora, Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef WESTON_COLOR_LCMS_H +#define WESTON_COLOR_LCMS_H + +#include + +#include "color.h" +#include "shared/helpers.h" + +struct weston_color_manager_lcms { + struct weston_color_manager base; +}; + +static inline struct weston_color_manager_lcms * +get_cmlcms(struct weston_color_manager *cm_base) +{ + return container_of(cm_base, struct weston_color_manager_lcms, base); +} + +#endif /* WESTON_COLOR_LCMS_H */ diff --git a/libweston/color-lcms/meson.build b/libweston/color-lcms/meson.build new file mode 100644 index 00000000..c1b8ae91 --- /dev/null +++ b/libweston/color-lcms/meson.build @@ -0,0 +1,29 @@ +if not get_option('color-management-lcms') + subdir_done() +endif + +dep_lcms2 = dependency('lcms2', version: '>= 2.9', required: false) +if not dep_lcms2.found() + error('color-lcms plugin requires lcms2 which was not found. Or, you can use \'-Dcolor-management-lcms=false\'.') +endif + +srcs_color_lcms = [ + 'color-lcms.c', +] + +deps_color_lcms = [ + dep_libm, + dep_libweston_private, + dep_lcms2, +] + +plugin_color_lcms = shared_library( + 'color-lcms', + srcs_color_lcms, + include_directories: common_inc, + dependencies: deps_color_lcms, + name_prefix: '', + install: true, + install_dir: dir_module_libweston +) +env_modmap += 'color-lcms.so=@0@;'.format(plugin_color_lcms.full_path()) diff --git a/libweston/color.h b/libweston/color.h index 18f8e4a3..970483e8 100644 --- a/libweston/color.h +++ b/libweston/color.h @@ -235,4 +235,8 @@ weston_paint_node_ensure_color_transform(struct weston_paint_node *pnode); struct weston_color_manager * weston_color_manager_noop_create(struct weston_compositor *compositor); +/* DSO module entrypoint */ +struct weston_color_manager * +weston_color_manager_create(struct weston_compositor *compositor); + #endif /* WESTON_COLOR_H */ diff --git a/libweston/compositor.c b/libweston/compositor.c index e5fcac3a..f762225b 100644 --- a/libweston/compositor.c +++ b/libweston/compositor.c @@ -8267,6 +8267,41 @@ weston_compositor_load_xwayland(struct weston_compositor *compositor) return 0; } +/** Load Little CMS color manager plugin + * + * Calling this function before loading any backend sets Little CMS + * as the active color matching module (CMM) instead of the default no-op + * color manager. + * + * \ingroup compositor + */ +WL_EXPORT int +weston_compositor_load_color_manager(struct weston_compositor *compositor) +{ + struct weston_color_manager * + (*cm_create)(struct weston_compositor *compositor); + + if (compositor->color_manager) { + weston_log("Error: Color manager '%s' is loaded, cannot load another.\n", + compositor->color_manager->name); + return -1; + } + + cm_create = weston_load_module("color-lcms.so", "weston_color_manager_create"); + if (!cm_create) { + weston_log("Error: Could not load color-lcms.so.\n"); + return -1; + } + + compositor->color_manager = cm_create(compositor); + if (!compositor->color_manager) { + weston_log("Error: loading color-lcms.so failed.\n"); + return -1; + } + + return 0; +} + /** Resolve an internal compositor error by disconnecting the client. * * This function is used in cases when the wl_buffer turns out diff --git a/libweston/meson.build b/libweston/meson.build index 8971cbc1..cbf36a80 100644 --- a/libweston/meson.build +++ b/libweston/meson.build @@ -246,6 +246,7 @@ if get_option('weston-launch') meson.add_install_script('echo', 'REMINDER: You are installing weston-launch, please make it setuid-root.') endif +subdir('color-lcms') subdir('renderer-gl') subdir('backend-drm') subdir('backend-fbdev') diff --git a/meson_options.txt b/meson_options.txt index da4ccaab..c7aa9ec0 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -142,7 +142,7 @@ option( 'color-management-lcms', type: 'boolean', value: true, - description: 'Compositor color management: lcms' + description: 'Compositor color management: Little CMS' ) option( 'color-management-colord',