SF: avoid skipping waiting for the earliest time to present
When the next expected presentation time is not allocated for
the previous frame, SF needs to wait before submitting it to HWC
to prevent early presentation.
Bug: 273419557
Test: tested by partner
Test: atest ASurfaceControlTest
Change-Id: Ia83755bbc71968369fd9176944b9a85135d8a04a
diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.cpp b/services/surfaceflinger/DisplayHardware/HWComposer.cpp
index 28148ac..f350eba 100644
--- a/services/surfaceflinger/DisplayHardware/HWComposer.cpp
+++ b/services/surfaceflinger/DisplayHardware/HWComposer.cpp
@@ -395,8 +395,8 @@
status_t HWComposer::getDeviceCompositionChanges(
HalDisplayId displayId, bool frameUsesClientComposition,
- std::chrono::steady_clock::time_point earliestPresentTime,
- const std::shared_ptr<FenceTime>& previousPresentFence, nsecs_t expectedPresentTime,
+ std::optional<std::chrono::steady_clock::time_point> earliestPresentTime,
+ nsecs_t expectedPresentTime,
std::optional<android::HWComposer::DeviceRequestedChanges>* outChanges) {
ATRACE_CALL();
@@ -426,14 +426,13 @@
// If composer supports getting the expected present time, we can skip
// as composer will make sure to prevent early presentation
- if (mComposer->isSupported(Hwc2::Composer::OptionalFeature::ExpectedPresentTime)) {
+ if (!earliestPresentTime) {
return true;
}
// composer doesn't support getting the expected present time. We can only
// skip validate if we know that we are not going to present early.
- return std::chrono::steady_clock::now() >= earliestPresentTime ||
- previousPresentFence->getSignalTime() == Fence::SIGNAL_TIME_PENDING;
+ return std::chrono::steady_clock::now() >= *earliestPresentTime;
}();
displayData.validateWasSkipped = false;
@@ -508,8 +507,8 @@
}
status_t HWComposer::presentAndGetReleaseFences(
- HalDisplayId displayId, std::chrono::steady_clock::time_point earliestPresentTime,
- const std::shared_ptr<FenceTime>& previousPresentFence) {
+ HalDisplayId displayId,
+ std::optional<std::chrono::steady_clock::time_point> earliestPresentTime) {
ATRACE_CALL();
RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
@@ -525,13 +524,9 @@
return NO_ERROR;
}
- const bool waitForEarliestPresent =
- !mComposer->isSupported(Hwc2::Composer::OptionalFeature::ExpectedPresentTime) &&
- previousPresentFence->getSignalTime() != Fence::SIGNAL_TIME_PENDING;
-
- if (waitForEarliestPresent) {
+ if (earliestPresentTime) {
ATRACE_NAME("wait for earliest present time");
- std::this_thread::sleep_until(earliestPresentTime);
+ std::this_thread::sleep_until(*earliestPresentTime);
}
auto error = hwcDisplay->present(&displayData.lastPresentFence);