2019-10-30 20:41:25 +01:00
|
|
|
#include <assert.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <libliftoff.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "libdrm_mock.h"
|
|
|
|
|
|
|
|
/* Number of page-flips before the plane allocation has stabilized */
|
|
|
|
#define STABILIZE_PAGEFLIP_COUNT 600 /* 10s at 60FPS */
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
struct liftoff_mock_plane *mock_plane;
|
|
|
|
int drm_fd;
|
2019-11-24 13:07:12 +01:00
|
|
|
struct liftoff_device *device;
|
2019-10-30 20:41:25 +01:00
|
|
|
struct liftoff_output *output;
|
|
|
|
struct liftoff_layer *layers[2], *layer;
|
|
|
|
uint32_t fbs[2];
|
|
|
|
drmModeAtomicReq *req;
|
2020-05-26 18:47:52 +02:00
|
|
|
int ret;
|
2019-10-30 20:41:25 +01:00
|
|
|
|
2021-03-31 12:44:24 +02:00
|
|
|
liftoff_log_set_priority(LIFTOFF_SILENT);
|
2019-10-30 20:41:25 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
drm_fd = liftoff_mock_drm_open();
|
2019-11-24 13:07:12 +01:00
|
|
|
device = liftoff_device_create(drm_fd);
|
|
|
|
assert(device != NULL);
|
2019-10-30 20:41:25 +01:00
|
|
|
|
2021-02-23 18:01:38 +01:00
|
|
|
liftoff_device_register_all_planes(device);
|
|
|
|
|
2019-11-24 13:07:12 +01:00
|
|
|
output = liftoff_output_create(device, liftoff_mock_drm_crtc_id);
|
2019-10-30 20:41:25 +01:00
|
|
|
layers[0] = add_layer(output, 0, 0, 1920, 1080);
|
|
|
|
layers[1] = add_layer(output, 0, 0, 1920, 1080);
|
|
|
|
|
|
|
|
/* All layers are compatible with the primary plane */
|
|
|
|
liftoff_mock_plane_add_compatible_layer(mock_plane, layers[0]);
|
|
|
|
liftoff_mock_plane_add_compatible_layer(mock_plane, layers[1]);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < sizeof(layers) / sizeof(layers[0]); i++) {
|
|
|
|
/* We will continuously update layers[i]. After some time we
|
|
|
|
* want to see it get a plane. */
|
|
|
|
layer = layers[i];
|
|
|
|
fprintf(stderr, "Testing layer %zu\n", i);
|
|
|
|
|
|
|
|
fbs[0] = liftoff_mock_drm_create_fb(layer);
|
|
|
|
fbs[1] = liftoff_mock_drm_create_fb(layer);
|
|
|
|
|
|
|
|
req = drmModeAtomicAlloc();
|
|
|
|
for (int j = 0; j < STABILIZE_PAGEFLIP_COUNT; j++) {
|
|
|
|
drmModeAtomicSetCursor(req, 0);
|
|
|
|
|
|
|
|
liftoff_layer_set_property(layer, "FB_ID", fbs[j % 2]);
|
|
|
|
|
2021-07-27 12:28:00 +02:00
|
|
|
ret = liftoff_output_apply(output, req, 0);
|
|
|
|
assert(ret == 0);
|
2020-05-26 18:47:52 +02:00
|
|
|
ret = drmModeAtomicCommit(drm_fd, req, 0, NULL);
|
|
|
|
assert(ret == 0);
|
2019-10-30 20:41:25 +01:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:14:33 +01:00
|
|
|
assert(liftoff_mock_plane_get_layer(mock_plane) == layer);
|
2019-10-30 20:41:25 +01:00
|
|
|
|
|
|
|
drmModeAtomicFree(req);
|
|
|
|
}
|
|
|
|
|
2019-11-24 13:07:12 +01:00
|
|
|
liftoff_device_destroy(device);
|
2019-10-30 20:41:25 +01:00
|
|
|
close(drm_fd);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|