Limit #ROT-SESSIONS to 4 in LayerRotMap and RotMgr

* Limit the number of rotator sessions to 4 both in
LayerRotMap and RotMgr structures

* Make use of MDPVersion getter fuctions to check
for maxMixerWidth and maxDownScale supported by MDP

Change-Id: I27dac877807fbb4ed6fcb3500a3a318a2ef5d8b2
diff --git a/libhwcomposer/hwc_mdpcomp.cpp b/libhwcomposer/hwc_mdpcomp.cpp
index 162ee4f..77bc0b5 100644
--- a/libhwcomposer/hwc_mdpcomp.cpp
+++ b/libhwcomposer/hwc_mdpcomp.cpp
@@ -45,7 +45,7 @@
 bool MDPComp::sEnableMixedMode = true;
 int MDPComp::sSimulationFlags = 0;
 int MDPComp::sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
-bool MDPComp::sEnable4k2kYUVSplit = false;
+bool MDPComp::sEnableYUVsplit = false;
 bool MDPComp::sSrcSplitEnabled = false;
 MDPComp* MDPComp::getObject(hwc_context_t *ctx, const int& dpy) {
     if(qdutils::MDPVersion::getInstance().isSrcSplit()) {
@@ -159,7 +159,7 @@
             property_get("persist.mdpcomp.4k2kSplit", property, "0") > 0 &&
             (!strncmp(property, "1", PROPERTY_VALUE_MAX) ||
             !strncasecmp(property,"true", PROPERTY_VALUE_MAX))) {
-        sEnable4k2kYUVSplit = true;
+        sEnableYUVsplit = true;
     }
 
     if ((property_get("persist.hwc.ptor.enable", property, NULL) > 0) &&
@@ -773,7 +773,7 @@
     mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount -
         mCurrentFrame.dropCount;
 
-    if(sEnable4k2kYUVSplit){
+    if(sEnableYUVsplit){
         adjustForSourceSplit(ctx, list);
     }
 
@@ -1055,7 +1055,7 @@
 
     int mdpCount = mCurrentFrame.mdpCount;
 
-    if(sEnable4k2kYUVSplit){
+    if(sEnableYUVsplit){
         adjustForSourceSplit(ctx, list);
     }
 
@@ -1221,7 +1221,7 @@
     if(mCurrentFrame.fbCount)
         mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
 
-    if(sEnable4k2kYUVSplit){
+    if(sEnableYUVsplit){
         adjustForSourceSplit(ctx, list);
     }
 
@@ -1549,7 +1549,7 @@
             cur_pipe->zOrder = mdpNextZOrder++;
 
             private_handle_t *hnd = (private_handle_t *)layer->handle;
-            if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
+            if(isYUVSplitNeeded(hnd) && sEnableYUVsplit){
                 if(configure4k2kYuv(ctx, layer,
                             mCurrentFrame.mdpToLayer[mdpIndex])
                         != 0 ){
@@ -1799,7 +1799,7 @@
                 mdpNextZOrder++;
                 hwc_layer_1_t* layer = &list->hwLayers[index];
                 private_handle_t *hnd = (private_handle_t *)layer->handle;
-                if(is4kx2kYuvBuffer(hnd)) {
+                if(isYUVSplitNeeded(hnd)) {
                     if(mdpNextZOrder <= mCurrentFrame.fbZ)
                         mCurrentFrame.fbZ += 1;
                     mdpNextZOrder++;
@@ -1839,7 +1839,7 @@
 
         hwc_layer_1_t* layer = &list->hwLayers[index];
         private_handle_t *hnd = (private_handle_t *)layer->handle;
-        if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
+        if(isYUVSplitNeeded(hnd) && sEnableYUVsplit){
             if(allocSplitVGPipesfor4k2k(ctx, index)){
                 continue;
             }
@@ -1919,7 +1919,7 @@
 
         int mdpIndex = mCurrentFrame.layerToMDP[i];
 
-        if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
+        if(isYUVSplitNeeded(hnd) && sEnableYUVsplit)
         {
             MdpYUVPipeInfo& pipe_info =
                 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
@@ -2018,7 +2018,7 @@
                 mdpNextZOrder++;
                 hwc_layer_1_t* layer = &list->hwLayers[index];
                 private_handle_t *hnd = (private_handle_t *)layer->handle;
-                if(is4kx2kYuvBuffer(hnd)) {
+                if(isYUVSplitNeeded(hnd)) {
                     hwc_rect_t dst = layer->displayFrame;
                     if((dst.left > lSplit) || (dst.right < lSplit)) {
                         mCurrentFrame.mdpCount += 1;
@@ -2079,7 +2079,7 @@
         private_handle_t *hnd = (private_handle_t *)layer->handle;
         hwc_rect_t dst = layer->displayFrame;
         const int lSplit = getLeftSplit(ctx, mDpy);
-        if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
+        if(isYUVSplitNeeded(hnd) && sEnableYUVsplit){
             if((dst.left > lSplit)||(dst.right < lSplit)){
                 if(allocSplitVGPipesfor4k2k(ctx, index)){
                     continue;
@@ -2175,7 +2175,7 @@
 
         int mdpIndex = mCurrentFrame.layerToMDP[i];
 
-        if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
+        if(isYUVSplitNeeded(hnd) && sEnableYUVsplit)
         {
             MdpYUVPipeInfo& pipe_info =
                 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
diff --git a/libhwcomposer/hwc_mdpcomp.h b/libhwcomposer/hwc_mdpcomp.h
index 1ebe0bd..5214ac6 100644
--- a/libhwcomposer/hwc_mdpcomp.h
+++ b/libhwcomposer/hwc_mdpcomp.h
@@ -248,7 +248,7 @@
     struct FrameInfo mCurrentFrame;
     struct LayerCache mCachedFrame;
     //Enable 4kx2k yuv layer split
-    static bool sEnable4k2kYUVSplit;
+    static bool sEnableYUVsplit;
     bool mModeOn; // if prepare happened
     bool allocSplitVGPipesfor4k2k(hwc_context_t *ctx, int index);
 };
diff --git a/libhwcomposer/hwc_utils.cpp b/libhwcomposer/hwc_utils.cpp
index 3696c05..8bed0fb 100644
--- a/libhwcomposer/hwc_utils.cpp
+++ b/libhwcomposer/hwc_utils.cpp
@@ -879,7 +879,7 @@
             ctx->listStats[dpy].yuvIndices[yuvCount] = (int)i;
             yuvCount++;
 
-            if(UNLIKELY(is4kx2kYuvBuffer(hnd))){
+            if(UNLIKELY(isYUVSplitNeeded(hnd))){
                 int& yuv4k2kCount = ctx->listStats[dpy].yuv4k2kCount;
                 ctx->listStats[dpy].yuv4k2kIndices[yuv4k2kCount] = (int)i;
                 yuv4k2kCount++;
@@ -2211,14 +2211,14 @@
 }
 
 void LayerRotMap::add(hwc_layer_1_t* layer, Rotator *rot) {
-    if(mCount >= MAX_SESS) return;
+    if(mCount >= RotMgr::MAX_ROT_SESS) return;
     mLayer[mCount] = layer;
     mRot[mCount] = rot;
     mCount++;
 }
 
 void LayerRotMap::reset() {
-    for (int i = 0; i < MAX_SESS; i++) {
+    for (int i = 0; i < RotMgr::MAX_ROT_SESS; i++) {
         mLayer[i] = 0;
         mRot[i] = 0;
     }
diff --git a/libhwcomposer/hwc_utils.h b/libhwcomposer/hwc_utils.h
index 66fdc65..008de4c 100644
--- a/libhwcomposer/hwc_utils.h
+++ b/libhwcomposer/hwc_utils.h
@@ -29,7 +29,9 @@
 #include <gralloc_priv.h>
 #include <utils/String8.h>
 #include "qdMetaData.h"
+#include "mdp_version.h"
 #include <overlayUtils.h>
+#include <overlayRotator.h>
 #include <EGL/egl.h>
 
 
@@ -190,7 +192,6 @@
 class LayerRotMap {
 public:
     LayerRotMap() { reset(); }
-    enum { MAX_SESS = 3 };
     void add(hwc_layer_1_t* layer, overlay::Rotator *rot);
     //Resets the mapping of layer to rotator
     void reset();
@@ -202,8 +203,8 @@
     overlay::Rotator* getRot(uint32_t index) const;
     void setReleaseFd(const int& fence);
 private:
-    hwc_layer_1_t* mLayer[MAX_SESS];
-    overlay::Rotator* mRot[MAX_SESS];
+    hwc_layer_1_t* mLayer[overlay::RotMgr::MAX_ROT_SESS];
+    overlay::Rotator* mRot[overlay::RotMgr::MAX_ROT_SESS];
     uint32_t mCount;
 };
 
@@ -406,10 +407,11 @@
     return (hnd && (hnd->bufferType == BUFFER_TYPE_VIDEO));
 }
 
-// Returns true if the buffer is yuv
-static inline bool is4kx2kYuvBuffer(const private_handle_t* hnd) {
+// Returns true if the buffer is yuv and exceeds the mixer width
+static inline bool isYUVSplitNeeded(const private_handle_t* hnd) {
+    int maxMixerWidth = qdutils::MDPVersion::getInstance().getMaxMixerWidth();
     return (hnd && (hnd->bufferType == BUFFER_TYPE_VIDEO) &&
-            (hnd->width > 2048));
+            (hnd->width > maxMixerWidth));
 }
 
 // Returns true if the buffer is secure