summaryrefslogtreecommitdiff
path: root/platform/android/src/map_renderer.cpp
diff options
context:
space:
mode:
authorIvo van Dongen <info@ivovandongen.nl>2017-09-18 11:31:45 +0300
committerIvo van Dongen <ivovandongen@users.noreply.github.com>2017-09-22 23:33:56 +0300
commitc17be060fd910dbcaf7334356743421ac6936e7e (patch)
tree5f1636059cc7fe92e99e891d46119655af997db6 /platform/android/src/map_renderer.cpp
parent8182b26dfe7c1ffd5066e9f0c2f9536264308067 (diff)
downloadqtlocation-mapboxgl-c17be060fd910dbcaf7334356743421ac6936e7e.tar.gz
[android] map snapshots
Diffstat (limited to 'platform/android/src/map_renderer.cpp')
-rw-r--r--platform/android/src/map_renderer.cpp25
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&) {