Merge "hwc: Do not set Secure flags for UI layers"
diff --git a/libhwcomposer/hwc.cpp b/libhwcomposer/hwc.cpp
index 84b1100..130f263 100644
--- a/libhwcomposer/hwc.cpp
+++ b/libhwcomposer/hwc.cpp
@@ -85,7 +85,6 @@
                   hwc_display_contents_1_t** displays) {
     memset(ctx->listStats, 0, sizeof(ctx->listStats));
     for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++){
-        ctx->listStats[i].yuvIndex = -1;
         hwc_display_contents_1_t *list = displays[i];
         // XXX:SurfaceFlinger no longer guarantees that this
         // value is reset on every prepare. However, for the layer
diff --git a/libhwcomposer/hwc_mdpcomp.cpp b/libhwcomposer/hwc_mdpcomp.cpp
index bbea007..ca3c4b5 100644
--- a/libhwcomposer/hwc_mdpcomp.cpp
+++ b/libhwcomposer/hwc_mdpcomp.cpp
@@ -471,24 +471,30 @@
             malloc(sizeof(PipeLayerPair) * currentFrame.count);
 
     if(isYuvPresent(ctx, dpy)) {
-        int nYuvIndex = ctx->listStats[dpy].yuvIndex;
-        hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
-        PipeLayerPair& info = currentFrame.pipeLayer[nYuvIndex];
-        MdpPipeInfo& pipe_info = info.pipeIndex;
-        pipe_info.index = getMdpPipe(ctx, MDPCOMP_OV_VG);
-        if(pipe_info.index < 0) {
-            ALOGD_IF(isDebug(), "%s: Unable to get pipe for Videos",
-                    __FUNCTION__);
-            return false;
+        int nYuvCount = ctx->listStats[dpy].yuvCount;
+
+        for(int index = 0; index < nYuvCount; index ++) {
+            int nYuvIndex = ctx->listStats[dpy].yuvIndices[index];
+            hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
+            PipeLayerPair& info = currentFrame.pipeLayer[nYuvIndex];
+            MdpPipeInfo& pipe_info = info.pipeIndex;
+            pipe_info.index = getMdpPipe(ctx, MDPCOMP_OV_VG);
+            if(pipe_info.index < 0) {
+                ALOGD_IF(isDebug(), "%s: Unable to get pipe for Videos",
+                        __FUNCTION__);
+                return false;
+            }
+            pipe_info.zOrder = nYuvIndex;
         }
-        pipe_info.zOrder = nYuvIndex;
     }
 
     for(int index = 0 ; index < layer_count ; index++ ) {
-        if(index  == ctx->listStats[dpy].yuvIndex )
+        hwc_layer_1_t* layer = &list->hwLayers[index];
+        private_handle_t *hnd = (private_handle_t *)layer->handle;
+
+        if(isYuvBuffer(hnd))
             continue;
 
-        hwc_layer_1_t* layer = &list->hwLayers[index];
         PipeLayerPair& info = currentFrame.pipeLayer[index];
         MdpPipeInfo& pipe_info = info.pipeIndex;
         pipe_info.index = getMdpPipe(ctx, MDPCOMP_OV_ANY);
diff --git a/libhwcomposer/hwc_utils.cpp b/libhwcomposer/hwc_utils.cpp
index 7a3adbb..e1f413c 100644
--- a/libhwcomposer/hwc_utils.cpp
+++ b/libhwcomposer/hwc_utils.cpp
@@ -172,15 +172,17 @@
 
     ctx->listStats[dpy].numAppLayers = list->numHwLayers - 1;
     ctx->listStats[dpy].fbLayerIndex = list->numHwLayers - 1;
-    ctx->listStats[dpy].yuvCount = 0;
-    ctx->listStats[dpy].yuvIndex = -1;
     ctx->listStats[dpy].skipCount = 0;
     ctx->listStats[dpy].needsAlphaScale = false;
+    ctx->listStats[dpy].yuvCount = 0;
 
     for (size_t i = 0; i < list->numHwLayers; i++) {
         hwc_layer_1_t const* layer = &list->hwLayers[i];
         private_handle_t *hnd = (private_handle_t *)layer->handle;
 
+        //reset stored yuv index
+        ctx->listStats[dpy].yuvIndices[i] = -1;
+
         if(list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
             continue;
         //We disregard FB being skip for now! so the else if
@@ -192,8 +194,9 @@
             ctx->listStats[dpy].needsAlphaScale = isAlphaScaled(layer);
 
         if (UNLIKELY(isYuvBuffer(hnd))) {
-            ctx->listStats[dpy].yuvCount++;
-            ctx->listStats[dpy].yuvIndex = i;
+            int& yuvCount = ctx->listStats[dpy].yuvCount;
+            ctx->listStats[dpy].yuvIndices[yuvCount] = i;
+            yuvCount++;
         }
     }
 }
diff --git a/libhwcomposer/hwc_utils.h b/libhwcomposer/hwc_utils.h
index 5316347..9692986 100644
--- a/libhwcomposer/hwc_utils.h
+++ b/libhwcomposer/hwc_utils.h
@@ -82,7 +82,7 @@
     int fbLayerIndex; //Always last for now. = numAppLayers
     //Video specific
     int yuvCount;
-    int yuvIndex;
+    int yuvIndices[MAX_NUM_LAYERS];
     bool needsAlphaScale;
 };
 
diff --git a/libhwcomposer/hwc_video.cpp b/libhwcomposer/hwc_video.cpp
index 41d4365..0c0a40d 100644
--- a/libhwcomposer/hwc_video.cpp
+++ b/libhwcomposer/hwc_video.cpp
@@ -34,7 +34,10 @@
 bool VideoOverlay::prepare(hwc_context_t *ctx, hwc_display_contents_1_t *list,
         int dpy) {
 
-    int yuvIndex =  ctx->listStats[dpy].yuvIndex;
+    if(ctx->listStats[dpy].yuvCount > 1)
+        return false;
+
+    int yuvIndex =  ctx->listStats[dpy].yuvIndices[0];
     sIsModeOn[dpy] = false;
 
     if(!ctx->mMDP.hasOverlay) {
@@ -184,7 +187,7 @@
         return true;
     }
 
-    int yuvIndex = ctx->listStats[dpy].yuvIndex;
+    int yuvIndex = ctx->listStats[dpy].yuvIndices[0];
     if(yuvIndex == -1) {
         return true;
     }