diff options
author | Ivo van Dongen <info@ivovandongen.nl> | 2017-09-08 14:36:11 +0300 |
---|---|---|
committer | Ivo van Dongen <info@ivovandongen.nl> | 2017-09-18 10:07:04 +0300 |
commit | cf0600694f2a8d2d78b3ca10d4b2f60464fbc692 (patch) | |
tree | 2aa5b766e261e1dbeeee0ccc803b8eb0edf90a91 | |
parent | 29fa5bbefeeff508cdbb3923b1f5a7625e4d4c79 (diff) | |
download | qtlocation-mapboxgl-cf0600694f2a8d2d78b3ca10d4b2f60464fbc692.tar.gz |
[android] skip actor and invalidate view directly from GL thread
- This ensures there is no deadlock when do a blocking call into the render thread
- This skips the async invalidated task, so there are more invalidations going on
- This means that the invalidate call on NativeMapView can now occur on the main thread AND the gl thread and we need to be careful not to touch anything else but GLSurfaceView#requestRender there
-rw-r--r-- | platform/android/src/android_gl_thread.hpp | 7 | ||||
-rw-r--r-- | platform/android/src/android_renderer_frontend.cpp | 15 | ||||
-rw-r--r-- | platform/android/src/android_renderer_frontend.hpp | 1 |
3 files changed, 6 insertions, 17 deletions
diff --git a/platform/android/src/android_gl_thread.hpp b/platform/android/src/android_gl_thread.hpp index 06bfce1444..1c2412d594 100644 --- a/platform/android/src/android_gl_thread.hpp +++ b/platform/android/src/android_gl_thread.hpp @@ -19,7 +19,7 @@ public: using InvalidateCallback = std::function<void ()>; template <class... Args> - AndroidGLThread(ActorRef<InvalidateCallback> callback_, Args&&... args) + AndroidGLThread(InvalidateCallback callback_, Args&&... args) : renderer(std::make_unique<Renderer>(std::forward<Args>(args)...)) , mailbox(std::make_shared<Mailbox>(*this)) , callback(callback_) @@ -38,7 +38,8 @@ public: queue.push(scheduled); } - callback.invoke(&InvalidateCallback::operator()); + // Invalidate so we get processing time later + callback(); } // Only safe on the GL Thread @@ -67,7 +68,7 @@ private: std::queue<std::weak_ptr<Mailbox>> queue; std::shared_ptr<Mailbox> mailbox; - ActorRef<InvalidateCallback> callback; + InvalidateCallback callback; ActorRef<Renderer> rendererRef; }; diff --git a/platform/android/src/android_renderer_frontend.cpp b/platform/android/src/android_renderer_frontend.cpp index b010022d94..443492fae7 100644 --- a/platform/android/src/android_renderer_frontend.cpp +++ b/platform/android/src/android_renderer_frontend.cpp @@ -1,8 +1,6 @@ #include "android_renderer_frontend.hpp" #include <mbgl/actor/scheduler.hpp> -#include <mbgl/renderer/backend_scope.hpp> -#include <mbgl/renderer/renderer.hpp> #include <mbgl/renderer/renderer_observer.hpp> #include <mbgl/storage/file_source.hpp> #include <mbgl/util/thread.hpp> @@ -69,16 +67,8 @@ AndroidRendererFrontend::AndroidRendererFrontend(float pixelRatio, std::string programCacheDir, InvalidateCallback invalidate) : backend(std::make_unique<AndroidRendererBackend>()) - , glThreadCallback(std::make_unique<Actor<AndroidGLThread::InvalidateCallback>>( - *Scheduler::GetCurrent(), - [&]() { - Log::Info(Event::JNI, "GL Thread invalidate callback"); - // TODO: replace the whole thing with rendererOberver.invalidate()? - asyncInvalidate.send(); - } - )) , glThread(std::make_unique<AndroidGLThread>( - glThreadCallback->self(), + invalidate, *backend, pixelRatio, fileSource, @@ -86,7 +76,7 @@ AndroidRendererFrontend::AndroidRendererFrontend(float pixelRatio, GLContextMode::Unique, programCacheDir )) - , asyncInvalidate([=, invalidate=std::move(invalidate)]() { + , asyncInvalidate([=]() { invalidate(); }) , mapRunLoop(util::RunLoop::Get()) { @@ -186,7 +176,6 @@ void AndroidRendererFrontend::requestSnapshot(SnapshotCallback callback_) { void AndroidRendererFrontend::resizeFramebuffer(int width, int height) { backend->resizeFramebuffer(width, height); framebufferSizeChanged = true; - // TODO: thread safe? asyncInvalidate.send(); } diff --git a/platform/android/src/android_renderer_frontend.hpp b/platform/android/src/android_renderer_frontend.hpp index 4e57f80d53..55cbf8c0b1 100644 --- a/platform/android/src/android_renderer_frontend.hpp +++ b/platform/android/src/android_renderer_frontend.hpp @@ -65,7 +65,6 @@ public: private: std::unique_ptr<AndroidRendererBackend> backend; - std::unique_ptr<Actor<AndroidGLThread::InvalidateCallback>> glThreadCallback; std::unique_ptr<AndroidGLThread> glThread; std::unique_ptr<RendererObserver> rendererObserver; std::shared_ptr<UpdateParameters> updateParameters; |