From 977c41a65c96e4ffdbd333de41c7c26303d3f149 Mon Sep 17 00:00:00 2001 From: Leandro Ribeiro Date: Fri, 6 Oct 2023 14:02:36 -0300 Subject: [PATCH] color: add get_stock_sRGB_color_profile() to color manager In the next commit we'll stop using NULL as the stock sRGB color profile, so add a function to the color manager to allow libweston core to have access to the stock sRGB profile. Signed-off-by: Leandro Ribeiro --- libweston/color-lcms/color-lcms.c | 1 + libweston/color-lcms/color-lcms.h | 3 +++ libweston/color-lcms/color-profile.c | 11 +++++++++++ libweston/color-noop.c | 22 ++++++++++++++++++++++ libweston/color.h | 8 ++++++++ 5 files changed, 45 insertions(+) diff --git a/libweston/color-lcms/color-lcms.c b/libweston/color-lcms/color-lcms.c index ba8e404f..4b56dc14 100644 --- a/libweston/color-lcms/color-lcms.c +++ b/libweston/color-lcms/color-lcms.c @@ -457,6 +457,7 @@ weston_color_manager_create(struct weston_compositor *compositor) cm->base.init = cmlcms_init; cm->base.destroy = cmlcms_destroy; cm->base.destroy_color_profile = cmlcms_destroy_color_profile; + cm->base.get_stock_sRGB_color_profile = cmlcms_get_stock_sRGB_color_profile; cm->base.get_color_profile_from_icc = cmlcms_get_color_profile_from_icc; cm->base.destroy_color_transform = cmlcms_destroy_color_transform; cm->base.get_surface_color_transform = cmlcms_get_surface_color_transform; diff --git a/libweston/color-lcms/color-lcms.h b/libweston/color-lcms/color-lcms.h index 4cf149f4..20461fce 100644 --- a/libweston/color-lcms/color-lcms.h +++ b/libweston/color-lcms/color-lcms.h @@ -127,6 +127,9 @@ get_cprof(struct weston_color_profile *cprof_base) return container_of(cprof_base, struct cmlcms_color_profile, base); } +struct weston_color_profile * +cmlcms_get_stock_sRGB_color_profile(struct weston_color_manager *cm_base); + bool cmlcms_get_color_profile_from_icc(struct weston_color_manager *cm, const void *icc_data, diff --git a/libweston/color-lcms/color-profile.c b/libweston/color-lcms/color-profile.c index 6fa9cd04..00e0ac5d 100644 --- a/libweston/color-lcms/color-profile.c +++ b/libweston/color-lcms/color-profile.c @@ -442,6 +442,17 @@ err_close: return false; } +struct weston_color_profile * +cmlcms_get_stock_sRGB_color_profile(struct weston_color_manager *cm_base) +{ + struct weston_color_manager_lcms *cm = get_cmlcms(cm_base); + struct cmlcms_color_profile *cprof; + + cprof = ref_cprof(cm->sRGB_profile); + + return &cprof->base; +} + bool cmlcms_get_color_profile_from_icc(struct weston_color_manager *cm_base, const void *icc_data, diff --git a/libweston/color-noop.c b/libweston/color-noop.c index 0cf1d913..b7236e88 100644 --- a/libweston/color-noop.c +++ b/libweston/color-noop.c @@ -64,6 +64,16 @@ get_cprof(struct weston_color_profile *cprof_base) return container_of(cprof_base, struct cmnoop_color_profile, base); } +static struct cmnoop_color_profile * +ref_cprof(struct cmnoop_color_profile *cprof) +{ + if (!cprof) + return NULL; + + weston_color_profile_ref(&cprof->base); + return cprof; +} + static void unref_cprof(struct cmnoop_color_profile *cprof) { @@ -101,6 +111,17 @@ cmnoop_color_profile_create(struct weston_color_manager_noop *cm, char *desc) return cprof; } +static struct weston_color_profile * +cmnoop_get_stock_sRGB_color_profile(struct weston_color_manager *cm_base) +{ + struct weston_color_manager_noop *cm = get_cmnoop(cm_base); + struct cmnoop_color_profile *cprof; + + cprof = ref_cprof(cm->stock_cprof); + + return &cprof->base; +} + static bool cmnoop_get_color_profile_from_icc(struct weston_color_manager *cm, const void *icc_data, @@ -213,6 +234,7 @@ weston_color_manager_noop_create(struct weston_compositor *compositor) cm->base.init = cmnoop_init; cm->base.destroy = cmnoop_destroy; cm->base.destroy_color_profile = cmnoop_destroy_color_profile; + cm->base.get_stock_sRGB_color_profile = cmnoop_get_stock_sRGB_color_profile; cm->base.get_color_profile_from_icc = cmnoop_get_color_profile_from_icc; cm->base.destroy_color_transform = cmnoop_destroy_color_transform; cm->base.get_surface_color_transform = cmnoop_get_surface_color_transform; diff --git a/libweston/color.h b/libweston/color.h index 96d0d28f..f630f237 100644 --- a/libweston/color.h +++ b/libweston/color.h @@ -262,6 +262,14 @@ struct weston_color_manager { void (*destroy_color_profile)(struct weston_color_profile *cprof); + /** Gets a reference to the stock sRGB color profile + * + * \param cm The color manager. + * \return A reference to the stock sRGB profile, never returns NULL. + */ + struct weston_color_profile * + (*get_stock_sRGB_color_profile)(struct weston_color_manager *cm); + /** Create a color profile from ICC data * * \param cm The color manager.