drm_hwcomposer: Add DRM_CURSOR_CAP to DrmDevice

This change reads the DRM_CURSOR_CAP_{WIDTH|HEIGHT} capabilities of
DrmDevice, and exposes their values. These values can be used to
convey a reasonable cursor plane size [1].

[1] https://dri.freedesktop.org/docs/drm/gpu/drm-uapi.html#c.DRM_CAP_CURSOR_WIDTH

Change-Id: Iecf01d00a9562656c6d5b5aa8e0ac49b1dc739e5
Signed-off-by: Andrew Wolfers <aswolfers@google.com>
diff --git a/drm/DrmDevice.cpp b/drm/DrmDevice.cpp
index fa5849f..f6141d4 100644
--- a/drm/DrmDevice.cpp
+++ b/drm/DrmDevice.cpp
@@ -90,6 +90,14 @@
   }
   HasAddFb2ModifiersSupport_ = cap_value != 0;
 
+  uint64_t cursor_width = 0;
+  uint64_t cursor_height = 0;
+  if (drmGetCap(*GetFd(), DRM_CAP_CURSOR_WIDTH, &cursor_width) == 0 &&
+      drmGetCap(*GetFd(), DRM_CAP_CURSOR_HEIGHT, &cursor_height) == 0) {
+    cap_cursor_size_ = std::pair<uint64_t, uint64_t>(cursor_width,
+                                                     cursor_height);
+  }
+
   drmSetMaster(*GetFd());
   if (drmIsMaster(*GetFd()) == 0) {
     ALOGE("DRM/KMS master access required");
diff --git a/drm/DrmDevice.h b/drm/DrmDevice.h
index baa719d..ac20855 100644
--- a/drm/DrmDevice.h
+++ b/drm/DrmDevice.h
@@ -106,6 +106,10 @@
   int GetProperty(uint32_t obj_id, uint32_t obj_type, const char *prop_name,
                   DrmProperty *property) const;
 
+  const std::optional<std::pair<uint64_t, uint64_t>> &GetCapCursorSize() const {
+    return cap_cursor_size_;
+  }
+
  private:
   explicit DrmDevice(ResourceManager *res_man, uint32_t index);
   auto Init(const char *path) -> int;
@@ -123,6 +127,7 @@
 
   std::pair<uint32_t, uint32_t> min_resolution_;
   std::pair<uint32_t, uint32_t> max_resolution_;
+  std::optional<std::pair<uint64_t, uint64_t>> cap_cursor_size_;
 
   bool HasAddFb2ModifiersSupport_{};
 
@@ -130,4 +135,5 @@
 
   ResourceManager *const res_man_;
 };
+
 }  // namespace android