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;
@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;
#include "SkRandom.h"
#include "SkStream.h"
#include "SkSurface.h"
+#include "SkTime.h"
using namespace sk_app;
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)
}
void Viewer::onPaint(SkCanvas* canvas) {
+ // Record measurements
+ double startTime = SkTime::GetMSecs();
+
drawSlide(canvas, false);
if (fSplitScreen && fWindow->supportsContentRect()) {
drawSlide(canvas, true);
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) {
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
}
}
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());
}
~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);
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;
virtual ~Application() {}
- virtual void onIdle(double ms) = 0;
+ virtual void onIdle() = 0;
};
} // namespace sk_app
#include "../Application.h"
#include "Timer.h"
-static double now_ms() { return SkTime::GetNSecs() * 1e-6; }
-
using sk_app::Application;
/**
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.
return;
}
- previousTime = currentTime;
- currentTime = now_ms();
- vkApp->onIdle(currentTime - previousTime);
+ vkApp->onIdle();
}
}
}
#include "SkTypes.h"
#include "SkUtils.h"
#include "Window_android.h"
-#include "SkTime.h"
namespace sk_app {
return 1; // continue receiving callbacks
}
-static double now_ms() { return SkTime::GetMSecs(); }
-
void* SkiaAndroidApp::pthread_main(void* arg) {
SkDebugf("pthread_main begins");
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();
}
}
using sk_app::Application;
-static double now_ms() { return SkTime::GetNSecs() * 1e-6; }
-
void finishWindow(sk_app::Window_unix* win) {
win->finishResize();
win->finishPaint();
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;
pendingWindows.foreach(finishWindow);
if (pendingWindows.count() > 0) {
- previousTime = currentTime;
- currentTime = now_ms();
- app->onIdle(currentTime - previousTime);
+ app->onIdle();
}
pendingWindows.reset();
}
#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);
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();
}
}