hwcomposer: keep secure content in an overlay when below skip layer

Secure content can not be displayed unless in an overlay.  Since
getLayerStats marks all layers under the skip layer for framebuffer
composition, when there is a skip layer on top of protected content,
the protected content disappears since surfaceflinger doesn't draw
protected layers.

Acked-by: Amara Venkata Mastan Manoj Kumar <manojavm@codeaurora.org>
Change-Id: I59dd5dffad08dbf578baa459f5f4c726b6674c83
diff --git a/libhwcomposer/hwc_utils.cpp b/libhwcomposer/hwc_utils.cpp
index 37eb8ea..553068f 100644
--- a/libhwcomposer/hwc_utils.cpp
+++ b/libhwcomposer/hwc_utils.cpp
@@ -111,6 +111,7 @@
     int extLayerIndex = -1; //ext-only or block except closed caption
     int extCount = 0; //ext-only except closed caption
     bool isExtBlockPresent = false; //is BLOCK layer present
+    bool yuvSecure = false;
 
     for (size_t i = 0; i < list->numHwLayers; i++) {
         private_handle_t *hnd =
@@ -119,8 +120,10 @@
         if (UNLIKELY(isYuvBuffer(hnd))) {
             yuvCount++;
             yuvLayerIndex = i;
+            yuvSecure = isSecureBuffer(hnd);
             //Animating
-            if (isSkipLayer(&list->hwLayers[i])) {
+            //Do not mark as SKIP if it is secure buffer
+            if (isSkipLayer(&list->hwLayers[i]) && !yuvSecure) {
                 isYuvLayerSkip = true;
             }
         } else if(UNLIKELY(isExtCC(hnd))) {
@@ -136,9 +139,12 @@
         } else if (isSkipLayer(&list->hwLayers[i])) { //Popups
             //If video layer is below a skip layer
             if(yuvLayerIndex != -1 && yuvLayerIndex < (ssize_t)i) {
-                isYuvLayerSkip = true;
+                //Do not mark as SKIP if it is secure buffer
+                if (!yuvSecure) {
+                    isYuvLayerSkip = true;
+                    skipCount++;
+                }
             }
-            skipCount++;
         }
     }
 
diff --git a/libhwcomposer/hwc_utils.h b/libhwcomposer/hwc_utils.h
index 33446b9..04bf864 100644
--- a/libhwcomposer/hwc_utils.h
+++ b/libhwcomposer/hwc_utils.h
@@ -93,6 +93,10 @@
     return (hnd && (hnd->bufferType == BUFFER_TYPE_VIDEO));
 }
 
+// Returns true if the buffer is secure
+static inline bool isSecureBuffer(const private_handle_t* hnd) {
+    return (hnd && (private_handle_t::PRIV_FLAGS_SECURE_BUFFER & hnd->flags));
+}
 //Return true if buffer is marked locked
 static inline bool isBufferLocked(const private_handle_t* hnd) {
     return (hnd && (private_handle_t::PRIV_FLAGS_HWC_LOCK & hnd->flags));