drm_hwcomposer: Add support for color encoding and range properties

Starting from the linux-v4.17, the DRM module has support for different
non-RGB color encodings that are controlled through plane-specific
COLOR_ENCODING and COLOR_RANGE properties.

This patch creates a matching between the HWC layer dataspace which is
supported by DRM driver and DRM plane properties.

Signed-off-by: Matvii Zorin <matvii.zorin@globallogic.com>
diff --git a/drm/DrmPlane.cpp b/drm/DrmPlane.cpp
index f994252..65bd8be 100644
--- a/drm/DrmPlane.cpp
+++ b/drm/DrmPlane.cpp
@@ -17,6 +17,7 @@
 #define LOG_TAG "hwc-drm-plane"
 
 #include "DrmPlane.h"
+#include "bufferinfo/BufferInfoGetter.h"
 
 #include <errno.h>
 #include <log/log.h>
@@ -141,6 +142,17 @@
   if (ret)
     ALOGI("Could not get IN_FENCE_FD property");
 
+  if (HasNonRgbFormat()) {
+    ret = drm_->GetPlaneProperty(*this, "COLOR_ENCODING",
+                                 &color_encoding_propery_);
+    if (ret)
+      ALOGI("Could not get COLOR_ENCODING property");
+
+    ret = drm_->GetPlaneProperty(*this, "COLOR_RANGE", &color_range_property_);
+    if (ret)
+      ALOGI("Could not get COLOR_RANGE property");
+  }
+
   return 0;
 }
 
@@ -161,6 +173,13 @@
          std::end(formats_);
 }
 
+bool DrmPlane::HasNonRgbFormat() const {
+  return std::find_if_not(std::begin(formats_), std::end(formats_),
+                          [](uint32_t format) {
+                            return BufferInfoGetter::IsDrmFormatRgb(format);
+                          }) != std::end(formats_);
+}
+
 const DrmProperty &DrmPlane::crtc_property() const {
   return crtc_property_;
 }
@@ -220,4 +239,12 @@
 const DrmProperty &DrmPlane::in_fence_fd_property() const {
   return in_fence_fd_property_;
 }
+
+const DrmProperty &DrmPlane::color_encoding_propery() const {
+  return color_encoding_propery_;
+}
+
+const DrmProperty &DrmPlane::color_range_property() const {
+  return color_range_property_;
+}
 }  // namespace android
diff --git a/drm/DrmPlane.h b/drm/DrmPlane.h
index 16731a8..7a915cc 100644
--- a/drm/DrmPlane.h
+++ b/drm/DrmPlane.h
@@ -44,6 +44,7 @@
   uint32_t type() const;
 
   bool IsFormatSupported(uint32_t format) const;
+  bool HasNonRgbFormat() const;
 
   const DrmProperty &crtc_property() const;
   const DrmProperty &fb_property() const;
@@ -60,6 +61,8 @@
   const DrmProperty &alpha_property() const;
   const DrmProperty &blend_property() const;
   const DrmProperty &in_fence_fd_property() const;
+  const DrmProperty &color_encoding_propery() const;
+  const DrmProperty &color_range_property() const;
 
  private:
   DrmDevice *drm_;
@@ -86,6 +89,8 @@
   DrmProperty alpha_property_;
   DrmProperty blend_property_;
   DrmProperty in_fence_fd_property_;
+  DrmProperty color_encoding_propery_;
+  DrmProperty color_range_property_;
 };
 }  // namespace android