sdm: Add support to override detail enhancer settings

1. Define an API to hwcompser to override the detail enhancer settings
   for destination scalar.
2. Disable partial update for a frame after detail enhancer parameters
   being overriden.
3. Add support to translate detail enhancer parameters to libscalar
   and configure the output of libscalar to destination scalar.

CRs-Fixed: 1005180
Change-Id: Ia152ebba7e5e6b15f91498479d423752af36006e
diff --git a/sdm/include/core/display_interface.h b/sdm/include/core/display_interface.h
index 9a44606..bb89d1d 100644
--- a/sdm/include/core/display_interface.h
+++ b/sdm/include/core/display_interface.h
@@ -76,6 +76,48 @@
                     //!< if VSync is enabled. Contents are not rendered in this state.
 };
 
+/*! @brief This enum represents flags to override detail enhancer parameters.
+
+  @sa DisplayInterface::SetDetailEnhancerData
+*/
+enum DetailEnhancerOverrideFlags {
+  kOverrideDEEnable            = 0x1,     // Specifies to enable detail enhancer
+  kOverrideDESharpen1          = 0x2,     // Specifies user defined Sharpening/smooth for noise
+  kOverrideDESharpen2          = 0x4,     // Specifies user defined Sharpening/smooth for signal
+  kOverrideDEClip              = 0x8,     // Specifies user defined DE clip shift
+  kOverrideDELimit             = 0x10,    // Specifies user defined DE limit value
+  kOverrideDEThrQuiet          = 0x20,    // Specifies user defined DE quiet threshold
+  kOverrideDEThrDieout         = 0x40,    // Specifies user defined DE dieout threshold
+  kOverrideDEThrLow            = 0x80,    // Specifies user defined DE low threshold
+  kOverrideDEThrHigh           = 0x100,   // Specifies user defined DE high threshold
+  kOverrideDEFilterConfig      = 0x200,   // Specifies user defined scaling filter config
+  kOverrideDEMax               = 0xFFFFFFFF,
+};
+
+/*! @brief This enum represents Y/RGB scaling filter configuration.
+
+  @sa DisplayInterface::SetDetailEnhancerData
+*/
+enum ScalingFilterConfig {
+  kFilterEdgeDirected,
+  kFilterCircular,
+  kFilterSeparable,
+  kFilterBilinear,
+  kFilterMax,
+};
+
+/*! @brief This enum represents the quality level of the content.
+
+  @sa DisplayInterface::SetDetailEnhancerData
+*/
+enum ContentQuality {
+  kContentQualityUnknown,  // Default: high artifact and noise
+  kContentQualityLow,      // Low quality content, high artifact and noise,
+  kContentQualityMedium,   // Medium quality, medium artifact and noise,
+  kContentQualityHigh,     // High quality content, low artifact and noise
+  kContentQualityMax,
+};
+
 /*! @brief This structure defines configuration for fixed properties of a display device.
 
   @sa DisplayInterface::GetConfig
@@ -109,6 +151,30 @@
   int64_t timestamp = 0;    //!< System monotonic clock timestamp in nanoseconds.
 };
 
+/*! @brief The structure defines the user input for detail enhancer module.
+
+  @sa DisplayInterface::SetDetailEnhancerData
+*/
+struct DisplayDetailEnhancerData {
+  uint32_t override_flags = 0;        // flags to specify which data to be set.
+  uint16_t enable = 0;                // Detail enchancer enable
+  int16_t sharpen_level1 = 0;         // Sharpening/smooth strenght for noise
+  int16_t sharpen_level2 = 0;         // Sharpening/smooth strenght for signal
+  uint16_t clip = 0;                  // DE clip shift
+  uint16_t limit = 0;                 // DE limit value
+  uint16_t thr_quiet = 0;             // DE quiet threshold
+  uint16_t thr_dieout = 0;            // DE dieout threshold
+  uint16_t thr_low = 0;               // DE low threshold
+  uint16_t thr_high = 0;              // DE high threshold
+  int32_t sharp_factor = 50;          // sharp_factor specifies sharpness/smoothness level,
+                                      // range -100..100 positive for sharpness and negative for
+                                      // smoothness
+  ContentQuality quality_level = kContentQualityUnknown;
+                                      // Specifies context quality level
+  ScalingFilterConfig filter_config = kFilterEdgeDirected;
+                                      // Y/RGB filter configuration
+};
+
 /*! @brief Display device event handler implemented by the client.
 
   @details This class declares prototype for display device event handler methods which must be
@@ -499,6 +565,14 @@
   */
   virtual DisplayError GetFrameBufferConfig(DisplayConfigVariableInfo *variable_info) = 0;
 
