drm_hwcomposer: Rework autofd
Motivation:
Current implementation of UniqueFd can be used in a different ways,
making analytical tracking of FD lifecycle much harder than it may be.
Keep this part clean is very important, since any wrong code may open
a hard-to-detect runtime bugs and fd leaks, which may accidentally slip
into the production.
Implementation:
1. Combine UniqueFd anf OutputFd into single class.
2. Reduce the API to be minimal and sufficient.
3. Document the API and use cases.
4. Move to utils/UniqueFd.h.
5. dup(fd) was replaced with fcntl(fd, F_DUPFD_CLOEXEC)) to
address clang-tidy findings. Find more information at [1]
[1]: https://clang.llvm.org/extra/clang-tidy/checks/android-cloexec-dup.html
Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
diff --git a/DrmHwcTwo.h b/DrmHwcTwo.h
index b4e1ce8..748fc81 100644
--- a/DrmHwcTwo.h
+++ b/DrmHwcTwo.h
@@ -82,27 +82,6 @@
buffer_ = buffer;
}
- int take_acquire_fence() {
- return acquire_fence_.Release();
- }
- void set_acquire_fence(int acquire_fence) {
- acquire_fence_.Set(dup(acquire_fence));
- }
-
- int release_fence() {
- return release_fence_.get();
- }
- int take_release_fence() {
- return release_fence_.Release();
- }
- void manage_release_fence() {
- release_fence_.Set(release_fence_raw_);
- release_fence_raw_ = -1;
- }
- OutputFd release_fence_output() {
- return OutputFd(&release_fence_raw_);
- }
-
hwc_rect_t display_frame() {
return display_frame_;
}
@@ -138,6 +117,10 @@
HWC2::Error SetLayerVisibleRegion(hwc_region_t visible);
HWC2::Error SetLayerZOrder(uint32_t order);
+ UniqueFd acquire_fence_;
+
+ UniqueFd release_fence_;
+
private:
// sf_type_ stores the initial type given to us by surfaceflinger,
// validated_type_ stores the type after running ValidateDisplay
@@ -146,9 +129,6 @@
HWC2::BlendMode blending_ = HWC2::BlendMode::None;
buffer_handle_t buffer_ = NULL;
- UniqueFd acquire_fence_;
- int release_fence_raw_ = -1;
- UniqueFd release_fence_;
hwc_rect_t display_frame_;
float alpha_ = 1.0f;
hwc_frect_t source_crop_;
@@ -316,7 +296,7 @@
}
private:
- void AddFenceToPresentFence(int fd);
+ void AddFenceToPresentFence(UniqueFd fd);
constexpr static size_t MATRIX_SIZE = 16;