2019-10-14 17:43:45 +02:00
|
|
|
#include <assert.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <libliftoff.h>
|
2021-07-30 16:22:58 +02:00
|
|
|
#include <stdbool.h>
|
2019-10-14 17:43:45 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "libdrm_mock.h"
|
|
|
|
|
2020-12-05 11:53:56 +01:00
|
|
|
struct context {
|
|
|
|
int drm_fd;
|
|
|
|
struct liftoff_output *output;
|
|
|
|
struct liftoff_mock_plane *mock_plane;
|
|
|
|
struct liftoff_layer *layer, *other_layer;
|
|
|
|
size_t commit_count;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct test_case {
|
|
|
|
const char *name;
|
|
|
|
void (*run)(struct context *ctx);
|
|
|
|
};
|
|
|
|
|
2019-10-14 17:43:45 +02:00
|
|
|
static struct liftoff_layer *add_layer(struct liftoff_output *output,
|
|
|
|
int x, int y, int width, int height)
|
|
|
|
{
|
|
|
|
uint32_t fb_id;
|
|
|
|
struct liftoff_layer *layer;
|
|
|
|
|
|
|
|
layer = liftoff_layer_create(output);
|
|
|
|
fb_id = liftoff_mock_drm_create_fb(layer);
|
|
|
|
liftoff_layer_set_property(layer, "FB_ID", fb_id);
|
|
|
|
liftoff_layer_set_property(layer, "CRTC_X", x);
|
|
|
|
liftoff_layer_set_property(layer, "CRTC_Y", y);
|
|
|
|
liftoff_layer_set_property(layer, "CRTC_W", width);
|
|
|
|
liftoff_layer_set_property(layer, "CRTC_H", height);
|
|
|
|
liftoff_layer_set_property(layer, "SRC_X", 0);
|
|
|
|
liftoff_layer_set_property(layer, "SRC_Y", 0);
|
|
|
|
liftoff_layer_set_property(layer, "SRC_W", width << 16);
|
|
|
|
liftoff_layer_set_property(layer, "SRC_H", height << 16);
|
|
|
|
|
|
|
|
return layer;
|
|
|
|
}
|
|
|
|
|
2020-12-05 11:53:56 +01:00
|
|
|
static void first_commit(struct context *ctx) {
|
2019-10-14 17:43:45 +02:00
|
|
|
drmModeAtomicReq *req;
|
2020-05-26 18:47:52 +02:00
|
|
|
int ret;
|
2019-10-14 17:43:45 +02:00
|
|
|
|
2020-12-05 11:53:56 +01:00
|
|
|
assert(ctx->commit_count == 0);
|
2019-10-14 17:43:45 +02:00
|
|
|
|
|
|
|
req = drmModeAtomicAlloc();
|
2021-07-27 12:28:00 +02:00
|
|
|
ret = liftoff_output_apply(ctx->output, req, 0);
|
|
|
|
assert(ret == 0);
|
2020-12-05 11:53:56 +01:00
|
|
|
ret = drmModeAtomicCommit(ctx->drm_fd, req, 0, NULL);
|
2020-05-26 18:47:52 +02:00
|
|
|
assert(ret == 0);
|
2019-10-14 17:43:45 +02:00
|
|
|
drmModeAtomicFree(req);
|
|
|
|
|
2020-12-05 11:53:56 +01:00
|
|
|
ctx->commit_count = liftoff_mock_commit_count;
|
2019-10-14 17:43:45 +02:00
|
|
|
/* We need to check whether the library can re-use old configurations
|
|
|
|
* with a single atomic commit. If we don't have enough planes/layers,
|
|
|
|
* the library will find a plane allocation in a single commit and we
|
|
|
|
* won't be able to tell the difference between a re-use and a complete
|
|
|
|
* run. */
|
2020-12-05 11:53:56 +01:00
|
|
|
assert(ctx->commit_count > 1);
|
|
|
|
}
|
2019-10-14 17:43:45 +02:00
|
|
|
|
2020-12-05 11:53:56 +01:00
|
|
|
static void second_commit(struct context *ctx, bool want_reuse_prev_alloc) {
|
|
|
|
drmModeAtomicReq *req;
|
|
|
|
int ret;
|
2019-10-14 17:43:45 +02:00
|
|
|
|
2020-12-05 11:53:56 +01:00
|
|
|
req = drmModeAtomicAlloc();
|
2021-07-27 12:28:00 +02:00
|
|
|
ret = liftoff_output_apply(ctx->output, req, 0);
|
|
|
|
assert(ret == 0);
|
2019-10-14 17:43:45 +02:00
|
|
|
if (want_reuse_prev_alloc) {
|
2019-11-24 13:25:59 +01:00
|
|
|
/* The library should perform only one TEST_ONLY commit with the
|
|
|
|
* previous plane allocation. */
|
2020-12-05 11:53:56 +01:00
|
|
|
assert(liftoff_mock_commit_count == ctx->commit_count + 1);
|
2019-10-14 17:43:45 +02:00
|
|
|
} else {
|
2019-11-24 13:25:59 +01:00
|
|
|
/* Since there are at least two planes, the library should
|
|
|
|
* perform more than one TEST_ONLY commit. */
|
2020-12-05 11:53:56 +01:00
|
|
|
assert(liftoff_mock_commit_count > ctx->commit_count + 1);
|
2019-10-14 17:43:45 +02:00
|
|
|
}
|
2020-12-05 11:53:56 +01:00
|
|
|
ret = drmModeAtomicCommit(ctx->drm_fd, req, 0, NULL);
|
2020-05-26 18:47:52 +02:00
|
|
|
assert(ret == 0);
|
2019-10-14 17:43:45 +02:00
|
|
|
drmModeAtomicFree(req);
|
2020-12-05 11:53:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void run_same(struct context *ctx) {
|
|
|
|
first_commit(ctx);
|
2020-12-05 12:36:34 +01:00
|
|
|
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer);
|
|
|
|
|
2020-12-05 11:53:56 +01:00
|
|
|
second_commit(ctx, true);
|
|
|
|
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void run_change_fb(struct context *ctx) {
|
|
|
|
first_commit(ctx);
|
2020-12-05 12:36:34 +01:00
|
|
|
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer);
|
|
|
|
|
2020-12-05 11:53:56 +01:00
|
|
|
liftoff_layer_set_property(ctx->layer, "FB_ID",
|
|
|
|
liftoff_mock_drm_create_fb(ctx->layer));
|
2020-12-05 12:36:34 +01:00
|
|
|
|
2020-12-05 11:53:56 +01:00
|
|
|
second_commit(ctx, true);
|
|
|
|
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer);
|
|
|
|
}
|
|
|
|
|
2020-12-05 12:36:34 +01:00
|
|
|
static void run_unset_fb(struct context *ctx) {
|
|
|
|
first_commit(ctx);
|
|
|
|
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer);
|
|
|
|
|
|
|
|
liftoff_layer_set_property(ctx->layer, "FB_ID", 0);
|
|
|
|
|
|
|
|
second_commit(ctx, false);
|
|
|
|
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void run_set_fb(struct context *ctx) {
|
|
|
|
liftoff_layer_set_property(ctx->layer, "FB_ID", 0);
|
|
|
|
first_commit(ctx);
|
|
|
|
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == NULL);
|
|
|
|
|
|
|
|
liftoff_layer_set_property(ctx->layer, "FB_ID",
|
|
|
|
liftoff_mock_drm_create_fb(ctx->layer));
|
|
|
|
|
|
|
|
second_commit(ctx, false);
|
|
|
|
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer);
|
|
|
|
}
|
|
|
|
|
2020-12-05 11:53:56 +01:00
|
|
|
static void run_add_layer(struct context *ctx) {
|
|
|
|
first_commit(ctx);
|
2020-12-05 12:36:34 +01:00
|
|
|
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer);
|
|
|
|
|
2020-12-05 11:53:56 +01:00
|
|
|
add_layer(ctx->output, 0, 0, 256, 256);
|
2020-12-05 12:36:34 +01:00
|
|
|
|
2020-12-05 11:53:56 +01:00
|
|
|
second_commit(ctx, false);
|
|
|
|
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void run_remove_layer(struct context *ctx) {
|
|
|
|
first_commit(ctx);
|
2020-12-05 12:36:34 +01:00
|
|
|
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer);
|
|
|
|
|
2020-12-05 11:53:56 +01:00
|
|
|
liftoff_layer_destroy(ctx->other_layer);
|
|
|
|
ctx->other_layer = NULL;
|
2020-12-05 12:36:34 +01:00
|
|
|
|
2020-12-05 11:53:56 +01:00
|
|
|
second_commit(ctx, false);
|
|
|
|
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void run_change_composition_layer(struct context *ctx) {
|
|
|
|
first_commit(ctx);
|
2020-12-05 12:36:34 +01:00
|
|
|
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer);
|
|
|
|
|
2020-12-05 11:53:56 +01:00
|
|
|
liftoff_output_set_composition_layer(ctx->output, ctx->layer);
|
2020-12-05 12:36:34 +01:00
|
|
|
|
2020-12-05 11:53:56 +01:00
|
|
|
second_commit(ctx, false);
|
|
|
|
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer);
|
|
|
|
}
|
|
|
|
|
2020-12-05 13:06:44 +01:00
|
|
|
static void run_change_alpha(struct context *ctx) {
|
|
|
|
liftoff_layer_set_property(ctx->layer, "alpha", 42);
|
|
|
|
|
|
|
|
first_commit(ctx);
|
|
|
|
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer);
|
|
|
|
|
|
|
|
liftoff_layer_set_property(ctx->layer, "alpha", 43);
|
|
|
|
|
|
|
|
second_commit(ctx, true);
|
|
|
|
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void run_set_alpha_from_opaque(struct context *ctx) {
|
|
|
|
liftoff_layer_set_property(ctx->layer, "alpha", 0xFFFF); /* opaque */
|
|
|
|
|
|
|
|
first_commit(ctx);
|
|
|
|
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer);
|
|
|
|
|
|
|
|
liftoff_layer_set_property(ctx->layer, "alpha", 42);
|
|
|
|
|
|
|
|
second_commit(ctx, false);
|
|
|
|
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void run_set_alpha_from_transparent(struct context *ctx) {
|
|
|
|
liftoff_layer_set_property(ctx->layer, "alpha", 0); /* transparent */
|
|
|
|
|
|
|
|
first_commit(ctx);
|
|
|
|
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == NULL);
|
|
|
|
|
|
|
|
liftoff_layer_set_property(ctx->layer, "alpha", 42);
|
|
|
|
|
|
|
|
second_commit(ctx, false);
|
|
|
|
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void run_unset_alpha_to_opaque(struct context *ctx) {
|
|
|
|
liftoff_layer_set_property(ctx->layer, "alpha", 42);
|
|
|
|
|
|
|
|
first_commit(ctx);
|
|
|
|
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer);
|
|
|
|
|
|
|
|
liftoff_layer_set_property(ctx->layer, "alpha", 0xFFFF); /* opaque */
|
|
|
|
|
|
|
|
second_commit(ctx, false);
|
|
|
|
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void run_unset_alpha_to_transparent(struct context *ctx) {
|
|
|
|
liftoff_layer_set_property(ctx->layer, "alpha", 42);
|
|
|
|
|
|
|
|
first_commit(ctx);
|
|
|
|
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer);
|
|
|
|
|
|
|
|
liftoff_layer_set_property(ctx->layer, "alpha", 0); /* transparent */
|
|
|
|
|
|
|
|
second_commit(ctx, false);
|
|
|
|
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == NULL);
|
|
|
|
}
|
|
|
|
|
2020-12-05 12:44:08 +01:00
|
|
|
static void run_change_in_fence_fd(struct context *ctx) {
|
|
|
|
liftoff_layer_set_property(ctx->layer, "IN_FENCE_FD", 42);
|
|
|
|
|
|
|
|
first_commit(ctx);
|
|
|
|
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer);
|
|
|
|
|
|
|
|
liftoff_layer_set_property(ctx->layer, "IN_FENCE_FD", 43);
|
|
|
|
|
|
|
|
second_commit(ctx, true);
|
|
|
|
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer);
|
|
|
|
}
|
|
|
|
|
2020-12-05 14:36:47 +01:00
|
|
|
static void run_change_fb_damage_clips(struct context *ctx) {
|
|
|
|
liftoff_layer_set_property(ctx->layer, "FB_DAMAGE_CLIPS", 42);
|
|
|
|
|
|
|
|
first_commit(ctx);
|
|
|
|
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer);
|
|
|
|
|
|
|
|
liftoff_layer_set_property(ctx->layer, "FB_DAMAGE_CLIPS", 43);
|
|
|
|
|
|
|
|
second_commit(ctx, true);
|
|
|
|
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer);
|
|
|
|
}
|
|
|
|
|
2020-12-05 11:53:56 +01:00
|
|
|
static const struct test_case tests[] = {
|
|
|
|
{ .name = "same", .run = run_same },
|
|
|
|
{ .name = "change-fb", .run = run_change_fb },
|
2020-12-05 12:36:34 +01:00
|
|
|
{ .name = "unset-fb", .run = run_unset_fb },
|
|
|
|
{ .name = "set-fb", .run = run_set_fb },
|
2020-12-05 11:53:56 +01:00
|
|
|
{ .name = "add-layer", .run = run_add_layer },
|
|
|
|
{ .name = "remove-layer", .run = run_remove_layer },
|
|
|
|
{ .name = "change-composition-layer", .run = run_change_composition_layer },
|
2020-12-05 13:06:44 +01:00
|
|
|
{ .name = "change-alpha", .run = run_change_alpha },
|
|
|
|
{ .name = "set-alpha-from-opaque", .run = run_set_alpha_from_opaque },
|
|
|
|
{ .name = "set-alpha-from-transparent", .run = run_set_alpha_from_transparent },
|
|
|
|
{ .name = "unset-alpha-to-opaque", .run = run_unset_alpha_to_opaque },
|
|
|
|
{ .name = "unset-alpha-to-transparent", .run = run_unset_alpha_to_transparent },
|
2020-12-05 12:44:08 +01:00
|
|
|
{ .name = "change-in-fence-fd", .run = run_change_in_fence_fd },
|
2020-12-05 14:36:47 +01:00
|
|
|
{ .name = "change-fb-damage-clips", .run = run_change_fb_damage_clips },
|
2020-12-05 11:53:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static void run(const struct test_case *test) {
|
|
|
|
struct context ctx = {0};
|
|
|
|
struct liftoff_device *device;
|
2020-12-05 13:06:44 +01:00
|
|
|
const char *prop_name;
|
|
|
|
drmModePropertyRes prop;
|
2020-12-05 11:53:56 +01:00
|
|
|
|
|
|
|
/* Always create two planes: a primary plane only compatible with
|
|
|
|
* `layer`, and a cursor plane incompatible with any layer. Always
|
|
|
|
* create 3 layers: `layer`, `other_layer`, and an unnamed third layer.
|
|
|
|
*/
|
|
|
|
|
|
|
|
ctx.mock_plane = liftoff_mock_drm_create_plane(DRM_PLANE_TYPE_PRIMARY);
|
|
|
|
/* Plane incompatible with all layers */
|
|
|
|
liftoff_mock_drm_create_plane(DRM_PLANE_TYPE_CURSOR);
|
|
|
|
|
2020-12-05 13:06:44 +01:00
|
|
|
prop_name = "alpha";
|
|
|
|
prop = (drmModePropertyRes){0};
|
|
|
|
strncpy(prop.name, prop_name, sizeof(prop.name) - 1);
|
|
|
|
liftoff_mock_plane_add_property(ctx.mock_plane, &prop);
|
|
|
|
|
|
|
|
prop_name = "IN_FENCE_FD";
|
|
|
|
prop = (drmModePropertyRes){0};
|
2020-12-05 12:44:08 +01:00
|
|
|
strncpy(prop.name, prop_name, sizeof(prop.name) - 1);
|
2020-12-05 14:36:47 +01:00
|
|
|
liftoff_mock_plane_add_property(ctx.mock_plane, &prop);
|
|
|
|
|
|
|
|
prop_name = "FB_DAMAGE_CLIPS";
|
|
|
|
prop = (drmModePropertyRes){0};
|
|
|
|
strncpy(prop.name, prop_name, sizeof(prop.name) - 1);
|
2020-12-05 12:44:08 +01:00
|
|
|
liftoff_mock_plane_add_property(ctx.mock_plane, &prop);
|
|
|
|
|
2020-12-05 11:53:56 +01:00
|
|
|
ctx.drm_fd = liftoff_mock_drm_open();
|
|
|
|
device = liftoff_device_create(ctx.drm_fd);
|
|
|
|
assert(device != NULL);
|
|
|
|
|
2021-02-23 18:01:38 +01:00
|
|
|
liftoff_device_register_all_planes(device);
|
|
|
|
|
2020-12-05 11:53:56 +01:00
|
|
|
ctx.output = liftoff_output_create(device, liftoff_mock_drm_crtc_id);
|
|
|
|
ctx.layer = add_layer(ctx.output, 0, 0, 1920, 1080);
|
|
|
|
/* Layers incompatible with all planes */
|
|
|
|
ctx.other_layer = add_layer(ctx.output, 0, 0, 256, 256);
|
|
|
|
add_layer(ctx.output, 0, 0, 256, 256);
|
|
|
|
|
|
|
|
liftoff_mock_plane_add_compatible_layer(ctx.mock_plane, ctx.layer);
|
|
|
|
|
|
|
|
test->run(&ctx);
|
2019-10-14 17:43:45 +02:00
|
|
|
|
2019-11-24 13:07:12 +01:00
|
|
|
liftoff_device_destroy(device);
|
2020-12-05 11:53:56 +01:00
|
|
|
close(ctx.drm_fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
const char *test_name;
|
|
|
|
|
2021-03-31 12:44:24 +02:00
|
|
|
liftoff_log_set_priority(LIFTOFF_DEBUG);
|
2020-12-05 11:53:56 +01:00
|
|
|
|
|
|
|
if (argc != 2) {
|
|
|
|
fprintf(stderr, "usage: %s <test-name>\n", argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
test_name = argv[1];
|
|
|
|
|
|
|
|
for (size_t i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) {
|
|
|
|
if (strcmp(test_name, tests[i].name) == 0) {
|
|
|
|
run(&tests[i]);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2019-10-14 17:43:45 +02:00
|
|
|
|
2020-12-05 11:53:56 +01:00
|
|
|
fprintf(stderr, "no such test: %s\n", test_name);
|
|
|
|
return 1;
|
2019-10-14 17:43:45 +02:00
|
|
|
}
|