display: Update to AU169 proprietary drop

Update to AU_LINUX_ANDROID_LA.HB.1.3.9.06.00.01.213.169

display_hal:
d30696d hwc: Do not use the sequence lock in eventcontrol
f5f61e5 Merge "hwc2: Address remaining review comments"
6d1749e Merge "gralloc: Fix gralloc protected allocations"
72dea24 hwc2: Address remaining review comments
afd2549 hwc2: Fix composition change check
7790772 hwc2: Add getHdrCapabilities
de758fd gralloc: Fix gralloc protected allocations

Change-Id: I71fc06db0b8f4ea3819cc037b4298deaba1b5036
diff --git a/msm8996/libgralloc/alloc_controller.cpp b/msm8996/libgralloc/alloc_controller.cpp
index 3a1ffbd..2a5d099 100644
--- a/msm8996/libgralloc/alloc_controller.cpp
+++ b/msm8996/libgralloc/alloc_controller.cpp
@@ -89,9 +89,9 @@
  * treated as uncached. */
 static bool useUncached(const int& usage) {
     if ((usage & GRALLOC_USAGE_PROTECTED) or
-       (usage & GRALLOC_USAGE_PRIVATE_UNCACHED) or
-       ((usage & GRALLOC_USAGE_SW_WRITE_MASK) == GRALLOC_USAGE_SW_WRITE_RARELY) or
-       ((usage & GRALLOC_USAGE_SW_READ_MASK) == GRALLOC_USAGE_SW_READ_RARELY))
+        (usage & GRALLOC_USAGE_PRIVATE_UNCACHED) or
+        ((usage & GRALLOC_USAGE_SW_WRITE_MASK) == GRALLOC_USAGE_SW_WRITE_RARELY) or
+        ((usage & GRALLOC_USAGE_SW_READ_MASK) ==  GRALLOC_USAGE_SW_READ_RARELY))
         return true;
 
     return false;
diff --git a/msm8996/sdm/libs/hwc/hwc_session.cpp b/msm8996/sdm/libs/hwc/hwc_session.cpp
index 7928765..87c3d00 100644
--- a/msm8996/sdm/libs/hwc/hwc_session.cpp
+++ b/msm8996/sdm/libs/hwc/hwc_session.cpp
@@ -432,8 +432,6 @@
 }
 
 int HWCSession::EventControl(hwc_composer_device_1 *device, int disp, int event, int enable) {
-  SEQUENCE_WAIT_SCOPE_LOCK(locker_);
-
   if (!device) {
     return -EINVAL;
   }
diff --git a/msm8996/sdm/libs/hwc2/hwc_display.cpp b/msm8996/sdm/libs/hwc2/hwc_display.cpp
index d9b3c73..14cbbdb 100644
--- a/msm8996/sdm/libs/hwc2/hwc_display.cpp
+++ b/msm8996/sdm/libs/hwc2/hwc_display.cpp
@@ -128,10 +128,10 @@
 
 // LayerStack operations
 HWC2::Error HWCDisplay::CreateLayer(hwc2_layer_t *out_layer_id) {
-  auto layer = *layer_set_.emplace(new HWCLayer(id_));
+  HWCLayer *layer = *layer_set_.emplace(new HWCLayer(id_));
   layer_map_.emplace(std::make_pair(layer->GetId(), layer));
   *out_layer_id = layer->GetId();
-  geometry_changes_ = GeometryChanges::kAdded;
+  geometry_changes_ |= GeometryChanges::kAdded;
   return HWC2::Error::None;
 }
 
@@ -161,7 +161,7 @@
     }
   }
 
-  geometry_changes_ = GeometryChanges::kRemoved;
+  geometry_changes_ |= GeometryChanges::kRemoved;
   return HWC2::Error::None;
 }
 
@@ -535,8 +535,11 @@
     if (!needs_fb_refresh && composition == kCompositionGPU) {
       composition = kCompositionSDE;
     }
+    HWC2::Composition current_hwc_composition  = hwc_layer->GetCompositionType();
+    // Convert the SDM layer composition to HWC2 type
     hwc_layer->SetComposition(composition);
-    if (hwc_layer->CompositionChanged()) {
+    // Update the changes list only if the HWC2 comp type changed from the previous cycle
+    if (current_hwc_composition != hwc_layer->GetCompositionType()) {
       layer_changes_[hwc_layer->GetId()] = hwc_layer->GetCompositionType();
     }
   }
@@ -1357,6 +1360,7 @@
     auto layer = hwc_layer->GetSDMLayer();
     if (layer->input_buffer->acquire_fence_fd >= 0) {
       close(layer->input_buffer->acquire_fence_fd);
+      layer->input_buffer->acquire_fence_fd = -1;
     }
   }
   int32_t &client_target_acquire_fence =
