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
This commit is contained in:
Simon Ser 2019-09-08 18:33:09 +03:00
parent d90d7bdc36
commit 42db49c6fe
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
2 changed files with 38 additions and 1 deletions

View file

@ -7,7 +7,33 @@
#include <unistd.h>
#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;

View file

@ -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 */