liboverlay: Refactor, bug-fixes, upgrade.

* Fix memory leak during copying pipe objects.
* Remove unused / unnecessary code.
* setMemoryId API is merged with queueBuffer.
* setParameter API is setTransform now.
* Rotator upgraded to:
  --Allow different rotator hardware types.
  --Remove dependency on MDP code.
  --Allocate memory only during first playback,
  close when the associated pipe is closed.
* Have single commit implementation.
* Include new format types.
* Remove WAIT and CHANNEL enums and usage. Replace BypassPipe with
  GenericPipe. Client expected to set alignments and parameters.
  Add transform combination enums.
* Allow APIs to be called in any order. Do transform calcs in commit.
  Move ext type setter and getter functions.
* Add calculations for 180 transform.
* Add secure session support in rotator
* Implement all rotations in terms of H flip, V flip and 90 rotation.

Change-Id: I34a9a2a0f1255b3467a0abbaa254d0b584e901ce
diff --git a/liboverlay/overlayCtrl.cpp b/liboverlay/overlayCtrl.cpp
index 6f84d07..bb91529 100644
--- a/liboverlay/overlayCtrl.cpp
+++ b/liboverlay/overlayCtrl.cpp
@@ -18,14 +18,14 @@
 #include <cutils/properties.h>
 #include "overlayCtrlData.h"
 #include "fb_priv.h"
