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/pipes/overlay3DPipe.h b/liboverlay/pipes/overlay3DPipe.h
index dce4bf4..86ebed7 100644
--- a/liboverlay/pipes/overlay3DPipe.h
+++ b/liboverlay/pipes/overlay3DPipe.h
@@ -50,20 +50,15 @@
     /* Please look at overlayGenPipe.h for info */
     explicit M3DExtPipe();
     ~M3DExtPipe();
-    bool open(RotatorBase* rot);
+    bool init(RotatorBase* rot);
     bool close();
     bool commit();
-    void setId(int id);
-    void setMemoryId(int id);
-    bool queueBuffer(uint32_t offset);
-    bool dequeueBuffer(void*& buf);
+    bool queueBuffer(int fd, uint32_t offset);
     bool waitForVsync();
     bool setCrop(const utils::Dim& d);
-    bool start(const utils::PipeArgs& args);
     bool setPosition(const utils::Dim& dim);
-    bool setParameter(const utils::Params& param);
+    bool setTransform(const utils::eTransform& param);
     bool setSource(const utils::PipeArgs& args);
-    const utils::PipeArgs& getArgs() const;
     utils::eOverlayPipeType getOvPipeType() const;
     void dump() const;
 private:
@@ -87,20 +82,15 @@
     /* Please look at overlayGenPipe.h for info */
     explicit M3DPrimaryPipe();
     ~M3DPrimaryPipe();
-    bool open(RotatorBase* rot);
+    bool init(RotatorBase* rot);
     bool close();
     bool commit();
-    void setId(int id);
-    void setMemoryId(int id);
-    bool queueBuffer(uint32_t offset);
-    bool dequeueBuffer(void*& buf);
+    bool queueBuffer(int fd, uint32_t offset);
     bool waitForVsync();
     bool setCrop(const utils::Dim& d);
-    bool start(const utils::PipeArgs& args);
     bool setPosition(const utils::Dim& dim);
-    bool setParameter(const utils::Params& param);
+    bool setTransform(const utils::eTransform& param);
     bool setSource(const utils::PipeArgs& args);
-    const utils::PipeArgs& getArgs() const;
     utils::eOverlayPipeType getOvPipeType() const;
     void dump() const;
 private:
@@ -124,20 +114,15 @@
     /* Please look at overlayGenPipe.h for info */
     explicit S3DExtPipe();
     ~S3DExtPipe();
-    bool open(RotatorBase* rot);
+    bool init(RotatorBase* rot);
     bool close();
     bool commit();
-    void setId(int id);
-    void setMemoryId(int id);
-    bool queueBuffer(uint32_t offset);
-    bool dequeueBuffer(void*& buf);
+    bool queueBuffer(int fd, uint32_t offset);
     bool waitForVsync();
     bool setCrop(const utils::Dim& d);
-    bool start(const utils::PipeArgs& args);
     bool setPosition(const utils::Dim& dim);
-    bool setParameter(const utils::Params& param);
+    bool setTransform(const utils::eTransform& param);
     bool setSource(const utils::PipeArgs& args);
-    const utils::PipeArgs& getArgs() const;
     utils::eOverlayPipeType getOvPipeType() const;
     void dump() const;
 private:
@@ -161,20 +146,15 @@
     /* Please look at overlayGenPipe.h for info */
     explicit S3DPrimaryPipe();
     ~S3DPrimaryPipe();
-    bool open(RotatorBase* rot);
+    bool init(RotatorBase* rot);
     bool close();
     bool commit();
-    void setId(int id);
-    void setMemoryId(int id);
-    bool queueBuffer(uint32_t offset);
-    bool dequeueBuffer(void*& buf);
+    bool queueBuffer(int fd, uint32_t offset);
     bool waitForVsync();
     bool setCrop(const utils::Dim& d);
-    bool start(const utils::PipeArgs& args);
     bool setPosition(const utils::Dim& dim);
-    bool setParameter(const utils::Params& param);
+    bool setTransform(const utils::eTransform& param);
     bool setSource(const utils::PipeArgs& args);
-    const utils::PipeArgs& getArgs() const;
     utils::eOverlayPipeType getOvPipeType() const;
     void dump() const;
 private:
@@ -197,10 +177,10 @@
 template <int CHAN>
 inline M3DExtPipe<CHAN>::~M3DExtPipe() { close(); }
 template <int CHAN>