+  /*! @brief Method to set detail enhancement data.
+
+    @param[in] de_data \link DisplayDetailEnhancerData \endlink
+
+    @return \link DisplayError \endlink
+  */
+  virtual DisplayError SetDetailEnhancerData(const DisplayDetailEnhancerData &de_data) = 0;
+
  protected:
   virtual ~DisplayInterface() { }
 };
diff --git a/sdm/include/private/hw_info_types.h b/sdm/include/private/hw_info_types.h
index 1a3fc05..0f40e17 100644
--- a/sdm/include/private/hw_info_types.h
+++ b/sdm/include/private/hw_info_types.h
@@ -91,15 +91,6 @@
   kHWSubBlockMax,
 };
 
-// y/RGB & UV Scaling Filters
-enum HWScalingFilter {
-  kScalingFilterEdgeDirected,
-  kScalingFilterCircular,
-  kScalingFilterSeparable,
-  kScalingFilterBilinear,
-  kScalingFilterMax,
-};
-
 enum HWAlphaInterpolation {
   kInterpolationPixelRepeat,
   kInterpolationBilinear,
@@ -316,16 +307,7 @@
   uint64_t sep_lut = 0;
 };
 
-struct HWDetailEnhanceData {
-  uint32_t enable = 0;
-  int16_t sharpen_level1 = 0;
-  int16_t sharpen_level2 = 0;
-  uint16_t clip = 0;
-  uint16_t limit = 0;
-  uint16_t thr_quiet = 0;
-  uint16_t thr_dieout = 0;
-  uint16_t thr_low = 0;
-  uint16_t thr_high = 0;
+struct HWDetailEnhanceData : DisplayDetailEnhancerData {
   uint16_t prec_shift = 0;
   int16_t adjust_a[MAX_DETAIL_ENHANCE_CURVE] = {0};
   int16_t adjust_b[MAX_DETAIL_ENHANCE_CURVE] = {0};
@@ -370,8 +352,8 @@
   uint32_t dst_height = 0;
   HWPlane plane[MAX_PLANES];
   // scale_v2_data fields
-  HWScalingFilter y_rgb_filter_cfg = kScalingFilterEdgeDirected;
-  HWScalingFilter uv_filter_cfg = kScalingFilterEdgeDirected;
+  ScalingFilterConfig y_rgb_filter_cfg = kFilterEdgeDirected;
+  ScalingFilterConfig uv_filter_cfg = kFilterEdgeDirected;
   HWAlphaInterpolation alpha_filter_cfg = kInterpolationPixelRepeat;
   HWBlendingFilter blend_cfg = kBlendFilterCircular;
 
diff --git a/sdm/include/private/resource_interface.h b/sdm/include/private/resource_interface.h
index a5ed619..6115112 100644
--- a/sdm/include/private/resource_interface.h
+++ b/sdm/include/private/resource_interface.h
@@ -58,6 +58,8 @@
                                               int x, int y) = 0;
   virtual DisplayError SetMaxBandwidthMode(HWBwModes mode) = 0;
   virtual DisplayError GetScaleLutConfig(HWScaleLutInfo *lut_info) = 0;
+  virtual DisplayError SetDetailEnhancerData(Handle display_ctx,
+                                             const DisplayDetailEnhancerData &de_data) = 0;
 
  protected:
   virtual ~ResourceInterface() { }
diff --git a/sdm/libs/core/comp_manager.cpp b/sdm/libs/core/comp_manager.cpp
index 289c5d9..6fa7e5f 100644
--- a/sdm/libs/core/comp_manager.cpp
+++ b/sdm/libs/core/comp_manager.cpp
@@ -481,5 +481,15 @@
   return resource_intf_->GetScaleLutConfig(lut_info);
 }
 
