From d735d89835fb3076e09594fce2a141fe1495e33f Mon Sep 17 00:00:00 2001 From: Chris Loer Date: Thu, 6 Sep 2018 14:58:37 -0700 Subject: [core] Port "collision group" plumbing to gl-native. [node] Hook up map-wide "crossSourceCollisions" option, defaulting to true. [test] Pass "crossSourceCollisions" test option through test harness; enable cross-source-collisions tests on native. --- include/mbgl/map/map.hpp | 3 ++- platform/node/CHANGELOG.md | 1 + platform/node/src/node_map.cpp | 18 ++++++++++++-- platform/node/src/node_map.hpp | 1 + platform/node/test/ignores.json | 2 -- platform/node/test/suite_implementation.js | 8 +++--- src/mbgl/geometry/feature_index.hpp | 5 +++- src/mbgl/map/map.cpp | 17 +++++++++---- src/mbgl/renderer/renderer_impl.cpp | 4 +-- src/mbgl/renderer/update_parameters.hpp | 2 ++ src/mbgl/text/collision_index.cpp | 34 ++++++++++++++++++-------- src/mbgl/text/collision_index.hpp | 8 +++--- src/mbgl/text/placement.cpp | 39 ++++++++++++++++++++++++------ src/mbgl/text/placement.hpp | 24 ++++++++++++++++-- src/mbgl/tile/geometry_tile.hpp | 4 +-- src/mbgl/util/grid_index.cpp | 24 ++++++++++++------ src/mbgl/util/grid_index.hpp | 5 ++-- 17 files changed, 149 insertions(+), 50 deletions(-) diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 3aee932070..ca6c62d280 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -37,7 +37,8 @@ public: Scheduler&, MapMode mapMode = MapMode::Continuous, ConstrainMode constrainMode = ConstrainMode::HeightOnly, - ViewportMode viewportMode = ViewportMode::Default); + ViewportMode viewportMode = ViewportMode::Default, + bool crossSourceCollisions = true); ~Map(); // Register a callback that will get called (on the render thread) when all resources have diff --git a/platform/node/CHANGELOG.md b/platform/node/CHANGELOG.md index 5b44d5be1f..fc8d2afe7b 100644 --- a/platform/node/CHANGELOG.md +++ b/platform/node/CHANGELOG.md @@ -6,6 +6,7 @@ - Remove unnecessary memory use when collision debug mode is not enabled ([#12294](https://github.com/mapbox/mapbox-gl-native/issues/12294)) - Added support for rendering `symbol-placement: line-center` ([#12337](https://github.com/mapbox/mapbox-gl-native/pull/12337)) - Add support for feature expressions in `line-pattern`, `fill-pattern`, and `fill-extrusion-pattern` properties. [#12284](https://github.com/mapbox/mapbox-gl-native/pull/12284) +- Add `crossSourceCollisions` map option, with default of `true`. When set to `false`, cross-source collision detection is disabled. ([#12820] (https://github.com/mapbox/mapbox-gl-native/issues/12820)) # 3.5.8 - October 19, 2017 - Fixes an issue that causes memory leaks when not deleting the frontend object diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp index 7dbccfcf41..e32c576e14 100644 --- a/platform/node/src/node_map.cpp +++ b/platform/node/src/node_map.cpp @@ -621,7 +621,10 @@ void NodeMap::cancel() { frontend = std::make_unique(mbgl::Size{ 256, 256 }, pixelRatio, *this, threadpool); map = std::make_unique(*frontend, mapObserver, frontend->getSize(), pixelRatio, - *this, threadpool, mode); + *this, threadpool, mode, + mbgl::ConstrainMode::HeightOnly, + mbgl::ViewportMode::Default, + crossSourceCollisions); // FIXME: Reload the style after recreating the map. We need to find // a better way of canceling an ongoing rendering on the core level @@ -1212,6 +1215,14 @@ NodeMap::NodeMap(v8::Local options) return mbgl::MapMode::Static; } }()) + , crossSourceCollisions([&] { + Nan::HandleScope scope; + return Nan::Has(options, Nan::New("crossSourceCollisions").ToLocalChecked()).FromJust() + ? Nan::Get(options, Nan::New("crossSourceCollisions").ToLocalChecked()) + .ToLocalChecked() + ->BooleanValue() + : true; + }()) , mapObserver(NodeMapObserver()) , frontend(std::make_unique(mbgl::Size { 256, 256 }, pixelRatio, *this, threadpool)) , map(std::make_unique(*frontend, @@ -1220,7 +1231,10 @@ NodeMap::NodeMap(v8::Local options) pixelRatio, *this, threadpool, - mode)), + mode, + mbgl::ConstrainMode::HeightOnly, + mbgl::ViewportMode::Default, + crossSourceCollisions)), async(new uv_async_t) { async->data = this; diff --git a/platform/node/src/node_map.hpp b/platform/node/src/node_map.hpp index 52fc1ef659..b83a238681 100644 --- a/platform/node/src/node_map.hpp +++ b/platform/node/src/node_map.hpp @@ -82,6 +82,7 @@ public: const float pixelRatio; mbgl::MapMode mode; + bool crossSourceCollisions; NodeThreadPool threadpool; NodeMapObserver mapObserver; std::unique_ptr frontend; diff --git a/platform/node/test/ignores.json b/platform/node/test/ignores.json index d2ec3644d9..67f0ff9a72 100644 --- a/platform/node/test/ignores.json +++ b/platform/node/test/ignores.json @@ -95,7 +95,6 @@ "render-tests/geojson/inline-linestring-fill": "current behavior is arbitrary", "render-tests/geojson/inline-polygon-symbol": "behavior needs reconciliation with gl-js", "render-tests/icon-rotate/with-offset": "https://github.com/mapbox/mapbox-gl-native/issues/11872", - "render-tests/icon-no-cross-source-collision/default": "skip - gl-js only", "render-tests/mixed-zoom/z10-z11": "https://github.com/mapbox/mapbox-gl-native/issues/10397", "render-tests/raster-masking/overlapping-zoom": "https://github.com/mapbox/mapbox-gl-native/issues/10195", "render-tests/real-world/bangkok": "https://github.com/mapbox/mapbox-gl-native/issues/10412", @@ -122,7 +121,6 @@ "render-tests/text-field/formatted-arabic": "skip - https://github.com/mapbox/mapbox-gl-native/pull/12624", "render-tests/text-field/formatted-line": "skip - https://github.com/mapbox/mapbox-gl-native/pull/12624", "render-tests/text-field/formatted": "skip - https://github.com/mapbox/mapbox-gl-native/pull/12624", - "render-tests/text-no-cross-source-collision/default": "skip - gl-js only", "render-tests/text-pitch-alignment/auto-text-rotation-alignment-map": "https://github.com/mapbox/mapbox-gl-native/issues/9732", "render-tests/text-pitch-alignment/map-text-rotation-alignment-map": "https://github.com/mapbox/mapbox-gl-native/issues/9732", "render-tests/text-pitch-alignment/viewport-text-rotation-alignment-map": "https://github.com/mapbox/mapbox-gl-native/issues/9732", diff --git a/platform/node/test/suite_implementation.js b/platform/node/test/suite_implementation.js index 704cab8940..f868af8ece 100644 --- a/platform/node/test/suite_implementation.js +++ b/platform/node/test/suite_implementation.js @@ -16,7 +16,7 @@ export default function (style, options, callback) { let map; if (options.recycleMap) { - const key = options.pixelRatio + '/' + tileMode; + const key = options.pixelRatio + '/' + tileMode + '/' + options.crossSourceCollisions; if (maps.has(key)) { map = maps.get(key); map.request = mapRequest; @@ -24,7 +24,8 @@ export default function (style, options, callback) { maps.set(key, new mbgl.Map({ ratio: options.pixelRatio, request: mapRequest, - mode: options.mapMode + mode: options.mapMode, + crossSourceCollisions: typeof options.crossSourceCollisions === "undefined" ? true : options.crossSourceCollisions })); map = maps.get(key); } @@ -32,7 +33,8 @@ export default function (style, options, callback) { map = new mbgl.Map({ ratio: options.pixelRatio, request: mapRequest, - mode: options.mapMode + mode: options.mapMode, + crossSourceCollisions: typeof options.crossSourceCollisions === "undefined" ? true : options.crossSourceCollisions }); } diff --git a/src/mbgl/geometry/feature_index.hpp b/src/mbgl/geometry/feature_index.hpp index 739c1f282f..cd041a7fdb 100644 --- a/src/mbgl/geometry/feature_index.hpp +++ b/src/mbgl/geometry/feature_index.hpp @@ -28,15 +28,17 @@ public: , bucketLeaderID(std::move(bucketName_)) , sortIndex(sortIndex_) , bucketInstanceId(0) + , collisionGroupId(0) {} - IndexedSubfeature(const IndexedSubfeature& other, uint32_t bucketInstanceId_) + IndexedSubfeature(const IndexedSubfeature& other, uint32_t bucketInstanceId_, uint16_t collisionGroupId_) : index(other.index) , sourceLayerName(other.sourceLayerName) , bucketLeaderID(other.bucketLeaderID) , sortIndex(other.sortIndex) , bucketInstanceId(bucketInstanceId_) + , collisionGroupId(collisionGroupId_) {} size_t index; std::string sourceLayerName; @@ -45,6 +47,7 @@ public: // Only used for symbol features uint32_t bucketInstanceId; + uint16_t collisionGroupId; }; class FeatureIndex { diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index ddac5c5c8f..9d886cb74c 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -44,7 +44,8 @@ public: Scheduler&, MapMode, ConstrainMode, - ViewportMode); + ViewportMode, + bool); ~Impl(); @@ -73,6 +74,7 @@ public: const MapMode mode; const float pixelRatio; + const bool crossSourceCollisions; MapDebugOptions debugOptions { MapDebugOptions::NoDebug }; @@ -96,7 +98,8 @@ Map::Map(RendererFrontend& rendererFrontend, Scheduler& scheduler, MapMode mapMode, ConstrainMode constrainMode, - ViewportMode viewportMode) + ViewportMode viewportMode, + bool crossSourceCollisions) : impl(std::make_unique(*this, rendererFrontend, mapObserver, @@ -105,7 +108,8 @@ Map::Map(RendererFrontend& rendererFrontend, scheduler, mapMode, constrainMode, - viewportMode)) { + viewportMode, + crossSourceCollisions)) { impl->transform.resize(size); } @@ -117,7 +121,8 @@ Map::Impl::Impl(Map& map_, Scheduler& scheduler_, MapMode mode_, ConstrainMode constrainMode_, - ViewportMode viewportMode_) + ViewportMode viewportMode_, + bool crossSourceCollisions_) : map(map_), observer(mapObserver), rendererFrontend(frontend), @@ -128,6 +133,7 @@ Map::Impl::Impl(Map& map_, viewportMode_), mode(mode_), pixelRatio(pixelRatio_), + crossSourceCollisions(crossSourceCollisions_), style(std::make_unique