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

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

Issue 1965013007: Use swipe gesture to switch between slides on Android (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Revision 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 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>
11 #include <pthread.h> 11 #include <pthread.h>
12 #include <stdio.h> 12 #include <stdio.h>
13 #include <unistd.h> 13 #include <unistd.h>
14 #include <unordered_map>
14 15
16 #include <android/keycodes.h>
15 #include <android/looper.h> 17 #include <android/looper.h>
16 #include <android/native_window_jni.h> 18 #include <android/native_window_jni.h>
17 19
18 #include "../Application.h" 20 #include "../Application.h"
19 #include "SkTypes.h" 21 #include "SkTypes.h"
20 #include "SkUtils.h" 22 #include "SkUtils.h"
21 #include "Window_android.h" 23 #include "Window_android.h"
22 24
23 namespace sk_app { 25 namespace sk_app {
24 26
25 static const int LOOPER_ID_MESSAGEPIPE = 1; 27 static const int LOOPER_ID_MESSAGEPIPE = 1;
26 28
29 static const std::unordered_map<int, Window::Key> ANDROID_TO_WINDOW_KEYMAP({
30 {AKEYCODE_SOFT_LEFT, Window::Key::kLeft},
31 {AKEYCODE_SOFT_RIGHT, Window::Key::kRight}
32 });
33
27 void* pthread_main(void* arg); 34 void* pthread_main(void* arg);
28 35
29 SkiaAndroidApp::SkiaAndroidApp() { 36 SkiaAndroidApp::SkiaAndroidApp() {
30 fNativeWindow = nullptr; 37 fNativeWindow = nullptr;
31 pthread_create(&fThread, nullptr, pthread_main, this); 38 pthread_create(&fThread, nullptr, pthread_main, this);
32 } 39 }
33 40
34 SkiaAndroidApp::~SkiaAndroidApp() { 41 SkiaAndroidApp::~SkiaAndroidApp() {
35 if (fWindow) { 42 if (fWindow) {
36 fWindow->detach(); 43 fWindow->detach();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 auto window_android = (Window_android*)skiaAndroidApp->fWindow; 90 auto window_android = (Window_android*)skiaAndroidApp->fWindow;
84 window_android->initDisplay(skiaAndroidApp->fNativeWindow); 91 window_android->initDisplay(skiaAndroidApp->fNativeWindow);
85 skiaAndroidApp->paintIfNeeded(); 92 skiaAndroidApp->paintIfNeeded();
86 break; 93 break;
87 } 94 }
88 case kSurfaceChanged: { 95 case kSurfaceChanged: {
89 SkASSERT(message.fNativeWindow == skiaAndroidApp->fNativeWindow && 96 SkASSERT(message.fNativeWindow == skiaAndroidApp->fNativeWindow &&
90 message.fNativeWindow); 97 message.fNativeWindow);
91 int width = ANativeWindow_getWidth(skiaAndroidApp->fNativeWindow); 98 int width = ANativeWindow_getWidth(skiaAndroidApp->fNativeWindow);
92 int height = ANativeWindow_getHeight(skiaAndroidApp->fNativeWindow); 99 int height = ANativeWindow_getHeight(skiaAndroidApp->fNativeWindow);
93 skiaAndroidApp->fWindow->onResize(width, height);
94 auto window_android = (Window_android*)skiaAndroidApp->fWindow; 100 auto window_android = (Window_android*)skiaAndroidApp->fWindow;
95 window_android->setContentRect(0, 0, width, height); 101 window_android->setContentRect(0, 0, width, height);
96 skiaAndroidApp->paintIfNeeded(); 102 skiaAndroidApp->paintIfNeeded();
97 break; 103 break;
98 } 104 }
99 case kSurfaceDestroyed: { 105 case kSurfaceDestroyed: {
100 if (skiaAndroidApp->fNativeWindow) { 106 if (skiaAndroidApp->fNativeWindow) {
101 auto window_android = (Window_android*)skiaAndroidApp->fWindow; 107 auto window_android = (Window_android*)skiaAndroidApp->fWindow;
102 window_android->onDisplayDestroyed(); 108 window_android->onDisplayDestroyed();
103 ANativeWindow_release(skiaAndroidApp->fNativeWindow); 109 ANativeWindow_release(skiaAndroidApp->fNativeWindow);
104 skiaAndroidApp->fNativeWindow = nullptr; 110 skiaAndroidApp->fNativeWindow = nullptr;
105 } 111 }
106 break; 112 break;
107 } 113 }
114 case kKeyPressed: {
115 auto it = ANDROID_TO_WINDOW_KEYMAP.find(message.keycode);
116 SkASSERT(it != ANDROID_TO_WINDOW_KEYMAP.end());
117 // No modifier is supported so far
118 skiaAndroidApp->fWindow->onKey(it->second, Window::kDown_InputState, 0);
119 skiaAndroidApp->fWindow->onKey(it->second, Window::kUp_InputState, 0 );
120 break;
121 }
108 default: { 122 default: {
109 // do nothing 123 // do nothing
110 } 124 }
111 } 125 }
112 126
113 return 1; // continue receiving callbacks 127 return 1; // continue receiving callbacks
114 } 128 }
115 129
116 void* pthread_main(void* arg) { 130 void* pthread_main(void* arg) {
117 SkDebugf("pthread_main begins"); 131 SkDebugf("pthread_main begins");
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 message.fNativeWindow = ANativeWindow_fromSurface(env, surface); 178 message.fNativeWindow = ANativeWindow_fromSurface(env, surface);
165 skiaAndroidApp->postMessage(message); 179 skiaAndroidApp->postMessage(message);
166 } 180 }
167 181
168 extern "C" JNIEXPORT void JNICALL Java_org_skia_viewer_ViewerActivity_onSurfaceD estroyed( 182 extern "C" JNIEXPORT void JNICALL Java_org_skia_viewer_ViewerActivity_onSurfaceD estroyed(
169 JNIEnv* env, jobject activity, jlong handle) { 183 JNIEnv* env, jobject activity, jlong handle) {
170 auto skiaAndroidApp = (SkiaAndroidApp*)handle; 184 auto skiaAndroidApp = (SkiaAndroidApp*)handle;
171 skiaAndroidApp->postMessage(Message(kSurfaceDestroyed)); 185 skiaAndroidApp->postMessage(Message(kSurfaceDestroyed));
172 } 186 }
173 187
188 extern "C" JNIEXPORT void JNICALL Java_org_skia_viewer_ViewerActivity_onKeyPress ed(JNIEnv* env,
189 jobject activity,
190 jlong handle,
191 jint keycode) {
192 auto skiaAndroidApp = (SkiaAndroidApp*)handle;
193 Message message(kKeyPressed);
194 message.keycode = keycode;
195 skiaAndroidApp->postMessage(message);
196 }
197
174 } // namespace sk_app 198 } // 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