+DisplayError CompManager::SetDetailEnhancerData(Handle display_ctx,
+                                                const DisplayDetailEnhancerData &de_data) {
+  SCOPE_LOCK(locker_);
+
+  DisplayCompositionContext *display_comp_ctx =
+                             reinterpret_cast<DisplayCompositionContext *>(display_ctx);
+
+  return resource_intf_->SetDetailEnhancerData(display_comp_ctx->display_resource_ctx, de_data);
+}
+
 }  // namespace sdm
 
diff --git a/sdm/libs/core/comp_manager.h b/sdm/libs/core/comp_manager.h
index 5587ab1..a77eed0 100644
--- a/sdm/libs/core/comp_manager.h
+++ b/sdm/libs/core/comp_manager.h
@@ -66,6 +66,7 @@
   bool CanSetIdleTimeout(Handle display_ctx);
   DisplayError SetMaxBandwidthMode(HWBwModes mode);
   DisplayError GetScaleLutConfig(HWScaleLutInfo *lut_info);
+  DisplayError SetDetailEnhancerData(Handle display_ctx, const DisplayDetailEnhancerData &de_data);
 
   // DumpImpl method
   virtual void AppendDump(char *buffer, uint32_t length);
diff --git a/sdm/libs/core/display_base.cpp b/sdm/libs/core/display_base.cpp
index c904e00..d9583b7 100644
--- a/sdm/libs/core/display_base.cpp
+++ b/sdm/libs/core/display_base.cpp
@@ -992,4 +992,9 @@
   return kErrorNone;
 }
 
+DisplayError DisplayBase::SetDetailEnhancerData(const DisplayDetailEnhancerData &de_data) {
+  SCOPE_LOCK(locker_);
+  return SetDetailEnhancerDataLocked(de_data);
+}
+
 }  // namespace sdm
diff --git a/sdm/libs/core/display_base.h b/sdm/libs/core/display_base.h
index e070bed..1672351 100644
--- a/sdm/libs/core/display_base.h
+++ b/sdm/libs/core/display_base.h
@@ -88,6 +88,7 @@
   DisplayError GetMixerResolution(uint32_t *width, uint32_t *height) final;
   DisplayError SetFrameBufferConfig(const DisplayConfigVariableInfo &variable_info) final;
   DisplayError GetFrameBufferConfig(DisplayConfigVariableInfo *variable_info) final;
+  DisplayError SetDetailEnhancerData(const DisplayDetailEnhancerData &de_data) final;
 
  protected:
   virtual DisplayError PrepareLocked(LayerStack *layer_stack);
@@ -108,6 +109,9 @@
   virtual DisplayError GetMixerResolutionLocked(uint32_t *width, uint32_t *height);
   virtual DisplayError SetFrameBufferConfigLocked(const DisplayConfigVariableInfo &variable_info);
   virtual DisplayError GetFrameBufferConfigLocked(DisplayConfigVariableInfo *variable_info);
+  virtual DisplayError SetDetailEnhancerDataLocked(const DisplayDetailEnhancerData &de_data) {
+    return kErrorNotSupported;
+  }
 
   // DumpImpl method
   void AppendDump(char *buffer, uint32_t length);
diff --git a/sdm/libs/core/display_primary.cpp b/sdm/libs/core/display_primary.cpp
index b1b7979..70b96fe 100644
--- a/sdm/libs/core/display_primary.cpp
+++ b/sdm/libs/core/display_primary.cpp
@@ -448,5 +448,16 @@
   return false;
 }
 
+DisplayError DisplayPrimary::SetDetailEnhancerDataLocked(const DisplayDetailEnhancerData &de_data) {
+  DisplayError error = comp_manager_->SetDetailEnhancerData(display_comp_ctx_, de_data);
+  if (error != kErrorNone) {
+    return error;
+  }
+
+  DisablePartialUpdateOneFrameLocked();
+
+  return kErrorNone;
+}
+
 }  // namespace sdm
 
