Skip to content
Commits on Source (7)
......@@ -229,22 +229,14 @@ cmlcms_get_hdr_meta(struct weston_output *output,
{
const struct weston_color_characteristics *cc;
/* TODO: get color characteristics from color profiles instead. */
hdr_meta->group_mask = 0;
/* Only SMPTE ST 2084 mode uses HDR Static Metadata Type 1 */
if (weston_output_get_eotf_mode(output) != WESTON_EOTF_MODE_ST2084)
return true;
/* ICC profile overrides color characteristics */
if (output->color_profile) {
/*
* TODO: extract characteristics from profile?
* Get dynamic range from weston_color_characteristics?
*/
return true;
}
cc = weston_output_get_color_characteristics(output);
/* Target content chromaticity */
......@@ -312,13 +304,7 @@ cmlcms_create_output_color_outcome(struct weston_color_manager *cm_base,
if (!cmlcms_get_hdr_meta(output, &co->hdr_meta))
goto out_fail;
/*
* TODO: if output->color_profile is NULL, maybe manufacture a
* profile from weston_color_characteristics if it has enough
* information?
* Or let the frontend decide to call a "create a profile from
* characteristics" API?
*/
assert(output->color_profile);
/* TODO: take container color space into account */
......@@ -381,8 +367,11 @@ cmlcms_destroy(struct weston_color_manager *cm_base)
{
struct weston_color_manager_lcms *cm = get_cmlcms(cm_base);
if (cm->sRGB_profile)
cmlcms_color_profile_destroy(cm->sRGB_profile);
if (cm->sRGB_profile) {
assert(cm->sRGB_profile->base.ref_count == 1);
unref_cprof(cm->sRGB_profile);
}
assert(wl_list_empty(&cm->color_transform_list));
assert(wl_list_empty(&cm->color_profile_list));
......@@ -454,6 +443,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;
......
......@@ -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,
......
......@@ -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,
......
......@@ -29,10 +29,15 @@
#include "color.h"
#include "shared/helpers.h"
#include "shared/string-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,68 @@ get_cmnoop(struct weston_color_manager *cm_base)
return container_of(cm_base, struct weston_color_manager_noop, base);
}
static inline struct cmnoop_color_profile *
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
cmnoop_destroy_color_profile(struct weston_color_profile *cprof)
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 struct weston_color_profile *
cmnoop_get_stock_sRGB_color_profile(struct weston_color_manager *cm_base)
{
/* Never called, as never creates an actual color profile. */
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
......@@ -67,7 +130,7 @@ cmnoop_get_color_profile_from_icc(struct weston_color_manager *cm,
struct weston_color_profile **cprof_out,
char **errmsg)
{
str_printf(errmsg, "ICC profiles are unsupported.");
*errmsg = xstrdup("ICC profiles are unsupported.");
return false;
}
......@@ -83,8 +146,12 @@ cmnoop_get_surface_color_transform(struct weston_color_manager *cm_base,
struct weston_output *output,
struct weston_surface_color_transform *surf_xform)
{
/* TODO: Assert surface has no colorspace set */
assert(output->color_profile == NULL);
struct weston_color_manager_noop *cmnoop = get_cmnoop(cm_base);
/* TODO: Assert that, if the surface has a cprof, it is the stock one */
assert(output->color_profile &&
get_cprof(output->color_profile) == cmnoop->stock_cprof);
if (!check_output_eotf_mode(output))
return false;
......@@ -100,16 +167,16 @@ static struct weston_output_color_outcome *
cmnoop_create_output_color_outcome(struct weston_color_manager *cm_base,
struct weston_output *output)
{
struct weston_color_manager_noop *cmnoop = get_cmnoop(cm_base);
struct weston_output_color_outcome *co;
assert(output->color_profile == NULL);
assert(output->color_profile &&
get_cprof(output->color_profile) == cmnoop->stock_cprof);
if (!check_output_eotf_mode(output))
return NULL;
co = zalloc(sizeof *co);
if (!co)
return NULL;
co = xzalloc(sizeof *co);
/* Identity transform on everything */
co->from_blend_to_output = NULL;
......@@ -121,11 +188,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;
}
......@@ -134,6 +221,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);
}
......@@ -142,9 +232,7 @@ weston_color_manager_noop_create(struct weston_compositor *compositor)
{
struct weston_color_manager_noop *cm;
cm = zalloc(sizeof *cm);
if (!cm)
return NULL;
cm = xzalloc(sizeof *cm);
cm->base.name = "no-op";
cm->base.compositor = compositor;
......@@ -152,6 +240,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;
......
......@@ -50,7 +50,6 @@
WL_EXPORT struct weston_color_profile *
weston_color_profile_ref(struct weston_color_profile *cprof)
{
/* NULL is a valid color space: sRGB */
if (!cprof)
return NULL;
......@@ -92,7 +91,7 @@ weston_color_profile_get_description(struct weston_color_profile *cprof)
if (cprof)
return cprof->description;
else
return "built-in default sRGB SDR profile";
return "(untagged)";
}
/**
......
......@@ -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.
......
......@@ -7170,6 +7170,8 @@ weston_output_set_color_outcome(struct weston_output *output)
struct weston_color_manager *cm = output->compositor->color_manager;
struct weston_output_color_outcome *colorout;
assert(output->color_profile);
colorout = cm->create_output_color_outcome(cm, output);
if (!colorout) {
weston_log("Creating color transformation for output \"%s\" failed.\n",
......@@ -7412,11 +7414,17 @@ WL_EXPORT bool
weston_output_set_color_profile(struct weston_output *output,
struct weston_color_profile *cprof)
{
struct weston_color_manager *cm = output->compositor->color_manager;
struct weston_color_profile *old;
struct weston_paint_node *pnode;
old = output->color_profile;
output->color_profile = weston_color_profile_ref(cprof);
if (!cprof) {
output->color_profile = cm->get_stock_sRGB_color_profile(cm);
} else {
output->color_profile = weston_color_profile_ref(cprof);
}
if (output->enabled) {
if (!weston_output_set_color_outcome(output)) {
......@@ -7603,6 +7611,8 @@ weston_output_init(struct weston_output *output,
struct weston_compositor *compositor,
const char *name)
{
struct weston_color_manager *cm;
output->pos.c = weston_coord(0, 0);
output->compositor = compositor;
output->destroying = 0;
......@@ -7636,6 +7646,11 @@ weston_output_init(struct weston_output *output,
weston_plane_init(&output->primary_plane, compositor);
weston_compositor_stack_plane(compositor,
&output->primary_plane, NULL);
/* Set the stock sRGB color profile for the output. Libweston users are
* free to set the color profile to whatever they want later on. */
cm = compositor->color_manager;
output->color_profile = cm->get_stock_sRGB_color_profile(cm);
}
/** Adds weston_output object to pending output list.
......@@ -7949,7 +7964,12 @@ weston_output_release(struct weston_output *output)
if (output->enabled)
weston_compositor_remove_output(output);
/* We always have a color profile set, as weston_output_init() sets the
* output cprof to the stock sRGB one. */
assert(output->color_profile);
weston_color_profile_unref(output->color_profile);
output->color_profile = NULL;
assert(output->color_outcome == NULL);
pixman_region32_fini(&output->region);
......
......@@ -36,6 +36,7 @@
#include "libweston-internal.h"
#include "backend.h"
#include "color.h"
#include "shared/xalloc.h"
struct config_testcase {
bool has_characteristics_key;
......@@ -148,6 +149,46 @@ create_config(const struct config_testcase *t)
return wc;
}
struct mock_color_manager {
struct weston_color_manager base;
struct weston_hdr_metadata_type1 *test_hdr_meta;
};
static struct weston_output_color_outcome *
mock_create_output_color_outcome(struct weston_color_manager *cm_base,
struct weston_output *output)
{
struct mock_color_manager *cm = container_of(cm_base, typeof(*cm), base);
struct weston_output_color_outcome *co;
co = xzalloc(sizeof *co);
co->hdr_meta = *cm->test_hdr_meta;
return co;
}
static struct weston_color_profile *
mock_cm_get_stock_sRGB_color_profile(struct weston_color_manager *mock_cm)
{
struct weston_color_profile *mock_cprof;
mock_cprof = xzalloc(sizeof(*mock_cprof));
mock_cprof->cm = mock_cm;
mock_cprof->ref_count = 1;
mock_cprof->description = xstrdup("mock cprof");
return mock_cprof;
}
static void
mock_cm_destroy_color_profile(struct weston_color_profile *mock_cprof)
{
free(mock_cprof->description);
free(mock_cprof);
}
/*
* Manufacture various weston.ini and check what
* wet_output_set_color_characteristics() says. Tests for the return value and
......@@ -161,9 +202,18 @@ TEST_P(color_characteristics_config_error, config_cases)
int retval;
char *logbuf;
size_t logsize;
struct mock_color_manager mock_cm = {
.base.create_output_color_outcome = mock_create_output_color_outcome,
.base.get_stock_sRGB_color_profile = mock_cm_get_stock_sRGB_color_profile,
.base.destroy_color_profile = mock_cm_destroy_color_profile,
};
struct weston_compositor mock_compositor = {
.color_manager = &mock_cm.base,
};
struct weston_output mock_output = {};
weston_output_init(&mock_output, NULL, "mockoutput");
wl_list_init(&mock_compositor.plane_list);
weston_output_init(&mock_output, &mock_compositor, "mockoutput");
logfile = open_memstream(&logbuf, &logsize);
weston_log_set_handler(logger, logger);
......@@ -190,9 +240,18 @@ TEST_P(color_characteristics_config_error, config_cases)
/* Setting NULL resets group_mask */
TEST(weston_output_set_color_characteristics_null)
{
struct mock_color_manager mock_cm = {
.base.create_output_color_outcome = mock_create_output_color_outcome,
.base.get_stock_sRGB_color_profile = mock_cm_get_stock_sRGB_color_profile,
.base.destroy_color_profile = mock_cm_destroy_color_profile,
};
struct weston_compositor mock_compositor = {
.color_manager = &mock_cm.base,
};
struct weston_output mock_output = {};
weston_output_init(&mock_output, NULL, "mockoutput");
wl_list_init(&mock_compositor.plane_list);
weston_output_init(&mock_output, &mock_compositor, "mockoutput");
mock_output.color_characteristics.group_mask = 1;
weston_output_set_color_characteristics(&mock_output, NULL);
......@@ -232,26 +291,6 @@ static const struct value_testcase value_cases[] = {
{ 11, 65535.1, false },
};
struct mock_color_manager {
struct weston_color_manager base;
struct weston_hdr_metadata_type1 *test_hdr_meta;
};
static struct weston_output_color_outcome *
mock_create_output_color_outcome(struct weston_color_manager *cm_base,
struct weston_output *output)
{
struct mock_color_manager *cm = container_of(cm_base, typeof(*cm), base);
struct weston_output_color_outcome *co;
co = zalloc(sizeof *co);
assert(co);
co->hdr_meta = *cm->test_hdr_meta;
return co;
}
/*
* Modify one value in a known good metadata structure, and see how
* validation reacts to it.
......@@ -280,6 +319,8 @@ TEST_P(hdr_metadata_type1_errors, value_cases)
};
struct mock_color_manager mock_cm = {
.base.create_output_color_outcome = mock_create_output_color_outcome,
.base.get_stock_sRGB_color_profile = mock_cm_get_stock_sRGB_color_profile,
.base.destroy_color_profile = mock_cm_destroy_color_profile,
.test_hdr_meta = &meta,
};
struct weston_compositor mock_compositor = {
......@@ -319,6 +360,8 @@ TEST(hdr_metadata_type1_ignore_unflagged)
};
struct mock_color_manager mock_cm = {
.base.create_output_color_outcome = mock_create_output_color_outcome,
.base.get_stock_sRGB_color_profile = mock_cm_get_stock_sRGB_color_profile,
.base.destroy_color_profile = mock_cm_destroy_color_profile,
.test_hdr_meta = &meta,
};
struct weston_compositor mock_compositor = {
......