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 "../Application.h" | 15 #include "../Application.h" |
16 #include "../Window.h" | 16 #include "../Window.h" |
17 | 17 |
18 namespace sk_app { | 18 namespace sk_app { |
19 | 19 |
20 enum MessageType { | 20 enum MessageType { |
21 kUndefined, | 21 kUndefined, |
22 kSurfaceCreated, | 22 kSurfaceCreated, |
23 kSurfaceChanged, | 23 kSurfaceChanged, |
24 kSurfaceDestroyed, | 24 kSurfaceDestroyed, |
25 kDestroyApp, | 25 kDestroyApp, |
26 kContentInvalidated, | 26 kContentInvalidated, |
27 kKeyPressed | 27 kKeyPressed, |
28 kTouched | |
28 }; | 29 }; |
29 | 30 |
30 struct Message { | 31 struct Message { |
31 MessageType fType = kUndefined; | 32 MessageType fType = kUndefined; |
32 ANativeWindow* fNativeWindow = nullptr; | 33 ANativeWindow* fNativeWindow = nullptr; |
33 int keycode = 0; | 34 int fKeycode = 0; |
35 int fTouchOwner, fTouchState; | |
36 float fTouchX, fTouchY; | |
34 | 37 |
35 Message() {} | 38 Message() {} |
36 Message(MessageType t) : fType(t) {} | 39 Message(MessageType t) : fType(t) {} |
37 }; | 40 }; |
38 | 41 |
39 struct SkiaAndroidApp { | 42 struct SkiaAndroidApp { |
40 Application* fApp; | 43 Application* fApp; |
41 Window* fWindow; | 44 Window* fWindow; |
42 jobject fAndroidApp; | 45 jobject fAndroidApp; |
43 | 46 |
44 SkiaAndroidApp(JNIEnv* env, jobject androidApp); | 47 SkiaAndroidApp(JNIEnv* env, jobject androidApp); |
45 | 48 |
46 void postMessage(const Message& message) const; | 49 void postMessage(const Message& message) const; |
47 void readMessage(Message* message) const; | 50 void readMessage(Message* message) const; |
48 void paintIfNeeded(); | 51 void paintIfNeeded(); |
49 | 52 |
50 // This must be called in SkiaAndroidApp's own pthread because the JNIEnv is thread sensitive | 53 // This must be called in SkiaAndroidApp's own pthread because the JNIEnv is thread sensitive |
51 void setTitle(const char* title) const; | 54 void setTitle(const char* title) const; |
55 | |
56 // This posts a kContentInvalidated message if there's no such message curre ntly in the queue | |
57 void inval(); | |
58 | |
52 private: | 59 private: |
53 pthread_t fThread; | 60 pthread_t fThread; |
54 ANativeWindow* fNativeWindow; | 61 ANativeWindow* fNativeWindow; |
55 int fPipes[2]; // 0 is the read message pipe, 1 is the write message pipe | 62 int fPipes[2]; // 0 is the read message pipe, 1 is the write message pipe |
56 JavaVM* fJavaVM; | 63 JavaVM* fJavaVM; |
57 JNIEnv* fPThreadEnv; | 64 JNIEnv* fPThreadEnv; |
58 jmethodID fSetTitleMethodID; | 65 jmethodID fSetTitleMethodID; |
59 | 66 |
67 bool fIsContentInvalidated = false; // use this to avoid duplicate invalida te events | |
68 pthread_mutex_t fMutex; | |
djsollen
2016/05/17 18:48:03
use SkMutex as it will handle the create and destr
liyuqian
2016/05/17 19:06:35
Done.
| |
69 | |
60 // 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 |
61 ~SkiaAndroidApp(); | 71 ~SkiaAndroidApp(); |
62 | 72 |
63 static int message_callback(int fd, int events, void* data); | 73 static int message_callback(int fd, int events, void* data); |
64 static void* pthread_main(void*); | 74 static void* pthread_main(void*); |
65 }; | 75 }; |
66 | 76 |
67 } // namespace sk_app | 77 } // namespace sk_app |
68 | 78 |
69 #endif | 79 #endif |
OLD | NEW |