From d5868d3da822f2bf3297229bd879e76853108a63 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Tue, 19 Mar 2019 16:57:36 +0200 Subject: [core] Remove file source from public Map ctor --- platform/default/src/mbgl/map/map_snapshotter.cpp | 44 +++++++++++----------- .../src/mbgl/storage/default_file_source.cpp | 4 +- platform/default/src/mbgl/storage/file_source.cpp | 15 ++++++++ 3 files changed, 39 insertions(+), 24 deletions(-) create mode 100644 platform/default/src/mbgl/storage/file_source.cpp (limited to 'platform/default/src') diff --git a/platform/default/src/mbgl/map/map_snapshotter.cpp b/platform/default/src/mbgl/map/map_snapshotter.cpp index 415ef7befd..cd8482e4ba 100644 --- a/platform/default/src/mbgl/map/map_snapshotter.cpp +++ b/platform/default/src/mbgl/map/map_snapshotter.cpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include #include @@ -14,15 +14,15 @@ namespace mbgl { class MapSnapshotter::Impl { public: - Impl(FileSource*, - std::shared_ptr, + Impl(std::shared_ptr, const std::pair style, const Size&, const float pixelRatio, const optional cameraOptions, const optional region, const optional programCacheDir, - const optional localFontFamily = {}); + const optional localFontFamily, + const ResourceOptions& resourceOptions); void setStyleURL(std::string styleURL); std::string getStyleURL() const; @@ -47,19 +47,18 @@ private: Map map; }; -MapSnapshotter::Impl::Impl(FileSource* fileSource, - std::shared_ptr scheduler_, - const std::pair style, - const Size& size, - const float pixelRatio, - const optional cameraOptions, - const optional region, - const optional programCacheDir, - const optional 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_, + const std::pair style, + const Size& size, + const float pixelRatio, + const optional cameraOptions, + const optional region, + const optional programCacheDir, + const optional localFontFamily, + const ResourceOptions& resourceOptions) + : scheduler(std::move(scheduler_)) + , frontend(size, pixelRatio, *scheduler, programCacheDir, GLContextMode::Unique, localFontFamily) + , map(frontend, MapObserver::nullObserver(), size, pixelRatio, *scheduler, MapOptions().withMapMode(MapMode::Static), resourceOptions) { if (style.first) { map.getStyle().loadJSON(style.second); } else{ @@ -164,17 +163,18 @@ LatLngBounds MapSnapshotter::Impl::getRegion() const { return map.latLngBoundsForCamera(getCameraOptions()); } -MapSnapshotter::MapSnapshotter(FileSource* fileSource, - std::shared_ptr scheduler, +MapSnapshotter::MapSnapshotter(std::shared_ptr scheduler, const std::pair style, const Size& size, const float pixelRatio, const optional cameraOptions, const optional region, const optional programCacheDir, - const optional localFontFamily) - : impl(std::make_unique>("Map Snapshotter", fileSource, std::move(scheduler), style, size, pixelRatio, cameraOptions, region, programCacheDir, localFontFamily)) { -} + const optional localFontFamily, + const ResourceOptions& resourceOptions) + : impl(std::make_unique>( + "Map Snapshotter", std::move(scheduler), style, size, pixelRatio, cameraOptions, + region, programCacheDir, localFontFamily, resourceOptions)) {} 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(assetRoot), maximumCacheSize) { + : DefaultFileSource(cachePath, std::make_unique(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 +#include + +#include + +namespace mbgl { + +std::shared_ptr FileSource::createPlatformFileSource(const ResourceOptions& options) { + auto fileSource = std::make_shared(options.cachePath(), options.assetPath()); + fileSource->setAccessToken(options.accessToken()); + fileSource->setAPIBaseURL(options.baseURL()); + return fileSource; +} + +} // namespace mbgl -- cgit v1.2.1 From 067ff28d0ac5c35c399069457051e53f900696a0 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Sun, 24 Mar 2019 17:15:37 +0200 Subject: [core] ResoureOptions explicit copy via clone() --- platform/default/src/mbgl/map/map_snapshotter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'platform/default/src') diff --git a/platform/default/src/mbgl/map/map_snapshotter.cpp b/platform/default/src/mbgl/map/map_snapshotter.cpp index cd8482e4ba..ca5eadafbc 100644 --- a/platform/default/src/mbgl/map/map_snapshotter.cpp +++ b/platform/default/src/mbgl/map/map_snapshotter.cpp @@ -174,7 +174,7 @@ MapSnapshotter::MapSnapshotter(std::shared_ptr scheduler, const ResourceOptions& resourceOptions) : impl(std::make_unique>( "Map Snapshotter", std::move(scheduler), style, size, pixelRatio, cameraOptions, - region, programCacheDir, localFontFamily, resourceOptions)) {} + region, programCacheDir, localFontFamily, resourceOptions.clone())) {} MapSnapshotter::~MapSnapshotter() = default; -- cgit v1.2.1 From 1cc1d4ea08ae02c3cc9b4dd1474845456c17d1bc Mon Sep 17 00:00:00 2001 From: Sudarsana Babu Nagineni Date: Tue, 26 Mar 2019 00:00:37 +0200 Subject: [core] Add setter/getter for size property in MapOptions --- platform/default/src/mbgl/map/map_snapshotter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'platform/default/src') diff --git a/platform/default/src/mbgl/map/map_snapshotter.cpp b/platform/default/src/mbgl/map/map_snapshotter.cpp index ca5eadafbc..d5a71a5508 100644 --- a/platform/default/src/mbgl/map/map_snapshotter.cpp +++ b/platform/default/src/mbgl/map/map_snapshotter.cpp @@ -58,7 +58,7 @@ MapSnapshotter::Impl::Impl(std::shared_ptr scheduler_, const ResourceOptions& resourceOptions) : scheduler(std::move(scheduler_)) , frontend(size, pixelRatio, *scheduler, programCacheDir, GLContextMode::Unique, localFontFamily) - , map(frontend, MapObserver::nullObserver(), size, pixelRatio, *scheduler, MapOptions().withMapMode(MapMode::Static), resourceOptions) { + , map(frontend, MapObserver::nullObserver(), pixelRatio, *scheduler, MapOptions().withMapMode(MapMode::Static).withSize(size), resourceOptions) { if (style.first) { map.getStyle().loadJSON(style.second); } else{ @@ -141,7 +141,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) { -- cgit v1.2.1 From 7af00a404f22742fed4a83e9a36d023d7515025f Mon Sep 17 00:00:00 2001 From: Sudarsana Babu Nagineni Date: Wed, 27 Mar 2019 19:17:04 +0200 Subject: [core] Include pixelRatio property in MapOptions Move pixelRatio property from Map constructor to MapOptions. --- platform/default/src/mbgl/map/map_snapshotter.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'platform/default/src') diff --git a/platform/default/src/mbgl/map/map_snapshotter.cpp b/platform/default/src/mbgl/map/map_snapshotter.cpp index d5a71a5508..227a61d272 100644 --- a/platform/default/src/mbgl/map/map_snapshotter.cpp +++ b/platform/default/src/mbgl/map/map_snapshotter.cpp @@ -58,7 +58,9 @@ MapSnapshotter::Impl::Impl(std::shared_ptr scheduler_, const ResourceOptions& resourceOptions) : scheduler(std::move(scheduler_)) , frontend(size, pixelRatio, *scheduler, programCacheDir, GLContextMode::Unique, localFontFamily) - , map(frontend, MapObserver::nullObserver(), pixelRatio, *scheduler, MapOptions().withMapMode(MapMode::Static).withSize(size), resourceOptions) { + , map(frontend, MapObserver::nullObserver(), *scheduler, + MapOptions().withMapMode(MapMode::Static).withSize(size).withPixelRatio(pixelRatio), + resourceOptions) { if (style.first) { map.getStyle().loadJSON(style.second); } else{ -- cgit v1.2.1 From 2455275bf47e1671a92eb2c1296c6b48f11f6b2e Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Tue, 2 Apr 2019 12:57:45 -0400 Subject: add onStyleImageMissing to allow dynamically loaded or generated images (#14253) Also make `Style#updateImage(...)` much faster when the image doesn't change size. This can be useful for asynchronously generating images. --- platform/default/src/mbgl/gl/headless_frontend.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'platform/default/src') 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(backend, pixelRatio, scheduler, mode, programCacheDir, localFontFamily)) { -- cgit v1.2.1