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

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

Issue 1982643004: Implement touch control (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: SkMutex 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
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 #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"
15 #include "../Application.h" 16 #include "../Application.h"
16 #include "../Window.h" 17 #include "../Window.h"
17 18
18 namespace sk_app { 19 namespace sk_app {
19 20
20 enum MessageType { 21 enum MessageType {
21 kUndefined, 22 kUndefined,
22 kSurfaceCreated, 23 kSurfaceCreated,
23 kSurfaceChanged, 24 kSurfaceChanged,
24 kSurfaceDestroyed, 25 kSurfaceDestroyed,
25 kDestroyApp, 26 kDestroyApp,
26 kContentInvalidated, 27 kContentInvalidated,
27 kKeyPressed 28 kKeyPressed,
29 kTouched
28 }; 30 };
29 31
30 struct Message { 32 struct Message {
31 MessageType fType = kUndefined; 33 MessageType fType = kUndefined;
32 ANativeWindow* fNativeWindow = nullptr; 34 ANativeWindow* fNativeWindow = nullptr;
33 int keycode = 0; 35 int fKeycode = 0;
36 int fTouchOwner, fTouchState;
37 float fTouchX, fTouchY;
34 38
35 Message() {} 39 Message() {}
36 Message(MessageType t) : fType(t) {} 40 Message(MessageType t) : fType(t) {}
37 }; 41 };
38 42
39 struct SkiaAndroidApp { 43 struct SkiaAndroidApp {
40 Application* fApp; 44 Application* fApp;
41 Window* fWindow; 45 Window* fWindow;
42 jobject fAndroidApp; 46 jobject fAndroidApp;
43 47
44 SkiaAndroidApp(JNIEnv* env, jobject androidApp); 48 SkiaAndroidApp(JNIEnv* env, jobject androidApp);
45 49
46 void postMessage(const Message& message) const; 50 void postMessage(const Message& message) const;
47 void readMessage(Message* message) const; 51 void readMessage(Message* message) const;
48 void paintIfNeeded(); 52 void paintIfNeeded();
49 53
50 // This must be called in SkiaAndroidApp's own pthread because the JNIEnv is thread sensitive 54 // This must be called in SkiaAndroidApp's own pthread because the JNIEnv is thread sensitive
51 void setTitle(const char* title) const; 55 void setTitle(const char* title) const;
56
57 // This posts a kContentInvalidated message if there's no such message curre ntly in the queue
58 void inval();
59
52 private: 60 private:
53 pthread_t fThread; 61 pthread_t fThread;
54 ANativeWindow* fNativeWindow; 62 ANativeWindow* fNativeWindow;
55 int fPipes[2]; // 0 is the read message pipe, 1 is the write message pipe 63 int fPipes[2]; // 0 is the read message pipe, 1 is the write message pipe
56 JavaVM* fJavaVM; 64 JavaVM* fJavaVM;
57 JNIEnv* fPThreadEnv; 65 JNIEnv* fPThreadEnv;
58 jmethodID fSetTitleMethodID; 66 jmethodID fSetTitleMethodID;
59 67
68 bool fIsContentInvalidated = false; // use this to avoid duplicate invalida te events
69 SkMutex fMutex;
70
60 // This must be called in SkiaAndroidApp's own pthread because the JNIEnv is thread sensitive 71 // This must be called in SkiaAndroidApp's own pthread because the JNIEnv is thread sensitive
61 ~SkiaAndroidApp(); 72 ~SkiaAndroidApp();
62 73
63 static int message_callback(int fd, int events, void* data); 74 static int message_callback(int fd, int events, void* data);
64 static void* pthread_main(void*); 75 static void* pthread_main(void*);
65 }; 76 };
66 77
67 } // namespace sk_app 78 } // namespace sk_app
68 79
69 #endif 80 #endif
OLDNEW
« no previous file with comments | « tools/viewer/sk_app/android/Window_android.cpp ('k') | tools/viewer/sk_app/android/surface_glue_android.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698