From 039bc80411e3b1ca09e2dd60c9f18105fc68d4fc Mon Sep 17 00:00:00 2001 From: Alexander Shalamov Date: Thu, 27 Feb 2020 16:55:44 +0200 Subject: [android] Update android snapshotter --- .../android/src/snapshotter/map_snapshotter.cpp | 46 ++++++++++------------ .../android/src/snapshotter/map_snapshotter.hpp | 3 -- 2 files changed, 20 insertions(+), 29 deletions(-) (limited to 'platform') diff --git a/platform/android/src/snapshotter/map_snapshotter.cpp b/platform/android/src/snapshotter/map_snapshotter.cpp index 0b38269ada..e888cae3df 100644 --- a/platform/android/src/snapshotter/map_snapshotter.cpp +++ b/platform/android/src/snapshotter/map_snapshotter.cpp @@ -36,34 +36,29 @@ MapSnapshotter::MapSnapshotter(jni::JNIEnv& _env, jFileSource = FileSource::getNativePeer(_env, _jFileSource); auto size = mbgl::Size { static_cast(width), static_cast(height) }; - optional cameraOptions; + showLogo = _showLogo; + + // Create the core snapshotter + snapshotter = std::make_unique( + size, + pixelRatio, + mbgl::android::FileSource::getSharedResourceOptions(_env, _jFileSource), + mbgl::MapSnapshotterObserver::nullObserver(), + _localIdeographFontFamily ? jni::Make(_env, _localIdeographFontFamily) : optional{}); + if (position) { - cameraOptions = CameraPosition::getCameraOptions(_env, position, pixelRatio); + snapshotter->setCameraOptions(CameraPosition::getCameraOptions(_env, position, pixelRatio)); } - optional bounds; if (region) { - bounds = LatLngBounds::getLatLngBounds(_env, region); + snapshotter->setRegion(LatLngBounds::getLatLngBounds(_env, region)); } - std::pair style; if (styleJSON) { - style = std::make_pair(true, jni::Make(_env, styleJSON)); + snapshotter->setStyleJSON(jni::Make(_env, styleJSON)); } else { - style = std::make_pair(false, jni::Make(_env, styleURL)); + snapshotter->setStyleJSON(jni::Make(_env, styleURL)); } - - showLogo = _showLogo; - // Create the core snapshotter - snapshotter = std::make_unique(style, - size, - pixelRatio, - cameraOptions, - bounds, - _localIdeographFontFamily ? - jni::Make(_env, _localIdeographFontFamily) : - optional{}, - mbgl::android::FileSource::getSharedResourceOptions(_env, _jFileSource)); } MapSnapshotter::~MapSnapshotter() = default; @@ -71,10 +66,11 @@ MapSnapshotter::~MapSnapshotter() = default; void MapSnapshotter::start(JNIEnv& env) { MBGL_VERIFY_THREAD(tid); activateFilesource(env); - - snapshotCallback = std::make_unique>( - *Scheduler::GetCurrent(), - [this](std::exception_ptr err, PremultipliedImage image, std::vector attributions, mbgl::MapSnapshotter::PointForFn pointForFn, mbgl::MapSnapshotter::LatLngForFn latLngForFn) { + snapshotter->snapshot([this](std::exception_ptr err, + PremultipliedImage image, + std::vector attributions, + mbgl::MapSnapshotter::PointForFn pointForFn, + mbgl::MapSnapshotter::LatLngForFn latLngForFn) { MBGL_VERIFY_THREAD(tid); android::UniqueEnv _env = android::AttachEnv(); static auto& javaClass = jni::Class::Singleton(*_env); @@ -100,13 +96,11 @@ void MapSnapshotter::start(JNIEnv& env) { deactivateFilesource(*_env); }); - - snapshotter->snapshot(snapshotCallback->self()); } void MapSnapshotter::cancel(JNIEnv& env) { MBGL_VERIFY_THREAD(tid); - snapshotCallback.reset(); + snapshotter->cancel(); deactivateFilesource(env); } diff --git a/platform/android/src/snapshotter/map_snapshotter.hpp b/platform/android/src/snapshotter/map_snapshotter.hpp index 608a4c855f..641a0e60f8 100644 --- a/platform/android/src/snapshotter/map_snapshotter.hpp +++ b/platform/android/src/snapshotter/map_snapshotter.hpp @@ -14,8 +14,6 @@ namespace mbgl { namespace android { -class SnapshotterRendererFrontend; - class MapSnapshotter { public: @@ -61,7 +59,6 @@ private: float pixelRatio; bool showLogo; - std::unique_ptr> snapshotCallback; std::unique_ptr snapshotter; FileSource *jFileSource; -- cgit v1.2.1