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

Side by Side Diff: tools/viewer/sk_app/android/surface_glue_android.cpp

Issue 2016343002: Revert of Add drawer with state information (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 6 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 unified diff | Download patch
« no previous file with comments | « tools/viewer/sk_app/android/surface_glue_android.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "surface_glue_android.h" 8 #include "surface_glue_android.h"
9 9
10 #include <jni.h> 10 #include <jni.h>
(...skipping 28 matching lines...) Expand all
39 {AMOTION_EVENT_ACTION_POINTER_UP, Window::kUp_InputState}, 39 {AMOTION_EVENT_ACTION_POINTER_UP, Window::kUp_InputState},
40 {AMOTION_EVENT_ACTION_MOVE, Window::kMove_InputState}, 40 {AMOTION_EVENT_ACTION_MOVE, Window::kMove_InputState},
41 {AMOTION_EVENT_ACTION_CANCEL, Window::kUp_InputState}, 41 {AMOTION_EVENT_ACTION_CANCEL, Window::kUp_InputState},
42 }); 42 });
43 43
44 SkiaAndroidApp::SkiaAndroidApp(JNIEnv* env, jobject androidApp) { 44 SkiaAndroidApp::SkiaAndroidApp(JNIEnv* env, jobject androidApp) {
45 env->GetJavaVM(&fJavaVM); 45 env->GetJavaVM(&fJavaVM);
46 fAndroidApp = env->NewGlobalRef(androidApp); 46 fAndroidApp = env->NewGlobalRef(androidApp);
47 jclass cls = env->GetObjectClass(fAndroidApp); 47 jclass cls = env->GetObjectClass(fAndroidApp);
48 fSetTitleMethodID = env->GetMethodID(cls, "setTitle", "(Ljava/lang/String;)V "); 48 fSetTitleMethodID = env->GetMethodID(cls, "setTitle", "(Ljava/lang/String;)V ");
49 fSetStateMethodID = env->GetMethodID(cls, "setState", "(Ljava/lang/String;)V ");
50 fNativeWindow = nullptr; 49 fNativeWindow = nullptr;
51 pthread_create(&fThread, nullptr, pthread_main, this); 50 pthread_create(&fThread, nullptr, pthread_main, this);
52 } 51 }
53 52
54 SkiaAndroidApp::~SkiaAndroidApp() { 53 SkiaAndroidApp::~SkiaAndroidApp() {
55 fPThreadEnv->DeleteGlobalRef(fAndroidApp); 54 fPThreadEnv->DeleteGlobalRef(fAndroidApp);
56 if (fWindow) { 55 if (fWindow) {
57 fWindow->detach(); 56 fWindow->detach();
58 } 57 }
59 if (fNativeWindow) { 58 if (fNativeWindow) {
60 ANativeWindow_release(fNativeWindow); 59 ANativeWindow_release(fNativeWindow);
61 fNativeWindow = nullptr; 60 fNativeWindow = nullptr;
62 } 61 }
63 if (fApp) { 62 if (fApp) {
64 delete fApp; 63 delete fApp;
65 } 64 }
66 } 65 }
67 66
68 void SkiaAndroidApp::setTitle(const char* title) const { 67 void SkiaAndroidApp::setTitle(const char* title) const {
69 jstring titleString = fPThreadEnv->NewStringUTF(title); 68 jstring titleString = fPThreadEnv->NewStringUTF(title);
70 fPThreadEnv->CallVoidMethod(fAndroidApp, fSetTitleMethodID, titleString); 69 fPThreadEnv->CallVoidMethod(fAndroidApp, fSetTitleMethodID, titleString);
71 fPThreadEnv->DeleteLocalRef(titleString); 70 fPThreadEnv->DeleteLocalRef(titleString);
72 } 71 }
73 72
74 void SkiaAndroidApp::setUIState(const Json::Value& state) const {
75 jstring jstr = fPThreadEnv->NewStringUTF(state.toStyledString().c_str());
76 fPThreadEnv->CallVoidMethod(fAndroidApp, fSetStateMethodID, jstr);
77 fPThreadEnv->DeleteLocalRef(jstr);
78 }
79
80 void SkiaAndroidApp::postMessage(const Message& message) const { 73 void SkiaAndroidApp::postMessage(const Message& message) const {
81 SkDEBUGCODE(auto writeSize =) write(fPipes[1], &message, sizeof(message)); 74 SkDEBUGCODE(auto writeSize =) write(fPipes[1], &message, sizeof(message));
82 SkASSERT(writeSize == sizeof(message)); 75 SkASSERT(writeSize == sizeof(message));
83 } 76 }
84 77
85 void SkiaAndroidApp::readMessage(Message* message) const { 78 void SkiaAndroidApp::readMessage(Message* message) const {
86 SkDEBUGCODE(auto readSize =) read(fPipes[0], message, sizeof(Message)); 79 SkDEBUGCODE(auto readSize =) read(fPipes[0], message, sizeof(Message));
87 SkASSERT(readSize == sizeof(Message)); 80 SkASSERT(readSize == sizeof(Message));
88 } 81 }
89 82
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 skiaAndroidApp->fWindow->onKey(it->second, Window::kUp_InputState, 0 ); 132 skiaAndroidApp->fWindow->onKey(it->second, Window::kUp_InputState, 0 );
140 break; 133 break;
141 } 134 }
142 case kTouched: { 135 case kTouched: {
143 auto it = ANDROID_TO_WINDOW_STATEMAP.find(message.fTouchState); 136 auto it = ANDROID_TO_WINDOW_STATEMAP.find(message.fTouchState);
144 SkASSERT(it != ANDROID_TO_WINDOW_STATEMAP.end()); 137 SkASSERT(it != ANDROID_TO_WINDOW_STATEMAP.end());
145 skiaAndroidApp->fWindow->onTouch(message.fTouchOwner, it->second, me ssage.fTouchX, 138 skiaAndroidApp->fWindow->onTouch(message.fTouchOwner, it->second, me ssage.fTouchX,
146 message.fTouchY); 139 message.fTouchY);
147 break; 140 break;
148 } 141 }
149 case kUIStateChanged: {
150 skiaAndroidApp->fWindow->onUIStateChanged(*message.stateName, *messa ge.stateValue);
151 delete message.stateName;
152 delete message.stateValue;
153 break;
154 }
155 default: { 142 default: {
156 // do nothing 143 // do nothing
157 } 144 }
158 } 145 }
159 146
160 return 1; // continue receiving callbacks 147 return 1; // continue receiving callbacks
161 } 148 }
162 149
163 void* SkiaAndroidApp::pthread_main(void* arg) { 150 void* SkiaAndroidApp::pthread_main(void* arg) {
164 SkDebugf("pthread_main begins"); 151 SkDebugf("pthread_main begins");
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 JNIEnv* env, jobject activity, jlong handle, jint owner, jfloat x, jfloat y, jint state) { 222 JNIEnv* env, jobject activity, jlong handle, jint owner, jfloat x, jfloat y, jint state) {
236 auto skiaAndroidApp = (SkiaAndroidApp*)handle; 223 auto skiaAndroidApp = (SkiaAndroidApp*)handle;
237 Message message(kTouched); 224 Message message(kTouched);
238 message.fTouchOwner = owner; 225 message.fTouchOwner = owner;
239 message.fTouchState = state; 226 message.fTouchState = state;
240 message.fTouchX = x; 227 message.fTouchX = x;
241 message.fTouchY = y; 228 message.fTouchY = y;
242 skiaAndroidApp->postMessage(message); 229 skiaAndroidApp->postMessage(message);
243 } 230 }
244 231
245 extern "C" JNIEXPORT void JNICALL Java_org_skia_viewer_ViewerActivity_onUIStateC hanged(
246 JNIEnv* env, jobject activity, jlong handle, jstring stateName, jstring stat eValue) {
247 auto skiaAndroidApp = (SkiaAndroidApp*)handle;
248 Message message(kUIStateChanged);
249 const char* nameChars = env->GetStringUTFChars(stateName, nullptr);
250 const char* valueChars = env->GetStringUTFChars(stateValue, nullptr);
251 message.stateName = new SkString(nameChars);
252 message.stateValue = new SkString(valueChars);
253 skiaAndroidApp->postMessage(message);
254 env->ReleaseStringUTFChars(stateName, nameChars);
255 env->ReleaseStringUTFChars(stateValue, valueChars);
256 }
257
258 } // namespace sk_app 232 } // namespace sk_app
OLDNEW
« no previous file with comments | « tools/viewer/sk_app/android/surface_glue_android.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698