diff options
author | Jim Van Verth <jvanverth@google.com> | 2017-11-03 13:36:07 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-11-03 18:26:34 +0000 |
commit | 90dcce5e50a5a5368a094566f7b764409353aa4a (patch) | |
tree | 72766fbdb450e4db2b17903428fceacad71612df /tools/viewer | |
parent | c30d9534bd8a35fa22b4f4f86780fbf015ce3ef4 (diff) |
Add ms display to Viewer.
Change-Id: I6303209d3ff597611ac1a5f558294c6d6fcba670
Reviewed-on: https://skia-review.googlesource.com/67766
Reviewed-by: Yuqian Li <liyuqian@google.com>
Commit-Queue: Jim Van Verth <jvanverth@google.com>
Diffstat (limited to 'tools/viewer')
-rw-r--r-- | tools/viewer/Viewer.cpp | 49 | ||||
-rw-r--r-- | tools/viewer/Viewer.h | 5 |
2 files changed, 50 insertions, 4 deletions
diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp index 2355d985b3..f13136931e 100644 --- a/tools/viewer/Viewer.cpp +++ b/tools/viewer/Viewer.cpp @@ -253,6 +253,8 @@ const char* kRefreshStateName = "Refresh"; Viewer::Viewer(int argc, char** argv, void* platformData) : fCurrentMeasurement(0) + , fCumulativeMeasurementTime(0) + , fCumulativeMeasurementCount(0) , fDisplayStats(false) , fRefresh(false) , fShowImGuiDebugWindow(false) @@ -337,6 +339,11 @@ Viewer::Viewer(int argc, char** argv, void* platformData) this->fDisplayStats = !this->fDisplayStats; fWindow->inval(); }); + fCommands.addCommand('0', "Overlays", "Reset stats", [this]() { + this->resetMeasurements(); + this->updateTitle(); + fWindow->inval(); + }); fCommands.addCommand('c', "Modes", "Cycle color mode", [this]() { switch (fColorMode) { case ColorMode::kLegacy: @@ -609,6 +616,24 @@ void Viewer::updateTitle() { title.appendf(" %s", curPrimaries >= 0 ? gNamedPrimaries[curPrimaries].fName : "Custom"); } + if (fDisplayStats) { + double ms = 0; + int count = 0; + int i = (fCurrentMeasurement + kMeasurementCount - 1) & (kMeasurementCount - 1); + do { + double inc = fAnimateTimes[i] + fPaintTimes[i] + fFlushTimes[i]; + if (inc <= 0) { + break; + } + ms += inc; + ++count; + i = (i + kMeasurementCount - 1) & (kMeasurementCount - 1); + } while (i != fCurrentMeasurement); + + title.appendf(" %8.4f ms -> %4.4f ms", ms / SkTMax(1, count), + fCumulativeMeasurementTime / SkTMax(1, fCumulativeMeasurementCount)); + } + title.append(" ["); title.append(kBackendTypeStrings[fBackendType]); if (int msaa = fWindow->sampleCount()) { @@ -650,6 +675,15 @@ void Viewer::listNames() { } } +void Viewer::resetMeasurements() { + memset(fPaintTimes, 0, sizeof(fPaintTimes)); + memset(fFlushTimes, 0, sizeof(fFlushTimes)); + memset(fAnimateTimes, 0, sizeof(fAnimateTimes)); + fCurrentMeasurement = 0; + fCumulativeMeasurementTime = 0; + fCumulativeMeasurementCount = 0; +} + void Viewer::setupCurrentSlide(int previousSlide) { if (fCurrentSlide == previousSlide) { return; // no change; do nothing @@ -679,6 +713,9 @@ void Viewer::setupCurrentSlide(int previousSlide) { if (previousSlide >= 0) { fSlides[previousSlide]->unload(); } + + this->resetMeasurements(); + fWindow->inval(); } @@ -837,6 +874,7 @@ void Viewer::onBackendCreated() { this->updateTitle(); this->updateUIState(); this->setupCurrentSlide(-1); + this->resetMeasurements(); fWindow->show(); fWindow->inval(); } @@ -854,22 +892,27 @@ void Viewer::onPaint(SkCanvas* canvas) { ImGui::NewFrame(); - drawSlide(canvas); + this->drawSlide(canvas); // Advance our timing bookkeeping + fCumulativeMeasurementTime += fAnimateTimes[fCurrentMeasurement] + + fPaintTimes[fCurrentMeasurement] + + fFlushTimes[fCurrentMeasurement]; + fCumulativeMeasurementCount++; fCurrentMeasurement = (fCurrentMeasurement + 1) & (kMeasurementCount - 1); SkASSERT(fCurrentMeasurement < kMeasurementCount); // Draw any overlays or UI that we don't want timed if (fDisplayStats) { drawStats(canvas); + this->updateTitle(); } fCommands.drawHelp(canvas); - drawImGui(canvas); + this->drawImGui(canvas); // Update the FPS - updateUIState(); + this->updateUIState(); } bool Viewer::onTouch(intptr_t owner, Window::InputState state, float x, float y) { diff --git a/tools/viewer/Viewer.h b/tools/viewer/Viewer.h index 1b68007ede..e37a945b7e 100644 --- a/tools/viewer/Viewer.h +++ b/tools/viewer/Viewer.h @@ -47,6 +47,7 @@ private: void setStartupSlide(); void setupCurrentSlide(int previousSlide); void listNames(); + void resetMeasurements(); void updateUIState(); @@ -59,11 +60,13 @@ private: sk_app::Window* fWindow; - static const int kMeasurementCount = 64; // should be power of 2 for fast mod + static const int kMeasurementCount = 1 << 6; // should be power of 2 for fast mod double fPaintTimes[kMeasurementCount]; double fFlushTimes[kMeasurementCount]; double fAnimateTimes[kMeasurementCount]; int fCurrentMeasurement; + double fCumulativeMeasurementTime; + int fCumulativeMeasurementCount; SkAnimTimer fAnimTimer; SkTArray<sk_sp<Slide>> fSlides; |