drm_hwcomposer: Support DisplayCommand.expectedPresentTime
DisplayCommand.expectedPresentTime indicates that the HWC should present
the composition as close to the desired time as possible. It may be that
the desired time is some number of vsync periods in the future.
A drm atomic commit will always present at the next vsync, and there is
no mechanism for userspace to indicate a desired present time.
Lacking a kernel uAPI to support this, an alternative is to sleep in
userspace until the next expected vsync aligns with the expected present
time.
Change-Id: Iad703eed9b0e459194f895339dd604990875f157
Signed-off-by: Drew Davenport <ddavenport@google.com>
diff --git a/hwc2_device/HwcDisplay.h b/hwc2_device/HwcDisplay.h
index 069a6ee..d0b4a47 100644
--- a/hwc2_device/HwcDisplay.h
+++ b/hwc2_device/HwcDisplay.h
@@ -97,7 +97,7 @@
auto GetConfig(hwc2_config_t config_id) const -> const HwcDisplayConfig *;
auto GetDisplayBoundsMm() -> std::pair<int32_t, int32_t>;
-
+
// To be called after SetDisplayProperties. Returns an empty vector if the
// requested layers have been validated, otherwise the vector describes
// the requested composition type changes.
@@ -107,11 +107,14 @@
// Mark previously validated properties as ready to present.
auto AcceptValidatedComposition() -> void;
+ using ReleaseFence = std::pair<ILayerId, SharedFd>;
// Present previously staged properties, and return fences to indicate when
// the new content has been presented, and when the previous buffers have
- // been released.
- using ReleaseFence = std::pair<ILayerId, SharedFd>;
- auto PresentStagedComposition(SharedFd &out_present_fence,
+ // been released. If |desired_present_time| is set, ensure that the
+ // composition is presented at the closest vsync to that requested time.
+ // Otherwise, present immediately.
+ auto PresentStagedComposition(std::optional<int64_t> desired_present_time,
+ SharedFd &out_present_fence,
std::vector<ReleaseFence> &out_release_fences)
-> bool;
@@ -254,6 +257,10 @@
const HwcDisplayConfig *config,
const std::optional<LayerData> &modeset_layer);
+ // Sleep the current thread until |present_time| is closest to the next
+ // expected vsync time.
+ void WaitForPresentTime(int64_t present_time, uint32_t vsync_period_ns);
+
HwcDisplayConfigs configs_;
DrmHwc *const hwc_;