diff --git a/msm8996/sdm/libs/hwc2/hwc_display.h b/msm8996/sdm/libs/hwc2/hwc_display.h
index 6430538..dd2b55d 100644
--- a/msm8996/sdm/libs/hwc2/hwc_display.h
+++ b/msm8996/sdm/libs/hwc2/hwc_display.h
@@ -159,14 +159,14 @@
     OUTPUT_LAYER_DUMP,
   };
 
-  CoreInterface *core_intf_;
-  HWCCallbacks *callbacks_;
+  CoreInterface *core_intf_ = nullptr;
+  HWCCallbacks *callbacks_  = nullptr;
   DisplayType type_;
   hwc2_display_t id_;
   bool needs_blit_ = false;
   DisplayInterface *display_intf_ = NULL;
   LayerStack layer_stack_;
-  HWCLayer *client_target_;                             // Also known as framebuffer target
+  HWCLayer *client_target_ = nullptr;                   // Also known as framebuffer target
   std::map<hwc2_layer_t, HWCLayer *> layer_map_;        // Look up by Id - TODO
   std::multiset<HWCLayer *, SortLayersByZ> layer_set_;  // Maintain a set sorted by Z
   std::map<hwc2_layer_t, HWC2::Composition> layer_changes_;
@@ -202,7 +202,7 @@
   BlitEngine *blit_engine_ = NULL;
   qService::QService *qservice_ = NULL;
   DisplayClass display_class_;
-  int32_t stored_retire_fence_;
+  int32_t stored_retire_fence_ = -1;
   uint32_t geometry_changes_ = GeometryChanges::kNone;
 };
 
diff --git a/msm8996/sdm/libs/hwc2/hwc_layers.cpp b/msm8996/sdm/libs/hwc2/hwc_layers.cpp
index 9be2317..ada1cac 100644
--- a/msm8996/sdm/libs/hwc2/hwc_layers.cpp
+++ b/msm8996/sdm/libs/hwc2/hwc_layers.cpp
@@ -26,10 +26,6 @@
 
 namespace sdm {
 
-bool SortLayersByZ::operator()(const HWCLayer *lhs, const HWCLayer *rhs) {
-  return lhs->GetZ() < rhs->GetZ();
-}
-
 std::atomic<hwc2_layer_t> HWCLayer::next_id_(1);
 
 // Layer operations
@@ -170,7 +166,7 @@
 
 HWC2::Error HWCLayer::SetLayerPlaneAlpha(float alpha) {
   // Conversion of float alpha in range 0.0 to 1.0 similar to the HWC Adapter
-  layer_->plane_alpha = static_cast<uint8_t>(255.0f * alpha + 0.5f);
+  layer_->plane_alpha = static_cast<uint8_t>(std::round(255.0f * alpha));
   geometry_changes_ |= kPlaneAlpha;
   return HWC2::Error::None;
 }
@@ -337,6 +333,36 @@
     case HAL_PIXEL_FORMAT_YCbCr_422_I:
       format = kFormatYCbCr422H2V1Packed;
       break;
+    case HAL_PIXEL_FORMAT_RGBA_1010102:
+      format = kFormatRGBA1010102;
+      break;
+    case HAL_PIXEL_FORMAT_ARGB_2101010:
+      format = kFormatARGB2101010;
+      break;
+    case HAL_PIXEL_FORMAT_RGBX_1010102:
+      format = kFormatRGBX1010102;
+      break;
+    case HAL_PIXEL_FORMAT_XRGB_2101010:
+      format = kFormatXRGB2101010;
+      break;
+    case HAL_PIXEL_FORMAT_BGRA_1010102:
+      format = kFormatBGRA1010102;
+      break;
+    case HAL_PIXEL_FORMAT_ABGR_2101010:
+      format = kFormatABGR2101010;
+      break;
+    case HAL_PIXEL_FORMAT_BGRX_1010102:
+      format = kFormatBGRX1010102;
+      break;
+    case HAL_PIXEL_FORMAT_XBGR_2101010:
+      format = kFormatXBGR2101010;
+      break;
+    case HAL_PIXEL_FORMAT_YCbCr_420_P010:
+      format = kFormatYCbCr420P010;
+      break;
+    case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC:
+      format = kFormatYCbCr420TP10Ubwc;
+      break;
     default:
       DLOGW("Unsupported format type = %d", source);
       return kFormatInvalid;
@@ -480,11 +506,7 @@
   if (layer_->composition == kCompositionSDE && layer_->flags.solid_fill != 0) {
     composition = HWC2::Composition::SolidColor;
   }
-  if (composition != composition_) {
-    // Composition changed for this layer
-    composition_changed_ = true;
-    composition_ = composition;
-  }
+  composition_ = composition;
 }
 void HWCLayer::PushReleaseFence(int32_t fence) {
   release_fences_.push(fence);
diff --git a/msm8996/sdm/libs/hwc2/hwc_layers.h b/msm8996/sdm/libs/hwc2/hwc_layers.h
index de3b7bb..b756c38 100644
--- a/msm8996/sdm/libs/hwc2/hwc_layers.h
+++ b/msm8996/sdm/libs/hwc2/hwc_layers.h
@@ -38,16 +38,16 @@
 namespace sdm {
 
 enum GeometryChanges {
-  kNone = 0x00,
-  kBlendMode = 0x01,
-  kDataspace = 0x02,
-  kDisplayFrame = 0x04,
-  kPlaneAlpha = 0x08,
-  kSourceCrop = 0x0A,
-  kTransform = 0x10,
-  kZOrder = 0x12,
-  kAdded = 0x14,
-  kRemoved = 0x18,
+  kNone         = 0x000,
+  kBlendMode    = 0x001,
+  kDataspace    = 0x002,
+  kDisplayFrame = 0x004,
+  kPlaneAlpha   = 0x008,
+  kSourceCrop   = 0x010,
+  kTransform    = 0x020,
+  kZOrder       = 0x040,
+  kAdded        = 0x080,
+  kRemoved      = 0x100,
 };
 
 class HWCLayer {
@@ -71,7 +71,6 @@
   HWC2::Error SetLayerVisibleRegion(hwc_region_t visible);
   HWC2::Error SetLayerZOrder(uint32_t z);
   void SetComposition(const LayerComposition &source);
-  bool CompositionChanged(void) { return composition_changed_; }
   HWC2::Composition GetCompositionType() { return composition_; }
   uint32_t GetGeometryChanges() { return geometry_changes_; }
   void ResetGeometryChanges() { geometry_changes_ = GeometryChanges::kNone; }
@@ -87,7 +86,6 @@
   std::queue<int32_t> release_fences_;
 
   HWC2::Composition composition_ = HWC2::Composition::Device;
-  bool composition_changed_ = false;
   uint32_t geometry_changes_ = GeometryChanges::kNone;
 
   void SetRect(const hwc_rect_t &source, LayerRect *target);
@@ -102,7 +100,9 @@
 };
 
 struct SortLayersByZ {
-  bool operator()(const HWCLayer *lhs, const HWCLayer *rhs);
+  bool operator()(const HWCLayer *lhs, const HWCLayer *rhs) {
+    return lhs->GetZ() < rhs->GetZ();
+  }
 };
 
 }  // namespace sdm
diff --git a/msm8996/sdm/libs/hwc2/hwc_session.cpp b/msm8996/sdm/libs/hwc2/hwc_session.cpp
index a7d2042..e774e55 100644
--- a/msm8996/sdm/libs/hwc2/hwc_session.cpp
+++ b/msm8996/sdm/libs/hwc2/hwc_session.cpp
@@ -340,6 +340,14 @@
   return HWC2_ERROR_NONE;
 }
 
