overlay: Add support for decimation.

Add support for decimation on top of what MDP can downscale,
because decimation can have quality issues.
B-family MDP downscale of 1/4, plus decimation of 1/16 can let
us have a total downscale of 1/64.

Also decimate by 2 (min) if width is greater than what layer mixer
supports and is not handled by the client.

Change-Id: I3b7c4bf321c7561bd98206ad118f4ac1ee2879ae
diff --git a/libhwcomposer/hwc_fbupdate.cpp b/libhwcomposer/hwc_fbupdate.cpp
index b8e6976..9f91a99 100644
--- a/libhwcomposer/hwc_fbupdate.cpp
+++ b/libhwcomposer/hwc_fbupdate.cpp
@@ -21,6 +21,9 @@
 #define DEBUG_FBUPDATE 0
 #include <gralloc_priv.h>
 #include "hwc_fbupdate.h"
+#include "mdp_version.h"
+
+using namespace qdutils;
 
 namespace qhwc {
 
diff --git a/libhwcomposer/hwc_mdpcomp.cpp b/libhwcomposer/hwc_mdpcomp.cpp
index b81eb5e..6381f59 100644
--- a/libhwcomposer/hwc_mdpcomp.cpp
+++ b/libhwcomposer/hwc_mdpcomp.cpp
@@ -24,6 +24,7 @@
 #include <overlayRotator.h>
 
 using namespace overlay;
+using namespace qdutils;
 using namespace overlay::utils;
 namespace ovutils = overlay::utils;
 
@@ -405,12 +406,11 @@
         return false;
     }
 
-    /* Workaround for downscales larger than 4x. Will be removed once decimator
-     * block is enabled for MDSS*/
-    if(ctx->mMDP.version == qdutils::MDSS_V5) {
+    if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
+        const uint32_t downscale =
+                qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
         hwc_rect_t crop = layer->sourceCrop;
         hwc_rect_t dst = layer->displayFrame;
-
         int cWidth = crop.right - crop.left;
         int cHeight = crop.bottom - crop.top;
         int dWidth = dst.right - dst.left;
@@ -420,7 +420,8 @@
             swap(cWidth, cHeight);
         }
 
-        if((cWidth/dWidth) > 4 || (cHeight/dHeight) > 4)
+        if(cWidth > MAX_DISPLAY_DIM || (cWidth/dWidth) > downscale ||
+                    (cHeight/dHeight) > downscale)
             return false;
     }
     return true;
diff --git a/libhwcomposer/hwc_utils.h b/libhwcomposer/hwc_utils.h
index 001e3e8..d4f5d94 100644
--- a/libhwcomposer/hwc_utils.h
+++ b/libhwcomposer/hwc_utils.h
@@ -34,7 +34,6 @@
 #define LIKELY( exp )       (__builtin_expect( (exp) != 0, true  ))
 #define UNLIKELY( exp )     (__builtin_expect( (exp) != 0, false ))
 #define MAX_NUM_LAYERS 32 //includes fb layer
-#define MAX_DISPLAY_DIM 2048
 
 // For support of virtual displays
 #define HWC_DISPLAY_VIRTUAL     (HWC_DISPLAY_EXTERNAL+1)