hwc2: Add support to handle QDCM frame capture

Re-introduce the special handling for QDCM frame capture path, as
the client can check the status of frame capture operation, a few
frames after the captured frame. In Concurrent Writeback, all the
members should get cleared at the end of current draw cycle.

CRs-Fixed: 2365252
Change-Id: Ia5b1340249bab3d312a0bbc59027d9d5bcc5d397
diff --git a/sdm/libs/hwc2/hwc_display_builtin.cpp b/sdm/libs/hwc2/hwc_display_builtin.cpp
index b368ca7..a1999c4 100644
--- a/sdm/libs/hwc2/hwc_display_builtin.cpp
+++ b/sdm/libs/hwc2/hwc_display_builtin.cpp
@@ -577,11 +577,27 @@
     validated_ = false;
   }
 
-  if (dump_output_to_file_) {
+  if (frame_capture_buffer_queued_) {
+    HandleFrameCapture();
+  } else if (dump_output_to_file_) {
     HandleFrameDump();
   }
 }
 
+void HWCDisplayBuiltIn::HandleFrameCapture() {
+  if (readback_configured_ && (output_buffer_.release_fence_fd >= 0)) {
+    frame_capture_status_ = sync_wait(output_buffer_.release_fence_fd, 1000);
+    ::close(output_buffer_.release_fence_fd);
+    output_buffer_.release_fence_fd = -1;
+  }
+
+  frame_capture_buffer_queued_ = false;
+  readback_buffer_queued_ = false;
+  post_processed_output_ = false;
+  readback_configured_ = false;
+  output_buffer_ = {};
+}
+
 void HWCDisplayBuiltIn::HandleFrameDump() {
   if (!readback_configured_) {
     dump_frame_count_ = 0;
@@ -694,14 +710,12 @@
 
   const native_handle_t *buffer = static_cast<native_handle_t *>(output_buffer_info.private_data);
   SetReadbackBuffer(buffer, -1, post_processed_output);
+  frame_capture_buffer_queued_ = true;
+  frame_capture_status_ = -EAGAIN;
 
   return 0;
 }
 
-bool HWCDisplayBuiltIn::GetFrameCaptureFence(int32_t *release_fence) {
-  return (GetReadbackBufferFence(release_fence) == HWC2::Error::None);
-}
-
 DisplayError HWCDisplayBuiltIn::SetDetailEnhancerConfig
                                    (const DisplayDetailEnhancerData &de_data) {
   DisplayError error = kErrorNotSupported;