| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 delete fApp; | 63 delete fApp; |
| 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() { | |
| 74 if (fNativeWindow && fWindow) { | |
| 75 fWindow->onPaint(); | |
| 76 } | |
| 77 } | |
| 78 | |
| 79 void SkiaAndroidApp::postMessage(const Message& message) const { | 73 void SkiaAndroidApp::postMessage(const Message& message) const { |
| 80 SkDEBUGCODE(auto writeSize =) write(fPipes[1], &message, sizeof(message)); | 74 SkDEBUGCODE(auto writeSize =) write(fPipes[1], &message, sizeof(message)); |
| 81 SkASSERT(writeSize == sizeof(message)); | 75 SkASSERT(writeSize == sizeof(message)); |
| 82 } | 76 } |
| 83 | 77 |
| 84 void SkiaAndroidApp::readMessage(Message* message) const { | 78 void SkiaAndroidApp::readMessage(Message* message) const { |
| 85 SkDEBUGCODE(auto readSize =) read(fPipes[0], message, sizeof(Message)); | 79 SkDEBUGCODE(auto readSize =) read(fPipes[0], message, sizeof(Message)); |
| 86 SkASSERT(readSize == sizeof(Message)); | 80 SkASSERT(readSize == sizeof(Message)); |
| 87 } | 81 } |
| 88 | 82 |
| 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) { | 83 int SkiaAndroidApp::message_callback(int fd, int events, void* data) { |
| 98 auto skiaAndroidApp = (SkiaAndroidApp*)data; | 84 auto skiaAndroidApp = (SkiaAndroidApp*)data; |
| 99 Message message; | 85 Message message; |
| 100 skiaAndroidApp->readMessage(&message); | 86 skiaAndroidApp->readMessage(&message); |
| 101 SkDebugf("message_callback %d", message.fType); | 87 SkDebugf("message_callback %d", message.fType); |
| 102 SkASSERT(message.fType != kUndefined); | 88 SkASSERT(message.fType != kUndefined); |
| 103 | 89 |
| 104 switch (message.fType) { | 90 switch (message.fType) { |
| 105 case kDestroyApp: { | 91 case kDestroyApp: { |
| 106 delete skiaAndroidApp; | 92 delete skiaAndroidApp; |
| 107 pthread_exit(nullptr); | 93 pthread_exit(nullptr); |
| 108 return 0; | 94 return 0; |
| 109 } | 95 } |
| 110 case kContentInvalidated: { | 96 case kContentInvalidated: { |
| 111 SkAutoMutexAcquire ama(skiaAndroidApp->fMutex); | 97 ((Window_android*)skiaAndroidApp->fWindow)->paintIfNeeded(); |
| 112 skiaAndroidApp->fIsContentInvalidated = false; | |
| 113 skiaAndroidApp->paintIfNeeded(); | |
| 114 break; | 98 break; |
| 115 } | 99 } |
| 116 case kSurfaceCreated: { | 100 case kSurfaceCreated: { |
| 117 SkASSERT(!skiaAndroidApp->fNativeWindow && message.fNativeWindow); | 101 SkASSERT(!skiaAndroidApp->fNativeWindow && message.fNativeWindow); |
| 118 skiaAndroidApp->fNativeWindow = message.fNativeWindow; | 102 skiaAndroidApp->fNativeWindow = message.fNativeWindow; |
| 119 auto window_android = (Window_android*)skiaAndroidApp->fWindow; | 103 auto window_android = (Window_android*)skiaAndroidApp->fWindow; |
| 120 window_android->initDisplay(skiaAndroidApp->fNativeWindow); | 104 window_android->initDisplay(skiaAndroidApp->fNativeWindow); |
| 121 skiaAndroidApp->paintIfNeeded(); | 105 ((Window_android*)skiaAndroidApp->fWindow)->paintIfNeeded(); |
| 122 break; | 106 break; |
| 123 } | 107 } |
| 124 case kSurfaceChanged: { | 108 case kSurfaceChanged: { |
| 125 SkASSERT(message.fNativeWindow == skiaAndroidApp->fNativeWindow && | 109 SkASSERT(message.fNativeWindow == skiaAndroidApp->fNativeWindow && |
| 126 message.fNativeWindow); | 110 message.fNativeWindow); |
| 127 int width = ANativeWindow_getWidth(skiaAndroidApp->fNativeWindow); | 111 int width = ANativeWindow_getWidth(skiaAndroidApp->fNativeWindow); |
| 128 int height = ANativeWindow_getHeight(skiaAndroidApp->fNativeWindow); | 112 int height = ANativeWindow_getHeight(skiaAndroidApp->fNativeWindow); |
| 129 auto window_android = (Window_android*)skiaAndroidApp->fWindow; | 113 auto window_android = (Window_android*)skiaAndroidApp->fWindow; |
| 130 window_android->setContentRect(0, 0, width, height); | 114 window_android->setContentRect(0, 0, width, height); |
| 131 skiaAndroidApp->paintIfNeeded(); | 115 window_android->paintIfNeeded(); |
| 132 break; | 116 break; |
| 133 } | 117 } |
| 134 case kSurfaceDestroyed: { | 118 case kSurfaceDestroyed: { |
| 135 if (skiaAndroidApp->fNativeWindow) { | 119 if (skiaAndroidApp->fNativeWindow) { |
| 136 auto window_android = (Window_android*)skiaAndroidApp->fWindow; | 120 auto window_android = (Window_android*)skiaAndroidApp->fWindow; |
| 137 window_android->onDisplayDestroyed(); | 121 window_android->onDisplayDestroyed(); |
| 138 ANativeWindow_release(skiaAndroidApp->fNativeWindow); | 122 ANativeWindow_release(skiaAndroidApp->fNativeWindow); |
| 139 skiaAndroidApp->fNativeWindow = nullptr; | 123 skiaAndroidApp->fNativeWindow = nullptr; |
| 140 } | 124 } |
| 141 break; | 125 break; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 auto skiaAndroidApp = (SkiaAndroidApp*)handle; | 223 auto skiaAndroidApp = (SkiaAndroidApp*)handle; |
| 240 Message message(kTouched); | 224 Message message(kTouched); |
| 241 message.fTouchOwner = owner; | 225 message.fTouchOwner = owner; |
| 242 message.fTouchState = state; | 226 message.fTouchState = state; |
| 243 message.fTouchX = x; | 227 message.fTouchX = x; |
| 244 message.fTouchY = y; | 228 message.fTouchY = y; |
| 245 skiaAndroidApp->postMessage(message); | 229 skiaAndroidApp->postMessage(message); |
| 246 } | 230 } |
| 247 | 231 |
| 248 } // namespace sk_app | 232 } // namespace sk_app |
| OLD | NEW |