diff options
Diffstat (limited to 'tools/viewer/sk_app/android')
-rw-r--r-- | tools/viewer/sk_app/android/Window_android.cpp | 12 | ||||
-rw-r--r-- | tools/viewer/sk_app/android/Window_android.h | 4 | ||||
-rw-r--r-- | tools/viewer/sk_app/android/surface_glue_android.cpp | 22 | ||||
-rw-r--r-- | tools/viewer/sk_app/android/surface_glue_android.h | 8 |
4 files changed, 16 insertions, 30 deletions
diff --git a/tools/viewer/sk_app/android/Window_android.cpp b/tools/viewer/sk_app/android/Window_android.cpp index 106c40b7b0..ed03c814dd 100644 --- a/tools/viewer/sk_app/android/Window_android.cpp +++ b/tools/viewer/sk_app/android/Window_android.cpp @@ -64,8 +64,16 @@ void Window_android::onDisplayDestroyed() { detach(); } -void Window_android::inval() { - fSkiaAndroidApp->inval(); +void Window_android::onInval() { + fSkiaAndroidApp->postMessage(Message(kContentInvalidated)); +} + +void Window_android::paintIfNeeded() { + if (fWindowContext) { // Check if initDisplay has already been called + onPaint(); + } else { + markInvalProcessed(); + } } } // namespace sk_app diff --git a/tools/viewer/sk_app/android/Window_android.h b/tools/viewer/sk_app/android/Window_android.h index c1cd1eb200..f7d348bc91 100644 --- a/tools/viewer/sk_app/android/Window_android.h +++ b/tools/viewer/sk_app/android/Window_android.h @@ -27,7 +27,9 @@ public: void show() override {} bool attach(BackendType attachType, const DisplayParams& params) override; - void inval() override; + void onInval() override; + + void paintIfNeeded(); bool scaleContentToFit() const override { return true; } bool supportsContentRect() const override { return true; } diff --git a/tools/viewer/sk_app/android/surface_glue_android.cpp b/tools/viewer/sk_app/android/surface_glue_android.cpp index 3a4fca539c..958b7876b8 100644 --- a/tools/viewer/sk_app/android/surface_glue_android.cpp +++ b/tools/viewer/sk_app/android/surface_glue_android.cpp @@ -70,12 +70,6 @@ void SkiaAndroidApp::setTitle(const char* title) const { fPThreadEnv->DeleteLocalRef(titleString); } -void SkiaAndroidApp::paintIfNeeded() { - if (fNativeWindow && fWindow) { - fWindow->onPaint(); - } -} - void SkiaAndroidApp::postMessage(const Message& message) const { SkDEBUGCODE(auto writeSize =) write(fPipes[1], &message, sizeof(message)); SkASSERT(writeSize == sizeof(message)); @@ -86,14 +80,6 @@ void SkiaAndroidApp::readMessage(Message* message) const { SkASSERT(readSize == sizeof(Message)); } -void SkiaAndroidApp::inval() { - SkAutoMutexAcquire ama(fMutex); - if (!fIsContentInvalidated) { - postMessage(Message(kContentInvalidated)); - fIsContentInvalidated = true; - } -} - int SkiaAndroidApp::message_callback(int fd, int events, void* data) { auto skiaAndroidApp = (SkiaAndroidApp*)data; Message message; @@ -108,9 +94,7 @@ int SkiaAndroidApp::message_callback(int fd, int events, void* data) { return 0; } case kContentInvalidated: { - SkAutoMutexAcquire ama(skiaAndroidApp->fMutex); - skiaAndroidApp->fIsContentInvalidated = false; - skiaAndroidApp->paintIfNeeded(); + ((Window_android*)skiaAndroidApp->fWindow)->paintIfNeeded(); break; } case kSurfaceCreated: { @@ -118,7 +102,7 @@ int SkiaAndroidApp::message_callback(int fd, int events, void* data) { skiaAndroidApp->fNativeWindow = message.fNativeWindow; auto window_android = (Window_android*)skiaAndroidApp->fWindow; window_android->initDisplay(skiaAndroidApp->fNativeWindow); - skiaAndroidApp->paintIfNeeded(); + ((Window_android*)skiaAndroidApp->fWindow)->paintIfNeeded(); break; } case kSurfaceChanged: { @@ -128,7 +112,7 @@ int SkiaAndroidApp::message_callback(int fd, int events, void* data) { int height = ANativeWindow_getHeight(skiaAndroidApp->fNativeWindow); auto window_android = (Window_android*)skiaAndroidApp->fWindow; window_android->setContentRect(0, 0, width, height); - skiaAndroidApp->paintIfNeeded(); + window_android->paintIfNeeded(); break; } case kSurfaceDestroyed: { diff --git a/tools/viewer/sk_app/android/surface_glue_android.h b/tools/viewer/sk_app/android/surface_glue_android.h index 7ffba3080a..a4698336f0 100644 --- a/tools/viewer/sk_app/android/surface_glue_android.h +++ b/tools/viewer/sk_app/android/surface_glue_android.h @@ -12,7 +12,6 @@ #include <android/native_window_jni.h> -#include "../private/SkMutex.h" #include "../Application.h" #include "../Window.h" @@ -49,14 +48,10 @@ struct SkiaAndroidApp { void postMessage(const Message& message) const; void readMessage(Message* message) const; - void paintIfNeeded(); // This must be called in SkiaAndroidApp's own pthread because the JNIEnv is thread sensitive void setTitle(const char* title) const; - // This posts a kContentInvalidated message if there's no such message currently in the queue - void inval(); - private: pthread_t fThread; ANativeWindow* fNativeWindow; @@ -65,9 +60,6 @@ private: JNIEnv* fPThreadEnv; jmethodID fSetTitleMethodID; - bool fIsContentInvalidated = false; // use this to avoid duplicate invalidate events - SkMutex fMutex; - // This must be called in SkiaAndroidApp's own pthread because the JNIEnv is thread sensitive ~SkiaAndroidApp(); |