sdm: Query strategy if there is a need to validate.

CRs-Fixed: 2407098
Change-Id: Iaf64932b6182f54d9e6ed37dde24e8d2b5a49234
diff --git a/composer/display_null.h b/composer/display_null.h
index ae3059e..4a9499f 100644
--- a/composer/display_null.h
+++ b/composer/display_null.h
@@ -62,6 +62,7 @@
                                                     uint8_t *out_data);
   virtual string Dump() { return ""; }
   virtual bool IsSupportSsppTonemap() { return false; }
+  virtual bool CanSkipValidate() { return true; }
 
   MAKE_NO_OP(TeardownConcurrentWriteback(void))
   MAKE_NO_OP(Commit(LayerStack *))
diff --git a/composer/hwc_display.cpp b/composer/hwc_display.cpp
index 3e219aa..baf45b6 100644
--- a/composer/hwc_display.cpp
+++ b/composer/hwc_display.cpp
@@ -805,6 +805,8 @@
       layer->flags.color_transform = true;
     }
 
+    layer_stack_.flags.mask_present |= layer->input_buffer.flags.mask_layer;
+
     layer_stack_.layers.push_back(layer);
   }
 
@@ -1573,10 +1575,11 @@
       // release fences and discard fences from driver
       if (swap_interval_zero_ || layer->flags.single_buffer) {
         close(layer_buffer->release_fence_fd);
-      } else if (layer->composition != kCompositionGPU) {
-        hwc_layer->PushBackReleaseFence(layer_buffer->release_fence_fd);
       } else {
-        hwc_layer->PushBackReleaseFence(-1);
+        // It may so happen that layer gets marked to GPU & app layer gets queued
+        // to MDP for composition. In those scenarios, release fence of buffer should
+        // have mdp and gpu sync points merged.
+        hwc_layer->PushBackReleaseFence(layer_buffer->release_fence_fd);
       }
     } else {
       // In case of flush or display paused, we don't return an error to f/w, so it will
@@ -2257,6 +2260,10 @@
     }
   }
 
+  if (!layer_set_.empty() && !display_intf_->CanSkipValidate()) {
+    return false;
+  }
+
   return true;
 }
 
diff --git a/include/display_properties.h b/include/display_properties.h
index 4f20713..1b9f199 100644
--- a/include/display_properties.h
+++ b/include/display_properties.h
@@ -103,6 +103,7 @@
 // Disable deferring power state request to first draw cycle
 #define DISABLE_DEFER_POWER_STATE            DISPLAY_PROP("disable_defer_power_state")
 #define ENABLE_DROP_REFRESH                  DISPLAY_PROP("enable_drop_refresh")
+#define DISABLE_PARALLEL_CACHE               DISPLAY_PROP("disable_parallel_cache")
 
 // Add all vendor.display properties above
 
diff --git a/sdm/include/core/display_interface.h b/sdm/include/core/display_interface.h
index 7e385bc..dc1dc85 100644
--- a/sdm/include/core/display_interface.h
+++ b/sdm/include/core/display_interface.h
@@ -879,6 +879,12 @@
   */
   virtual DisplayError SetPanelLuminanceAttributes(float min_lum, float max_lum) = 0;
 
+  /*! @brief Method to query if there is a need to validate.
+
+      @return \link boolean \endlink
+  */
+  virtual bool CanSkipValidate() = 0;
+
  protected:
   virtual ~DisplayInterface() { }
 };
diff --git a/sdm/include/core/layer_stack.h b/sdm/include/core/layer_stack.h
index 9aba8fa..e8ea272 100644
--- a/sdm/include/core/layer_stack.h
+++ b/sdm/include/core/layer_stack.h
@@ -243,6 +243,8 @@
       uint32_t hdr_present : 1;  //!< Set if stack has HDR content
 
       uint32_t fast_path : 1;    //!< Preference for fast/slow path draw-cycle, set by client.
+
+      uint32_t mask_present : 1;  //!< Set if layer stack has mask layers.
     };
 
     uint32_t flags = 0;               //!< For initialization purpose only.
diff --git a/sdm/include/private/strategy_interface.h b/sdm/include/private/strategy_interface.h
index 3f1b9ab..31fda2a 100644
--- a/sdm/include/private/strategy_interface.h
+++ b/sdm/include/private/strategy_interface.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.
 *
 * Redistribution and use in source and binary forms, with or without modification, are permitted
 * provided that the following conditions are met:
@@ -57,6 +57,7 @@
   /* Sets the list of color modes supported on a display */
   virtual DisplayError SetColorModesInfo(const std::vector<PrimariesTransfer> &colormodes_cs) = 0;
   virtual DisplayError SetBlendSpace(const PrimariesTransfer &blend_space) = 0;
+  virtual bool CanSkipValidate() = 0;
 
   virtual ~StrategyInterface() { }
 };
diff --git a/sdm/libs/core/comp_manager.cpp b/sdm/libs/core/comp_manager.cpp
index a607b1e..acdc071 100644
--- a/sdm/libs/core/comp_manager.cpp
+++ b/sdm/libs/core/comp_manager.cpp
@@ -629,4 +629,11 @@
   max_sde_builtin_layers_ = (disabled && (powered_on_displays_.size() <= 1)) ? kMaxSDELayers : 2;
 }
 
+bool CompManager::CanSkipValidate(Handle display_ctx) {
+  DisplayCompositionContext *display_comp_ctx =
+      reinterpret_cast<DisplayCompositionContext *>(display_ctx);
+
+  return display_comp_ctx->strategy->CanSkipValidate();
+}
+
 }  // namespace sdm
diff --git a/sdm/libs/core/comp_manager.h b/sdm/libs/core/comp_manager.h
index 54cde85..e69b61a 100644
--- a/sdm/libs/core/comp_manager.h
+++ b/sdm/libs/core/comp_manager.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.
 *
 * Redistribution and use in source and binary forms, with or without modification, are permitted
 * provided that the following conditions are met:
@@ -83,6 +83,7 @@
   DisplayError SetBlendSpace(Handle display_ctx, const PrimariesTransfer &blend_space);
   void HandleSecureEvent(Handle display_ctx, SecureEvent secure_event);
   void SetSafeMode(bool enable) { safe_mode_ = enable; }
+  bool CanSkipValidate(Handle display_ctx);
 
  private:
   static const int kMaxThermalLevel = 3;
diff --git a/sdm/libs/core/display_base.cpp b/sdm/libs/core/display_base.cpp
index 86840d8..5ed4426 100644
--- a/sdm/libs/core/display_base.cpp
+++ b/sdm/libs/core/display_base.cpp
@@ -1932,4 +1932,8 @@
   return false;
 }
 
+bool DisplayBase::CanSkipValidate() {
+  return comp_manager_->CanSkipValidate(display_comp_ctx_);
+}
+
 }  // namespace sdm
diff --git a/sdm/libs/core/display_base.h b/sdm/libs/core/display_base.h
index 838fc85..fec72ba 100644
--- a/sdm/libs/core/display_base.h
+++ b/sdm/libs/core/display_base.h
@@ -154,6 +154,7 @@
     return kErrorNotSupported;
   }
   virtual DisplayError GetRefreshRate(uint32_t *refresh_rate) { return kErrorNotSupported; }
+  virtual bool CanSkipValidate();
 
  protected:
   const char *kBt2020Pq = "bt2020_pq";
diff --git a/sdm/libs/core/strategy.cpp b/sdm/libs/core/strategy.cpp
index 5098b01..76351f9 100644
--- a/sdm/libs/core/strategy.cpp
+++ b/sdm/libs/core/strategy.cpp
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2014 - 2018, The Linux Foundation. All rights reserved.
+* Copyright (c) 2014 - 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:
@@ -270,4 +270,11 @@
   return kErrorNotSupported;
 }
 
+bool Strategy::CanSkipValidate() {
+  if (strategy_intf_) {
+    return strategy_intf_->CanSkipValidate();
+  }
+  return true;
+}
+
 }  // namespace sdm
diff --git a/sdm/libs/core/strategy.h b/sdm/libs/core/strategy.h
index db10f11..ecb6143 100644
--- a/sdm/libs/core/strategy.h
+++ b/sdm/libs/core/strategy.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.
 *
 * Redistribution and use in source and binary forms, with or without modification, are permitted
 * provided that the following conditions are met:
@@ -56,6 +56,7 @@
   DisplayError SetIdleTimeoutMs(uint32_t active_ms);
   DisplayError SetColorModesInfo(const std::vector<PrimariesTransfer> &colormodes_cs);
   DisplayError SetBlendSpace(const PrimariesTransfer &blend_space);
+  bool CanSkipValidate();
 
  private:
   void GenerateROI();