Merge "hwc: Dump in SDM only if layer stack is valid"
diff --git a/libgralloc1/gr_buf_mgr.cpp b/libgralloc1/gr_buf_mgr.cpp
index 189f19e..815f2b0 100644
--- a/libgralloc1/gr_buf_mgr.cpp
+++ b/libgralloc1/gr_buf_mgr.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011-2017 The Linux Foundation. All rights reserved.
+ * Copyright (c) 2011-2018 The Linux Foundation. All rights reserved.
  * Not a Contribution
  *
  * Copyright (C) 2010 The Android Open Source Project
@@ -407,7 +407,7 @@
     flags |= private_handle_t::PRIV_FLAGS_HW_TEXTURE;
   }
 
-  if (prod_usage & GRALLOC1_CONSUMER_USAGE_PRIVATE_SECURE_DISPLAY) {
+  if (cons_usage & GRALLOC1_CONSUMER_USAGE_PRIVATE_SECURE_DISPLAY) {
     flags |= private_handle_t::PRIV_FLAGS_SECURE_DISPLAY;
   }
 
diff --git a/libgralloc1/gralloc_priv.h b/libgralloc1/gralloc_priv.h
index a7ed5a8..7553017 100644
--- a/libgralloc1/gralloc_priv.h
+++ b/libgralloc1/gralloc_priv.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011-2017, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2011-2018, The Linux Foundation. All rights reserved.
  * Not a Contribution
  *
  * Copyright (C) 2008 The Android Open Source Project
@@ -66,7 +66,7 @@
 #define GRALLOC1_CONSUMER_USAGE_PRIVATE_WFD            0x00200000
 
 /* This flag is used for SECURE display usecase */
-#define GRALLOC1_CONSUMER_USAGE_PRIVATE_SECURE_DISPLAY 0x01000000
+#define GRALLOC1_CONSUMER_USAGE_PRIVATE_SECURE_DISPLAY 0x02000000
 
 /* This flag is used to indicate P010 format */
 #define GRALLOC1_CONSUMER_USAGE_PRIVATE_10BIT       GRALLOC1_PRODUCER_USAGE_PRIVATE_10BIT
diff --git a/sdm/include/private/hw_info_types.h b/sdm/include/private/hw_info_types.h
index 5d311d9..52bc73e 100644
--- a/sdm/include/private/hw_info_types.h
+++ b/sdm/include/private/hw_info_types.h
@@ -123,6 +123,13 @@
   kPPSplit,
 };
 
+enum HwHdrEotf {
+  kHdrEOTFInvalid = 0,
+  kHdrEOTFSDR = 0x1,
+  kHdrEOTFHdrLumRange = 0x2,
+  kHdrEOTFHDR10 = 0x4,
+  kHdrEOTFHLG = 0x8,
+};
 
 typedef std::map<HWSubBlockType, std::vector<LayerBufferFormat>> FormatsMap;
 typedef std::map<LayerBufferFormat, float> CompRatioMap;
diff --git a/sdm/libs/core/display_base.cpp b/sdm/libs/core/display_base.cpp
index b07c8a6..383bdba 100644
--- a/sdm/libs/core/display_base.cpp
+++ b/sdm/libs/core/display_base.cpp
@@ -155,7 +155,7 @@
     hw_layers_info.app_layer_count++;
   }
 
-  DLOGD_IF(kTagNone, "LayerStack layer_count: %d, app_layer_count: %d, gpu_target_index: %d, "
+  DLOGD_IF(kTagDisplay, "LayerStack layer_count: %d, app_layer_count: %d, gpu_target_index: %d, "
            "display type: %d", layers.size(), hw_layers_info.app_layer_count,
            hw_layers_info.gpu_target_index, display_type_);
 
diff --git a/sdm/libs/core/fb/hw_device.cpp b/sdm/libs/core/fb/hw_device.cpp
index 38e57d8..2c529ae 100644
--- a/sdm/libs/core/fb/hw_device.cpp
+++ b/sdm/libs/core/fb/hw_device.cpp
@@ -116,6 +116,10 @@
     device_fd_ = -1;
   }
 
+  if (stored_retire_fence >= 0) {
+    Sys::close_(stored_retire_fence);
+    stored_retire_fence = -1;
+  }
   return kErrorNone;
 }
 
