Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] skip actor and invalidate view directly from GL thread
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
ivovandongen committed Sep 8, 2017
1 parent a3afcb5 commit 82f03a9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 17 deletions.
7 changes: 4 additions & 3 deletions platform/android/src/android_gl_thread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AndroidGLThread : public Scheduler {
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_)
Expand All @@ -38,7 +38,8 @@ class AndroidGLThread : public Scheduler {
queue.push(scheduled);
}

callback.invoke(&InvalidateCallback::operator());
// Invalidate so we get processing time later
callback();
}

// Only safe on the GL Thread
Expand Down Expand Up @@ -67,7 +68,7 @@ class AndroidGLThread : public Scheduler {
std::queue<std::weak_ptr<Mailbox>> queue;

std::shared_ptr<Mailbox> mailbox;
ActorRef<InvalidateCallback> callback;
InvalidateCallback callback;
ActorRef<Renderer> rendererRef;
};

Expand Down
15 changes: 2 additions & 13 deletions platform/android/src/android_renderer_frontend.cpp
Original file line number Diff line number Diff line change
@@ -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>
Expand Down Expand Up @@ -69,24 +67,16 @@ 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,
scheduler,
GLContextMode::Unique,
programCacheDir
))
, asyncInvalidate([=, invalidate=std::move(invalidate)]() {
, asyncInvalidate([=]() {
invalidate();
})
, mapRunLoop(util::RunLoop::Get()) {
Expand Down Expand Up @@ -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();
}

Expand Down
1 change: 0 additions & 1 deletion platform/android/src/android_renderer_frontend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class AndroidRendererFrontend : public RendererFrontend {

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;
Expand Down

0 comments on commit 82f03a9

Please sign in to comment.