diff --git a/sdm/libs/core/display_primary.h b/sdm/libs/core/display_primary.h
index 15c9dfa..f029961 100644
--- a/sdm/libs/core/display_primary.h
+++ b/sdm/libs/core/display_primary.h
@@ -73,6 +73,7 @@
   virtual DisplayError ControlPartialUpdateLocked(bool enable, uint32_t *pending);
   virtual DisplayError DisablePartialUpdateOneFrameLocked();
   virtual DisplayError SetMixerResolutionLocked(uint32_t width, uint32_t height);
+  virtual DisplayError SetDetailEnhancerDataLocked(const DisplayDetailEnhancerData &de_data);
 
   bool NeedsMixerReconfiguration(LayerStack *layer_stack, uint32_t *new_mixer_width,
                                  uint32_t *new_mixer_height);
diff --git a/sdm/libs/core/fb/hw_scale.cpp b/sdm/libs/core/fb/hw_scale.cpp
index 06277fc..3d175e5 100644
--- a/sdm/libs/core/fb/hw_scale.cpp
+++ b/sdm/libs/core/fb/hw_scale.cpp
@@ -241,19 +241,19 @@
   }
 }
 
-uint32_t HWScaleV2::GetMDPScalingFilter(HWScalingFilter filter_cfg) {
+uint32_t HWScaleV2::GetMDPScalingFilter(ScalingFilterConfig filter_cfg) {
   switch (filter_cfg) {
-  case kScalingFilterEdgeDirected:
+  case kFilterEdgeDirected:
     return FILTER_EDGE_DIRECTED_2D;
-  case kScalingFilterCircular:
+  case kFilterCircular:
     return FILTER_CIRCULAR_2D;
-  case kScalingFilterSeparable:
+  case kFilterSeparable:
     return FILTER_SEPARABLE_1D;
-  case kScalingFilterBilinear:
+  case kFilterBilinear:
     return FILTER_BILINEAR;
   default:
     DLOGE("Invalid Scaling Filter");
-    return kScalingFilterMax;
+    return kFilterMax;
   }
 }
 
diff --git a/sdm/libs/core/fb/hw_scale.h b/sdm/libs/core/fb/hw_scale.h
index 022d5a1..7590833 100644
--- a/sdm/libs/core/fb/hw_scale.h
+++ b/sdm/libs/core/fb/hw_scale.h
@@ -76,7 +76,7 @@
 
  private:
   uint32_t GetMDPAlphaInterpolation(HWAlphaInterpolation alpha_filter_cfg);
-  uint32_t GetMDPScalingFilter(HWScalingFilter filter_cfg);
+  uint32_t GetMDPScalingFilter(ScalingFilterConfig filter_cfg);
 };
 
 }  // namespace sdm
diff --git a/sdm/libs/core/resource_default.cpp b/sdm/libs/core/resource_default.cpp
index 312f55f..bdbd8b7 100644
--- a/sdm/libs/core/resource_default.cpp
+++ b/sdm/libs/core/resource_default.cpp
@@ -904,4 +904,9 @@
   return kErrorNone;
 }
 
+DisplayError ResourceDefault::SetDetailEnhancerData(Handle display_ctx,
+                                                    const DisplayDetailEnhancerData &de_data) {
+  return kErrorNotSupported;
+}
+
 }  // namespace sdm
diff --git a/sdm/libs/core/resource_default.h b/sdm/libs/core/resource_default.h
index 29258e6..b57ce94 100644
--- a/sdm/libs/core/resource_default.h
+++ b/sdm/libs/core/resource_default.h
@@ -59,6 +59,8 @@
   DisplayError ValidateCursorConfig(Handle display_ctx, const Layer *layer, bool is_top);
   DisplayError ValidateCursorPosition(Handle display_ctx, HWLayers *hw_layers, int x, int y);
   DisplayError SetMaxBandwidthMode(HWBwModes mode);
+  virtual DisplayError SetDetailEnhancerData(Handle display_ctx,
+                                             const DisplayDetailEnhancerData &de_data);
 
  private:
   enum PipeOwner {