From 5458cf8ec62c548480d5bb142afa71e4269ddac9 Mon Sep 17 00:00:00 2001 From: Yuqian Li Date: Wed, 24 May 2017 09:58:07 -0400 Subject: [PATCH] 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 Commit-Queue: Yuqian Li --- samplecode/SampleApp.cpp | 15 +++++++++++++++ samplecode/SampleApp.h | 3 +++ 2 files changed, 18 insertions(+) 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 @@ 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 diff --git a/samplecode/SampleApp.h b/samplecode/SampleApp.h index 65037f7..4fd75ab 100644 --- a/samplecode/SampleApp.h +++ b/samplecode/SampleApp.h @@ -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; -- 2.7.4