hwc/overlay: validate and prepare frame

Send the entire frame (array of overlays) to driver, so that it would
check pipes params and the whole frame wrt bandwidth and SMP.

Now, the overlay's commit API just prepares an overlay object but
makes no ioctl calls.

If the driver finds the frame, as a whole, to be not ok, the
validation fails and overlay/hwc return silently.

If a certain overlay object is mis-configured or pipes are
unavailable, the driver sets the number of objects it processed.
Overlay uses this to dump the incorrect config.

Change-Id: Ifb2b7fadc6bd6d9d94a35ba3908fbd832f41447f
diff --git a/liboverlay/overlay.cpp b/liboverlay/overlay.cpp
index ad23e84..6feffc4 100644
--- a/liboverlay/overlay.cpp
+++ b/liboverlay/overlay.cpp
@@ -69,13 +69,6 @@
         PipeBook::resetAllocation(i);
     }
     mDumpStr[0] = '\0';
-
-#ifdef USES_QSEED_SCALAR
-    Scale *scalar = getScalar();
-    if(scalar) {
-        scalar->configBegin();
-    }
-#endif
 }
 
 void Overlay::configDone() {
@@ -98,13 +91,6 @@
     }
     dump();
     PipeBook::save();
-
-#ifdef USES_QSEED_SCALAR
-    Scale *scalar = getScalar();
-    if(scalar) {
-        scalar->configDone();
-    }
-#endif
 }
 
 int Overlay::getPipeId(utils::eDest dest) {
@@ -435,6 +421,22 @@
     }
 }
 
+bool Overlay::validateAndSet(const int& dpy, const int& fbFd) {
+    GenericPipe* pipeArray[PipeBook::NUM_PIPES];
+    memset(&pipeArray, 0, sizeof(pipeArray));
+
+    int num = 0;
+    for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
+        if(PipeBook::isUsed(i) && mPipeBook[i].valid() &&
+                mPipeBook[i].mDisplay == dpy) {
+            pipeArray[num++] = mPipeBook[i].mPipe;
+        }
+    }
+
+    //Protect against misbehaving clients
+    return num ? GenericPipe::validateAndSet(pipeArray, num, fbFd) : true;
+}
+
 void Overlay::initScalar() {
 #ifdef USES_QSEED_SCALAR
     if(sLibScaleHandle == NULL) {