Merge "sdm : Allow configurable sdm layer limit for external"
diff --git a/sdm/include/utils/debug.h b/sdm/include/utils/debug.h
index 99254ad..540a25e 100644
--- a/sdm/include/utils/debug.h
+++ b/sdm/include/utils/debug.h
@@ -78,6 +78,7 @@
   static bool IsAVRDisabled();
   static bool IsExtAnimDisabled();
   static DisplayError GetMixerResolution(uint32_t *width, uint32_t *height);
+  static int GetExtMaxlayers();
   static bool GetProperty(const char *property_name, char *value);
   static bool SetProperty(const char *property_name, const char *value);
 
diff --git a/sdm/libs/core/comp_manager.cpp b/sdm/libs/core/comp_manager.cpp
index b98c74e..d1530dc 100644
--- a/sdm/libs/core/comp_manager.cpp
+++ b/sdm/libs/core/comp_manager.cpp
@@ -119,6 +119,7 @@
   // resources for the added display is configured properly.
   if (!display_comp_ctx->is_primary_panel) {
     safe_mode_ = true;
+    max_sde_ext_layers_ = UINT32(Debug::GetExtMaxlayers());
   }
 
   DLOGV_IF(kTagCompManager, "registered display bit mask 0x%x, configured display bit mask 0x%x, " \
@@ -213,7 +214,7 @@
 
   // Limit 2 layer SDE Comp if its not a Primary Display
   if (!display_comp_ctx->is_primary_panel) {
-    constraints->max_layers = 2;
+    constraints->max_layers = max_sde_ext_layers_;
   }
 
   // If a strategy fails after successfully allocating resources, then set safe mode
diff --git a/sdm/libs/core/comp_manager.h b/sdm/libs/core/comp_manager.h
index 86554b9..ebb257b 100644
--- a/sdm/libs/core/comp_manager.h
+++ b/sdm/libs/core/comp_manager.h
@@ -106,6 +106,7 @@
   HWResourceInfo hw_res_info_;
   ExtensionInterface *extension_intf_ = NULL;
   uint32_t max_layers_ = kMaxSDELayers;
+  uint32_t max_sde_ext_layers_ = 0;
 };
 
 }  // namespace sdm
diff --git a/sdm/libs/utils/debug.cpp b/sdm/libs/utils/debug.cpp
index 4a8e070..e1024dd 100644
--- a/sdm/libs/utils/debug.cpp
+++ b/sdm/libs/utils/debug.cpp
@@ -31,6 +31,7 @@
 #include <utils/debug.h>
 #include <utils/constants.h>
 #include <string>
+#include <algorithm>
 
 namespace sdm {
 
@@ -178,6 +179,13 @@
   return kErrorNone;
 }
 
+int Debug::GetExtMaxlayers() {
+  int max_external_layers = 0;
+  debug_.debug_handler_->GetProperty("sdm.max_external_layers", &max_external_layers);
+
+  return std::max(max_external_layers, 2);
+}
+
 bool Debug::GetProperty(const char* property_name, char* value) {
   if (debug_.debug_handler_->GetProperty(property_name, value) != kErrorNone) {
     return false;