Add cumulative fps to SampleApp
authorYuqian Li <liyuqian@google.com>
Wed, 24 May 2017 13:58:07 +0000 (09:58 -0400)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Wed, 24 May 2017 15:38:17 +0000 (15:38 +0000)
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>

samplecode/SampleApp.cpp
samplecode/SampleApp.h

index bdd1ef16734dd16ee92c1056bdb881b99a5d0c33..87873f16f10974af8c0865a4b7c18f1364ac2840 100644 (file)
@@ -383,6 +383,7 @@ public:
     }
 
     void windowSizeChanged(SampleWindow* win) override {
+        win->resetFPS();
 #if SK_SUPPORT_GPU
         if (fCurContext) {
             AttachmentInfo attachmentInfo;
@@ -1480,6 +1481,8 @@ void SampleWindow::afterChildren(SkCanvas* orig) {
         orig->flush();
         fTimer.end();
         fMeasureFPS_Time += fTimer.fWall;
+        fCumulativeFPS_Time += fTimer.fWall;
+        fCumulativeFPS_Count += FPS_REPEAT_COUNT;
     }
 }
 
@@ -1582,6 +1585,7 @@ void SampleWindow::updateMatrix(){
     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 @@ bool SampleWindow::previousSample() {
 #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::nextSample() {
 }
 
 bool SampleWindow::goToSample(int i) {
+    this->resetFPS();
     fCurrIndex = (i) % fSamples.count();
     this->loadView((*fSamples[fCurrIndex])());
     return true;
@@ -1869,6 +1875,9 @@ bool SampleWindow::onHandleChar(SkUnichar uni) {
                 this->inval(nullptr);
             }
             break;
+        case '0':
+            this->resetFPS();
+            break;
         case 'A':
             if (gSkUseAnalyticAA.load() && !gSkForceAnalyticAA.load()) {
                 gSkForceAnalyticAA = true;
@@ -2001,6 +2010,11 @@ void SampleWindow::toggleFPS() {
     this->inval(nullptr);
 }
 
+void SampleWindow::resetFPS() {
+    fCumulativeFPS_Time = 0;
+    fCumulativeFPS_Count = 0;
+}
+
 void SampleWindow::toggleDistanceFieldFonts() {
     // reset backend
     fDevManager->tearDownBackend(this);
@@ -2279,6 +2293,7 @@ void SampleWindow::updateTitle() {
 
     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
index 65037f7c0c3683a5eacfb863dee70a6771d09ec9..4fd75abc6dc485540324dbf1212cb82612ad4494 100644 (file)
@@ -134,6 +134,7 @@ public:
     void toggleRendering();
     void toggleSlideshow();
     void toggleFPS();
+    void resetFPS();
     void showOverview();
     void toggleDistanceFieldFonts();
     void setPixelGeometry(int pixelGeometryIndex);
@@ -213,6 +214,8 @@ private:
     bool fUseDeferredCanvas;
     WallTimer fTimer;
     double fMeasureFPS_Time;
+    double fCumulativeFPS_Time;
+    int    fCumulativeFPS_Count;
     bool fMagnify;
     int fTilingMode;