hwc: Add support for configuring maximum mdp layers on secondary

Add support for configuring the maximum mdp layers on secondary
via persist.hwc.maxseclayers property. The default value is 1.

Move the check for max allowed layers to postHeuristicsHandling
rather than it being a part of strategies itself.

Change-Id: Icae6cb7e400fd95f60e0b3eb64e6b768e4dbd861
diff --git a/libhwcomposer/hwc_mdpcomp.cpp b/libhwcomposer/hwc_mdpcomp.cpp
index 466151b..2a72968 100644
--- a/libhwcomposer/hwc_mdpcomp.cpp
+++ b/libhwcomposer/hwc_mdpcomp.cpp
@@ -46,6 +46,7 @@
 int MDPComp::sMaxPipesPerMixer = 0;
 bool MDPComp::sEnableYUVsplit = false;
 bool MDPComp::sSrcSplitEnabled = false;
+int MDPComp::sMaxSecLayers = 1;
 bool MDPComp::enablePartialUpdateForMDP3 = false;
 MDPComp* MDPComp::getObject(hwc_context_t *ctx, const int& dpy) {
     if(qdutils::MDPVersion::getInstance().isSrcSplit()) {
@@ -139,6 +140,16 @@
             sMaxPipesPerMixer = min(val, sMaxPipesPerMixer);
     }
 
+    /* Maximum layers allowed to use MDP on secondary panels. If property
+     * doesn't exist, default to 1. Using the property it can be set to 0 or
+     * more.
+     */
+    if(property_get("persist.hwc.maxseclayers", property, "1") > 0) {
+        int val = atoi(property);
+        sMaxSecLayers = (val >= 0) ? val : 1;
+        sMaxSecLayers = min(sMaxSecLayers, sMaxPipesPerMixer);
+    }
+
     if(ctx->mMDP.panel != MIPI_CMD_PANEL) {
         sIdleInvalidator = IdleInvalidator::getInstance();
         if(sIdleInvalidator->init(timeout_handler, ctx) < 0) {
@@ -832,13 +843,6 @@
     if(sSimulationFlags & MDPCOMP_AVOID_FULL_MDP)
         return false;
 
-    //Will benefit presentation / secondary-only layer.
-    if((mDpy > HWC_DISPLAY_PRIMARY) &&
-            (list->numHwLayers - 1) > MAX_SEC_LAYERS) {
-        ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
-        return false;
-    }
-
     const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
     for(int i = 0; i < numAppLayers; i++) {
         hwc_layer_1_t* layer = &list->hwLayers[i];
@@ -1160,14 +1164,6 @@
         adjustForSourceSplit(ctx, list);
     }
 
-    //Will benefit cases where a video has non-updating background.
-    if((mDpy > HWC_DISPLAY_PRIMARY) and
-            (mdpCount > MAX_SEC_LAYERS)) {
-        ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
-        reset(ctx);
-        return false;
-    }
-
     if(!postHeuristicsHandling(ctx, list)) {
         ALOGD_IF(isDebug(), "post heuristic handling failed");
         reset(ctx);
@@ -1819,6 +1815,14 @@
         ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
         return false;
     }
+
+    //Will benefit cases where a video has non-updating background.
+    if((mDpy > HWC_DISPLAY_PRIMARY) and
+            (mCurrentFrame.mdpCount > sMaxSecLayers)) {
+        ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
+        return false;
+    }
+
     // Init rotCount to number of rotate sessions used by other displays
     int rotCount = ctx->mRotMgr->getNumActiveSessions();
     // Count the number of rotator sessions required for current display
diff --git a/libhwcomposer/hwc_mdpcomp.h b/libhwcomposer/hwc_mdpcomp.h
index 7fa6674..8929c40 100644
--- a/libhwcomposer/hwc_mdpcomp.h
+++ b/libhwcomposer/hwc_mdpcomp.h
@@ -58,8 +58,6 @@
     static void setMaxPipesPerMixer(const uint32_t value);
 
 protected:
-    enum { MAX_SEC_LAYERS = 1 }; //TODO add property support
-
     enum ePipeType {
         MDPCOMP_OV_RGB = ovutils::OV_MDP_PIPE_RGB,
         MDPCOMP_OV_VG = ovutils::OV_MDP_PIPE_VG,
@@ -258,6 +256,7 @@
     static int sMaxPipesPerMixer;
     static bool sSrcSplitEnabled;
     static IdleInvalidator *sIdleInvalidator;
+    static int sMaxSecLayers;
     struct FrameInfo mCurrentFrame;
     struct LayerCache mCachedFrame;
     //Enable 4kx2k yuv layer split