hwc/overlay: Dynamic pipe tracking.

Remove state based pipe handling and make pipes tracked dynamically.
Add the configStart, configDone, nextPipe availablePipes APIs.
Remove setState API.

-configStart marks all pipes available.
-configDone garbage-collects unused pipe objects.
-nextPipe returns the index of next available pipe and create a corresponding
pipe object if not present
-availablePipes returns total of "unallocated" pipes. (Pipes could be allocated
but unused)

Changes in hwc adapt to the new overlay APIs.
Compile out MDP comp.
Remove unused files in overlay and hwc.
Update licenses.

Conflicts:

	libhwcomposer/hwc.cpp
	libhwcomposer/hwc_utils.cpp

Bug: 7626586
Change-Id: Id8e56901d34e5dc0fd088260d05e3e46f68ff090
Signed-off-by: Saurabh Shah <saurshah@codeaurora.org>
Signed-off-by: Iliyan Malchev <malchev@google.com>
diff --git a/liboverlay/Android.mk b/liboverlay/Android.mk
index 3c1057d..39244fd 100644
--- a/liboverlay/Android.mk
+++ b/liboverlay/Android.mk
@@ -14,7 +14,8 @@
       overlayUtils.cpp \
       overlayMdp.cpp \
       overlayRotator.cpp \
-      mdpRotator.cpp \
-      mdssRotator.cpp
+      overlayMdpRot.cpp \
+      overlayMdssRot.cpp \
+      pipes/overlayGenPipe.cpp
 
 include $(BUILD_SHARED_LIBRARY)
diff --git a/liboverlay/mdpWrapper.h b/liboverlay/mdpWrapper.h
index b1eb76c..255ffd7 100644
--- a/liboverlay/mdpWrapper.h
+++ b/liboverlay/mdpWrapper.h
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2011, Code Aurora Forum. All rights reserved.
+* Copyright (c) 2011, The Linux Foundation. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
@@ -10,7 +10,7 @@
 *      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
+*    * Neither the name of The Linux Foundation nor the names of its
 *      contributors may be used to endorse or promote products derived
 *      from this software without specific prior written permission.
 *
@@ -152,7 +152,7 @@
     return true;
 }
 
