services/surfaceflinger/SurfaceFlinger.cpp
// frameTime:当前时间 expectedVsyncTime:期待的上屏时间,未来的硬件vsync时间
bool SurfaceFlinger::commit(nsecs_t frameTime, int64_t vsyncId, nsecs_t expectedVsyncTime)
FTL_FAKE_GUARD(kMainThreadContext) {
ATRACE_CALL();
// calculate the expected present time once and use the cached
// value throughout this frame to make sure all layers are
// seeing this same value.
if (expectedVsyncTime >= frameTime) {
mExpectedPresentTime = expectedVsyncTime;
} else {
const DisplayStatInfo stats = mScheduler->getDisplayStatInfo(frameTime);
mExpectedPresentTime = calculateExpectedPresentTime(stats);
}
const nsecs_t lastScheduledPresentTime = mScheduledPresentTime;
mScheduledPresentTime = expectedVsyncTime;
const auto vsyncIn = [&] {
if (!ATRACE_ENABLED()) return 0.f;
return (mExpectedPresentTime - systemTime()) / 1e6f;
}();
// 打印相关的trace 在未来的的多少毫秒内提交(从现在到规划上帧的硬件vsync时间)
ATRACE_FORMAT("%s %" PRId64 " vsyncIn %.2fms%s", __func__, vsyncId, vsyncIn,
mExpectedPresentTime == expectedVsyncTime ? "" : " (adjusted)");
// When Backpressure propagation is enabled we want to give a small grace period
// for the present fence to fire instead of just giving up on this frame to handle cases
// where present fence is just about to get signaled.
const int graceTimeForPresentFenceMs =
(mPropagateBackpressureClientComposition || !mHadClientComposition) ? 1 : 0;
ATRACE_INT("graceTimeForPresentFenceMs", graceTimeForPresentFenceMs);
// Pending frames may trigger backpressure propagation.
/*
* previousFramePending 上一帧的PresentFence的是否已经single, 没有single的话则previousFramePending 为ture
* 说明 上一帧的 合成定然超时
* */
const TracedOrdinal<bool> framePending = {"PrevFramePending",
previousFramePending(graceTimeForPresentFenceMs)};
// Frame missed counts for metrics tracking.
// A frame is missed if the prior frame is still pending. If no longer pending,
// then we still count the frame as missed if the predicted present time
// was further in the past than when the fence actually fired.
// Add some slop to correct for drift. This should generally be
// smaller than a typical frame duration, but should not be so small
// that it reports reasonable drift as a missed frame.
const DisplayStatInfo stats = mScheduler->getDisplayStatInfo(systemTime());
const nsecs_t frameMissedSlop = stats.vsyncPeriod / 2;
// 获取上一帧 PresentFence 的 sigle time
const nsecs_t previousPresentTime = previousFramePresentTime();
/*
* 总结一下:
* previousPresentTime:上一帧 PresentFence 的 sigle time
* lastScheduledPresentTime:当前帧的期待的上屏时间,未来的硬件vsync时间
* framePending: 上一帧的合成是否超时
* frameMissedSlop:当前周期的一半
* */
/*
* frameMissed 主要是用来 表明 当前的帧的合成 frameMissed: 用来在正式合成前预测 当前帧的合成是否错过 当前帧的期待的上屏时间
* */
const TracedOrdinal<bool> frameMissed = {"PrevFrameMissed",
framePending ||
(previousPresentTime >= 0 &&
(lastScheduledPresentTime <
previousPresentTime - frameMissedSlop))};
const TracedOrdinal<bool> hwcFrameMissed = {"PrevHwcFrameMissed",
mHadDeviceComposition && frameMissed};
const TracedOrdinal<bool> gpuFrameMissed = {"PrevGpuFrameMissed",
mHadClientComposition && frameMissed};
/*
* TracedOrdinal 重载了类型转换运算符, 故 if (frameMissed) 相当于把 TracedOrdinal 转换为 bool,
* 触发了 类型抓换操作,根据 TracedOrdinal的定义,返回的是 TracedOrdinal.mData
* */
if (frameMissed) {
mFrameMissedCount++;
mTimeStats->incrementMissedFrames();
}
if (hwcFrameMissed) {
mHwcFrameMissedCount++;
}
if (gpuFrameMissed) {
mGpuFrameMissedCount++;
}
SurfaceFlinger::commit frameMissed计算
最新推荐文章于 2024-06-27 18:56:26 发布
本文介绍了Android系统中SurfaceFlinger组件的commit函数,关注于帧时间管理,预期上屏时间计算,以及帧错过检测,包括回压传播处理和性能跟踪指标。
摘要由CSDN通过智能技术生成