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 "../private/SkMutex.h" | |
16 #include "../Application.h" | 15 #include "../Application.h" |
17 #include "../Window.h" | 16 #include "../Window.h" |
18 | 17 |
19 namespace sk_app { | 18 namespace sk_app { |
20 | 19 |
21 enum MessageType { | 20 enum MessageType { |
22 kUndefined, | 21 kUndefined, |
23 kSurfaceCreated, | 22 kSurfaceCreated, |
24 kSurfaceChanged, | 23 kSurfaceChanged, |
25 kSurfaceDestroyed, | 24 kSurfaceDestroyed, |
(...skipping 16 matching lines...) Expand all Loading... |
42 | 41 |
43 struct SkiaAndroidApp { | 42 struct SkiaAndroidApp { |
44 Application* fApp; | 43 Application* fApp; |
45 Window* fWindow; | 44 Window* fWindow; |
46 jobject fAndroidApp; | 45 jobject fAndroidApp; |
47 | 46 |
48 SkiaAndroidApp(JNIEnv* env, jobject androidApp); | 47 SkiaAndroidApp(JNIEnv* env, jobject androidApp); |
49 | 48 |
50 void postMessage(const Message& message) const; | 49 void postMessage(const Message& message) const; |
51 void readMessage(Message* message) const; | 50 void readMessage(Message* message) const; |
52 void paintIfNeeded(); | |
53 | 51 |
54 // This must be called in SkiaAndroidApp's own pthread because the JNIEnv is
thread sensitive | 52 // This must be called in SkiaAndroidApp's own pthread because the JNIEnv is
thread sensitive |
55 void setTitle(const char* title) const; | 53 void setTitle(const char* title) const; |
56 | 54 |
57 // This posts a kContentInvalidated message if there's no such message curre
ntly in the queue | |
58 void inval(); | |
59 | |
60 private: | 55 private: |
61 pthread_t fThread; | 56 pthread_t fThread; |
62 ANativeWindow* fNativeWindow; | 57 ANativeWindow* fNativeWindow; |
63 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 |
64 JavaVM* fJavaVM; | 59 JavaVM* fJavaVM; |
65 JNIEnv* fPThreadEnv; | 60 JNIEnv* fPThreadEnv; |
66 jmethodID fSetTitleMethodID; | 61 jmethodID fSetTitleMethodID; |
67 | 62 |
68 bool fIsContentInvalidated = false; // use this to avoid duplicate invalida
te events | |
69 SkMutex fMutex; | |
70 | |
71 // 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 |
72 ~SkiaAndroidApp(); | 64 ~SkiaAndroidApp(); |
73 | 65 |
74 static int message_callback(int fd, int events, void* data); | 66 static int message_callback(int fd, int events, void* data); |
75 static void* pthread_main(void*); | 67 static void* pthread_main(void*); |
76 }; | 68 }; |
77 | 69 |
78 } // namespace sk_app | 70 } // namespace sk_app |
79 | 71 |
80 #endif | 72 #endif |
OLD | NEW |