hwc/fb/overlay: wait for fbpost and pan display

Draw sequence in hwc_set
--eglSwapBuffers
--wait for fb_post. Its ok to draw to External only at this point.
--draw to external   | Parallel with PAN
--commit to external | Parallel with PAN
--wait for pan (happening in fb_post) to finish.

Call MSMFB_OVERLAY_SET ioctl only when params change.

These thing together ensure a correct sequence and should fix tearing and
stuttering, the latter assuming there are no other display pipeline delays.

Acked-by: Arun Kumar K.R <akumarkr@codeaurora.org>

Change-Id: Ibb0ad8485fa6b30dc6ac07ae8b25a760941c08ce
diff --git a/libhwcomposer/hwc.cpp b/libhwcomposer/hwc.cpp
index 4a73c64..a46a172 100644
--- a/libhwcomposer/hwc.cpp
+++ b/libhwcomposer/hwc.cpp
@@ -193,9 +193,14 @@
             MDPComp::draw(ctx, list);
             EGLBoolean success = eglSwapBuffers((EGLDisplay)list->dpy,
                                                 (EGLSurface)list->sur);
+            wait4fbPost(ctx);
+            //Can draw to HDMI only when fb_post is reached
             UIMirrorOverlay::draw(ctx);
+            //HDMI commit and primary commit (PAN) happening in parallel
             if(ctx->mExtDisplay->getExternalDisplay())
                 ctx->mExtDisplay->commit();
+            //Virtual barrier for threads to finish
+            wait4Pan(ctx);
         } else {
             ctx->mOverlay->setState(ovutils::OV_CLOSED);
             ctx->qbuf->unlockAll();