hwc: Implement mixed mode composition.

With this change we are moving  MDP composition from all-or-nothing
implementation to mixed mode implementation where layers can
partially be composited through MDP and while rest of the layers are
composed / cached in framebuffer.

        - Mixed mode design is based on layer caching
        - Mixed mode path is configured only when non-bypassing
          layers are cached.
        - Never allow mixed mode when FB needs to be  udpated.
        - If we cannot bypass all MDP comp marked layers, bail
          out completely.

Change-Id: Ie08f39db07e032b537f042d0d2bfe772ebfed049
diff --git a/libhwcomposer/hwc_utils.cpp b/libhwcomposer/hwc_utils.cpp
index 3245889..57f94fe 100644
--- a/libhwcomposer/hwc_utils.cpp
+++ b/libhwcomposer/hwc_utils.cpp
@@ -29,7 +29,6 @@
 #include "hwc_utils.h"
 #include "hwc_mdpcomp.h"
 #include "hwc_fbupdate.h"
-#include "hwc_video.h"
 #include "mdp_version.h"
 #include "hwc_copybit.h"
 #include "external.h"
@@ -118,10 +117,6 @@
         IFBUpdate::getObject(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres,
         HWC_DISPLAY_PRIMARY);
 
-    ctx->mVidOv[HWC_DISPLAY_PRIMARY] =
-        IVideoOverlay::getObject(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres,
-        HWC_DISPLAY_PRIMARY);
-
     // Check if the target supports copybit compostion (dyn/mdp/c2d) to
     // decide if we need to open the copybit module.
     int compositionType =
@@ -134,9 +129,11 @@
     }
 
     ctx->mExtDisplay = new ExternalDisplay(ctx);
-    for (uint32_t i = 0; i < MAX_DISPLAYS; i++)
-        ctx->mLayerCache[i] = new LayerCache();
-    ctx->mMDPComp = MDPComp::getObject(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres);
+
+    ctx->mMDPComp[HWC_DISPLAY_PRIMARY] =
+         MDPComp::getObject(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres,
+         HWC_DISPLAY_PRIMARY);
+
     MDPComp::init(ctx);
 
     pthread_mutex_init(&(ctx->vstate.lock), NULL);
@@ -191,16 +188,12 @@
             delete ctx->mFBUpdate[i];
             ctx->mFBUpdate[i] = NULL;
         }
-        if(ctx->mVidOv[i]) {
-            delete ctx->mVidOv[i];
-            ctx->mVidOv[i] = NULL;
+        if(ctx->mMDPComp[i]) {
+            delete ctx->mMDPComp[i];
+            ctx->mMDPComp[i] = NULL;
         }
     }
 
-    if(ctx->mMDPComp) {
-        delete ctx->mMDPComp;
-        ctx->mMDPComp = NULL;
-    }
 
     pthread_mutex_destroy(&(ctx->vstate.lock));
     pthread_cond_destroy(&(ctx->vstate.cond));
@@ -361,12 +354,28 @@
     }
 }
 
-bool isSecuring(hwc_context_t* ctx) {
+bool isSecuring(hwc_context_t* ctx, hwc_layer_1_t const* layer) {
     if((ctx->mMDP.version < qdutils::MDSS_V5) &&
        (ctx->mMDP.version > qdutils::MDP_V3_0) &&
         ctx->mSecuring) {
         return true;
     }
+    if (isSecureModePolicy(ctx->mMDP.version)) {
+        private_handle_t *hnd = (private_handle_t *)layer->handle;
+        if(ctx->mSecureMode) {
+            if (! isSecureBuffer(hnd)) {
+                ALOGD_IF(HWC_UTILS_DEBUG,"%s:Securing Turning ON ...",
+                         __FUNCTION__);
+                return true;
+            }
+        } else {
+            if (isSecureBuffer(hnd)) {
+                ALOGD_IF(HWC_UTILS_DEBUG,"%s:Securing Turning OFF ...",
+                         __FUNCTION__);
+                return true;
+            }
+        }
+    }
     return false;
 }
 
@@ -693,12 +702,12 @@
             getMdpFormat(hnd->format), hnd->size);
 
     if(isYuvBuffer(hnd) && ctx->mMDP.version >= qdutils::MDP_V4_2 &&
-                ctx->mMDP.version < qdutils::MDSS_V5) {
-        downscale = getDownscaleFactor(
-                crop.right - crop.left,
-                crop.bottom - crop.top,
-                dst.right - dst.left,
-                dst.bottom - dst.top);
+       ctx->mMDP.version < qdutils::MDSS_V5) {
+        downscale =  getDownscaleFactor(
+            crop.right - crop.left,
+            crop.bottom - crop.top,
+            dst.right - dst.left,
+            dst.bottom - dst.top);
         if(downscale) {
             rotFlags = ROT_DOWNSCALE_ENABLED;
         }
@@ -839,71 +848,4 @@
 
     return 0;
 }
-
-void LayerCache::resetLayerCache(int num) {
-    for(uint32_t i = 0; i < MAX_NUM_LAYERS; i++) {
-        hnd[i] = NULL;
-    }
-    numHwLayers = num;
-}
-
-void LayerCache::updateLayerCache(hwc_display_contents_1_t* list) {
-
-    int numFbLayers = 0;
-    int numCacheableLayers = 0;
-
-    canUseLayerCache = false;
-    //Bail if geometry changed or num of layers changed
-    if(list->flags & HWC_GEOMETRY_CHANGED ||
-       list->numHwLayers != numHwLayers ) {
-        resetLayerCache(list->numHwLayers);
-        return;
-    }
-
-    for(uint32_t i = 0; i < list->numHwLayers; i++) {
-        //Bail on skip layers
-        if(list->hwLayers[i].flags & HWC_SKIP_LAYER) {
-            resetLayerCache(list->numHwLayers);
-            return;
-        }
-
-        if(list->hwLayers[i].compositionType == HWC_FRAMEBUFFER) {
-            numFbLayers++;
-            if(hnd[i] == NULL) {
-                hnd[i] = list->hwLayers[i].handle;
-            } else if (hnd[i] ==
-                       list->hwLayers[i].handle) {
-                numCacheableLayers++;
-            } else {
-                hnd[i] = NULL;
-                return;
-            }
-        } else {
-            hnd[i] = NULL;
-        }
-    }
-    if(numFbLayers == numCacheableLayers)
-        canUseLayerCache = true;
-
-    //XXX: The marking part is separate, if MDP comp wants
-    // to use it in the future. Right now getting MDP comp
-    // to use this is more trouble than it is worth.
-    markCachedLayersAsOverlay(list);
-}
-
-void LayerCache::markCachedLayersAsOverlay(hwc_display_contents_1_t* list) {
-    //This optimization only works if ALL the layer handles
-    //that were on the framebuffer didn't change.
-    if(canUseLayerCache){
-        for(uint32_t i = 0; i < list->numHwLayers; i++) {
-            if (list->hwLayers[i].handle &&
-                list->hwLayers[i].handle == hnd[i] &&
-                list->hwLayers[i].compositionType != HWC_FRAMEBUFFER_TARGET)
-            {
-                list->hwLayers[i].compositionType = HWC_OVERLAY;
-            }
-        }
-    }
-}
-
 };//namespace qhwc