sdm: Add mask layer flag support to input buffer flags.

Set DISABLE_MASK_LAYER_HINT property to disable
this hint.

Change-Id: I526025e2c32d386877b4b0b70c6423642421213f
CRs-Fixed: 2396411
diff --git a/include/display_properties.h b/include/display_properties.h
index 8f5b7df..cd7ef15 100644
--- a/include/display_properties.h
+++ b/include/display_properties.h
@@ -96,6 +96,7 @@
 #define DISABLE_EXCl_RECT_PARTIAL_FB         DISPLAY_PROP("disable_excl_rect_partial_fb")
 #define DISABLE_FBID_CACHE                   DISPLAY_PROP("disable_fbid_cache")
 #define DISABLE_HOTPLUG_BWCHECK              DISPLAY_PROP("disable_hotplug_bwcheck")
+#define DISABLE_MASK_LAYER_HINT              DISPLAY_PROP("disable_mask_layer_hint")
 
 #define DISABLE_HDR_LUT_GEN                  DISPLAY_PROP("disable_hdr_lut_gen")
 #define ENABLE_DEFAULT_COLOR_MODE            DISPLAY_PROP("enable_default_color_mode")
diff --git a/sdm/include/core/layer_buffer.h b/sdm/include/core/layer_buffer.h
index b5f1701..1114dbd 100644
--- a/sdm/include/core/layer_buffer.h
+++ b/sdm/include/core/layer_buffer.h
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2014, 2016-2018, The Linux Foundation. All rights reserved.
+* Copyright (c) 2014, 2016-2019, The Linux Foundation. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification, are permitted
 * provided that the following conditions are met:
@@ -220,6 +220,10 @@
 
       uint32_t hdr : 1;             //!< This flag shall be set by the client to indicate that the
                                     //!< the content is HDR.
+
+      uint32_t mask_layer : 1;      //!< This flag shall be set by client to indicate that the layer
+                                    //!< is union of solid fill regions typically transparent pixels
+                                    //!< and black pixels.
     };
 
     uint32_t flags = 0;             //!< For initialization purpose only.
diff --git a/sdm/libs/hwc2/hwc_layers.cpp b/sdm/libs/hwc2/hwc_layers.cpp
index 36516bb..a41f24c 100644
--- a/sdm/libs/hwc2/hwc_layers.cpp
+++ b/sdm/libs/hwc2/hwc_layers.cpp
@@ -1040,4 +1040,9 @@
   }
 }
 
+void HWCLayer::SetLayerAsMask() {
+  layer_->input_buffer.flags.mask_layer = true;
+  DLOGV_IF(kTagClient, " Layer Id: ""[%" PRIu64 "]", id_);
+}
+
 }  // namespace sdm
diff --git a/sdm/libs/hwc2/hwc_layers.h b/sdm/libs/hwc2/hwc_layers.h
index b5d5eaa..d990fc1 100644
--- a/sdm/libs/hwc2/hwc_layers.h
+++ b/sdm/libs/hwc2/hwc_layers.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014-2018, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2014-2019, The Linux Foundation. All rights reserved.
  * Not a Contribution.
  *
  * Copyright 2015 The Android Open Source Project
@@ -26,6 +26,7 @@
 #include <gralloc_priv.h>
 #include <qdMetaData.h>
 #include <core/layer_stack.h>
+#include <core/layer_buffer.h>
 #include <utils/utils.h>
 #define HWC2_INCLUDE_STRINGIFICATION
 #define HWC2_USE_CPP11
@@ -111,6 +112,7 @@
   void SetPartialUpdate(bool enabled) { partial_update_enabled_ = enabled; }
   bool IsNonIntegralSourceCrop() { return non_integral_source_crop_; }
   bool HasMetaDataRefreshRate() { return has_metadata_refresh_rate_; }
+  void SetLayerAsMask();
 
  private:
   Layer *layer_ = nullptr;
diff --git a/sdm/libs/hwc2/hwc_session.cpp b/sdm/libs/hwc2/hwc_session.cpp
index 0956401..525bef1 100644
--- a/sdm/libs/hwc2/hwc_session.cpp
+++ b/sdm/libs/hwc2/hwc_session.cpp
@@ -208,6 +208,7 @@
   StartServices();
   HWCDebugHandler::Get()->GetProperty(ENABLE_NULL_DISPLAY_PROP, &null_display_mode_);
   HWCDebugHandler::Get()->GetProperty(DISABLE_HOTPLUG_BWCHECK, &disable_hotplug_bwcheck_);
+  HWCDebugHandler::Get()->GetProperty(DISABLE_MASK_LAYER_HINT, &disable_mask_layer_hint_);
   DisplayError error = kErrorNone;
 
   HWDisplayInterfaceInfo hw_disp_info = {};
diff --git a/sdm/libs/hwc2/hwc_session.h b/sdm/libs/hwc2/hwc_session.h
index ea8112e..2142ec6 100644
--- a/sdm/libs/hwc2/hwc_session.h
+++ b/sdm/libs/hwc2/hwc_session.h
@@ -434,6 +434,7 @@
   int32_t max_sde_builtin_displays_ = 0;
   int32_t registered_builtin_displays_ = 0;
   int32_t disable_hotplug_bwcheck_ = 0;
+  int32_t disable_mask_layer_hint_ = 0;
 };
 
 }  // namespace sdm
diff --git a/sdm/libs/hwc2/hwc_session_services.cpp b/sdm/libs/hwc2/hwc_session_services.cpp
index dc5d2a9..90347f9 100644
--- a/sdm/libs/hwc2/hwc_session_services.cpp
+++ b/sdm/libs/hwc2/hwc_session_services.cpp
@@ -755,6 +755,25 @@
 }
 
 Return<int32_t> HWCSession::setLayerAsMask(uint32_t disp_id, uint64_t layer_id) {
+  SCOPE_LOCK(locker_[disp_id]);
+  HWCDisplay *hwc_display = hwc_display_[disp_id];
+  if (!hwc_display) {
+    DLOGW("Display = %d is not connected.", disp_id);
+    return -EINVAL;
+  }
+
+  if (disable_mask_layer_hint_) {
+    DLOGW("Mask layer hint is disabled!");
+    return -EINVAL;
+  }
+
+  auto hwc_layer = hwc_display->GetHWCLayer(layer_id);
+  if (hwc_layer == nullptr) {
+    return -EINVAL;
+  }
+
+  hwc_layer->SetLayerAsMask();
+
   return 0;
 }