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 #include "surface_glue_android.h" | 8 #include "surface_glue_android.h" |
9 | 9 |
10 #include <jni.h> | 10 #include <jni.h> |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 } | 64 } |
65 } | 65 } |
66 | 66 |
67 void SkiaAndroidApp::setTitle(const char* title) const { | 67 void SkiaAndroidApp::setTitle(const char* title) const { |
68 jstring titleString = fPThreadEnv->NewStringUTF(title); | 68 jstring titleString = fPThreadEnv->NewStringUTF(title); |
69 fPThreadEnv->CallVoidMethod(fAndroidApp, fSetTitleMethodID, titleString); | 69 fPThreadEnv->CallVoidMethod(fAndroidApp, fSetTitleMethodID, titleString); |
70 fPThreadEnv->DeleteLocalRef(titleString); | 70 fPThreadEnv->DeleteLocalRef(titleString); |
71 } | 71 } |
72 | 72 |
73 void SkiaAndroidApp::paintIfNeeded() { | 73 void SkiaAndroidApp::paintIfNeeded() { |
74 if (fNativeWindow && fWindow) { | 74 if (fWindow) { |
75 fWindow->onPaint(); | 75 if (fNativeWindow) { |
| 76 fWindow->onPaint(); |
| 77 } else { |
| 78 fWindow->uncheckInval(); |
| 79 } |
76 } | 80 } |
77 } | 81 } |
78 | 82 |
79 void SkiaAndroidApp::postMessage(const Message& message) const { | 83 void SkiaAndroidApp::postMessage(const Message& message) const { |
80 SkDEBUGCODE(auto writeSize =) write(fPipes[1], &message, sizeof(message)); | 84 SkDEBUGCODE(auto writeSize =) write(fPipes[1], &message, sizeof(message)); |
81 SkASSERT(writeSize == sizeof(message)); | 85 SkASSERT(writeSize == sizeof(message)); |
82 } | 86 } |
83 | 87 |
84 void SkiaAndroidApp::readMessage(Message* message) const { | 88 void SkiaAndroidApp::readMessage(Message* message) const { |
85 SkDEBUGCODE(auto readSize =) read(fPipes[0], message, sizeof(Message)); | 89 SkDEBUGCODE(auto readSize =) read(fPipes[0], message, sizeof(Message)); |
86 SkASSERT(readSize == sizeof(Message)); | 90 SkASSERT(readSize == sizeof(Message)); |
87 } | 91 } |
88 | 92 |
89 void SkiaAndroidApp::inval() { | |
90 SkAutoMutexAcquire ama(fMutex); | |
91 if (!fIsContentInvalidated) { | |
92 postMessage(Message(kContentInvalidated)); | |
93 fIsContentInvalidated = true; | |
94 } | |
95 } | |
96 | |
97 int SkiaAndroidApp::message_callback(int fd, int events, void* data) { | 93 int SkiaAndroidApp::message_callback(int fd, int events, void* data) { |
98 auto skiaAndroidApp = (SkiaAndroidApp*)data; | 94 auto skiaAndroidApp = (SkiaAndroidApp*)data; |
99 Message message; | 95 Message message; |
100 skiaAndroidApp->readMessage(&message); | 96 skiaAndroidApp->readMessage(&message); |
101 SkDebugf("message_callback %d", message.fType); | 97 SkDebugf("message_callback %d", message.fType); |
102 SkASSERT(message.fType != kUndefined); | 98 SkASSERT(message.fType != kUndefined); |
103 | 99 |
104 switch (message.fType) { | 100 switch (message.fType) { |
105 case kDestroyApp: { | 101 case kDestroyApp: { |
106 delete skiaAndroidApp; | 102 delete skiaAndroidApp; |
107 pthread_exit(nullptr); | 103 pthread_exit(nullptr); |
108 return 0; | 104 return 0; |
109 } | 105 } |
110 case kContentInvalidated: { | 106 case kContentInvalidated: { |
111 SkAutoMutexAcquire ama(skiaAndroidApp->fMutex); | |
112 skiaAndroidApp->fIsContentInvalidated = false; | |
113 skiaAndroidApp->paintIfNeeded(); | 107 skiaAndroidApp->paintIfNeeded(); |
114 break; | 108 break; |
115 } | 109 } |
116 case kSurfaceCreated: { | 110 case kSurfaceCreated: { |
117 SkASSERT(!skiaAndroidApp->fNativeWindow && message.fNativeWindow); | 111 SkASSERT(!skiaAndroidApp->fNativeWindow && message.fNativeWindow); |
118 skiaAndroidApp->fNativeWindow = message.fNativeWindow; | 112 skiaAndroidApp->fNativeWindow = message.fNativeWindow; |
119 auto window_android = (Window_android*)skiaAndroidApp->fWindow; | 113 auto window_android = (Window_android*)skiaAndroidApp->fWindow; |
120 window_android->initDisplay(skiaAndroidApp->fNativeWindow); | 114 window_android->initDisplay(skiaAndroidApp->fNativeWindow); |
121 skiaAndroidApp->paintIfNeeded(); | 115 skiaAndroidApp->paintIfNeeded(); |
122 break; | 116 break; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 auto skiaAndroidApp = (SkiaAndroidApp*)handle; | 233 auto skiaAndroidApp = (SkiaAndroidApp*)handle; |
240 Message message(kTouched); | 234 Message message(kTouched); |
241 message.fTouchOwner = owner; | 235 message.fTouchOwner = owner; |
242 message.fTouchState = state; | 236 message.fTouchState = state; |
243 message.fTouchX = x; | 237 message.fTouchX = x; |
244 message.fTouchY = y; | 238 message.fTouchY = y; |
245 skiaAndroidApp->postMessage(message); | 239 skiaAndroidApp->postMessage(message); |
246 } | 240 } |
247 | 241 |
248 } // namespace sk_app | 242 } // namespace sk_app |
OLD | NEW |