mirror of
https://gitlab.freedesktop.org/emersion/libliftoff.git
synced 2025-01-15 03:40:52 +01:00
Change planes to be a linked list instead of an array
We'll need this anyway when we allow users to choose which planes to give us. Let's not start building algorithms on top of arrays.
This commit is contained in:
parent
14848bb802
commit
165d013b80
2 changed files with 27 additions and 32 deletions
54
display.c
54
display.c
|
@ -7,18 +7,23 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "private.h"
|
#include "private.h"
|
||||||
|
|
||||||
static bool plane_init(struct hwc_plane *plane, struct hwc_display *display,
|
static struct hwc_plane *plane_create(struct hwc_display *display, int32_t id)
|
||||||
int32_t id)
|
|
||||||
{
|
{
|
||||||
|
struct hwc_plane *plane;
|
||||||
drmModePlane *drm_plane;
|
drmModePlane *drm_plane;
|
||||||
drmModeObjectProperties *drm_props;
|
drmModeObjectProperties *drm_props;
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
drmModePropertyRes *drm_prop;
|
drmModePropertyRes *drm_prop;
|
||||||
struct hwc_plane_property *prop;
|
struct hwc_plane_property *prop;
|
||||||
|
|
||||||
|
plane = calloc(1, sizeof(*plane));
|
||||||
|
if (plane == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
drm_plane = drmModeGetPlane(display->drm_fd, id);
|
drm_plane = drmModeGetPlane(display->drm_fd, id);
|
||||||
if (drm_plane == NULL) {
|
if (drm_plane == NULL) {
|
||||||
return false;
|
return NULL;
|
||||||
}
|
}
|
||||||
plane->id = drm_plane->plane_id;
|
plane->id = drm_plane->plane_id;
|
||||||
plane->possible_crtcs = drm_plane->possible_crtcs;
|
plane->possible_crtcs = drm_plane->possible_crtcs;
|
||||||
|
@ -27,20 +32,20 @@ static bool plane_init(struct hwc_plane *plane, struct hwc_display *display,
|
||||||
drm_props = drmModeObjectGetProperties(display->drm_fd, id,
|
drm_props = drmModeObjectGetProperties(display->drm_fd, id,
|
||||||
DRM_MODE_OBJECT_PLANE);
|
DRM_MODE_OBJECT_PLANE);
|
||||||
if (drm_props == NULL) {
|
if (drm_props == NULL) {
|
||||||
return false;
|
return NULL;
|
||||||
}
|
}
|
||||||
plane->props = calloc(drm_props->count_props,
|
plane->props = calloc(drm_props->count_props,
|
||||||
sizeof(struct hwc_plane_property));
|
sizeof(struct hwc_plane_property));
|
||||||
if (plane->props == NULL) {
|
if (plane->props == NULL) {
|
||||||
drmModeFreeObjectProperties(drm_props);
|
drmModeFreeObjectProperties(drm_props);
|
||||||
return false;
|
return NULL;
|
||||||
}
|
}
|
||||||
for (i = 0; i < drm_props->count_props; i++) {
|
for (i = 0; i < drm_props->count_props; i++) {
|
||||||
drm_prop = drmModeGetProperty(display->drm_fd,
|
drm_prop = drmModeGetProperty(display->drm_fd,
|
||||||
drm_props->props[i]);
|
drm_props->props[i]);
|
||||||
if (drm_prop == NULL) {
|
if (drm_prop == NULL) {
|
||||||
drmModeFreeObjectProperties(drm_props);
|
drmModeFreeObjectProperties(drm_props);
|
||||||
return false;
|
return NULL;
|
||||||
}
|
}
|
||||||
prop = &plane->props[i];
|
prop = &plane->props[i];
|
||||||
memcpy(prop->name, drm_prop->name, sizeof(prop->name));
|
memcpy(prop->name, drm_prop->name, sizeof(prop->name));
|
||||||
|
@ -50,12 +55,16 @@ static bool plane_init(struct hwc_plane *plane, struct hwc_display *display,
|
||||||
}
|
}
|
||||||
drmModeFreeObjectProperties(drm_props);
|
drmModeFreeObjectProperties(drm_props);
|
||||||
|
|
||||||
return true;
|
hwc_list_insert(display->planes.prev, &plane->link);
|
||||||
|
|
||||||
|
return plane;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void plane_finish(struct hwc_plane *plane)
|
static void plane_destroy(struct hwc_plane *plane)
|
||||||
{
|
{
|
||||||
|
hwc_list_remove(&plane->link);
|
||||||
free(plane->props);
|
free(plane->props);
|
||||||
|
free(plane);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct hwc_display *hwc_display_create(int drm_fd)
|
struct hwc_display *hwc_display_create(int drm_fd)
|
||||||
|
@ -74,6 +83,7 @@ struct hwc_display *hwc_display_create(int drm_fd)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hwc_list_init(&display->planes);
|
||||||
hwc_list_init(&display->outputs);
|
hwc_list_init(&display->outputs);
|
||||||
|
|
||||||
/* TODO: allow users to choose which layers to hand over */
|
/* TODO: allow users to choose which layers to hand over */
|
||||||
|
@ -83,19 +93,11 @@ struct hwc_display *hwc_display_create(int drm_fd)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
display->planes = calloc(drm_plane_res->count_planes,
|
|
||||||
sizeof(struct hwc_plane));
|
|
||||||
if (display->planes == NULL) {
|
|
||||||
hwc_display_destroy(display);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
for (i = 0; i < drm_plane_res->count_planes; i++) {
|
for (i = 0; i < drm_plane_res->count_planes; i++) {
|
||||||
if (!plane_init(&display->planes[i], display,
|
if (plane_create(display, drm_plane_res->planes[i]) == NULL) {
|
||||||
drm_plane_res->planes[i])) {
|
|
||||||
hwc_display_destroy(display);
|
hwc_display_destroy(display);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
display->planes_len++;
|
|
||||||
}
|
}
|
||||||
drmModeFreePlaneResources(drm_plane_res);
|
drmModeFreePlaneResources(drm_plane_res);
|
||||||
|
|
||||||
|
@ -104,13 +106,12 @@ struct hwc_display *hwc_display_create(int drm_fd)
|
||||||
|
|
||||||
void hwc_display_destroy(struct hwc_display *display)
|
void hwc_display_destroy(struct hwc_display *display)
|
||||||
{
|
{
|
||||||
size_t i;
|
struct hwc_plane *plane, *tmp;
|
||||||
|
|
||||||
close(display->drm_fd);
|
close(display->drm_fd);
|
||||||
for (i = 0; i < display->planes_len; i++) {
|
hwc_list_for_each_safe(plane, tmp, &display->planes, link) {
|
||||||
plane_finish(&display->planes[i]);
|
plane_destroy(plane);
|
||||||
}
|
}
|
||||||
free(display->planes);
|
|
||||||
free(display);
|
free(display);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,14 +184,12 @@ static bool layer_choose_plane(struct hwc_layer *layer, drmModeAtomicReq *req)
|
||||||
struct hwc_display *display;
|
struct hwc_display *display;
|
||||||
int cursor;
|
int cursor;
|
||||||
struct hwc_plane *plane;
|
struct hwc_plane *plane;
|
||||||
size_t i;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
display = layer->output->display;
|
display = layer->output->display;
|
||||||
cursor = drmModeAtomicGetCursor(req);
|
cursor = drmModeAtomicGetCursor(req);
|
||||||
|
|
||||||
for (i = 0; i < display->planes_len; i++) {
|
hwc_list_for_each(plane, &display->planes, link) {
|
||||||
plane = &display->planes[i];
|
|
||||||
if (plane->layer != NULL) {
|
if (plane->layer != NULL) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -223,15 +222,13 @@ static bool layer_choose_plane(struct hwc_layer *layer, drmModeAtomicReq *req)
|
||||||
|
|
||||||
bool hwc_display_apply(struct hwc_display *display, drmModeAtomicReq *req)
|
bool hwc_display_apply(struct hwc_display *display, drmModeAtomicReq *req)
|
||||||
{
|
{
|
||||||
size_t i;
|
|
||||||
struct hwc_output *output;
|
struct hwc_output *output;
|
||||||
struct hwc_layer *layer;
|
struct hwc_layer *layer;
|
||||||
struct hwc_plane *plane;
|
struct hwc_plane *plane;
|
||||||
|
|
||||||
/* Unset all existing plane and layer mappings.
|
/* Unset all existing plane and layer mappings.
|
||||||
TODO: incremental updates keeping old configuration if possible */
|
TODO: incremental updates keeping old configuration if possible */
|
||||||
for (i = 0; i < display->planes_len; i++) {
|
hwc_list_for_each(plane, &display->planes, link) {
|
||||||
plane = &display->planes[i];
|
|
||||||
if (plane->layer != NULL) {
|
if (plane->layer != NULL) {
|
||||||
plane->layer->plane = NULL;
|
plane->layer->plane = NULL;
|
||||||
plane->layer = NULL;
|
plane->layer = NULL;
|
||||||
|
@ -240,8 +237,7 @@ bool hwc_display_apply(struct hwc_display *display, drmModeAtomicReq *req)
|
||||||
|
|
||||||
/* Disable all planes. Do it before building mappings to make sure not
|
/* Disable all planes. Do it before building mappings to make sure not
|
||||||
to hit bandwidth limits because too many planes are enabled. */
|
to hit bandwidth limits because too many planes are enabled. */
|
||||||
for (i = 0; i < display->planes_len; i++) {
|
hwc_list_for_each(plane, &display->planes, link) {
|
||||||
plane = &display->planes[i];
|
|
||||||
if (plane->layer == NULL) {
|
if (plane->layer == NULL) {
|
||||||
fprintf(stderr, "Disabling plane %d\n", plane->id);
|
fprintf(stderr, "Disabling plane %d\n", plane->id);
|
||||||
if (!plane_apply(plane, NULL, req)) {
|
if (!plane_apply(plane, NULL, req)) {
|
||||||
|
|
|
@ -7,9 +7,7 @@
|
||||||
struct hwc_display {
|
struct hwc_display {
|
||||||
int drm_fd;
|
int drm_fd;
|
||||||
|
|
||||||
struct hwc_plane *planes;
|
struct hwc_list planes; /* hwc_plane.link */
|
||||||
size_t planes_len;
|
|
||||||
|
|
||||||
struct hwc_list outputs; /* hwc_output.link */
|
struct hwc_list outputs; /* hwc_output.link */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -40,6 +38,7 @@ struct hwc_plane {
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
uint32_t possible_crtcs;
|
uint32_t possible_crtcs;
|
||||||
/* TODO: formats */
|
/* TODO: formats */
|
||||||
|
struct hwc_list link; /* hwc_display.planes */
|
||||||
|
|
||||||
struct hwc_plane_property *props;
|
struct hwc_plane_property *props;
|
||||||
size_t props_len;
|
size_t props_len;
|
||||||
|
|
Loading…
Reference in a new issue