diff options
Diffstat (limited to 'src/mbgl/style')
21 files changed, 128 insertions, 96 deletions
diff --git a/src/mbgl/style/layer_impl.hpp b/src/mbgl/style/layer_impl.hpp index 569ef65906..f350044925 100644 --- a/src/mbgl/style/layer_impl.hpp +++ b/src/mbgl/style/layer_impl.hpp @@ -34,6 +34,10 @@ public: Impl& operator=(const Impl&) = delete; + // Returns true buckets if properties affecting layout have changed: i.e. filter, + // visibility, layout properties, or data-driven paint properties. + virtual bool hasLayoutDifference(const Layer::Impl&) const = 0; + // Utility function for automatic layer grouping. virtual void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const = 0; diff --git a/src/mbgl/style/layers/background_layer_impl.cpp b/src/mbgl/style/layers/background_layer_impl.cpp index 4b4f44a8d8..a59a84fbe9 100644 --- a/src/mbgl/style/layers/background_layer_impl.cpp +++ b/src/mbgl/style/layers/background_layer_impl.cpp @@ -3,5 +3,9 @@ namespace mbgl { namespace style { +bool BackgroundLayer::Impl::hasLayoutDifference(const Layer::Impl&) const { + return false; +} + } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/layers/background_layer_impl.hpp b/src/mbgl/style/layers/background_layer_impl.hpp index 4f14662658..248a751027 100644 --- a/src/mbgl/style/layers/background_layer_impl.hpp +++ b/src/mbgl/style/layers/background_layer_impl.hpp @@ -11,6 +11,7 @@ class BackgroundLayer::Impl : public Layer::Impl { public: using Layer::Impl::Impl; + bool hasLayoutDifference(const Layer::Impl&) const override; void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const override; BackgroundPaintProperties::Transitionable paint; diff --git a/src/mbgl/style/layers/circle_layer_impl.cpp b/src/mbgl/style/layers/circle_layer_impl.cpp index cdb371bd58..69f574cd6b 100644 --- a/src/mbgl/style/layers/circle_layer_impl.cpp +++ b/src/mbgl/style/layers/circle_layer_impl.cpp @@ -3,5 +3,13 @@ namespace mbgl { namespace style { +bool CircleLayer::Impl::hasLayoutDifference(const Layer::Impl& other) const { + assert(dynamic_cast<const CircleLayer::Impl*>(&other)); + const auto& impl = static_cast<const style::CircleLayer::Impl&>(other); + return filter != impl.filter || + visibility != impl.visibility || + paint.hasDataDrivenPropertyDifference(impl.paint); +} + } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/layers/circle_layer_impl.hpp b/src/mbgl/style/layers/circle_layer_impl.hpp index 79ef879ab9..4b148cdc42 100644 --- a/src/mbgl/style/layers/circle_layer_impl.hpp +++ b/src/mbgl/style/layers/circle_layer_impl.hpp @@ -11,6 +11,7 @@ class CircleLayer::Impl : public Layer::Impl { public: using Layer::Impl::Impl; + bool hasLayoutDifference(const Layer::Impl&) const override; void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const override; CirclePaintProperties::Transitionable paint; diff --git a/src/mbgl/style/layers/custom_layer_impl.cpp b/src/mbgl/style/layers/custom_layer_impl.cpp index e2ed00a10d..10dd058861 100644 --- a/src/mbgl/style/layers/custom_layer_impl.cpp +++ b/src/mbgl/style/layers/custom_layer_impl.cpp @@ -16,6 +16,10 @@ CustomLayer::Impl::Impl(const std::string& id_, context = context_; } +bool CustomLayer::Impl::hasLayoutDifference(const Layer::Impl&) const { + return false; +} + void CustomLayer::Impl::stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const { } diff --git a/src/mbgl/style/layers/custom_layer_impl.hpp b/src/mbgl/style/layers/custom_layer_impl.hpp index 26a75f5834..466d1f3e3f 100644 --- a/src/mbgl/style/layers/custom_layer_impl.hpp +++ b/src/mbgl/style/layers/custom_layer_impl.hpp @@ -22,6 +22,7 @@ public: void render(const TransformState&) const; private: + bool hasLayoutDifference(const Layer::Impl&) const override; void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const override; CustomLayerInitializeFunction initializeFn = nullptr; diff --git a/src/mbgl/style/layers/fill_extrusion_layer_impl.cpp b/src/mbgl/style/layers/fill_extrusion_layer_impl.cpp index 07df4cd331..d37c2ad29b 100644 --- a/src/mbgl/style/layers/fill_extrusion_layer_impl.cpp +++ b/src/mbgl/style/layers/fill_extrusion_layer_impl.cpp @@ -3,5 +3,13 @@ namespace mbgl { namespace style { +bool FillExtrusionLayer::Impl::hasLayoutDifference(const Layer::Impl& other) const { + assert(dynamic_cast<const FillExtrusionLayer::Impl*>(&other)); + const auto& impl = static_cast<const style::FillExtrusionLayer::Impl&>(other); + return filter != impl.filter || + visibility != impl.visibility || + paint.hasDataDrivenPropertyDifference(impl.paint); +} + } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/layers/fill_extrusion_layer_impl.hpp b/src/mbgl/style/layers/fill_extrusion_layer_impl.hpp index 73c65469d1..9abc6fc4b3 100644 --- a/src/mbgl/style/layers/fill_extrusion_layer_impl.hpp +++ b/src/mbgl/style/layers/fill_extrusion_layer_impl.hpp @@ -11,6 +11,7 @@ class FillExtrusionLayer::Impl : public Layer::Impl { public: using Layer::Impl::Impl; + bool hasLayoutDifference(const Layer::Impl&) const override; void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const override; FillExtrusionPaintProperties::Transitionable paint; diff --git a/src/mbgl/style/layers/fill_layer_impl.cpp b/src/mbgl/style/layers/fill_layer_impl.cpp index 38672c5bfe..0dc7ed14d5 100644 --- a/src/mbgl/style/layers/fill_layer_impl.cpp +++ b/src/mbgl/style/layers/fill_layer_impl.cpp @@ -3,5 +3,13 @@ namespace mbgl { namespace style { +bool FillLayer::Impl::hasLayoutDifference(const Layer::Impl& other) const { + assert(dynamic_cast<const FillLayer::Impl*>(&other)); + const auto& impl = static_cast<const style::FillLayer::Impl&>(other); + return filter != impl.filter || + visibility != impl.visibility || + paint.hasDataDrivenPropertyDifference(impl.paint); +} + } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/layers/fill_layer_impl.hpp b/src/mbgl/style/layers/fill_layer_impl.hpp index 72ea8ab352..2673cd7443 100644 --- a/src/mbgl/style/layers/fill_layer_impl.hpp +++ b/src/mbgl/style/layers/fill_layer_impl.hpp @@ -11,6 +11,7 @@ class FillLayer::Impl : public Layer::Impl { public: using Layer::Impl::Impl; + bool hasLayoutDifference(const Layer::Impl&) const override; void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const override; FillPaintProperties::Transitionable paint; diff --git a/src/mbgl/style/layers/line_layer_impl.cpp b/src/mbgl/style/layers/line_layer_impl.cpp index 16a164eb9d..bee88d6a47 100644 --- a/src/mbgl/style/layers/line_layer_impl.cpp +++ b/src/mbgl/style/layers/line_layer_impl.cpp @@ -3,5 +3,14 @@ namespace mbgl { namespace style { +bool LineLayer::Impl::hasLayoutDifference(const Layer::Impl& other) const { + assert(dynamic_cast<const LineLayer::Impl*>(&other)); + const auto& impl = static_cast<const style::LineLayer::Impl&>(other); + return filter != impl.filter || + visibility != impl.visibility || + layout != impl.layout || + paint.hasDataDrivenPropertyDifference(impl.paint); +} + } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/layers/line_layer_impl.hpp b/src/mbgl/style/layers/line_layer_impl.hpp index 333821dc17..04adc0e85c 100644 --- a/src/mbgl/style/layers/line_layer_impl.hpp +++ b/src/mbgl/style/layers/line_layer_impl.hpp @@ -11,6 +11,7 @@ class LineLayer::Impl : public Layer::Impl { public: using Layer::Impl::Impl; + bool hasLayoutDifference(const Layer::Impl&) const override; void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const override; LineLayoutProperties::Unevaluated layout; diff --git a/src/mbgl/style/layers/raster_layer_impl.cpp b/src/mbgl/style/layers/raster_layer_impl.cpp index 1c2204c5d7..a995f50dd3 100644 --- a/src/mbgl/style/layers/raster_layer_impl.cpp +++ b/src/mbgl/style/layers/raster_layer_impl.cpp @@ -3,5 +3,9 @@ namespace mbgl { namespace style { +bool RasterLayer::Impl::hasLayoutDifference(const Layer::Impl&) const { + return false; +} + } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/layers/raster_layer_impl.hpp b/src/mbgl/style/layers/raster_layer_impl.hpp index 2178fd69d4..adbe703e92 100644 --- a/src/mbgl/style/layers/raster_layer_impl.hpp +++ b/src/mbgl/style/layers/raster_layer_impl.hpp @@ -11,6 +11,7 @@ class RasterLayer::Impl : public Layer::Impl { public: using Layer::Impl::Impl; + bool hasLayoutDifference(const Layer::Impl&) const override; void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const override; RasterPaintProperties::Transitionable paint; diff --git a/src/mbgl/style/layers/symbol_layer_impl.cpp b/src/mbgl/style/layers/symbol_layer_impl.cpp index 3f0ab9b8fb..b59768725d 100644 --- a/src/mbgl/style/layers/symbol_layer_impl.cpp +++ b/src/mbgl/style/layers/symbol_layer_impl.cpp @@ -3,5 +3,14 @@ namespace mbgl { namespace style { +bool SymbolLayer::Impl::hasLayoutDifference(const Layer::Impl& other) const { + assert(dynamic_cast<const SymbolLayer::Impl*>(&other)); + const auto& impl = static_cast<const style::SymbolLayer::Impl&>(other); + return filter != impl.filter || + visibility != impl.visibility || + layout != impl.layout || + paint.hasDataDrivenPropertyDifference(impl.paint); +} + } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/layers/symbol_layer_impl.hpp b/src/mbgl/style/layers/symbol_layer_impl.hpp index 7b9415436d..f8ef87dcdf 100644 --- a/src/mbgl/style/layers/symbol_layer_impl.hpp +++ b/src/mbgl/style/layers/symbol_layer_impl.hpp @@ -11,6 +11,7 @@ class SymbolLayer::Impl : public Layer::Impl { public: using Layer::Impl::Impl; + bool hasLayoutDifference(const Layer::Impl&) const override; void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const override; SymbolLayoutProperties::Unevaluated layout; diff --git a/src/mbgl/style/properties.hpp b/src/mbgl/style/properties.hpp index 678d38563a..24ac030541 100644 --- a/src/mbgl/style/properties.hpp +++ b/src/mbgl/style/properties.hpp @@ -205,6 +205,12 @@ public: .transition(parameters, std::move(prior.template get<Ps>()))... }; } + + bool hasDataDrivenPropertyDifference(const Transitionable& other) const { + bool result = false; + util::ignore({ (result |= this->template get<Ps>().value.hasDataDrivenPropertyDifference(other.template get<Ps>().value))... }); + return result; + } }; }; diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index 74ce401292..4acafba0ee 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -54,21 +54,6 @@ namespace style { static Observer nullObserver; -struct QueueSourceReloadVisitor { - UpdateBatch& updateBatch; - - // No need to reload sources for these types; their visibility can change but - // they don't participate in layout. - void operator()(CustomLayer&) {} - void operator()(RasterLayer&) {} - void operator()(BackgroundLayer&) {} - - template <class VectorLayer> - void operator()(VectorLayer& layer) { - updateBatch.sourceIDs.insert(layer.getSourceID()); - } -}; - Style::Style(Scheduler& scheduler_, FileSource& fileSource_, float pixelRatio) : scheduler(scheduler_), fileSource(fileSource_), @@ -105,7 +90,6 @@ void Style::setJSON(const std::string& json) { renderSources.clear(); layers.clear(); transitionOptions = {}; - updateBatch = {}; Parser parser; auto error = parser.parse(json); @@ -193,7 +177,6 @@ std::unique_ptr<Source> Style::removeSource(const std::string& id) { auto source = std::move(*it); source->setObserver(nullptr); sources.erase(it); - updateBatch.sourceIDs.erase(id); return source; } @@ -244,7 +227,6 @@ Layer* Style::addLayer(std::unique_ptr<Layer> layer, optional<std::string> befor } layer->setObserver(this); - layer->accept(QueueSourceReloadVisitor { updateBatch }); return layers.emplace(before ? findLayer(*before) : layers.end(), std::move(layer))->get(); } @@ -339,14 +321,17 @@ void Style::update(const UpdateParameters& parameters) { parameters.mode == MapMode::Continuous ? util::DEFAULT_FADE_DURATION : Duration::zero() }; - const TileParameters tileParameters(parameters.pixelRatio, - parameters.debugOptions, - parameters.transformState, - parameters.scheduler, - parameters.fileSource, - parameters.mode, - parameters.annotationManager, - *this); + const TileParameters tileParameters { + parameters.pixelRatio, + parameters.debugOptions, + parameters.transformState, + parameters.scheduler, + parameters.fileSource, + parameters.mode, + parameters.annotationManager, + *spriteAtlas, + *glyphAtlas + }; // Update light. const bool lightChanged = renderLight.impl != light->impl; @@ -382,7 +367,7 @@ void Style::update(const UpdateParameters& parameters) { // Update changed images. for (const auto& entry : imageDiff.changed) { - spriteAtlas->updateImage(entry.second); + spriteAtlas->updateImage(entry.second[1]); } if (spriteLoaded && !spriteAtlas->isLoaded()) { @@ -396,26 +381,6 @@ void Style::update(const UpdateParameters& parameters) { newSourceImpls.push_back(source->baseImpl); } - const SourceDifference sourceDiff = diffSources(sourceImpls, newSourceImpls); - sourceImpls = std::move(newSourceImpls); - - // Remove render layers for removed sources. - for (const auto& entry : sourceDiff.removed) { - renderLayers.erase(entry.first); - } - - // Create render sources for newly added sources. - for (const auto& entry : sourceDiff.added) { - std::unique_ptr<RenderSource> renderSource = RenderSource::create(entry.second); - renderSource->setObserver(this); - renderSources.emplace(entry.first, std::move(renderSource)); - } - - // Update render sources for changed sources. - for (const auto& entry : sourceDiff.changed) { - renderSources.at(entry.first)->setImpl(entry.second); - } - std::vector<Immutable<Layer::Impl>> newLayerImpls; newLayerImpls.reserve(layers.size()); @@ -438,7 +403,7 @@ void Style::update(const UpdateParameters& parameters) { // Update render layers for changed layers. for (const auto& entry : layerDiff.changed) { - renderLayers.at(entry.first)->setImpl(entry.second); + renderLayers.at(entry.first)->setImpl(entry.second[1]); } // Update layers for class and zoom changes. @@ -457,35 +422,51 @@ void Style::update(const UpdateParameters& parameters) { } - // Update tiles for each source. - for (const auto& entry : renderSources) { - entry.second->enabled = false; + const SourceDifference sourceDiff = diffSources(sourceImpls, newSourceImpls); + sourceImpls = std::move(newSourceImpls); + + // Remove render layers for removed sources. + for (const auto& entry : sourceDiff.removed) { + renderSources.erase(entry.first); } - for (const auto& entry : renderLayers) { - RenderLayer& layer = *entry.second; - if (layer.needsRendering(zoomHistory.lastZoom)) { - if (RenderSource* source = getRenderSource(layer.baseImpl->source)) { - source->enabled = true; - } - } + // Create render sources for newly added sources. + for (const auto& entry : sourceDiff.added) { + std::unique_ptr<RenderSource> renderSource = RenderSource::create(entry.second); + renderSource->setObserver(this); + renderSources.emplace(entry.first, std::move(renderSource)); } - for (const auto& entry : renderSources) { - bool updated = updateBatch.sourceIDs.count(entry.first); - if (entry.second->enabled) { - if (updated) { - entry.second->reloadTiles(); + // Update all sources. + for (const auto& source : sourceImpls) { + std::vector<Immutable<Layer::Impl>> filteredLayers; + bool needsRendering = false; + bool needsRelayout = false; + + for (const auto& layer : layerImpls) { + if (layer->type == LayerType::Background || + layer->type == LayerType::Custom || + layer->source != source->id) { + continue; + } + + if (getRenderLayer(layer->id)->needsRendering(zoomHistory.lastZoom)) { + needsRendering = true; + } + + if (hasLayoutDifference(layerDiff, layer->id)) { + needsRelayout = true; } - entry.second->updateTiles(tileParameters); - } else if (updated) { - entry.second->invalidateTiles(); - } else { - entry.second->removeTiles(); + + filteredLayers.push_back(layer); } - } - updateBatch.sourceIDs.clear(); + renderSources.at(source->id)->update(source, + filteredLayers, + needsRendering, + needsRelayout, + tileParameters); + } } std::vector<const Source*> Style::getSources() const { @@ -580,7 +561,7 @@ RenderData Style::getRenderData(MapDebugOptions debugOptions, float angle) const RenderData result; for (const auto& entry : renderSources) { - if (entry.second->enabled) { + if (entry.second->isEnabled()) { result.sources.insert(entry.second.get()); } } @@ -801,13 +782,11 @@ void Style::onSpriteError(std::exception_ptr error) { observer->onResourceError(error); } -void Style::onLayerFilterChanged(Layer& layer) { - layer.accept(QueueSourceReloadVisitor { updateBatch }); +void Style::onLayerFilterChanged(Layer&) { observer->onUpdate(Update::Repaint); } -void Style::onLayerVisibilityChanged(Layer& layer) { - layer.accept(QueueSourceReloadVisitor { updateBatch }); +void Style::onLayerVisibilityChanged(Layer&) { observer->onUpdate(Update::Repaint); } @@ -815,13 +794,11 @@ void Style::onLayerPaintPropertyChanged(Layer&) { observer->onUpdate(Update::Repaint); } -void Style::onLayerDataDrivenPaintPropertyChanged(Layer& layer) { - layer.accept(QueueSourceReloadVisitor { updateBatch }); +void Style::onLayerDataDrivenPaintPropertyChanged(Layer&) { observer->onUpdate(Update::Repaint); } -void Style::onLayerLayoutPropertyChanged(Layer& layer, const char *) { - layer.accept(QueueSourceReloadVisitor { updateBatch }); +void Style::onLayerLayoutPropertyChanged(Layer&, const char *) { observer->onUpdate(Update::Repaint); } diff --git a/src/mbgl/style/style.hpp b/src/mbgl/style/style.hpp index 2d0b9eddbb..9138637894 100644 --- a/src/mbgl/style/style.hpp +++ b/src/mbgl/style/style.hpp @@ -5,7 +5,6 @@ #include <mbgl/style/source_observer.hpp> #include <mbgl/style/layer_observer.hpp> #include <mbgl/style/light_observer.hpp> -#include <mbgl/style/update_batch.hpp> #include <mbgl/style/image.hpp> #include <mbgl/renderer/render_source.hpp> #include <mbgl/renderer/render_source_observer.hpp> @@ -179,7 +178,6 @@ private: std::exception_ptr lastError; - UpdateBatch updateBatch; ZoomHistory zoomHistory; bool spriteLoaded = false; diff --git a/src/mbgl/style/update_batch.hpp b/src/mbgl/style/update_batch.hpp deleted file mode 100644 index 562df52afa..0000000000 --- a/src/mbgl/style/update_batch.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include <unordered_set> -#include <string> - -namespace mbgl { -namespace style { - -class UpdateBatch { -public: - std::unordered_set<std::string> sourceIDs; -}; - -} // namespace style -} // namespace mbgl |