diff options
author | Ivo van Dongen <info@ivovandongen.nl> | 2017-09-18 11:31:45 +0300 |
---|---|---|
committer | Ivo van Dongen <ivovandongen@users.noreply.github.com> | 2017-09-22 23:33:56 +0300 |
commit | c17be060fd910dbcaf7334356743421ac6936e7e (patch) | |
tree | 5f1636059cc7fe92e99e891d46119655af997db6 /platform/android/src/map_renderer.cpp | |
parent | 8182b26dfe7c1ffd5066e9f0c2f9536264308067 (diff) | |
download | qtlocation-mapboxgl-c17be060fd910dbcaf7334356743421ac6936e7e.tar.gz |
[android] map snapshots
Diffstat (limited to 'platform/android/src/map_renderer.cpp')
-rw-r--r-- | platform/android/src/map_renderer.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/platform/android/src/map_renderer.cpp b/platform/android/src/map_renderer.cpp index 0db41ffe8a..3cf39ad3ff 100644 --- a/platform/android/src/map_renderer.cpp +++ b/platform/android/src/map_renderer.cpp @@ -2,6 +2,7 @@ #include <mbgl/renderer/renderer.hpp> #include <mbgl/util/shared_thread_pool.hpp> +#include <mbgl/util/run_loop.hpp> #include <string> @@ -75,8 +76,26 @@ void MapRenderer::setObserver(std::shared_ptr<RendererObserver> _rendererObserve } } +void MapRenderer::requestSnapshot(SnapshotCallback callback) { + auto self = ActorRef<MapRenderer>(*this, mailbox); + self.invoke( + &MapRenderer::scheduleSnapshot, + std::make_unique<SnapshotCallback>([&, callback=std::move(callback), runloop=util::RunLoop::Get()](PremultipliedImage image) { + runloop->invoke([callback=std::move(callback), image=std::move(image)]() mutable { + callback(std::move(image)); + }); + snapshotCallback.reset(); + }) + ); +} + // Called on OpenGL thread // +void MapRenderer::scheduleSnapshot(std::unique_ptr<SnapshotCallback> callback) { + snapshotCallback = std::move(callback); + requestRender(); +} + void MapRenderer::render(JNIEnv&) { assert (renderer); @@ -103,6 +122,12 @@ void MapRenderer::render(JNIEnv&) { } renderer->render(*params); + + // Deliver the snapshot if requested + if (snapshotCallback) { + snapshotCallback->operator()(backend->readFramebuffer()); + snapshotCallback.reset(); + } } void MapRenderer::onSurfaceCreated(JNIEnv&) { |