Add cumulative fps to SampleApp
In some samples (whose frame time is really really small),
the fps number jumps so fast that I can hardly see even
the first digit of the number. This problem will become
more severe for threaded backend which substantially lowers
the frame time. Taking an average over a long time would
give me a much more stable fps number.
Bug: skia:
Change-Id: Ie6052b4735d9410d5e644331bf025b5bf9f40323
Reviewed-on: https://skia-review.googlesource.com/17823
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Yuqian Li <liyuqian@google.com>
diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp
index bdd1ef1..87873f1 100644
--- a/samplecode/SampleApp.cpp
+++ b/samplecode/SampleApp.cpp
@@ -383,6 +383,7 @@
}
void windowSizeChanged(SampleWindow* win) override {
+ win->resetFPS();
#if SK_SUPPORT_GPU
if (fCurContext) {
AttachmentInfo attachmentInfo;
@@ -1480,6 +1481,8 @@
orig->flush();
fTimer.end();
fMeasureFPS_Time += fTimer.fWall;
+ fCumulativeFPS_Time += fTimer.fWall;
+ fCumulativeFPS_Count += FPS_REPEAT_COUNT;
}
}
@@ -1582,6 +1585,7 @@
this->inval(nullptr);
}
bool SampleWindow::previousSample() {
+ this->resetFPS();
fCurrIndex = (fCurrIndex - 1 + fSamples.count()) % fSamples.count();
this->loadView((*fSamples[fCurrIndex])());
return true;
@@ -1590,6 +1594,7 @@
#include "SkResourceCache.h"
#include "SkGlyphCache.h"
bool SampleWindow::nextSample() {
+ this->resetFPS();
fCurrIndex = (fCurrIndex + 1) % fSamples.count();
this->loadView((*fSamples[fCurrIndex])());
@@ -1603,6 +1608,7 @@
}
bool SampleWindow::goToSample(int i) {
+ this->resetFPS();
fCurrIndex = (i) % fSamples.count();
this->loadView((*fSamples[fCurrIndex])());
return true;
@@ -1869,6 +1875,9 @@
this->inval(nullptr);
}
break;
+ case '0':
+ this->resetFPS();
+ break;
case 'A':
if (gSkUseAnalyticAA.load() && !gSkForceAnalyticAA.load()) {
gSkForceAnalyticAA = true;
@@ -2001,6 +2010,11 @@
this->inval(nullptr);
}
+void SampleWindow::resetFPS() {
+ fCumulativeFPS_Time = 0;
+ fCumulativeFPS_Count = 0;
+}
+
void SampleWindow::toggleDistanceFieldFonts() {
// reset backend
fDevManager->tearDownBackend(this);
@@ -2279,6 +2293,7 @@
if (fMeasureFPS) {
title.appendf(" %8.4f ms", fMeasureFPS_Time / (float)FPS_REPEAT_COUNT);
+ title.appendf(" -> %4.4f ms", fCumulativeFPS_Time / (float)SkTMax(1, fCumulativeFPS_Count));
}
#if SK_SUPPORT_GPU