sf: Add support for Secure Display.

- Add secure UI layers to primary and remove other layers from
  internal and external list for Secure Display usecase.

- Dont let secure UI layers to be captured on screen

- Secure display content is rendered in sRGB dataspace and it
  expects the display to output in sRGB.  Hence force sRGB color
  mode to avoid conversion to P3.

- Limit protected contents for secure UI

- Do not switch to protected GPU context for secure camera usecases.

Change-Id: Ib0c1a591450ae5d3680e3571f9c27acc5c9bb519
CRs-Fixed: 2627348
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index 3d67a6b..7140da1 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -67,9 +67,11 @@
 #include "MonitoredProducer.h"
 #include "SurfaceFlinger.h"
 #include "TimeStats/TimeStats.h"
+#include "QtiGralloc.h"
 
 #define DEBUG_RESIZE 0
 
+using android::hardware::graphics::common::V1_0::BufferUsage;
 namespace android {
 
 using base::StringAppendF;
@@ -477,6 +479,8 @@
     compositionState->geomBufferUsesDisplayInverseTransform = getTransformToDisplayInverse();
     compositionState->geomUsesSourceCrop = usesSourceCrop();
     compositionState->isSecure = isSecure();
+    compositionState->isSecureDisplay = isSecureDisplay();
+    compositionState->isSecureCamera = isSecureCamera();
 
     compositionState->type = type;
     compositionState->appId = appId;
@@ -763,6 +767,17 @@
     return (s.flags & layer_state_t::eLayerSecure);
 }
 
+bool Layer::isSecureDisplay() const {
+    sp<const GraphicBuffer> buffer = getBuffer();
+    return buffer && (buffer->getUsage() & GRALLOC_USAGE_PRIVATE_SECURE_DISPLAY);
+}
+
+bool Layer::isSecureCamera() const {
+    sp<const GraphicBuffer> buffer = getBuffer();
+    bool protected_buffer = buffer && (buffer->getUsage() & BufferUsage::PROTECTED);
+    bool camera_output = buffer && (buffer->getUsage() & BufferUsage::CAMERA_OUTPUT);
+    return protected_buffer && camera_output;
+}
 // ----------------------------------------------------------------------------
 // transaction
 // ----------------------------------------------------------------------------