Index: tools/viewer/Viewer.cpp |
diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp |
index 9f3b8f2e27df62d505737ac37a8d0503c7d63d98..9ee1bf925908ab7fa7137c156d0cc09a7afeb9a9 100644 |
--- a/tools/viewer/Viewer.cpp |
+++ b/tools/viewer/Viewer.cpp |
@@ -422,9 +422,11 @@ void Viewer::updateUIState() { |
// 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[kValue] = kBackendTypeStrings[fBackendType]; |
backendState[kOptions] = Json::Value(Json::arrayValue); |
+ for(auto str : kBackendTypeStrings) { |
+ backendState[kOptions].append(Json::Value(str)); |
+ } |
Json::Value state(Json::arrayValue); |
state.append(slideState); |
@@ -434,7 +436,10 @@ void Viewer::updateUIState() { |
} |
void Viewer::onUIStateChanged(const SkString& stateName, const SkString& stateValue) { |
- // Currently, we only recognize the Slide state |
+ // For those who will add more features to handle the state change in this function: |
+ // After the change, please call updateUIState no notify the frontend (e.g., Android app). |
+ // For example, after slide change, updateUIState is called inside setupCurrentSlide; |
+ // after backend change, updateUIState is called in this function. |
if (stateName.equals(kSlideStateName)) { |
int previousSlide = fCurrentSlide; |
fCurrentSlide = 0; |
@@ -449,6 +454,20 @@ void Viewer::onUIStateChanged(const SkString& stateName, const SkString& stateVa |
fCurrentSlide = previousSlide; |
SkDebugf("Slide not found: %s", stateValue.c_str()); |
} |
+ } else if (stateName.equals(kBackendStateName)) { |
+ for (int i = 0; i < sk_app::Window::kBackendTypeCount; i++) { |
+ if (stateValue.equals(kBackendTypeStrings[i])) { |
+ if (fBackendType != i) { |
+ fBackendType = (sk_app::Window::BackendType)i; |
+ fWindow->detach(); |
+ fWindow->attach(fBackendType, DisplayParams()); |
+ fWindow->inval(); |
+ updateTitle(); |
scroggo
2016/06/02 18:58:37
nit:
this->updateTitle();
this->updateUIState();
|
+ updateUIState(); |
+ } |
+ break; |
+ } |
+ } |
} else { |
SkDebugf("Unknown stateName: %s", stateName.c_str()); |
} |