hwc2: Fix retire fences

The HWC2 header does not require deferring the retire fence, also
known as the present fence. The retire fence is now known as the
present fence in the HWC2 header and it belongs to the
current frame that is submitted and is signalled when the current
frame is picked up. Also, the retire fence was incorrectly set to
the release fence of the output buffer. Use the retire fence
instead.

Bug: 30204952
Change-Id: Ide2fdcc27d0ed42119ccb1e37e16d43c32a39790
diff --git a/msm8996/sdm/libs/hwc2/hwc_display.cpp b/msm8996/sdm/libs/hwc2/hwc_display.cpp
index 8d4fd8a..6194184 100644
--- a/msm8996/sdm/libs/hwc2/hwc_display.cpp
+++ b/msm8996/sdm/libs/hwc2/hwc_display.cpp
@@ -895,25 +895,21 @@
     }
   }
 
-  *out_retire_fence = stored_retire_fence_;
+  *out_retire_fence = -1;
   if (!flush_) {
     // if swapinterval property is set to 0 then close and reset the list retire fence
     if (swap_interval_zero_) {
       close(layer_stack_.retire_fence_fd);
       layer_stack_.retire_fence_fd = -1;
     }
-    stored_retire_fence_ = layer_stack_.retire_fence_fd;
-    if (id_ == HWC_DISPLAY_PRIMARY) {
-      *out_retire_fence = layer_stack_.retire_fence_fd;
-    }
+    *out_retire_fence = layer_stack_.retire_fence_fd;
 
     if (dump_frame_count_) {
       dump_frame_count_--;
       dump_frame_index_++;
     }
-  } else {
-    stored_retire_fence_ = -1;
   }
+
   geometry_changes_ = GeometryChanges::kNone;
   flush_ = false;
 
diff --git a/msm8996/sdm/libs/hwc2/hwc_display.h b/msm8996/sdm/libs/hwc2/hwc_display.h
index 880fca2..cc90694 100644
--- a/msm8996/sdm/libs/hwc2/hwc_display.h
+++ b/msm8996/sdm/libs/hwc2/hwc_display.h
@@ -259,7 +259,6 @@
   bool validated_ = false;
   bool color_tranform_failed_ = false;
   HWCColorMode *color_mode_ = NULL;
-  int32_t stored_retire_fence_ = -1;
 
  private:
   void DumpInputBuffers(void);
diff --git a/msm8996/sdm/libs/hwc2/hwc_display_virtual.cpp b/msm8996/sdm/libs/hwc2/hwc_display_virtual.cpp
index 32ec36a..90e3015 100644
--- a/msm8996/sdm/libs/hwc2/hwc_display_virtual.cpp
+++ b/msm8996/sdm/libs/hwc2/hwc_display_virtual.cpp
@@ -148,13 +148,6 @@
       }
 
       status = HWCDisplay::PostCommitLayerStack(out_retire_fence);
-      // On Virtual displays, use the output buffer release fence as the retire fence
-      // Close the layer stack retire fence as it is unused
-      if (layer_stack_.output_buffer) {
-        stored_retire_fence_ = layer_stack_.output_buffer->release_fence_fd;
-        close(layer_stack_.retire_fence_fd);
-        layer_stack_.retire_fence_fd = -1;
-      }
     }
   }
   CloseAcquireFds();