+#include "gralloc_priv.h" //for interlace
 
 namespace overlay{
 
-bool Ctrl::open(uint32_t fbnum,
-        RotatorBase* rot) {
-    // MDP/FD open
-    if(!mMdp.open(fbnum)) {
-        ALOGE("Ctrl failed to open fbnum=%d", fbnum);
+bool Ctrl::init(uint32_t fbnum) {
+    // MDP/FD init
+    if(!mMdp.init(fbnum)) {
+        ALOGE("Ctrl failed to init fbnum=%d", fbnum);
         return false;
     }
 
@@ -34,127 +34,12 @@
         return false;
     }
 
-    OVASSERT(rot, "rot is null");
-    mRot = rot;
-    // rot should be already opened
-
     return true;
 }
 
-bool Ctrl::start(const utils::PipeArgs& args)
-{
-    int colorFormat = utils::getColorFormat(args.whf.format);
-    utils::eMdpFlags flags = args.mdpFlags;
-
-    //XXX: Support for interlaced content
-    if (0) {
-
-        setMdpFlags(flags, utils::OV_MDP_DEINTERLACE);
-
-        // Get the actual format
-        colorFormat = args.whf.format ^ HAL_PIXEL_FORMAT_INTERLACE;
-    }
-    utils::Whf hwwhf(args.whf);
-    int fmt = utils::getMdpFormat(colorFormat);
-    // FIXME format should probably be int and not uint
-    if (fmt < 0) {
-        ALOGE("Ctrl failed getMdpFormat unsopported "
-                "colorFormat=%d format=%d flags=%d",
-                colorFormat, fmt, flags);
-        return false;
-    }
-    hwwhf.format = fmt;
-
-    // devices should be already opened
-    // (by calling open earlier in the flow)
-
-    const utils::PipeArgs newargs(flags, // mdp flags
-            args.orientation, // trans
-            hwwhf,
-            args.wait,
-            args.zorder,
-            args.isFg,
-            args.rotFlags);
-    if (!setInfo(newargs)) {
-        ALOGE("Ctrl failed to setInfo mdpflags=%d wait=%d zorder=%d",
-                newargs.mdpFlags, newargs.wait, newargs.zorder);
-        hwwhf.dump();
-        return false;
-    }
-
-    // FIXME, can we remove that and have it in
-    // setSource only when source changed?
-    if(!mRot->start(newargs)) {
-        ALOGE("Ctrl failed to start Rotation session");
-        return false;
-    }
-
-    // if geom is different, we need to prepare a new rot buffers.
-    // remap on demand when the current orientation is 90,180, etc.
-    // and the prev orientation was 0. It means we go from orient
-    if(!mRot->remap(utils::ROT_NUM_BUFS, newargs)) {
-        ALOGE("%s Error in remapping", __FUNCTION__);
-    }
-
-    if(!mMdp.set()) {
-        ALOGE("Ctrl start failed set overlay");
-        return false;
-    }
-
-    // cache the src to be the current mCrop vals
-    mCrop.w = hwwhf.w;
-    mCrop.h = hwwhf.h;
-
-    return true;
-}
-
-inline void Ctrl::updateSource(RotatorBase* r,
-        const utils::PipeArgs& args,
-        utils::ScreenInfo& info)
-{
-    mMdp.updateSource(r, args, info);
-}
-
 bool Ctrl::setSource(const utils::PipeArgs& args)
 {
-    mMdp.setWait(args.wait);
-
-    utils::PipeArgs newargs(args);
-    utils::Whf whf(args.whf);
-    // check geom change
-    if(mOvBufInfo != whf) {
-        // whf.format is given as HAL, that is why it is
-        // needed to be MDP fmt.
-        whf.format = utils::getColorFormat(whf.format);
-        int fmt = utils::getMdpFormat(whf.format);
-        OVASSERT(-1 != fmt, "Ctrl setSource format is -1");
-        whf.format = fmt;
-        newargs.whf = whf;
-        updateSource(mRot, newargs, mInfo);
-        mMdp.setUserData(0);
-        if(!mRot->start(newargs)) {
-            ALOGE("%s failed start rot", __FUNCTION__);
-            return false;
-        }
-
-        // if geom is different, we need to prepare a new rot buffers.
-        // remap on demand when the current orientation is 90,180, etc.
-        // and the prev orientation was 0. It means we go from orient
-        if(!mRot->remap(utils::ROT_NUM_BUFS, newargs)) {
-            ALOGE("%s Error in remapping", __FUNCTION__);
-        }
-    }
-
-    // needed for setSource
-    mOrient = args.orientation;
-
-    // cache last whf from gralloc hnd
-    mOvBufInfo = args.whf;
-
-    // orign impl is returning false here
-    // because they will close the overlay and reopen it.
-    // New design would not do that.
-    return true;
+    return mMdp.setSource(args);
 }
 
 bool Ctrl::setPosition(const utils::Dim& dim)
@@ -172,41 +57,21 @@
     return true;
 }
 
-bool Ctrl::setParameter(const utils::Params& p)
+bool Ctrl::setTransform(const utils::eTransform& orient, const bool& rotUsed)
 {
-    if (utils::OVERLAY_TRANSFORM == p.param &&
-            p.value == mMdp.getUserData()) {
-        // nothing to do here
-        return true;
-    }
-
-    utils::eTransform trns = static_cast<utils::eTransform>(p.value);
-    switch (p.param) {
-        case utils::OVERLAY_DITHER:
-            // nothing here today
-            ALOGE("Ctrl setParameter OVERLAY_DITHER not impl");
-            return true;
-        case utils::OVERLAY_TRANSFORM:
-            if(!mRot->overlayTransform(mMdp, trns)) {
-                ALOGE("Ctrl setParameter failed Rot overlayTransform");
-                return false;
-            }
-            break;
-        default:
-            ALOGE("Ctrl setParameter unknown param %d", p.param);
-            return false;
+    if(!mMdp.setTransform(orient, rotUsed)) {
+        ALOGE("Ctrl setTransform failed for Mdp");
+        return false;
     }
     return true;
 }
 
 bool Ctrl::setCrop(const utils::Dim& d)
 {
-    // FIXME check channel validity
     if(!mMdp.setCrop(d)) {
         ALOGE("Data setCrop failed in MDP setCrop");
         return false;
     }
-    mCrop = d;
     return true;
 }
 
@@ -224,11 +89,9 @@
     }
     if (inWhf.w * fbHeight > fbWidth * inWhf.h) {
         inWhf.h = fbWidth * inWhf.h / inWhf.w;
-        utils::even_out(inWhf.h);
         inWhf.w = fbWidth;
     } else if (inWhf.w * fbHeight < fbWidth * inWhf.h) {
         inWhf.w = fbHeight * inWhf.w / inWhf.h;
-        utils::even_out(inWhf.w);
         inWhf.h = fbHeight;
     } else {
         inWhf.w = fbWidth;
@@ -339,10 +202,8 @@
 
 void Ctrl::dump() const {
     ALOGE("== Dump Ctrl start ==");
-    ALOGE("orient=%d", mOrient);
     mInfo.dump("mInfo");
     mMdp.dump();
-    mRot->dump();
     ALOGE("== Dump Ctrl end ==");
 }