Merge changes Id8595dcb,I50c4227d,Ic7b31bbd,I26ef3b1a,I4c9727ad into pi-dev
am: 9711b52606

Change-Id: I09f4179fad30abae457c96557e00af8a4632c61a
diff --git a/msm8909w_3100/libqdutils/display_config.cpp b/msm8909w_3100/libqdutils/display_config.cpp
index 83d912e..ec24614 100644
--- a/msm8909w_3100/libqdutils/display_config.cpp
+++ b/msm8909w_3100/libqdutils/display_config.cpp
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2013-2014, 2016, The Linux Foundation. All rights reserved.
+* Copyright (c) 2013-2014, 2016, 2018 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
@@ -316,6 +316,22 @@
     return panel_brightness;
 }
 
+int setStandByMode(int mode) {
+    status_t err = (status_t) FAILED_TRANSACTION;
+    sp<IQService> binder = getBinder();
+    Parcel inParcel, outParcel;
+
+    if(binder != NULL) {
+        inParcel.writeInt32(mode);
+        err = binder->dispatch(IQService::SET_STAND_BY_MODE,
+              &inParcel, &outParcel);
+        if(err) {
+            ALOGE("%s() failed with err %d", __FUNCTION__, err);
+        }
+    }
+    return err;
+}
+
 }// namespace
 
 // ----------------------------------------------------------------------------
diff --git a/msm8909w_3100/libqdutils/display_config.h b/msm8909w_3100/libqdutils/display_config.h
index 6512bf5..d5b56ed 100644
--- a/msm8909w_3100/libqdutils/display_config.h
+++ b/msm8909w_3100/libqdutils/display_config.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013 - 2016 The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013 - 2016, 2018 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
@@ -158,6 +158,7 @@
 // Retrieves the current panel brightness value
 int getPanelBrightness();
 
+int setStandByMode(int mode);
 }; //namespace
 
 #endif
diff --git a/msm8909w_3100/libqservice/IQService.h b/msm8909w_3100/libqservice/IQService.h
index bf4343a..47dd1b0 100644
--- a/msm8909w_3100/libqservice/IQService.h
+++ b/msm8909w_3100/libqservice/IQService.h
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2010 The Android Open Source Project
- * Copyright (C) 2012-2014, 2016 The Linux Foundation. All rights reserved.
+ * Copyright (C) 2012-2014, 2016, 2018 The Linux Foundation. All rights reserved.
  *
  * Not a Contribution, Apache license notifications and license are
  * retained for attribution purposes only.
@@ -75,6 +75,7 @@
         SET_LAYER_MIXER_RESOLUTION = 33, // Enables client to set layer mixer resolution.
         SET_COLOR_MODE = 34, // Overrides the QDCM mode on the display
         GET_HDR_CAPABILITIES = 35, // Get HDR capabilities for legacy HWC interface
+        SET_STAND_BY_MODE = 36, //Set stand by mode for MDP3 hardware.
         COMMAND_LIST_END = 400,
     };
 
diff --git a/msm8909w_3100/sdm/libs/core/display_base.cpp b/msm8909w_3100/sdm/libs/core/display_base.cpp
index 07e250e..78de716 100644
--- a/msm8909w_3100/sdm/libs/core/display_base.cpp
+++ b/msm8909w_3100/sdm/libs/core/display_base.cpp
@@ -444,15 +444,9 @@
     break;
 
   case kStateDoze:
-    error = hw_intf_->DozeSuspend();
-    active = true;
-    break;
-
   case kStateDozeSuspend:
     error = hw_intf_->DozeSuspend();
-    if (display_type_ != kPrimary) {
-      active = true;
-    }
+    active = true;
     break;
 
   case kStateStandby:
diff --git a/msm8909w_3100/sdm/libs/hwc2/hwc_display.cpp b/msm8909w_3100/sdm/libs/hwc2/hwc_display.cpp
index 3acf08e..2b87d78 100644
--- a/msm8909w_3100/sdm/libs/hwc2/hwc_display.cpp
+++ b/msm8909w_3100/sdm/libs/hwc2/hwc_display.cpp
@@ -457,6 +457,9 @@
   metadata_refresh_rate_ = 0;
   auto working_primaries = ColorPrimaries_BT709_5;
 
