diff options
author | 2016-07-06 14:11:32 -0700 | |
---|---|---|
committer | 2016-07-06 14:11:32 -0700 | |
commit | 2edb0f4a02fd1dbb8d6cb628b84048bcc875f72f (patch) | |
tree | a5e2e0c234f592a617eda847cf1cf47f4a2c8661 /tools/viewer | |
parent | 5b794fad18344e8dbb840be49d1bc66ebe754b31 (diff) |
More accurate render time and continuous fresh
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2129613002
Review-Url: https://codereview.chromium.org/2129613002
Diffstat (limited to 'tools/viewer')
-rw-r--r-- | tools/viewer/Viewer.cpp | 25 | ||||
-rw-r--r-- | tools/viewer/Viewer.h | 3 | ||||
-rw-r--r-- | tools/viewer/sk_app/Application.h | 2 | ||||
-rw-r--r-- | tools/viewer/sk_app/android/main_android.cpp | 9 | ||||
-rw-r--r-- | tools/viewer/sk_app/android/surface_glue_android.cpp | 9 | ||||
-rw-r--r-- | tools/viewer/sk_app/unix/main_unix.cpp | 9 | ||||
-rw-r--r-- | tools/viewer/sk_app/win/main_win.cpp | 9 |
7 files changed, 24 insertions, 42 deletions
diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp index 0ed7e26f0a..ff77cc444e 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()); } diff --git a/tools/viewer/Viewer.h b/tools/viewer/Viewer.h index e140e1b87a..1ed135d819 100644 --- a/tools/viewer/Viewer.h +++ b/tools/viewer/Viewer.h @@ -24,7 +24,7 @@ public: ~Viewer() override; void onPaint(SkCanvas* canvas); - void onIdle(double ms) override; + void onIdle() override; bool onTouch(intptr_t owner, sk_app::Window::InputState state, float x, float y); void onUIStateChanged(const SkString& stateName, const SkString& stateValue); @@ -52,6 +52,7 @@ private: int fCurrentSlide; bool fDisplayStats; + bool fRefresh; // whether to continuously refresh for measuring render time // whether to split the screen and draw two copies of the slide, one with sRGB and one without bool fSplitScreen; diff --git a/tools/viewer/sk_app/Application.h b/tools/viewer/sk_app/Application.h index 235ff09ed4..df9a20d358 100644 --- a/tools/viewer/sk_app/Application.h +++ b/tools/viewer/sk_app/Application.h @@ -16,7 +16,7 @@ public: virtual ~Application() {} - virtual void onIdle(double ms) = 0; + virtual void onIdle() = 0; }; } // namespace sk_app diff --git a/tools/viewer/sk_app/android/main_android.cpp b/tools/viewer/sk_app/android/main_android.cpp index 9334f0ccd3..ee2dab570d 100644 --- a/tools/viewer/sk_app/android/main_android.cpp +++ b/tools/viewer/sk_app/android/main_android.cpp @@ -13,8 +13,6 @@ #include "../Application.h" #include "Timer.h" -static double now_ms() { return SkTime::GetNSecs() * 1e-6; } - using sk_app::Application; /** @@ -36,9 +34,6 @@ void android_main(struct android_app* state) { const_cast<char**>(gCmdLine), state)); - double currentTime = 0.0; - double previousTime = 0.0; - // loop waiting for stuff to do. while (1) { // Read all pending events. @@ -60,9 +55,7 @@ void android_main(struct android_app* state) { return; } - previousTime = currentTime; - currentTime = now_ms(); - vkApp->onIdle(currentTime - previousTime); + vkApp->onIdle(); } } } diff --git a/tools/viewer/sk_app/android/surface_glue_android.cpp b/tools/viewer/sk_app/android/surface_glue_android.cpp index 0c1ab0cca2..d001cd5367 100644 --- a/tools/viewer/sk_app/android/surface_glue_android.cpp +++ b/tools/viewer/sk_app/android/surface_glue_android.cpp @@ -22,7 +22,6 @@ #include "SkTypes.h" #include "SkUtils.h" #include "Window_android.h" -#include "SkTime.h" namespace sk_app { @@ -167,8 +166,6 @@ int SkiaAndroidApp::message_callback(int fd, int events, void* data) { return 1; // continue receiving callbacks } -static double now_ms() { return SkTime::GetMSecs(); } - void* SkiaAndroidApp::pthread_main(void* arg) { SkDebugf("pthread_main begins"); @@ -184,17 +181,13 @@ void* SkiaAndroidApp::pthread_main(void* arg) { skiaAndroidApp->fApp = Application::Create(0, nullptr, skiaAndroidApp); - double currentTime = 0.0; - double previousTime = 0.0; while (true) { const int ident = ALooper_pollAll(0, nullptr, nullptr, nullptr); if (ident >= 0) { SkDebugf("Unhandled ALooper_pollAll ident=%d !", ident); } else { - previousTime = currentTime; - currentTime = now_ms(); - skiaAndroidApp->fApp->onIdle(currentTime - previousTime); + skiaAndroidApp->fApp->onIdle(); } } diff --git a/tools/viewer/sk_app/unix/main_unix.cpp b/tools/viewer/sk_app/unix/main_unix.cpp index d595379174..5e6b7fe3ee 100644 --- a/tools/viewer/sk_app/unix/main_unix.cpp +++ b/tools/viewer/sk_app/unix/main_unix.cpp @@ -13,8 +13,6 @@ using sk_app::Application; -static double now_ms() { return SkTime::GetNSecs() * 1e-6; } - void finishWindow(sk_app::Window_unix* win) { win->finishResize(); win->finishPaint(); @@ -26,9 +24,6 @@ int main(int argc, char**argv) { Application* app = Application::Create(argc, argv, (void*)display); - double currentTime = 0.0; - double previousTime = 0.0; - // Get the file descriptor for the X display int x11_fd = ConnectionNumber(display); fd_set in_fds; @@ -75,9 +70,7 @@ int main(int argc, char**argv) { pendingWindows.foreach(finishWindow); if (pendingWindows.count() > 0) { - previousTime = currentTime; - currentTime = now_ms(); - app->onIdle(currentTime - previousTime); + app->onIdle(); } pendingWindows.reset(); } diff --git a/tools/viewer/sk_app/win/main_win.cpp b/tools/viewer/sk_app/win/main_win.cpp index ba1629c837..4800258973 100644 --- a/tools/viewer/sk_app/win/main_win.cpp +++ b/tools/viewer/sk_app/win/main_win.cpp @@ -27,8 +27,6 @@ static char* tchar_to_utf8(const TCHAR* str) { #endif } -static double now_ms() { return SkTime::GetNSecs() * 1e-6; } - // This file can work with GUI or CONSOLE subsystem types since we define _tWinMain and main(). static int main_common(HINSTANCE hInstance, int show, int argc, char**argv); @@ -66,18 +64,13 @@ static int main_common(HINSTANCE hInstance, int show, int argc, char**argv) { MSG msg = { 0 }; - double currentTime = 0.0; - double previousTime = 0.0; - // Main message loop while (WM_QUIT != msg.message) { if (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } else { - previousTime = currentTime; - currentTime = now_ms(); - app->onIdle(currentTime - previousTime); + app->onIdle(); } } |