From 42db49c6fe6e7fb3d1ce62757abc3d8805cc55ff Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Sun, 8 Sep 2019 18:33:09 +0300 Subject: [PATCH] Guess zpos from plane type Many drivers don't expose the zpos plane property. We can guess it from the plane type though: primary, overlay, cursor. Except some drivers expose underlays too: underlays, primary, overlay, cursor. Underlay planes don't have a special type, they are just marked as overlays. To detect them, check whether their plane ID is less than the primary plane ID. References: https://github.com/emersion/libhwc/issues/3 --- display.c | 38 +++++++++++++++++++++++++++++++++++++- include/private.h | 1 + 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/display.c b/display.c index 7b31026..ddf844e 100644 --- a/display.c +++ b/display.c @@ -7,7 +7,33 @@ #include #include "private.h" -static struct hwc_plane *plane_create(struct hwc_display *display, int32_t id) +static int guess_plane_zpos_from_type(struct hwc_display *display, + uint32_t plane_id, int type) +{ + struct hwc_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: + if (hwc_list_empty(&display->planes)) { + return 0; /* No primary plane, shouldn't happen */ + } + primary = hwc_container_of(display->planes.next, primary, link); + if (plane_id < primary->id) { + return -1; + } else { + return 1; + } + } + return 0; +} + +static struct hwc_plane *plane_create(struct hwc_display *display, uint32_t id) { struct hwc_plane *plane; drmModePlane *drm_plane; @@ -15,6 +41,7 @@ static struct hwc_plane *plane_create(struct hwc_display *display, int32_t id) uint32_t i; drmModePropertyRes *drm_prop; struct hwc_plane_property *prop; + int type = -1; plane = calloc(1, sizeof(*plane)); if (plane == NULL) { @@ -52,9 +79,18 @@ static struct hwc_plane *plane_create(struct hwc_display *display, int32_t id) prop->id = drm_prop->prop_id; drmModeFreeProperty(drm_prop); plane->props_len++; + + if (strcmp(prop->name, "type") == 0) { + type = drm_props->prop_values[i]; + } } drmModeFreeObjectProperties(drm_props); + if (type >= 0) { + plane->zpos = guess_plane_zpos_from_type(display, plane->id, + type); + } + hwc_list_insert(display->planes.prev, &plane->link); return plane; diff --git a/include/private.h b/include/private.h index 665b3dd..936180a 100644 --- a/include/private.h +++ b/include/private.h @@ -41,6 +41,7 @@ struct hwc_layer_property { struct hwc_plane { uint32_t id; uint32_t possible_crtcs; + int zpos; /* greater values mean closer to the eye */ /* TODO: formats */ struct hwc_list link; /* hwc_display.planes */