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

Unified Diff: tools/viewer/Viewer.cpp

Issue 2004633002: Add drawer with state information (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Format Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/viewer/Viewer.h ('k') | tools/viewer/sk_app/Window.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/viewer/Viewer.cpp
diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp
index c4b8b26dc51e3fda5a43a66962f5dba0a397de0d..f0de75d543f31cc46ee579079744139498a9414f 100644
--- a/tools/viewer/Viewer.cpp
+++ b/tools/viewer/Viewer.cpp
@@ -35,6 +35,12 @@ static bool on_touch_handler(int owner, Window::InputState state, float x, float
return viewer->onTouch(owner, state, x, y);
}
+static void on_ui_state_changed_handler(const SkString& stateName, const SkString& stateValue, void* userData) {
+ Viewer* viewer = reinterpret_cast<Viewer*>(userData);
+
+ return viewer->onUIStateChanged(stateName, stateValue);
+}
+
DEFINE_bool2(fullscreen, f, true, "Run fullscreen.");
DEFINE_string(key, "", "Space-separated key/value pairs to add to JSON identifying this builder.");
DEFINE_string2(match, m, nullptr,
@@ -53,6 +59,12 @@ const char *kBackendTypeStrings[sk_app::Window::kBackendTypeCount] = {
" [Vulkan]"
};
+const char* kName = "name";
+const char* kValue = "value";
+const char* kOptions = "options";
+const char* kSlideStateName = "Slide";
+const char* kBackendStateName = "Backend";
+
Viewer::Viewer(int argc, char** argv, void* platformData)
: fCurrentMeasurement(0)
, fDisplayStats(false)
@@ -79,6 +91,7 @@ Viewer::Viewer(int argc, char** argv, void* platformData)
fCommands.attach(fWindow);
fWindow->registerPaintFunc(on_paint_handler, this);
fWindow->registerTouchFunc(on_touch_handler, this);
+ fWindow->registerUIStateChangedFunc(on_ui_state_changed_handler, this);
// add key-bindings
fCommands.addCommand('s', "Overlays", "Toggle stats display", [this]() {
@@ -213,6 +226,10 @@ void Viewer::updateTitle() {
}
void Viewer::setupCurrentSlide(int previousSlide) {
+ if (fCurrentSlide == previousSlide) {
+ return; // no change; do nothing
+ }
+
fGesture.reset();
fDefaultMatrix.reset();
fDefaultMatrixInv.reset();
@@ -235,6 +252,7 @@ void Viewer::setupCurrentSlide(int previousSlide) {
}
this->updateTitle();
+ this->fWindow->setUIState(computeUIStateJson());
djsollen 2016/05/26 18:08:40 just call a private updateUIState() function that
fSlides[fCurrentSlide]->load();
if (previousSlide >= 0) {
fSlides[previousSlide]->unload();
@@ -382,3 +400,48 @@ void Viewer::onIdle(double ms) {
fWindow->inval();
}
}
+
+Json::Value Viewer::computeUIStateJson() const {
djsollen 2016/05/26 18:08:40 rename to updateUIState
+ Json::Value slideState(Json::objectValue);
+ slideState[kName] = kSlideStateName;
+ slideState[kValue] = fSlides[fCurrentSlide]->getName().c_str();
+ Json::Value allSlideNames(Json::arrayValue);
+ for(auto slide : fSlides) {
+ allSlideNames.append(Json::Value(slide->getName().c_str()));
+ }
+ slideState[kOptions] = allSlideNames;
+
+ // This state is currently a demo for the one without options.
+ // We will be able to change the backend too.
+ Json::Value backendState(Json::objectValue);
+ backendState[kName] = kBackendStateName;
+ backendState[kValue] = fBackendType == sk_app::Window::kVulkan_BackendType ?
+ "Vulkan" : "Other than Vulkan";
+ backendState[kOptions] = Json::Value(Json::arrayValue);
+
+ Json::Value state(Json::arrayValue);
+ state.append(slideState);
+ state.append(backendState);
+ return state;
+}
+
+void Viewer::onUIStateChanged(const SkString& stateName, const SkString& stateValue) {
+ // Currently, we only recognize the Slide state
+ if (stateName.equals(kSlideStateName)) {
+ int previousSlide = fCurrentSlide;
+ fCurrentSlide = 0;
+ for(auto slide : fSlides) {
+ if (slide->getName().equals(stateValue)) {
+ setupCurrentSlide(previousSlide);
+ break;
+ }
+ fCurrentSlide++;
+ }
+ if (fCurrentSlide >= fSlides.count()) {
+ fCurrentSlide = previousSlide;
+ SkDebugf("Slide not found: %s", stateValue.c_str());
+ }
+ } else {
+ SkDebugf("Unknown stateName: %s", stateName.c_str());
+ }
+}
« no previous file with comments | « tools/viewer/Viewer.h ('k') | tools/viewer/sk_app/Window.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698