+  uint32_t color_mode_count = 0;
+  display_intf_->GetColorModeCount(&color_mode_count);
+
   // Add one layer for fb target
   // TODO(user): Add blit target layers
   for (auto hwc_layer : layer_set_) {
@@ -523,7 +526,7 @@
     bool hdr_layer = layer->input_buffer.color_metadata.colorPrimaries == ColorPrimaries_BT2020 &&
                      (layer->input_buffer.color_metadata.transfer == Transfer_SMPTE_ST2084 ||
                      layer->input_buffer.color_metadata.transfer == Transfer_HLG);
-    if (hdr_layer && !disable_hdr_handling_) {
+    if (hdr_layer && !disable_hdr_handling_ && color_mode_count) {
       // dont honor HDR when its handling is disabled
       layer->input_buffer.flags.hdr = true;
       layer_stack_.flags.hdr_present = true;
@@ -1102,10 +1105,6 @@
 
 
 HWC2::Error HWCDisplay::CommitLayerStack(void) {
-  if (shutdown_pending_ || layer_set_.empty()) {
-    return HWC2::Error::None;
-  }
-
   if (skip_validate_ && !CanSkipValidate()) {
     validated_.reset(type_);
   }
@@ -1115,6 +1114,10 @@
     return HWC2::Error::NotValidated;
   }
 
+  if (shutdown_pending_ || layer_set_.empty()) {
+    return HWC2::Error::None;
+  }
+
   DumpInputBuffers();
 
   if (!flush_) {
@@ -1199,8 +1202,10 @@
       close(layer_buffer->acquire_fence_fd);
       layer_buffer->acquire_fence_fd = -1;
     }
+    layer->request.flags = {};
   }
 
+  client_target_->GetSDMLayer()->request.flags = {};
   *out_retire_fence = -1;
   if (!flush_) {
     // if swapinterval property is set to 0 then close and reset the list retire fence
@@ -1220,8 +1225,6 @@
   geometry_changes_ = GeometryChanges::kNone;
   flush_ = false;
 
-  ClearRequestFlags();
-
   return status;
 }
 
@@ -1881,12 +1884,6 @@
   }
 }
 
-void HWCDisplay::ClearRequestFlags() {
-  for (Layer *layer : layer_stack_.layers) {
-    layer->request.flags = {};
-  }
-}
-
 std::string HWCDisplay::Dump() {
   std::ostringstream os;
   os << "-------------------------------" << std::endl;
diff --git a/msm8909w_3100/sdm/libs/hwc2/hwc_display.h b/msm8909w_3100/sdm/libs/hwc2/hwc_display.h
index 6a200d1..2df25c5 100644
--- a/msm8909w_3100/sdm/libs/hwc2/hwc_display.h
+++ b/msm8909w_3100/sdm/libs/hwc2/hwc_display.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
@@ -148,6 +148,9 @@
   virtual int SetState(bool connected) {
     return kErrorNotSupported;
   }
+  virtual DisplayError SetStandByMode(bool enable) {
+    return kErrorNotSupported;
+  }
   int SetPanelBrightness(int level);
   int GetPanelBrightness(int *level);
   int ToggleScreenUpdates(bool enable);
@@ -237,7 +240,6 @@
   bool IsLayerUpdating(const Layer *layer);
   uint32_t SanitizeRefreshRate(uint32_t req_refresh_rate);
   virtual void CloseAcquireFds();
-  virtual void ClearRequestFlags();
   virtual void GetUnderScanConfig() { }
 
   enum {
diff --git a/msm8909w_3100/sdm/libs/hwc2/hwc_display_primary.cpp b/msm8909w_3100/sdm/libs/hwc2/hwc_display_primary.cpp
index abf01fd..df068b2 100644
--- a/msm8909w_3100/sdm/libs/hwc2/hwc_display_primary.cpp
+++ b/msm8909w_3100/sdm/libs/hwc2/hwc_display_primary.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.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
@@ -594,4 +594,28 @@
   return display_intf_->GetMixerResolution(width, height);
 }
 
+DisplayError HWCDisplayPrimary::SetStandByMode(bool enable) {
+  if (enable) {
+    if (!display_null_.IsActive()) {
+      stored_display_intf_ = display_intf_;
+      display_intf_ = &display_null_;
+      display_null_.SetActive(true);
+      DLOGD("Null display is connected successfully");
+    } else {
+      DLOGD("Null display is already connected.");
+    }
+  } else {
+    if (display_null_.IsActive()) {
+      display_intf_ = stored_display_intf_;
+      validated_.reset();
+      display_null_.SetActive(false);
+      DLOGD("Display is connected successfully");
+    } else {
+      DLOGD("Display is already connected.");
+    }
+  }
+
+  return kErrorNone;
+}
+
 }  // namespace sdm