diff --git a/sdm/libs/hwc2/hwc_display_primary.cpp b/sdm/libs/hwc2/hwc_display_primary.cpp
index ee6f03e..1f2fdf6 100644
--- a/sdm/libs/hwc2/hwc_display_primary.cpp
+++ b/sdm/libs/hwc2/hwc_display_primary.cpp
@@ -207,7 +207,10 @@
   }
 
   if (layer_set_.empty()) {
-    flush_ = true;
+    // Avoid flush for Command mode panel.
+    DisplayConfigFixedInfo display_config;
+    display_intf_->GetConfig(&display_config);
+    flush_ = !display_config.is_cmdmode;
     return status;
   }
 
diff --git a/sdm/libs/hwc2/hwc_layers.cpp b/sdm/libs/hwc2/hwc_layers.cpp
index 0bcffc6..d611352 100644
--- a/sdm/libs/hwc2/hwc_layers.cpp
+++ b/sdm/libs/hwc2/hwc_layers.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014-2017, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2014-2018, The Linux Foundation. All rights reserved.
  * Not a Contribution.
  *
  * Copyright 2015 The Android Open Source Project
@@ -180,12 +180,15 @@
 HWCLayer::~HWCLayer() {
   // Close any fences left for this layer
   while (!release_fences_.empty()) {
-    close(release_fences_.front());
+    ::close(release_fences_.front());
     release_fences_.pop();
   }
   if (layer_) {
     if (layer_->input_buffer.acquire_fence_fd >= 0) {
-      close(layer_->input_buffer.acquire_fence_fd);
+      ::close(layer_->input_buffer.acquire_fence_fd);
+    }
+    if (buffer_fd_ >= 0) {
+      ::close(buffer_fd_);
     }
     delete layer_;
   }
@@ -257,10 +260,14 @@
   layer_buffer->flags.secure_display = secure_display;
 
   if (layer_buffer->acquire_fence_fd >= 0) {
-    close(layer_buffer->acquire_fence_fd);
+    ::close(layer_buffer->acquire_fence_fd);
   }
   layer_buffer->acquire_fence_fd = acquire_fence;
-  layer_buffer->planes[0].fd = handle->fd;
+  if (buffer_fd_ >= 0) {
+    ::close(buffer_fd_);
+  }
+  buffer_fd_ = ::dup(handle->fd);
+  layer_buffer->planes[0].fd = buffer_fd_;
   layer_buffer->planes[0].offset = handle->offset;
   layer_buffer->planes[0].stride = UINT32(handle->width);
   layer_buffer->size = handle->size;
@@ -728,7 +735,7 @@
   float fps = 0;
   uint32_t frame_rate = layer->frame_rate;
   if (getMetaData(handle, GET_REFRESH_RATE, &fps) == 0) {
-    frame_rate = RoundToStandardFPS(fps);
+    frame_rate = (fps != 0) ? RoundToStandardFPS(fps) : layer->frame_rate;
   }
 
   int32_t interlaced = 0;
diff --git a/sdm/libs/hwc2/hwc_layers.h b/sdm/libs/hwc2/hwc_layers.h
index 5f5792f..ed03c50 100644
--- a/sdm/libs/hwc2/hwc_layers.h
+++ b/sdm/libs/hwc2/hwc_layers.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014-2017, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2014-2018, The Linux Foundation. All rights reserved.
  * Not a Contribution.
  *
  * Copyright 2015 The Android Open Source Project
@@ -111,6 +111,7 @@
   LayerRect dst_rect_ = {};
   bool needs_validate_ = true;
   bool single_buffer_ = false;
+  int buffer_fd_ = -1;
 
   // Composition requested by client(SF)
   HWC2::Composition client_requested_ = HWC2::Composition::Device;
diff --git a/sdm/libs/hwc2/hwc_session.cpp b/sdm/libs/hwc2/hwc_session.cpp
index fdb8358..36b55d0 100644
--- a/sdm/libs/hwc2/hwc_session.cpp
+++ b/sdm/libs/hwc2/hwc_session.cpp
@@ -804,7 +804,7 @@
   }
 
   // Sequence locking currently begins on Validate, so cancel the sequence lock on failures
-  if (status != HWC2::Error::None) {
+  if (status != HWC2::Error::None && status != HWC2::Error::HasChanges) {
     SEQUENCE_CANCEL_SCOPE_LOCK(locker_[display]);
   }