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