sdm: Add support for color mode & color transform

- Add SDM Interface for color mode & transform.
- Add support in HWC2 to query and set color mode/transform.

Change-Id: Idb2cbb610a2d63a7dd4c67b6a29e77ce81b6bd2c
Crs-fixed: 1018813
diff --git a/sdm/libs/hwc2/hwc_display_primary.cpp b/sdm/libs/hwc2/hwc_display_primary.cpp
index 40ac723..517959e 100644
--- a/sdm/libs/hwc2/hwc_display_primary.cpp
+++ b/sdm/libs/hwc2/hwc_display_primary.cpp
@@ -34,6 +34,10 @@
 #include <stdarg.h>
 #include <sys/mman.h>
 
+#include <map>
+#include <string>
+#include <vector>
+
 #include "hwc_display_primary.h"
 #include "hwc_debugger.h"
 
@@ -103,7 +107,13 @@
     use_metadata_refresh_rate_ = false;
   }
 
-  return HWCDisplay::Init();
+  int status = HWCDisplay::Init();
+  if (status) {
+    return status;
+  }
+  color_mode_ = new HWCColorMode(display_intf_);
+
+  return INT(color_mode_->Init());
 }
 
 void HWCDisplayPrimary::ProcessBootAnimCompleted() {
@@ -153,6 +163,11 @@
     return status;
   }
 
+  if (color_tranform_failed_) {
+    // Must fall back to client composition
+    MarkLayersForClientComposition();
+  }
+
   // Fill in the remaining blanks in the layers and add them to the SDM layerstack
   BuildLayerStack();
 
@@ -213,6 +228,48 @@
   return status;
 }
 
+HWC2::Error HWCDisplayPrimary::GetColorModes(uint32_t *out_num_modes,
+                                             int32_t /*android_color_mode_t*/ *out_modes) {
+  if (out_modes == nullptr) {
+    *out_num_modes = color_mode_->GetColorModeCount();
+  } else {
+    color_mode_->GetColorModes(out_num_modes, out_modes);
+  }
+
+  return HWC2::Error::None;
+}
+
+HWC2::Error HWCDisplayPrimary::SetColorMode(int32_t /*android_color_mode_t*/ mode) {
+  auto status = color_mode_->SetColorMode(mode);
+  if (status != HWC2::Error::None) {
+    DLOGE("failed for mode = %d", mode);
+    return status;
+  }
+
+  callbacks_->Refresh(HWC_DISPLAY_PRIMARY);
+
+  return status;
+}
+
+HWC2::Error HWCDisplayPrimary::SetColorTransform(const float *matrix,
+                                                 android_color_transform_t hint) {
+  if (!matrix) {
+    return HWC2::Error::BadParameter;
+  }
+
+  auto status = color_mode_->SetColorTransform(matrix, hint);
+  if (status != HWC2::Error::None) {
+    DLOGE("failed for hint = %d", hint);
+    color_tranform_failed_ = true;
+    return status;
+  }
+
+  callbacks_->Refresh(HWC_DISPLAY_PRIMARY);
+  color_tranform_failed_ = false;
+
+  return status;
+}
+
 int HWCDisplayPrimary::Perform(uint32_t operation, ...) {
   va_list args;
   va_start(args, operation);