Fix Choreographer affecting ASurfaceControlTest
Fixes `testSurfaceTransaction_setFrameTimeline_notPreferredIndex` case
on devices that do not have high refresh rates (e.g. max 60Hz). This
occurred because the transaction-ready logic in SF does not consider
transactions to be too early if the expected presentation time is over
100ms in the future, so the frame would just be deemed ready and
presented asap. Thus, no longer provide frame timelines that are far
into the future, which are not useful as well.
Test: atest ASurfaceControlTest
Test: atest ChoreographerTest
Test: atest ChoreographerNativeTest
Test: atest DisplayEventStructLayoutTest
Test: atest ParcelableVsyncEventData
Test: atest libsurfacefligner_unittest
Fixes: 270612751
Change-Id: Ic05717bc153a9b07409b8d7912a1c40e1e31a57e
diff --git a/services/surfaceflinger/Scheduler/EventThread.cpp b/services/surfaceflinger/Scheduler/EventThread.cpp
index 74665a7..f79688d 100644
--- a/services/surfaceflinger/Scheduler/EventThread.cpp
+++ b/services/surfaceflinger/Scheduler/EventThread.cpp
@@ -42,6 +42,7 @@
#include <utils/Errors.h>
#include <utils/Trace.h>
+#include <scheduler/VsyncConfig.h>
#include "DisplayHardware/DisplayMode.h"
#include "FrameTimeline.h"
#include "VSyncDispatch.h"
@@ -597,25 +598,34 @@
nsecs_t timestamp,
nsecs_t preferredExpectedPresentationTime,
nsecs_t preferredDeadlineTimestamp) const {
+ uint32_t currentIndex = 0;
// Add 1 to ensure the preferredFrameTimelineIndex entry (when multiplier == 0) is included.
- for (int64_t multiplier = -VsyncEventData::kFrameTimelinesLength + 1, currentIndex = 0;
+ for (int64_t multiplier = -VsyncEventData::kFrameTimelinesLength + 1;
currentIndex < VsyncEventData::kFrameTimelinesLength; multiplier++) {
nsecs_t deadlineTimestamp = preferredDeadlineTimestamp + multiplier * frameInterval;
- // Valid possible frame timelines must have future values.
- if (deadlineTimestamp > timestamp) {
- if (multiplier == 0) {
- outVsyncEventData.preferredFrameTimelineIndex = currentIndex;
- }
- nsecs_t expectedPresentationTime =
- preferredExpectedPresentationTime + multiplier * frameInterval;
- outVsyncEventData.frameTimelines[currentIndex] =
- {.vsyncId =
- generateToken(timestamp, deadlineTimestamp, expectedPresentationTime),
- .deadlineTimestamp = deadlineTimestamp,
- .expectedPresentationTime = expectedPresentationTime};
- currentIndex++;
+ // Valid possible frame timelines must have future values, so find a later frame timeline.
+ if (deadlineTimestamp <= timestamp) {
+ continue;
}
+
+ nsecs_t expectedPresentationTime =
+ preferredExpectedPresentationTime + multiplier * frameInterval;
+ if (expectedPresentationTime >= preferredExpectedPresentationTime +
+ scheduler::VsyncConfig::kEarlyLatchMaxThreshold.count()) {
+ break;
+ }
+
+ if (multiplier == 0) {
+ outVsyncEventData.preferredFrameTimelineIndex = currentIndex;
+ }
+
+ outVsyncEventData.frameTimelines[currentIndex] =
+ {.vsyncId = generateToken(timestamp, deadlineTimestamp, expectedPresentationTime),
+ .deadlineTimestamp = deadlineTimestamp,
+ .expectedPresentationTime = expectedPresentationTime};
+ currentIndex++;
}
+ outVsyncEventData.frameTimelinesLength = currentIndex;
}
void EventThread::dispatchEvent(const DisplayEventReceiver::Event& event,