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/compositor/DrmDisplayComposition.h b/compositor/DrmDisplayComposition.h
index 27b34f2..1738630 100644
--- a/compositor/DrmDisplayComposition.h
+++ b/compositor/DrmDisplayComposition.h
@@ -127,16 +127,10 @@
return planner_;
}
- int take_out_fence() {
- return out_fence_.Release();
- }
-
- void set_out_fence(int out_fence) {
- out_fence_.Set(out_fence);
- }
-
void Dump(std::ostringstream *out) const;
+ UniqueFd out_fence_;
+
private:
bool validate_composition_type(DrmCompositionType desired);
@@ -147,8 +141,6 @@
uint32_t dpms_mode_ = DRM_MODE_DPMS_ON;
DrmMode display_mode_;
- UniqueFd out_fence_ = -1;
-
bool geometry_changed_ = true;
std::vector<DrmHwcLayer> layers_;
std::vector<DrmCompositionPlane> composition_planes_;