fps property
double
get
fps
Implementation
static double get fps {
int sum = 0;
for (FrameTiming timing in lastFrames) {
// 计算渲染耗时
int duration = timing.timestampInMicroseconds(FramePhase.rasterFinish) -
timing.timestampInMicroseconds(FramePhase.buildStart);
// 判断耗时是否在 Vsync 信号周期内
if (duration < frameInterval.inMicroseconds) {
sum += 1;
} else {
// 有丢帧,向上取整
int count = (duration / frameInterval.inMicroseconds).ceil();
sum += count;
}
}
return lastFrames.length / sum * 60;
}