+static int32_t GetHdrCapabilities(hwc2_device_t* device, hwc2_display_t display,
+                                  uint32_t* out_num_types, int32_t* out_types,
+                                  float* out_max_luminance, float* out_max_average_luminance,
+                                  float* out_min_luminance) {
+  *out_num_types = 0;
+  return HWC2_ERROR_NONE;
+}
+
 static uint32_t GetMaxVirtualDisplayCount(hwc2_device_t *device) {
   return 1;
 }
@@ -383,9 +391,8 @@
   auto desc = static_cast<HWC2::Callback>(descriptor);
   auto error = hwc_session->callbacks_.Register(desc, callback_data, pointer);
   DLOGD("Registering callback: %s", to_string(desc).c_str());
-  // TODO(user): The hotplug should only be called when the HOTPLUG callback is registered
-  // However, this causes SurfaceFlinger to behave weirdly - investigate further.
-  hwc_session->callbacks_.Hotplug(HWC_DISPLAY_PRIMARY, HWC2::Connection::Connected);
+  if (descriptor == HWC2_CALLBACK_HOTPLUG)
+    hwc_session->callbacks_.Hotplug(HWC_DISPLAY_PRIMARY, HWC2::Connection::Connected);
   return INT32(error);
 }
 
@@ -570,6 +577,8 @@
       return AsFP<HWC2_PFN_GET_DISPLAY_REQUESTS>(GetDisplayRequests);
     case HWC2::FunctionDescriptor::GetDisplayType:
       return AsFP<HWC2_PFN_GET_DISPLAY_TYPE>(GetDisplayType);
+    case HWC2::FunctionDescriptor::GetHdrCapabilities:
+      return AsFP<HWC2_PFN_GET_HDR_CAPABILITIES>(GetHdrCapabilities);
     case HWC2::FunctionDescriptor::GetDozeSupport:
       return AsFP<HWC2_PFN_GET_DOZE_SUPPORT>(GetDozeSupport);
     case HWC2::FunctionDescriptor::GetMaxVirtualDisplayCount: