liboverlay: Adjust values to align with MDP requirement

For YUV only:
Crop rectangle (src_rect) needs to be even for x/y and w/h
Destination dst_rect w/h need to be even (x/y can be odd).

Signed-off-by: Saurabh Shah <saurshah@codeaurora.org>

Change-Id: Ib0c1b7d31773e71d60f080b4beacaa68e32a990e
diff --git a/liboverlay/overlayMdp.cpp b/liboverlay/overlayMdp.cpp
index d161f4a..f4e0b51 100644
--- a/liboverlay/overlayMdp.cpp
+++ b/liboverlay/overlayMdp.cpp
@@ -23,6 +23,21 @@
 
 namespace ovutils = overlay::utils;
 namespace overlay {
+
+//Helper to even out x,w and y,h pairs
+//x,y are always evened to ceil and w,h are evened to floor
+static void normalizeCrop(uint32_t& xy, uint32_t& wh) {
+    if(xy & 1) {
+        utils::even_ceil(xy);
+        if(wh & 1)
+            utils::even_floor(wh);
+        else
+            wh -= 2;
+    } else {
+        utils::even_floor(wh);
+    }
+}
+
 bool MdpCtrl::init(uint32_t fbnum) {
     // FD init
     if(!utils::openDev(mFd, fbnum,
@@ -131,6 +146,14 @@
 bool MdpCtrl::set() {
     //deferred calcs, so APIs could be called in any order.
     doTransform();
+    utils::Whf whf = getSrcWhf();
+    if(utils::isYuv(whf.format)) {
+        normalizeCrop(mOVInfo.src_rect.x, mOVInfo.src_rect.w);
+        normalizeCrop(mOVInfo.src_rect.y, mOVInfo.src_rect.h);
+        utils::even_floor(mOVInfo.dst_rect.w);
+        utils::even_floor(mOVInfo.dst_rect.h);
+    }
+
     if(this->ovChanged()) {
         if(!mdp_wrapper::setOverlay(mFd.getFD(), mOVInfo)) {
             ALOGE("MdpCtrl failed to setOverlay, restoring last known "
@@ -142,6 +165,7 @@
         }
         this->save();
     }
+
     return true;
 }