hwc: Use correct z-order in video overlay

Set z-order of video layer to 0 and framebuffer to 1 in case
of video overlay composition so that the blending takes effect.
Also set is_fg OFF for framebuffer.

Change-Id: I05f930074d265d690f29a1003b7c28077df89bbf
CRs-fixed: 458180
diff --git a/libhwcomposer/hwc_fbupdate.cpp b/libhwcomposer/hwc_fbupdate.cpp
index 7a740ee..5f524c7 100644
--- a/libhwcomposer/hwc_fbupdate.cpp
+++ b/libhwcomposer/hwc_fbupdate.cpp
@@ -21,6 +21,7 @@
 #define DEBUG_FBUPDATE 0
 #include <gralloc_priv.h>
 #include "hwc_fbupdate.h"
+#include "hwc_video.h"
 
 namespace qhwc {
 
@@ -82,11 +83,20 @@
         mDest = dest;
 
         ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_FLAGS_NONE;
+        // If any of the layers has pre-multiplied alpha, set Pre multiplied
+        // Flag as the compositied output is alpha pre-multiplied.
+        if(ctx->listStats[mDpy].preMultipliedAlpha == true)
+               ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_BLEND_FG_PREMULT);
+
+        ovutils::eZorder z_order =
+              ctx->mVidOv[mDpy]->isModeOn()?ovutils::ZORDER_1:ovutils::ZORDER_0;
+        ovutils::eIsFg is_fg =
+           ctx->mVidOv[mDpy]->isModeOn()? ovutils::IS_FG_OFF:ovutils::IS_FG_SET;
 
         ovutils::PipeArgs parg(mdpFlags,
                 info,
-                ovutils::ZORDER_0,
-                ovutils::IS_FG_SET,
+                z_order,
+                is_fg,
                 ovutils::ROT_FLAGS_NONE);
         ov.setSource(parg, dest);
 
@@ -189,11 +199,20 @@
         mDestRight = destR;
 
         ovutils::eMdpFlags mdpFlagsL = ovutils::OV_MDP_FLAGS_NONE;
+        //If any layer has pre-multiplied alpha, set Pre multiplied
+        //Flag as the compositied output is alpha pre-multiplied.
+        if(ctx->listStats[mDpy].preMultipliedAlpha == true)
+            ovutils::setMdpFlags(mdpFlagsL, ovutils::OV_MDP_BLEND_FG_PREMULT);
+
+        ovutils::eZorder z_order =
+              ctx->mVidOv[mDpy]->isModeOn()?ovutils::ZORDER_1:ovutils::ZORDER_0;
+        ovutils::eIsFg is_fg =
+           ctx->mVidOv[mDpy]->isModeOn()? ovutils::IS_FG_OFF:ovutils::IS_FG_SET;
 
         ovutils::PipeArgs pargL(mdpFlagsL,
                 info,
-                ovutils::ZORDER_0,
-                ovutils::IS_FG_SET,
+                z_order,
+                is_fg,
                 ovutils::ROT_FLAGS_NONE);
         ov.setSource(pargL, destL);
 
@@ -201,8 +220,8 @@
         ovutils::setMdpFlags(mdpFlagsR, ovutils::OV_MDSS_MDP_RIGHT_MIXER);
         ovutils::PipeArgs pargR(mdpFlagsR,
                 info,
-                ovutils::ZORDER_0,
-                ovutils::IS_FG_SET,
+                z_order,
+                is_fg,
                 ovutils::ROT_FLAGS_NONE);
         ov.setSource(pargR, destR);