hwc/ov: Fix MDP orientation flags and values.

--Fix MDP_SOURCE_ROTATED_90 removal.
Since mdp flags are updated fresh each round,
this flag should not be removed if there is no 90.
If pre-rotation is used, this flag is set by hwc and removed here.
(Affects anything having a 90 component in transform)

--Provide MDP adjusted transform to prerotation calcs.
Clients on Android don't switch flips if 90 component is present,
but expect the output to be that way. (camera)
We do it in HAL and then calculate final crop for MDP.
(Affects anything using 90 + Just 1 flip i.e camera)

--Pass 0 transform to MDP even for flips, since we
prerotate if there is 90 with flips or use MDP to flip via flags,
so no need to flip transform calcs.
(Affects anything using just flips).

Change-Id: I115a82ee4558794db0b6b641710494b9007d6f54
diff --git a/libhwcomposer/hwc_utils.cpp b/libhwcomposer/hwc_utils.cpp
index 11f7dc5..12fbe26 100644
--- a/libhwcomposer/hwc_utils.cpp
+++ b/libhwcomposer/hwc_utils.cpp
@@ -603,6 +603,9 @@
     Dim srcCrop(crop.left, crop.top,
             crop.right - crop.left,
             crop.bottom - crop.top);
+    //getMdpOrient will switch the flips if the source is 90 rotated.
+    //Clients in Android dont factor in 90 rotation while deciding the flip.
+    orient = static_cast<eTransform>(ovutils::getMdpOrient(orient));
     preRotateSource(orient, whf, srcCrop);
     crop.left = srcCrop.x;
     crop.top = srcCrop.y;
@@ -653,11 +656,13 @@
             return -1;
         whf.format = (*rot)->getDstFormat();
         updateSource(orient, whf, crop);
-        //For the mdp, since we are pre-rotating
-        transform = 0;
         rotFlags |= ovutils::ROT_PREROTATED;
     }
 
+    //For the mdp, since either we are pre-rotating or MDP does flips
+    orient = OVERLAY_TRANSFORM_0;
+    transform = 0;
+
     PipeArgs parg(mdpFlags, whf, z, isFg, static_cast<eRotFlags>(rotFlags));
     if(configMdp(ctx->mOverlay, parg, orient, crop, dst, dest) < 0) {
         ALOGE("%s: commit failed for low res panel", __FUNCTION__);
@@ -699,8 +704,6 @@
             return -1;
         whf.format = (*rot)->getDstFormat();
         updateSource(orient, whf, crop);
-        //For the mdp, since we are pre-rotating
-        transform = 0;
         rotFlags |= ROT_PREROTATED;
     }
 
@@ -726,7 +729,7 @@
     //When buffer is flipped, contents of mixer config also needs to swapped.
     //Not needed if the layer is confined to one half of the screen.
     //If rotator has been used then it has also done the flips, so ignore them.
-    if(layer->transform & HWC_TRANSFORM_FLIP_V && lDest != OV_INVALID
+    if((orient & OVERLAY_TRANSFORM_FLIP_V) && lDest != OV_INVALID
             && rDest != OV_INVALID && rot == NULL) {
         hwc_rect_t new_cropR;
         new_cropR.left = tmp_cropL.left;
@@ -744,6 +747,10 @@
 
     }
 
+    //For the mdp, since either we are pre-rotating or MDP does flips
+    orient = OVERLAY_TRANSFORM_0;
+    transform = 0;
+
     //configure left mixer
     if(lDest != OV_INVALID) {
         PipeArgs pargL(mdpFlagsL, whf, z, isFg,
diff --git a/liboverlay/overlayMdp.h b/liboverlay/overlayMdp.h
index 7d3bbee..08d744f 100644
--- a/liboverlay/overlayMdp.h
+++ b/liboverlay/overlayMdp.h
@@ -296,10 +296,8 @@
 
 inline void MdpCtrl::setRotationFlags() {
     const int u = getUserData();
-    if (u == MDP_ROT_90 || u == MDP_ROT_270)
+    if (u & MDP_ROT_90)
         mOVInfo.flags |= MDP_SOURCE_ROTATED_90;
-    else
-        mOVInfo.flags &= ~MDP_SOURCE_ROTATED_90;
 }
 
 ///////    MdpCtrl3D //////
diff --git a/liboverlay/overlayUtils.cpp b/liboverlay/overlayUtils.cpp
index 4cc7a37..ebc88d1 100644
--- a/liboverlay/overlayUtils.cpp
+++ b/liboverlay/overlayUtils.cpp
@@ -213,7 +213,10 @@
     return x - ( y + z );
 }
 
-void preRotateSource(eTransform& tr, Whf& whf, Dim& srcCrop) {
+//Expects transform to be adjusted for clients of Android.
+//i.e flips switched if 90 component present.
+//See getMdpOrient()
+void preRotateSource(const eTransform& tr, Whf& whf, Dim& srcCrop) {
     if(tr & OVERLAY_TRANSFORM_FLIP_H) {
         srcCrop.x = compute(whf.w, srcCrop.x, srcCrop.w);
     }
@@ -229,7 +232,6 @@
         swap(whf.w, whf.h);
         swap(srcCrop.w, srcCrop.h);
     }
-    tr = OVERLAY_TRANSFORM_0;
 }
 
 bool is3DTV() {
diff --git a/liboverlay/overlayUtils.h b/liboverlay/overlayUtils.h
index 5eb0e1e..3eabc1d 100644
--- a/liboverlay/overlayUtils.h
+++ b/liboverlay/overlayUtils.h
@@ -688,7 +688,7 @@
         value--;
 }
 
-void preRotateSource(eTransform& tr, Whf& whf, Dim& srcCrop);
+void preRotateSource(const eTransform& tr, Whf& whf, Dim& srcCrop);
 void getDump(char *buf, size_t len, const char *prefix, const mdp_overlay& ov);
 void getDump(char *buf, size_t len, const char *prefix, const msmfb_img& ov);
 void getDump(char *buf, size_t len, const char *prefix, const mdp_rect& ov);