aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorGravatar liyuqian <liyuqian@google.com>2016-06-07 06:57:40 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-06-07 06:57:40 -0700
commit1f508fd0fed5a91c0fccde8ba1c81a91e7fbe7d2 (patch)
treea78a7acf6442af2ffbec937d2cf54842f126fc1f /tools
parent06115ee4300ef6756729dfbcb3e2fc70ebf0413a (diff)
Show FPS in UI state
Diffstat (limited to 'tools')
-rw-r--r--tools/viewer/Viewer.cpp24
-rw-r--r--tools/viewer/Viewer.h2
2 files changed, 21 insertions, 5 deletions
diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp
index c11b82bec0..de4c4cce30 100644
--- a/tools/viewer/Viewer.cpp
+++ b/tools/viewer/Viewer.cpp
@@ -67,7 +67,7 @@ const char* kSlideStateName = "Slide";
const char* kBackendStateName = "Backend";
const char* kSoftkeyStateName = "Softkey";
const char* kSoftkeyHint = "Please select a softkey";
-
+const char* kFpsStateName = "FPS";
Viewer::Viewer(int argc, char** argv, void* platformData)
: fCurrentMeasurement(0)
@@ -170,6 +170,8 @@ Viewer::Viewer(int argc, char** argv, void* platformData)
}
void Viewer::initSlides() {
+ fAllSlideNames = Json::Value(Json::arrayValue);
+
const skiagm::GMRegistry* gms(skiagm::GMRegistry::Head());
while (gms) {
SkAutoTDelete<skiagm::GM> gm(gms->factory()(nullptr));
@@ -410,6 +412,7 @@ void Viewer::onIdle(double ms) {
fAnimTimer.updateTime();
if (fSlides[fCurrentSlide]->animate(fAnimTimer) || fDisplayStats) {
fWindow->inval();
+ updateUIState(); // Update the FPS
}
}
@@ -418,11 +421,12 @@ void Viewer::updateUIState() {
Json::Value slideState(Json::objectValue);
slideState[kName] = kSlideStateName;
slideState[kValue] = fSlides[fCurrentSlide]->getName().c_str();
- Json::Value allSlideNames(Json::arrayValue);
- for(auto slide : fSlides) {
- allSlideNames.append(Json::Value(slide->getName().c_str()));
+ if (fAllSlideNames.size() == 0) {
+ for(auto slide : fSlides) {
+ fAllSlideNames.append(Json::Value(slide->getName().c_str()));
+ }
}
- slideState[kOptions] = allSlideNames;
+ slideState[kOptions] = fAllSlideNames;
// Backend state
Json::Value backendState(Json::objectValue);
@@ -443,10 +447,20 @@ void Viewer::updateUIState() {
softkeyState[kOptions].append(Json::Value(softkey.c_str()));
}
+ // FPS state
+ Json::Value fpsState(Json::objectValue);
+ fpsState[kName] = kFpsStateName;
+ double measurement = fMeasurements[
+ (fCurrentMeasurement + (kMeasurementCount-1)) % kMeasurementCount
+ ];
+ fpsState[kValue] = SkStringPrintf("%8.3lf ms", measurement).c_str();
+ fpsState[kOptions] = Json::Value(Json::arrayValue);
+
Json::Value state(Json::arrayValue);
state.append(slideState);
state.append(backendState);
state.append(softkeyState);
+ state.append(fpsState);
fWindow->setUIState(state);
}
diff --git a/tools/viewer/Viewer.h b/tools/viewer/Viewer.h
index 4b260dfc1d..3a4164df16 100644
--- a/tools/viewer/Viewer.h
+++ b/tools/viewer/Viewer.h
@@ -66,6 +66,8 @@ private:
// identity unless the window initially scales the content to fit the screen.
SkMatrix fDefaultMatrix;
SkMatrix fDefaultMatrixInv;
+
+ Json::Value fAllSlideNames; // cache all slide names for fast updateUIState
};