-inline bool M3DExtPipe<CHAN>::open(RotatorBase* rot) {
-    ALOGE_IF(DEBUG_OVERLAY, "M3DExtPipe open");
-    if(!mM3d.open(rot)) {
-        ALOGE("3Dpipe failed to open");
+inline bool M3DExtPipe<CHAN>::init(RotatorBase* rot) {
+    ALOGE_IF(DEBUG_OVERLAY, "M3DExtPipe init");
+    if(!mM3d.init(rot)) {
+        ALOGE("3Dpipe failed to init");
         return false;
     }
     return true;
@@ -212,15 +192,9 @@
 template <int CHAN>
 inline bool M3DExtPipe<CHAN>::commit() { return mM3d.commit(); }
 template <int CHAN>
-inline void M3DExtPipe<CHAN>::setId(int id) { mM3d.setId(id); }
-template <int CHAN>
-inline void M3DExtPipe<CHAN>::setMemoryId(int id) { mM3d.setMemoryId(id); }
-template <int CHAN>
-inline bool M3DExtPipe<CHAN>::queueBuffer(uint32_t offset) {
-    return mM3d.queueBuffer(offset); }
-template <int CHAN>
-inline bool M3DExtPipe<CHAN>::dequeueBuffer(void*& buf) {
-    return mM3d.dequeueBuffer(buf); }
+inline bool M3DExtPipe<CHAN>::queueBuffer(int fd, uint32_t offset) {
+    return mM3d.queueBuffer(fd, offset);
+}
 template <int CHAN>
 inline bool M3DExtPipe<CHAN>::waitForVsync() {
     return mM3d.waitForVsync(); }
@@ -233,14 +207,7 @@
     }
     return mM3d.setCrop(_dim);
 }
-template <int CHAN>
-inline bool M3DExtPipe<CHAN>::start(const utils::PipeArgs& args) {
-    if(!mM3d.start(args)) {
-        ALOGE("M3DExtPipe start failed");
-        return false;
-    }
-    return true;
-}
+
 template <int CHAN>
 inline bool M3DExtPipe<CHAN>::setPosition(const utils::Dim& d) {
     utils::Dim _dim;
@@ -258,8 +225,8 @@
     return mM3d.setPosition(_dim);
 }
 template <int CHAN>
-inline bool M3DExtPipe<CHAN>::setParameter(const utils::Params& param) {
-    return mM3d.setParameter(param);
+inline bool M3DExtPipe<CHAN>::setTransform(const utils::eTransform& param) {
+    return mM3d.setTransform(param);
 }
 template <int CHAN>
 inline bool M3DExtPipe<CHAN>::setSource(const utils::PipeArgs& args)
@@ -267,19 +234,9 @@
     // extract 3D fmt
     mM3Dfmt = utils::format3DInput(utils::getS3DFormat(args.whf.format)) |
             utils::HAL_3D_OUT_MONOS_MASK;
-    if(mM3d.isClosed()){
-        if(!this->start(args)) {
-            ALOGE("M3DExtPipe setSource failed to start");
-            return false;
-        }
-    }
     return mM3d.setSource(args);
 }
 template <int CHAN>
-inline const utils::PipeArgs& M3DExtPipe<CHAN>::getArgs() const {
-    return mM3d.getArgs();
-}
-template <int CHAN>
 inline utils::eOverlayPipeType M3DExtPipe<CHAN>::getOvPipeType() const {
     return utils::OV_PIPE_TYPE_M3D_EXTERNAL;
 }
@@ -296,10 +253,10 @@
 template <int CHAN>
 inline M3DPrimaryPipe<CHAN>::~M3DPrimaryPipe() { close(); }
 template <int CHAN>
-inline bool M3DPrimaryPipe<CHAN>::open(RotatorBase* rot) {
-    ALOGE_IF(DEBUG_OVERLAY, "M3DPrimaryPipe open");
-    if(!mM3d.open(rot)) {
-        ALOGE("3Dpipe failed to open");
+inline bool M3DPrimaryPipe<CHAN>::init(RotatorBase* rot) {
+    ALOGE_IF(DEBUG_OVERLAY, "M3DPrimaryPipe init");
+    if(!mM3d.init(rot)) {
+        ALOGE("3Dpipe failed to init");
         return false;
     }
     return true;
@@ -311,15 +268,9 @@
 template <int CHAN>
 inline bool M3DPrimaryPipe<CHAN>::commit() { return mM3d.commit(); }
 template <int CHAN>
-inline void M3DPrimaryPipe<CHAN>::setId(int id) { mM3d.setId(id); }
-template <int CHAN>
-inline void M3DPrimaryPipe<CHAN>::setMemoryId(int id) { mM3d.setMemoryId(id); }
-template <int CHAN>
-inline bool M3DPrimaryPipe<CHAN>::queueBuffer(uint32_t offset) {
-    return mM3d.queueBuffer(offset); }
-template <int CHAN>
-inline bool M3DPrimaryPipe<CHAN>::dequeueBuffer(void*& buf) {
-    return mM3d.dequeueBuffer(buf); }
+inline bool M3DPrimaryPipe<CHAN>::queueBuffer(int fd, uint32_t offset) {
+    return mM3d.queueBuffer(fd, offset);
+}
 template <int CHAN>
 inline bool M3DPrimaryPipe<CHAN>::waitForVsync() {
     return mM3d.waitForVsync(); }
@@ -333,20 +284,12 @@
     return mM3d.setCrop(_dim);
 }
 template <int CHAN>
-inline bool M3DPrimaryPipe<CHAN>::start(const utils::PipeArgs& args) {
-    if(!mM3d.start(args)) {
-        ALOGE("M3DPrimaryPipe start failed");
-        return false;
-    }
-    return true;
-}
-template <int CHAN>
 inline bool M3DPrimaryPipe<CHAN>::setPosition(const utils::Dim& d) {
     return mM3d.setPosition(d);
 }
 template <int CHAN>
-inline bool M3DPrimaryPipe<CHAN>::setParameter(const utils::Params& param) {
-    return mM3d.setParameter(param);
+inline bool M3DPrimaryPipe<CHAN>::setTransform(const utils::eTransform& param) {
+    return mM3d.setTransform(param);
 }
 template <int CHAN>
 inline bool M3DPrimaryPipe<CHAN>::setSource(const utils::PipeArgs& args)
@@ -354,19 +297,9 @@
     // extract 3D fmt
     mM3Dfmt = utils::format3DInput(utils::getS3DFormat(args.whf.format)) |
             utils::HAL_3D_OUT_MONOS_MASK;
-    if (mM3d.isClosed()) {
-        if (!this->start(args)) {
-            ALOGE("M3DPrimaryPipe setSource failed to start");
-            return false;
-        }
-    }
     return mM3d.setSource(args);
 }
 template <int CHAN>
-inline const utils::PipeArgs& M3DPrimaryPipe<CHAN>::getArgs() const {
-    return mM3d.getArgs();
-}
-template <int CHAN>
 inline utils::eOverlayPipeType M3DPrimaryPipe<CHAN>::getOvPipeType() const {
     return utils::OV_PIPE_TYPE_M3D_PRIMARY;
 }
@@ -382,10 +315,10 @@
 template <int CHAN>
 inline S3DExtPipe<CHAN>::~S3DExtPipe() { close(); }
 template <int CHAN>
-inline bool S3DExtPipe<CHAN>::open(RotatorBase* rot) {
-    ALOGE_IF(DEBUG_OVERLAY, "S3DExtPipe open");
-    if(!mS3d.open(rot)) {
-        ALOGE("3Dpipe failed to open");
+inline bool S3DExtPipe<CHAN>::init(RotatorBase* rot) {
+    ALOGE_IF(DEBUG_OVERLAY, "S3DExtPipe init");
+    if(!mS3d.init(rot)) {
+        ALOGE("3Dpipe failed to init");
         return false;
     }
     return true;
@@ -400,16 +333,9 @@
 template <int CHAN>
 inline bool S3DExtPipe<CHAN>::commit() { return mS3d.commit(); }
 template <int CHAN>
-inline void S3DExtPipe<CHAN>::setId(int id) { mS3d.setId(id); }
-template <int CHAN>
-inline void S3DExtPipe<CHAN>::setMemoryId(int id) { mS3d.setMemoryId(id); }
-template <int CHAN>
-inline bool S3DExtPipe<CHAN>::queueBuffer(uint32_t offset) {
-    //this->dump();
-    return mS3d.queueBuffer(offset); }
-template <int CHAN>
-inline bool S3DExtPipe<CHAN>::dequeueBuffer(void*& buf) {
-    return mS3d.dequeueBuffer(buf); }
+inline bool S3DExtPipe<CHAN>::queueBuffer(int fd, uint32_t offset) {
+    return mS3d.queueBuffer(fd, offset);
+}
 template <int CHAN>
 inline bool S3DExtPipe<CHAN>::waitForVsync() {
     return mS3d.waitForVsync(); }
@@ -423,20 +349,6 @@
     return mS3d.setCrop(_dim);
 }
 template <int CHAN>
-inline bool S3DExtPipe<CHAN>::start(const utils::PipeArgs& args) {
-    OVASSERT(mS3Dfmt, "S3DExtPipe mS3Dfmt should not be 0 here");
-    if(!mS3d.start(args)) {
-        ALOGE("S3DExtPipe start failed");
-        return false;
-    }
-    uint32_t fmt = mS3Dfmt & utils::OUTPUT_3D_MASK;
-    if(!utils::send3DInfoPacket(fmt)){
-        ALOGE("Error S3DExtPipe start error send3DInfoPacket %d", fmt);
-        return false;
-    }
-    return true;
-}
-template <int CHAN>
 inline bool S3DExtPipe<CHAN>::setPosition(const utils::Dim& d)
 {
     utils::Dim _dim;
@@ -450,25 +362,15 @@
     return mS3d.setPosition(_dim);
 }
 template <int CHAN>
-inline bool S3DExtPipe<CHAN>::setParameter(const utils::Params& param) {
-    return mS3d.setParameter(param);
+inline bool S3DExtPipe<CHAN>::setTransform(const utils::eTransform& param) {
+    return mS3d.setTransform(param);
 }
 template <int CHAN>
 inline bool S3DExtPipe<CHAN>::setSource(const utils::PipeArgs& args) {
     mS3Dfmt = utils::getS3DFormat(args.whf.format);
-    if(mS3d.isClosed()){
-        if(!this->start(args)) {
-            ALOGE("S3DExtPipe setSource failed to start");
-            return false;
-        }
-    }
     return mS3d.setSource(args);
 }
 template <int CHAN>
-inline const utils::PipeArgs& S3DExtPipe<CHAN>::getArgs() const {
-    return mS3d.getArgs();
-}
-template <int CHAN>
 inline utils::eOverlayPipeType S3DExtPipe<CHAN>::getOvPipeType() const {
     return utils::OV_PIPE_TYPE_S3D_EXTERNAL;
 }
@@ -484,10 +386,10 @@
 template <int CHAN>
 inline S3DPrimaryPipe<CHAN>::~S3DPrimaryPipe() { close(); }
 template <int CHAN>
-inline bool S3DPrimaryPipe<CHAN>::open(RotatorBase* rot) {
-    ALOGE_IF(DEBUG_OVERLAY, "S3DPrimaryPipe open");
-    if(!mS3d.open(rot)) {
-        ALOGE("3Dpipe failed to open");
+inline bool S3DPrimaryPipe<CHAN>::init(RotatorBase* rot) {
+    ALOGE_IF(DEBUG_OVERLAY, "S3DPrimaryPipe init");
+    if(!mS3d.init(rot)) {
+        ALOGE("3Dpipe failed to init");
         return false;
     }
     // set the ctrl fd
@@ -502,18 +404,20 @@
     mCtrl3D.close();
     return mS3d.close();
 }
+
 template <int CHAN>
-inline bool S3DPrimaryPipe<CHAN>::commit() { return mS3d.commit(); }
+inline bool S3DPrimaryPipe<CHAN>::commit() {
+    uint32_t fmt = mS3Dfmt & utils::OUTPUT_3D_MASK;
+    if(!utils::send3DInfoPacket(fmt)){
+        ALOGE("Error S3DExtPipe start error send3DInfoPacket %d", fmt);
+        return false;
+    }
+    return mS3d.commit();
+}
 template <int CHAN>
-inline void S3DPrimaryPipe<CHAN>::setId(int id) { mS3d.setId(id); }
-template <int CHAN>
-inline void S3DPrimaryPipe<CHAN>::setMemoryId(int id) { mS3d.setMemoryId(id); }
-template <int CHAN>
-inline bool S3DPrimaryPipe<CHAN>::queueBuffer(uint32_t offset) {
-    return mS3d.queueBuffer(offset); }
-template <int CHAN>
-inline bool S3DPrimaryPipe<CHAN>::dequeueBuffer(void*& buf) {
-    return mS3d.dequeueBuffer(buf); }
+inline bool S3DPrimaryPipe<CHAN>::queueBuffer(int fd, uint32_t offset) {
+    return mS3d.queueBuffer(fd, offset);
+}
 template <int CHAN>
 inline bool S3DPrimaryPipe<CHAN>::waitForVsync() {
     return mS3d.waitForVsync(); }
@@ -527,14 +431,6 @@
     return mS3d.setCrop(_dim);
 }
 template <int CHAN>
-inline bool S3DPrimaryPipe<CHAN>::start(const utils::PipeArgs& args) {
-    if(!mS3d.start(args)) {
-        ALOGE("S3DPrimaryPipe start failed");
-        return false;
-    }
-    return true;
-}
-template <int CHAN>
 inline bool S3DPrimaryPipe<CHAN>::setPosition(const utils::Dim& d)
 {
     utils::Whf fbwhf(mS3d.getScreenInfo().mFBWidth,
@@ -562,47 +458,35 @@
 * So the easiest way to achieve it, is to make sure FB0 is having it before
 * setParam is running */
 template <>
-inline bool S3DPrimaryPipe<utils::OV_PIPE0>::setParameter(
-        const utils::Params& param) {
-    if(utils::OVERLAY_TRANSFORM == param.param){
-        uint32_t barrier=0;
-        switch(param.value) {
-            case HAL_TRANSFORM_ROT_90:
-            case HAL_TRANSFORM_ROT_270:
-                barrier = utils::BARRIER_LAND;
-                break;
-            default:
-                barrier = utils::BARRIER_PORT;
-                break;
-        }
-        if(!utils::enableBarrier(barrier)) {
-            ALOGE("S3DPrimaryPipe setParameter failed to enable barrier");
-        }
+inline bool S3DPrimaryPipe<utils::OV_PIPE0>::setTransform(
+        const utils::eTransform& param) {
+    uint32_t barrier=0;
+    switch(param) {
+        case utils::OVERLAY_TRANSFORM_ROT_90:
+        case utils::OVERLAY_TRANSFORM_ROT_270:
+            barrier = utils::BARRIER_LAND;
+            break;
+        default:
+            barrier = utils::BARRIER_PORT;
+            break;
     }
-    return mS3d.setParameter(param);
+    if(!utils::enableBarrier(barrier)) {
+        ALOGE("S3DPrimaryPipe setTransform failed to enable barrier");
+    }
+    return mS3d.setTransform(param);
 }
 
 template <int CHAN>
-inline bool S3DPrimaryPipe<CHAN>::setParameter(const utils::Params& param) {
-    return mS3d.setParameter(param);
+inline bool S3DPrimaryPipe<CHAN>::setTransform(const utils::eTransform& param) {
+    return mS3d.setTransform(param);
 }
 template <int CHAN>
 inline bool S3DPrimaryPipe<CHAN>::setSource(const utils::PipeArgs& args)
 {
     mS3Dfmt = utils::getS3DFormat(args.whf.format);
-    if(mS3d.isClosed()){
-        if(!this->start(args)) {
-            ALOGE("S3DPrimaryPipe setSource failed to start");
-            return false;
-        }
-    }
     return mS3d.setSource(args);
 }
 template <int CHAN>
-inline const utils::PipeArgs& S3DPrimaryPipe<CHAN>::getArgs() const {
-    return mS3d.getArgs();
-}
-template <int CHAN>
 inline utils::eOverlayPipeType S3DPrimaryPipe<CHAN>::getOvPipeType() const {
     return utils::OV_PIPE_TYPE_S3D_PRIMARY;
 }
diff --git a/liboverlay/pipes/overlayBypassPipe.h b/liboverlay/pipes/overlayBypassPipe.h
deleted file mode 100644
index 593a693..0000000
--- a/liboverlay/pipes/overlayBypassPipe.h
+++ /dev/null
@@ -1,213 +0,0 @@
-/*
-* Copyright (c) 2012, Code Aurora Forum. All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are
-* met:
-*    * Redistributions of source code must retain the above copyright
-*      notice, this list of conditions and the following disclaimer.
-*    * Redistributions in binary form must reproduce the above
-*      copyright notice, this list of conditions and the following
-*      disclaimer in the documentation and/or other materials provided
-*      with the distribution.
-*    * Neither the name of Code Aurora Forum, Inc. nor the names of its
-*      contributors may be used to endorse or promote products derived
-*      from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
-* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
-* ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
-* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
-* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
-* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#ifndef OVERLAY_BYPASS_PIPE_H
-#define OVERLAY_BYPASS_PIPE_H
-
-#include "overlayGenPipe.h"
-#include "overlayUtils.h"
-#include "overlayCtrlData.h"
-#include "overlayMdp.h"
-#include "overlayRotator.h"
-
-namespace overlay {
-
-/* A specific impl of GenericPipe
-* Whenever needed to have a pass through - we do it.
-* If there is a special need for a different behavior - do it here
-* PipeType = 0 (RGB), 1 (VG) */
-template <utils::eMdpPipeType PipeType, utils::eIsFg IsFg, utils::eWait Wait,
-    utils::eZorder Zorder>
-class BypassPipe : utils::NoCopy {
-public:
-    /* Please look at overlayGenPipe.h for info */
-    explicit BypassPipe();
-    ~BypassPipe();
-    bool open(RotatorBase* rot);
-    bool close();
-    bool commit();
-    void setId(int id);
-    void setMemoryId(int id);
-    bool queueBuffer(uint32_t offset);
-    bool dequeueBuffer(void*& buf);
-    bool waitForVsync();
-    bool setCrop(const utils::Dim& dim);
-    bool start(const utils::PipeArgs& args);
-    bool setPosition(const utils::Dim& dim);
-    bool setParameter(const utils::Params& param);
-    bool setSource(const utils::PipeArgs& args);
-    const utils::PipeArgs& getArgs() const;
-    utils::eOverlayPipeType getOvPipeType() const;
-    void dump() const;
-private:
-    overlay::GenericPipe<ovutils::PRIMARY> mBypass;
-};
-
-//------------------Inlines and Templates---------------------
-
-template <utils::eMdpPipeType PipeType, utils::eIsFg IsFg, utils::eWait Wait,
-    utils::eZorder Zorder>
-inline BypassPipe<PipeType, IsFg, Wait, Zorder>::BypassPipe() {}
-
-template <utils::eMdpPipeType PipeType, utils::eIsFg IsFg, utils::eWait Wait,
-    utils::eZorder Zorder>
-inline BypassPipe<PipeType, IsFg, Wait, Zorder>::~BypassPipe() {
-    close();
-}
-
-template <utils::eMdpPipeType PipeType, utils::eIsFg IsFg, utils::eWait Wait,
-    utils::eZorder Zorder>
-inline bool BypassPipe<PipeType, IsFg, Wait, Zorder>::open(RotatorBase* rot) {
-    ALOGE_IF(DEBUG_OVERLAY, "BypassPipe open");
-    return mBypass.open(rot);
-}
-
-template <utils::eMdpPipeType PipeType, utils::eIsFg IsFg, utils::eWait Wait,
-    utils::eZorder Zorder>
-inline bool BypassPipe<PipeType, IsFg, Wait, Zorder>::close() {
-    return mBypass.close();
-}
-
-template <utils::eMdpPipeType PipeType, utils::eIsFg IsFg, utils::eWait Wait,
-    utils::eZorder Zorder>
-inline bool BypassPipe<PipeType, IsFg, Wait, Zorder>::commit() {
-    return mBypass.commit();
-}
-
-template <utils::eMdpPipeType PipeType, utils::eIsFg IsFg, utils::eWait Wait,
-    utils::eZorder Zorder>
-inline void BypassPipe<PipeType, IsFg, Wait, Zorder>::setId(int id) {
-    mBypass.setId(id);
-}
-
-template <utils::eMdpPipeType PipeType, utils::eIsFg IsFg, utils::eWait Wait,
-    utils::eZorder Zorder>
-inline void BypassPipe<PipeType, IsFg, Wait, Zorder>::setMemoryId(int id) {
-    mBypass.setMemoryId(id);
-}
-
-template <utils::eMdpPipeType PipeType, utils::eIsFg IsFg, utils::eWait Wait,
-    utils::eZorder Zorder>
-inline bool BypassPipe<PipeType, IsFg, Wait, Zorder>::queueBuffer(
-        uint32_t offset) {
-    return mBypass.queueBuffer(offset);
-}
-
-template <utils::eMdpPipeType PipeType, utils::eIsFg IsFg, utils::eWait Wait,
-    utils::eZorder Zorder>
-inline bool BypassPipe<PipeType, IsFg, Wait, Zorder>::dequeueBuffer(
-        void*& buf) {
-    return mBypass.dequeueBuffer(buf);
-}
-
-template <utils::eMdpPipeType PipeType, utils::eIsFg IsFg, utils::eWait Wait,
-    utils::eZorder Zorder>
-inline bool BypassPipe<PipeType, IsFg, Wait, Zorder>::waitForVsync() {
-    return mBypass.waitForVsync();
-}
-
-template <utils::eMdpPipeType PipeType, utils::eIsFg IsFg, utils::eWait Wait,
-    utils::eZorder Zorder>
-inline bool BypassPipe<PipeType, IsFg, Wait, Zorder>::setCrop(
-        const utils::Dim& dim) {
-    return mBypass.setCrop(dim);
-}
-
-template <utils::eMdpPipeType PipeType, utils::eIsFg IsFg, utils::eWait Wait,
-    utils::eZorder Zorder>
-inline bool BypassPipe<PipeType, IsFg, Wait, Zorder>::start(
-        const utils::PipeArgs& args) {
-    return mBypass.start(args);
-}
-
-template <utils::eMdpPipeType PipeType, utils::eIsFg IsFg, utils::eWait Wait,
-    utils::eZorder Zorder>
-inline bool BypassPipe<PipeType, IsFg, Wait, Zorder>::setPosition(
-        const utils::Dim& dim) {
-    return mBypass.setPosition(dim);
-}
-
-template <utils::eMdpPipeType PipeType, utils::eIsFg IsFg, utils::eWait Wait,
-    utils::eZorder Zorder>
-inline bool BypassPipe<PipeType, IsFg, Wait, Zorder>::setParameter(
-        const utils::Params& param) {
-    return mBypass.setParameter(param);
-}
-
-template <utils::eMdpPipeType PipeType, utils::eIsFg IsFg, utils::eWait Wait,
-    utils::eZorder Zorder>
-inline bool BypassPipe<PipeType, IsFg, Wait, Zorder>::setSource(
-        const utils::PipeArgs& args) {
-    utils::PipeArgs arg(args);
-
-    // Stride aligned to 32
-    arg.whf.w = utils::align(arg.whf.w, 32);
-    arg.whf.h = utils::align(arg.whf.h, 32);
-
-    // VG or RG pipe
-    if (PipeType == utils::OV_MDP_PIPE_VG) {
-        setMdpFlags(arg.mdpFlags, utils::OV_MDP_PIPE_SHARE);
-    }
-
-    // Set is_fg flag
-    arg.isFg = IsFg;
-
-    // Wait or no wait
-    arg.wait = Wait;
-
-    // Z-order
-    arg.zorder = Zorder;
-
-    return mBypass.setSource(arg);
-}
-
-template <utils::eMdpPipeType PipeType, utils::eIsFg IsFg, utils::eWait Wait,
-    utils::eZorder Zorder>
-inline const utils::PipeArgs& BypassPipe<PipeType, IsFg, Wait,
-        Zorder>::getArgs() const {
-    return mBypass.getArgs();
-}
-
-template <utils::eMdpPipeType PipeType, utils::eIsFg IsFg, utils::eWait Wait,
-    utils::eZorder Zorder>
-inline utils::eOverlayPipeType BypassPipe<PipeType, IsFg, Wait,
-        Zorder>::getOvPipeType() const {
-    return utils::OV_PIPE_TYPE_BYPASS;
-}
-
-template <utils::eMdpPipeType PipeType, utils::eIsFg IsFg, utils::eWait Wait,
-    utils::eZorder Zorder>
-inline void BypassPipe<PipeType, IsFg, Wait, Zorder>::dump() const {
-    ALOGE("Bypass VG Pipe");
-    mBypass.dump();
-}
-
-} // overlay
-
-#endif // OVERLAY_BYPASS_PIPE_H
diff --git a/liboverlay/pipes/overlayGenPipe.h b/liboverlay/pipes/overlayGenPipe.h
index 1fd4a4f..c2d774b 100644
--- a/liboverlay/pipes/overlayGenPipe.h
+++ b/liboverlay/pipes/overlayGenPipe.h
@@ -34,65 +34,38 @@
 #include "overlayRotator.h"
 #include "overlayCtrlData.h"
 
-// FIXME make int to be uint32 whenever possible
-
 namespace overlay {
 
 template <int PANEL>
 class GenericPipe : utils::NoCopy {
 public:
-    /* ctor init */
+    /* ctor */
     explicit GenericPipe();
-
-    /* dtor close */
+    /* dtor */
     ~GenericPipe();
-
-    /* CTRL/DATA/ROT open */
-    bool open(RotatorBase* rot);
-
+    /* CTRL/DATA init. Not owning rotator, will not  init it */
+    bool init(RotatorBase* rot);
     /* CTRL/DATA close. Not owning rotator, will not close it */
     bool close();
 
+    /* Control APIs */
+    /* set source using whf, orient and wait flag */
+    bool setSource(const utils::PipeArgs& args);
+    /* set crop a.k.a the region of interest */
+    bool setCrop(const utils::Dim& d);
+    /* set orientation*/
+    bool setTransform(const utils::eTransform& param);
+    /* set mdp posision using dim */
+    bool setPosition(const utils::Dim& dim);
     /* commit changes to the overlay "set"*/
     bool commit();
 
-    /* "Data" related interface */
-
-    /* set ID directly to data channel */
-    void setId(int id);
-
-    /* Set FD / memid */
-    void setMemoryId(int id);
-
+    /* Data APIs */
     /* queue buffer to the overlay */
-    bool queueBuffer(uint32_t offset);
-
-    /* dequeue buffer to the overlay NOTSUPPORTED */
-    bool dequeueBuffer(void*& buf);
-
+    bool queueBuffer(int fd, uint32_t offset);
     /* wait for vsync to be done */
     bool waitForVsync();
 
-    /* set crop data FIXME setROI (Region Of Intrest) */
-    bool setCrop(const utils::Dim& d);
-
-    /* "Ctrl" related interface */
-
-    /*
-     * Start a session, opens the rotator
-     * FIXME, we might want to open the rotator separately
-     */
-    bool start(const utils::PipeArgs& args);
-
-    /* set mdp posision using dim */
-    bool setPosition(const utils::Dim& dim);
-
-    /* set param using Params (param,value pair) */
-    bool setParameter(const utils::Params& param);
-
-    /* set source using whf, orient and wait flag */
-    bool setSource(const utils::PipeArgs& args);
-
     /* return cached startup args */
     const utils::PipeArgs& getArgs() const;
 
@@ -123,33 +96,33 @@
     /* dump the state of the object */
     void dump() const;
 private:
-    /* set Closed channel */
+    /* set Closed pipe */
     bool setClosed();
-    // kick off rotator.
-    bool startRotator();
 
     /* Ctrl/Data aggregator */
     CtrlData mCtrlData;
 
-    /* caching startup params. useful when need
-     * to have the exact copy of that pipe.
-     * For example when HDMI is connected, and we would
-     * like to open/start the pipe with the args */
-    utils::PipeArgs mArgs;
-
     /* rotator mdp base
      * Can point to NullRotator or to Rotator*/
     RotatorBase* mRot;
 
-    /* my flags */
-    enum { CLOSED = 1<<0 };
-    uint32_t mFlags;
+    //Whether rotator is used for 0-rot or otherwise
+    bool mRotUsed;
+
+    /* Pipe open or closed */
+    enum ePipeState {
+        CLOSED,
+        OPEN
+    };
+    ePipeState pipeState;
 };
 
 //------------------------Inlines and Templates ----------------------
 
 template <int PANEL>
-GenericPipe<PANEL>::GenericPipe() : mRot(0), mFlags(CLOSED) {}
+GenericPipe<PANEL>::GenericPipe() : mRot(0), mRotUsed(false),
+        pipeState(CLOSED) {
+}
 
 template <int PANEL>
 GenericPipe<PANEL>::~GenericPipe() {
@@ -157,33 +130,42 @@
 }
 
 template <int PANEL>
-bool GenericPipe<PANEL>::open(RotatorBase* rot)
+bool GenericPipe<PANEL>::init(RotatorBase* rot)
 {
+    ALOGE_IF(DEBUG_OVERLAY, "GenericPipe init");
     OVASSERT(rot, "rot is null");
-    // open ctrl and data
+
+    // init ctrl and data
     uint32_t fbnum = utils::getFBForPanel(PANEL);
-    ALOGE_IF(DEBUG_OVERLAY, "GenericPipe open");
-    if(!mCtrlData.ctrl.open(fbnum, rot)) {
-        ALOGE("GenericPipe failed to open ctrl");
+
+    if(!mCtrlData.ctrl.init(fbnum)) {
+        ALOGE("GenericPipe failed to init ctrl");
         return false;
     }
-    if(!mCtrlData.data.open(fbnum, rot)) {
-        ALOGE("GenericPipe failed to open data");
+
+    if(!mCtrlData.data.init(fbnum)) {
+        ALOGE("GenericPipe failed to init data");
         return false;
     }
+
+    //Cache the rot ref. Ownership is with OverlayImpl.
     mRot = rot;
 
-    // NOTE: we won't have the flags as non CLOSED since we
-    // consider the pipe opened for business only when we call
-    // start()
+    mRotUsed = false;
+
+    // NOTE:init() on the rot is called by OverlayImpl
+    // Pipes only have to worry about using rot, and not init or close.
 
     return true;
 }
 
 template <int PANEL>
 bool GenericPipe<PANEL>::close() {
-    if(isClosed()) return true;
+    if(isClosed())
+        return true;
+
     bool ret = true;
+
     if(!mCtrlData.ctrl.close()) {
         ALOGE("GenericPipe failed to close ctrl");
         ret = false;
@@ -192,25 +174,106 @@
         ALOGE("GenericPipe failed to close data");
         ret = false;
     }
+
+    // NOTE:close() on the rot is called by OverlayImpl
+    // Pipes only have to worry about using rot, and not init or close.
+
     setClosed();
     return ret;
 }
 
 template <int PANEL>
-inline bool GenericPipe<PANEL>::commit(){
-    OVASSERT(isOpen(), "State is closed, cannot commit");
-    return mCtrlData.ctrl.commit();
+inline bool GenericPipe<PANEL>::setSource(
+        const utils::PipeArgs& args)
+{
+    utils::PipeArgs newargs(args);
+    //Interlace video handling.
+    if(newargs.whf.format & INTERLACE_MASK) {
+        setMdpFlags(newargs.mdpFlags, utils::OV_MDP_DEINTERLACE);
+    }
+    utils::Whf whf(newargs.whf);
+    //Extract HAL format from lower bytes. Deinterlace if interlaced.
+    whf.format = utils::getColorFormat(whf.format);
+    //Get MDP equivalent of HAL format.
+    whf.format = utils::getMdpFormat(whf.format);
+    newargs.whf = whf;
+
+    //Cache if user wants 0-rotation
+    mRotUsed = newargs.rotFlags & utils::ROT_FLAG_ENABLED;
+    mRot->setSource(newargs.whf);
+    mRot->setFlags(newargs.mdpFlags);
+    return mCtrlData.ctrl.setSource(newargs);
 }
 
 template <int PANEL>
-inline void GenericPipe<PANEL>::setMemoryId(int id) {
-    OVASSERT(isOpen(), "State is closed, cannot setMemoryId");
-    mCtrlData.data.setMemoryId(id);
+inline bool GenericPipe<PANEL>::setCrop(
+        const overlay::utils::Dim& d) {
+    return mCtrlData.ctrl.setCrop(d);
 }
 
 template <int PANEL>
-inline void GenericPipe<PANEL>::setId(int id) {
-    mCtrlData.data.setId(id); }
+inline bool GenericPipe<PANEL>::setTransform(
+        const utils::eTransform& orient)
+{
+    //Rotation could be enabled by user for zero-rot or the layer could have
+    //some transform. Mark rotation enabled in either case.
+    mRotUsed |= (orient != utils::OVERLAY_TRANSFORM_0);
+    mRot->setTransform(orient, mRotUsed);
+
+    return mCtrlData.ctrl.setTransform(orient, mRotUsed);
+}
+
+template <int PANEL>
+inline bool GenericPipe<PANEL>::setPosition(const utils::Dim& d)
+{
+    return mCtrlData.ctrl.setPosition(d);
+}
+
+template <int PANEL>
+inline bool GenericPipe<PANEL>::commit() {
+    bool ret = false;
+    //If wanting to use rotator, start it.
+    if(mRotUsed) {
+        if(!mRot->commit()) {
+            ALOGE("GenPipe Rotator commit failed");
+            return false;
+        }
+    }
+    ret = mCtrlData.ctrl.commit();
+    pipeState = ret ? OPEN : CLOSED;
+    return ret;
+}
+
+template <int PANEL>
+inline bool GenericPipe<PANEL>::queueBuffer(int fd, uint32_t offset) {
+    //TODO Move pipe-id transfer to CtrlData class. Make ctrl and data private.
+    OVASSERT(isOpen(), "State is closed, cannot queueBuffer");
+    int pipeId = mCtrlData.ctrl.getPipeId();
+    OVASSERT(-1 != pipeId, "Ctrl ID should not be -1");
+    // set pipe id from ctrl to data
+    mCtrlData.data.setPipeId(pipeId);
+
+    int finalFd = fd;
+    uint32_t finalOffset = offset;
+    //If rotator is to be used, queue to it, so it can ROTATE.
+    if(mRotUsed) {
+        if(!mRot->queueBuffer(fd, offset)) {
+            ALOGE("GenPipe Rotator play failed");
+            return false;
+        }
+        //Configure MDP's source buffer as the current output buffer of rotator
+        if(mRot->getDstMemId() != -1) {
+            finalFd = mRot->getDstMemId();
+            finalOffset = mRot->getDstOffset();
+        } else {
+            //Could be -1 for NullRotator, if queue above succeeds.
+            //Need an actual rotator. Modify overlay State Traits.
+            //Not fatal, keep queuing to MDP without rotation.
+            ALOGE("Null rotator in use, where an actual is required");
+        }
+    }
+    return mCtrlData.data.queueBuffer(finalFd, finalOffset);
+}
 
 template <int PANEL>
 inline int GenericPipe<PANEL>::getCtrlFd() const {
@@ -218,128 +281,12 @@
 }
 
 template <int PANEL>
-inline bool GenericPipe<PANEL>::setCrop(
-        const overlay::utils::Dim& d) {
-    OVASSERT(isOpen(), "State is closed, cannot setCrop");
-    return mCtrlData.ctrl.setCrop(d);
-}
-
-template <int PANEL>
-bool GenericPipe<PANEL>::start(const utils::PipeArgs& args)
-{
-    /* open before your start control rotator */
-    uint32_t sz = args.whf.size; //utils::getSizeByMdp(args.whf);
-    OVASSERT(sz, "GenericPipe sz=%d", sz);
-    if(!mRot->open()) {
-        ALOGE("GenericPipe start failed to open rot");
-        return false;
-    }
-
-    if(!mCtrlData.ctrl.start(args)){
-        ALOGE("GenericPipe failed to start");
-        return false;
-    }
-
-    int ctrlId = mCtrlData.ctrl.getId();
-    OVASSERT(-1 != ctrlId, "Ctrl ID should not be -1");
-    // set ID requeset to assoc ctrl to data
-    setId(ctrlId);
-    // set ID request to assoc MDP data to ROT MDP data
-    mRot->setDataReqId(mCtrlData.data.getId());
-
-    // cache the args for future reference.
-    mArgs = args;
-
-    // we got here so we are open+start and good to go
-    mFlags = 0; // clear flags from CLOSED
-    // TODO make it more robust when more flags
-    // are added
-
-    return true;
-}
-
-template <int PANEL>
-inline const utils::PipeArgs& GenericPipe<PANEL>::getArgs() const
-{
-    return mArgs;
-}
-
-template <int PANEL>
-bool GenericPipe<PANEL>::startRotator() {
-    // kick off rotator
-    if(!mRot->start()) {
-        ALOGE("GenericPipe failed to start rotator");
-        return false;
-    }
-    return true;
-}
-
-template <int PANEL>
-inline bool GenericPipe<PANEL>::queueBuffer(uint32_t offset) {
-    OVASSERT(isOpen(), "State is closed, cannot queueBuffer");
-    return mCtrlData.data.queueBuffer(offset);
-}
-
-template <int PANEL>
-inline bool GenericPipe<PANEL>::dequeueBuffer(void*&) {
-    OVASSERT(isOpen(), "State is closed, cannot dequeueBuffer");
-    // can also set error to NOTSUPPORTED in the future
-    return false;
-}
-
-template <int PANEL>
 inline bool GenericPipe<PANEL>::waitForVsync() {
     OVASSERT(isOpen(), "State is closed, cannot waitForVsync");
-
     return mCtrlData.data.waitForVsync();
 }
 
 template <int PANEL>
-inline bool GenericPipe<PANEL>::setPosition(const utils::Dim& dim)
-{
-    OVASSERT(isOpen(), "State is closed, cannot setPosition");
-    return mCtrlData.ctrl.setPosition(dim);
-}
-
-template <int PANEL>
-inline bool GenericPipe<PANEL>::setParameter(
-        const utils::Params& param)
-{
-    OVASSERT(isOpen(), "State is closed, cannot setParameter");
-    // Currently setParameter would start rotator
-    if(!mCtrlData.ctrl.setParameter(param)) {
-        ALOGE("GenericPipe failed to setparam");
-        return false;
-    }
-    // if rot flags are ENABLED it means we would always
-    // like to have rot. Even with 0 rot. (solves tearing)
-    if(utils::ROT_FLAG_ENABLED == mArgs.rotFlags) {
-        mRot->setEnable();
-    }
-    return startRotator();
-}
-
-template <int PANEL>
-inline bool GenericPipe<PANEL>::setSource(
-        const utils::PipeArgs& args)
-{
-    // cache the recent args.
-    mArgs = args;
-    // setSource is the 1st thing that is being called on a pipe.
-    // If pipe is closed, we should start everything.
-    // we assume it is being opened with the correct FDs.
-    if(isClosed()) {
-        if(!this->start(args)) {
-            ALOGE("GenericPipe setSource failed to start");
-            return false;
-        }
-        return true;
-    }
-
-    return mCtrlData.ctrl.setSource(args);
-}
-
-template <int PANEL>
 inline utils::Dim GenericPipe<PANEL>::getAspectRatio(
         const utils::Whf& whf) const
 {
@@ -374,7 +321,7 @@
 void GenericPipe<PANEL>::dump() const
 {
     ALOGE("== Dump Generic pipe start ==");
-    ALOGE("flags=0x%x", mFlags);
+    ALOGE("pipe state = %d", (int)pipeState);
     OVASSERT(mRot, "GenericPipe should have a valid Rot");
     mCtrlData.ctrl.dump();
     mCtrlData.data.dump();
@@ -384,20 +331,20 @@
 
 template <int PANEL>
 inline bool GenericPipe<PANEL>::isClosed() const  {
-    return utils::getBit(mFlags, CLOSED);
+    return (pipeState == CLOSED);
 }
 
 template <int PANEL>
 inline bool GenericPipe<PANEL>::isOpen() const  {
-    return !isClosed();
+    return (pipeState == OPEN);
 }
 
 template <int PANEL>
 inline bool GenericPipe<PANEL>::setClosed() {
-    return utils::setBit(mFlags, CLOSED);
+    pipeState = CLOSED;
+    return true;
 }
 
-
 } //namespace overlay
 
 #endif // OVERLAY_GENERIC_PIPE_H
diff --git a/liboverlay/pipes/overlayHdmiPipe.h b/liboverlay/pipes/overlayHdmiPipe.h
deleted file mode 100644
index 48c3817..0000000
--- a/liboverlay/pipes/overlayHdmiPipe.h
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
-* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are
-* met:
-*    * Redistributions of source code must retain the above copyright
-*      notice, this list of conditions and the following disclaimer.
-*    * Redistributions in binary form must reproduce the above
-*      copyright notice, this list of conditions and the following
-*      disclaimer in the documentation and/or other materials provided
-*      with the distribution.
-*    * Neither the name of Code Aurora Forum, Inc. nor the names of its
-*      contributors may be used to endorse or promote products derived
-*      from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
-* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
-* ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
-* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
-* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
-* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#ifndef OVERLAY_HDMI_PIPE_H
-#define OVERLAY_HDMI_PIPE_H
-
-#include "overlayGenPipe.h"
-#include "overlayUtils.h"
-#include "overlayCtrlData.h"
-#include "overlayMdp.h"
-#include "overlayRotator.h"
-
-namespace overlay {
-
-/* A specific impl of GenericPipe
-* Whenever needed to have a pass through - we do it.
-* If there is a special need for a different behavior - do it here */
-class HdmiPipe : utils::NoCopy {
-public:
-    /* Please look at overlayGenPipe.h for info */
-    explicit HdmiPipe();
-    ~HdmiPipe();
-    bool open(RotatorBase* rot);
-    bool close();
-    bool commit();
-    void setId(int id);
-    void setMemoryId(int id);
-    bool queueBuffer(uint32_t offset);
-    bool dequeueBuffer(void*& buf);
-    bool waitForVsync();
-    bool setCrop(const utils::Dim& dim);
-    bool start(const utils::PipeArgs& args);
-    bool setPosition(const utils::Dim& dim);
-    bool setParameter(const utils::Params& param);
-    bool setSource(const utils::PipeArgs& args);
-    const utils::PipeArgs& getArgs() const;
-    utils::eOverlayPipeType getOvPipeType() const;
-    void dump() const;
-private:
-    overlay::GenericPipe<ovutils::EXTERNAL> mHdmi;
-};
-
-//------------------Inlines -----------------------------
-
-inline HdmiPipe::HdmiPipe() {}
-inline HdmiPipe::~HdmiPipe() { close(); }
-inline bool HdmiPipe::open(RotatorBase* rot) {
-    ALOGE_IF(DEBUG_OVERLAY, "HdmiPipe open");
-    return mHdmi.open(rot);
-}
-inline bool HdmiPipe::close() { return mHdmi.close(); }
-inline bool HdmiPipe::commit() { return mHdmi.commit(); }
-inline void HdmiPipe::setId(int id) { mHdmi.setId(id); }
-inline void HdmiPipe::setMemoryId(int id) { mHdmi.setMemoryId(id); }
-inline bool HdmiPipe::queueBuffer(uint32_t offset) {
-    return mHdmi.queueBuffer(offset); }
-inline bool HdmiPipe::dequeueBuffer(void*& buf) {
-    return mHdmi.dequeueBuffer(buf); }
-inline bool HdmiPipe::waitForVsync() {
-    return mHdmi.waitForVsync(); }
-inline bool HdmiPipe::setCrop(const utils::Dim& dim) {
-    return mHdmi.setCrop(dim); }
-inline bool HdmiPipe::start(const utils::PipeArgs& args) {
-    return mHdmi.start(args); }
-inline bool HdmiPipe::setPosition(const utils::Dim& dim)
-{
-    utils::Dim d;
-    // Need to change dim to aspect ratio
-    if (utils::FrameBufferInfo::getInstance()->supportTrueMirroring()) {
-        // Use dim info to calculate aspect ratio for true UI mirroring
-        d = mHdmi.getAspectRatio(dim);
-    } else {
-        // Use cached crop data to get aspect ratio
-        utils::Dim crop = mHdmi.getCrop();
-        utils::Whf whf(crop.w, crop.h, 0);
-        d = mHdmi.getAspectRatio(whf);
-    }
-    ALOGE_IF(DEBUG_OVERLAY, "Calculated aspect ratio for HDMI: x=%d, y=%d, w=%d, h=%d, o=%d",
-            d.x, d.y, d.w, d.h, d.o);
-    return mHdmi.setPosition(d);
-}
-inline bool HdmiPipe::setParameter(const utils::Params& param) {
-    return mHdmi.setParameter(param); }
-inline bool HdmiPipe::setSource(const utils::PipeArgs& args) {
-    utils::PipeArgs arg(args);
-    return mHdmi.setSource(arg);
-}
-inline const utils::PipeArgs& HdmiPipe::getArgs() const {
-    return mHdmi.getArgs();
-}
-inline utils::eOverlayPipeType HdmiPipe::getOvPipeType() const {
-    return utils::OV_PIPE_TYPE_HDMI;
-}
-inline void HdmiPipe::dump() const {
-    ALOGE("HDMI Pipe");
-    mHdmi.dump();
-}
-
-
-} // overlay
-
-#endif // OVERLAY_HDMI_PIPE_H
diff --git a/liboverlay/pipes/overlayUIMirrorPipe.h b/liboverlay/pipes/overlayUIMirrorPipe.h
index 47fbc37..1c22020 100644
--- a/liboverlay/pipes/overlayUIMirrorPipe.h
+++ b/liboverlay/pipes/overlayUIMirrorPipe.h
@@ -46,74 +46,61 @@
     /* Please look at overlayGenPipe.h for info */
     explicit UIMirrorPipe();
     ~UIMirrorPipe();
-    bool open(RotatorBase* rot);
+    bool init(RotatorBase* rot);
     bool close();
     bool commit();
-    void setId(int id);
-    void setMemoryId(int id);
-    bool queueBuffer(uint32_t offset);
-    bool dequeueBuffer(void*& buf);
+    bool queueBuffer(int fd, uint32_t offset);
     bool waitForVsync();
     bool setCrop(const utils::Dim& dim);
-    bool start(const utils::PipeArgs& args);
     bool setPosition(const utils::Dim& dim);
-    bool setParameter(const utils::Params& param);
+    bool setTransform(const utils::eTransform& param);
     bool setSource(const utils::PipeArgs& args);
-    const utils::PipeArgs& getArgs() const;
     utils::eOverlayPipeType getOvPipeType() const;
     void dump() const;
 private:
     overlay::GenericPipe<ovutils::EXTERNAL> mUI;
+    utils::eTransform mPrimFBOr; //Primary FB's orientation
 };
 
 //----------------------------Inlines -----------------------------
 
-inline UIMirrorPipe::UIMirrorPipe() {}
+inline UIMirrorPipe::UIMirrorPipe() { mPrimFBOr = utils::OVERLAY_TRANSFORM_0; }
 inline UIMirrorPipe::~UIMirrorPipe() { close(); }
-inline bool UIMirrorPipe::open(RotatorBase* rot) {
-    ALOGE_IF(DEBUG_OVERLAY, "UIMirrorPipe open");
-    bool ret = mUI.open(rot);
-    //If source to rotator is framebuffer, which is the case we UI Mirror pipe,
-    //we need to inform driver during playback. Since FB does not use ION.
-    rot->setSrcFB(true);
+inline bool UIMirrorPipe::init(RotatorBase* rot) {
+    ALOGE_IF(DEBUG_OVERLAY, "UIMirrorPipe init");
+    bool ret = mUI.init(rot);
+    //If source to rotator is FB, which is the case with UI Mirror pipe,
+    //we need to inform driver during playback, since FB does not use ION.
+    rot->setSrcFB();
     return ret;
 }
 inline bool UIMirrorPipe::close() { return mUI.close(); }
 inline bool UIMirrorPipe::commit() { return mUI.commit(); }
-inline void UIMirrorPipe::setId(int id) { mUI.setId(id); }
-inline void UIMirrorPipe::setMemoryId(int id) { mUI.setMemoryId(id); }
-inline bool UIMirrorPipe::queueBuffer(uint32_t offset) {
-    return mUI.queueBuffer(offset); }
-inline bool UIMirrorPipe::dequeueBuffer(void*& buf) {
-    return mUI.dequeueBuffer(buf); }
+inline bool UIMirrorPipe::queueBuffer(int fd, uint32_t offset) {
+    return mUI.queueBuffer(fd, offset);
+}
 inline bool UIMirrorPipe::waitForVsync() {
     return mUI.waitForVsync(); }
 inline bool UIMirrorPipe::setCrop(const utils::Dim& dim) {
     return mUI.setCrop(dim); }
-inline bool UIMirrorPipe::start(const utils::PipeArgs& args) {
-    if(!mUI.start(args)) {
-        ALOGE("%s failed to start", __FUNCTION__);
-        return false;
-    }
-    return true;
-}
-inline bool UIMirrorPipe::setPosition(const utils::Dim& dim) {
 
+inline bool UIMirrorPipe::setPosition(const utils::Dim& dim) {
     ovutils::Dim pdim;
-    switch (dim.o) {
-        case 0:
-        case HAL_TRANSFORM_ROT_180:
+    //using utils::eTransform;
+    switch (mPrimFBOr) {
+        case utils::OVERLAY_TRANSFORM_0:
+        case utils::OVERLAY_TRANSFORM_ROT_180:
             {
-                ovutils::Whf whf(dim.x, dim.y, 0);
+                ovutils::Whf whf(dim.w, dim.h, 0);
                 pdim = mUI.getAspectRatio(whf);
                 break;
             }
-        case HAL_TRANSFORM_ROT_90:
-        case HAL_TRANSFORM_ROT_270:
+        case utils::OVERLAY_TRANSFORM_ROT_90:
+        case utils::OVERLAY_TRANSFORM_ROT_270:
             {
                 // Calculate the Aspectratio for the UI in the landscape mode
                 // Width and height will be swapped as there is rotation
-                ovutils::Whf whf(dim.y, dim.x, 0);
+                ovutils::Whf whf(dim.h, dim.w, 0);
                 pdim = mUI.getAspectRatio(whf);
                 break;
             }
@@ -121,43 +108,43 @@
             ALOGE("%s: Unknown orientation %d", __FUNCTION__, dim.o);
             return false;
     }
-
-    ovutils::even_out(pdim.x);
-    ovutils::even_out(pdim.y);
-    ovutils::even_out(pdim.w);
-    ovutils::even_out(pdim.h);
     return mUI.setPosition(pdim);
 }
-inline bool UIMirrorPipe::setParameter(const utils::Params& param) {
 
-    OVASSERT(utils::OVERLAY_TRANSFORM_UI == param.param,
-            "%p Expecting OVERLAY_TRANSFORM_UI", __FUNCTION__);
+inline bool UIMirrorPipe::setTransform(const utils::eTransform& param) {
 
-    int orientation = param.value;
+    //Cache the primary FB orientation, since the TV's will be 0, we need this
+    //info to translate later.
+    mPrimFBOr = param;
+    utils::eTransform transform = param;
 
     // Figure out orientation to transform to
-    switch (param.value) {
-        case 0:
-            orientation = 0;
+    switch (param) {
+        case utils::OVERLAY_TRANSFORM_0:
+            transform = utils::OVERLAY_TRANSFORM_0;
             break;
-        case HAL_TRANSFORM_ROT_180:
-            orientation = HAL_TRANSFORM_ROT_180;
+        case utils::OVERLAY_TRANSFORM_ROT_180:
+        //If prim FB is drawn 180 rotated, rotate by additional 180 to make
+        //it to 0, which is TV's orientation.
+            transform = utils::OVERLAY_TRANSFORM_ROT_180;
             break;
-        case HAL_TRANSFORM_ROT_90:
-            orientation = HAL_TRANSFORM_ROT_270;
+        case utils::OVERLAY_TRANSFORM_ROT_90:
+        //If prim FB is drawn 90 rotated, rotate by additional 270 to make
+        //it to 0, which is TV's orientation.
+            transform = utils::OVERLAY_TRANSFORM_ROT_270;
             break;
-        case HAL_TRANSFORM_ROT_270:
-            orientation = HAL_TRANSFORM_ROT_90;
+        case utils::OVERLAY_TRANSFORM_ROT_270:
+        //If prim FB is drawn 270 rotated, rotate by additional 90 to make
+        //it to 0, which is TV's orientation.
+            transform = utils::OVERLAY_TRANSFORM_ROT_90;
             break;
         default:
-            ALOGE("%s: Unknown orientation %d", __FUNCTION__, param.value);
+            ALOGE("%s: Unknown orientation %d", __FUNCTION__,
+                    static_cast<int>(param));
             return false;
     }
 
-    ovutils::eTransform transform =
-            static_cast<ovutils::eTransform>(orientation);
-    const ovutils::Params prms (ovutils::OVERLAY_TRANSFORM, transform);
-    return mUI.setParameter(prms);
+    return mUI.setTransform(transform);
 }
 
 inline bool UIMirrorPipe::setSource(const utils::PipeArgs& args) {
@@ -175,9 +162,6 @@
 
     return mUI.setSource(arg);
 }
-inline const utils::PipeArgs& UIMirrorPipe::getArgs() const {
-    return mUI.getArgs();
-}
 inline utils::eOverlayPipeType UIMirrorPipe::getOvPipeType() const {
     return utils::OV_PIPE_TYPE_UI_MIRROR;
 }
diff --git a/liboverlay/pipes/overlayVideoExtPipe.h b/liboverlay/pipes/overlayVideoExtPipe.h
new file mode 100644
index 0000000..8196fe7
--- /dev/null
+++ b/liboverlay/pipes/overlayVideoExtPipe.h
@@ -0,0 +1,119 @@
+/*
+* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+*    * Redistributions of source code must retain the above copyright
+*      notice, this list of conditions and the following disclaimer.
+*    * Redistributions in binary form must reproduce the above
+*      copyright notice, this list of conditions and the following
+*      disclaimer in the documentation and/or other materials provided
+*      with the distribution.
+*    * Neither the name of Code Aurora Forum, Inc. nor the names of its
+*      contributors may be used to endorse or promote products derived
+*      from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+* ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef OVERLAY_VIDEO_EXT_PIPE_H
+#define OVERLAY_VIDEO_EXT_PIPE_H
+
+#include "overlayGenPipe.h"
+#include "overlayUtils.h"
+#include "overlayCtrlData.h"
+#include "overlayMdp.h"
+#include "overlayRotator.h"
+
+namespace overlay {
+
+/* A specific impl of GenericPipe
+* Whenever needed to have a pass through - we do it.
+* If there is a special need for a different behavior - do it here */
+class VideoExtPipe : utils::NoCopy {
+public:
+    /* Please look at overlayGenPipe.h for info */
+    explicit VideoExtPipe();
+    ~VideoExtPipe();
+    bool init(RotatorBase* rot);
+    bool close();
+    bool commit();
+    bool queueBuffer(int fd, uint32_t offset);
+    bool waitForVsync();
+    bool setCrop(const utils::Dim& dim);
+    bool setPosition(const utils::Dim& dim);
+    bool setTransform(const utils::eTransform& param);
+    bool setSource(const utils::PipeArgs& args);
+    utils::eOverlayPipeType getOvPipeType() const;
+    void dump() const;
+private:
+    overlay::GenericPipe<ovutils::EXTERNAL> mVideoExt;
+};
+
+//------------------Inlines -----------------------------
+
+inline VideoExtPipe::VideoExtPipe() {}
+inline VideoExtPipe::~VideoExtPipe() { close(); }
+inline bool VideoExtPipe::init(RotatorBase* rot) {
+    ALOGE_IF(DEBUG_OVERLAY, "VideoExtPipe init");
+    return mVideoExt.init(rot);
+}
+inline bool VideoExtPipe::close() { return mVideoExt.close(); }
+inline bool VideoExtPipe::commit() { return mVideoExt.commit(); }
+inline bool VideoExtPipe::queueBuffer(int fd, uint32_t offset) {
+    return mVideoExt.queueBuffer(fd, offset);
+}
+inline bool VideoExtPipe::waitForVsync() {
+    return mVideoExt.waitForVsync();
+}
+inline bool VideoExtPipe::setCrop(const utils::Dim& dim) {
+    return mVideoExt.setCrop(dim);
+}
+inline bool VideoExtPipe::setPosition(const utils::Dim& dim)
+{
+    utils::Dim d;
+    // Need to change dim to aspect ratio
+    if (utils::FrameBufferInfo::getInstance()->supportTrueMirroring()) {
+        // Use dim info to calculate aspect ratio for true UI mirroring
+        d = mVideoExt.getAspectRatio(dim);
+    } else {
+        // Use cached crop data to get aspect ratio
+        utils::Dim crop = mVideoExt.getCrop();
+        utils::Whf whf(crop.w, crop.h, 0);
+        d = mVideoExt.getAspectRatio(whf);
+    }
+    ALOGE_IF(DEBUG_OVERLAY, "Calculated aspect ratio for EXT: x=%d, y=%d, w=%d,"
+            "h=%d, o=%d",
+            d.x, d.y, d.w, d.h, d.o);
+    return mVideoExt.setPosition(d);
+}
+inline bool VideoExtPipe::setTransform(const utils::eTransform& param) {
+    return mVideoExt.setTransform(param);
+}
+inline bool VideoExtPipe::setSource(const utils::PipeArgs& args) {
+    utils::PipeArgs arg(args);
+    return mVideoExt.setSource(arg);
+}
+inline utils::eOverlayPipeType VideoExtPipe::getOvPipeType() const {
+    return utils::OV_PIPE_TYPE_VIDEO_EXT;
+}
+inline void VideoExtPipe::dump() const {
+    ALOGE("Video Ext Pipe");
+    mVideoExt.dump();
+}
+
+
+} // overlay
+
+#endif // OVERLAY_VIDEO_EXT_PIPE_H