From 29eff4028d9a17557c0aca5ce68c824335e1489e Mon Sep 17 00:00:00 2001 From: Alexander Shalamov Date: Thu, 27 Feb 2020 12:42:13 +0200 Subject: [core] Remove Actor from public Snapshotter API --- .../default/include/mbgl/map/map_snapshotter.hpp | 6 +-- platform/default/src/mbgl/map/map_snapshotter.cpp | 44 +++++++++++++++++++--- 2 files changed, 39 insertions(+), 11 deletions(-) (limited to 'platform') diff --git a/platform/default/include/mbgl/map/map_snapshotter.hpp b/platform/default/include/mbgl/map/map_snapshotter.hpp index 938c9bd4bf..7742669c46 100644 --- a/platform/default/include/mbgl/map/map_snapshotter.hpp +++ b/platform/default/include/mbgl/map/map_snapshotter.hpp @@ -9,13 +9,9 @@ #include #include #include - namespace mbgl { -template class ActorRef; struct CameraOptions; -class FileSource; -class Size; class LatLngBounds; class ResourceOptions; @@ -54,7 +50,7 @@ public: using LatLngForFn = std::function; using Attributions = std::vector; using Callback = std::function; - void snapshot(ActorRef); + void snapshot(Callback); private: class Impl; diff --git a/platform/default/src/mbgl/map/map_snapshotter.cpp b/platform/default/src/mbgl/map/map_snapshotter.cpp index a3029f151a..95d5f3d75b 100644 --- a/platform/default/src/mbgl/map/map_snapshotter.cpp +++ b/platform/default/src/mbgl/map/map_snapshotter.cpp @@ -11,6 +11,8 @@ #include #include #include +#include +#include #include namespace mbgl { @@ -161,8 +163,32 @@ public: map.jumpTo(map.cameraForLatLngs(latLngs, insets)); } - void snapshot(ActorRef callback) { - map.renderStill([this, callback = std::move(callback)](std::exception_ptr error) { + void snapshot(MapSnapshotter::Callback callback) { + if (!callback) { + Log::Error(Event::General, "MapSnapshotter::Callback is not set"); + return; + } + + if (renderStillCallback) { + callback(std::make_exception_ptr(util::MisuseException("MapSnapshotter is currently rendering an image")), + PremultipliedImage(), + {}, + {}, + {}); + } + + renderStillCallback = std::make_unique>( + *Scheduler::GetCurrent(), + [this, cb = std::move(callback)](std::exception_ptr ptr, + PremultipliedImage image, + Attributions attributions, + PointForFn pfn, + LatLngForFn latLonFn) { + cb(ptr, std::move(image), std::move(attributions), std::move(pfn), std::move(latLonFn)); + renderStillCallback.reset(); + }); + + map.renderStill([this, actorRef = renderStillCallback->self()](std::exception_ptr error) { // Create lambda that captures the current transform state // and can be used to translate for geographic to screen // coordinates @@ -194,7 +220,7 @@ public: } // Invoke callback - callback.invoke(&MapSnapshotter::Callback::operator(), + actorRef.invoke(&MapSnapshotter::Callback::operator(), error, error ? PremultipliedImage() : frontend.takeImage(), std::move(attributions), @@ -207,6 +233,7 @@ public: SnapshotterRendererFrontend& getRenderer() { return frontend; } private: + std::unique_ptr> renderStillCallback; SnapshotterRendererFrontend frontend; Map map; }; @@ -218,12 +245,17 @@ MapSnapshotter::MapSnapshotter(std::pair style, optional region, optional localFontFamily, const ResourceOptions& resourceOptions) - : impl(std::make_unique( - std::move(style), size, pixelRatio, std::move(cameraOptions), std::move(region), localFontFamily, resourceOptions.clone())) {} + : impl(std::make_unique(std::move(style), + size, + pixelRatio, + std::move(cameraOptions), + std::move(region), + localFontFamily, + resourceOptions.clone())) {} MapSnapshotter::~MapSnapshotter() = default; -void MapSnapshotter::snapshot(ActorRef callback) { +void MapSnapshotter::snapshot(MapSnapshotter::Callback callback) { impl->snapshot(std::move(callback)); } -- cgit v1.2.1