diff options
author | Tim Watson <tewatson89@gmail.com> | 2019-04-03 14:51:13 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-03 14:51:13 -0700 |
commit | 0ff25060dae4858a1b60e2277dbd8921de7a6785 (patch) | |
tree | d29d578b9b9d6cfb0999b7a30819d379b85172b7 /platform/default/src | |
parent | ba2b7a74c420856401d344ff15b27771175c9819 (diff) | |
parent | 0f416fbbde9b146eb28a4bf88586738d12505007 (diff) | |
download | qtlocation-mapboxgl-upstream/friedbunny-external-pr-14135.tar.gz |
Merge pull request #1 from mapbox/masterupstream/friedbunny-external-pr-14135
Merge Master
Diffstat (limited to 'platform/default/src')
4 files changed, 49 insertions, 26 deletions
diff --git a/platform/default/src/mbgl/gl/headless_frontend.cpp b/platform/default/src/mbgl/gl/headless_frontend.cpp index f3dae2dbc9..c311e2df41 100644 --- a/platform/default/src/mbgl/gl/headless_frontend.cpp +++ b/platform/default/src/mbgl/gl/headless_frontend.cpp @@ -20,7 +20,13 @@ HeadlessFrontend::HeadlessFrontend(Size size_, float pixelRatio_, Scheduler& sch asyncInvalidate([this] { if (renderer && updateParameters) { mbgl::BackendScope guard { backend }; - renderer->render(*updateParameters); + + // onStyleImageMissing might be called during a render. The user implemented method + // could trigger a call to MGLRenderFrontend#update which overwrites `updateParameters`. + // Copy the shared pointer here so that the parameters aren't destroyed while `render(...)` is + // still using them. + auto updateParameters_ = updateParameters; + renderer->render(*updateParameters_); } }), renderer(std::make_unique<Renderer>(backend, pixelRatio, scheduler, mode, programCacheDir, localFontFamily)) { diff --git a/platform/default/src/mbgl/map/map_snapshotter.cpp b/platform/default/src/mbgl/map/map_snapshotter.cpp index 415ef7befd..227a61d272 100644 --- a/platform/default/src/mbgl/map/map_snapshotter.cpp +++ b/platform/default/src/mbgl/map/map_snapshotter.cpp @@ -5,7 +5,7 @@ #include <mbgl/map/map.hpp> #include <mbgl/map/map_options.hpp> #include <mbgl/map/transform_state.hpp> -#include <mbgl/storage/file_source.hpp> +#include <mbgl/storage/resource_options.hpp> #include <mbgl/style/style.hpp> #include <mbgl/util/event.hpp> #include <mbgl/map/transform.hpp> @@ -14,15 +14,15 @@ namespace mbgl { class MapSnapshotter::Impl { public: - Impl(FileSource*, - std::shared_ptr<Scheduler>, + Impl(std::shared_ptr<Scheduler>, const std::pair<bool, std::string> style, const Size&, const float pixelRatio, const optional<CameraOptions> cameraOptions, const optional<LatLngBounds> region, const optional<std::string> programCacheDir, - const optional<std::string> localFontFamily = {}); + const optional<std::string> localFontFamily, + const ResourceOptions& resourceOptions); void setStyleURL(std::string styleURL); std::string getStyleURL() const; @@ -47,19 +47,20 @@ private: Map map; }; -MapSnapshotter::Impl::Impl(FileSource* fileSource, - std::shared_ptr<Scheduler> scheduler_, - const std::pair<bool, std::string> style, - const Size& size, - const float pixelRatio, - const optional<CameraOptions> cameraOptions, - const optional<LatLngBounds> region, - const optional<std::string> programCacheDir, - const optional<std::string> localFontFamily) - : scheduler(std::move(scheduler_)) - , frontend(size, pixelRatio, *scheduler, programCacheDir, GLContextMode::Unique, localFontFamily) - , map(frontend, MapObserver::nullObserver(), size, pixelRatio, *fileSource, *scheduler, MapOptions().withMapMode(MapMode::Static)) { - +MapSnapshotter::Impl::Impl(std::shared_ptr<Scheduler> scheduler_, + const std::pair<bool, std::string> style, + const Size& size, + const float pixelRatio, + const optional<CameraOptions> cameraOptions, + const optional<LatLngBounds> region, + const optional<std::string> programCacheDir, + const optional<std::string> localFontFamily, + const ResourceOptions& resourceOptions) + : scheduler(std::move(scheduler_)) + , frontend(size, pixelRatio, *scheduler, programCacheDir, GLContextMode::Unique, localFontFamily) + , map(frontend, MapObserver::nullObserver(), *scheduler, + MapOptions().withMapMode(MapMode::Static).withSize(size).withPixelRatio(pixelRatio), + resourceOptions) { if (style.first) { map.getStyle().loadJSON(style.second); } else{ @@ -142,7 +143,7 @@ void MapSnapshotter::Impl::setSize(Size size) { } Size MapSnapshotter::Impl::getSize() const { - return map.getSize(); + return map.getMapOptions().size(); } void MapSnapshotter::Impl::setCameraOptions(CameraOptions cameraOptions) { @@ -164,17 +165,18 @@ LatLngBounds MapSnapshotter::Impl::getRegion() const { return map.latLngBoundsForCamera(getCameraOptions()); } -MapSnapshotter::MapSnapshotter(FileSource* fileSource, - std::shared_ptr<Scheduler> scheduler, +MapSnapshotter::MapSnapshotter(std::shared_ptr<Scheduler> scheduler, const std::pair<bool, std::string> style, const Size& size, const float pixelRatio, const optional<CameraOptions> cameraOptions, const optional<LatLngBounds> region, const optional<std::string> programCacheDir, - const optional<std::string> localFontFamily) - : impl(std::make_unique<util::Thread<MapSnapshotter::Impl>>("Map Snapshotter", fileSource, std::move(scheduler), style, size, pixelRatio, cameraOptions, region, programCacheDir, localFontFamily)) { -} + const optional<std::string> localFontFamily, + const ResourceOptions& resourceOptions) + : impl(std::make_unique<util::Thread<MapSnapshotter::Impl>>( + "Map Snapshotter", std::move(scheduler), style, size, pixelRatio, cameraOptions, + region, programCacheDir, localFontFamily, resourceOptions.clone())) {} MapSnapshotter::~MapSnapshotter() = default; diff --git a/platform/default/src/mbgl/storage/default_file_source.cpp b/platform/default/src/mbgl/storage/default_file_source.cpp index 32eb8b3d58..4d812044cf 100644 --- a/platform/default/src/mbgl/storage/default_file_source.cpp +++ b/platform/default/src/mbgl/storage/default_file_source.cpp @@ -201,9 +201,9 @@ private: }; DefaultFileSource::DefaultFileSource(const std::string& cachePath, - const std::string& assetRoot, + const std::string& assetPath, uint64_t maximumCacheSize) - : DefaultFileSource(cachePath, std::make_unique<AssetFileSource>(assetRoot), maximumCacheSize) { + : DefaultFileSource(cachePath, std::make_unique<AssetFileSource>(assetPath), maximumCacheSize) { } DefaultFileSource::DefaultFileSource(const std::string& cachePath, diff --git a/platform/default/src/mbgl/storage/file_source.cpp b/platform/default/src/mbgl/storage/file_source.cpp new file mode 100644 index 0000000000..a7bbe82f5a --- /dev/null +++ b/platform/default/src/mbgl/storage/file_source.cpp @@ -0,0 +1,15 @@ +#include <mbgl/storage/resource_options.hpp> +#include <mbgl/storage/default_file_source.hpp> + +#include <memory> + +namespace mbgl { + +std::shared_ptr<FileSource> FileSource::createPlatformFileSource(const ResourceOptions& options) { + auto fileSource = std::make_shared<DefaultFileSource>(options.cachePath(), options.assetPath()); + fileSource->setAccessToken(options.accessToken()); + fileSource->setAPIBaseURL(options.baseURL()); + return fileSource; +} + +} // namespace mbgl |