From: liyuqian Date: Wed, 6 Jul 2016 21:11:32 +0000 (-0700) Subject: More accurate render time and continuous fresh X-Git-Tag: accepted/tizen/5.0/unified/20181102.025319~116^2~950 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2edb0f4a02fd1dbb8d6cb628b84048bcc875f72f;p=platform%2Fupstream%2FlibSkiaSharp.git 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 --- diff --git a/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/StateAdapter.java b/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/StateAdapter.java index 6c080bd..3aea965 100644 --- a/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/StateAdapter.java +++ b/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/StateAdapter.java @@ -37,6 +37,9 @@ public class StateAdapter extends BaseAdapter implements AdapterView.OnItemSelec private static final String OPTIONS = "options"; private static final String BACKEND_STATE_NAME = "Backend"; private static final String FPS_STATE_NAME = "FPS"; + private static final String REFRESH_STATE_NAME = "Refresh"; + private static final String ON = "ON"; + private static final String OFF = "OFF"; private static final int FILTER_LENGTH = 20; private ViewerActivity mViewerActivity; @@ -103,6 +106,8 @@ public class StateAdapter extends BaseAdapter implements AdapterView.OnItemSelec @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mFPSFloatText.setVisibility(isChecked ? View.VISIBLE : View.INVISIBLE); + // Quickly set the bool fRefresh in native Viewer app for continuous refresh + mViewerActivity.onStateChanged(REFRESH_STATE_NAME, isChecked ? ON : OFF); } }); return view; diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp index 0ed7e26..ff77cc4 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 e140e1b..1ed135d 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 235ff09..df9a20d 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 9334f0c..ee2dab5 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(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 0c1ab0c..d001cd5 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 d595379..5e6b7fe 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 ba1629c..4800258 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(); } }