overlay: pipe reservation mechanism for overlay

This change provides APIs for this mechanism. In a case where
pipeid corresponding to the layer needs to be reserved, then pipe
session could be initiated for that pipe. This will ensure that
the pipe is not garbage collected, and is manually destroyed when
the session (or pipe requirement) has been ended. This change
also provides the api to locally allocate the dest for the given
reserved overlay pipeid.

Change-Id: I3fec3e26f69305c280395b7a92edf9e457398052
diff --git a/liboverlay/overlay.h b/liboverlay/overlay.h
index 854fa30..13debb7 100644
--- a/liboverlay/overlay.h
+++ b/liboverlay/overlay.h
@@ -76,6 +76,15 @@
      * asisgned to a mixer within a display it cannot be reused for another
      * mixer without being UNSET once*/
     utils::eDest nextPipe(utils::eMdpPipeType, int dpy, int mixer);
+    /* Returns the eDest corresponding to an already allocated pipeid.
+     * Useful for the reservation case, when libvpu reserves the pipe at its
+     * end, and expect the overlay to allocate a given pipe for a layer.
+     */
+    utils::eDest reservePipe(int pipeid);
+    /* getting dest for the given pipeid */
+    utils::eDest getDest(int pipeid);
+    /* getting overlay.pipeid for the given dest */
+    int getPipeId(utils::eDest dest);
 
     void setSource(const utils::PipeArgs args, utils::eDest dest);
     void setCrop(const utils::Dim& d, utils::eDest dest);
@@ -85,6 +94,14 @@
     bool commit(utils::eDest dest);
     bool queueBuffer(int fd, uint32_t offset, utils::eDest dest);
 
+    /* pipe reservation session is running */
+    bool sessionInProgress(utils::eDest dest);
+    /* pipe reservation session has ended*/
+    bool isSessionEnded(utils::eDest dest);
+    /* start session for the pipe reservation */
+    void startSession(utils::eDest dest);
+    /* end all started sesisons */
+    void endAllSessions();
     /* Returns available ("unallocated") pipes for a display's mixer */
     int availablePipes(int dpy, int mixer);
     /* Returns available ("unallocated") pipes for a display */
@@ -160,7 +177,13 @@
 
         static int NUM_PIPES;
         static utils::eMdpPipeType pipeTypeLUT[utils::OV_MAX];
-
+        /* Session for reserved pipes */
+        enum Session {
+            NONE,
+            START,
+            END
+        };
+        Session mSession;
 
     private:
         //usage tracks if a successful commit happened. So a pipe could be
@@ -312,6 +335,18 @@
     return pipeTypeLUT[(int)dest];
 }
 
+inline void Overlay::startSession(utils::eDest dest) {
+    mPipeBook[(int)dest].mSession = PipeBook::START;
+}
+
+inline bool Overlay::sessionInProgress(utils::eDest dest) {
+    return (mPipeBook[(int)dest].mSession == PipeBook::START);
+}
+
+inline bool Overlay::isSessionEnded(utils::eDest dest) {
+    return (mPipeBook[(int)dest].mSession == PipeBook::END);
+}
+
 inline const char* Overlay::PipeBook::getDestStr(utils::eDest dest) {
     switch(getPipeType(dest)) {
         case utils::OV_MDP_PIPE_RGB: return "RGB";