Rename display to device

"Display" can also mean "screen"/"monitor", so it's kind of confusing for
this usage.
This commit is contained in:
Simon Ser 2019-11-24 12:59:10 +01:00
parent 5f39331f78
commit b0e2b083f9
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
6 changed files with 83 additions and 83 deletions

64
alloc.c
View file

@ -189,7 +189,7 @@ static bool has_allocated_layer_over(struct liftoff_output *output,
}
i = -1;
liftoff_list_for_each(other_plane, &output->display->planes, link) {
liftoff_list_for_each(other_plane, &output->device->planes, link) {
i++;
if (i >= (ssize_t)step->plane_idx) {
break;
@ -230,7 +230,7 @@ static bool has_allocated_plane_under(struct liftoff_output *output,
plane = liftoff_container_of(step->plane_link, plane, link);
i = -1;
liftoff_list_for_each(other_plane, &output->display->planes, link) {
liftoff_list_for_each(other_plane, &output->device->planes, link) {
i++;
if (i >= (ssize_t)step->plane_idx) {
break;
@ -343,12 +343,12 @@ bool check_alloc_valid(struct alloc_result *result, struct alloc_step *step)
return true;
}
static bool display_test_commit(struct liftoff_display *display,
static bool device_test_commit(struct liftoff_device *device,
drmModeAtomicReq *req, bool *compatible)
{
int ret;
ret = drmModeAtomicCommit(display->drm_fd, req,
ret = drmModeAtomicCommit(device->drm_fd, req,
DRM_MODE_ATOMIC_TEST_ONLY, NULL);
if (ret == 0) {
*compatible = true;
@ -366,7 +366,7 @@ static bool display_test_commit(struct liftoff_display *display,
bool output_choose_layers(struct liftoff_output *output,
struct alloc_result *result, struct alloc_step *step)
{
struct liftoff_display *display;
struct liftoff_device *device;
struct liftoff_plane *plane;
struct liftoff_layer *layer;
int cursor;
@ -374,9 +374,9 @@ bool output_choose_layers(struct liftoff_output *output,
bool compatible;
struct alloc_step next_step;
display = output->display;
device = output->device;
if (step->plane_link == &display->planes) { /* Allocation finished */
if (step->plane_link == &device->planes) { /* Allocation finished */
if (step->score > result->best_score &&
check_alloc_valid(result, step)) {
/* We found a better allocation */
@ -437,7 +437,7 @@ bool output_choose_layers(struct liftoff_output *output,
continue;
}
if (!display_test_commit(display, result->req, &compatible)) {
if (!device_test_commit(device, result->req, &compatible)) {
return false;
}
if (compatible) {
@ -465,7 +465,7 @@ skip:
return true;
}
static bool apply_current(struct liftoff_display *display,
static bool apply_current(struct liftoff_device *device,
drmModeAtomicReq *req)
{
struct liftoff_plane *plane;
@ -474,7 +474,7 @@ static bool apply_current(struct liftoff_display *display,
cursor = drmModeAtomicGetCursor(req);
liftoff_list_for_each(plane, &display->planes, link) {
liftoff_list_for_each(plane, &device->planes, link) {
if (!plane_apply(plane, plane->layer, req, &compatible)) {
drmModeAtomicSetCursor(req, cursor);
return false;
@ -509,7 +509,7 @@ static bool layer_needs_realloc(struct liftoff_layer *layer)
return false;
}
static bool reuse_previous_alloc(struct liftoff_display *display,
static bool reuse_previous_alloc(struct liftoff_device *device,
drmModeAtomicReq *req)
{
struct liftoff_output *output;
@ -517,7 +517,7 @@ static bool reuse_previous_alloc(struct liftoff_display *display,
int cursor;
bool compatible;
liftoff_list_for_each(output, &display->outputs, link) {
liftoff_list_for_each(output, &device->outputs, link) {
liftoff_list_for_each(layer, &output->layers, link) {
if (layer_needs_realloc(layer)) {
return false;
@ -527,10 +527,10 @@ static bool reuse_previous_alloc(struct liftoff_display *display,
cursor = drmModeAtomicGetCursor(req);
if (!apply_current(display, req)) {
if (!apply_current(device, req)) {
return false;
}
if (!display_test_commit(display, req, &compatible) || !compatible) {
if (!device_test_commit(device, req, &compatible) || !compatible) {
drmModeAtomicSetCursor(req, cursor);
return false;
}
@ -538,38 +538,38 @@ static bool reuse_previous_alloc(struct liftoff_display *display,
return true;
}
static void mark_layers_clean(struct liftoff_display *display)
static void mark_layers_clean(struct liftoff_device *device)
{
struct liftoff_output *output;
struct liftoff_layer *layer;
liftoff_list_for_each(output, &display->outputs, link) {
liftoff_list_for_each(output, &device->outputs, link) {
liftoff_list_for_each(layer, &output->layers, link) {
layer_mark_clean(layer);
}
}
}
static void update_layers_priority(struct liftoff_display *display)
static void update_layers_priority(struct liftoff_device *device)
{
struct liftoff_output *output;
struct liftoff_layer *layer;
display->page_flip_counter++;
device->page_flip_counter++;
bool period_elapsed =
display->page_flip_counter >= LIFTOFF_PRIORITY_PERIOD;
device->page_flip_counter >= LIFTOFF_PRIORITY_PERIOD;
if (period_elapsed) {
display->page_flip_counter = 0;
device->page_flip_counter = 0;
}
liftoff_list_for_each(output, &display->outputs, link) {
liftoff_list_for_each(output, &device->outputs, link) {
liftoff_list_for_each(layer, &output->layers, link) {
layer_update_priority(layer, period_elapsed);
}
}
}
bool liftoff_display_apply(struct liftoff_display *display, drmModeAtomicReq *req)
bool liftoff_device_apply(struct liftoff_device *device, drmModeAtomicReq *req)
{
struct liftoff_output *output;
struct liftoff_plane *plane;
@ -579,15 +579,15 @@ bool liftoff_display_apply(struct liftoff_display *display, drmModeAtomicReq *re
size_t i;
bool compatible;
update_layers_priority(display);
update_layers_priority(device);
if (reuse_previous_alloc(display, req)) {
if (reuse_previous_alloc(device, req)) {
liftoff_log(LIFTOFF_DEBUG, "Re-using previous plane allocation");
return true;
}
/* Unset all existing plane and layer mappings. */
liftoff_list_for_each(plane, &display->planes, link) {
liftoff_list_for_each(plane, &device->planes, link) {
if (plane->layer != NULL) {
plane->layer->plane = NULL;
plane->layer = NULL;
@ -596,7 +596,7 @@ bool liftoff_display_apply(struct liftoff_display *display, drmModeAtomicReq *re
/* Disable all planes. Do it before building mappings to make sure not
to hit bandwidth limits because too many planes are enabled. */
liftoff_list_for_each(plane, &display->planes, link) {
liftoff_list_for_each(plane, &device->planes, link) {
if (plane->layer == NULL) {
liftoff_log(LIFTOFF_DEBUG,
"Disabling plane %d", plane->id);
@ -608,7 +608,7 @@ bool liftoff_display_apply(struct liftoff_display *display, drmModeAtomicReq *re
}
result.req = req;
result.planes_len = liftoff_list_length(&display->planes);
result.planes_len = liftoff_list_length(&device->planes);
step.alloc = malloc(result.planes_len * sizeof(*step.alloc));
result.best = malloc(result.planes_len * sizeof(*result.best));
@ -622,7 +622,7 @@ bool liftoff_display_apply(struct liftoff_display *display, drmModeAtomicReq *re
* issues? Also: be fair when mapping planes to outputs, don't give all
* planes to a single output. Also: don't treat each output separately,
* allocate planes for all outputs at once. */
liftoff_list_for_each(output, &display->outputs, link) {
liftoff_list_for_each(output, &device->outputs, link) {
/* For each plane, try to find a layer. Don't do it the other
* way around (ie. for each layer, try to find a plane) because
* some drivers want user-space to enable the primary plane
@ -636,7 +636,7 @@ bool liftoff_display_apply(struct liftoff_display *display, drmModeAtomicReq *re
if (output->composition_layer != NULL) {
result.non_composition_layers_len--;
}
step.plane_link = display->planes.next;
step.plane_link = device->planes.next;
step.plane_idx = 0;
step.score = 0;
step.last_layer_zpos = INT_MAX;
@ -651,7 +651,7 @@ bool liftoff_display_apply(struct liftoff_display *display, drmModeAtomicReq *re
/* Apply the best allocation */
i = 0;
liftoff_list_for_each(plane, &display->planes, link) {
liftoff_list_for_each(plane, &device->planes, link) {
layer = result.best[i];
i++;
if (layer == NULL) {
@ -668,7 +668,7 @@ bool liftoff_display_apply(struct liftoff_display *display, drmModeAtomicReq *re
layer->plane = plane;
}
if (!apply_current(display, req)) {
if (!apply_current(device, req)) {
return false;
}
}
@ -676,7 +676,7 @@ bool liftoff_display_apply(struct liftoff_display *display, drmModeAtomicReq *re
free(step.alloc);
free(result.best);
mark_layers_clean(display);
mark_layers_clean(device);
return true;
}

View file

@ -4,45 +4,45 @@
#include "log.h"
#include "private.h"
struct liftoff_display *liftoff_display_create(int drm_fd)
struct liftoff_device *liftoff_device_create(int drm_fd)
{
struct liftoff_display *display;
struct liftoff_device *device;
drmModeRes *drm_res;
drmModePlaneRes *drm_plane_res;
uint32_t i;
display = calloc(1, sizeof(*display));
if (display == NULL) {
device = calloc(1, sizeof(*device));
if (device == NULL) {
liftoff_log_errno(LIFTOFF_ERROR, "calloc");
return NULL;
}
liftoff_list_init(&display->planes);
liftoff_list_init(&display->outputs);
liftoff_list_init(&device->planes);
liftoff_list_init(&device->outputs);
display->drm_fd = dup(drm_fd);
if (display->drm_fd < 0) {
device->drm_fd = dup(drm_fd);
if (device->drm_fd < 0) {
liftoff_log_errno(LIFTOFF_ERROR, "dup");
liftoff_display_destroy(display);
liftoff_device_destroy(device);
return NULL;
}
drm_res = drmModeGetResources(drm_fd);
if (drm_res == NULL) {
liftoff_log_errno(LIFTOFF_ERROR, "drmModeGetResources");
liftoff_display_destroy(display);
liftoff_device_destroy(device);
return NULL;
}
display->crtcs = malloc(drm_res->count_crtcs * sizeof(uint32_t));
if (display->crtcs == NULL) {
device->crtcs = malloc(drm_res->count_crtcs * sizeof(uint32_t));
if (device->crtcs == NULL) {
liftoff_log_errno(LIFTOFF_ERROR, "malloc");
drmModeFreeResources(drm_res);
liftoff_display_destroy(display);
liftoff_device_destroy(device);
return NULL;
}
display->crtcs_len = drm_res->count_crtcs;
memcpy(display->crtcs, drm_res->crtcs,
device->crtcs_len = drm_res->count_crtcs;
memcpy(device->crtcs, drm_res->crtcs,
drm_res->count_crtcs * sizeof(uint32_t));
drmModeFreeResources(drm_res);
@ -51,29 +51,29 @@ struct liftoff_display *liftoff_display_create(int drm_fd)
drm_plane_res = drmModeGetPlaneResources(drm_fd);
if (drm_plane_res == NULL) {
liftoff_log_errno(LIFTOFF_ERROR, "drmModeGetPlaneResources");
liftoff_display_destroy(display);
liftoff_device_destroy(device);
return NULL;
}
for (i = 0; i < drm_plane_res->count_planes; i++) {
if (plane_create(display, drm_plane_res->planes[i]) == NULL) {
liftoff_display_destroy(display);
if (plane_create(device, drm_plane_res->planes[i]) == NULL) {
liftoff_device_destroy(device);
return NULL;
}
}
drmModeFreePlaneResources(drm_plane_res);
return display;
return device;
}
void liftoff_display_destroy(struct liftoff_display *display)
void liftoff_device_destroy(struct liftoff_device *device)
{
struct liftoff_plane *plane, *tmp;
close(display->drm_fd);
liftoff_list_for_each_safe(plane, tmp, &display->planes, link) {
close(device->drm_fd);
liftoff_list_for_each_safe(plane, tmp, &device->planes, link) {
plane_destroy(plane);
}
free(display->crtcs);
free(display);
free(device->crtcs);
free(device);
}

View file

@ -7,7 +7,7 @@
#include <stddef.h>
#include <xf86drmMode.h>
struct liftoff_display;
struct liftoff_device;
struct liftoff_output;
struct liftoff_layer;
@ -15,21 +15,21 @@ struct liftoff_layer;
* Initialize libliftoff for a DRM node. The node is expected to have
* DRM_CLIENT_CAP_UNIVERSAL_PLANES and DRM_CLIENT_CAP_ATOMIC enabled.
*/
struct liftoff_display *liftoff_display_create(int drm_fd);
void liftoff_display_destroy(struct liftoff_display *display);
struct liftoff_device *liftoff_device_create(int drm_fd);
void liftoff_device_destroy(struct liftoff_device *device);
/**
* Build a layer to plane mapping and append the plane configuration to `req`.
* Callers are expected to commit `req` afterwards and can read the layer to
* plane mapping with `liftoff_layer_get_plane_id`.
*/
bool liftoff_display_apply(struct liftoff_display *display,
bool liftoff_device_apply(struct liftoff_device *device,
drmModeAtomicReq *req);
/**
* Make the display manage a CRTC's planes. The returned output allows callers
* Make the device manage a CRTC's planes. The returned output allows callers
* to attach layers.
*/
struct liftoff_output *liftoff_output_create(struct liftoff_display *display,
struct liftoff_output *liftoff_output_create(struct liftoff_device *device,
uint32_t crtc_id);
void liftoff_output_destroy(struct liftoff_output *output);
/**

View file

@ -9,7 +9,7 @@
* given number of page-flips */
#define LIFTOFF_PRIORITY_PERIOD 60
struct liftoff_display {
struct liftoff_device {
int drm_fd;
struct liftoff_list planes; /* liftoff_plane.link */
@ -22,10 +22,10 @@ struct liftoff_display {
};
struct liftoff_output {
struct liftoff_display *display;
struct liftoff_device *device;
uint32_t crtc_id;
size_t crtc_index;
struct liftoff_list link; /* liftoff_display.outputs */
struct liftoff_list link; /* liftoff_device.outputs */
struct liftoff_layer *composition_layer;
@ -56,7 +56,7 @@ struct liftoff_plane {
uint32_t type;
int zpos; /* greater values mean closer to the eye */
/* TODO: formats */
struct liftoff_list link; /* liftoff_display.planes */
struct liftoff_list link; /* liftoff_device.planes */
struct liftoff_plane_property *props;
size_t props_len;
@ -81,7 +81,7 @@ bool layer_intersects(struct liftoff_layer *a, struct liftoff_layer *b);
void layer_mark_clean(struct liftoff_layer *layer);
void layer_update_priority(struct liftoff_layer *layer, bool make_current);
struct liftoff_plane *plane_create(struct liftoff_display *display, uint32_t id);
struct liftoff_plane *plane_create(struct liftoff_device *device, uint32_t id);
void plane_destroy(struct liftoff_plane *plane);
struct liftoff_plane_property *plane_get_property(struct liftoff_plane *plane,
const char *name);

View file

@ -4,7 +4,7 @@
#include <sys/types.h>
#include "private.h"
struct liftoff_output *liftoff_output_create(struct liftoff_display *display,
struct liftoff_output *liftoff_output_create(struct liftoff_device *device,
uint32_t crtc_id)
{
struct liftoff_output *output;
@ -12,8 +12,8 @@ struct liftoff_output *liftoff_output_create(struct liftoff_display *display,
size_t i;
crtc_index = -1;
for (i = 0; i < display->crtcs_len; i++) {
if (display->crtcs[i] == crtc_id) {
for (i = 0; i < device->crtcs_len; i++) {
if (device->crtcs[i] == crtc_id) {
crtc_index = i;
break;
}
@ -26,11 +26,11 @@ struct liftoff_output *liftoff_output_create(struct liftoff_display *display,
if (output == NULL) {
return NULL;
}
output->display = display;
output->device = device;
output->crtc_id = crtc_id;
output->crtc_index = crtc_index;
liftoff_list_init(&output->layers);
liftoff_list_insert(&display->outputs, &output->link);
liftoff_list_insert(&device->outputs, &output->link);
return output;
}

22
plane.c
View file

@ -3,7 +3,7 @@
#include <string.h>
#include "private.h"
static int guess_plane_zpos_from_type(struct liftoff_display *display,
static int guess_plane_zpos_from_type(struct liftoff_device *device,
uint32_t plane_id, uint32_t type)
{
struct liftoff_plane *primary;
@ -16,10 +16,10 @@ static int guess_plane_zpos_from_type(struct liftoff_display *display,
case DRM_PLANE_TYPE_CURSOR:
return 2;
case DRM_PLANE_TYPE_OVERLAY:
if (liftoff_list_empty(&display->planes)) {
if (liftoff_list_empty(&device->planes)) {
return 0; /* No primary plane, shouldn't happen */
}
primary = liftoff_container_of(display->planes.next,
primary = liftoff_container_of(device->planes.next,
primary, link);
if (plane_id < primary->id) {
return -1;
@ -30,7 +30,7 @@ static int guess_plane_zpos_from_type(struct liftoff_display *display,
return 0;
}
struct liftoff_plane *plane_create(struct liftoff_display *display, uint32_t id)
struct liftoff_plane *plane_create(struct liftoff_device *device, uint32_t id)
{
struct liftoff_plane *plane, *cur;
drmModePlane *drm_plane;
@ -47,7 +47,7 @@ struct liftoff_plane *plane_create(struct liftoff_display *display, uint32_t id)
return NULL;
}
drm_plane = drmModeGetPlane(display->drm_fd, id);
drm_plane = drmModeGetPlane(device->drm_fd, id);
if (drm_plane == NULL) {
liftoff_log_errno(LIFTOFF_ERROR, "drmModeGetPlane");
return NULL;
@ -56,7 +56,7 @@ struct liftoff_plane *plane_create(struct liftoff_display *display, uint32_t id)
plane->possible_crtcs = drm_plane->possible_crtcs;
drmModeFreePlane(drm_plane);
drm_props = drmModeObjectGetProperties(display->drm_fd, id,
drm_props = drmModeObjectGetProperties(device->drm_fd, id,
DRM_MODE_OBJECT_PLANE);
if (drm_props == NULL) {
liftoff_log_errno(LIFTOFF_ERROR, "drmModeObjectGetProperties");
@ -70,7 +70,7 @@ struct liftoff_plane *plane_create(struct liftoff_display *display, uint32_t id)
return NULL;
}
for (i = 0; i < drm_props->count_props; i++) {
drm_prop = drmModeGetProperty(display->drm_fd,
drm_prop = drmModeGetProperty(device->drm_fd,
drm_props->props[i]);
if (drm_prop == NULL) {
liftoff_log_errno(LIFTOFF_ERROR, "drmModeGetProperty");
@ -101,7 +101,7 @@ struct liftoff_plane *plane_create(struct liftoff_display *display, uint32_t id)
free(plane);
return NULL;
} else if (!has_zpos) {
plane->zpos = guess_plane_zpos_from_type(display, plane->id,
plane->zpos = guess_plane_zpos_from_type(device, plane->id,
plane->type);
}
@ -110,9 +110,9 @@ struct liftoff_plane *plane_create(struct liftoff_display *display, uint32_t id)
* far from the primary planes, then planes closer and closer to the
* primary plane. */
if (plane->type == DRM_PLANE_TYPE_PRIMARY) {
liftoff_list_insert(&display->planes, &plane->link);
liftoff_list_insert(&device->planes, &plane->link);
} else {
liftoff_list_for_each(cur, &display->planes, link) {
liftoff_list_for_each(cur, &device->planes, link) {
if (cur->type != DRM_PLANE_TYPE_PRIMARY &&
plane->zpos >= cur->zpos) {
liftoff_list_insert(cur->link.prev, &plane->link);
@ -121,7 +121,7 @@ struct liftoff_plane *plane_create(struct liftoff_display *display, uint32_t id)
}
if (plane->link.next == NULL) { /* not inserted */
liftoff_list_insert(display->planes.prev, &plane->link);
liftoff_list_insert(device->planes.prev, &plane->link);
}
}