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 --- benchmark/api/query.benchmark.cpp | 4 ++-- benchmark/api/render.benchmark.cpp | 16 ++++++++-------- bin/render.cpp | 4 ++-- include/mbgl/map/map.hpp | 6 +----- include/mbgl/map/map_options.hpp | 16 ++++++++++++++++ platform/android/src/native_map_view.cpp | 5 +++-- platform/default/src/mbgl/map/map_snapshotter.cpp | 4 ++-- platform/glfw/main.cpp | 2 +- platform/ios/src/MGLMapView.mm | 3 ++- platform/macos/src/MGLMapView.mm | 3 ++- platform/node/src/node_map.cpp | 12 ++++++++---- platform/qt/src/qmapboxgl.cpp | 9 +++++---- src/mbgl/map/map.cpp | 20 ++++---------------- src/mbgl/map/map_impl.cpp | 3 +-- src/mbgl/map/map_impl.hpp | 2 +- src/mbgl/map/map_options.cpp | 10 ++++++++++ test/api/annotations.test.cpp | 4 ++-- test/api/api_misuse.test.cpp | 4 ++-- test/api/custom_geometry_source.test.cpp | 4 ++-- test/api/custom_layer.test.cpp | 4 ++-- test/api/query.test.cpp | 4 ++-- test/api/recycle_map.cpp | 4 ++-- test/gl/context.test.cpp | 4 ++-- test/map/map.test.cpp | 17 +++++++++-------- test/map/prefetch.test.cpp | 4 ++-- test/src/mbgl/test/map_adapter.hpp | 3 +-- test/text/local_glyph_rasterizer.test.cpp | 4 ++-- test/util/memory.test.cpp | 12 ++++++------ 28 files changed, 102 insertions(+), 85 deletions(-) diff --git a/benchmark/api/query.benchmark.cpp b/benchmark/api/query.benchmark.cpp index 5e273d69ac..1db958c1be 100644 --- a/benchmark/api/query.benchmark.cpp +++ b/benchmark/api/query.benchmark.cpp @@ -32,8 +32,8 @@ public: util::RunLoop loop; ThreadPool threadPool{ 4 }; HeadlessFrontend frontend { { 1000, 1000 }, 1, threadPool }; - Map map { frontend, MapObserver::nullObserver(), frontend.getSize(), 1, threadPool, - MapOptions().withMapMode(MapMode::Static), + Map map { frontend, MapObserver::nullObserver(), 1, threadPool, + MapOptions().withMapMode(MapMode::Static).withSize(frontend.getSize()), ResourceOptions().withCachePath("benchmark/fixtures/api/cache.db").withAssetPath(".").withAccessToken("foobar") }; ScreenBox box{{ 0, 0 }, { 1000, 1000 }}; }; diff --git a/benchmark/api/render.benchmark.cpp b/benchmark/api/render.benchmark.cpp index b66c3f228c..378ea705f1 100644 --- a/benchmark/api/render.benchmark.cpp +++ b/benchmark/api/render.benchmark.cpp @@ -45,8 +45,8 @@ static void prepare(Map& map, optional json = {}) { static void API_renderStill_reuse_map(::benchmark::State& state) { RenderBenchmark bench; HeadlessFrontend frontend { size, pixelRatio, bench.threadPool }; - Map map { frontend, MapObserver::nullObserver(), size, pixelRatio, bench.threadPool, - MapOptions().withMapMode(MapMode::Static), + Map map { frontend, MapObserver::nullObserver(), pixelRatio, bench.threadPool, + MapOptions().withMapMode(MapMode::Static).withSize(size), ResourceOptions().withCachePath(cachePath).withAccessToken("foobar") }; prepare(map); @@ -58,8 +58,8 @@ static void API_renderStill_reuse_map(::benchmark::State& state) { static void API_renderStill_reuse_map_formatted_labels(::benchmark::State& state) { RenderBenchmark bench; HeadlessFrontend frontend { size, pixelRatio, bench.threadPool }; - Map map { frontend, MapObserver::nullObserver(), size, pixelRatio, bench.threadPool, - MapOptions().withMapMode(MapMode::Static), ResourceOptions().withCachePath(cachePath).withAccessToken("foobar") }; + Map map { frontend, MapObserver::nullObserver(), pixelRatio, bench.threadPool, + MapOptions().withMapMode(MapMode::Static).withSize(size), ResourceOptions().withCachePath(cachePath).withAccessToken("foobar") }; prepare(map, util::read_file("benchmark/fixtures/api/style_formatted_labels.json")); while (state.KeepRunning()) { @@ -70,8 +70,8 @@ static void API_renderStill_reuse_map_formatted_labels(::benchmark::State& state static void API_renderStill_reuse_map_switch_styles(::benchmark::State& state) { RenderBenchmark bench; HeadlessFrontend frontend { size, pixelRatio, bench.threadPool }; - Map map { frontend, MapObserver::nullObserver(), size, pixelRatio, bench.threadPool, - MapOptions().withMapMode(MapMode::Static), ResourceOptions().withCachePath(cachePath).withAccessToken("foobar") }; + Map map { frontend, MapObserver::nullObserver(), pixelRatio, bench.threadPool, + MapOptions().withMapMode(MapMode::Static).withSize(size), ResourceOptions().withCachePath(cachePath).withAccessToken("foobar") }; while (state.KeepRunning()) { prepare(map, { "{}" }); @@ -86,8 +86,8 @@ static void API_renderStill_recreate_map(::benchmark::State& state) { while (state.KeepRunning()) { HeadlessFrontend frontend { size, pixelRatio, bench.threadPool }; - Map map { frontend, MapObserver::nullObserver(), size, pixelRatio, bench.threadPool, - MapOptions().withMapMode(MapMode::Static), ResourceOptions().withCachePath(cachePath).withAccessToken("foobar") }; + Map map { frontend, MapObserver::nullObserver(), pixelRatio, bench.threadPool, + MapOptions().withMapMode(MapMode::Static).withSize(size), ResourceOptions().withCachePath(cachePath).withAccessToken("foobar") }; prepare(map); frontend.render(map); } diff --git a/bin/render.cpp b/bin/render.cpp index c22d551928..03d1e86144 100644 --- a/bin/render.cpp +++ b/bin/render.cpp @@ -78,8 +78,8 @@ int main(int argc, char *argv[]) { ThreadPool threadPool(4); HeadlessFrontend frontend({ width, height }, pixelRatio, threadPool); - Map map(frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio, threadPool, - MapOptions().withMapMode(MapMode::Static), + Map map(frontend, MapObserver::nullObserver(), pixelRatio, threadPool, + MapOptions().withMapMode(MapMode::Static).withSize(frontend.getSize()), ResourceOptions().withCachePath(cache_file).withAssetPath(asset_root).withAccessToken(std::string(token))); if (style.find("://") == std::string::npos) { diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 9134272ea7..822c400ddf 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -34,7 +34,6 @@ class Map : private util::noncopyable { public: explicit Map(RendererFrontend&, MapObserver&, - Size size, float pixelRatio, Scheduler&, const MapOptions&, @@ -91,16 +90,13 @@ public: void setNorthOrientation(NorthOrientation); void setConstrainMode(ConstrainMode); void setViewportMode(ViewportMode); + void setSize(Size); MapOptions getMapOptions() const; //Projection Mode void setProjectionMode(const ProjectionMode&); ProjectionMode getProjectionMode() const; - // Size - void setSize(Size); - Size getSize() const; - // Projection ScreenCoordinate pixelForLatLng(const LatLng&) const; LatLng latLngForPixel(const ScreenCoordinate&) const; diff --git a/include/mbgl/map/map_options.hpp b/include/mbgl/map/map_options.hpp index 8d5c12b96c..508d569ea5 100644 --- a/include/mbgl/map/map_options.hpp +++ b/include/mbgl/map/map_options.hpp @@ -2,6 +2,7 @@ #include #include +#include #include @@ -103,6 +104,21 @@ public: */ NorthOrientation northOrientation() const; + /** + * @brief Sets the size to resize the map object and renderer backend. + * + * @param size_ A size given in logical pixels. + * @return reference to MapOptions for chaining options together. + */ + MapOptions& withSize(Size size_); + + /** + * @brief Gets the previously set size. + * + * @return Size. + */ + Size size() const; + private: class Impl; std::unique_ptr impl_; diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp index 1eb4c56728..d30a216353 100755 --- a/platform/android/src/native_map_view.cpp +++ b/platform/android/src/native_map_view.cpp @@ -81,14 +81,15 @@ NativeMapView::NativeMapView(jni::JNIEnv& _env, // Create Map options MapOptions options; options.withMapMode(MapMode::Continuous) + .withSize(mbgl::Size{ static_cast(width), static_cast(height) }) .withConstrainMode(ConstrainMode::HeightOnly) .withViewportMode(ViewportMode::Default) .withCrossSourceCollisions(_crossSourceCollisions); // Create the core map map = std::make_unique( - *rendererFrontend, *this, mbgl::Size{ static_cast(width), static_cast(height) }, - pixelRatio, *threadPool, options, mbgl::android::FileSource::getSharedResourceOptions(_env, jFileSource)); + *rendererFrontend, *this, pixelRatio, *threadPool, options, + mbgl::android::FileSource::getSharedResourceOptions(_env, jFileSource)); } /** 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) { diff --git a/platform/glfw/main.cpp b/platform/glfw/main.cpp index c27e5fe8ce..9f87e579a7 100644 --- a/platform/glfw/main.cpp +++ b/platform/glfw/main.cpp @@ -110,7 +110,7 @@ int main(int argc, char *argv[]) { mbgl::ThreadPool threadPool(4); GLFWRendererFrontend rendererFrontend { std::make_unique(backend, view->getPixelRatio(), threadPool), backend }; - mbgl::Map map(rendererFrontend, backend, view->getSize(), view->getPixelRatio(), threadPool, mbgl::MapOptions(), resourceOptions); + mbgl::Map map(rendererFrontend, backend, view->getPixelRatio(), threadPool, mbgl::MapOptions().withSize(view->getSize()), resourceOptions); backend.setMap(&map); diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index f885f67a10..036cfd5756 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -479,6 +479,7 @@ public: mbgl::MapOptions mapOptions; mapOptions.withMapMode(mbgl::MapMode::Continuous) + .withSize(self.size) .withConstrainMode(mbgl::ConstrainMode::None) .withViewportMode(mbgl::ViewportMode::Default) .withCrossSourceCollisions(enableCrossSourceCollisions); @@ -488,7 +489,7 @@ public: .withAssetPath([NSBundle mainBundle].resourceURL.path.UTF8String); NSAssert(!_mbglMap, @"_mbglMap should be NULL"); - _mbglMap = new mbgl::Map(*_rendererFrontend, *_mbglView, self.size, config.scaleFactor, *_mbglThreadPool, mapOptions, resourceOptions); + _mbglMap = new mbgl::Map(*_rendererFrontend, *_mbglView, config.scaleFactor, *_mbglThreadPool, mapOptions, resourceOptions); // start paused if in IB if (_isTargetingInterfaceBuilder || background) { diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm index c5d3279c81..fdcc2090b1 100644 --- a/platform/macos/src/MGLMapView.mm +++ b/platform/macos/src/MGLMapView.mm @@ -292,6 +292,7 @@ public: mbgl::MapOptions mapOptions; mapOptions.withMapMode(mbgl::MapMode::Continuous) + .withSize(self.size) .withConstrainMode(mbgl::ConstrainMode::None) .withViewportMode(mbgl::ViewportMode::Default) .withCrossSourceCollisions(enableCrossSourceCollisions); @@ -300,7 +301,7 @@ public: resourceOptions.withCachePath([[MGLOfflineStorage sharedOfflineStorage] mbglCachePath]) .withAssetPath([NSBundle mainBundle].resourceURL.path.UTF8String); - _mbglMap = new mbgl::Map(*_rendererFrontend, *_mbglView, self.size, config.scaleFactor, *_mbglThreadPool, mapOptions, resourceOptions); + _mbglMap = new mbgl::Map(*_rendererFrontend, *_mbglView, config.scaleFactor, *_mbglThreadPool, mapOptions, resourceOptions); // Install the OpenGL layer. Interface Builder’s synchronous drawing means // we can’t display a map, so don’t even bother to have a map layer. diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp index 7ad9c362bf..bcd5fb1c16 100644 --- a/platform/node/src/node_map.cpp +++ b/platform/node/src/node_map.cpp @@ -631,8 +631,10 @@ void NodeMap::cancel() { }); frontend = std::make_unique(mbgl::Size{ 256, 256 }, pixelRatio, threadpool); - map = std::make_unique(*frontend, mapObserver, frontend->getSize(), pixelRatio, threadpool, - mbgl::MapOptions().withMapMode(mode).withCrossSourceCollisions(crossSourceCollisions), + map = std::make_unique(*frontend, mapObserver, pixelRatio, threadpool, + mbgl::MapOptions().withSize(frontend->getSize()) + .withMapMode(mode) + .withCrossSourceCollisions(crossSourceCollisions), mbgl::ResourceOptions().withPlatformContext(reinterpret_cast(this))); // FIXME: Reload the style after recreating the map. We need to find @@ -1212,8 +1214,10 @@ NodeMap::NodeMap(v8::Local options) }()) , mapObserver(NodeMapObserver()) , frontend(std::make_unique(mbgl::Size { 256, 256 }, pixelRatio, threadpool)) - , map(std::make_unique(*frontend, mapObserver, frontend->getSize(), pixelRatio, threadpool, - mbgl::MapOptions().withMapMode(mode).withCrossSourceCollisions(crossSourceCollisions), + , map(std::make_unique(*frontend, mapObserver, pixelRatio, threadpool, + mbgl::MapOptions().withSize(frontend->getSize()) + .withMapMode(mode) + .withCrossSourceCollisions(crossSourceCollisions), mbgl::ResourceOptions().withPlatformContext(reinterpret_cast(this)))) , async(new uv_async_t) { async->data = this; diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp index 313860890c..ff6a4498dc 100644 --- a/platform/qt/src/qmapboxgl.cpp +++ b/platform/qt/src/qmapboxgl.cpp @@ -1127,7 +1127,7 @@ void QMapboxGL::resize(const QSize& size_) { auto size = sanitizedSize(size_); - if (d_ptr->mapObj->getSize() == size) + if (d_ptr->mapObj->getMapOptions().size() == size) return; d_ptr->mapObj->setSize(size); @@ -1705,8 +1705,9 @@ void QMapboxGL::connectionEstablished() \a copyrightsHtml is a string with a HTML snippet. */ -mbgl::MapOptions mapOptionsFromQMapboxGLSettings(const QMapboxGLSettings &settings) { +mbgl::MapOptions mapOptionsFromQMapboxGLSettings(const QMapboxGLSettings &settings, const QSize &size) { return std::move(mbgl::MapOptions() + .withSize(sanitizedSize(size)) .withMapMode(static_cast(settings.mapMode())) .withConstrainMode(static_cast(settings.constrainMode())) .withViewportMode(static_cast(settings.viewportMode()))); @@ -1740,8 +1741,8 @@ QMapboxGLPrivate::QMapboxGLPrivate(QMapboxGL *q, const QMapboxGLSettings &settin auto resourceOptions = resourceOptionsFromQMapboxGLSettings(settings); // Setup the Map object. - mapObj = std::make_unique(*this, *m_mapObserver, sanitizedSize(size), m_pixelRatio, *m_threadPool, - mapOptionsFromQMapboxGLSettings(settings), resourceOptions); + mapObj = std::make_unique(*this, *m_mapObserver, m_pixelRatio, *m_threadPool, + mapOptionsFromQMapboxGLSettings(settings, size), resourceOptions); if (settings.resourceTransform()) { m_resourceTransform = std::make_unique>(*mbgl::Scheduler::GetCurrent(), diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 06c637b232..cfec9952b5 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -29,12 +29,11 @@ using namespace style; Map::Map(RendererFrontend& frontend, MapObserver& observer, - const Size size, const float pixelRatio, Scheduler& scheduler, const MapOptions& mapOptions, const ResourceOptions& resourceOptions) - : impl(std::make_unique(frontend, observer, scheduler, size, pixelRatio, + : impl(std::make_unique(frontend, observer, scheduler, pixelRatio, FileSource::getSharedFileSource(resourceOptions), mapOptions)) {} Map::Map(std::unique_ptr impl_) : impl(std::move(impl_)) {} @@ -308,47 +307,36 @@ BoundOptions Map::getBounds() const { .withMaxZoom(impl->transform.getState().getMaxZoom()); } -#pragma mark - Size +#pragma mark - Map options void Map::setSize(const Size size) { impl->transform.resize(size); impl->onUpdate(); } -Size Map::getSize() const { - return impl->transform.getState().getSize(); -} - -#pragma mark - North Orientation - void Map::setNorthOrientation(NorthOrientation orientation) { impl->transform.setNorthOrientation(orientation); impl->onUpdate(); } -#pragma mark - Constrain mode - void Map::setConstrainMode(mbgl::ConstrainMode mode) { impl->transform.setConstrainMode(mode); impl->onUpdate(); } -#pragma mark - Viewport mode - void Map::setViewportMode(mbgl::ViewportMode mode) { impl->transform.setViewportMode(mode); impl->onUpdate(); } -#pragma mark - Map options - MapOptions Map::getMapOptions() const { return std::move(MapOptions() .withMapMode(impl->mode) .withConstrainMode(impl->transform.getConstrainMode()) .withViewportMode(impl->transform.getViewportMode()) .withCrossSourceCollisions(impl->crossSourceCollisions) - .withNorthOrientation(impl->transform.getNorthOrientation())); + .withNorthOrientation(impl->transform.getNorthOrientation()) + .withSize(impl->transform.getState().getSize())); } #pragma mark - Projection mode diff --git a/src/mbgl/map/map_impl.cpp b/src/mbgl/map/map_impl.cpp index cdc8c231e4..afaa05229c 100644 --- a/src/mbgl/map/map_impl.cpp +++ b/src/mbgl/map/map_impl.cpp @@ -10,7 +10,6 @@ namespace mbgl { Map::Impl::Impl(RendererFrontend& frontend_, MapObserver& observer_, Scheduler& scheduler_, - Size size_, float pixelRatio_, std::shared_ptr fileSource_, const MapOptions& mapOptions) @@ -27,7 +26,7 @@ Map::Impl::Impl(RendererFrontend& frontend_, transform.setNorthOrientation(mapOptions.northOrientation()); style->impl->setObserver(this); rendererFrontend.setObserver(*this); - transform.resize(size_); + transform.resize(mapOptions.size()); } Map::Impl::~Impl() { diff --git a/src/mbgl/map/map_impl.hpp b/src/mbgl/map/map_impl.hpp index 13ffdc02ae..90b0a721ca 100644 --- a/src/mbgl/map/map_impl.hpp +++ b/src/mbgl/map/map_impl.hpp @@ -30,7 +30,7 @@ struct StillImageRequest { class Map::Impl : public style::Observer, public RendererObserver { public: - Impl(RendererFrontend&, MapObserver&, Scheduler&, Size size, float pixelRatio, std::shared_ptr, const MapOptions&); + Impl(RendererFrontend&, MapObserver&, Scheduler&, float pixelRatio, std::shared_ptr, const MapOptions&); ~Impl() final; // StyleObserver diff --git a/src/mbgl/map/map_options.cpp b/src/mbgl/map/map_options.cpp index b4ad38ac7f..98cabb2550 100644 --- a/src/mbgl/map/map_options.cpp +++ b/src/mbgl/map/map_options.cpp @@ -9,6 +9,7 @@ public: ViewportMode viewportMode = ViewportMode::Default; NorthOrientation orientation = NorthOrientation::Upwards; bool crossSourceCollisions = true; + Size size; }; // These requires the complete type of Impl. @@ -61,4 +62,13 @@ NorthOrientation MapOptions::northOrientation() const { return impl_->orientation; } +MapOptions& MapOptions::withSize(Size size_) { + impl_->size = size_; + return *this; +} + +Size MapOptions::size() const { + return impl_->size; +} + } // namespace mbgl diff --git a/test/api/annotations.test.cpp b/test/api/annotations.test.cpp index 2a9737e10b..612c4f0ab8 100644 --- a/test/api/annotations.test.cpp +++ b/test/api/annotations.test.cpp @@ -32,8 +32,8 @@ public: float pixelRatio { 1 }; HeadlessFrontend frontend { pixelRatio, threadPool }; - MapAdapter map { frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio, std::make_shared(), - threadPool, MapOptions().withMapMode(MapMode::Static)}; + MapAdapter map { frontend, MapObserver::nullObserver(), pixelRatio, std::make_shared(), + threadPool, MapOptions().withMapMode(MapMode::Static).withSize(frontend.getSize())}; void checkRendering(const char * name) { test::checkImage(std::string("test/fixtures/annotations/") + name, diff --git a/test/api/api_misuse.test.cpp b/test/api/api_misuse.test.cpp index 6fc04ab26f..17eb2de14b 100644 --- a/test/api/api_misuse.test.cpp +++ b/test/api/api_misuse.test.cpp @@ -25,9 +25,9 @@ TEST(API, RenderWithoutCallback) { float pixelRatio { 1 }; HeadlessFrontend frontend { pixelRatio, threadPool }; - auto map = std::make_unique(frontend, MapObserver::nullObserver(), frontend.getSize(), + auto map = std::make_unique(frontend, MapObserver::nullObserver(), pixelRatio, std::make_shared(), threadPool, - MapOptions().withMapMode(MapMode::Static)); + MapOptions().withMapMode(MapMode::Static).withSize(frontend.getSize())); map->renderStill(nullptr); // Force Map thread to join. diff --git a/test/api/custom_geometry_source.test.cpp b/test/api/custom_geometry_source.test.cpp index 58af09c1ac..679291372d 100644 --- a/test/api/custom_geometry_source.test.cpp +++ b/test/api/custom_geometry_source.test.cpp @@ -23,8 +23,8 @@ TEST(CustomGeometrySource, Grid) { auto threadPool = sharedThreadPool(); float pixelRatio { 1 }; HeadlessFrontend frontend { pixelRatio, *threadPool }; - Map map(frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio, *threadPool, - MapOptions().withMapMode(MapMode::Static), + Map map(frontend, MapObserver::nullObserver(), pixelRatio, *threadPool, + MapOptions().withMapMode(MapMode::Static).withSize(frontend.getSize()), ResourceOptions().withCachePath(":memory:").withAssetPath("test/fixtures/api/assets")); map.getStyle().loadJSON(util::read_file("test/fixtures/api/water.json")); map.jumpTo(CameraOptions().withCenter(LatLng { 37.8, -122.5 }).withZoom(10.0)); diff --git a/test/api/custom_layer.test.cpp b/test/api/custom_layer.test.cpp index e16d2852ec..4f1429d637 100644 --- a/test/api/custom_layer.test.cpp +++ b/test/api/custom_layer.test.cpp @@ -93,8 +93,8 @@ TEST(CustomLayer, Basic) { ThreadPool threadPool(4); float pixelRatio { 1 }; HeadlessFrontend frontend { pixelRatio, threadPool }; - Map map(frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio, threadPool, - MapOptions().withMapMode(MapMode::Static), + Map map(frontend, MapObserver::nullObserver(), pixelRatio, threadPool, + MapOptions().withMapMode(MapMode::Static).withSize(frontend.getSize()), ResourceOptions().withCachePath(":memory:").withAssetPath("test/fixtures/api/assets")); map.getStyle().loadJSON(util::read_file("test/fixtures/api/water.json")); map.jumpTo(CameraOptions().withCenter(LatLng { 37.8, -122.5 }).withZoom(10.0)); diff --git a/test/api/query.test.cpp b/test/api/query.test.cpp index b4297bfe82..0dd9882be2 100644 --- a/test/api/query.test.cpp +++ b/test/api/query.test.cpp @@ -38,8 +38,8 @@ public: ThreadPool threadPool { 4 }; float pixelRatio { 1 }; HeadlessFrontend frontend { pixelRatio, threadPool }; - MapAdapter map { frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio, fileSource, - threadPool, MapOptions().withMapMode(MapMode::Static)}; + MapAdapter map { frontend, MapObserver::nullObserver(), pixelRatio, fileSource, + threadPool, MapOptions().withMapMode(MapMode::Static).withSize(frontend.getSize())}; }; std::vector getTopClusterFeature(QueryTest& test) { diff --git a/test/api/recycle_map.cpp b/test/api/recycle_map.cpp index 7d14bd14de..6f1560d463 100644 --- a/test/api/recycle_map.cpp +++ b/test/api/recycle_map.cpp @@ -27,9 +27,9 @@ TEST(API, RecycleMapUpdateImages) { float pixelRatio { 1 }; HeadlessFrontend frontend { pixelRatio, threadPool }; - auto map = std::make_unique(frontend, MapObserver::nullObserver(), frontend.getSize(), + auto map = std::make_unique(frontend, MapObserver::nullObserver(), pixelRatio, std::make_shared(), threadPool, - MapOptions().withMapMode(MapMode::Static)); + MapOptions().withMapMode(MapMode::Static).withSize(frontend.getSize())); EXPECT_TRUE(map); diff --git a/test/gl/context.test.cpp b/test/gl/context.test.cpp index ff9b2ecac2..d9b2750a95 100644 --- a/test/gl/context.test.cpp +++ b/test/gl/context.test.cpp @@ -91,8 +91,8 @@ TEST(GLContextMode, Shared) { HeadlessFrontend frontend { pixelRatio, threadPool, {}, GLContextMode::Shared }; - Map map(frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio, threadPool, - MapOptions().withMapMode(MapMode::Static), + Map map(frontend, MapObserver::nullObserver(), pixelRatio, threadPool, + MapOptions().withMapMode(MapMode::Static).withSize(frontend.getSize()), ResourceOptions().withCachePath(":memory:").withAssetPath("test/fixtures/api/assets")); map.getStyle().loadJSON(util::read_file("test/fixtures/api/water.json")); map.jumpTo(CameraOptions().withCenter(LatLng { 37.8, -122.5 }).withZoom(10.0)); diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp index fc8a7bffba..c50b66efaf 100644 --- a/test/map/map.test.cpp +++ b/test/map/map.test.cpp @@ -41,8 +41,8 @@ public: MapTest(float pixelRatio = 1, MapMode mode = MapMode::Static) : fileSource(std::make_shared()) , frontend(pixelRatio, threadPool) - , map(frontend, observer, frontend.getSize(), pixelRatio, - fileSource, threadPool, MapOptions().withMapMode(mode)) {} + , map(frontend, observer, pixelRatio, + fileSource, threadPool, MapOptions().withMapMode(mode).withSize(frontend.getSize())) {} template MapTest(const std::string& cachePath, const std::string& assetPath, @@ -50,8 +50,8 @@ public: typename std::enable_if::value>::type* = 0) : fileSource(std::make_shared(cachePath, assetPath)) , frontend(pixelRatio, threadPool) - , map(frontend, observer, frontend.getSize(), pixelRatio, - fileSource, threadPool, MapOptions().withMapMode(mode)) {} + , map(frontend, observer, pixelRatio, + fileSource, threadPool, MapOptions().withMapMode(mode).withSize(frontend.getSize())) {} }; TEST(Map, RendererState) { @@ -85,7 +85,7 @@ TEST(Map, RendererState) { const ScreenCoordinate& point = test.frontend.pixelForLatLng(coordinate); EXPECT_NEAR(coordinate.latitude(), latLng.latitude(), 1e-1); EXPECT_NEAR(coordinate.longitude(), latLng.longitude(), 1e-1); - const Size size = test.map.getSize(); + const Size size = test.map.getMapOptions().size(); EXPECT_NEAR(point.x, size.width / 2.0, 1e-7); EXPECT_NEAR(point.y, size.height / 2.0, 1e-7); } @@ -221,9 +221,10 @@ TEST(Map, CameraToLatLngBounds) { test.map.jumpTo(CameraOptions().withCenter(LatLng { 45, 90 }).withZoom(16.0)); + const Size size = test.map.getMapOptions().size(); LatLngBounds bounds = LatLngBounds::hull( test.map.latLngForPixel({}), - test.map.latLngForPixel({ double(test.map.getSize().width), double(test.map.getSize().height) })); + test.map.latLngForPixel({ double(size.width), double(size.height) })); CameraOptions camera = test.map.getCameraOptions(); @@ -734,8 +735,8 @@ TEST(Map, TEST_DISABLED_ON_CI(ContinuousRendering)) { }); }; - Map map(frontend, observer, frontend.getSize(), pixelRatio, threadPool, - MapOptions().withMapMode(MapMode::Continuous), + Map map(frontend, observer, pixelRatio, threadPool, + MapOptions().withMapMode(MapMode::Continuous).withSize(frontend.getSize()), ResourceOptions().withCachePath(":memory:").withAssetPath("test/fixtures/api/assets")); map.getStyle().loadJSON(util::read_file("test/fixtures/api/water.json")); diff --git a/test/map/prefetch.test.cpp b/test/map/prefetch.test.cpp index 2830045983..520228e010 100644 --- a/test/map/prefetch.test.cpp +++ b/test/map/prefetch.test.cpp @@ -37,8 +37,8 @@ TEST(Map, PrefetchTiles) { }; HeadlessFrontend frontend { { 512, 512 }, 1, threadPool }; - MapAdapter map(frontend, observer, frontend.getSize(), 1, fileSource, threadPool, - MapOptions().withMapMode(MapMode::Continuous)); + MapAdapter map(frontend, observer, 1, fileSource, threadPool, + MapOptions().withMapMode(MapMode::Continuous).withSize(frontend.getSize())); std::vector tiles; diff --git a/test/src/mbgl/test/map_adapter.hpp b/test/src/mbgl/test/map_adapter.hpp index e0fc449f48..67abea953d 100644 --- a/test/src/mbgl/test/map_adapter.hpp +++ b/test/src/mbgl/test/map_adapter.hpp @@ -12,12 +12,11 @@ class MapAdapter : public Map { public: explicit MapAdapter(RendererFrontend& frontend, MapObserver& observer, - Size size, float ratio, std::shared_ptr fileSource, Scheduler& scheduler, const MapOptions& options) - : Map(std::make_unique(frontend, observer, scheduler, size, ratio, std::move(fileSource), options)) {} + : Map(std::make_unique(frontend, observer, scheduler, ratio, std::move(fileSource), options)) {} }; } // namespace mbgl diff --git a/test/text/local_glyph_rasterizer.test.cpp b/test/text/local_glyph_rasterizer.test.cpp index a266021f25..ac272e2f9f 100644 --- a/test/text/local_glyph_rasterizer.test.cpp +++ b/test/text/local_glyph_rasterizer.test.cpp @@ -43,8 +43,8 @@ public: ThreadPool threadPool { 4 }; float pixelRatio { 1 }; HeadlessFrontend frontend; - MapAdapter map { frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio, fileSource, - threadPool, MapOptions().withMapMode(MapMode::Static)}; + MapAdapter map { frontend, MapObserver::nullObserver(), pixelRatio, fileSource, + threadPool, MapOptions().withMapMode(MapMode::Static).withSize(frontend.getSize())}; void checkRendering(const char * name) { test::checkImage(std::string("test/fixtures/local_glyphs/") + name, diff --git a/test/util/memory.test.cpp b/test/util/memory.test.cpp index c1ae597986..03545c648b 100644 --- a/test/util/memory.test.cpp +++ b/test/util/memory.test.cpp @@ -73,8 +73,8 @@ TEST(Memory, Vector) { float ratio { 2 }; HeadlessFrontend frontend { { 256, 256 }, ratio, test.threadPool }; - MapAdapter map(frontend, MapObserver::nullObserver(), frontend.getSize(), ratio, test.fileSource, - test.threadPool, MapOptions().withMapMode(MapMode::Static)); + MapAdapter map(frontend, MapObserver::nullObserver(), ratio, test.fileSource, + test.threadPool, MapOptions().withMapMode(MapMode::Static).withSize(frontend.getSize())); map.jumpTo(CameraOptions().withZoom(16)); map.getStyle().loadURL("mapbox://streets"); @@ -86,8 +86,8 @@ TEST(Memory, Raster) { float ratio { 2 }; HeadlessFrontend frontend { { 256, 256 }, ratio, test.threadPool }; - MapAdapter map(frontend, MapObserver::nullObserver(), frontend.getSize(), ratio, test.fileSource, - test.threadPool, MapOptions().withMapMode(MapMode::Static)); + MapAdapter map(frontend, MapObserver::nullObserver(), ratio, test.fileSource, + test.threadPool, MapOptions().withMapMode(MapMode::Static).withSize(frontend.getSize())); map.getStyle().loadURL("mapbox://satellite"); frontend.render(map); @@ -124,8 +124,8 @@ TEST(Memory, Footprint) { public: FrontendAndMap(MemoryTest& test_, const char* style) : frontend(Size{ 256, 256 }, 2, test_.threadPool) - , map(frontend, MapObserver::nullObserver(), frontend.getSize(), 2, test_.fileSource - , test_.threadPool, MapOptions().withMapMode(MapMode::Static)) { + , map(frontend, MapObserver::nullObserver(), 2, test_.fileSource + , test_.threadPool, MapOptions().withMapMode(MapMode::Static).withSize(frontend.getSize())) { map.jumpTo(CameraOptions().withZoom(16)); map.getStyle().loadURL(style); frontend.render(map); -- cgit v1.2.1