drm_hwcomposer: Introduce SharedFd, use standard c++ RAII for UniqueFd
We use too much dup() system calls for present fence propagating.
Also when propagating acquire fence we use additional logic for
skipping such propagation for the validate/test cycle.
Both issues can be solved by introducing SharedFd, which will track
reference count of fd object.
After that the UniqueFd is used very rarely and can be simplified by
wrapping it into std::unique_ptr without caring too much of adding
an extra malloc/free operation.
Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
diff --git a/hwc2_device/HwcDisplay.cpp b/hwc2_device/HwcDisplay.cpp
index 194889e..d957dc3 100644
--- a/hwc2_device/HwcDisplay.cpp
+++ b/hwc2_device/HwcDisplay.cpp
@@ -452,7 +452,7 @@
}
layers[num_layers - 1] = l.first;
- fences[num_layers - 1] = UniqueFd::Dup(present_fence_.Get()).Release();
+ fences[num_layers - 1] = DupFd(present_fence_);
}
*num_elements = num_layers;
@@ -592,8 +592,8 @@
if (ret != HWC2::Error::None)
return ret;
- this->present_fence_ = UniqueFd::Dup(a_args.out_fence.Get());
- *out_present_fence = a_args.out_fence.Release();
+ this->present_fence_ = a_args.out_fence;
+ *out_present_fence = DupFd(a_args.out_fence);
++frame_no_;
return HWC2::Error::None;
diff --git a/hwc2_device/HwcDisplay.h b/hwc2_device/HwcDisplay.h
index 4ad57b7..6cac60f 100644
--- a/hwc2_device/HwcDisplay.h
+++ b/hwc2_device/HwcDisplay.h
@@ -200,7 +200,7 @@
DrmHwcTwo *const hwc2_;
- UniqueFd present_fence_;
+ SharedFd present_fence_;
std::optional<DrmMode> staged_mode_;
int64_t staged_mode_change_time_{};
diff --git a/hwc2_device/HwcLayer.cpp b/hwc2_device/HwcLayer.cpp
index 589a0a7..d3936b3 100644
--- a/hwc2_device/HwcLayer.cpp
+++ b/hwc2_device/HwcLayer.cpp
@@ -53,7 +53,7 @@
*/
HWC2::Error HwcLayer::SetLayerBuffer(buffer_handle_t buffer,
int32_t acquire_fence) {
- acquire_fence_ = UniqueFd(acquire_fence);
+ acquire_fence_ = MakeUniqueFd(acquire_fence);
buffer_handle_ = buffer;
buffer_handle_updated_ = true;
diff --git a/hwc2_device/HwcLayer.h b/hwc2_device/HwcLayer.h
index 627d5ac..7f647a8 100644
--- a/hwc2_device/HwcLayer.h
+++ b/hwc2_device/HwcLayer.h
@@ -86,8 +86,7 @@
uint32_t z_order_ = 0;
LayerData layer_data_;
- /* Should be populated to layer_data_.acquire_fence only before presenting */
- UniqueFd acquire_fence_;
+ SharedFd acquire_fence_;
/* The following buffer data can have 2 sources:
* 1 - Mapper@4 metadata API