hwc: Handle multiple videos with priority to secure

In video handling this patch makes sure:
1) Sufficient VG pipes are available, not just any pipes
2) If VG pipes are insufficient in multi-video scenarios
    preference is given to secure videos

Change-Id: I170592463a1c28348108a1b12d60908cf3063d7d
diff --git a/liboverlay/overlay.h b/liboverlay/overlay.h
index 4b91038..9d7f5c8 100644
--- a/liboverlay/overlay.h
+++ b/liboverlay/overlay.h
@@ -86,6 +86,8 @@
     int availablePipes(int dpy, int mixer);
     /* Returns available ("unallocated") pipes for a display */
     int availablePipes(int dpy);
+    /* Returns available ("unallocated") pipe of given type for a display */
+    int availablePipes(int dpy, utils::eMdpPipeType type);
     /* Returns if any of the requested pipe type is attached to any of the
      * displays
      */
@@ -215,6 +217,19 @@
     return avail;
 }
 
+inline int Overlay::availablePipes(int dpy, utils::eMdpPipeType type) {
+    int avail = 0;
+    for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
+        if((mPipeBook[i].mDisplay == DPY_UNUSED ||
+            mPipeBook[i].mDisplay == dpy) &&
+            PipeBook::isNotAllocated(i) &&
+            type == PipeBook::getPipeType((utils::eDest)i)) {
+            avail++;
+        }
+    }
+    return avail;
+}
+
 inline void Overlay::setDMAMode(const int& mode) {
     if(mode == DMA_LINE_MODE || mode == DMA_BLOCK_MODE)
         sDMAMode = mode;