backend-drm: Hard-code zpos values if HW doesn't exposes them
authorMarius Vlad <marius.vlad@collabora.com>
Tue, 29 Oct 2019 15:29:37 +0000 (17:29 +0200)
committerDaniel Stone <daniels@collabora.com>
Mon, 11 Nov 2019 16:51:48 +0000 (16:51 +0000)
This is based on the assumption that overlays are in between cursor and
primary plane and it is required to be able to assign views to planes,
even if the driver doesn't not expose such property.

As we hard-code them as immutable the commit part would not need any
further modifications.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
Suggested-by: Daniel Stone <daniel.stone@collabora.com>
libweston/backend-drm/drm.c

index dd579e3ca824ee73a87a5dda063c6da0ba8a63ff..33ccbeb364f5211140c05e2b7d3b8ccfe843c418 100644 (file)
 
 static const char default_seat[] = "seat0";
 
+static void
+drm_backend_create_faked_zpos(struct drm_backend *b)
+{
+       struct drm_plane *plane;
+       uint64_t zpos = 0ULL;
+       uint64_t zpos_min_primary;
+       uint64_t zpos_min_overlay;
+       uint64_t zpos_min_cursor;
+
+       zpos_min_primary = zpos;
+       wl_list_for_each(plane, &b->plane_list, link) {
+               /* if the property is there, bail out sooner */
+               if (plane->props[WDRM_PLANE_ZPOS].prop_id != 0)
+                       return;
+
+               if (plane->type != WDRM_PLANE_TYPE_PRIMARY)
+                       continue;
+               zpos++;
+       }
+
+       zpos_min_overlay = zpos;
+       wl_list_for_each(plane, &b->plane_list, link) {
+               if (plane->type != WDRM_PLANE_TYPE_OVERLAY)
+                       continue;
+               zpos++;
+       }
+
+       zpos_min_cursor = zpos;
+       wl_list_for_each(plane, &b->plane_list, link) {
+               if (plane->type != WDRM_PLANE_TYPE_CURSOR)
+                       continue;
+               zpos++;
+       }
+
+       drm_debug(b, "[drm-backend] zpos property not found. "
+                    "Using invented immutable zpos values:\n");
+       /* assume that invented zpos values are immutable */
+       wl_list_for_each(plane, &b->plane_list, link) {
+               if (plane->type == WDRM_PLANE_TYPE_PRIMARY) {
+                       plane->zpos_min = zpos_min_primary;
+                       plane->zpos_max = zpos_min_primary;
+               } else if (plane->type == WDRM_PLANE_TYPE_OVERLAY) {
+                       plane->zpos_min = zpos_min_overlay;
+                       plane->zpos_max = zpos_min_overlay;
+               } else if (plane->type == WDRM_PLANE_TYPE_CURSOR) {
+                       plane->zpos_min = zpos_min_cursor;
+                       plane->zpos_max = zpos_min_cursor;
+               }
+               drm_debug(b, "\t[plane] %s plane %d, zpos_min %"PRIu64", "
+                             "zpos_max %"PRIu64"\n",
+                             drm_output_get_plane_type_name(plane),
+                             plane->plane_id, plane->zpos_min, plane->zpos_max);
+       }
+}
+
 static void
 wl_array_remove_uint32(struct wl_array *array, uint32_t elm)
 {
@@ -2856,6 +2911,9 @@ drm_backend_create(struct weston_compositor *compositor,
                goto err_udev_input;
        }
 
+       /* 'compute' faked zpos values in case HW doesn't expose any */
+       drm_backend_create_faked_zpos(b);
+
        /* A this point we have some idea of whether or not we have a working
         * cursor plane. */
        if (!b->cursors_are_broken)