summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Shalamov <alexander.shalamov@mapbox.com>2020-02-27 12:42:13 +0200
committerAlexander Shalamov <alexander.shalamov@mapbox.com>2020-03-05 17:43:37 +0200
commit29eff4028d9a17557c0aca5ce68c824335e1489e (patch)
treee040f8f24af53764aff78e9033f5f7fa5824f1ca
parent09e69654fa7e7b1f14e3c6e0d140690935eed97d (diff)
downloadqtlocation-mapboxgl-29eff4028d9a17557c0aca5ce68c824335e1489e.tar.gz
[core] Remove Actor from public Snapshotter API
-rw-r--r--platform/default/include/mbgl/map/map_snapshotter.hpp6
-rw-r--r--platform/default/src/mbgl/map/map_snapshotter.cpp44
2 files changed, 39 insertions, 11 deletions
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 <string>
#include <vector>
#include <functional>
-
namespace mbgl {
-template<class> class ActorRef;
struct CameraOptions;
-class FileSource;
-class Size;
class LatLngBounds;
class ResourceOptions;
@@ -54,7 +50,7 @@ public:
using LatLngForFn = std::function<LatLng (const ScreenCoordinate&)>;
using Attributions = std::vector<std::string>;
using Callback = std::function<void (std::exception_ptr, PremultipliedImage, Attributions, PointForFn, LatLngForFn)>;
- void snapshot(ActorRef<Callback>);
+ 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 <mbgl/storage/resource_options.hpp>
#include <mbgl/style/style.hpp>
#include <mbgl/util/event.hpp>
+#include <mbgl/util/exception.hpp>
+#include <mbgl/util/logging.hpp>
#include <mbgl/util/thread.hpp>
namespace mbgl {
@@ -161,8 +163,32 @@ public:
map.jumpTo(map.cameraForLatLngs(latLngs, insets));
}
- void snapshot(ActorRef<MapSnapshotter::Callback> 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<Actor<MapSnapshotter::Callback>>(
+ *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<Actor<MapSnapshotter::Callback>> renderStillCallback;
SnapshotterRendererFrontend frontend;
Map map;
};
@@ -218,12 +245,17 @@ MapSnapshotter::MapSnapshotter(std::pair<bool, std::string> style,
optional<LatLngBounds> region,
optional<std::string> localFontFamily,
const ResourceOptions& resourceOptions)
- : impl(std::make_unique<MapSnapshotter::Impl>(
- std::move(style), size, pixelRatio, std::move(cameraOptions), std::move(region), localFontFamily, resourceOptions.clone())) {}
+ : impl(std::make_unique<MapSnapshotter::Impl>(std::move(style),
+ size,
+ pixelRatio,
+ std::move(cameraOptions),
+ std::move(region),
+ localFontFamily,
+ resourceOptions.clone())) {}
MapSnapshotter::~MapSnapshotter() = default;
-void MapSnapshotter::snapshot(ActorRef<MapSnapshotter::Callback> callback) {
+void MapSnapshotter::snapshot(MapSnapshotter::Callback callback) {
impl->snapshot(std::move(callback));
}