hwc: [8x26]Never allow primary get DMA pipe when external connect

For 8x26, if external display is connected, DMA pipe should never
be occupied by primary display. Otherwise, external display would
lack DMA pipe if switch to GPU composition.

This patch refines former commit: 9c1eb2be21a4952ee097d33

CRs-Fixed: 640934
Change-Id: Idc64b724cfacf9e8e22ca73e4e443e8d989e1212
diff --git a/libhwcomposer/hwc_mdpcomp.cpp b/libhwcomposer/hwc_mdpcomp.cpp
index 5f4d592..69d4f09 100644
--- a/libhwcomposer/hwc_mdpcomp.cpp
+++ b/libhwcomposer/hwc_mdpcomp.cpp
@@ -611,15 +611,6 @@
             ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
             return false;
         }
-
-        //For 8x26, if there is only one layer which needs scale for secondary
-        //while no scale for primary display, DMA pipe is occupied by primary.
-        //If need to fall back to GLES composition, virtual display lacks DMA
-        //pipe and error is reported.
-        if(qdutils::MDPVersion::getInstance().is8x26() &&
-                                mDpy >= HWC_DISPLAY_EXTERNAL &&
-                                qhwc::needsScaling(layer))
-            return false;
     }
 
     mCurrentFrame.fbCount = 0;
@@ -1406,6 +1397,7 @@
                 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres > 1024);
         pipeSpecs.dpy = mDpy;
         pipeSpecs.fb = false;
+        pipeSpecs.numActiveDisplays = ctx->numActiveDisplays;
 
         pipe_info.index = ctx->mOverlay->getPipe(pipeSpecs);
 
diff --git a/liboverlay/overlay.cpp b/liboverlay/overlay.cpp
index c1757ad..6cb30d3 100644
--- a/liboverlay/overlay.cpp
+++ b/liboverlay/overlay.cpp
@@ -203,7 +203,9 @@
     if(pipeSpecs.formatClass == FORMAT_YUV) { //video
         return nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
     } else if(pipeSpecs.fb == false) { //RGB app layers
-        if(not pipeSpecs.needsScaling) {
+        if((not pipeSpecs.needsScaling) and
+          (not (pipeSpecs.numActiveDisplays > 1 &&
+                pipeSpecs.dpy == DPY_PRIMARY))) {
             dest = nextPipe(OV_MDP_PIPE_DMA, pipeSpecs.dpy, pipeSpecs.mixer);
         }
         if(dest == OV_INVALID) {
@@ -220,7 +222,9 @@
                 dest = nextPipe(OV_MDP_PIPE_VG, pipeSpecs.dpy, pipeSpecs.mixer);
             }
         }
-        if(dest == OV_INVALID and (not pipeSpecs.needsScaling)) {
+        if(dest == OV_INVALID and (not pipeSpecs.needsScaling) and
+          (not (pipeSpecs.numActiveDisplays > 1 &&
+                pipeSpecs.dpy == DPY_PRIMARY))) {
             dest = nextPipe(OV_MDP_PIPE_DMA, pipeSpecs.dpy, pipeSpecs.mixer);
         }
     }
diff --git a/liboverlay/overlay.h b/liboverlay/overlay.h
index fa19dc3..042ebc2 100644
--- a/liboverlay/overlay.h
+++ b/liboverlay/overlay.h
@@ -57,12 +57,13 @@
 
     struct PipeSpecs {
         PipeSpecs() : formatClass(FORMAT_RGB), needsScaling(false), fb(false),
-                dpy(DPY_PRIMARY), mixer(MIXER_DEFAULT) {}
+                dpy(DPY_PRIMARY), mixer(MIXER_DEFAULT), numActiveDisplays(1) {}
         int formatClass;
         bool needsScaling;
         bool fb;
         int dpy;
         int mixer;
+        int numActiveDisplays;
     };
 
     /* dtor close */