OLD | NEW |
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 #ifndef surface_glue_android_DEFINED | 8 #ifndef surface_glue_android_DEFINED |
9 #define surface_glue_android_DEFINED | 9 #define surface_glue_android_DEFINED |
10 | 10 |
11 #include <pthread.h> | 11 #include <pthread.h> |
12 | 12 |
13 #include <android/native_window_jni.h> | 13 #include <android/native_window_jni.h> |
14 | 14 |
| 15 #include "SkString.h" |
| 16 |
15 #include "../Application.h" | 17 #include "../Application.h" |
16 #include "../Window.h" | 18 #include "../Window.h" |
17 | 19 |
18 namespace sk_app { | 20 namespace sk_app { |
19 | 21 |
20 enum MessageType { | 22 enum MessageType { |
21 kUndefined, | 23 kUndefined, |
22 kSurfaceCreated, | 24 kSurfaceCreated, |
23 kSurfaceChanged, | 25 kSurfaceChanged, |
24 kSurfaceDestroyed, | 26 kSurfaceDestroyed, |
25 kDestroyApp, | 27 kDestroyApp, |
26 kContentInvalidated, | 28 kContentInvalidated, |
27 kKeyPressed, | 29 kKeyPressed, |
28 kTouched | 30 kTouched, |
| 31 kUIStateChanged, |
29 }; | 32 }; |
30 | 33 |
31 struct Message { | 34 struct Message { |
32 MessageType fType = kUndefined; | 35 MessageType fType = kUndefined; |
33 ANativeWindow* fNativeWindow = nullptr; | 36 ANativeWindow* fNativeWindow = nullptr; |
34 int fKeycode = 0; | 37 int fKeycode = 0; |
35 int fTouchOwner, fTouchState; | 38 int fTouchOwner, fTouchState; |
36 float fTouchX, fTouchY; | 39 float fTouchX, fTouchY; |
37 | 40 |
| 41 SkString* stateName; |
| 42 SkString* stateValue; |
| 43 |
38 Message() {} | 44 Message() {} |
39 Message(MessageType t) : fType(t) {} | 45 Message(MessageType t) : fType(t) {} |
40 }; | 46 }; |
41 | 47 |
42 struct SkiaAndroidApp { | 48 struct SkiaAndroidApp { |
43 Application* fApp; | 49 Application* fApp; |
44 Window* fWindow; | 50 Window* fWindow; |
45 jobject fAndroidApp; | 51 jobject fAndroidApp; |
46 | 52 |
47 SkiaAndroidApp(JNIEnv* env, jobject androidApp); | 53 SkiaAndroidApp(JNIEnv* env, jobject androidApp); |
48 | 54 |
49 void postMessage(const Message& message) const; | 55 void postMessage(const Message& message) const; |
50 void readMessage(Message* message) const; | 56 void readMessage(Message* message) const; |
51 | 57 |
52 // This must be called in SkiaAndroidApp's own pthread because the JNIEnv is
thread sensitive | 58 // These must be called in SkiaAndroidApp's own pthread because the JNIEnv i
s thread sensitive |
53 void setTitle(const char* title) const; | 59 void setTitle(const char* title) const; |
| 60 void setUIState(const Json::Value& state) const; |
54 | 61 |
55 private: | 62 private: |
56 pthread_t fThread; | 63 pthread_t fThread; |
57 ANativeWindow* fNativeWindow; | 64 ANativeWindow* fNativeWindow; |
58 int fPipes[2]; // 0 is the read message pipe, 1 is the write message pipe | 65 int fPipes[2]; // 0 is the read message pipe, 1 is the write message pipe |
59 JavaVM* fJavaVM; | 66 JavaVM* fJavaVM; |
60 JNIEnv* fPThreadEnv; | 67 JNIEnv* fPThreadEnv; |
61 jmethodID fSetTitleMethodID; | 68 jmethodID fSetTitleMethodID, fSetStateMethodID; |
62 | 69 |
63 // This must be called in SkiaAndroidApp's own pthread because the JNIEnv is
thread sensitive | 70 // This must be called in SkiaAndroidApp's own pthread because the JNIEnv is
thread sensitive |
64 ~SkiaAndroidApp(); | 71 ~SkiaAndroidApp(); |
65 | 72 |
66 static int message_callback(int fd, int events, void* data); | 73 static int message_callback(int fd, int events, void* data); |
67 static void* pthread_main(void*); | 74 static void* pthread_main(void*); |
68 }; | 75 }; |
69 | 76 |
70 } // namespace sk_app | 77 } // namespace sk_app |
71 | 78 |
72 #endif | 79 #endif |
OLD | NEW |