Introduce liftoff_layer_unset_property()

This can be used when a propperty doesn't have a default/no-op
value, such as COLOR_ENCODING and COLOR_RANGE.
This commit is contained in:
Simon Ser 2022-08-05 23:08:24 +02:00
parent 1d425f542c
commit 9c84f7945a
4 changed files with 79 additions and 0 deletions

View file

@ -144,6 +144,12 @@ int
liftoff_layer_set_property(struct liftoff_layer *layer, const char *name,
uint64_t value);
/**
* Unset a property on the layer.
*/
void
liftoff_layer_unset_property(struct liftoff_layer *layer, const char *name);
/**
* Force composition on this layer.
*

20
layer.c
View file

@ -92,6 +92,26 @@ liftoff_layer_set_property(struct liftoff_layer *layer, const char *name,
return 0;
}
void
liftoff_layer_unset_property(struct liftoff_layer *layer, const char *name)
{
struct liftoff_layer_property *prop, *last;
prop = layer_get_property(layer, name);
if (prop == NULL) {
return;
}
last = &layer->props[layer->props_len - 1];
if (prop != last) {
*prop = *last;
}
memset(last, 0, sizeof(*last));
layer->props_len--;
layer->changed = true;
}
void
liftoff_layer_set_fb_composited(struct liftoff_layer *layer)
{

View file

@ -76,6 +76,7 @@ tests = {
'ignore-alpha',
'immutable-zpos',
'unmatched',
'unset',
],
}

View file

@ -282,6 +282,56 @@ test_unmatched_prop(void)
return 0;
}
static int
test_unset_prop(void)
{
struct liftoff_mock_plane *mock_plane;
int drm_fd;
struct liftoff_device *device;
struct liftoff_output *output;
struct liftoff_layer *layer;
drmModeAtomicReq *req;
int ret;
mock_plane = liftoff_mock_drm_create_plane(DRM_PLANE_TYPE_PRIMARY);
drm_fd = liftoff_mock_drm_open();
device = liftoff_device_create(drm_fd);
assert(device != NULL);
liftoff_device_register_all_planes(device);
output = liftoff_output_create(device, liftoff_mock_drm_crtc_id);
layer = add_layer(output, 0, 0, 1920, 1080);
liftoff_layer_set_property(layer, "asdf", 0); /* doesn't exist */
liftoff_layer_set_property(layer, "alpha", 0xFFFF);
liftoff_mock_plane_add_compatible_layer(mock_plane, layer);
req = drmModeAtomicAlloc();
ret = liftoff_output_apply(output, req, 0);
assert(ret == 0);
ret = drmModeAtomicCommit(drm_fd, req, 0, NULL);
assert(ret == 0);
assert(liftoff_mock_plane_get_layer(mock_plane) == NULL);
drmModeAtomicFree(req);
liftoff_layer_unset_property(layer, "asdf");
req = drmModeAtomicAlloc();
ret = liftoff_output_apply(output, req, 0);
assert(ret == 0);
ret = drmModeAtomicCommit(drm_fd, req, 0, NULL);
assert(ret == 0);
assert(liftoff_mock_plane_get_layer(mock_plane) == layer);
drmModeAtomicFree(req);
liftoff_device_destroy(device);
close(drm_fd);
return 0;
}
int
main(int argc, char *argv[])
{
@ -305,6 +355,8 @@ main(int argc, char *argv[])
return test_immutable_zpos();
} else if (strcmp(test_name, "unmatched") == 0) {
return test_unmatched_prop();
} else if (strcmp(test_name, "unset") == 0) {
return test_unset_prop();
} else {
fprintf(stderr, "no such test: %s\n", test_name);
return 1;