Index: tools/viewer/Viewer.cpp |
diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp |
index 0ed7e26f0a940e635d455b6a4ed19d0ccf2e1110..ff77cc444ef569d5c7864e61fcbdf8bd69b4da21 100644 |
--- a/tools/viewer/Viewer.cpp |
+++ b/tools/viewer/Viewer.cpp |
@@ -20,6 +20,7 @@ |
#include "SkRandom.h" |
#include "SkStream.h" |
#include "SkSurface.h" |
+#include "SkTime.h" |
using namespace sk_app; |
@@ -86,10 +87,12 @@ const char* kFpsStateName = "FPS"; |
const char* kSplitScreenStateName = "Split screen"; |
const char* kON = "ON"; |
const char* kOFF = "OFF"; |
+const char* kRefreshStateName = "Refresh"; |
Viewer::Viewer(int argc, char** argv, void* platformData) |
: fCurrentMeasurement(0) |
, fDisplayStats(false) |
+ , fRefresh(false) |
, fSplitScreen(false) |
, fBackendType(sk_app::Window::kNativeGL_BackendType) |
, fZoomCenterX(0.0f) |
@@ -400,6 +403,9 @@ void Viewer::drawSlide(SkCanvas* canvas, bool inSplitScreen) { |
} |
void Viewer::onPaint(SkCanvas* canvas) { |
+ // Record measurements |
+ double startTime = SkTime::GetMSecs(); |
+ |
drawSlide(canvas, false); |
if (fSplitScreen && fWindow->supportsContentRect()) { |
drawSlide(canvas, true); |
@@ -409,6 +415,11 @@ void Viewer::onPaint(SkCanvas* canvas) { |
drawStats(canvas); |
} |
fCommands.drawHelp(canvas); |
+ |
+ fMeasurements[fCurrentMeasurement++] = SkTime::GetMSecs() - startTime; |
+ fCurrentMeasurement &= (kMeasurementCount - 1); // fast mod |
+ SkASSERT(fCurrentMeasurement < kMeasurementCount); |
+ updateUIState(); // Update the FPS |
} |
bool Viewer::onTouch(intptr_t owner, Window::InputState state, float x, float y) { |
@@ -480,16 +491,10 @@ void Viewer::drawStats(SkCanvas* canvas) { |
canvas->restore(); |
} |
-void Viewer::onIdle(double ms) { |
- // Record measurements |
- fMeasurements[fCurrentMeasurement++] = ms; |
- fCurrentMeasurement &= (kMeasurementCount - 1); // fast mod |
- SkASSERT(fCurrentMeasurement < kMeasurementCount); |
- |
+void Viewer::onIdle() { |
fAnimTimer.updateTime(); |
- if (fSlides[fCurrentSlide]->animate(fAnimTimer) || fDisplayStats) { |
+ if (fSlides[fCurrentSlide]->animate(fAnimTimer) || fDisplayStats || fRefresh) { |
fWindow->inval(); |
- updateUIState(); // Update the FPS |
} |
} |
@@ -596,6 +601,10 @@ void Viewer::onUIStateChanged(const SkString& stateName, const SkString& stateVa |
fWindow->inval(); |
updateUIState(); |
} |
+ } else if (stateName.equals(kRefreshStateName)) { |
+ // This state is actually NOT in the UI state. |
+ // We use this to allow Android to quickly set bool fRefresh. |
+ fRefresh = stateValue.equals(kON); |
} else { |
SkDebugf("Unknown stateName: %s", stateName.c_str()); |
} |