Add TaggedScheduler, couple lifetime of tasks and orchestrator (#2398)
This commit is contained in:
@@ -28,7 +28,7 @@ private:
|
||||
AndroidRendererBackend& backend;
|
||||
};
|
||||
|
||||
AndroidRendererBackend::AndroidRendererBackend()
|
||||
AndroidRendererBackend::AndroidRendererBackend(const TaggedScheduler& threadPool)
|
||||
: gl::RendererBackend(gfx::ContextMode::Unique),
|
||||
mbgl::gfx::Renderable({64, 64}, std::make_unique<AndroidGLRenderableResource>(*this)) {}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace android {
|
||||
|
||||
class AndroidRendererBackend : public gl::RendererBackend, public mbgl::gfx::Renderable {
|
||||
public:
|
||||
AndroidRendererBackend();
|
||||
AndroidRendererBackend(const TaggedScheduler& threadPool);
|
||||
~AndroidRendererBackend() override;
|
||||
|
||||
void updateViewPort();
|
||||
|
||||
@@ -82,6 +82,10 @@ void AndroidRendererFrontend::update(std::shared_ptr<UpdateParameters> params) {
|
||||
updateAsyncTask->send();
|
||||
}
|
||||
|
||||
const TaggedScheduler& AndroidRendererFrontend::getThreadPool() const {
|
||||
return mapRenderer.getThreadPool();
|
||||
}
|
||||
|
||||
void AndroidRendererFrontend::reduceMemoryUse() {
|
||||
mapRenderer.actor().invoke(&Renderer::reduceMemoryUse);
|
||||
}
|
||||
|
||||
@@ -37,6 +37,8 @@ public:
|
||||
|
||||
void update(std::shared_ptr<UpdateParameters>) override;
|
||||
|
||||
const TaggedScheduler& getThreadPool() const override;
|
||||
|
||||
// Feature querying
|
||||
std::vector<Feature> queryRenderedFeatures(const ScreenCoordinate&, const RenderedQueryOptions&) const;
|
||||
std::vector<Feature> queryRenderedFeatures(const ScreenBox&, const RenderedQueryOptions&) const;
|
||||
|
||||
@@ -22,6 +22,7 @@ MapRenderer::MapRenderer(jni::JNIEnv& _env,
|
||||
pixelRatio(pixelRatio_),
|
||||
localIdeographFontFamily(localIdeographFontFamily_ ? jni::Make<std::string>(_env, localIdeographFontFamily_)
|
||||
: std::optional<std::string>{}),
|
||||
threadPool(Scheduler::GetBackground(), {}),
|
||||
mailboxData(this) {}
|
||||
|
||||
MapRenderer::MailboxData::MailboxData(Scheduler* scheduler_)
|
||||
@@ -84,20 +85,17 @@ void MapRenderer::schedule(std::function<void()>&& scheduled) {
|
||||
}
|
||||
}
|
||||
|
||||
std::size_t MapRenderer::waitForEmpty(Milliseconds timeout) {
|
||||
void MapRenderer::waitForEmpty([[maybe_unused]] const util::SimpleIdentity tag) {
|
||||
try {
|
||||
android::UniqueEnv _env = android::AttachEnv();
|
||||
static auto& javaClass = jni::Class<MapRenderer>::Singleton(*_env);
|
||||
static auto waitForEmpty = javaClass.GetMethod<jni::jint(jni::jlong)>(*_env, "waitForEmpty");
|
||||
static auto waitForEmpty = javaClass.GetMethod<void()>(*_env, "waitForEmpty");
|
||||
if (auto weakReference = javaPeer.get(*_env)) {
|
||||
return weakReference.Call(*_env, waitForEmpty, static_cast<int64_t>(timeout.count()));
|
||||
return weakReference.Call(*_env, waitForEmpty);
|
||||
}
|
||||
// If the peer is already cleaned up, there's nothing to wait for
|
||||
return 0;
|
||||
} catch (...) {
|
||||
Log::Error(Event::Android, "MapRenderer::waitForEmpty failed");
|
||||
jni::ThrowJavaError(*android::AttachEnv(), std::current_exception());
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,7 +219,7 @@ void MapRenderer::onSurfaceCreated(JNIEnv&) {
|
||||
backend.reset();
|
||||
|
||||
// Create the new backend and renderer
|
||||
backend = std::make_unique<AndroidRendererBackend>();
|
||||
backend = std::make_unique<AndroidRendererBackend>(threadPool);
|
||||
renderer = std::make_unique<Renderer>(*backend, pixelRatio, localIdeographFontFamily);
|
||||
rendererRef = std::make_unique<ActorRef<Renderer>>(*renderer, mailboxData.getMailbox());
|
||||
|
||||
|
||||
@@ -67,11 +67,12 @@ public:
|
||||
// From Scheduler. Schedules by using callbacks to the
|
||||
// JVM to process the mailbox on the right thread.
|
||||
void schedule(std::function<void()>&& scheduled) override;
|
||||
void schedule(const util::SimpleIdentity, std::function<void()>&& fn) override { schedule(std::move(fn)); };
|
||||
|
||||
mapbox::base::WeakPtr<Scheduler> makeWeakPtr() override { return weakFactory.makeWeakPtr(); }
|
||||
|
||||
// Wait for the queue to be empty
|
||||
// A timeout of zero results in an unbounded wait
|
||||
std::size_t waitForEmpty(Milliseconds timeout) override;
|
||||
void waitForEmpty(const util::SimpleIdentity tag) override;
|
||||
|
||||
void requestRender();
|
||||
|
||||
@@ -79,6 +80,9 @@ public:
|
||||
using SnapshotCallback = std::function<void(PremultipliedImage)>;
|
||||
void requestSnapshot(SnapshotCallback);
|
||||
|
||||
AndroidRendererBackend& getRendererBackend() const { return *backend; }
|
||||
const TaggedScheduler& getThreadPool() const { return threadPool; }
|
||||
|
||||
protected:
|
||||
// Called from the GL Thread //
|
||||
|
||||
@@ -119,7 +123,7 @@ private:
|
||||
float pixelRatio;
|
||||
std::optional<std::string> localIdeographFontFamily;
|
||||
|
||||
std::shared_ptr<ThreadPool> threadPool;
|
||||
TaggedScheduler threadPool;
|
||||
const MailboxData mailboxData;
|
||||
|
||||
std::mutex initialisationMutex;
|
||||
|
||||
Reference in New Issue
Block a user