SF: use TextureView hint when selecting the refresh rate
SF would only try to heuristically calculate the frame rate of a layer
when TextureView is updating. This fixes a bug where SF tries to
heuristically calculate the frame rate for UI animations but fails
due to long frames.
Bug: 280249265
Test: Playing a video on Facebook and observe refresh rate
Test: go/cb-pcmark
Change-Id: Ic98484b8313f1e8e6ad01297b63bb64da6d4a6dd
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index 3371ae2..a821466 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -3077,6 +3077,7 @@
mDrawingState.desiredPresentTime = desiredPresentTime;
mDrawingState.isAutoTimestamp = isAutoTimestamp;
mDrawingState.latchedVsyncId = info.vsyncId;
+ mDrawingState.useVsyncIdForRefreshRateSelection = info.useForRefreshRateSelection;
mDrawingState.modified = true;
if (!buffer) {
resetDrawingStateBufferInfo();
@@ -3139,15 +3140,31 @@
}
void Layer::recordLayerHistoryBufferUpdate(const scheduler::LayerProps& layerProps) {
+ ATRACE_CALL();
const nsecs_t presentTime = [&] {
- if (!mDrawingState.isAutoTimestamp) return mDrawingState.desiredPresentTime;
+ if (!mDrawingState.isAutoTimestamp) {
+ ATRACE_FORMAT_INSTANT("desiredPresentTime");
+ return mDrawingState.desiredPresentTime;
+ }
- const auto prediction = mFlinger->mFrameTimeline->getTokenManager()->getPredictionsForToken(
- mDrawingState.latchedVsyncId);
- if (prediction.has_value()) return prediction->presentTime;
+ if (mDrawingState.useVsyncIdForRefreshRateSelection) {
+ const auto prediction =
+ mFlinger->mFrameTimeline->getTokenManager()->getPredictionsForToken(
+ mDrawingState.latchedVsyncId);
+ if (prediction.has_value()) {
+ ATRACE_FORMAT_INSTANT("predictedPresentTime");
+ return prediction->presentTime;
+ }
+ }
return static_cast<nsecs_t>(0);
}();
+
+ if (ATRACE_ENABLED() && presentTime > 0) {
+ const auto presentIn = TimePoint::fromNs(presentTime) - TimePoint::now();
+ ATRACE_FORMAT_INSTANT("presentIn %s", to_string(presentIn).c_str());
+ }
+
mFlinger->mScheduler->recordLayerHistory(sequence, layerProps, presentTime,
scheduler::LayerHistory::LayerUpdateType::Buffer);
}