-inline bool endRotator(int fd, int sessionId) {
+inline bool endRotator(int fd, uint32_t sessionId) {
     if (ioctl(fd, MSM_ROTATOR_IOCTL_FINISH, &sessionId) < 0) {
         ALOGE("Failed to call ioctl MSM_ROTATOR_IOCTL_FINISH err=%s",
                 strerror(errno));
@@ -214,8 +214,12 @@
     dump("src", ov.src);
     dump("src_rect", ov.src_rect);
     dump("dst_rect", ov.dst_rect);
+    /*
+    Commented off to prevent verbose logging, since user_data could have 8 or so
+    fields which are mostly 0
     dump("user_data", ov.user_data,
             sizeof(ov.user_data)/sizeof(ov.user_data[0]));
+    */
 }
 inline void dump(const char* const s, const msmfb_img& ov) {
     ALOGE("%s msmfb_img w=%d h=%d format=%d %s",
@@ -239,7 +243,7 @@
     }
 }
 inline void dump(const char* const s, const msm_rotator_img_info& rot) {
-    ALOGE("%s msm_rotator_img_info sessid=%d dstx=%d dsty=%d rot=%d, ena=%d",
+    ALOGE("%s msm_rotator_img_info sessid=%u dstx=%d dsty=%d rot=%d, ena=%d",
             s, rot.session_id, rot.dst_x, rot.dst_y,
             rot.rotations, rot.enable);
     dump("src", rot.src);
@@ -247,7 +251,7 @@
     dump("src_rect", rot.src_rect);
 }
 inline void dump(const char* const s, const msm_rotator_data_info& rot) {
-    ALOGE("%s msm_rotator_data_info sessid=%d verkey=%d",
+    ALOGE("%s msm_rotator_data_info sessid=%u verkey=%d",
             s, rot.session_id, rot.version_key);
     dump("src", rot.src);
     dump("dst", rot.dst);
diff --git a/liboverlay/overlay.cpp b/liboverlay/overlay.cpp
index 170b8a9..7b7719c 100644
--- a/liboverlay/overlay.cpp
+++ b/liboverlay/overlay.cpp
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
+* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
@@ -10,7 +10,7 @@
 *      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
+*    * Neither the name of The Linux Foundation nor the names of its
 *      contributors may be used to endorse or promote products derived
 *      from this software without specific prior written permission.
 *
@@ -27,180 +27,202 @@
 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
-#include "overlayUtils.h"
-#include "overlayImpl.h"
 #include "overlay.h"
+#include "pipes/overlayGenPipe.h"
+#include "mdp_version.h"
 
-#include "overlayMdp.h"
-#include "overlayCtrlData.h"
+#define PIPE_DEBUG 0
 
 namespace overlay {
+using namespace utils;
 
-//Helper
-bool isStateValid(const utils::eOverlayState& st) {
-    switch (st) {
-        case utils::OV_CLOSED:
-            ALOGE("Overlay %s failed, state is OV_CLOSED; set state first",
-                    __FUNCTION__);
-            return false;
-            break;
-        case utils::OV_2D_VIDEO_ON_PANEL:
-        case utils::OV_2D_VIDEO_ON_PANEL_TV:
-        case utils::OV_2D_VIDEO_ON_TV:
-        case utils::OV_3D_VIDEO_ON_2D_PANEL:
-        case utils::OV_3D_VIDEO_ON_3D_PANEL:
-        case utils::OV_3D_VIDEO_ON_3D_TV:
-        case utils::OV_3D_VIDEO_ON_2D_PANEL_2D_TV:
-        case utils::OV_UI_MIRROR:
-        case utils::OV_2D_TRUE_UI_MIRROR:
-        case utils::OV_UI_VIDEO_TV:
-        case utils::OV_BYPASS_1_LAYER:
-        case utils::OV_BYPASS_2_LAYER:
-        case utils::OV_BYPASS_3_LAYER:
-        case utils::OV_DUAL_DISP:
-            break;
-        default:
-            OVASSERT(false, "%s Unknown state %d", __FUNCTION__, st);
-            return false;
+Overlay::Overlay() {
+    int numPipes = 0;
+    int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion();
+    if (mdpVersion > qdutils::MDP_V3_1) numPipes = 4;
+    if (mdpVersion >= qdutils::MDSS_V5) numPipes = 6;
+
+    PipeBook::NUM_PIPES = numPipes;
+    for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
+        mPipeBook[i].init();
     }
-    return true;
-}
 
-Overlay::Overlay(): mOv(0) {
+    mDumpStr[0] = '\0';
 }
 
 Overlay::~Overlay() {
-    mOv = mState.handleEvent(utils::OV_CLOSED, mOv);
-    delete mOv;
-    mOv = 0;
+    for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
+        mPipeBook[i].destroy();
+    }
 }
 
-bool Overlay::commit(utils::eDest dest)
-{
-    OVASSERT(mOv,
-            "%s Overlay and Rotator should be init at this point",
-            __FUNCTION__);
-    utils::eOverlayState st = mState.state();
-    if(isStateValid(st)) {
-        if(!mOv->commit(dest)) {
-            ALOGE("Overlay %s failed", __FUNCTION__);
-            return false;
+void Overlay::configBegin() {
+    for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
+        //Mark as available for this round.
+        PipeBook::resetUse(i);
+        PipeBook::resetAllocation(i);
+    }
+    mDumpStr[0] = '\0';
+}
+
+void Overlay::configDone() {
+    if(PipeBook::pipeUsageUnchanged()) return;
+
+    for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
+        if(PipeBook::isNotUsed(i)) {
+            //Forces UNSET on pipes, flushes rotator memory and session, closes
+            //fds
+            if(mPipeBook[i].valid()) {
+                char str[32];
+                sprintf(str, "Unset pipe=%s dpy=%d; ", getDestStr((eDest)i),
+                        mPipeBook[i].mDisplay);
+                strncat(mDumpStr, str, strlen(str));
+            }
+            mPipeBook[i].destroy();
         }
     }
-    return true;
+    dump();
+    PipeBook::save();
+}
+
+eDest Overlay::nextPipe(eMdpPipeType type, int dpy) {
+    eDest dest = OV_INVALID;
+
+    for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
+        //Match requested pipe type
+        if(type == OV_MDP_PIPE_ANY || type == getPipeType((eDest)i)) {
+            //If the pipe is not allocated to any display or used by the
+            //requesting display already in previous round.
+            if((mPipeBook[i].mDisplay == PipeBook::DPY_UNUSED ||
+                    mPipeBook[i].mDisplay == dpy) &&
+                    PipeBook::isNotAllocated(i)) {
+                dest = (eDest)i;
+                PipeBook::setAllocation(i);
+                break;
+            }
+        }
+    }
+
+    if(dest != OV_INVALID) {
+        int index = (int)dest;
+        //If the pipe is not registered with any display OR if the pipe is
+        //requested again by the same display using it, then go ahead.
+        mPipeBook[index].mDisplay = dpy;
+        if(not mPipeBook[index].valid()) {
+            mPipeBook[index].mPipe = new GenericPipe(dpy);
+            char str[32];
+            snprintf(str, 32, "Set pipe=%s dpy=%d; ", getDestStr(dest), dpy);
+            strncat(mDumpStr, str, strlen(str));
+        }
+    } else {
+        ALOGD_IF(PIPE_DEBUG, "Pipe unavailable type=%d display=%d",
+                (int)type, dpy);
+    }
+
+    return dest;
+}
+
+bool Overlay::commit(utils::eDest dest) {
+    bool ret = false;
+    int index = (int)dest;
+    validate(index);
+
+    if(mPipeBook[index].mPipe->commit()) {
+        ret = true;
+        PipeBook::setUse((int)dest);
+    } else {
+        PipeBook::resetUse((int)dest);
+    }
+    return ret;
 }
 
 bool Overlay::queueBuffer(int fd, uint32_t offset,
-        utils::eDest dest)
-{
-    OVASSERT(mOv,
-            "%s Overlay and Rotator should be init at this point",
-            __FUNCTION__);
-    utils::eOverlayState st = mState.state();
-    if(isStateValid(st)) {
-        if(!mOv->queueBuffer(fd, offset, dest)) {
-            ALOGE("Overlay %s failed", __FUNCTION__);
-            return false;
-        }
+        utils::eDest dest) {
+    int index = (int)dest;
+    bool ret = false;
+    validate(index);
+    //Queue only if commit() has succeeded (and the bit set)
+    if(PipeBook::isUsed((int)dest)) {
+        ret = mPipeBook[index].mPipe->queueBuffer(fd, offset);
     }
-    return true;
+    return ret;
 }
 
-bool Overlay::setCrop(const utils::Dim& d,
-        utils::eDest dest)
-{
-    OVASSERT(mOv,
-            "%s Overlay and Rotator should be init at this point",
-            __FUNCTION__);
-    utils::eOverlayState st = mState.state();
-    if(isStateValid(st)) {
-        if(!mOv->setCrop(d, dest)) {
-            ALOGE("Overlay %s failed", __FUNCTION__);
-            return false;
-        }
-    }
-    return true;
-}
-bool Overlay::setPosition(const utils::Dim& d,
-        utils::eDest dest)
-{
-    OVASSERT(mOv,
-            "%s Overlay and Rotator should be init at this point",
-            __FUNCTION__);
-    utils::eOverlayState st = mState.state();
-    if(isStateValid(st)) {
-        if(!mOv->setPosition(d, dest)) {
-            ALOGE("Overlay %s failed", __FUNCTION__);
-            return false;
-        }
-    }
-    return true;
+void Overlay::setCrop(const utils::Dim& d,
+        utils::eDest dest) {
+    int index = (int)dest;
+    validate(index);
+    mPipeBook[index].mPipe->setCrop(d);
 }
 
-bool Overlay::setTransform(const int orient,
-        utils::eDest dest)
-{
+void Overlay::setPosition(const utils::Dim& d,
+        utils::eDest dest) {
+    int index = (int)dest;
+    validate(index);
+    mPipeBook[index].mPipe->setPosition(d);
+}
+
+void Overlay::setTransform(const int orient,
+        utils::eDest dest) {
+    int index = (int)dest;
+    validate(index);
+
     utils::eTransform transform =
             static_cast<utils::eTransform>(orient);
+    mPipeBook[index].mPipe->setTransform(transform);
 
-    utils::eOverlayState st = mState.state();
-    if(isStateValid(st)) {
-        if(!mOv->setTransform(transform, dest)) {
-            ALOGE("Overlay %s failed", __FUNCTION__);
-            return false;
-        }
+}
+
+void Overlay::setSource(const utils::PipeArgs args,
+        utils::eDest dest) {
+    int index = (int)dest;
+    validate(index);
+
+    PipeArgs newArgs(args);
+    if(dest == OV_VG0 || dest == OV_VG1) {
+        setMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_SHARE);
+    } else {
+        clearMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_SHARE);
     }
-    return true;
+    mPipeBook[index].mPipe->setSource(newArgs);
 }
 
-bool Overlay::setSource(const utils::PipeArgs args[utils::MAX_PIPES],
-        utils::eDest dest)
-{
-    utils::PipeArgs margs[utils::MAX_PIPES] = {
-        args[0], args[1], args[2] };
-    utils::eOverlayState st = mState.state();
-
-    if(isStateValid(st)) {
-        if (!mOv->setSource(margs, dest)) {
-            ALOGE("Overlay %s failed", __FUNCTION__);
-            return false;
-        }
+Overlay* Overlay::getInstance() {
+    if(sInstance == NULL) {
+        sInstance = new Overlay();
     }
-    return true;
-}
-
-void Overlay::dump() const
-{
-    OVASSERT(mOv,
-            "%s Overlay and Rotator should be init at this point",
-            __FUNCTION__);
-    ALOGE("== Dump Overlay start ==");
-    mState.dump();
-    mOv->dump();
-    ALOGE("== Dump Overlay end ==");
-}
-
-void Overlay::setState(utils::eOverlayState s) {
-    mOv = mState.handleEvent(s, mOv);
-}
-
-utils::eOverlayState Overlay::getState() const {
-    return mState.state();
-}
-
-Overlay *Overlay::sInstance[] = {0};
-
-Overlay* Overlay::getInstance(int disp) {
-    if(sInstance[disp] == NULL) {
-        sInstance[disp] = new Overlay();
-    }
-    return sInstance[disp];
+    return sInstance;
 }
 
 void Overlay::initOverlay() {
     if(utils::initOverlay() == -1) {
-        ALOGE("utils::initOverlay() ERROR!!");
+        ALOGE("%s failed", __FUNCTION__);
     }
 }
 
-} // overlay
+void Overlay::dump() const {
+    if(strlen(mDumpStr)) { //dump only on state change
+        ALOGD("%s\n", mDumpStr);
+    }
+}
+
+void Overlay::PipeBook::init() {
+    mPipe = NULL;
+    mDisplay = DPY_UNUSED;
+}
+
+void Overlay::PipeBook::destroy() {
+    if(mPipe) {
+        delete mPipe;
+        mPipe = NULL;
+    }
+    mDisplay = DPY_UNUSED;
+}
+
+Overlay* Overlay::sInstance = 0;
+int Overlay::PipeBook::NUM_PIPES = 0;
+int Overlay::PipeBook::sPipeUsageBitmap = 0;
+int Overlay::PipeBook::sLastUsageBitmap = 0;
+int Overlay::PipeBook::sAllocatedBitmap = 0;
+
+}; // namespace overlay
diff --git a/liboverlay/overlay.h b/liboverlay/overlay.h
index f8f9c34..523e3f7 100644
--- a/liboverlay/overlay.h
+++ b/liboverlay/overlay.h
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
+* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
@@ -10,7 +10,7 @@
 *      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
+*    * Neither the name of The Linux Foundation. nor the names of its
 *      contributors may be used to endorse or promote products derived
 *      from this software without specific prior written permission.
 *
@@ -31,66 +31,174 @@
 #define OVERLAY_H
 
 #include "overlayUtils.h"
-#include "overlayState.h"
-#include "overlayImpl.h"
 
 namespace overlay {
-/**/
+class GenericPipe;
+
 class Overlay : utils::NoCopy {
 public:
     /* dtor close */
     ~Overlay();
 
-    /* Overlay related func */
+    /* Marks the beginning of a drawing round, resets usage bits on pipes
+     * Should be called when drawing begins before any pipe config is done.
+     */
+    void configBegin();
 
-    /* Following is the same as the pure virt interface in ov impl  */
+    /* Marks the end of config for this drawing round
+     * Will do garbage collection of pipe objects and thus calling UNSETs,
+     * closing FDs, removing rotator objects and memory, if allocated.
+     * Should be called after all pipe configs are done.
+     */
+    void configDone();
 
-    bool setSource(const utils::PipeArgs args[utils::MAX_PIPES],
-            utils::eDest dest = utils::OV_PIPE_ALL);
-    bool setCrop(const utils::Dim& d,
-            utils::eDest dest = utils::OV_PIPE_ALL);
-    bool setTransform(const int orientation,
-            utils::eDest dest = utils::OV_PIPE_ALL);
-    bool setPosition(const utils::Dim& dim,
-            utils::eDest dest = utils::OV_PIPE_ALL);
-    bool commit(utils::eDest dest = utils::OV_PIPE_ALL);
+    /* Returns an available pipe based on the type of pipe requested. When ANY
+     * is requested, the first available VG or RGB is returned. If no pipe is
+     * available for the display "dpy" then INV is returned. Note: If a pipe is
+     * assigned to a certain display, then it cannot be assigned to another
+     * display without being garbage-collected once */
+    utils::eDest nextPipe(utils::eMdpPipeType, int dpy);
 
-    bool queueBuffer(int fd, uint32_t offset,
-            utils::eDest dest = utils::OV_PIPE_ALL);
+    void setSource(const utils::PipeArgs args, utils::eDest dest);
+    void setCrop(const utils::Dim& d, utils::eDest dest);
+    void setTransform(const int orientation, utils::eDest dest);
+    void setPosition(const utils::Dim& dim, utils::eDest dest);
+    bool commit(utils::eDest dest);
+    bool queueBuffer(int fd, uint32_t offset, utils::eDest dest);
 
-    void dump() const;
-
-    /* state related functions */
-    void setState(utils::eOverlayState s);
-
-    /* expose state */
-    utils::eOverlayState getState() const;
-
-    /* Closes open pipes */
+    /* Closes open pipes, called during startup */
     static void initOverlay();
-
-    /* Returns the per-display singleton instance of overlay */
-    static Overlay* getInstance(int disp);
+    /* Returns the singleton instance of overlay */
+    static Overlay* getInstance();
+    /* Returns total of available ("unallocated") pipes */
+    static int availablePipes();
 
 private:
     /* Ctor setup */
-    Overlay();
+    explicit Overlay();
+    /*Validate index range, abort if invalid */
+    void validate(int index);
+    void dump() const;
 
-    /* reset all pointers */
-    void reset();
+    /* Just like a Facebook for pipes, but much less profile info */
+    struct PipeBook {
+        enum { DPY_PRIMARY, DPY_EXTERNAL, DPY_UNUSED };
 
-    /* Holds the state, state transition logic
-     * In the meantime, using simple enum rather than
-     * a class */
-    OverlayState mState;
+        void init();
+        void destroy();
+        /* Check if pipe exists and return true, false otherwise */
+        bool valid();
 
-    /* Holds the actual overlay impl, set when changing state*/
-    OverlayImplBase *mOv;
+        /* Hardware pipe wrapper */
+        GenericPipe *mPipe;
+        /* Display using this pipe. Refer to enums above */
+        int mDisplay;
 
-    /* Per-display Singleton Instance HWC_NUM_DISPLAY_TYPES */
-    static Overlay *sInstance[2];
+        /* operations on bitmap */
+        static bool pipeUsageUnchanged();
+        static void setUse(int index);
+        static void resetUse(int index);
+        static bool isUsed(int index);
+        static bool isNotUsed(int index);
+        static void save();
+
+        static void setAllocation(int index);
+        static void resetAllocation(int index);
+        static bool isAllocated(int index);
+        static bool isNotAllocated(int index);
+        /* Returns total of available ("unallocated") pipes */
+        static int availablePipes();
+
+        static int NUM_PIPES;
+
+    private:
+        //usage tracks if a successful commit happened. So a pipe could be
+        //allocated to a display, but it may not end up using it for various
+        //reasons. If one display actually uses a pipe then it amy not be
+        //used by another display, without an UNSET in between.
+        static int sPipeUsageBitmap;
+        static int sLastUsageBitmap;
+        //Tracks which pipe objects are allocated. This does not imply that they
+        //will actually be used. For example, a display might choose to acquire
+        //3 pipe objects in one shot and proceed with config only if it gets all
+        //3. The bitmap helps allocate different pipe objects on each request.
+        static int sAllocatedBitmap;
+    };
+
+    PipeBook mPipeBook[utils::OV_INVALID]; //Used as max
+
+    /* Dump string */
+    char mDumpStr[256];
+
+    /* Singleton Instance*/
+    static Overlay *sInstance;
 };
 
-} // overlay
+inline void Overlay::validate(int index) {
+    OVASSERT(index >=0 && index < PipeBook::NUM_PIPES, \
+        "%s, Index out of bounds: %d", __FUNCTION__, index);
+    OVASSERT(mPipeBook[index].valid(), "Pipe does not exist %s",
+            utils::getDestStr((utils::eDest)index));
+}
+
+inline int Overlay::availablePipes() {
+    return PipeBook::availablePipes();
+}
+
+inline int Overlay::PipeBook::availablePipes() {
+    int used = 0;
+    int bmp = sAllocatedBitmap;
+    for(; bmp; used++) {
+        //clearing from lsb
+        bmp = bmp & (bmp - 1);
+    }
+    return NUM_PIPES - used;
+}
+
+inline bool Overlay::PipeBook::valid() {
+    return (mPipe != NULL);
+}
+
+inline bool Overlay::PipeBook::pipeUsageUnchanged() {
+    return (sPipeUsageBitmap == sLastUsageBitmap);
+}
+
+inline void Overlay::PipeBook::setUse(int index) {
+    sPipeUsageBitmap |= (1 << index);
+}
+
+inline void Overlay::PipeBook::resetUse(int index) {
+    sPipeUsageBitmap &= ~(1 << index);
+}
+
+inline bool Overlay::PipeBook::isUsed(int index) {
+    return sPipeUsageBitmap & (1 << index);
+}
+
+inline bool Overlay::PipeBook::isNotUsed(int index) {
+    return !isUsed(index);
+}
+
+inline void Overlay::PipeBook::save() {
+    sLastUsageBitmap = sPipeUsageBitmap;
+}
+
+inline void Overlay::PipeBook::setAllocation(int index) {
+    sAllocatedBitmap |= (1 << index);
+}
+
+inline void Overlay::PipeBook::resetAllocation(int index) {
+    sAllocatedBitmap &= ~(1 << index);
+}
+
+inline bool Overlay::PipeBook::isAllocated(int index) {
+    return sAllocatedBitmap & (1 << index);
+}
+
+inline bool Overlay::PipeBook::isNotAllocated(int index) {
+    return !isAllocated(index);
+}
+
+}; // overlay
 
 #endif // OVERLAY_H
diff --git a/liboverlay/overlayCtrl.cpp b/liboverlay/overlayCtrl.cpp
index 9047f3e..ac4a296 100644
--- a/liboverlay/overlayCtrl.cpp
+++ b/liboverlay/overlayCtrl.cpp
@@ -77,129 +77,8 @@
 
 utils::ActionSafe* utils::ActionSafe::sActionSafe = NULL;
 
-utils::Dim Ctrl::getAspectRatio(const utils::Whf& whf) const
-{
-    utils::Whf inWhf(whf.w, whf.h, mMdp.getSrcWhf().format);
-    utils::Whf tmpwhf(inWhf);
-    uint32_t fbWidth  = mInfo.mFBWidth;
-    uint32_t fbHeight = mInfo.mFBHeight;
-
-    /* Calculate the width and height if it is YUV TILE format*/
-    if (inWhf.format == HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED) {
-        tmpwhf.w = whf.w - (utils::alignup(whf.w, 64) - whf.w);
-        tmpwhf.h = whf.h - (utils::alignup(whf.h, 32) - whf.h);
-    }
-    if (inWhf.w * fbHeight > fbWidth * inWhf.h) {
-        inWhf.h = fbWidth * inWhf.h / inWhf.w;
-        inWhf.w = fbWidth;
-    } else if (inWhf.w * fbHeight < fbWidth * inWhf.h) {
-        inWhf.w = fbHeight * inWhf.w / inWhf.h;
-        inWhf.h = fbHeight;
-    } else {
-        inWhf.w = fbWidth;
-        inWhf.h = fbHeight;
-    }
-    /* Scaling of upto a max of 8 times supported */
-    if (inWhf.w > (tmpwhf.w * utils::HW_OV_MAGNIFICATION_LIMIT)){
-        inWhf.w = utils::HW_OV_MAGNIFICATION_LIMIT * tmpwhf.w;
-    }
-    if(inWhf.h > (tmpwhf.h * utils::HW_OV_MAGNIFICATION_LIMIT)) {
-        inWhf.h = utils::HW_OV_MAGNIFICATION_LIMIT * tmpwhf.h;
-    }
-    if (inWhf.w > fbWidth) inWhf.w = fbWidth;
-    if (inWhf.h > fbHeight) inWhf.h = fbHeight;
-
-    float asWidth = utils::ActionSafe::getInstance()->getHeight();
-    float asHeight = utils::ActionSafe::getInstance()->getWidth();
-
-    inWhf.w = inWhf.w * (1.0f - asWidth / 100.0f);
-    inWhf.h = inWhf.h * (1.0f - asHeight / 100.0f);
-
-    uint32_t x = (fbWidth - inWhf.w) / 2.0;
-    uint32_t y = (fbHeight - inWhf.h) / 2.0;
-    return utils::Dim(x, y, inWhf.w, inWhf.h);
-}
-
 utils::FrameBufferInfo* utils::FrameBufferInfo::sFBInfoInstance = 0;
 
-// This function gets the destination position for external display
-// based on the position and aspect ratio of the primary
-utils::Dim Ctrl::getAspectRatio(const utils::Dim& dim) const {
-    float priWidth  = utils::FrameBufferInfo::getInstance()->getWidth();
-    float priHeight = utils::FrameBufferInfo::getInstance()->getHeight();
-    float fbWidth = mInfo.mFBWidth;
-    float fbHeight = mInfo.mFBHeight;
-    float wRatio = 1.0;
-    float hRatio = 1.0;
-    float xRatio = 1.0;
-    float yRatio = 1.0;
-    utils::Dim inDim(dim);
-
-    int xPos = 0;
-    int yPos = 0;
-    int tmp = 0;
-    utils::Dim tmpDim;
-    switch(inDim.o) {
-        case MDP_ROT_NOP:
-        case MDP_ROT_180:
-            {
-                utils::Whf whf((uint32_t) priWidth, (uint32_t) priHeight, 0);
-                tmpDim = getAspectRatio(whf);
-                xPos = tmpDim.x;
-                yPos = tmpDim.y;
-                fbWidth = tmpDim.w;
-                fbHeight = tmpDim.h;
-
-                if (inDim.o == MDP_ROT_180) {
-                    inDim.x = priWidth - (inDim.x + inDim.w);
-                    inDim.y = priHeight - (inDim.y + inDim.h);
-                }
-                break;
-            }
-        case MDP_ROT_90:
-        case MDP_ROT_270:
-            {
-                if(inDim.o == MDP_ROT_90) {
-                    tmp = inDim.y;
-                    inDim.y = priWidth - (inDim.x + inDim.w);
-                    inDim.x = tmp;
-                }
-                else if (inDim.o == MDP_ROT_270) {
-                    tmp = inDim.x;
-                    inDim.x = priHeight - (inDim.y + inDim.h);
-                    inDim.y = tmp;
-                }
-
-                // Swap the destination width/height
-                utils::swapWidthHeight(inDim.w, inDim.h);
-                // Swap width/height for primary
-                utils::swapWidthHeight(priWidth, priHeight);
-                utils::Whf whf((uint32_t) priWidth, (uint32_t) priHeight, 0);
-                tmpDim = getAspectRatio(whf);
-                xPos = tmpDim.x;
-                yPos = tmpDim.y;
-                fbWidth = tmpDim.w;
-                fbHeight = tmpDim.h;
-                break;
-            }
-        default:
-            ALOGE("%s: Unknown Orientation", __FUNCTION__);
-            break;
-    }
-
-    // Calculate the position
-    xRatio = inDim.x/priWidth;
-    yRatio = inDim.y/priHeight;
-    wRatio = inDim.w/priWidth;
-    hRatio = inDim.h/priHeight;
-
-    return utils::Dim((xRatio * fbWidth) + xPos,   // x
-            (yRatio * fbHeight) + yPos,  // y
-            (wRatio * fbWidth),          // width
-            (hRatio * fbHeight),         // height
-            inDim.o);                    // orientation
-}
-
 void Ctrl::dump() const {
     ALOGE("== Dump Ctrl start ==");
     mInfo.dump("mInfo");
diff --git a/liboverlay/overlayCtrlData.h b/liboverlay/overlayCtrlData.h
index 3c7eb42..f4c95f9 100644
--- a/liboverlay/overlayCtrlData.h
+++ b/liboverlay/overlayCtrlData.h
@@ -72,8 +72,6 @@
     int  getPipeId() const;
     /* ctrl fd */
     int  getFd() const;
-    utils::Dim getAspectRatio(const utils::Whf& whf) const;
-    utils::Dim getAspectRatio(const utils::Dim& dim) const;
 
     /* access for screen info */
     utils::ScreenInfo getScreenInfo() const;
diff --git a/liboverlay/overlayImpl.h b/liboverlay/overlayImpl.h
deleted file mode 100644
index 1d22694..0000000
--- a/liboverlay/overlayImpl.h
+++ /dev/null
@@ -1,634 +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_IMPL_H
-#define OVERLAY_IMPL_H
-
-#include "overlayUtils.h"
-#include "overlayRotator.h"
-
-namespace overlay {
-
-// Interface only. No member, no definiton (except ~ which can
-// also be =0 with impl in cpp)
-class OverlayImplBase {
-public:
-    /* empty dtor. can be =0 with cpp impl*/
-    virtual ~OverlayImplBase() {}
-
-    /* Init pipe/rot for one dest */
-    virtual bool initPipe(RotatorBase* rot, utils::eDest dest) = 0;
-
-    /* Close pipe/rot for all specified dest */
-    virtual bool closePipe(utils::eDest dest) = 0;
-
-    /* Copy specified pipe/rot from ov passed in (used by state machine only) */
-    virtual bool copyOvPipe(OverlayImplBase* ov, utils::eDest dest) = 0;
-
-    /* Init all pipes
-     * To init just one pipe, use initPipe()
-     * */
-    virtual bool init(RotatorBase* rot0,
-            RotatorBase* rot1,
-            RotatorBase* rot2) = 0;
-
-    /* Close all pipes
-     * To close just one pipe, use closePipe()
-     * */
-    virtual bool close() = 0;
-
-    /*
-     * Commit changes to the overlay
-     * */
-    virtual bool commit(utils::eDest dest = utils::OV_PIPE_ALL) = 0;
-
-    /* Queue buffer with fd from an offset*/
-    virtual bool queueBuffer(int fd, uint32_t offset,
-            utils::eDest dest = utils::OV_PIPE_ALL) = 0;
-
-    /* Crop existing destination using Dim coordinates */
-    virtual bool setCrop(const utils::Dim& d,
-            utils::eDest dest = utils::OV_PIPE_ALL) = 0;
-
-    /* Set new position using Dim */
-    virtual bool setPosition(const utils::Dim& dim,
-            utils::eDest dest = utils::OV_PIPE_ALL) = 0;
-
-    /* Set parameters - usually needed for Rotator, but would
-     * be passed down the stack as well */
-    virtual bool setTransform(const utils::eTransform& param,
-            utils::eDest dest = utils::OV_PIPE_ALL) = 0;
-
-    /* Set new source including orientation */
-    virtual bool setSource(const utils::PipeArgs[utils::MAX_PIPES],
-            utils::eDest dest = utils::OV_PIPE_ALL) = 0;
-
-    /* Dump underlying state */
-    virtual void dump() const = 0;
-};
-
-class NullPipe {
-public:
-    bool init(RotatorBase* rot) { return true; }
-    bool close() { return true; }
-    bool start(const utils::PipeArgs& args) { return true; }
-    bool commit() { return true; }
-    bool setCrop(const utils::Dim& d) { return true; }
-    bool setPosition(const utils::Dim& dim) { return true; }
-    bool setTransform(const utils::eTransform& param) { return true; }
-    bool setSource(const utils::PipeArgs& args) { return true; }
-    bool queueBuffer(int fd, uint32_t offset) { return true; }
-    void dump() const {}
-};
-
-/*
-* Each pipe is not specific to a display (primary/external). The order in the
-* template params, will setup the priorities of the pipes.
-* */
-template <class P0, class P1=NullPipe, class P2=NullPipe>
-class OverlayImpl : public OverlayImplBase {
-public:
-    typedef P0 pipe0;
-    typedef P1 pipe1;
-    typedef P2 pipe2;
-
-    /* ctor */
-    OverlayImpl();
-
-    /*
-     * Comments of the below functions are the same as the one
-     * in OverlayImplBase.
-     * */
-    virtual ~OverlayImpl();
-
-    virtual bool initPipe(RotatorBase* rot, utils::eDest dest);
-    virtual bool closePipe(utils::eDest dest);
-    virtual bool copyOvPipe(OverlayImplBase* ov, utils::eDest dest);
-
-    virtual bool init(RotatorBase* rot0,
-            RotatorBase* rot1,
-            RotatorBase* rot2);
-    virtual bool close();
-    virtual bool commit(utils::eDest dest = utils::OV_PIPE_ALL);
-    virtual bool setCrop(const utils::Dim& d,
-            utils::eDest dest = utils::OV_PIPE_ALL);
-    virtual bool setPosition(const utils::Dim& dim,
-            utils::eDest dest = utils::OV_PIPE_ALL);
-    virtual bool setTransform(const utils::eTransform& param,
-            utils::eDest dest = utils::OV_PIPE_ALL);
-    virtual bool setSource(const utils::PipeArgs[utils::MAX_PIPES],
-            utils::eDest dest = utils::OV_PIPE_ALL);
-    virtual bool queueBuffer(int fd, uint32_t offset,
-            utils::eDest dest = utils::OV_PIPE_ALL);
-    virtual void dump() const;
-
-private:
-    P0* mPipe0;
-    P1* mPipe1;
-    P2* mPipe2;
-    // More Px here in the future as needed
-
-    /*  */
-
-    /* Each Px has it's own Rotator here.
-     * will pass rotator to the lower layer in stack
-     * but only overlay is allowed to control the lifetime
-     * of the rotator instace */
-    RotatorBase* mRotP0;
-    RotatorBase* mRotP1;
-    RotatorBase* mRotP2;
-};
-
-
-
-//-----------Inlines and Template defn---------------------------------
-
-/**** OverlayImpl ****/
-
-template <class P0, class P1, class P2>
-OverlayImpl<P0, P1, P2>::OverlayImpl() :
-    mPipe0(0), mPipe1(0), mPipe2(0),
-    mRotP0(0), mRotP1(0), mRotP2(0)
-{
-    //Do not create a pipe here.
-    //Either initPipe can create a pipe OR
-    //copyOvPipe can assign a pipe.
-}
-
-template <class P0, class P1, class P2>
-OverlayImpl<P0, P1, P2>::~OverlayImpl()
-{
-    //Do not delete pipes.
-    //closePipe will close and delete.
-}
-
-/* Init only one pipe/rot pair per call */
-template <class P0, class P1, class P2>
-bool OverlayImpl<P0, P1, P2>::initPipe(RotatorBase* rot, utils::eDest dest)
-{
-    OVASSERT(rot, "%s: OverlayImpl rot is null", __FUNCTION__);
-    OVASSERT(utils::isValidDest(dest), "%s: OverlayImpl invalid dest=%d",
-            __FUNCTION__, dest);
-
-    bool ret = true;
-
-    if (utils::OV_PIPE0 & dest) {
-        ALOGE_IF(DEBUG_OVERLAY, "init pipe0");
-
-        mRotP0 = rot;
-        ret = mRotP0->init();
-        if(!ret) {
-            ALOGE("%s: OverlayImpl rot0 failed to init", __FUNCTION__);
-            return false;
-        }
-
-        mPipe0 = new P0();
-        OVASSERT(mPipe0, "%s: OverlayImpl pipe0 is null", __FUNCTION__);
-        ret = mPipe0->init(rot);
-        if(!ret) {
-            ALOGE("%s: OverlayImpl pipe0 failed to init", __FUNCTION__);
-            return false;
-        }
-
-        return ret;
-    }
-
-    if (utils::OV_PIPE1 & dest) {
-        ALOGE_IF(DEBUG_OVERLAY, "init pipe1");
-
-        mRotP1 = rot;
-        ret = mRotP1->init();
-        if(!ret) {
-            ALOGE("%s: OverlayImpl rot1 failed to init", __FUNCTION__);
-            return false;
-        }
-
-        mPipe1 = new P1();
-        OVASSERT(mPipe1, "%s: OverlayImpl pipe1 is null", __FUNCTION__);
-        ret = mPipe1->init(rot);
-        if(!ret) {
-            ALOGE("%s: OverlayImpl pipe1 failed to init", __FUNCTION__);
-            return false;
-        }
-
-        return ret;
-    }
-
-    if (utils::OV_PIPE2 & dest) {
-        ALOGE_IF(DEBUG_OVERLAY, "init pipe2");
-
-        mRotP2 = rot;
-        ret = mRotP2->init();
-        if(!ret) {
-            ALOGE("%s: OverlayImpl rot2 failed to init", __FUNCTION__);
-            return false;
-        }
-
-        mPipe2 = new P2();
-        OVASSERT(mPipe2, "%s: OverlayImpl pipe2 is null", __FUNCTION__);
-        ret = mPipe2->init(rot);
-        if(!ret) {
-            ALOGE("%s: OverlayImpl pipe2 failed to init", __FUNCTION__);
-            return false;
-        }
-
-        return ret;
-    }
-
-    // Should have returned by here
-    return false;
-}
-
-/* Close pipe/rot for all specified dest */
-template <class P0, class P1, class P2>
-bool OverlayImpl<P0, P1, P2>::closePipe(utils::eDest dest)
-{
-    OVASSERT(utils::isValidDest(dest), "%s: OverlayImpl invalid dest=%d",
-            __FUNCTION__, dest);
-
-    if (utils::OV_PIPE0 & dest) {
-        // Close pipe0
-        OVASSERT(mPipe0, "%s: OverlayImpl pipe0 is null", __FUNCTION__);
-        ALOGE_IF(DEBUG_OVERLAY, "Close pipe0");
-        if (!mPipe0->close()) {
-            ALOGE("%s: OverlayImpl failed to close pipe0", __FUNCTION__);
-            return false;
-        }
-        delete mPipe0;
-        mPipe0 = 0;
-
-        // Close the rotator for pipe0
-        OVASSERT(mRotP0, "%s: OverlayImpl rot0 is null", __FUNCTION__);
-        if (!mRotP0->close()) {
-            ALOGE("%s: OverlayImpl failed to close rot for pipe0", __FUNCTION__);
-        }
-        delete mRotP0;
-        mRotP0 = 0;
-    }
-
-    if (utils::OV_PIPE1 & dest) {
-        // Close pipe1
-        OVASSERT(mPipe1, "%s: OverlayImpl pipe1 is null", __FUNCTION__);
-        ALOGE_IF(DEBUG_OVERLAY, "Close pipe1");
-        if (!mPipe1->close()) {
-            ALOGE("%s: OverlayImpl failed to close pipe1", __FUNCTION__);
-            return false;
-        }
-        delete mPipe1;
-        mPipe1 = 0;
-
-        // Close the rotator for pipe1
-        OVASSERT(mRotP1, "%s: OverlayImpl rot1 is null", __FUNCTION__);
-        if (!mRotP1->close()) {
-            ALOGE("%s: OverlayImpl failed to close rot for pipe1", __FUNCTION__);
-        }
-        delete mRotP1;
-        mRotP1 = 0;
-    }
-
-    if (utils::OV_PIPE2 & dest) {
-        // Close pipe2
-        OVASSERT(mPipe2, "%s: OverlayImpl pipe2 is null", __FUNCTION__);
-        ALOGE_IF(DEBUG_OVERLAY, "Close pipe2");
-        if (!mPipe2->close()) {
-            ALOGE("%s: OverlayImpl failed to close pipe2", __FUNCTION__);
-            return false;
-        }
-        delete mPipe2;
-        mPipe2 = 0;
-
-        // Close the rotator for pipe2
-        OVASSERT(mRotP2, "%s: OverlayImpl rot2 is null", __FUNCTION__);
-        if (!mRotP2->close()) {
-            ALOGE("%s: OverlayImpl failed to close rot for pipe2", __FUNCTION__);
-        }
-        delete mRotP2;
-        mRotP2 = 0;
-    }
-
-    return true;
-}
-
-/* Copy pipe/rot from ov for all specified dest */
-template <class P0, class P1, class P2>
-bool OverlayImpl<P0, P1, P2>::copyOvPipe(OverlayImplBase* ov,
-        utils::eDest dest)
-{
-    OVASSERT(ov, "%s: OverlayImpl ov is null", __FUNCTION__);
-    OVASSERT(utils::isValidDest(dest), "%s: OverlayImpl invalid dest=%d",
-            __FUNCTION__, dest);
-
-    OverlayImpl<P0, P1, P2>* ovimpl = static_cast<OverlayImpl<P0, P1, P2>*>(ov);
-
-    if (utils::OV_PIPE0 & dest) {
-        mPipe0 = ovimpl->mPipe0;
-        mRotP0 = ovimpl->mRotP0;
-        ovimpl->mPipe0 = 0;
-        ovimpl->mRotP0 = 0;
-    }
-
-    if (utils::OV_PIPE1 & dest) {
-        mPipe1 = ovimpl->mPipe1;
-        mRotP1 = ovimpl->mRotP1;
-        ovimpl->mPipe1 = 0;
-        ovimpl->mRotP1 = 0;
-    }
-
-    if (utils::OV_PIPE2 & dest) {
-        mPipe2 = ovimpl->mPipe2;
-        mRotP2 = ovimpl->mRotP2;
-        ovimpl->mPipe2 = 0;
-        ovimpl->mRotP2 = 0;
-    }
-
-    return true;
-}
-
-/* Init all pipes/rot */
-template <class P0, class P1, class P2>
-bool OverlayImpl<P0, P1, P2>::init(RotatorBase* rot0,
-        RotatorBase* rot1,
-        RotatorBase* rot2)
-{
-    if (!this->initPipe(rot0, utils::OV_PIPE0)) {
-        if (!this->close()) {
-            ALOGE("%s: failed to close at least one pipe", __FUNCTION__);
-        }
-        return false;
-    }
-
-    if (!this->initPipe(rot1, utils::OV_PIPE1)) {
-        if (!this->close()) {
-            ALOGE("%s: failed to close at least one pipe", __FUNCTION__);
-        }
-        return false;
-    }
-
-    if (!this->initPipe(rot2, utils::OV_PIPE2)) {
-        if (!this->close()) {
-            ALOGE("%s: failed to close at least one pipe", __FUNCTION__);
-        }
-        return false;
-    }
-
-    return true;
-}
-
-/* Close all pipes/rot */
-template <class P0, class P1, class P2>
-bool OverlayImpl<P0, P1, P2>::close()
-{
-    if (!this->closePipe(utils::OV_PIPE_ALL)) {
-        return false;
-    }
-
-    return true;
-}
-
-template <class P0, class P1, class P2>
-bool OverlayImpl<P0, P1, P2>::commit(utils::eDest dest)
-{
-    OVASSERT(mPipe0 && mPipe1 && mPipe2,
-            "%s: Pipes are null p0=%p p1=%p p2=%p",
-            __FUNCTION__, mPipe0, mPipe1, mPipe2);
-
-    if (utils::OV_PIPE0 & dest) {
-        if(!mPipe0->commit()) {
-            ALOGE("OverlayImpl p0 failed to commit");
-            return false;
-        }
-    }
-
-    if (utils::OV_PIPE1 & dest) {
-        if(!mPipe1->commit()) {
-            ALOGE("OverlayImpl p1 failed to commit");
-            return false;
-        }
-    }
-
-    if (utils::OV_PIPE2 & dest) {
-        if(!mPipe2->commit()) {
-            ALOGE("OverlayImpl p2 failed to commit");
-            return false;
-        }
-    }
-
-    return true;
-}
-
-template <class P0, class P1, class P2>
-bool OverlayImpl<P0, P1, P2>::setCrop(const utils::Dim& d, utils::eDest dest)
-{
-    OVASSERT(mPipe0 && mPipe1 && mPipe2,
-            "%s: Pipes are null p0=%p p1=%p p2=%p",
-            __FUNCTION__, mPipe0, mPipe1, mPipe2);
-
-    if (utils::OV_PIPE0 & dest) {
-        if(!mPipe0->setCrop(d)) {
-            ALOGE("OverlayImpl p0 failed to crop");
-            return false;
-        }
-    }
-
-    if (utils::OV_PIPE1 & dest) {
-        if(!mPipe1->setCrop(d)) {
-            ALOGE("OverlayImpl p1 failed to crop");
-            return false;
-        }
-    }
-
-    if (utils::OV_PIPE2 & dest) {
-        if(!mPipe2->setCrop(d)) {
-            ALOGE("OverlayImpl p2 failed to crop");
-            return false;
-        }
-    }
-
-    return true;
-}
-
-template <class P0, class P1, class P2>
-bool OverlayImpl<P0, P1, P2>::setPosition(const utils::Dim& d,
-        utils::eDest dest)
-{
-    OVASSERT(mPipe0 && mPipe1 && mPipe2,
-            "%s: Pipes are null p0=%p p1=%p p2=%p",
-            __FUNCTION__, mPipe0, mPipe1, mPipe2);
-
-    if (utils::OV_PIPE0 & dest) {
-        if(!mPipe0->setPosition(d)) {
-            ALOGE("OverlayImpl p0 failed to setpos");
-            return false;
-        }
-    }
-
-    if (utils::OV_PIPE1 & dest) {
-        if(!mPipe1->setPosition(d)) {
-            ALOGE("OverlayImpl p1 failed to setpos");
-            return false;
-        }
-    }
-
-    if (utils::OV_PIPE2 & dest) {
-        if(!mPipe2->setPosition(d)) {
-            ALOGE("OverlayImpl p2 failed to setpos");
-            return false;
-        }
-    }
-
-    return true;
-}
-
-template <class P0, class P1, class P2>
-bool OverlayImpl<P0, P1, P2>::setTransform(const utils::eTransform& param,
-        utils::eDest dest)
-{
-    OVASSERT(mPipe0 && mPipe1 && mPipe2,
-            "%s: Pipes are null p0=%p p1=%p p2=%p",
-            __FUNCTION__, mPipe0, mPipe1, mPipe2);
-
-    if (utils::OV_PIPE0 & dest) {
-        if(!mPipe0->setTransform(param)) {
-            ALOGE("OverlayImpl p0 failed to setparam");
-            return false;
-        }
-    }
-
-    if (utils::OV_PIPE1 & dest) {
-        if(!mPipe1->setTransform(param)) {
-            ALOGE("OverlayImpl p1 failed to setparam");
-            return false;
-        }
-    }
-
-    if (utils::OV_PIPE2 & dest) {
-        if(!mPipe2->setTransform(param)) {
-            ALOGE("OverlayImpl p2 failed to setparam");
-            return false;
-        }
-    }
-
-    return true;
-}
-
-template <class P0, class P1, class P2>
-bool OverlayImpl<P0, P1, P2>::setSource(
-        const utils::PipeArgs args[utils::MAX_PIPES],
-        utils::eDest dest)
-{
-    OVASSERT(mPipe0 && mPipe1 && mPipe2,
-            "%s: Pipes are null p0=%p p1=%p p2=%p",
-            __FUNCTION__, mPipe0, mPipe1, mPipe2);
-
-    if (utils::OV_PIPE0 & dest) {
-        if(!mPipe0->setSource(args[0])) {
-            ALOGE("OverlayImpl p0 failed to setsrc");
-            return false;
-        }
-    }
-
-    if (utils::OV_PIPE1 & dest) {
-        if(!mPipe1->setSource(args[1])) {
-            ALOGE("OverlayImpl p1 failed to setsrc");
-            return false;
-        }
-    }
-
-    if (utils::OV_PIPE2 & dest) {
-        if(!mPipe2->setSource(args[2])) {
-            ALOGE("OverlayImpl p2 failed to setsrc");
-            return false;
-        }
-    }
-
-    return true;
-}
-
-template <class P0, class P1, class P2>
-bool OverlayImpl<P0, P1, P2>::queueBuffer(int fd, uint32_t offset,
-        utils::eDest dest)
-{
-    OVASSERT(mPipe0 && mPipe1 && mPipe2,
-            "%s: Pipes are null p0=%p p1=%p p2=%p",
-            __FUNCTION__, mPipe0, mPipe1, mPipe2);
-
-    if (utils::OV_PIPE0 & dest) {
-        if(!mPipe0->queueBuffer(fd, offset)) {
-            ALOGE("OverlayImpl p0 failed to queueBuffer");
-            return false;
-        }
-    }
-
-    if (utils::OV_PIPE1 & dest) {
-        if(!mPipe1->queueBuffer(fd, offset)) {
-            ALOGE("OverlayImpl p1 failed to queueBuffer");
-            return false;
-        }
-    }
-
-    if (utils::OV_PIPE2 & dest) {
-        if(!mPipe2->queueBuffer(fd, offset)) {
-            ALOGE("OverlayImpl p2 failed to queueBuffer");
-            return false;
-        }
-    }
-
-    return true;
-}
-
-template <class P0, class P1, class P2>
-void OverlayImpl<P0, P1, P2>::dump() const
-{
-    OVASSERT(mPipe0 && mPipe1 && mPipe2,
-            "%s: Pipes are null p0=%p p1=%p p2=%p",
-            __FUNCTION__, mPipe0, mPipe1, mPipe2);
-    ALOGE("== Dump OverlayImpl dump start ROT p0 ==");
-    mRotP0->dump();
-    ALOGE("== Dump OverlayImpl dump end ROT p0 ==");
-    ALOGE("== Dump OverlayImpl dump start ROT p1 ==");
-    mRotP1->dump();
-    ALOGE("== Dump OverlayImpl dump end ROT p1 ==");
-    ALOGE("== Dump OverlayImpl dump start ROT p2 ==");
-    mRotP2->dump();
-    ALOGE("== Dump OverlayImpl dump end ROT p2 ==");
-    ALOGE("== Dump OverlayImpl dump start p0 ==");
-    mPipe0->dump();
-    ALOGE("== Dump OverlayImpl dump end p0 ==");
-    ALOGE("== Dump OverlayImpl dump start p1 ==");
-    mPipe1->dump();
-    ALOGE("== Dump OverlayImpl dump end p1 ==");
-    ALOGE("== Dump OverlayImpl dump start p2 ==");
-    mPipe2->dump();
-    ALOGE("== Dump OverlayImpl dump end p2 ==");
-}
-
-
-} // overlay
-
-#endif // OVERLAY_IMPL_H
diff --git a/liboverlay/mdpRotator.cpp b/liboverlay/overlayMdpRot.cpp
similarity index 74%
rename from liboverlay/mdpRotator.cpp
rename to liboverlay/overlayMdpRot.cpp
index cb18dac..f96ddb7 100644
--- a/liboverlay/mdpRotator.cpp
+++ b/liboverlay/overlayMdpRot.cpp
@@ -1,18 +1,20 @@
 /*
-* Copyright (C) 2008 The Android Open Source Project
-* Copyright (c) 2010-2012, Code Aurora Forum. All rights reserved.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*      http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (C) 2008 The Android Open Source Project
+ * Copyright (c) 2010-2012, The Linux Foundation. All rights reserved.
+ * Not a Contribution, Apache license notifications and license are retained
+ * for attribution purposes only.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include "overlayUtils.h"
@@ -22,6 +24,48 @@
 
 namespace overlay {
 
+MdpRot::MdpRot() {
+    reset();
+    init();
+}
+
+MdpRot::~MdpRot() { close(); }
+
+void MdpRot::setEnable() { mRotImgInfo.enable = 1; }
+
+void MdpRot::setDisable() { mRotImgInfo.enable = 0; }
+
+bool MdpRot::enabled() const { return mRotImgInfo.enable; }
+
+void MdpRot::setRotations(uint32_t r) { mRotImgInfo.rotations = r; }
+
+int MdpRot::getDstMemId() const {
+    return mRotDataInfo.dst.memory_id;
+}
+
+uint32_t MdpRot::getDstOffset() const {
+    return mRotDataInfo.dst.offset;
+}
+
+uint32_t MdpRot::getSessId() const { return mRotImgInfo.session_id; }
+
+void MdpRot::setSrcFB() {
+    mRotDataInfo.src.flags |= MDP_MEMORY_ID_TYPE_FB;
+}
+
+void MdpRot::save() {
+    mLSRotImgInfo = mRotImgInfo;
+}
+
+bool MdpRot::rotConfChanged() const {
+    // 0 means same
+    if(0 == ::memcmp(&mRotImgInfo, &mLSRotImgInfo,
+                sizeof (msm_rotator_img_info))) {
+        return false;
+    }
+    return true;
+}
+
 bool MdpRot::init()
 {
     if(!mFd.open(Res::rotPath, O_RDWR)){
@@ -116,9 +160,9 @@
 
 bool MdpRot::close() {
     bool success = true;
-    if(mFd.valid() && (getSessId() > 0)) {
+    if(mFd.valid() && (getSessId() != 0)) {
         if(!mdp_wrapper::endRotator(mFd.getFD(), getSessId())) {
-            ALOGE("Mdp Rot error endRotator, fd=%d sessId=%d",
+            ALOGE("Mdp Rot error endRotator, fd=%d sessId=%u",
                     mFd.getFD(), getSessId());
             success = false;
         }
diff --git a/liboverlay/mdssRotator.cpp b/liboverlay/overlayMdssRot.cpp
similarity index 79%
rename from liboverlay/mdssRotator.cpp
rename to liboverlay/overlayMdssRot.cpp
index 52d6e67..39c7f95 100644
--- a/liboverlay/mdssRotator.cpp
+++ b/liboverlay/overlayMdssRot.cpp
@@ -1,18 +1,20 @@
 /*
-* Copyright (C) 2008 The Android Open Source Project
-* Copyright (c) 2010-2012, Code Aurora Forum. All rights reserved.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*      http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (C) 2008 The Android Open Source Project
+ * Copyright (c) 2010-2012, The Linux Foundation. All rights reserved.
+ * Not a Contribution, Apache license notifications and license are retained
+ * for attribution purposes only.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include "overlayUtils.h"
@@ -25,6 +27,34 @@
 namespace ovutils = overlay::utils;
 
 namespace overlay {
+MdssRot::MdssRot() {
+    reset();
+    init();
+}
+
+MdssRot::~MdssRot() { close(); }
+
+void MdssRot::setEnable() { mEnabled = true; }
+
+void MdssRot::setDisable() { mEnabled = false; }
+
+bool MdssRot::enabled() const { return mEnabled; }
+
+void MdssRot::setRotations(uint32_t flags) { mRotInfo.flags |= flags; }
+
+int MdssRot::getDstMemId() const {
+    return mRotData.dst_data.memory_id;
+}
+
+uint32_t MdssRot::getDstOffset() const {
+    return mRotData.dst_data.offset;
+}
+
+uint32_t MdssRot::getSessId() const { return mRotInfo.id; }
+
+void MdssRot::setSrcFB() {
+    mRotData.data.flags |= MDP_MEMORY_ID_TYPE_FB;
+}
 
 bool MdssRot::init() {
     if(!utils::openDev(mFd, 0, Res::fbPath, O_RDWR)) {
@@ -175,7 +205,7 @@
             ALOGE("MdssRot::close unsetOverlay failed, fd=%d sessId=%d",
                   mFd.getFD(), getSessId());
 		    success = false;
-	}
+	    }
     }
 
     if (!mFd.close()) {
diff --git a/liboverlay/overlayRotator.cpp b/liboverlay/overlayRotator.cpp
index 377265f..956ea2b 100644
--- a/liboverlay/overlayRotator.cpp
+++ b/liboverlay/overlayRotator.cpp
@@ -1,18 +1,20 @@
 /*
-* Copyright (C) 2008 The Android Open Source Project
-* Copyright (c) 2010-2012, Code Aurora Forum. All rights reserved.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*      http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (C) 2008 The Android Open Source Project
+ * Copyright (c) 2010-2012, The Linux Foundation. All rights reserved.
+ * Not a Contribution, Apache license notifications and license are retained
+ * for attribution purposes only.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include "overlayRotator.h"
@@ -23,7 +25,21 @@
 
 namespace overlay {
 
-int IRotatorHw::getRotatorHwType() {
+Rotator::~Rotator() {}
+
+Rotator* Rotator::getRotator() {
+    int type = getRotatorHwType();
+    if(type == TYPE_MDP) {
+        return new MdpRot(); //will do reset
+    } else if(type == TYPE_MDSS) {
+        return new MdssRot();
+    } else {
+        ALOGE("%s Unknown h/w type %d", __FUNCTION__, type);
+        return NULL;
+    }
+}
+
+int Rotator::getRotatorHwType() {
     int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion();
     if (mdpVersion == qdutils::MDSS_V5)
         return TYPE_MDSS;
diff --git a/liboverlay/overlayRotator.h b/liboverlay/overlayRotator.h
index 075e46d..4ef33f3 100644
--- a/liboverlay/overlayRotator.h
+++ b/liboverlay/overlayRotator.h
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2011, Code Aurora Forum. All rights reserved.
+* Copyright (c) 2011, The Linux Foundation. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
@@ -10,7 +10,7 @@
 *      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
+*    * Neither the name of The Linux Foundation. nor the names of its
 *      contributors may be used to endorse or promote products derived
 *      from this software without specific prior written permission.
 *
@@ -38,136 +38,36 @@
 
 namespace overlay {
 
-class IRotatorHw;
-/*
-* RotatorBase. No members, just interface.
-* can also be =0 with empty impl in cpp.
-* */
-class RotatorBase {
-public:
-    /* Most of the below are No op funcs for RotatorBase */
-    virtual ~RotatorBase() {}
-    virtual bool init() = 0;
-    virtual bool close() = 0;
-    virtual void setSource(const utils::Whf& wfh) = 0;
-    virtual void setFlags(const utils::eMdpFlags& flags) = 0;
-    virtual void setTransform(const utils::eTransform& rot,
-            const bool& rotUsed) = 0;
-    virtual bool commit() = 0;
-    virtual bool queueBuffer(int fd, uint32_t offset) = 0;
-
-    virtual void setEnable() = 0;
-    virtual void setDisable() = 0;
-    virtual void setRotations(uint32_t r) = 0;
-    virtual void setSrcFB() = 0;
-
-    virtual bool enabled() const = 0;
-    virtual uint32_t getSessId() const = 0;
-    virtual int getDstMemId() const = 0;
-    virtual uint32_t getDstOffset() const = 0;
-    virtual void dump() const = 0;
-
-protected:
-    //Hardware specific rotator impl.
-    IRotatorHw *mRot;
-};
-
-/*
- * Rotator Hw Interface. Any hardware specific implementation should inherit
- * from this.
- */
-class IRotatorHw {
-public:
-    /* Most of the below are No op funcs for RotatorBase */
-    virtual ~IRotatorHw() {}
-    /* init fd for rotator. map bufs is defered */
-    virtual bool init() = 0;
-    /* close fd, mem */
-    virtual bool close() = 0;
-    /* set src */
-    virtual void setSource(const utils::Whf& wfh) = 0;
-    /* set mdp flags, will use only stuff necessary for rotator */
-    virtual void setFlags(const utils::eMdpFlags& flags) = 0;
-    /* Set rotation and calculate */
-    virtual void setTransform(const utils::eTransform& rot,
-            const bool& rotUsed) = 0;
-    /* calls underlying wrappers to start rotator */
-    virtual bool commit() = 0;
-    /* Lazy buffer allocation. queue buffer */
-    virtual bool queueBuffer(int fd, uint32_t offset) = 0;
-    /* set enable/disable flag */
-    virtual void setEnable() = 0;
-    virtual void setDisable() = 0;
-    /* set rotator flag*/
-    virtual void setRotations(uint32_t r) = 0;
-    /* Mark src as FB (non-ION) */
-    virtual void setSrcFB() = 0;
-    /* Retusn true if rotator enabled */
-    virtual bool enabled() const = 0;
-    /* returns rotator session id */
-    virtual uint32_t getSessId() const = 0;
-    /* get dst (for offset and memory id) non-virt */
-    virtual int getDstMemId() const = 0;
-    virtual uint32_t getDstOffset() const = 0;
-    /* dump the state of the object */
-    virtual void dump() const = 0;
-
-    enum { TYPE_MDP, TYPE_MDSS };
-    /*Returns rotator h/w type */
-    static int getRotatorHwType();
-};
-
-/*
-* Actual Rotator impl.
-* */
-class Rotator : public RotatorBase
+class Rotator
 {
 public:
-    explicit Rotator();
+    enum { TYPE_MDP, TYPE_MDSS };
     virtual ~Rotator();
-    virtual bool init();
-    virtual bool close();
-    virtual void setSource(const utils::Whf& wfh);
-    virtual void setFlags(const utils::eMdpFlags& flags);
+    virtual bool init() = 0;
+    virtual bool close() = 0;
+    virtual void setSource(const utils::Whf& wfh) = 0;
+    virtual void setFlags(const utils::eMdpFlags& flags) = 0;
     virtual void setTransform(const utils::eTransform& rot,
-            const bool& rotUsed);
-    virtual bool commit();
-    virtual void setRotations(uint32_t r);
-    virtual void setSrcFB();
-    virtual int getDstMemId() const;
-    virtual uint32_t getDstOffset() const;
-    virtual void setEnable();
-    virtual void setDisable();
-    virtual bool enabled () const;
-    virtual uint32_t getSessId() const;
-    virtual bool queueBuffer(int fd, uint32_t offset);
-    virtual void dump() const;
-};
+            const bool& rotUsed) = 0;
+    virtual bool commit() = 0;
+    virtual void setRotations(uint32_t r) = 0;
+    virtual void setSrcFB() = 0;
+    virtual int getDstMemId() const = 0;
+    virtual uint32_t getDstOffset() const = 0;
+    virtual void setEnable() = 0;
+    virtual void setDisable() = 0;
+    virtual bool enabled () const = 0;
+    virtual uint32_t getSessId() const = 0;
+    virtual bool queueBuffer(int fd, uint32_t offset) = 0;
+    virtual void dump() const = 0;
+    static Rotator *getRotator();
 
-/*
-* Null/Empty impl of RotatorBase
-* */
-class NullRotator : public RotatorBase {
-public:
-    /* Most of the below are No op funcs for RotatorBase */
-    virtual ~NullRotator();
-    virtual bool init();
-    virtual bool close();
-    virtual void setSource(const utils::Whf& wfh);
-    virtual void setFlags(const utils::eMdpFlags& flags);
-    virtual void setTransform(const utils::eTransform& rot,
-            const bool& rotUsed);
-    virtual bool commit();
-    virtual void setRotations(uint32_t r);
-    virtual bool queueBuffer(int fd, uint32_t offset);
-    virtual void setEnable();
-    virtual void setDisable();
-    virtual bool enabled () const;
-    virtual void setSrcFB();
-    virtual uint32_t getSessId() const;
-    virtual int getDstMemId() const;
-    virtual uint32_t getDstOffset() const;
-    virtual void dump() const;
+protected:
+    explicit Rotator() {}
+
+private:
+    /*Returns rotator h/w type */
+    static int getRotatorHwType();
 };
 
 /*
@@ -209,29 +109,29 @@
 * MDP rot holds MDP's rotation related structures.
 *
 * */
-class MdpRot : public IRotatorHw {
+class MdpRot : public Rotator {
 public:
-    explicit MdpRot();
-    ~MdpRot();
-    bool init();
-    bool close();
-    void setSource(const utils::Whf& whf);
+    virtual ~MdpRot();
+    virtual bool init();
+    virtual bool close();
+    virtual void setSource(const utils::Whf& wfh);
     virtual void setFlags(const utils::eMdpFlags& flags);
-    void setTransform(const utils::eTransform& rot,
+    virtual void setTransform(const utils::eTransform& rot,
             const bool& rotUsed);
-    bool commit();
-    bool queueBuffer(int fd, uint32_t offset);
-    void setEnable();
-    void setDisable();
-    void setRotations(uint32_t r);
-    void setSrcFB();
-    bool enabled() const;
-    uint32_t getSessId() const;
-    int getDstMemId() const;
-    uint32_t getDstOffset() const;
-    void dump() const;
+    virtual bool commit();
+    virtual void setRotations(uint32_t r);
+    virtual void setSrcFB();
+    virtual int getDstMemId() const;
+    virtual uint32_t getDstOffset() const;
+    virtual void setEnable();
+    virtual void setDisable();
+    virtual bool enabled () const;
+    virtual uint32_t getSessId() const;
+    virtual bool queueBuffer(int fd, uint32_t offset);
+    virtual void dump() const;
 
 private:
+    explicit MdpRot();
     /* remap rot buffers */
     bool remap(uint32_t numbufs);
     bool open_i(uint32_t numbufs, uint32_t bufsz);
@@ -261,35 +161,37 @@
     RotMem mMem;
     /* Single Rotator buffer size */
     uint32_t mBufSize;
+
+    friend Rotator* Rotator::getRotator();
 };
 
 /*
 +* MDSS Rot holds MDSS's rotation related structures.
 +*
 +* */
-class MdssRot : public IRotatorHw {
+class MdssRot : public Rotator {
 public:
-    explicit MdssRot();
-    ~MdssRot();
-    bool init();
-    bool close();
-    void setSource(const utils::Whf& whf);
+    virtual ~MdssRot();
+    virtual bool init();
+    virtual bool close();
+    virtual void setSource(const utils::Whf& wfh);
     virtual void setFlags(const utils::eMdpFlags& flags);
-    void setTransform(const utils::eTransform& rot,
+    virtual void setTransform(const utils::eTransform& rot,
             const bool& rotUsed);
-    bool commit();
-    bool queueBuffer(int fd, uint32_t offset);
-    void setEnable();
-    void setDisable();
-    void setRotations(uint32_t r);
-    void setSrcFB();
-    bool enabled() const;
-    uint32_t getSessId() const;
-    int getDstMemId() const;
-    uint32_t getDstOffset() const;
-    void dump() const;
+    virtual bool commit();
+    virtual void setRotations(uint32_t r);
+    virtual void setSrcFB();
+    virtual int getDstMemId() const;
+    virtual uint32_t getDstOffset() const;
+    virtual void setEnable();
+    virtual void setDisable();
+    virtual bool enabled () const;
+    virtual uint32_t getSessId() const;
+    virtual bool queueBuffer(int fd, uint32_t offset);
+    virtual void dump() const;
 
 private:
+    explicit MdssRot();
     /* remap rot buffers */
     bool remap(uint32_t numbufs);
     bool open_i(uint32_t numbufs, uint32_t bufsz);
@@ -312,145 +214,10 @@
     uint32_t mBufSize;
     /* Enable/Disable Mdss Rot*/
     bool mEnabled;
+
+    friend Rotator* Rotator::getRotator();
 };
 
-//--------------inlines------------------------------------
-
-///// Rotator /////
-inline Rotator::Rotator() {
-    int type = IRotatorHw::getRotatorHwType();
-    if(type == IRotatorHw::TYPE_MDP) {
-        mRot = new MdpRot(); //will do reset
-    } else if(type == IRotatorHw::TYPE_MDSS) {
-        mRot = new MdssRot();
-    } else {
-        ALOGE("%s Unknown h/w type %d", __FUNCTION__, type);
-    }
-}
-inline Rotator::~Rotator() {
-    delete mRot; //will do close
-}
-inline bool Rotator::init() {
-    if(!mRot->init()) {
-        ALOGE("Rotator::init failed");
-        return false;
-    }
-    return true;
-}
-inline bool Rotator::close() {
-    return mRot->close();
-}
-inline void Rotator::setSource(const utils::Whf& whf) {
-    mRot->setSource(whf);
-}
-inline void Rotator::setFlags(const utils::eMdpFlags& flags) {
-    mRot->setFlags(flags);
-}
-inline void Rotator::setTransform(const utils::eTransform& rot,
-        const bool& rotUsed)
-{
-    mRot->setTransform(rot, rotUsed);
-}
-inline bool Rotator::commit() {
-    return mRot->commit();
-}
-inline void Rotator::setEnable(){ mRot->setEnable(); }
-inline void Rotator::setDisable(){ mRot->setDisable(); }
-inline bool Rotator::enabled() const { return mRot->enabled(); }
-inline void Rotator::setSrcFB() { mRot->setSrcFB(); }
-inline int Rotator::getDstMemId() const {
-    return mRot->getDstMemId();
-}
-inline uint32_t Rotator::getDstOffset() const {
-    return mRot->getDstOffset();
-}
-inline void Rotator::setRotations(uint32_t rot) {
-    mRot->setRotations (rot);
-}
-inline uint32_t Rotator::getSessId() const {
-    return mRot->getSessId();
-}
-inline void Rotator::dump() const {
-    ALOGE("== Dump Rotator start ==");
-    mRot->dump();
-    ALOGE("== Dump Rotator end ==");
-}
-inline bool Rotator::queueBuffer(int fd, uint32_t offset) {
-    return mRot->queueBuffer(fd, offset);
-}
-
-
-///// Null Rotator /////
-inline NullRotator::~NullRotator() {}
-inline bool NullRotator::init() { return true; }
-inline bool NullRotator::close() { return true; }
-inline bool NullRotator::commit() { return true; }
-inline void NullRotator::setSource(const utils::Whf& wfh) {}
-inline void NullRotator::setFlags(const utils::eMdpFlags& flags) {}
-inline void NullRotator::setTransform(const utils::eTransform& rot, const bool&)
-{}
-inline void NullRotator::setRotations(uint32_t) {}
-inline void NullRotator::setEnable() {}
-inline void NullRotator::setDisable() {}
-inline bool NullRotator::enabled() const { return false; }
-inline uint32_t NullRotator::getSessId() const { return 0; }
-inline bool NullRotator::queueBuffer(int fd, uint32_t offset) { return true; }
-inline void NullRotator::setSrcFB() {}
-inline int NullRotator::getDstMemId() const { return -1; }
-inline uint32_t NullRotator::getDstOffset() const { return 0;}
-inline void NullRotator::dump() const {
-    ALOGE("== Dump NullRotator dump (null) start/end ==");
-}
-
-
-//// MdpRot ////
-inline MdpRot::MdpRot() { reset(); }
-inline MdpRot::~MdpRot() { close(); }
-inline void MdpRot::setEnable() { mRotImgInfo.enable = 1; }
-inline void MdpRot::setDisable() { mRotImgInfo.enable = 0; }
-inline bool MdpRot::enabled() const { return mRotImgInfo.enable; }
-inline void MdpRot::setRotations(uint32_t r) { mRotImgInfo.rotations = r; }
-inline int MdpRot::getDstMemId() const {
-    return mRotDataInfo.dst.memory_id;
-}
-inline uint32_t MdpRot::getDstOffset() const {
-    return mRotDataInfo.dst.offset;
-}
-inline uint32_t MdpRot::getSessId() const { return mRotImgInfo.session_id; }
-inline void MdpRot::setSrcFB() {
-    mRotDataInfo.src.flags |= MDP_MEMORY_ID_TYPE_FB;
-}
-inline void MdpRot::save() {
-    mLSRotImgInfo = mRotImgInfo;
-}
-inline bool MdpRot::rotConfChanged() const {
-    // 0 means same
-    if(0 == ::memcmp(&mRotImgInfo, &mLSRotImgInfo,
-                sizeof (msm_rotator_img_info))) {
-        return false;
-    }
-    return true;
-}
-
-
-//// MdssRot ////
-inline MdssRot::MdssRot() { reset(); }
-inline MdssRot::~MdssRot() { close(); }
-inline void MdssRot::setEnable() { mEnabled = true; }
-inline void MdssRot::setDisable() { mEnabled = false; }
-inline bool MdssRot::enabled() const { return mEnabled; }
-inline void MdssRot::setRotations(uint32_t flags) { mRotInfo.flags |= flags; }
-inline int MdssRot::getDstMemId() const {
-    return mRotData.dst_data.memory_id;
-}
-inline uint32_t MdssRot::getDstOffset() const {
-    return mRotData.dst_data.offset;
-}
-inline uint32_t MdssRot::getSessId() const { return mRotInfo.id; }
-inline void MdssRot::setSrcFB() {
-    mRotData.data.flags |= MDP_MEMORY_ID_TYPE_FB;
-}
-
 } // overlay
 
 #endif // OVERlAY_ROTATOR_H
diff --git a/liboverlay/overlayState.h b/liboverlay/overlayState.h
deleted file mode 100644
index 85d61d5..0000000
--- a/liboverlay/overlayState.h
+++ /dev/null
@@ -1,667 +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_STATE_H
-#define OVERLAY_STATE_H
-
-#include "overlayUtils.h"
-#include "overlayImpl.h"
-#include "overlayRotator.h"
-#include "pipes/overlayGenPipe.h"
-#include "pipes/overlayVideoExtPipe.h"
-#include "pipes/overlayUIMirrorPipe.h"
-#include "pipes/overlay3DPipe.h"
-
-namespace overlay {
-
-/*
-* Used by Overlay class. Invokes each event
-* */
-
-class OverlayState : utils::NoCopy {
-public:
-    /*ctor*/
-    explicit OverlayState();
-
-    /*dtor*/
-    ~OverlayState();
-
-    /* return current state */
-    utils::eOverlayState state() const;
-
-    /* Hard reset to a new state. If the state is the same
-     * as the current one, it would be a no-op */
-    OverlayImplBase* reset(utils::eOverlayState s);
-
-    /* Caller pass the state to the handleEvent function.
-     * The input is the current OverlayImplBase*, and output is
-     * a pointer to (possibly new) instance of OverlayImplBase
-     * The eFormat can be 2D/3D etc. */
-    OverlayImplBase* handleEvent(utils::eOverlayState s,
-            OverlayImplBase* ov);
-
-    /* Dump */
-    void dump() const;
-
-private:
-
-    /* Transitions from a state to a state. Default behavior is to move from an
-     * old state to CLOSED and from CLOSED to a new state. Any impl wishing to
-     * copy pipes should specialize this call */
-    template<utils::eOverlayState FROM_STATE, utils::eOverlayState TO_STATE>
-    OverlayImplBase* handle_from_to(OverlayImplBase* ov);
-
-    /* Just a convenient intermediate function to bring down the number of
-     * combinations arising from multiple states */
-    template<utils::eOverlayState FROM_STATE>
-    OverlayImplBase* handle_from(utils::eOverlayState toState,
-            OverlayImplBase* ov);
-
-    /* Substitues for partially specialized templated handle functions since the
-     * standard doesn't allow partial specialization of functions */
-    template<utils::eOverlayState FROM_STATE>
-    OverlayImplBase* handle_xxx_to_CLOSED(OverlayImplBase* ov);
-
-    template<utils::eOverlayState TO_STATE>
-    OverlayImplBase* handle_CLOSED_to_xxx(OverlayImplBase* ov);
-
-    /* States here */
-    utils::eOverlayState mState;
-};
-
-//------------------------State Traits --------------------------
-
-// primary has nothing
-template <int STATE> struct StateTraits {};
-
-/*
- * For 3D_xxx we need channel ID besides the FBx since
- * get crop/position 3D need that to determine pos/crop
- * info.
- * */
-
-template <> struct StateTraits<utils::OV_2D_VIDEO_ON_PANEL>
-{
-    typedef overlay::GenericPipe<utils::PRIMARY> pipe0; //prim video
-    typedef overlay::NullPipe pipe1;   // place holder
-    typedef overlay::NullPipe pipe2;   // place holder
-
-    typedef Rotator rot0;
-    typedef NullRotator rot1;
-    typedef NullRotator rot2;
-
-    typedef overlay::OverlayImpl<pipe0, pipe1, pipe2> ovimpl;
-};
-
-template <> struct StateTraits<utils::OV_2D_VIDEO_ON_PANEL_TV>
-{
-    typedef overlay::GenericPipe<utils::PRIMARY> pipe0; //prim video
-    typedef overlay::VideoExtPipe pipe1; //ext video
-    typedef overlay::GenericPipe<utils::EXTERNAL> pipe2; //ext subtitle
-
-    typedef Rotator rot0;
-    typedef Rotator rot1;
-    typedef NullRotator rot2;
-
-    typedef overlay::OverlayImpl<pipe0, pipe1, pipe2> ovimpl;
-};
-
-template <> struct StateTraits<utils::OV_2D_VIDEO_ON_TV>
-{
-    typedef overlay::NullPipe pipe0; //nothing on primary with mdp
-    typedef overlay::VideoExtPipe pipe1; //ext video
-    typedef overlay::GenericPipe<utils::EXTERNAL> pipe2; //ext subtitle
-
-    typedef NullRotator rot0;
-    typedef Rotator rot1;
-    typedef NullRotator rot2;
-
-    typedef overlay::OverlayImpl<pipe0, pipe1, pipe2> ovimpl;
-};
-
-template <> struct StateTraits<utils::OV_UI_VIDEO_TV>
-{
-    typedef overlay::GenericPipe<utils::EXTERNAL> pipe0; //ext UI
-    typedef overlay::GenericPipe<utils::EXTERNAL> pipe1; //ext video
-    typedef overlay::NullPipe pipe2;
-
-    typedef Rotator rot0;
-    typedef Rotator rot1;
-    typedef NullRotator rot2;
-
-    typedef overlay::OverlayImpl<pipe0, pipe1, pipe2> ovimpl;
-};
-
-template <> struct StateTraits<utils::OV_3D_VIDEO_ON_2D_PANEL>
-{
-    typedef overlay::M3DPrimaryPipe<utils::OV_PIPE0> pipe0;
-    typedef overlay::NullPipe pipe1;   // place holder
-    typedef overlay::NullPipe pipe2;   // place holder
-
-    typedef Rotator rot0;
-    typedef NullRotator rot1;
-    typedef NullRotator rot2;
-
-    typedef overlay::OverlayImpl<pipe0> ovimpl;
-};
-
-template <> struct StateTraits<utils::OV_3D_VIDEO_ON_3D_PANEL>
-{
-    typedef overlay::S3DPrimaryPipe<utils::OV_PIPE0> pipe0;
-    typedef overlay::S3DPrimaryPipe<utils::OV_PIPE1> pipe1;
-    typedef overlay::NullPipe pipe2;   // place holder
-
-    typedef Rotator rot0;
-    typedef Rotator rot1;
-    typedef NullRotator rot2;
-
-    typedef overlay::OverlayImpl<pipe0, pipe1> ovimpl;
-};
-
-template <> struct StateTraits<utils::OV_3D_VIDEO_ON_3D_TV>
-{
-    typedef overlay::S3DExtPipe<utils::OV_PIPE0> pipe0;
-    typedef overlay::S3DExtPipe<utils::OV_PIPE1> pipe1;
-    typedef overlay::NullPipe pipe2;   // place holder
-
-    typedef NullRotator rot0;
-    typedef NullRotator rot1;
-    typedef NullRotator rot2;
-
-    typedef overlay::OverlayImpl<pipe0, pipe1> ovimpl;
-};
-
-template <> struct StateTraits<utils::OV_3D_VIDEO_ON_2D_PANEL_2D_TV>
-{
-    typedef overlay::M3DPrimaryPipe<utils::OV_PIPE0> pipe0;
-    typedef overlay::M3DExtPipe<utils::OV_PIPE1> pipe1;
-    typedef overlay::NullPipe pipe2;   // place holder
-
-    typedef Rotator rot0;
-    typedef NullRotator rot1;
-    typedef NullRotator rot2;
-
-    typedef overlay::OverlayImpl<pipe0, pipe1> ovimpl;
-};
-
-template <> struct StateTraits<utils::OV_UI_MIRROR>
-{
-    typedef overlay::GenericPipe<ovutils::EXTERNAL> pipe0; //Ext UI
-    typedef overlay::NullPipe pipe1;   // place holder
-    typedef overlay::NullPipe pipe2;   // place holder
-
-    typedef Rotator rot0;
-    typedef NullRotator rot1;
-    typedef NullRotator rot2;
-
-    typedef overlay::OverlayImpl<pipe0, pipe1, pipe2> ovimpl;
-};
-
-template <> struct StateTraits<utils::OV_2D_TRUE_UI_MIRROR>
-{
-    typedef overlay::GenericPipe<utils::PRIMARY> pipe0; //Vid prim
-    typedef overlay::VideoExtPipe pipe1;
-    typedef overlay::GenericPipe<ovutils::EXTERNAL> pipe2; //EXT UI
-
-    typedef Rotator rot0;
-    typedef Rotator rot1;
-    typedef Rotator rot2;
-
-    typedef overlay::OverlayImpl<pipe0, pipe1, pipe2> ovimpl;
-};
-
-template <> struct StateTraits<utils::OV_BYPASS_1_LAYER>
-{
-    typedef overlay::GenericPipe<utils::PRIMARY> pipe0;
-    typedef overlay::NullPipe pipe1;   // place holder
-    typedef overlay::NullPipe pipe2;   // place holder
-
-    typedef NullRotator rot0;
-    typedef NullRotator rot1;
-    typedef NullRotator rot2;
-
-    typedef overlay::OverlayImpl<pipe0, pipe1, pipe2> ovimpl;
-};
-
-template <> struct StateTraits<utils::OV_BYPASS_2_LAYER>
-{
-    typedef overlay::GenericPipe<utils::PRIMARY> pipe0;
-    typedef overlay::GenericPipe<utils::PRIMARY> pipe1;
-    typedef overlay::NullPipe pipe2;   // place holder
-
-    typedef NullRotator rot0;
-    typedef NullRotator rot1;
-    typedef NullRotator rot2;
-
-    typedef overlay::OverlayImpl<pipe0, pipe1, pipe2> ovimpl;
-};
-
-template <> struct StateTraits<utils::OV_BYPASS_3_LAYER>
-{
-    typedef overlay::GenericPipe<utils::PRIMARY> pipe0;
-    typedef overlay::GenericPipe<utils::PRIMARY> pipe1;
-    typedef overlay::GenericPipe<utils::PRIMARY> pipe2;
-
-    typedef NullRotator rot0;
-    typedef NullRotator rot1;
-    typedef NullRotator rot2;
-
-    typedef overlay::OverlayImpl<pipe0, pipe1, pipe2> ovimpl;
-};
-
-template <> struct StateTraits<utils::OV_DUAL_DISP>
-{
-    typedef overlay::GenericPipe<utils::EXTERNAL> pipe0;
-    typedef overlay::NullPipe pipe1;
-    typedef overlay::NullPipe pipe2;
-
-    typedef NullRotator rot0;
-    typedef NullRotator rot1;
-    typedef NullRotator rot2;
-
-    typedef overlay::OverlayImpl<pipe0, pipe1, pipe2> ovimpl;
-};
-
-
-//------------------------Inlines --------------------------------
-
-
-inline OverlayState::OverlayState() : mState(utils::OV_CLOSED){}
-inline OverlayState::~OverlayState() {}
-inline utils::eOverlayState OverlayState::state() const { return mState; }
-inline OverlayImplBase* OverlayState::reset(utils::eOverlayState s) {
-    return handleEvent(s, 0);
-}
-inline void OverlayState::dump() const {
-    ALOGE("== Dump state %d start/end ==", mState);
-}
-
-inline OverlayImplBase* OverlayState::handleEvent(utils::eOverlayState toState,
-        OverlayImplBase* ov)
-{
-    OverlayImplBase* newov = ov; // at least, we return the same
-    if (mState != toState) {
-        ALOGD_IF(DEBUG_OVERLAY, "%s: state changed %s-->%s",
-                __FUNCTION__, getStateString(mState), getStateString(toState));
-    } else {
-        ALOGD_IF(DEBUG_OVERLAY, "%s: no state change, state=%s",
-                __FUNCTION__, getStateString(toState));
-        return newov;
-    }
-
-    switch(mState)
-    {
-        case utils::OV_CLOSED:
-            newov = handle_from<utils::OV_CLOSED>(toState, ov);
-            break;
-        case utils::OV_2D_VIDEO_ON_PANEL:
-            newov = handle_from<utils::OV_2D_VIDEO_ON_PANEL>(toState, ov);
-            break;
-        case utils::OV_2D_VIDEO_ON_PANEL_TV:
-            newov = handle_from<utils::OV_2D_VIDEO_ON_PANEL_TV>(toState, ov);
-            break;
-        case utils::OV_2D_VIDEO_ON_TV:
-            newov = handle_from<utils::OV_2D_VIDEO_ON_TV>(toState, ov);
-            break;
-        case utils::OV_3D_VIDEO_ON_2D_PANEL:
-            newov = handle_from<utils::OV_3D_VIDEO_ON_2D_PANEL>(toState, ov);
-            break;
-        case utils::OV_3D_VIDEO_ON_3D_PANEL:
-            newov = handle_from<utils::OV_3D_VIDEO_ON_3D_PANEL>(toState, ov);
-            break;
-        case utils::OV_3D_VIDEO_ON_3D_TV:
-            newov = handle_from<utils::OV_3D_VIDEO_ON_3D_TV>(toState, ov);
-            break;
-        case utils::OV_3D_VIDEO_ON_2D_PANEL_2D_TV:
-            newov = handle_from<utils::OV_3D_VIDEO_ON_2D_PANEL_2D_TV>(toState,
-                                                                      ov);
-            break;
-        case utils::OV_UI_MIRROR:
-            newov = handle_from<utils::OV_UI_MIRROR>(toState, ov);
-            break;
-        case utils::OV_2D_TRUE_UI_MIRROR:
-            newov = handle_from<utils::OV_2D_TRUE_UI_MIRROR>(toState, ov);
-            break;
-        case utils::OV_UI_VIDEO_TV:
-            newov = handle_from<utils::OV_UI_VIDEO_TV>(toState, ov);
-            break;
-        case utils::OV_BYPASS_1_LAYER:
-            newov = handle_from<utils::OV_BYPASS_1_LAYER>(toState, ov);
-            break;
-        case utils::OV_BYPASS_2_LAYER:
-            newov = handle_from<utils::OV_BYPASS_2_LAYER>(toState, ov);
-            break;
-        case utils::OV_BYPASS_3_LAYER:
-            newov = handle_from<utils::OV_BYPASS_3_LAYER>(toState, ov);
-            break;
-        case utils::OV_DUAL_DISP:
-            newov = handle_from<utils::OV_DUAL_DISP>(toState, ov);
-            break;
-        default:
-            OVASSERT(1 == 0, "%s: unknown state = %d", __FUNCTION__, mState);
-
-    }
-    return newov;
-}
-
-template <utils::eOverlayState FROM_STATE>
-inline OverlayImplBase* OverlayState::handle_from(utils::eOverlayState toState,
-        OverlayImplBase* ov) {
-
-    switch(toState)
-    {
-        case utils::OV_CLOSED:
-            ov = handle_xxx_to_CLOSED<FROM_STATE>(ov);
-            break;
-        case utils::OV_2D_VIDEO_ON_PANEL:
-            ov = handle_from_to<FROM_STATE, utils::OV_2D_VIDEO_ON_PANEL>(ov);
-            break;
-        case utils::OV_2D_VIDEO_ON_PANEL_TV:
-            ov = handle_from_to<FROM_STATE, utils::OV_2D_VIDEO_ON_PANEL_TV>(ov);
-            break;
-        case utils::OV_2D_VIDEO_ON_TV:
-            ov = handle_from_to<FROM_STATE, utils::OV_2D_VIDEO_ON_TV>(ov);
-            break;
-        case utils::OV_3D_VIDEO_ON_2D_PANEL:
-            ov = handle_from_to<FROM_STATE, utils::OV_3D_VIDEO_ON_2D_PANEL>(ov);
-            break;
-        case utils::OV_3D_VIDEO_ON_3D_PANEL:
-            ov = handle_from_to<FROM_STATE, utils::OV_3D_VIDEO_ON_3D_PANEL>(ov);
-            break;
-        case utils::OV_3D_VIDEO_ON_3D_TV:
-            ov = handle_from_to<FROM_STATE, utils::OV_3D_VIDEO_ON_3D_TV>(ov);
-            break;
-        case utils::OV_3D_VIDEO_ON_2D_PANEL_2D_TV:
-            ov = handle_from_to<FROM_STATE,
-                        utils::OV_3D_VIDEO_ON_2D_PANEL_2D_TV>(ov);
-            break;
-        case utils::OV_UI_MIRROR:
-            ov = handle_from_to<FROM_STATE, utils::OV_UI_MIRROR>(ov);
-            break;
-        case utils::OV_2D_TRUE_UI_MIRROR:
-            ov = handle_from_to<FROM_STATE, utils::OV_2D_TRUE_UI_MIRROR>(ov);
-            break;
-        case utils::OV_UI_VIDEO_TV:
-            ov = handle_from_to<FROM_STATE, utils::OV_UI_VIDEO_TV>(ov);
-            break;
-        case utils::OV_BYPASS_1_LAYER:
-            ov = handle_from_to<FROM_STATE, utils::OV_BYPASS_1_LAYER>(ov);
-            break;
-        case utils::OV_BYPASS_2_LAYER:
-            ov = handle_from_to<FROM_STATE, utils::OV_BYPASS_2_LAYER>(ov);
-            break;
-        case utils::OV_BYPASS_3_LAYER:
-            ov = handle_from_to<FROM_STATE, utils::OV_BYPASS_3_LAYER>(ov);
-            break;
-        case utils::OV_DUAL_DISP:
-            ov = handle_from_to<FROM_STATE, utils::OV_DUAL_DISP>(ov);
-            break;
-        default:
-            OVASSERT(1 == 0, "%s: unknown state = %d", __FUNCTION__, toState);
-    }
-    mState = toState;
-    return ov;
-}
-
-
-/* Transition default from any to any. Does in two steps.
- * Moves from OLD to CLOSED and then from CLOSED to NEW
- */
-template<utils::eOverlayState FROM_STATE, utils::eOverlayState TO_STATE>
-inline OverlayImplBase* OverlayState::handle_from_to(OverlayImplBase* ov) {
-    handle_xxx_to_CLOSED<FROM_STATE>(ov);
-    return handle_CLOSED_to_xxx<TO_STATE>(ov);
-}
-
-//---------------Specializations-------------
-
-
-/* Transition from CLOSED to ANY */
-template<utils::eOverlayState TO_STATE>
-inline OverlayImplBase* OverlayState::handle_CLOSED_to_xxx(
-            OverlayImplBase* /*ignored*/) {
-    //If going from CLOSED to CLOSED, nothing to do.
-    if(TO_STATE == utils::OV_CLOSED) return NULL;
-    ALOGD("FROM_STATE = %s TO_STATE = %s",
-            utils::getStateString(utils::OV_CLOSED),
-            utils::getStateString(TO_STATE));
-    OverlayImplBase* ov = new typename StateTraits<TO_STATE>::ovimpl;
-    RotatorBase* rot0 = new typename StateTraits<TO_STATE>::rot0;
-    RotatorBase* rot1 = new typename StateTraits<TO_STATE>::rot1;
-    RotatorBase* rot2 = new typename StateTraits<TO_STATE>::rot2;
-    if(!ov->init(rot0, rot1, rot2)) {
-        ALOGE("Overlay failed to init in state %d", TO_STATE);
-        return 0;
-    }
-    return ov;
-}
-
-/* Transition from ANY to CLOSED */
-template<utils::eOverlayState FROM_STATE>
-inline OverlayImplBase* OverlayState::handle_xxx_to_CLOSED(OverlayImplBase* ov)
-{
-    //If going from CLOSED to CLOSED, nothing to do.
-    if(FROM_STATE == utils::OV_CLOSED) return NULL;
-    ALOGD("FROM_STATE = %s TO_STATE = %s",
-            utils::getStateString(FROM_STATE),
-            utils::getStateString(utils::OV_CLOSED));
-    OVASSERT(ov, "%s: ov is null", __FUNCTION__);
-    if(!ov->close()) {
-        ALOGE("%s: Failed to ov close", __FUNCTION__);
-    }
-    delete ov;
-    ov = 0;
-    return 0;
-}
-
-/* Transition from 2D_VIDEO_ON_PANEL to 2D_VIDEO_ON_PANEL_TV */
-template<>
-inline OverlayImplBase* OverlayState::handle_from_to<
-        utils::OV_2D_VIDEO_ON_PANEL,
-        utils::OV_2D_VIDEO_ON_PANEL_TV>(
-        OverlayImplBase* ov) {
-    OVASSERT(ov, "%s: ov is null", __FUNCTION__);
-    ALOGD("FROM_STATE = %s TO_STATE = %s",
-            utils::getStateString(utils::OV_2D_VIDEO_ON_PANEL),
-            utils::getStateString(utils::OV_2D_VIDEO_ON_PANEL_TV));
-    // Create new ovimpl based on new state
-    typedef StateTraits<utils::OV_2D_VIDEO_ON_PANEL_TV> NewState;
-    OverlayImplBase* newov = new NewState::ovimpl;
-
-    //copy pipe0/rot0 (primary video)
-    newov->copyOvPipe(ov, utils::OV_PIPE0);
-    //close old pipe1, create new pipe1
-    ov->closePipe(utils::OV_PIPE1);
-    RotatorBase* rot1 = new NewState::rot1;
-    newov->initPipe(rot1, utils::OV_PIPE1);
-    //close old pipe2, create new pipe2
-    ov->closePipe(utils::OV_PIPE2);
-    RotatorBase* rot2 = new NewState::rot2;
-    newov->initPipe(rot2, utils::OV_PIPE2);
-    // All pipes are copied or deleted so no more need for previous ovimpl
-    delete ov;
-    ov = 0;
-    return newov;
-}
-
-/* Transition from 2D_VIDEO_ON_PANEL_TV to 2D_VIDEO_ON_PANEL */
-template<>
-inline OverlayImplBase* OverlayState::handle_from_to<
-        utils::OV_2D_VIDEO_ON_PANEL_TV,
-        utils::OV_2D_VIDEO_ON_PANEL>(
-        OverlayImplBase* ov) {
-    OVASSERT(ov, "%s: ov is null", __FUNCTION__);
-    ALOGD("FROM_STATE = %s TO_STATE = %s",
-            utils::getStateString(utils::OV_2D_VIDEO_ON_PANEL_TV),
-            utils::getStateString(utils::OV_2D_VIDEO_ON_PANEL));
-
-    // Create new ovimpl based on new state
-    typedef StateTraits<utils::OV_2D_VIDEO_ON_PANEL> NewState;
-    OverlayImplBase* newov = new NewState::ovimpl;
-
-    //copy pipe0/rot0 (primary video)
-    newov->copyOvPipe(ov, utils::OV_PIPE0);
-    //close old pipe1, create new pipe1
-    ov->closePipe(utils::OV_PIPE1);
-    RotatorBase* rot1 = new NewState::rot1;
-    newov->initPipe(rot1, utils::OV_PIPE1);
-    //close old pipe2, create new pipe2
-    ov->closePipe(utils::OV_PIPE2);
-    RotatorBase* rot2 = new NewState::rot2;
-    newov->initPipe(rot2, utils::OV_PIPE2);
-    // All pipes are copied or deleted so no more need for previous ovimpl
-    delete ov;
-    ov = 0;
-    return newov;
-}
-
-/* Transition from 2D_VIDEO_ON_PANEL_TV to 2D_VIDEO_ON_TV */
-template<>
-inline OverlayImplBase* OverlayState::handle_from_to<
-        utils::OV_2D_VIDEO_ON_PANEL_TV,
-        utils::OV_2D_VIDEO_ON_TV>(
-        OverlayImplBase* ov) {
-    OVASSERT(ov, "%s: ov is null", __FUNCTION__);
-    ALOGD("FROM_STATE = %s TO_STATE = %s",
-            utils::getStateString(utils::OV_2D_VIDEO_ON_PANEL_TV),
-            utils::getStateString(utils::OV_2D_VIDEO_ON_TV));
-
-    // Create new ovimpl based on new state
-    typedef StateTraits<utils::OV_2D_VIDEO_ON_TV> NewState;
-    OverlayImplBase* newov = new NewState::ovimpl;
-
-    //close old pipe0, create new pipe0
-    ov->closePipe(utils::OV_PIPE0);
-    RotatorBase* rot0 = new NewState::rot0;
-    newov->initPipe(rot0, utils::OV_PIPE0);
-    //copy pipe1/rot1 (ext video)
-    newov->copyOvPipe(ov, utils::OV_PIPE1);
-    //copy pipe2/rot2 (ext cc)
-    newov->copyOvPipe(ov, utils::OV_PIPE2);
-    // All pipes are copied or deleted so no more need for previous ovimpl
-    delete ov;
-    ov = 0;
-    return newov;
-}
-
-/* Transition from 2D_VIDEO_ON_TV to 2D_VIDEO_ON_PANEL_TV */
-template<>
-inline OverlayImplBase* OverlayState::handle_from_to<
-        utils::OV_2D_VIDEO_ON_TV,
-        utils::OV_2D_VIDEO_ON_PANEL_TV>(
-        OverlayImplBase* ov) {
-    OVASSERT(ov, "%s: ov is null", __FUNCTION__);
-    ALOGD("FROM_STATE = %s TO_STATE = %s",
-            utils::getStateString(utils::OV_2D_VIDEO_ON_TV),
-            utils::getStateString(utils::OV_2D_VIDEO_ON_PANEL_TV));
-
-    // Create new ovimpl based on new state
-    typedef StateTraits<utils::OV_2D_VIDEO_ON_PANEL_TV> NewState;
-    OverlayImplBase* newov = new NewState::ovimpl;
-
-    //close old pipe0, create new pipe0
-    ov->closePipe(utils::OV_PIPE0);
-    RotatorBase* rot0 = new NewState::rot0;
-    newov->initPipe(rot0, utils::OV_PIPE0);
-    //copy pipe1/rot1 (ext video)
-    newov->copyOvPipe(ov, utils::OV_PIPE1);
-    //copy pipe2/rot2 (ext cc)
-    newov->copyOvPipe(ov, utils::OV_PIPE2);
-    // All pipes are copied or deleted so no more need for previous ovimpl
-    delete ov;
-    ov = 0;
-    return newov;
-}
-
-/* Transition from OV_UI_MIRROR to OV_UI_VIDEO_TV */
-template<>
-inline OverlayImplBase* OverlayState::handle_from_to<
-        utils::OV_UI_MIRROR,
-        utils::OV_UI_VIDEO_TV>(
-        OverlayImplBase* ov) {
-    OVASSERT(ov, "%s: ov is null", __FUNCTION__);
-    ALOGD("FROM_STATE = %s TO_STATE = %s",
-            utils::getStateString(utils::OV_UI_MIRROR),
-            utils::getStateString(utils::OV_UI_VIDEO_TV));
-
-    // Create new ovimpl based on new state
-    typedef StateTraits<utils::OV_UI_VIDEO_TV> NewState;
-    OverlayImplBase* newov = new NewState::ovimpl;
-
-    //copy pipe0/rot0 (ext video)
-    newov->copyOvPipe(ov, utils::OV_PIPE0);
-
-    ov->closePipe(utils::OV_PIPE1);
-    RotatorBase* rot1 = new NewState::rot1;
-    newov->initPipe(rot1, utils::OV_PIPE1);
-
-    ov->closePipe(utils::OV_PIPE2);
-    RotatorBase* rot2 = new NewState::rot2;
-    newov->initPipe(rot2, utils::OV_PIPE2);
-
-    // All pipes are copied or deleted so no more need for previous ovimpl
-    delete ov;
-    ov = 0;
-    return newov;
-}
-
-/* Transition from OV_UI_VIDEO_TV to OV_UI_MIRROR */
-template<>
-inline OverlayImplBase* OverlayState::handle_from_to<
-        utils::OV_UI_VIDEO_TV,
-        utils::OV_UI_MIRROR>(
-        OverlayImplBase* ov) {
-    OVASSERT(ov, "%s: ov is null", __FUNCTION__);
-    ALOGD("FROM_STATE = %s TO_STATE = %s",
-            utils::getStateString(utils::OV_UI_VIDEO_TV),
-            utils::getStateString(utils::OV_UI_MIRROR));
-
-    // Create new ovimpl based on new state
-    typedef StateTraits<utils::OV_UI_MIRROR> NewState;
-    OverlayImplBase* newov = new NewState::ovimpl;
-
-    //copy pipe0/rot0 (ext video)
-    newov->copyOvPipe(ov, utils::OV_PIPE0);
-
-    ov->closePipe(utils::OV_PIPE1);
-    RotatorBase* rot1 = new NewState::rot1;
-    newov->initPipe(rot1, utils::OV_PIPE1);
-
-    ov->closePipe(utils::OV_PIPE2);
-    RotatorBase* rot2 = new NewState::rot2;
-    newov->initPipe(rot2, utils::OV_PIPE2);
-
-    // All pipes are copied or deleted so no more need for previous ovimpl
-    delete ov;
-    ov = 0;
-    return newov;
-}
-} // overlay
-
-#endif // OVERLAY_STATE_H
diff --git a/liboverlay/overlayUtils.cpp b/liboverlay/overlayUtils.cpp
index 1c9c72b..207531a 100644
--- a/liboverlay/overlayUtils.cpp
+++ b/liboverlay/overlayUtils.cpp
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
+* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
@@ -10,7 +10,7 @@
 *      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
+*    * Neither the name of The Linux Foundation nor the names of its
 *      contributors may be used to endorse or promote products derived
 *      from this software without specific prior written permission.
 *
@@ -151,13 +151,6 @@
     return mFBHeight;
 }
 
-bool FrameBufferInfo::supportTrueMirroring() const {
-    char value[PROPERTY_VALUE_MAX] = {0};
-    property_get("hw.trueMirrorSupported", value, "0");
-    int trueMirroringSupported = atoi(value);
-    return (trueMirroringSupported && mBorderFillSupported);
-}
-
 /* clears any VG pipes allocated to the fb devices */
 int initOverlay() {
     msmfb_mixer_info_req  req;
@@ -253,20 +246,6 @@
     return -1;
 }
 
-//Set by client as HDMI/WFD
-void setExtType(const int& type) {
-    if(type != HDMI && type != WFD) {
-        ALOGE("%s: Unrecognized type %d", __func__, type);
-        return;
-    }
-    sExtType = type;
-}
-
-//Return External panel type set by client.
-int getExtType() {
-    return sExtType;
-}
-
 bool is3DTV() {
     char is3DTV = '0';
     IOFile fp(Res::edid3dInfoFile, "r");
diff --git a/liboverlay/overlayUtils.h b/liboverlay/overlayUtils.h
index 7432ff8..f9fcca8 100644
--- a/liboverlay/overlayUtils.h
+++ b/liboverlay/overlayUtils.h
@@ -43,6 +43,7 @@
 #include <sys/types.h>
 #include <utils/Log.h>
 #include "gralloc_priv.h" //for interlace
+
 /*
 *
 * Collection of utilities functions/structs/enums etc...
@@ -123,9 +124,6 @@
     /* Gets height of primary framebuffer */
     int getHeight() const;
 
-    /* Indicates whether true mirroring is supported */
-    bool supportTrueMirroring() const;
-
 private:
     int mFBWidth;
     int mFBHeight;
@@ -266,16 +264,8 @@
  * Rotator flags: not to be confused with orientation flags.
  * Ususally, you want to open the rotator to make sure it is
  * ready for business.
- * ROT_FLAG_DISABLED: Rotator would not kick in. (ioctl will emit errors).
- * ROT_FLAG_ENABLED: and when rotation is needed.
- *                   (prim video playback)
- *                   (UI mirroring on HDMI w/ 0 degree rotator. - just memcpy)
- * In HDMI UI mirroring, rotator is always used.
- * Even when w/o orienation change on primary,
- * we do 0 rotation on HDMI and using rotator buffers.
- * That is because we might see tearing otherwise. so
- * we use another buffer (rotator).
- * When a simple video playback on HDMI, no rotator is being used.(null r).
+ * ROT_FLAG_DISABLED: Rotator not used unless required.
+ * ROT_FLAG_ENABLED: Rotator used even if not required.
  * */
 enum eRotFlags {
     ROT_FLAG_DISABLED = 0,
@@ -313,26 +303,32 @@
     ZORDER_0,
     ZORDER_1,
     ZORDER_2,
+    ZORDER_3,
     Z_SYSTEM_ALLOC = 0xFFFF
 };
 
 enum eMdpPipeType {
     OV_MDP_PIPE_RGB,
-    OV_MDP_PIPE_VG
+    OV_MDP_PIPE_VG,
+    OV_MDP_PIPE_ANY, //Any
 };
 
-// Max pipes via overlay (VG0, VG1, RGB1)
-enum { MAX_PIPES = 3 };
-
-/* Used to identify destination channels and
- * also 3D channels e.g. when in 3D mode with 2
- * pipes opened and it is used in get crop/pos 3D
- * */
+/* Used to identify destination pipes
+ */
 enum eDest {
-    OV_PIPE0 = 1 << 0,
-    OV_PIPE1 = 1 << 1,
-    OV_PIPE2 = 1 << 2,
-    OV_PIPE_ALL  = (OV_PIPE0 | OV_PIPE1 | OV_PIPE2)
+    OV_VG0 = 0,
+    OV_RGB0,
+    OV_VG1,
+    OV_RGB1,
+    OV_VG2,
+    OV_RGB2,
+    OV_INVALID,
+};
+
+/* Used when a buffer is split over 2 pipes and sent to display */
+enum {
+    OV_LEFT_SPLIT = 0,
+    OV_RIGHT_SPLIT,
 };
 
 /* values for copybit_set_parameter(OVERLAY_TRANSFORM) */
@@ -385,38 +381,6 @@
     eRotFlags rotFlags;
 };
 
-enum eOverlayState{
-    /* No pipes from overlay open */
-    OV_CLOSED = 0,
-
-    /* 2D Video */
-    OV_2D_VIDEO_ON_PANEL,
-    OV_2D_VIDEO_ON_PANEL_TV,
-    OV_2D_VIDEO_ON_TV,
-
-    /* 3D Video on one display (panel or TV) */
-    OV_3D_VIDEO_ON_2D_PANEL,
-    OV_3D_VIDEO_ON_3D_PANEL,
-    OV_3D_VIDEO_ON_3D_TV,
-
-    /* 3D Video on two displays (panel and TV) */
-    OV_3D_VIDEO_ON_2D_PANEL_2D_TV,
-
-    /* UI Mirroring */
-    OV_UI_MIRROR,
-    OV_2D_TRUE_UI_MIRROR,
-    /* Dual display with video */
-    OV_UI_VIDEO_TV,
-
-    /* Composition Bypass */
-    OV_BYPASS_1_LAYER,
-    OV_BYPASS_2_LAYER,
-    OV_BYPASS_3_LAYER,
-
-    /* External only for dual-disp */
-    OV_DUAL_DISP,
-};
-
 inline void setMdpFlags(eMdpFlags& f, eMdpFlags v) {
     f = static_cast<eMdpFlags>(setBit(f, v));
 }
@@ -431,44 +395,6 @@
 //Panels could be categorized as primary and external
 enum { PRIMARY, EXTERNAL };
 
-//External Panels could use HDMI or WFD
-enum {
-    HDMI = 1,
-    WFD = 2
-};
-
-//TODO Make this a part of some appropriate class
-static int sExtType = HDMI; //HDMI or WFD
-//Set by client as HDMI/WFD
-void setExtType(const int& type);
-//Return External panel type set by client.
-int getExtType();
-
-
-//Gets the FB number for the external type.
-//As of now, HDMI always has fb1, WFD could use fb1 or fb2
-//Assumes Ext type set by setExtType() from client.
-static int getFBForPanel(int panel) { // PRIMARY OR EXTERNAL
-    switch(panel) {
-        case PRIMARY: return FB0;
-            break;
-        case EXTERNAL:
-            switch(getExtType()) {
-                case HDMI: return FB1;
-                    break;
-                case WFD: return FB2;//Hardcoding fb2 for wfd. Will change.
-                    break;
-            }
-            break;
-        default:
-            ALOGE("%s: Unrecognized PANEL category %d", __func__, panel);
-            break;
-    }
-    return -1;
-}
-
-// number of rgb pipes bufs (max)
-
 // 2 for rgb0/1 double bufs
 enum { RGB_PIPE_NUM_BUFS = 2 };
 
@@ -491,7 +417,6 @@
  * It returns MDP related enum/define that match rot+flip*/
 int getMdpOrient(eTransform rotation);
 const char* getFormatString(int format);
-const char* getStateString(eOverlayState state);
 
 // Cannot use HW_OVERLAY_MAGNIFICATION_LIMIT, since at the time
 // of integration, HW_OVERLAY_MAGNIFICATION_LIMIT was a define
@@ -582,16 +507,6 @@
     return false;
 }
 
-inline bool isValidDest(eDest dest)
-{
-    if ((OV_PIPE0 & dest) ||
-            (OV_PIPE1 & dest) ||
-            (OV_PIPE2 & dest)) {
-        return true;
-    }
-    return false;
-}
-
 inline const char* getFormatString(int format){
     static const char* const formats[] = {
         "MDP_RGB_565",
@@ -631,44 +546,6 @@
     return formats[format];
 }
 
-inline const char* getStateString(eOverlayState state){
-    switch (state) {
-        case OV_CLOSED:
-            return "OV_CLOSED";
-        case OV_2D_VIDEO_ON_PANEL:
-            return "OV_2D_VIDEO_ON_PANEL";
-        case OV_2D_VIDEO_ON_PANEL_TV:
-            return "OV_2D_VIDEO_ON_PANEL_TV";
-        case OV_2D_VIDEO_ON_TV:
-            return "OV_2D_VIDEO_ON_TV";
-        case OV_3D_VIDEO_ON_2D_PANEL:
-            return "OV_3D_VIDEO_ON_2D_PANEL";
-        case OV_3D_VIDEO_ON_3D_PANEL:
-            return "OV_3D_VIDEO_ON_3D_PANEL";
-        case OV_3D_VIDEO_ON_3D_TV:
-            return "OV_3D_VIDEO_ON_3D_TV";
-        case OV_3D_VIDEO_ON_2D_PANEL_2D_TV:
-            return "OV_3D_VIDEO_ON_2D_PANEL_2D_TV";
-        case OV_UI_MIRROR:
-            return "OV_UI_MIRROR";
-        case OV_2D_TRUE_UI_MIRROR:
-            return "OV_2D_TRUE_UI_MIRROR";
-        case OV_UI_VIDEO_TV:
-            return "OV_UI_VIDEO_TV";
-        case OV_BYPASS_1_LAYER:
-            return "OV_BYPASS_1_LAYER";
-        case OV_BYPASS_2_LAYER:
-            return "OV_BYPASS_2_LAYER";
-        case OV_BYPASS_3_LAYER:
-            return "OV_BYPASS_3_LAYER";
-        case OV_DUAL_DISP:
-            return "OV_DUAL_DISP";
-        default:
-            return "UNKNOWN_STATE";
-    }
-    return "BAD_STATE";
-}
-
 inline void Whf::dump() const {
     ALOGE("== Dump WHF w=%d h=%d f=%d s=%d start/end ==",
             w, h, format, size);
@@ -751,7 +628,7 @@
 }
 
 template <>
-inline Dim getPositionS3DImpl<utils::OV_PIPE1>(const Whf& whf)
+inline Dim getPositionS3DImpl<utils::OV_RIGHT_SPLIT>(const Whf& whf)
 {
     switch (whf.format & OUTPUT_3D_MASK)
     {
@@ -799,7 +676,7 @@
 }
 
 template <>
-inline Dim getCropS3DImpl<utils::OV_PIPE1>(const Dim& in, uint32_t fmt) {
+inline Dim getCropS3DImpl<utils::OV_RIGHT_SPLIT>(const Dim& in, uint32_t fmt) {
     switch (fmt & INPUT_3D_MASK)
     {
         case HAL_3D_IN_SIDE_BY_SIDE_L_R:
@@ -855,6 +732,35 @@
         value--;
 }
 
+inline const char* getDestStr(eDest dest) {
+    switch(dest) {
+        case OV_VG0: return "VG0";
+        case OV_RGB0: return "RGB0";
+        case OV_VG1: return "VG1";
+        case OV_RGB1: return "RGB1";
+        case OV_VG2: return "VG2";
+        case OV_RGB2: return "RGB2";
+        default: return "Invalid";
+    }
+    return "Invalid";
+}
+
+inline eMdpPipeType getPipeType(eDest dest) {
+    switch(dest) {
+        case OV_VG0:
+        case OV_VG1:
+        case OV_VG2:
+            return OV_MDP_PIPE_VG;
+        case OV_RGB0:
+        case OV_RGB1:
+        case OV_RGB2:
+            return OV_MDP_PIPE_RGB;
+        default:
+            return OV_MDP_PIPE_ANY;
+    }
+    return OV_MDP_PIPE_ANY;
+}
+
 } // namespace utils ends
 
 //--------------------Class Res stuff (namespace overlay only) -----------
diff --git a/liboverlay/pipes/overlayGenPipe.cpp b/liboverlay/pipes/overlayGenPipe.cpp
new file mode 100644
index 0000000..ecb3b16
--- /dev/null
+++ b/liboverlay/pipes/overlayGenPipe.cpp
@@ -0,0 +1,222 @@
+/*
+* Copyright (c) 2012, The Linux Foundation. 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 The Linux Foundation 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.
+*/
+
+#include "overlayGenPipe.h"
+
+namespace overlay {
+
+GenericPipe::GenericPipe(int dpy) : mFbNum(dpy), mRot(0), mRotUsed(false),
+        pipeState(CLOSED) {
+    init();
+}
+
+GenericPipe::~GenericPipe() {
+    close();
+}
+
+bool GenericPipe::init()
+{
+    ALOGE_IF(DEBUG_OVERLAY, "GenericPipe init");
+    mRotUsed = false;
+
+    if(!mCtrlData.ctrl.init(mFbNum)) {
+        ALOGE("GenericPipe failed to init ctrl");
+        return false;
+    }
+
+    if(!mCtrlData.data.init(mFbNum)) {
+        ALOGE("GenericPipe failed to init data");
+        return false;
+    }
+
+    //get a new rotator object, take ownership
+    mRot = Rotator::getRotator();
+
+    return true;
+}
+
+bool GenericPipe::close() {
+    bool ret = true;
+
+    if(!mCtrlData.ctrl.close()) {
+        ALOGE("GenericPipe failed to close ctrl");
+        ret = false;
+    }
+    if (!mCtrlData.data.close()) {
+        ALOGE("GenericPipe failed to close data");
+        ret = false;
+    }
+
+    delete mRot;
+    mRot = 0;
+
+    setClosed();
+    return ret;
+}
+
+bool GenericPipe::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);
+}
+
+bool GenericPipe::setCrop(
+        const overlay::utils::Dim& d) {
+    return mCtrlData.ctrl.setCrop(d);
+}
+
+bool GenericPipe::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);
+}
+
+bool GenericPipe::setPosition(const utils::Dim& d)
+{
+    return mCtrlData.ctrl.setPosition(d);
+}
+
+bool GenericPipe::commit() {
+    bool ret = false;
+    //If wanting to use rotator, start it.
+    if(mRotUsed) {
+        if(!mRot->commit()) {
+            ALOGE("GenPipe Rotator commit failed");
+            //If rot commit fails, flush rotator session, memory, fd and create
+            //a hollow rotator object
+            delete mRot;
+            mRot = Rotator::getRotator();
+            pipeState = CLOSED;
+            return false;
+        }
+    }
+
+    ret = mCtrlData.ctrl.commit();
+
+    //If mdp commit fails, flush rotator session, memory, fd and create a hollow
+    //rotator object
+    if(ret == false) {
+        delete mRot;
+        mRot = Rotator::getRotator();
+    }
+
+    pipeState = ret ? OPEN : CLOSED;
+    return ret;
+}
+
+bool GenericPipe::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);
+}
+
+int GenericPipe::getCtrlFd() const {
+    return mCtrlData.ctrl.getFd();
+}
+
+utils::ScreenInfo GenericPipe::getScreenInfo() const
+{
+    return mCtrlData.ctrl.getScreenInfo();
+}
+
+utils::Dim GenericPipe::getCrop() const
+{
+    return mCtrlData.ctrl.getCrop();
+}
+
+void GenericPipe::dump() const
+{
+    ALOGE("== Dump Generic pipe start ==");
+    ALOGE("pipe state = %d", (int)pipeState);
+    OVASSERT(mRot, "GenericPipe should have a valid Rot");
+    mCtrlData.ctrl.dump();
+    mCtrlData.data.dump();
+    mRot->dump();
+    ALOGE("== Dump Generic pipe end ==");
+}
+
+bool GenericPipe::isClosed() const  {
+    return (pipeState == CLOSED);
+}
+
+bool GenericPipe::isOpen() const  {
+    return (pipeState == OPEN);
+}
+
+bool GenericPipe::setClosed() {
+    pipeState = CLOSED;
+    return true;
+}
+
+} //namespace overlay
diff --git a/liboverlay/pipes/overlayGenPipe.h b/liboverlay/pipes/overlayGenPipe.h
index cbcb05a..d0bb3a8 100644
--- a/liboverlay/pipes/overlayGenPipe.h
+++ b/liboverlay/pipes/overlayGenPipe.h
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
+* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
@@ -10,7 +10,7 @@
 *      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
+*    * Neither the name of The Linux Foundation nor the names of its
 *      contributors may be used to endorse or promote products derived
 *      from this software without specific prior written permission.
 *
@@ -36,15 +36,15 @@
 
 namespace overlay {
 
-template <int PANEL>
+
 class GenericPipe : utils::NoCopy {
 public:
     /* ctor */
-    explicit GenericPipe();
+    explicit GenericPipe(int dpy);
     /* dtor */
     ~GenericPipe();
     /* CTRL/DATA init. Not owning rotator, will not  init it */
-    bool init(RotatorBase* rot);
+    bool init();
     /* CTRL/DATA close. Not owning rotator, will not close it */
     bool close();
 
@@ -73,12 +73,6 @@
     /* retrieve cached crop data */
     utils::Dim getCrop() const;
 
-    /* return aspect ratio from ctrl data */
-    utils::Dim getAspectRatio(const utils::Whf& whf) const;
-
-    /* return aspect ratio from ctrl data for true UI mirroring */
-    utils::Dim getAspectRatio(const utils::Dim& dim) const;
-
     /* is closed */
     bool isClosed() const;
 
@@ -94,12 +88,12 @@
     /* set Closed pipe */
     bool setClosed();
 
+    int mFbNum;
+
     /* Ctrl/Data aggregator */
     CtrlData mCtrlData;
 
-    /* rotator mdp base
-     * Can point to NullRotator or to Rotator*/
-    RotatorBase* mRot;
+    Rotator* mRot;
 
     //Whether rotator is used for 0-rot or otherwise
     bool mRotUsed;
@@ -112,223 +106,6 @@
     ePipeState pipeState;
 };
 
-//------------------------Inlines and Templates ----------------------
-
-template <int PANEL>
-GenericPipe<PANEL>::GenericPipe() : mRot(0), mRotUsed(false),
-        pipeState(CLOSED) {
-}
-
-template <int PANEL>
-GenericPipe<PANEL>::~GenericPipe() {
-    close();
-}
-
-template <int PANEL>
-bool GenericPipe<PANEL>::init(RotatorBase* rot)
-{
-    ALOGE_IF(DEBUG_OVERLAY, "GenericPipe init");
-    OVASSERT(rot, "rot is null");
-
-    // init ctrl and data
-    uint32_t fbnum = utils::getFBForPanel(PANEL);
-
-    if(!mCtrlData.ctrl.init(fbnum)) {
-        ALOGE("GenericPipe failed to init ctrl");
-        return false;
-    }
-
-    if(!mCtrlData.data.init(fbnum)) {
-        ALOGE("GenericPipe failed to init data");
-        return false;
-    }
-
-    //Cache the rot ref. Ownership is with OverlayImpl.
-    mRot = rot;
-
-    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;
-
-    bool ret = true;
-
-    if(!mCtrlData.ctrl.close()) {
-        ALOGE("GenericPipe failed to close ctrl");
-        ret = false;
-    }
-    if (!mCtrlData.data.close()) {
-        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>::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 bool GenericPipe<PANEL>::setCrop(
-        const overlay::utils::Dim& d) {
-    return mCtrlData.ctrl.setCrop(d);
-}
-
-template <int PANEL>
-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 {
-    return mCtrlData.ctrl.getFd();
-}
-
-template <int PANEL>
-inline utils::Dim GenericPipe<PANEL>::getAspectRatio(
-        const utils::Whf& whf) const
-{
-    return mCtrlData.ctrl.getAspectRatio(whf);
-}
-
-template <int PANEL>
-inline utils::Dim GenericPipe<PANEL>::getAspectRatio(
-        const utils::Dim& dim) const
-{
-    return mCtrlData.ctrl.getAspectRatio(dim);
-}
-
-template <int PANEL>
-inline utils::ScreenInfo GenericPipe<PANEL>::getScreenInfo() const
-{
-    return mCtrlData.ctrl.getScreenInfo();
-}
-
-template <int PANEL>
-inline utils::Dim GenericPipe<PANEL>::getCrop() const
-{
-    return mCtrlData.ctrl.getCrop();
-}
-
-template <int PANEL>
-void GenericPipe<PANEL>::dump() const
-{
-    ALOGE("== Dump Generic pipe start ==");
-    ALOGE("pipe state = %d", (int)pipeState);
-    OVASSERT(mRot, "GenericPipe should have a valid Rot");
-    mCtrlData.ctrl.dump();
-    mCtrlData.data.dump();
-    mRot->dump();
-    ALOGE("== Dump Generic pipe end ==");
-}
-
-template <int PANEL>
-inline bool GenericPipe<PANEL>::isClosed() const  {
-    return (pipeState == CLOSED);
-}
-
-template <int PANEL>
-inline bool GenericPipe<PANEL>::isOpen() const  {
-    return (pipeState == OPEN);
-}
-
-template <int PANEL>
-inline bool GenericPipe<PANEL>::setClosed() {
-    pipeState = CLOSED;
-    return true;
-}
-
 } //namespace overlay
 
 #endif // OVERLAY_GENERIC_PIPE_H
diff --git a/liboverlay/pipes/overlayUIMirrorPipe.h b/liboverlay/pipes/overlayUIMirrorPipe.h
deleted file mode 100644
index c2b73bd..0000000
--- a/liboverlay/pipes/overlayUIMirrorPipe.h
+++ /dev/null
@@ -1,169 +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_UI_PIPE_H
-#define OVERLAY_UI_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 UIMirrorPipe : utils::NoCopy {
-public:
-    /* Please look at overlayGenPipe.h for info */
-    explicit UIMirrorPipe();
-    ~UIMirrorPipe();
-    bool init(RotatorBase* rot);
-    bool close();
-    bool commit();
-    bool queueBuffer(int fd, uint32_t offset);
-    bool setCrop(const utils::Dim& dim);
-    bool setPosition(const utils::Dim& dim);
-    bool setTransform(const utils::eTransform& param);
-    bool setSource(const utils::PipeArgs& args);
-    void dump() const;
-private:
-    overlay::GenericPipe<ovutils::EXTERNAL> mUI;
-    utils::eTransform mPrimFBOr; //Primary FB's orientation
-};
-
-//----------------------------Inlines -----------------------------
-
-inline UIMirrorPipe::UIMirrorPipe() { mPrimFBOr = utils::OVERLAY_TRANSFORM_0; }
-inline UIMirrorPipe::~UIMirrorPipe() { close(); }
-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 bool UIMirrorPipe::queueBuffer(int fd, uint32_t offset) {
-    return mUI.queueBuffer(fd, offset);
-}
-inline bool UIMirrorPipe::setCrop(const utils::Dim& dim) {
-    return mUI.setCrop(dim); }
-
-inline bool UIMirrorPipe::setPosition(const utils::Dim& dim) {
-    ovutils::Dim pdim;
-    //using utils::eTransform;
-    switch (mPrimFBOr) {
-        case utils::OVERLAY_TRANSFORM_0:
-        case utils::OVERLAY_TRANSFORM_ROT_180:
-            {
-                ovutils::Whf whf(dim.w, dim.h, 0);
-                pdim = mUI.getAspectRatio(whf);
-                break;
-            }
-        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.h, dim.w, 0);
-                pdim = mUI.getAspectRatio(whf);
-                break;
-            }
-        default:
-            ALOGE("%s: Unknown orientation %d", __FUNCTION__, dim.o);
-            return false;
-    }
-    return mUI.setPosition(pdim);
-}
-
-inline bool UIMirrorPipe::setTransform(const utils::eTransform& param) {
-
-    //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) {
-        case utils::OVERLAY_TRANSFORM_0:
-            transform = utils::OVERLAY_TRANSFORM_0;
-            break;
-        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 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 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__,
-                    static_cast<int>(param));
-            return false;
-    }
-
-    return mUI.setTransform(transform);
-}
-
-inline bool UIMirrorPipe::setSource(const utils::PipeArgs& args) {
-    utils::PipeArgs arg(args);
-
-    // Rotator flag enabled because buffer comes from fb
-    arg.rotFlags = utils::ROT_FLAG_ENABLED;
-
-    // For true UI mirroring, want the UI to go through available RGB pipe
-    // so do not set the PIPE SHARE flag which allocates VG pipe
-    if (utils::FrameBufferInfo::getInstance()->supportTrueMirroring()) {
-        arg.mdpFlags = static_cast<utils::eMdpFlags>(
-                arg.mdpFlags & ~utils::OV_MDP_PIPE_SHARE);
-    }
-
-    return mUI.setSource(arg);
-}
-inline void UIMirrorPipe::dump() const {
-    ALOGE("UI Mirror Pipe");
-    mUI.dump();
-}
-
-
-} // overlay
-
-#endif // OVERLAY_UI_PIPE_H
diff --git a/liboverlay/pipes/overlayVideoExtPipe.h b/liboverlay/pipes/overlayVideoExtPipe.h
deleted file mode 100644
index d4e1f3f..0000000
--- a/liboverlay/pipes/overlayVideoExtPipe.h
+++ /dev/null
@@ -1,111 +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_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 setCrop(const utils::Dim& dim);
-    bool setPosition(const utils::Dim& dim);
-    bool setTransform(const utils::eTransform& param);
-    bool setSource(const utils::PipeArgs& args);
-    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::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 void VideoExtPipe::dump() const {
-    ALOGE("Video Ext Pipe");
-    mVideoExt.dump();
-}
-
-
-} // overlay
-
-#endif // OVERLAY_VIDEO_EXT_PIPE_H