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.cpp b/libhwcomposer/hwc.cpp
index a81e761..42f5c85 100644
--- a/libhwcomposer/hwc.cpp
+++ b/libhwcomposer/hwc.cpp
@@ -30,7 +30,6 @@
 #include <overlayRotator.h>
 #include <mdp_version.h>
 #include "hwc_utils.h"
-#include "hwc_video.h"
 #include "hwc_fbupdate.h"
 #include "hwc_mdpcomp.h"
 #include "external.h"
@@ -102,8 +101,6 @@
 
         if(ctx->mFBUpdate[i])
             ctx->mFBUpdate[i]->reset();
-        if(ctx->mVidOv[i])
-            ctx->mVidOv[i]->reset();
         if(ctx->mCopyBit[i])
             ctx->mCopyBit[i]->reset();
     }
@@ -139,21 +136,18 @@
         uint32_t last = list->numHwLayers - 1;
         hwc_layer_1_t *fbLayer = &list->hwLayers[last];
         if(fbLayer->handle) {
-            if(list->numHwLayers > MAX_NUM_LAYERS) {
-                ctx->mFBUpdate[dpy]->prepare(ctx, list);
-                return 0;
-            }
             setListStats(ctx, list, dpy);
-            bool ret = ctx->mMDPComp->prepare(ctx, list);
-            if(!ret) {
-                // IF MDPcomp fails use this route
-                ctx->mVidOv[dpy]->prepare(ctx, list);
-                ctx->mFBUpdate[dpy]->prepare(ctx, list);
-                // Use Copybit, when MDP comp fails
-                if(ctx->mCopyBit[dpy])
-                    ctx->mCopyBit[dpy]->prepare(ctx, list, dpy);
-                ctx->mLayerCache[dpy]->updateLayerCache(list);
-            }
+            int fbZOrder = ctx->mMDPComp[dpy]->prepare(ctx, list);
+            if(fbZOrder >= 0)
+                ctx->mFBUpdate[dpy]->prepare(ctx, list, fbZOrder);
+
+            /* Temporarily commenting out C2D until we support partial
+               copybit composition for mixed mode MDP
+
+            // Use Copybit, when MDP comp fails
+            if((fbZOrder >= 0) && ctx->mCopyBit[dpy])
+                ctx->mCopyBit[dpy]->prepare(ctx, list, dpy);
+            */
         }
     }
     return 0;
@@ -172,16 +166,17 @@
         if(!ctx->dpyAttr[dpy].isPause) {
             if(fbLayer->handle) {
                 ctx->mExtDispConfiguring = false;
-                if(list->numHwLayers > MAX_NUM_LAYERS) {
-                    ctx->mFBUpdate[dpy]->prepare(ctx, list);
-                    return 0;
-                }
                 setListStats(ctx, list, dpy);
-                ctx->mVidOv[dpy]->prepare(ctx, list);
-                ctx->mFBUpdate[dpy]->prepare(ctx, list);
-                ctx->mLayerCache[dpy]->updateLayerCache(list);
-                if(ctx->mCopyBit[dpy])
+                int fbZOrder = ctx->mMDPComp[dpy]->prepare(ctx, list);
+                if(fbZOrder >= 0)
+                    ctx->mFBUpdate[dpy]->prepare(ctx, list, fbZOrder);
+
+                /* Temporarily commenting out C2D until we support partial
+                   copybit composition for mixed mode MDP
+
+                if((fbZOrder >= 0) && ctx->mCopyBit[dpy])
                     ctx->mCopyBit[dpy]->prepare(ctx, list, dpy);
+                */
             }
         } else {
             // External Display is in Pause state.
@@ -299,7 +294,8 @@
                 // so that any pipe unsets gets committed
                 if (display_commit(ctx, dpy) < 0) {
                     ret = -1;
-                    ALOGE("%s:post failed for external display !! ", __FUNCTION__);
+                    ALOGE("%s:post failed for external display !! ",
+                          __FUNCTION__);
                 }
             } else {
             }
@@ -360,11 +356,8 @@
             copybitDone = ctx->mCopyBit[dpy]->draw(ctx, list, dpy, &fd);
         if(list->numHwLayers > 1)
             hwc_sync(ctx, list, dpy, fd);
-        if (!ctx->mVidOv[dpy]->draw(ctx, list)) {
-            ALOGE("%s: VideoOverlay draw failed", __FUNCTION__);
-            ret = -1;
-        }
-        if (!ctx->mMDPComp->draw(ctx, list)) {
+
+        if (!ctx->mMDPComp[dpy]->draw(ctx, list)) {
             ALOGE("%s: MDPComp draw failed", __FUNCTION__);
             ret = -1;
         }
@@ -413,8 +406,8 @@
         if(list->numHwLayers > 1)
             hwc_sync(ctx, list, dpy, fd);
 
-        if (!ctx->mVidOv[dpy]->draw(ctx, list)) {
-            ALOGE("%s: VideoOverlay::draw fail!", __FUNCTION__);
+        if (!ctx->mMDPComp[dpy]->draw(ctx, list)) {
+            ALOGE("%s: MDPComp draw failed", __FUNCTION__);
             ret = -1;
         }
 
@@ -558,7 +551,10 @@
     dumpsys_log(aBuf, "Qualcomm HWC state:\n");
     dumpsys_log(aBuf, "  MDPVersion=%d\n", ctx->mMDP.version);
     dumpsys_log(aBuf, "  DisplayPanel=%c\n", ctx->mMDP.panel);
-    ctx->mMDPComp->dump(aBuf);
+    for(int dpy = 0; dpy < MAX_DISPLAYS; dpy++) {
+        if(ctx->mMDPComp[dpy])
+            ctx->mMDPComp[dpy]->dump(aBuf);
+    }
     char ovDump[2048] = {'\0'};
     ctx->mOverlay->getDump(ovDump, 2048);
     dumpsys_log(aBuf, ovDump);