liboverlay: Refactor, bug-fixes, upgrade.

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

Change-Id: I34a9a2a0f1255b3467a0abbaa254d0b584e901ce
diff --git a/libhwcomposer/hwc.cpp b/libhwcomposer/hwc.cpp
index a5e31ef..699e2ac 100644
--- a/libhwcomposer/hwc.cpp
+++ b/libhwcomposer/hwc.cpp
@@ -23,6 +23,7 @@
 #include <EGL/egl.h>
 
 #include "hwc_utils.h"
+#include "hwc_video.h"
 
 using namespace qhwc;
 
@@ -65,19 +66,19 @@
 static int hwc_prepare(hwc_composer_device_t *dev, hwc_layer_list_t* list)
 {
     hwc_context_t* ctx = (hwc_context_t*)(dev);
+    ctx->overlayInUse = false;
+
+    //Prepare is called after a vsync, so unlock previous buffers here.
+    ctx->qbuf->unlockAllPrevious();
+
     if (LIKELY(list)) {
         getLayerStats(ctx, list);
-        cleanOverlays(ctx);
-        for (int i=list->numHwLayers-1; i >= 0 ; i--) {
-            private_handle_t *hnd =
-                (private_handle_t *)list->hwLayers[i].handle;
-            if (isSkipLayer(&list->hwLayers[i])) {
-                break;
-            } else if(isYuvBuffer(hnd)) {
-                handleYUV(ctx,&list->hwLayers[i]);
-            } else {
-                list->hwLayers[i].compositionType = HWC_FRAMEBUFFER;
-            }
+        if(VideoOverlay::prepare(ctx, list)) {
+            ctx->overlayInUse = true;
+            //Nothing here
+        } else if (0) {
+            //Other features
+            ctx->overlayInUse = true;
         }
     }
     return 0;
@@ -91,21 +92,16 @@
     int ret = 0;
     hwc_context_t* ctx = (hwc_context_t*)(dev);
     if (LIKELY(list)) {
-        for (size_t i=0; i<list->numHwLayers; i++) {
-            if (list->hwLayers[i].flags & HWC_SKIP_LAYER) {
-                continue;
-            } else if (list->hwLayers[i].compositionType == HWC_OVERLAY) {
-                drawLayerUsingOverlay(ctx, &(list->hwLayers[i]));
-            }
-        }
-        //XXX: Handle vsync with FBIO_WAITFORVSYNC ioctl
-        //All other operations (including pan display) should be NOWAIT
+        VideoOverlay::draw(ctx, list);
         EGLBoolean sucess = eglSwapBuffers((EGLDisplay)dpy, (EGLSurface)sur);
     } else {
-        //XXX: put in a wrapper for non overlay targets
-        setOverlayState(ctx, ovutils::OV_CLOSED);
+        ctx->mOverlay->setState(ovutils::OV_CLOSED);
+        ctx->qbuf->unlockAllPrevious();
     }
-    ctx->qbuf->unlockAllPrevious();
+
+    if(!ctx->overlayInUse)
+        ctx->mOverlay->setState(ovutils::OV_CLOSED);
+
     return ret;
 }