diff --git a/msm8909w_3100/sdm/libs/hwc2/hwc_display_primary.h b/msm8909w_3100/sdm/libs/hwc2/hwc_display_primary.h
index 17f45f8..bd880a5 100644
--- a/msm8909w_3100/sdm/libs/hwc2/hwc_display_primary.h
+++ b/msm8909w_3100/sdm/libs/hwc2/hwc_display_primary.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014-2016, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2014-2016, 2018 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
@@ -34,6 +34,7 @@
 
 #include "cpuhint.h"
 #include "hwc_display.h"
+#include "display_null.h"
 
 namespace sdm {
 
@@ -67,6 +68,7 @@
   virtual int GetFrameCaptureStatus() { return frame_capture_status_; }
   virtual DisplayError SetDetailEnhancerConfig(const DisplayDetailEnhancerData &de_data);
   virtual DisplayError ControlPartialUpdate(bool enable, uint32_t *pending);
+  virtual DisplayError SetStandByMode(bool enable);
 
  private:
   HWCDisplayPrimary(CoreInterface *core_intf, BufferAllocator *buffer_allocator,
@@ -102,6 +104,11 @@
   BufferInfo output_buffer_info_ = {};
   void *output_buffer_base_ = nullptr;
   int default_mode_status_ = 0;
+
+  //Null display
+  DisplayNull display_null_;
+  DisplayInterface *stored_display_intf_ = NULL;
+
 };
 
 }  // namespace sdm
diff --git a/msm8909w_3100/sdm/libs/hwc2/hwc_session.cpp b/msm8909w_3100/sdm/libs/hwc2/hwc_session.cpp
index 0ebe639..fdd647c 100644
--- a/msm8909w_3100/sdm/libs/hwc2/hwc_session.cpp
+++ b/msm8909w_3100/sdm/libs/hwc2/hwc_session.cpp
@@ -491,7 +491,9 @@
 }
 
 static uint32_t GetMaxVirtualDisplayCount(hwc2_device_t *device) {
-  return 1;
+  char property[PROPERTY_VALUE_MAX];
+  property_get("debug.sdm.support_writeback", property, "1");
+  return (uint32_t) atoi(property);
 }
 
 static int32_t GetReleaseFences(hwc2_device_t *device, hwc2_display_t display,
@@ -1013,6 +1015,10 @@
       status = SetColorModeOverride(input_parcel);
       break;
 
+    case qService::IQService::SET_STAND_BY_MODE:
+      status = SetStandByMode(input_parcel);
+      break;
+
     default:
       DLOGW("QService command = %d is not supported", command);
       return -EINVAL;
@@ -1499,6 +1505,21 @@
   return android::NO_ERROR;
 }
 
+android::status_t HWCSession::SetStandByMode(const android::Parcel *input_parcel) {
+  SCOPE_LOCK(locker_);
+
+  bool enable = (input_parcel->readInt32() > 0);
+
+  if (!hwc_display_[HWC_DISPLAY_PRIMARY]) {
+    DLOGI("Primary display is not initialized");
+    return -EINVAL;
+  }
+
+  hwc_display_[HWC_DISPLAY_PRIMARY]->SetStandByMode(enable);
+
+  return android::NO_ERROR;
+}
+
 void HWCSession::Refresh(hwc2_display_t display) {
   SCOPE_LOCK(callbacks_lock_);
   HWC2::Error err = callbacks_.Refresh(display);
diff --git a/msm8909w_3100/sdm/libs/hwc2/hwc_session.h b/msm8909w_3100/sdm/libs/hwc2/hwc_session.h
index f2b1057..e5131d8 100644
--- a/msm8909w_3100/sdm/libs/hwc2/hwc_session.h
+++ b/msm8909w_3100/sdm/libs/hwc2/hwc_session.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
@@ -218,6 +218,7 @@
                                           android::Parcel *output_parcel);
   android::status_t SetMixerResolution(const android::Parcel *input_parcel);
   android::status_t SetColorModeOverride(const android::Parcel *input_parcel);
+  android::status_t SetStandByMode(const android::Parcel *input_parcel);
 
   void Refresh(hwc2_display_t display);
   void HotPlug(hwc2_display_t display, HWC2::Connection state);