color-noop: add stock color profile

In the next commit we introduce a function to get the stock sRGB color
profile from the color-manager, so mock a stock color profile in the
color-noop.

It has no valid content, but should make callers happy. This is safe to
do because the color profile is opaque, and only color-noop itself
should have access to its content.

color-lcms already has a stock sRGB color profile, so we don't have
to do anything there.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
This commit is contained in:
Leandro Ribeiro 2023-10-06 13:56:09 -03:00 committed by Pekka Paalanen
parent 33ed93561e
commit 154ce42b8c

View File

@ -31,8 +31,13 @@
#include "shared/helpers.h"
#include "shared/xalloc.h"
struct cmnoop_color_profile {
struct weston_color_profile base;
};
struct weston_color_manager_noop {
struct weston_color_manager base;
struct cmnoop_color_profile *stock_cprof; /* no real content */
};
static bool
@ -53,10 +58,47 @@ get_cmnoop(struct weston_color_manager *cm_base)
return container_of(cm_base, struct weston_color_manager_noop, base);
}
static void
cmnoop_destroy_color_profile(struct weston_color_profile *cprof)
static inline struct cmnoop_color_profile *
get_cprof(struct weston_color_profile *cprof_base)
{
/* Never called, as never creates an actual color profile. */
return container_of(cprof_base, struct cmnoop_color_profile, base);
}
static void
unref_cprof(struct cmnoop_color_profile *cprof)
{
if (!cprof)
return;
weston_color_profile_unref(&cprof->base);
}
static void
cmnoop_color_profile_destroy(struct cmnoop_color_profile *cprof)
{
free(cprof->base.description);
free(cprof);
}
static void
cmnoop_destroy_color_profile(struct weston_color_profile *cprof_base)
{
struct cmnoop_color_profile *cprof = get_cprof(cprof_base);
cmnoop_color_profile_destroy(cprof);
}
static struct cmnoop_color_profile *
cmnoop_color_profile_create(struct weston_color_manager_noop *cm, char *desc)
{
struct cmnoop_color_profile *cprof;
cprof = xzalloc(sizeof *cprof);
weston_color_profile_init(&cprof->base, &cm->base);
cprof->base.description = desc;
return cprof;
}
static bool
@ -119,11 +161,31 @@ cmnoop_create_output_color_outcome(struct weston_color_manager *cm_base,
return co;
}
static bool
cmnoop_create_stock_profile(struct weston_color_manager_noop *cm)
{
char *desc;
desc = xstrdup("stock sRGB color profile");
cm->stock_cprof = cmnoop_color_profile_create(cm, desc);
if (!cm->stock_cprof) {
free(desc);
return false;
}
return true;
}
static bool
cmnoop_init(struct weston_color_manager *cm_base)
{
struct weston_color_manager_noop *cm = get_cmnoop(cm_base);
if (!cmnoop_create_stock_profile(cm))
return false;
/* No renderer requirements to check. */
/* Nothing to initialize. */
return true;
}
@ -132,6 +194,9 @@ cmnoop_destroy(struct weston_color_manager *cm_base)
{
struct weston_color_manager_noop *cmnoop = get_cmnoop(cm_base);
assert(cmnoop->stock_cprof->base.ref_count == 1);
unref_cprof(cmnoop->stock_cprof);
free(cmnoop);
}