color-lcms: add debug scope for color profiles

It prints the existent color profiles for new subscribers. Also prints
any creation/destruction of color profiles.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
This commit is contained in:
Leandro Ribeiro 2023-03-06 17:25:49 -03:00 committed by Pekka Paalanen
parent d827bdd5d4
commit a28e0c26e1
3 changed files with 59 additions and 1 deletions

View File

@ -389,6 +389,7 @@ cmlcms_destroy(struct weston_color_manager *cm_base)
cmsDeleteContext(cm->lcms_ctx);
weston_log_scope_destroy(cm->transforms_scope);
weston_log_scope_destroy(cm->profiles_scope);
free(cm);
}
@ -417,6 +418,26 @@ transforms_scope_new_sub(struct weston_log_subscription *subs, void *data)
}
}
static void
profiles_scope_new_sub(struct weston_log_subscription *subs, void *data)
{
struct weston_color_manager_lcms *cm = data;
struct cmlcms_color_profile *cprof;
char *str;
if (wl_list_empty(&cm->color_profile_list))
return;
weston_log_subscription_printf(subs, "Existent:\n");
wl_list_for_each(cprof, &cm->color_profile_list, link) {
weston_log_subscription_printf(subs, "Color profile %p:\n", cprof);
str = cmlcms_color_profile_print(cprof);
weston_log_subscription_printf(subs, "%s", str);
free(str);
}
}
WL_EXPORT struct weston_color_manager *
weston_color_manager_create(struct weston_compositor *compositor)
{
@ -444,12 +465,19 @@ weston_color_manager_create(struct weston_compositor *compositor)
weston_compositor_add_log_scope(compositor, "color-lcms-transformations",
"Color transformation creation and destruction.\n",
transforms_scope_new_sub, NULL, cm);
if (!cm->transforms_scope)
cm->profiles_scope =
weston_compositor_add_log_scope(compositor, "color-lcms-profiles",
"Color profile creation and destruction.\n",
profiles_scope_new_sub, NULL, cm);
if (!cm->profiles_scope || !cm->transforms_scope)
goto err;
return &cm->base;
err:
weston_log_scope_destroy(cm->transforms_scope);
weston_log_scope_destroy(cm->profiles_scope);
free(cm);
return NULL;
}

View File

@ -36,6 +36,7 @@
struct weston_color_manager_lcms {
struct weston_color_manager base;
struct weston_log_scope *profiles_scope;
struct weston_log_scope *transforms_scope;
cmsContext lcms_ctx;
@ -222,6 +223,9 @@ cmlcms_create_stock_profile(struct weston_color_manager_lcms *cm);
void
cmlcms_color_profile_destroy(struct cmlcms_color_profile *cprof);
char *
cmlcms_color_profile_print(const struct cmlcms_color_profile *cprof);
bool
retrieve_eotf_and_output_inv_eotf(cmsContext lcms_ctx,
cmsHPROFILE hProfile,

View File

@ -35,6 +35,7 @@
#include "color-lcms.h"
#include "shared/helpers.h"
#include "shared/string-helpers.h"
#include "shared/xalloc.h"
struct xyz_arr_flt {
float v[3];
@ -298,6 +299,17 @@ cmlcms_find_color_profile_by_md5(const struct weston_color_manager_lcms *cm,
return NULL;
}
char *
cmlcms_color_profile_print(const struct cmlcms_color_profile *cprof)
{
char *str;
str_printf(&str, " description: %s\n", cprof->base.description);
abort_oom_if_null(str);
return str;
}
static struct cmlcms_color_profile *
cmlcms_color_profile_create(struct weston_color_manager_lcms *cm,
cmsHPROFILE profile,
@ -305,6 +317,7 @@ cmlcms_color_profile_create(struct weston_color_manager_lcms *cm,
char **errmsg)
{
struct cmlcms_color_profile *cprof;
char *str;
cprof = zalloc(sizeof *cprof);
if (!cprof)
@ -316,17 +329,30 @@ cmlcms_color_profile_create(struct weston_color_manager_lcms *cm,
cmsGetHeaderProfileID(profile, cprof->md5sum.bytes);
wl_list_insert(&cm->color_profile_list, &cprof->link);
weston_log_scope_printf(cm->profiles_scope,
"New color profile: %p\n", cprof);
str = cmlcms_color_profile_print(cprof);
weston_log_scope_printf(cm->profiles_scope, "%s", str);
free(str);
return cprof;
}
void
cmlcms_color_profile_destroy(struct cmlcms_color_profile *cprof)
{
struct weston_color_manager_lcms *cm = get_cmlcms(cprof->base.cm);
wl_list_remove(&cprof->link);
cmsFreeToneCurveTriple(cprof->vcgt);
cmsFreeToneCurveTriple(cprof->eotf);
cmsFreeToneCurveTriple(cprof->output_inv_eotf_vcgt);
cmsCloseProfile(cprof->profile);
weston_log_scope_printf(cm->profiles_scope, "Destroyed color profile %p. " \
"Description: %s\n", cprof, cprof->base.description);
free(cprof->base.description);
free(cprof);
}