diff --git a/example/compositor.c b/example/compositor.c index bfbbdce..57b4b1b 100644 --- a/example/compositor.c +++ b/example/compositor.c @@ -111,6 +111,7 @@ int main(int argc, char *argv[]) struct liftoff_layer *composition_layer; struct dumb_fb fbs[MAX_LAYERS_LEN] = {0}; struct liftoff_layer *layers[MAX_LAYERS_LEN]; + struct liftoff_plane *plane; drmModeAtomicReq *req; int ret; size_t i; @@ -200,7 +201,7 @@ int main(int argc, char *argv[]) /* Composite layers that didn't make it into a plane */ for (i = 1; i < layers_len; i++) { - if (liftoff_layer_get_plane_id(layers[i]) == 0) { + if (liftoff_layer_get_plane(layers[i]) == NULL) { composite(drm_fd, &composition_fb, &fbs[i], i * 100, i * 100); } @@ -212,11 +213,13 @@ int main(int argc, char *argv[]) return 1; } + plane = liftoff_layer_get_plane(composition_layer); printf("Composition layer got assigned to plane %u\n", - liftoff_layer_get_plane_id(composition_layer)); + plane ? liftoff_plane_get_id(plane) : 0); for (i = 0; i < layers_len; i++) { + plane = liftoff_layer_get_plane(layers[i]); printf("Layer %zu got assigned to plane %u\n", i, - liftoff_layer_get_plane_id(layers[i])); + plane ? liftoff_plane_get_id(plane) : 0); } sleep(1); diff --git a/example/dynamic.c b/example/dynamic.c index 2d70f40..619a6f4 100644 --- a/example/dynamic.c +++ b/example/dynamic.c @@ -92,6 +92,7 @@ static bool draw(void) int ret, inc; size_t i; uint32_t flags; + struct liftoff_plane *plane; active_layer = &layers[active_layer_idx]; @@ -124,8 +125,13 @@ static bool draw(void) drmModeAtomicFree(req); for (i = 0; i < sizeof(layers) / sizeof(layers[0]); i++) { - printf("Layer %zu got assigned to plane %u\n", i, - liftoff_layer_get_plane_id(layers[i].layer)); + plane = liftoff_layer_get_plane(layers[i].layer); + if (plane != NULL) { + printf("Layer %zu got assigned to plane %u\n", i, + liftoff_plane_get_id(plane)); + } else { + printf("Layer %zu has no plane assigned\n", i); + } } return true; diff --git a/example/multi-output.c b/example/multi-output.c index f28d3e7..ccf2034 100644 --- a/example/multi-output.c +++ b/example/multi-output.c @@ -74,6 +74,7 @@ int main(int argc, char *argv[]) drmModeCrtc *crtcs[MAX_OUTPUTS], *crtc; struct liftoff_output *outputs[MAX_OUTPUTS], *output; struct liftoff_layer *layers[MAX_OUTPUTS * LAYERS_PER_OUTPUT]; + struct liftoff_plane *plane; size_t outputs_len, layers_len; drmModeAtomicReq *req; int ret; @@ -168,8 +169,13 @@ int main(int argc, char *argv[]) } for (i = 0; i < layers_len; i++) { - printf("Layer %zu got assigned to plane %u\n", i, - liftoff_layer_get_plane_id(layers[i])); + plane = liftoff_layer_get_plane(layers[i]); + if (plane != NULL) { + printf("Layer %zu got assigned to plane %u\n", i, + liftoff_plane_get_id(plane)); + } else { + printf("Layer %zu has no plane assigned\n", i); + } } sleep(1); diff --git a/example/simple.c b/example/simple.c index ae2ed30..fc75141 100644 --- a/example/simple.c +++ b/example/simple.c @@ -72,6 +72,7 @@ int main(int argc, char *argv[]) drmModeConnector *connector; struct liftoff_output *output; struct liftoff_layer *layers[LAYERS_LEN]; + struct liftoff_plane *plane; drmModeAtomicReq *req; int ret; size_t i; @@ -140,8 +141,13 @@ int main(int argc, char *argv[]) } for (i = 0; i < sizeof(layers) / sizeof(layers[0]); i++) { - printf("Layer %zu got assigned to plane %u\n", i, - liftoff_layer_get_plane_id(layers[i])); + plane = liftoff_layer_get_plane(layers[i]); + if (plane != NULL) { + printf("Layer %zu got assigned to plane %u\n", i, + liftoff_plane_get_id(plane)); + } else { + printf("Layer %zu has no plane assigned\n", i); + } } sleep(1); diff --git a/include/libliftoff.h b/include/libliftoff.h index 7052d6c..ef669f6 100644 --- a/include/libliftoff.h +++ b/include/libliftoff.h @@ -122,9 +122,9 @@ void liftoff_layer_set_fb_composited(struct liftoff_layer *layer); /** * Retrieve the plane mapped to this layer. * - * Zero is returned if no plane is mapped. + * NULL is returned if no plane is mapped. */ -uint32_t liftoff_layer_get_plane_id(struct liftoff_layer *layer); +struct liftoff_plane *liftoff_layer_get_plane(struct liftoff_layer *layer); enum liftoff_log_priority { LIFTOFF_SILENT, diff --git a/layer.c b/layer.c index 7e9def3..014e967 100644 --- a/layer.c +++ b/layer.c @@ -99,12 +99,9 @@ void liftoff_layer_set_fb_composited(struct liftoff_layer *layer) layer->changed = true; } -uint32_t liftoff_layer_get_plane_id(struct liftoff_layer *layer) +struct liftoff_plane *liftoff_layer_get_plane(struct liftoff_layer *layer) { - if (layer->plane == NULL) { - return 0; - } - return layer->plane->id; + return layer->plane; } void layer_get_rect(struct liftoff_layer *layer, struct liftoff_rect *rect) diff --git a/test/test_alloc.c b/test/test_alloc.c index d9965d4..b521915 100644 --- a/test/test_alloc.c +++ b/test/test_alloc.c @@ -616,6 +616,7 @@ static void run_test(struct test_layer *test_layers) struct liftoff_device *device; struct liftoff_output *output; struct liftoff_layer *layers[64]; + struct liftoff_plane *plane; drmModeAtomicReq *req; bool ok; int ret; @@ -662,9 +663,10 @@ static void run_test(struct test_layer *test_layers) drmModeAtomicFree(req); for (i = 0; test_layers[i].width > 0; i++) { - plane_id = liftoff_layer_get_plane_id(layers[i]); + plane = liftoff_layer_get_plane(layers[i]); mock_plane = NULL; - if (plane_id != 0) { + if (plane != NULL) { + plane_id = liftoff_plane_get_id(plane); mock_plane = liftoff_mock_drm_get_plane(plane_id); } plane_index_got = -1; diff --git a/test/test_prop.c b/test/test_prop.c index 3d3ba29..b5133b0 100644 --- a/test/test_prop.c +++ b/test/test_prop.c @@ -84,7 +84,7 @@ static int test_prop_default(const char *prop_name) assert(ok); ret = drmModeAtomicCommit(drm_fd, req, 0, NULL); assert(ret == 0); - assert(liftoff_layer_get_plane_id(layer) == 0); + assert(liftoff_layer_get_plane(layer) == NULL); drmModeAtomicFree(req); /* The layer should get assigned to the plane without the prop when @@ -98,7 +98,7 @@ static int test_prop_default(const char *prop_name) assert(ok); ret = drmModeAtomicCommit(drm_fd, req, 0, NULL); assert(ret == 0); - assert(liftoff_layer_get_plane_id(layer) != 0); + assert(liftoff_layer_get_plane(layer) != NULL); drmModeAtomicFree(req); /* The layer should get assigned to the plane with the prop when using @@ -114,7 +114,7 @@ static int test_prop_default(const char *prop_name) assert(ok); ret = drmModeAtomicCommit(drm_fd, req, 0, NULL); assert(ret == 0); - assert(liftoff_layer_get_plane_id(layer) != 0); + assert(liftoff_layer_get_plane(layer) != NULL); drmModeAtomicFree(req); liftoff_device_destroy(device);