liboverlay: Add support for MDSS Bandwidth Compression

- This adds support for Bandwidth Compression.
- If MDSS supports BWC, then we set BWC flags
  to both Rotator(encode) and overlay(decode)

Change-Id: I6f7800716a2ce2ab855f4c0b1a53cd96f7d06d74
diff --git a/libhwcomposer/hwc_utils.cpp b/libhwcomposer/hwc_utils.cpp
index 8fdaf06..d8f8c70 100644
--- a/libhwcomposer/hwc_utils.cpp
+++ b/libhwcomposer/hwc_utils.cpp
@@ -628,6 +628,12 @@
         if(transform & HWC_TRANSFORM_ROT_90) {
             ovutils::setMdpFlags(mdpFlags,
                     ovutils::OV_MDP_SOURCE_ROTATED_90);
+            // enable bandwidth compression only if src width < 2048
+            if(qdutils::MDPVersion::getInstance().supportsBWC() &&
+                hnd->width < qdutils::MAX_DISPLAY_DIM) {
+                ovutils::setMdpFlags(mdpFlags,
+                                 ovutils::OV_MDSS_MDP_BWC_EN);
+            }
         }
     }
 
diff --git a/liboverlay/overlayMdssRot.cpp b/liboverlay/overlayMdssRot.cpp
index 1fabdca..6f2b564 100644
--- a/liboverlay/overlayMdssRot.cpp
+++ b/liboverlay/overlayMdssRot.cpp
@@ -20,6 +20,8 @@
 #include "overlayUtils.h"
 #include "overlayRotator.h"
 
+#define DEBUG_MDSS_ROT 0
+
 #ifdef VENUS_COLOR_FORMAT
 #include <media/msm_media_info.h>
 #else
@@ -252,7 +254,11 @@
     ovutils::Whf destWhf(mRotInfo.dst_rect.w, mRotInfo.dst_rect.h,
             mRotInfo.src.format); //mdss src and dst formats are same.
 
-    opBufSize = Rotator::calcOutputBufSize(destWhf);
+    if (mRotInfo.flags & ovutils::OV_MDSS_MDP_BWC_EN) {
+        opBufSize = calcCompressedBufSize();
+    } else {
+        opBufSize = Rotator::calcOutputBufSize(destWhf);
+    }
 
     if (mRotInfo.flags & utils::OV_MDP_SECURE_OVERLAY_SESSION)
         opBufSize = utils::align(opBufSize, SIZE_1M);
@@ -265,4 +271,23 @@
     ovutils::getDump(buf, len, "MdssRotData", mRotData);
 }
 
+// Calculate the compressed o/p buffer size for BWC
+uint32_t MdssRot::calcCompressedBufSize() {
+    uint32_t bufSize = 0;
+    int aWidth = ovutils::align(mRotInfo.src_rect.w, 64);
+    int aHeight = ovutils::align(mRotInfo.src_rect.h, 4);
+    int rau_cnt = aWidth/64;
+    int stride0 = (64 * 4 * rau_cnt) + rau_cnt/8;
+    int stride1 = (64 * 2 * rau_cnt) + rau_cnt/8;
+    int stride0_off = (aHeight/4);
+    int stride1_off = (aHeight/2);
+
+    //New o/p size for BWC
+    bufSize = (stride0 * stride0_off + stride1 * stride1_off) +
+                (rau_cnt * 2 * (stride0_off + stride1_off));
+    ALOGD_IF(DEBUG_MDSS_ROT, "%s: width = %d, height = %d raucount = %d"
+         "opBufSize = %d ", __FUNCTION__, aWidth, aHeight, rau_cnt, bufSize);
+    return bufSize;
+}
+
 } // namespace overlay
diff --git a/liboverlay/overlayRotator.h b/liboverlay/overlayRotator.h
index c02dfba..120721c 100644
--- a/liboverlay/overlayRotator.h
+++ b/liboverlay/overlayRotator.h
@@ -198,6 +198,8 @@
     /* Calculates the rotator's o/p buffer size post the transform calcs and
      * knowing the o/p format depending on whether fastYuv is enabled or not */
     uint32_t calcOutputBufSize();
+    // Calculate the compressed o/p buffer size for BWC
+    uint32_t calcCompressedBufSize();
 
     /* MdssRot info structure */
     mdp_overlay   mRotInfo;
diff --git a/liboverlay/overlayUtils.h b/liboverlay/overlayUtils.h
index ceb238d..0893328 100644
--- a/liboverlay/overlayUtils.h
+++ b/liboverlay/overlayUtils.h
@@ -262,6 +262,7 @@
     OV_MDP_FLIP_V = MDP_FLIP_UD,
     OV_MDSS_MDP_RIGHT_MIXER = MDSS_MDP_RIGHT_MIXER,
     OV_MDP_PP_EN = MDP_OVERLAY_PP_CFG_EN,
+    OV_MDSS_MDP_BWC_EN = MDP_BWC_EN,
 };
 
 enum eZorder {
diff --git a/libqdutils/mdp_version.cpp b/libqdutils/mdp_version.cpp
index 8da293d..e3e78ca 100644
--- a/libqdutils/mdp_version.cpp
+++ b/libqdutils/mdp_version.cpp
@@ -117,5 +117,9 @@
     return mMDPDownscale;
 }
 
+bool MDPVersion::supportsBWC() {
+    // BWC - Bandwidth Compression
+    return (mFeatures & MDP_BWC_EN);
+}
 }; //namespace qdutils
 
diff --git a/libqdutils/mdp_version.h b/libqdutils/mdp_version.h
index 2fca640..0586001 100644
--- a/libqdutils/mdp_version.h
+++ b/libqdutils/mdp_version.h
@@ -82,6 +82,7 @@
     uint8_t getDMAPipes() { return mDMAPipes; }
     bool supportsDecimation();
     uint32_t getMaxMDPDownscale();
+    bool supportsBWC();
 private:
     int mMDPVersion;
     char mPanelType;