hwc2 : Fix fence management issue during power state change

- Power state transitions (on and doze) are concurrently issued with a
  commit. The new commit gets a new release fence for the same pipes
  which were staged in previous cycle. The previous releases fence gets
  signaled at this point causing resource manager pipe fences in dangling
  state.

CRs-Fixed: 2265827
Change-Id: I5dfe9b004e6fc2a4e14e6b4085a032287066b5ce
diff --git a/sdm/include/private/resource_interface.h b/sdm/include/private/resource_interface.h
index fa4efb6..03a797b 100644
--- a/sdm/include/private/resource_interface.h
+++ b/sdm/include/private/resource_interface.h
@@ -37,6 +37,7 @@
     kCmdGetDefaultClk,
     kCmdDisableRotatorOneFrame,
     kCmdSetDisplayState,
+    kCmdUpdateSyncHandle,
     kCmdMax,
   };
 
diff --git a/sdm/libs/core/comp_manager.cpp b/sdm/libs/core/comp_manager.cpp
index 9e6cc23..9001cd7 100644
--- a/sdm/libs/core/comp_manager.cpp
+++ b/sdm/libs/core/comp_manager.cpp
@@ -534,7 +534,7 @@
   return kErrorNone;
 }
 
-bool CompManager::SetDisplayState(Handle display_ctx, DisplayState state) {
+bool CompManager::SetDisplayState(Handle display_ctx, DisplayState state, int sync_handle) {
   DisplayCompositionContext *display_comp_ctx =
       reinterpret_cast<DisplayCompositionContext *>(display_ctx);
 
@@ -572,6 +572,8 @@
   bool inactive = (state == kStateOff) || (state == kStateDozeSuspend);
   UpdateStrategyConstraints(display_comp_ctx->is_primary_panel, inactive);
 
+  resource_intf_->Perform(ResourceInterface::kCmdUpdateSyncHandle,
+                          display_comp_ctx->display_resource_ctx, sync_handle);
   return true;
 }
 
diff --git a/sdm/libs/core/comp_manager.h b/sdm/libs/core/comp_manager.h
index e69b61a..e9c465c 100644
--- a/sdm/libs/core/comp_manager.h
+++ b/sdm/libs/core/comp_manager.h
@@ -71,7 +71,7 @@
   void ControlPartialUpdate(Handle display_ctx, bool enable);
   DisplayError ValidateScaling(const LayerRect &crop, const LayerRect &dst, bool rotate90);
   DisplayError ValidateAndSetCursorPosition(Handle display_ctx, HWLayers *hw_layers, int x, int y);
-  bool SetDisplayState(Handle display_ctx, DisplayState state);
+  bool SetDisplayState(Handle display_ctx, DisplayState state, int sync_handle);
   DisplayError SetMaxBandwidthMode(HWBwModes mode);
   DisplayError GetScaleLutConfig(HWScaleLutInfo *lut_info);
   DisplayError SetDetailEnhancerData(Handle display_ctx, const DisplayDetailEnhancerData &de_data);
diff --git a/sdm/libs/core/display_base.cpp b/sdm/libs/core/display_base.cpp
index 20709b6..8666052 100644
--- a/sdm/libs/core/display_base.cpp
+++ b/sdm/libs/core/display_base.cpp
@@ -612,7 +612,7 @@
   if (error == kErrorNone) {
     active_ = active;
     state_ = state;
-    comp_manager_->SetDisplayState(display_comp_ctx_, state);
+    comp_manager_->SetDisplayState(display_comp_ctx_, state, release_fence ? *release_fence : -1);
   }
 
   // Handle vsync pending on resume, Since the power on commit is synchronous we pass -1 as retire