2019-10-11 16:09:35 +02:00
|
|
|
#include <inttypes.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "private.h"
|
|
|
|
|
2019-11-24 12:59:10 +01:00
|
|
|
static int guess_plane_zpos_from_type(struct liftoff_device *device,
|
2019-10-11 16:09:35 +02:00
|
|
|
uint32_t plane_id, uint32_t type)
|
|
|
|
{
|
|
|
|
struct liftoff_plane *primary;
|
|
|
|
|
|
|
|
/* From far to close to the eye: primary, overlay, cursor. Unless
|
|
|
|
* the overlay ID < primary ID. */
|
|
|
|
switch (type) {
|
|
|
|
case DRM_PLANE_TYPE_PRIMARY:
|
|
|
|
return 0;
|
|
|
|
case DRM_PLANE_TYPE_CURSOR:
|
|
|
|
return 2;
|
|
|
|
case DRM_PLANE_TYPE_OVERLAY:
|
2019-11-24 12:59:10 +01:00
|
|
|
if (liftoff_list_empty(&device->planes)) {
|
2019-10-11 16:09:35 +02:00
|
|
|
return 0; /* No primary plane, shouldn't happen */
|
|
|
|
}
|
2019-11-24 12:59:10 +01:00
|
|
|
primary = liftoff_container_of(device->planes.next,
|
2019-10-11 16:09:35 +02:00
|
|
|
primary, link);
|
|
|
|
if (plane_id < primary->id) {
|
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-02-29 02:04:26 +01:00
|
|
|
static void log_plane(struct liftoff_device *device,
|
|
|
|
struct liftoff_plane *plane)
|
2020-02-26 18:35:00 +01:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
int per_line = 0;
|
|
|
|
|
|
|
|
if (!log_has(LIFTOFF_DEBUG)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-29 02:04:26 +01:00
|
|
|
debug_cnt(device, " type: ");
|
2020-02-26 18:35:00 +01:00
|
|
|
if (plane->type == DRM_PLANE_TYPE_PRIMARY) {
|
2020-02-29 02:04:26 +01:00
|
|
|
debug_cnt(device, "Primary");
|
2020-02-26 18:35:00 +01:00
|
|
|
} else if (plane->type == DRM_PLANE_TYPE_CURSOR) {
|
2020-02-29 02:04:26 +01:00
|
|
|
debug_cnt(device, "Cursor");
|
2020-02-26 18:35:00 +01:00
|
|
|
} else {
|
2020-02-29 02:04:26 +01:00
|
|
|
debug_cnt(device, "Overlay");
|
2020-02-26 18:35:00 +01:00
|
|
|
}
|
2020-02-29 02:51:17 +01:00
|
|
|
debug_end(device, 0);
|
2020-02-29 02:04:26 +01:00
|
|
|
|
2020-02-26 18:35:00 +01:00
|
|
|
liftoff_log(LIFTOFF_DEBUG, " zpos: %"PRIu32, plane->zpos);
|
|
|
|
|
2020-02-29 02:04:26 +01:00
|
|
|
debug_cnt(device, " props:");
|
2020-02-26 18:35:00 +01:00
|
|
|
for (i = 0; i < plane->props_len; i++) {
|
|
|
|
if (per_line == 5) {
|
2020-02-29 02:51:17 +01:00
|
|
|
debug_end(device, 0);
|
2020-02-29 02:04:26 +01:00
|
|
|
debug_cnt(device, " ");
|
2020-02-26 18:35:00 +01:00
|
|
|
per_line = 0;
|
|
|
|
}
|
2020-02-29 02:04:26 +01:00
|
|
|
debug_cnt(device, " %s", plane->props[i].name);
|
2020-02-26 18:35:00 +01:00
|
|
|
per_line++;
|
|
|
|
}
|
2020-02-29 02:51:17 +01:00
|
|
|
debug_end(device, 0);
|
2020-02-26 18:35:00 +01:00
|
|
|
}
|
|
|
|
|
2019-11-24 12:59:10 +01:00
|
|
|
struct liftoff_plane *plane_create(struct liftoff_device *device, uint32_t id)
|
2019-10-11 16:09:35 +02:00
|
|
|
{
|
|
|
|
struct liftoff_plane *plane, *cur;
|
|
|
|
drmModePlane *drm_plane;
|
|
|
|
drmModeObjectProperties *drm_props;
|
|
|
|
uint32_t i;
|
|
|
|
drmModePropertyRes *drm_prop;
|
|
|
|
struct liftoff_plane_property *prop;
|
|
|
|
uint64_t value;
|
|
|
|
bool has_type = false, has_zpos = false;
|
|
|
|
|
2020-02-29 02:04:26 +01:00
|
|
|
debug_cnt(device, "Plane %"PRIu32, id);
|
2020-02-29 02:51:17 +01:00
|
|
|
debug_end(device, 0);
|
2020-02-26 18:35:00 +01:00
|
|
|
|
2019-10-11 16:09:35 +02:00
|
|
|
plane = calloc(1, sizeof(*plane));
|
|
|
|
if (plane == NULL) {
|
2019-10-19 12:35:14 +02:00
|
|
|
liftoff_log_errno(LIFTOFF_ERROR, "calloc");
|
2019-10-11 16:09:35 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-11-24 12:59:10 +01:00
|
|
|
drm_plane = drmModeGetPlane(device->drm_fd, id);
|
2019-10-11 16:09:35 +02:00
|
|
|
if (drm_plane == NULL) {
|
2019-10-19 12:35:14 +02:00
|
|
|
liftoff_log_errno(LIFTOFF_ERROR, "drmModeGetPlane");
|
2019-10-11 16:09:35 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
plane->id = drm_plane->plane_id;
|
|
|
|
plane->possible_crtcs = drm_plane->possible_crtcs;
|
|
|
|
drmModeFreePlane(drm_plane);
|
|
|
|
|
2019-11-24 12:59:10 +01:00
|
|
|
drm_props = drmModeObjectGetProperties(device->drm_fd, id,
|
2019-10-11 16:09:35 +02:00
|
|
|
DRM_MODE_OBJECT_PLANE);
|
|
|
|
if (drm_props == NULL) {
|
2019-10-19 12:35:14 +02:00
|
|
|
liftoff_log_errno(LIFTOFF_ERROR, "drmModeObjectGetProperties");
|
2019-10-11 16:09:35 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
plane->props = calloc(drm_props->count_props,
|
|
|
|
sizeof(struct liftoff_plane_property));
|
|
|
|
if (plane->props == NULL) {
|
2019-10-19 12:35:14 +02:00
|
|
|
liftoff_log_errno(LIFTOFF_ERROR, "calloc");
|
2019-10-11 16:09:35 +02:00
|
|
|
drmModeFreeObjectProperties(drm_props);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
for (i = 0; i < drm_props->count_props; i++) {
|
2019-11-24 12:59:10 +01:00
|
|
|
drm_prop = drmModeGetProperty(device->drm_fd,
|
2019-10-11 16:09:35 +02:00
|
|
|
drm_props->props[i]);
|
|
|
|
if (drm_prop == NULL) {
|
2019-10-19 12:35:14 +02:00
|
|
|
liftoff_log_errno(LIFTOFF_ERROR, "drmModeGetProperty");
|
2019-10-11 16:09:35 +02:00
|
|
|
drmModeFreeObjectProperties(drm_props);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
prop = &plane->props[i];
|
|
|
|
memcpy(prop->name, drm_prop->name, sizeof(prop->name));
|
|
|
|
prop->id = drm_prop->prop_id;
|
|
|
|
drmModeFreeProperty(drm_prop);
|
|
|
|
plane->props_len++;
|
|
|
|
|
|
|
|
value = drm_props->prop_values[i];
|
|
|
|
if (strcmp(prop->name, "type") == 0) {
|
|
|
|
plane->type = value;
|
|
|
|
has_type = true;
|
|
|
|
} else if (strcmp(prop->name, "zpos") == 0) {
|
|
|
|
plane->zpos = value;
|
|
|
|
has_zpos = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
drmModeFreeObjectProperties(drm_props);
|
|
|
|
|
|
|
|
if (!has_type) {
|
|
|
|
liftoff_log(LIFTOFF_ERROR,
|
2020-02-26 18:35:00 +01:00
|
|
|
"plane %"PRIu32" is missing the 'type' property",
|
|
|
|
plane->id);
|
2019-10-11 16:09:35 +02:00
|
|
|
free(plane);
|
|
|
|
return NULL;
|
|
|
|
} else if (!has_zpos) {
|
2019-11-24 12:59:10 +01:00
|
|
|
plane->zpos = guess_plane_zpos_from_type(device, plane->id,
|
2019-10-11 16:09:35 +02:00
|
|
|
plane->type);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* During plane allocation, we will use the plane list order to fill
|
|
|
|
* planes with FBs. Primary planes need to be filled first, then planes
|
|
|
|
* far from the primary planes, then planes closer and closer to the
|
|
|
|
* primary plane. */
|
|
|
|
if (plane->type == DRM_PLANE_TYPE_PRIMARY) {
|
2019-11-24 12:59:10 +01:00
|
|
|
liftoff_list_insert(&device->planes, &plane->link);
|
2019-10-11 16:09:35 +02:00
|
|
|
} else {
|
2019-11-24 12:59:10 +01:00
|
|
|
liftoff_list_for_each(cur, &device->planes, link) {
|
2019-10-11 16:09:35 +02:00
|
|
|
if (cur->type != DRM_PLANE_TYPE_PRIMARY &&
|
|
|
|
plane->zpos >= cur->zpos) {
|
|
|
|
liftoff_list_insert(cur->link.prev, &plane->link);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (plane->link.next == NULL) { /* not inserted */
|
2019-11-24 12:59:10 +01:00
|
|
|
liftoff_list_insert(device->planes.prev, &plane->link);
|
2019-10-11 16:09:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-29 02:04:26 +01:00
|
|
|
log_plane(device, plane);
|
2020-02-26 18:35:00 +01:00
|
|
|
|
2019-10-11 16:09:35 +02:00
|
|
|
return plane;
|
|
|
|
}
|
|
|
|
|
|
|
|
void plane_destroy(struct liftoff_plane *plane)
|
|
|
|
{
|
2019-12-06 15:06:14 +01:00
|
|
|
if (plane->layer != NULL) {
|
|
|
|
plane->layer->plane = NULL;
|
|
|
|
}
|
2019-10-11 16:09:35 +02:00
|
|
|
liftoff_list_remove(&plane->link);
|
|
|
|
free(plane->props);
|
|
|
|
free(plane);
|
|
|
|
}
|
2019-10-19 12:43:09 +02:00
|
|
|
|
|
|
|
struct liftoff_plane_property *plane_get_property(struct liftoff_plane *plane,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < plane->props_len; i++) {
|
|
|
|
if (strcmp(plane->props[i].name, name) == 0) {
|
|
|
|
return &plane->props[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool plane_set_prop(struct liftoff_plane *plane, drmModeAtomicReq *req,
|
|
|
|
struct liftoff_plane_property *prop, uint64_t value)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = drmModeAtomicAddProperty(req, plane->id, prop->id, value);
|
|
|
|
if (ret < 0) {
|
|
|
|
liftoff_log_errno(LIFTOFF_ERROR, "drmModeAtomicAddProperty");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool set_plane_prop_str(struct liftoff_plane *plane,
|
|
|
|
drmModeAtomicReq *req, const char *name,
|
|
|
|
uint64_t value)
|
|
|
|
{
|
|
|
|
struct liftoff_plane_property *prop;
|
|
|
|
|
|
|
|
prop = plane_get_property(plane, name);
|
|
|
|
if (prop == NULL) {
|
|
|
|
liftoff_log(LIFTOFF_DEBUG,
|
|
|
|
"plane %"PRIu32" is missing the %s property",
|
|
|
|
plane->id, name);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return plane_set_prop(plane, req, prop, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool plane_apply(struct liftoff_plane *plane, struct liftoff_layer *layer,
|
|
|
|
drmModeAtomicReq *req, bool *compatible)
|
|
|
|
{
|
|
|
|
int cursor;
|
|
|
|
size_t i;
|
|
|
|
struct liftoff_layer_property *layer_prop;
|
|
|
|
struct liftoff_plane_property *plane_prop;
|
|
|
|
|
|
|
|
*compatible = true;
|
|
|
|
cursor = drmModeAtomicGetCursor(req);
|
|
|
|
|
|
|
|
if (layer == NULL) {
|
|
|
|
return set_plane_prop_str(plane, req, "FB_ID", 0) &&
|
|
|
|
set_plane_prop_str(plane, req, "CRTC_ID", 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!set_plane_prop_str(plane, req, "CRTC_ID", layer->output->crtc_id)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < layer->props_len; i++) {
|
|
|
|
layer_prop = &layer->props[i];
|
|
|
|
if (strcmp(layer_prop->name, "zpos") == 0) {
|
|
|
|
/* We don't yet support setting the zpos property. We
|
|
|
|
* only use it (read-only) during plane allocation. */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
plane_prop = plane_get_property(plane, layer_prop->name);
|
|
|
|
if (plane_prop == NULL) {
|
|
|
|
*compatible = false;
|
|
|
|
drmModeAtomicSetCursor(req, cursor);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!plane_set_prop(plane, req, plane_prop, layer_prop->value)) {
|
|
|
|
drmModeAtomicSetCursor(req, cursor);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|