sdm: Add support for dynamic color metadata

Change updates the dynamic color metadata interface for HDR10.
Move the creation of colormanager before registering the display to
allow passing the hdr library interface to color manager.

CRs-Fixed: 2102517
Change-Id: I51723e896168648fac74515d2f72b6c743673e8e
diff --git a/include/color_metadata.h b/include/color_metadata.h
index aff6fc9..3ddf757 100644
--- a/include/color_metadata.h
+++ b/include/color_metadata.h
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2016, The Linux Foundation. All rights reserved.
+* Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification, are permitted
 * provided that the following conditions are met:
@@ -30,6 +30,7 @@
 #else
 #include <stdbool.h>
 #endif
+#include <stdint.h>
 
 typedef enum ColorRange {
   Range_Limited = 0,
@@ -136,6 +137,7 @@
   uint32_t           crPostLutTargetValue[3*33];
 } ColorRemappingInfo;
 
+#define HDR_DYNAMIC_META_DATA_SZ 1024
 typedef struct ColorMetaData {
   // Default values based on sRGB, needs to be overridden in gralloc
   // based on the format and size.
@@ -147,6 +149,11 @@
   MasteringDisplay   masteringDisplayInfo;
   ContentLightLevel  contentLightLevel;
   ColorRemappingInfo cRI;
+
+  // Dynamic meta data elements
+  bool dynamicMetaDataValid;
+  uint32_t dynamicMetaDataLen;
+  uint8_t dynamicMetaDataPayload[HDR_DYNAMIC_META_DATA_SZ];
 } ColorMetaData;
 
 typedef struct Color10Bit {
diff --git a/sdm/include/private/color_interface.h b/sdm/include/private/color_interface.h
index 94be13d..165c093 100644
--- a/sdm/include/private/color_interface.h
+++ b/sdm/include/private/color_interface.h
@@ -51,6 +51,19 @@
 
 typedef DisplayError (*DestroyColorInterface)(DisplayType type);
 
+class ColorModeInterface {
+ public:
+  virtual DisplayError ColorIntfGetActiveColorParam(uint32_t hint, uint32_t display_id,
+                                                    void* data) = 0;
+  virtual DisplayError ColorIntfSetActiveColorParam(uint32_t hint, uint32_t display_id,
+                                                    void* data) = 0;
+ protected:
+  virtual ~ColorModeInterface() {}
+};
+
+extern "C" ColorModeInterface* GetColorModeInterface(DisplayType type);
+extern "C" void ReleaseColorModeInterface(DisplayType type);
+
 class ColorInterface {
  public:
   virtual DisplayError ColorSVCRequestRoute(const PPDisplayAPIPayload &in_payload,
diff --git a/sdm/libs/core/display_base.cpp b/sdm/libs/core/display_base.cpp
index 51aa012..705ef80 100644
--- a/sdm/libs/core/display_base.cpp
+++ b/sdm/libs/core/display_base.cpp
@@ -83,6 +83,15 @@
     }
   }
 
+  color_mgr_ = ColorManagerProxy::CreateColorManagerProxy(display_type_, hw_intf_,
+                                                          display_attributes_, hw_panel_info_);
+
+  if (!color_mgr_) {
+    DLOGW("Unable to create ColorManagerProxy for display = %d", display_type_);
+  } else if (InitializeColorModes() != kErrorNone) {
+    DLOGW("InitColorModes failed for display = %d", display_type_);
+  }
+
   error = comp_manager_->RegisterDisplay(display_type_, display_attributes_, hw_panel_info_,
                                          mixer_attributes_, fb_config_, &display_comp_ctx_);
   if (error != kErrorNone) {
@@ -100,14 +109,6 @@
     DisplayBase::SetMaxMixerStages(max_mixer_stages);
   }
 
-  color_mgr_ = ColorManagerProxy::CreateColorManagerProxy(display_type_, hw_intf_,
-                               display_attributes_, hw_panel_info_);
-  if (!color_mgr_) {
-    DLOGW("Unable to create ColorManagerProxy for display = %d", display_type_);
-  } else if (InitializeColorModes() != kErrorNone) {
-    DLOGW("InitColorModes failed for display = %d", display_type_);
-  }
-
   Debug::Get()->GetProperty("sdm.disable_hdr_lut_gen", &disable_hdr_lut_gen_);
   // TODO(user): Temporary changes, to be removed when DRM driver supports
   // Partial update with Destination scaler enabled.
@@ -116,6 +117,7 @@
   return kErrorNone;
 
 CleanupOnError:
+  ClearColorInfo();
   if (display_comp_ctx_) {
     comp_manager_->UnregisterDisplay(display_comp_ctx_);
   }
@@ -126,15 +128,7 @@
 DisplayError DisplayBase::Deinit() {
   {  // Scope for lock
     lock_guard<recursive_mutex> obj(recursive_mutex_);
-    color_modes_.clear();
-    color_mode_map_.clear();
-    color_mode_attr_map_.clear();
-
-    if (color_mgr_) {
-      delete color_mgr_;
-      color_mgr_ = NULL;
-    }
-
+    ClearColorInfo();
     comp_manager_->UnregisterDisplay(display_comp_ctx_);
   }
   HWEventsInterface::Destroy(hw_events_intf_);
@@ -1625,4 +1619,15 @@
                                 mixer_height != display_height);
 }
 
+void DisplayBase::ClearColorInfo() {
+  color_modes_.clear();
+  color_mode_map_.clear();
+  color_mode_attr_map_.clear();
+
+  if (color_mgr_) {
+    delete color_mgr_;
+    color_mgr_ = NULL;
+  }
+}
+
 }  // namespace sdm
diff --git a/sdm/libs/core/display_base.h b/sdm/libs/core/display_base.h
index 9696a3f..94ff5f5 100644
--- a/sdm/libs/core/display_base.h
+++ b/sdm/libs/core/display_base.h
@@ -147,6 +147,7 @@
   bool IsSupportColorModeAttribute(const std::string &color_mode);
   DisplayState GetLastPowerMode();
   void SetPUonDestScaler();
+  void ClearColorInfo();
 
   recursive_mutex recursive_mutex_;
   DisplayType display_type_;