Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: tools/viewer/Viewer.cpp

Issue 2043793002: Show FPS in UI state (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: line100 Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/viewer/Viewer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "Viewer.h" 8 #include "Viewer.h"
9 9
10 #include "GMSlide.h" 10 #include "GMSlide.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 " [Vulkan]" 60 " [Vulkan]"
61 }; 61 };
62 62
63 const char* kName = "name"; 63 const char* kName = "name";
64 const char* kValue = "value"; 64 const char* kValue = "value";
65 const char* kOptions = "options"; 65 const char* kOptions = "options";
66 const char* kSlideStateName = "Slide"; 66 const char* kSlideStateName = "Slide";
67 const char* kBackendStateName = "Backend"; 67 const char* kBackendStateName = "Backend";
68 const char* kSoftkeyStateName = "Softkey"; 68 const char* kSoftkeyStateName = "Softkey";
69 const char* kSoftkeyHint = "Please select a softkey"; 69 const char* kSoftkeyHint = "Please select a softkey";
70 70 const char* kFpsStateName = "FPS";
71 71
72 Viewer::Viewer(int argc, char** argv, void* platformData) 72 Viewer::Viewer(int argc, char** argv, void* platformData)
73 : fCurrentMeasurement(0) 73 : fCurrentMeasurement(0)
74 , fDisplayStats(false) 74 , fDisplayStats(false)
75 , fBackendType(sk_app::Window::kVulkan_BackendType) 75 , fBackendType(sk_app::Window::kVulkan_BackendType)
76 , fZoomCenterX(0.0f) 76 , fZoomCenterX(0.0f)
77 , fZoomCenterY(0.0f) 77 , fZoomCenterY(0.0f)
78 , fZoomLevel(0.0f) 78 , fZoomLevel(0.0f)
79 , fZoomScale(SK_Scalar1) 79 , fZoomScale(SK_Scalar1)
80 { 80 {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 fAnimTimer.run(); 163 fAnimTimer.run();
164 164
165 // set up first frame 165 // set up first frame
166 fCurrentSlide = 0; 166 fCurrentSlide = 0;
167 setupCurrentSlide(-1); 167 setupCurrentSlide(-1);
168 168
169 fWindow->show(); 169 fWindow->show();
170 } 170 }
171 171
172 void Viewer::initSlides() { 172 void Viewer::initSlides() {
173 fAllSlideNames = Json::Value(Json::arrayValue);
174
173 const skiagm::GMRegistry* gms(skiagm::GMRegistry::Head()); 175 const skiagm::GMRegistry* gms(skiagm::GMRegistry::Head());
174 while (gms) { 176 while (gms) {
175 SkAutoTDelete<skiagm::GM> gm(gms->factory()(nullptr)); 177 SkAutoTDelete<skiagm::GM> gm(gms->factory()(nullptr));
176 178
177 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, gm->getName())) { 179 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, gm->getName())) {
178 sk_sp<Slide> slide(new GMSlide(gm.release())); 180 sk_sp<Slide> slide(new GMSlide(gm.release()));
179 fSlides.push_back(slide); 181 fSlides.push_back(slide);
180 } 182 }
181 183
182 gms = gms->next(); 184 gms = gms->next();
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 405
404 void Viewer::onIdle(double ms) { 406 void Viewer::onIdle(double ms) {
405 // Record measurements 407 // Record measurements
406 fMeasurements[fCurrentMeasurement++] = ms; 408 fMeasurements[fCurrentMeasurement++] = ms;
407 fCurrentMeasurement &= (kMeasurementCount - 1); // fast mod 409 fCurrentMeasurement &= (kMeasurementCount - 1); // fast mod
408 SkASSERT(fCurrentMeasurement < kMeasurementCount); 410 SkASSERT(fCurrentMeasurement < kMeasurementCount);
409 411
410 fAnimTimer.updateTime(); 412 fAnimTimer.updateTime();
411 if (fSlides[fCurrentSlide]->animate(fAnimTimer) || fDisplayStats) { 413 if (fSlides[fCurrentSlide]->animate(fAnimTimer) || fDisplayStats) {
412 fWindow->inval(); 414 fWindow->inval();
415 updateUIState(); // Update the FPS
413 } 416 }
414 } 417 }
415 418
416 void Viewer::updateUIState() { 419 void Viewer::updateUIState() {
417 // Slide state 420 // Slide state
418 Json::Value slideState(Json::objectValue); 421 Json::Value slideState(Json::objectValue);
419 slideState[kName] = kSlideStateName; 422 slideState[kName] = kSlideStateName;
420 slideState[kValue] = fSlides[fCurrentSlide]->getName().c_str(); 423 slideState[kValue] = fSlides[fCurrentSlide]->getName().c_str();
421 Json::Value allSlideNames(Json::arrayValue); 424 if (fAllSlideNames.size() == 0) {
422 for(auto slide : fSlides) { 425 for(auto slide : fSlides) {
423 allSlideNames.append(Json::Value(slide->getName().c_str())); 426 fAllSlideNames.append(Json::Value(slide->getName().c_str()));
427 }
424 } 428 }
425 slideState[kOptions] = allSlideNames; 429 slideState[kOptions] = fAllSlideNames;
426 430
427 // Backend state 431 // Backend state
428 Json::Value backendState(Json::objectValue); 432 Json::Value backendState(Json::objectValue);
429 backendState[kName] = kBackendStateName; 433 backendState[kName] = kBackendStateName;
430 backendState[kValue] = kBackendTypeStrings[fBackendType]; 434 backendState[kValue] = kBackendTypeStrings[fBackendType];
431 backendState[kOptions] = Json::Value(Json::arrayValue); 435 backendState[kOptions] = Json::Value(Json::arrayValue);
432 for (auto str : kBackendTypeStrings) { 436 for (auto str : kBackendTypeStrings) {
433 backendState[kOptions].append(Json::Value(str)); 437 backendState[kOptions].append(Json::Value(str));
434 } 438 }
435 439
436 // Softkey state 440 // Softkey state
437 Json::Value softkeyState(Json::objectValue); 441 Json::Value softkeyState(Json::objectValue);
438 softkeyState[kName] = kSoftkeyStateName; 442 softkeyState[kName] = kSoftkeyStateName;
439 softkeyState[kValue] = kSoftkeyHint; 443 softkeyState[kValue] = kSoftkeyHint;
440 softkeyState[kOptions] = Json::Value(Json::arrayValue); 444 softkeyState[kOptions] = Json::Value(Json::arrayValue);
441 softkeyState[kOptions].append(kSoftkeyHint); 445 softkeyState[kOptions].append(kSoftkeyHint);
442 for (const auto& softkey : fCommands.getCommandsAsSoftkeys()) { 446 for (const auto& softkey : fCommands.getCommandsAsSoftkeys()) {
443 softkeyState[kOptions].append(Json::Value(softkey.c_str())); 447 softkeyState[kOptions].append(Json::Value(softkey.c_str()));
444 } 448 }
445 449
450 // FPS state
451 Json::Value fpsState(Json::objectValue);
452 fpsState[kName] = kFpsStateName;
453 double measurement = fMeasurements[
454 (fCurrentMeasurement + (kMeasurementCount-1)) % kMeasurementCount
455 ];
456 fpsState[kValue] = SkStringPrintf("%8.3lf ms", measurement).c_str();
457 fpsState[kOptions] = Json::Value(Json::arrayValue);
458
446 Json::Value state(Json::arrayValue); 459 Json::Value state(Json::arrayValue);
447 state.append(slideState); 460 state.append(slideState);
448 state.append(backendState); 461 state.append(backendState);
449 state.append(softkeyState); 462 state.append(softkeyState);
463 state.append(fpsState);
450 464
451 fWindow->setUIState(state); 465 fWindow->setUIState(state);
452 } 466 }
453 467
454 void Viewer::onUIStateChanged(const SkString& stateName, const SkString& stateVa lue) { 468 void Viewer::onUIStateChanged(const SkString& stateName, const SkString& stateVa lue) {
455 // For those who will add more features to handle the state change in this f unction: 469 // For those who will add more features to handle the state change in this f unction:
456 // After the change, please call updateUIState no notify the frontend (e.g., Android app). 470 // After the change, please call updateUIState no notify the frontend (e.g., Android app).
457 // For example, after slide change, updateUIState is called inside setupCurr entSlide; 471 // For example, after slide change, updateUIState is called inside setupCurr entSlide;
458 // after backend change, updateUIState is called in this function. 472 // after backend change, updateUIState is called in this function.
459 if (stateName.equals(kSlideStateName)) { 473 if (stateName.equals(kSlideStateName)) {
(...skipping 26 matching lines...) Expand all
486 } 500 }
487 } else if (stateName.equals(kSoftkeyStateName)) { 501 } else if (stateName.equals(kSoftkeyStateName)) {
488 if (!stateValue.equals(kSoftkeyHint)) { 502 if (!stateValue.equals(kSoftkeyHint)) {
489 fCommands.onSoftkey(stateValue); 503 fCommands.onSoftkey(stateValue);
490 updateUIState(); // This is still needed to reset the value to kSoft keyHint 504 updateUIState(); // This is still needed to reset the value to kSoft keyHint
491 } 505 }
492 } else { 506 } else {
493 SkDebugf("Unknown stateName: %s", stateName.c_str()); 507 SkDebugf("Unknown stateName: %s", stateName.c_str());
494 } 508 }
495 } 509 }
OLDNEW
« no previous file with comments | « tools/viewer/Viewer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698