overlay: Add support for rotator downscale

Add support for rotator downscale. This is enabled from 8994 onwards
Constraints:
--Downscale should be a power of 2, max upto 32
--Both directions should have equal downscale
--{src_w, src_h} mod downscale = 0
--No BWC
--No Interlaced video support

The rotator's destination rect is modified to reflect the presence of
downscale. Any downscale calcs should be done only after adjusting
crop to meet rotator's requirements.

Smaller downscale is used if we need to chop off any more than 1
line or pixel.

Change-Id: Id07d62fefa3213035f16cca49497800716484a95
diff --git a/liboverlay/overlayRotator.h b/liboverlay/overlayRotator.h
index 64387cd..7d1b0b1 100644
--- a/liboverlay/overlayRotator.h
+++ b/liboverlay/overlayRotator.h
@@ -88,6 +88,13 @@
     virtual void getDump(char *buf, size_t len) const = 0;
     void setReleaseFd(const int& fence) { mMem.setReleaseFd(fence); }
     static Rotator *getRotator();
+    /* Returns downscale by successfully applying constraints
+     * Returns 0 if target doesnt support rotator downscaling
+     * or if any of the constraints are not met
+     */
+    static int getDownscaleFactor(const int& srcW, const int& srcH,
+            const int& dstW, const int& dstH, const uint32_t& mdpFormat,
+            const bool& isInterlaced);
 
 protected:
     /* Rotator memory manager */
@@ -146,6 +153,16 @@
      * knowing the o/p format depending on whether fastYuv is enabled or not */
     uint32_t calcOutputBufSize();
 
+    /* Applies downscale by taking areas
+     * Returns a log(downscale)
+     * Constraints applied:
+     * - downscale should be a power of 2
+     * - Max downscale is 1/8
+     */
+    static int getDownscaleFactor(const int& srcW, const int& srcH,
+            const int& dstW, const int& dstH, const uint32_t& mdpFormat,
+            const bool& isInterlaced);
+
     /* rot info*/
     msm_rotator_img_info mRotImgInfo;
     /* Last saved rot info*/
@@ -158,6 +175,9 @@
     OvFD mFd;
 
     friend Rotator* Rotator::getRotator();
+    friend int Rotator::getDownscaleFactor(const int& srcW, const int& srcH,
+            const int& dstW, const int& dstH, const uint32_t& mdpFormat,
+            const bool& isInterlaced);
 };
 
 /*
@@ -202,6 +222,25 @@
     // Calculate the compressed o/p buffer size for BWC
     uint32_t calcCompressedBufSize(const utils::Whf& destWhf);
 
+     /* Caller's responsibility to swap srcW, srcH if there is a 90 transform
+      * Returns actual downscale (not a log value)
+      * Constraints applied:
+      * - downscale should be a power of 2
+      * - Max downscale is 1/32
+      * - Equal downscale is applied in both directions
+      * - {srcW, srcH} mod downscale = 0
+      * - Interlaced content is not supported
+      */
+    static int getDownscaleFactor(const int& srcW, const int& srcH,
+            const int& dstW, const int& dstH, const uint32_t& mdpFormat,
+            const bool& isInterlaced);
+
+    static utils::Dim getFormatAdjustedCrop(const utils::Dim& crop,
+            const uint32_t& mdpFormat, const bool& isInterlaced);
+
+    static utils::Dim getDownscaleAdjustedCrop(const utils::Dim& crop,
+            const uint32_t& downscale);
+
     /* MdssRot info structure */
     mdp_overlay   mRotInfo;
     /* MdssRot data structure */
@@ -212,8 +251,12 @@
     OvFD mFd;
     /* Enable/Disable Mdss Rot*/
     bool mEnabled;
+    int mDownscale;
 
     friend Rotator* Rotator::getRotator();
+    friend int Rotator::getDownscaleFactor(const int& srcW, const int& srcH,
+            const int& dstW, const int& dstH, const uint32_t& mdpFormat,
+            const bool& isInterlaced);
 };
 
 // Holder of rotator objects. Manages lifetimes