aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/viewer/Viewer.cpp
diff options
context:
space:
mode:
authorGravatar liyuqian <liyuqian@google.com>2016-06-02 12:16:25 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-06-02 12:16:25 -0700
commit6cb70251829a467b146da9bc8925064f33608e48 (patch)
treebbd9e5d31aceebaf0a96684e68a421ef56cf7269 /tools/viewer/Viewer.cpp
parent0dd9f2cbc445c477a840743420a6b2867ebbe120 (diff)
Implement OpenGL backend in Android viewer app
Diffstat (limited to 'tools/viewer/Viewer.cpp')
-rw-r--r--tools/viewer/Viewer.cpp25
1 files changed, 22 insertions, 3 deletions
diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp
index 5228a0fd12..c73b1ba9ce 100644
--- a/tools/viewer/Viewer.cpp
+++ b/tools/viewer/Viewer.cpp
@@ -424,9 +424,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);
@@ -436,7 +438,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;
@@ -451,6 +456,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();
+ updateUIState();
+ }
+ break;
+ }
+ }
} else {
SkDebugf("Unknown stateName: %s", stateName.c_str());
}