render/color: Invert ownership model of color_transform types.

Color transform can have multiple types and these different types
want to store different metadata. We previously stored this metadata
directly on wlr_color_transform even for transforms that don't use it.

Instead, let's take the prior art from wlr_scene where each scene node
is built on a base node. Notice how wlr_color_transform_lut3d now has
a `struct wlr_color_transform base`. This is advantageous in multiple
ways:

1. We don't allocate memory for metadata that will never be used.
2. This is more type safe: Compositors can pass around a
struct wlr_color_transform_lut3d if they know they only want to use a
3d_lut.
3. This is more scalable. As we add more transform types, we don't have
to keep growing a monolithic struct.
This commit is contained in:
Alexander Orzechowski 2024-08-24 14:33:22 -04:00
parent fa2abbeefb
commit 3187479c07
4 changed files with 54 additions and 23 deletions

View file

@ -18,7 +18,7 @@ static void handle_lcms_error(cmsContext ctx, cmsUInt32Number code, const char *
struct wlr_color_transform *wlr_color_transform_init_linear_to_icc(
const void *data, size_t size) {
struct wlr_color_transform *tx = NULL;
struct wlr_color_transform_lut3d *tx = NULL;
cmsContext ctx = cmsCreateContext(NULL, NULL);
if (ctx == NULL) {
@ -95,15 +95,15 @@ struct wlr_color_transform *wlr_color_transform_init_linear_to_icc(
}
}
tx = calloc(1, sizeof(struct wlr_color_transform));
tx = calloc(1, sizeof(struct wlr_color_transform_lut3d));
if (!tx) {
goto out_lcms_tr;
}
tx->type = COLOR_TRANSFORM_LUT_3D;
tx->lut3d.dim_len = dim_len;
tx->lut3d.lut_3d = lut_3d;
tx->ref_count = 1;
wlr_addon_set_init(&tx->addons);
tx->base.type = COLOR_TRANSFORM_LUT_3D;
tx->dim_len = dim_len;
tx->lut_3d = lut_3d;
tx->base.ref_count = 1;
wlr_addon_set_init(&tx->base.addons);
out_lcms_tr:
cmsDeleteTransform(lcms_tr);
@ -115,5 +115,5 @@ out_icc_profile:
cmsCloseProfile(icc_profile);
out_ctx:
cmsDeleteContext(ctx);
return tx;
return &tx->base;
}