diff options
Diffstat (limited to 'src')
49 files changed, 366 insertions, 386 deletions
diff --git a/src/mbgl/layermanager/circle_layer_factory.cpp b/src/mbgl/layermanager/circle_layer_factory.cpp index 0ea56e5711..28c64fc400 100644 --- a/src/mbgl/layermanager/circle_layer_factory.cpp +++ b/src/mbgl/layermanager/circle_layer_factory.cpp @@ -24,7 +24,7 @@ std::unique_ptr<style::Layer> CircleLayerFactory::createLayer(const std::string& return layer; } -std::unique_ptr<Bucket> CircleLayerFactory::createBucket(const BucketParameters& parameters, const std::vector<const RenderLayer*>& layers) noexcept { +std::unique_ptr<Bucket> CircleLayerFactory::createBucket(const BucketParameters& parameters, const std::vector<Immutable<style::LayerProperties>>& layers) noexcept { return std::make_unique<CircleBucket>(parameters, layers); } diff --git a/src/mbgl/layermanager/fill_extrusion_layer_factory.cpp b/src/mbgl/layermanager/fill_extrusion_layer_factory.cpp index b2558825ef..bc1647afa4 100644 --- a/src/mbgl/layermanager/fill_extrusion_layer_factory.cpp +++ b/src/mbgl/layermanager/fill_extrusion_layer_factory.cpp @@ -26,8 +26,10 @@ std::unique_ptr<style::Layer> FillExtrusionLayerFactory::createLayer(const std:: std::unique_ptr<Layout> FillExtrusionLayerFactory::createLayout(const LayoutParameters& parameters, std::unique_ptr<GeometryTileLayer> layer, - const std::vector<const RenderLayer*>& group) noexcept { - return std::make_unique<PatternLayout<FillExtrusionBucket>>(parameters.bucketParameters, group, std::move(layer), parameters.imageDependencies); + const std::vector<Immutable<style::LayerProperties>>& group) noexcept { + using namespace style; + using LayoutType = PatternLayout<FillExtrusionBucket, FillExtrusionLayerProperties, FillExtrusionPattern, FillExtrusionPaintProperties::PossiblyEvaluated>; + return std::make_unique<LayoutType>(parameters.bucketParameters, group, std::move(layer), parameters.imageDependencies); } std::unique_ptr<RenderLayer> FillExtrusionLayerFactory::createRenderLayer(Immutable<style::Layer::Impl> impl) noexcept { diff --git a/src/mbgl/layermanager/fill_layer_factory.cpp b/src/mbgl/layermanager/fill_layer_factory.cpp index 60a1818585..f9b59359c5 100644 --- a/src/mbgl/layermanager/fill_layer_factory.cpp +++ b/src/mbgl/layermanager/fill_layer_factory.cpp @@ -27,8 +27,10 @@ std::unique_ptr<style::Layer> FillLayerFactory::createLayer(const std::string& i std::unique_ptr<Layout> FillLayerFactory::createLayout(const LayoutParameters& parameters, std::unique_ptr<GeometryTileLayer> layer, - const std::vector<const RenderLayer*>& group) noexcept { - return std::make_unique<PatternLayout<FillBucket>>(parameters.bucketParameters, group, std::move(layer), parameters.imageDependencies); + const std::vector<Immutable<style::LayerProperties>>& group) noexcept { + using namespace style; + using LayoutType = PatternLayout<FillBucket, FillLayerProperties, FillPattern, FillPaintProperties::PossiblyEvaluated>; + return std::make_unique<LayoutType>(parameters.bucketParameters, group, std::move(layer), parameters.imageDependencies); } std::unique_ptr<RenderLayer> FillLayerFactory::createRenderLayer(Immutable<style::Layer::Impl> impl) noexcept { diff --git a/src/mbgl/layermanager/heatmap_layer_factory.cpp b/src/mbgl/layermanager/heatmap_layer_factory.cpp index 5d6a595b46..1cd5d18f79 100644 --- a/src/mbgl/layermanager/heatmap_layer_factory.cpp +++ b/src/mbgl/layermanager/heatmap_layer_factory.cpp @@ -24,7 +24,7 @@ std::unique_ptr<style::Layer> HeatmapLayerFactory::createLayer(const std::string return layer; } -std::unique_ptr<Bucket> HeatmapLayerFactory::createBucket(const BucketParameters& parameters, const std::vector<const RenderLayer*>& layers) noexcept { +std::unique_ptr<Bucket> HeatmapLayerFactory::createBucket(const BucketParameters& parameters, const std::vector<Immutable<style::LayerProperties>>& layers) noexcept { return std::make_unique<HeatmapBucket>(parameters, layers); } diff --git a/src/mbgl/layermanager/layer_factory.cpp b/src/mbgl/layermanager/layer_factory.cpp index ceeb304f44..f4967b0e5d 100644 --- a/src/mbgl/layermanager/layer_factory.cpp +++ b/src/mbgl/layermanager/layer_factory.cpp @@ -25,12 +25,14 @@ optional<std::string> LayerFactory::getSource(const style::conversion::Convertib return source; } -std::unique_ptr<Bucket> LayerFactory::createBucket(const BucketParameters&, const std::vector<const RenderLayer*>&) noexcept { +std::unique_ptr<Bucket> LayerFactory::createBucket(const BucketParameters&, const std::vector<Immutable<style::LayerProperties>>&) noexcept { assert(false); return nullptr; } -std::unique_ptr<Layout> LayerFactory::createLayout(const LayoutParameters&, std::unique_ptr<GeometryTileLayer>, const std::vector<const RenderLayer*>&) noexcept { +std::unique_ptr<Layout> LayerFactory::createLayout(const LayoutParameters&, + std::unique_ptr<GeometryTileLayer>, + const std::vector<Immutable<style::LayerProperties>>&) noexcept { assert(false); return nullptr; } diff --git a/src/mbgl/layermanager/layer_manager.cpp b/src/mbgl/layermanager/layer_manager.cpp index e6195caeba..1e2074cd70 100644 --- a/src/mbgl/layermanager/layer_manager.cpp +++ b/src/mbgl/layermanager/layer_manager.cpp @@ -25,7 +25,8 @@ std::unique_ptr<style::Layer> LayerManager::createLayer( return nullptr; } -std::unique_ptr<Bucket> LayerManager::createBucket(const BucketParameters& parameters, const std::vector<const RenderLayer*>& layers) noexcept { +std::unique_ptr<Bucket> LayerManager::createBucket(const BucketParameters& parameters, + const std::vector<Immutable<style::LayerProperties>>& layers) noexcept { assert(!layers.empty()); assert(parameters.layerType->layout == style::LayerTypeInfo::Layout::NotRequired); LayerFactory* factory = getFactory(parameters.layerType); @@ -35,7 +36,7 @@ std::unique_ptr<Bucket> LayerManager::createBucket(const BucketParameters& param std::unique_ptr<Layout> LayerManager::createLayout(const LayoutParameters& parameters, std::unique_ptr<GeometryTileLayer> tileLayer, - const std::vector<const RenderLayer*>& layers) noexcept { + const std::vector<Immutable<style::LayerProperties>>& layers) noexcept { assert(!layers.empty()); assert(parameters.bucketParameters.layerType->layout == style::LayerTypeInfo::Layout::Required); LayerFactory* factory = getFactory(parameters.bucketParameters.layerType); diff --git a/src/mbgl/layermanager/line_layer_factory.cpp b/src/mbgl/layermanager/line_layer_factory.cpp index 8bf756e159..212fb45665 100644 --- a/src/mbgl/layermanager/line_layer_factory.cpp +++ b/src/mbgl/layermanager/line_layer_factory.cpp @@ -26,8 +26,10 @@ std::unique_ptr<style::Layer> LineLayerFactory::createLayer(const std::string& i std::unique_ptr<Layout> LineLayerFactory::createLayout(const LayoutParameters& parameters, std::unique_ptr<GeometryTileLayer> layer, - const std::vector<const RenderLayer*>& group) noexcept { - return std::make_unique<PatternLayout<LineBucket>>(parameters.bucketParameters, group, std::move(layer), parameters.imageDependencies); + const std::vector<Immutable<style::LayerProperties>>& group) noexcept { + using namespace style; + using LayoutType = PatternLayout<LineBucket, LineLayerProperties, LinePattern, LinePaintProperties::PossiblyEvaluated, LineLayoutProperties::PossiblyEvaluated>; + return std::make_unique<LayoutType>(parameters.bucketParameters, group, std::move(layer), parameters.imageDependencies); } std::unique_ptr<RenderLayer> LineLayerFactory::createRenderLayer(Immutable<style::Layer::Impl> impl) noexcept { diff --git a/src/mbgl/layermanager/symbol_layer_factory.cpp b/src/mbgl/layermanager/symbol_layer_factory.cpp index d992741551..f5a4640db7 100644 --- a/src/mbgl/layermanager/symbol_layer_factory.cpp +++ b/src/mbgl/layermanager/symbol_layer_factory.cpp @@ -26,7 +26,7 @@ std::unique_ptr<style::Layer> SymbolLayerFactory::createLayer(const std::string& std::unique_ptr<Layout> SymbolLayerFactory::createLayout(const LayoutParameters& parameters, std::unique_ptr<GeometryTileLayer> tileLayer, - const std::vector<const RenderLayer*>& group) noexcept { + const std::vector<Immutable<style::LayerProperties>>& group) noexcept { return std::make_unique<SymbolLayout>(parameters.bucketParameters, group, std::move(tileLayer), diff --git a/src/mbgl/layout/pattern_layout.hpp b/src/mbgl/layout/pattern_layout.hpp index 8dabfab919..fe2e9c5950 100644 --- a/src/mbgl/layout/pattern_layout.hpp +++ b/src/mbgl/layout/pattern_layout.hpp @@ -3,6 +3,7 @@ #include <mbgl/renderer/bucket_parameters.hpp> #include <mbgl/geometry/feature_index.hpp> #include <mbgl/renderer/render_layer.hpp> +#include <mbgl/style/layer_properties.hpp> namespace mbgl { @@ -22,31 +23,32 @@ public: PatternLayerMap patterns; }; -template <class B> +template <class BucketType, + class LayerPropertiesType, + class PatternPropertyType, + class PossiblyEvaluatedPaintPropertiesType, + class PossiblyEvaluatedLayoutPropertiesType = typename style::Properties<>::PossiblyEvaluated> class PatternLayout : public Layout { public: PatternLayout(const BucketParameters& parameters, - const std::vector<const RenderLayer*>& layers, + const std::vector<Immutable<style::LayerProperties>>& group, std::unique_ptr<GeometryTileLayer> sourceLayer_, ImageDependencies& patternDependencies) - : Layout(), - bucketLeaderID(layers.at(0)->getID()), - sourceLayer(std::move(sourceLayer_)), + : sourceLayer(std::move(sourceLayer_)), zoom(parameters.tileID.overscaledZ), overscaling(parameters.tileID.overscaleFactor()), hasPattern(false) { - - using PatternLayer = typename B::RenderLayerType; - const auto renderLayer = static_cast<const PatternLayer*>(layers.at(0)); - const typename PatternLayer::StyleLayerImpl& leader = renderLayer->impl(); - layout = leader.layout.evaluate(PropertyEvaluationParameters(zoom)); - sourceLayerID = leader.sourceLayer; - groupID = renderLayer->getID(); - - for (const auto& layer : layers) { - const typename B::PossiblyEvaluatedPaintProperties evaluatedProps = static_cast<const PatternLayer*>(layer)->evaluated; - const auto patternProperty = evaluatedProps.template get<typename PatternLayer::PatternProperty>(); - const auto constantPattern = patternProperty.constantOr({ "", "" }); + assert(!group.empty()); + auto leaderLayerProperties = staticImmutableCast<LayerPropertiesType>(group.front()); + layout = leaderLayerProperties->layerImpl().layout.evaluate(PropertyEvaluationParameters(zoom)); + sourceLayerID = leaderLayerProperties->layerImpl().sourceLayer; + bucketLeaderID = leaderLayerProperties->layerImpl().id; + + for (const auto& layerProperties : group) { + const std::string& layerId = layerProperties->baseImpl->id; + const auto evaluatedProps = static_cast<const LayerPropertiesType&>(*layerProperties).evaluated; + const auto patternProperty = evaluatedProps.template get<PatternPropertyType>(); + const auto constantPattern = patternProperty.constantOr(Faded<std::basic_string<char> >{ "", ""}); // determine if layer group has any layers that use *-pattern property and add // constant pattern dependencies. if (!patternProperty.isConstant()) { @@ -56,33 +58,34 @@ public: patternDependencies.emplace(constantPattern.to, ImageType::Pattern); patternDependencies.emplace(constantPattern.from, ImageType::Pattern); } - layerPaintProperties.emplace(layer->getID(), std::move(evaluatedProps)); + layerPaintProperties.emplace(layerId, std::move(evaluatedProps)); } const size_t featureCount = sourceLayer->featureCount(); for (size_t i = 0; i < featureCount; ++i) { auto feature = sourceLayer->getFeature(i); - if (!leader.filter(style::expression::EvaluationContext { this->zoom, feature.get() })) + if (!leaderLayerProperties->layerImpl().filter(style::expression::EvaluationContext { this->zoom, feature.get() })) continue; PatternLayerMap patternDependencyMap; if (hasPattern) { - for (const auto& layer : layers) { - const auto it = layerPaintProperties.find(layer->getID()); + for (const auto& layerProperties : group) { + const std::string& layerId = layerProperties->baseImpl->id; + const auto it = layerPaintProperties.find(layerId); if (it != layerPaintProperties.end()) { const auto paint = it->second; - const auto patternProperty = paint.template get<typename PatternLayer::PatternProperty>(); + const auto patternProperty = paint.template get<PatternPropertyType>(); if (!patternProperty.isConstant()) { // For layers with non-data-constant pattern properties, evaluate their expression and add // the patterns to the dependency vector - const auto min = patternProperty.evaluate(*feature, zoom - 1, PatternLayer::PatternProperty::defaultValue()); - const auto mid = patternProperty.evaluate(*feature, zoom, PatternLayer::PatternProperty::defaultValue()); - const auto max = patternProperty.evaluate(*feature, zoom + 1, PatternLayer::PatternProperty::defaultValue()); + const auto min = patternProperty.evaluate(*feature, zoom - 1, PatternPropertyType::defaultValue()); + const auto mid = patternProperty.evaluate(*feature, zoom, PatternPropertyType::defaultValue()); + const auto max = patternProperty.evaluate(*feature, zoom + 1, PatternPropertyType::defaultValue()); patternDependencies.emplace(min.to, ImageType::Pattern); patternDependencies.emplace(mid.to, ImageType::Pattern); patternDependencies.emplace(max.to, ImageType::Pattern); - patternDependencyMap.emplace(layer->getID(), PatternDependency {min.to, mid.to, max.to}); + patternDependencyMap.emplace(layerId, PatternDependency {min.to, mid.to, max.to}); } } @@ -99,15 +102,15 @@ public: } void createBucket(const ImagePositions& patternPositions, std::unique_ptr<FeatureIndex>& featureIndex, std::unordered_map<std::string, std::shared_ptr<Bucket>>& buckets, const bool, const bool) override { - auto bucket = std::make_shared<B>(layout, layerPaintProperties, zoom, overscaling); + auto bucket = std::make_shared<BucketType>(layout, layerPaintProperties, zoom, overscaling); for (auto & patternFeature : features) { const auto i = patternFeature.i; std::unique_ptr<GeometryTileFeature> feature = std::move(patternFeature.feature); - PatternLayerMap patterns = patternFeature.patterns; + const PatternLayerMap& patterns = patternFeature.patterns; GeometryCollection geometries = feature->getGeometries(); bucket->addFeature(*feature, geometries, patternPositions, patterns); - featureIndex->insert(geometries, i, sourceLayerID, groupID); + featureIndex->insert(geometries, i, sourceLayerID, bucketLeaderID); } if (bucket->hasData()) { for (const auto& pair : layerPaintProperties) { @@ -116,19 +119,18 @@ public: } }; - std::map<std::string, typename B::PossiblyEvaluatedPaintProperties> layerPaintProperties; - const std::string bucketLeaderID; + std::map<std::string, PossiblyEvaluatedPaintPropertiesType> layerPaintProperties; + std::string bucketLeaderID; private: const std::unique_ptr<GeometryTileLayer> sourceLayer; std::vector<PatternFeature> features; - typename B::PossiblyEvaluatedLayoutProperties layout; + PossiblyEvaluatedLayoutPropertiesType layout; const float zoom; const uint32_t overscaling; std::string sourceLayerID; - std::string groupID; bool hasPattern; }; diff --git a/src/mbgl/layout/symbol_layout.cpp b/src/mbgl/layout/symbol_layout.cpp index 03cfe506ec..0eb98f7569 100644 --- a/src/mbgl/layout/symbol_layout.cpp +++ b/src/mbgl/layout/symbol_layout.cpp @@ -40,16 +40,18 @@ expression::Value sectionOptionsToValue(const SectionOptions& options) { } return result; } -} // namespace +inline const SymbolLayerProperties& toSymbolLayerProperties(const Immutable<LayerProperties>& layer) { + return static_cast<const SymbolLayerProperties&>(*layer); +} +} // namespace SymbolLayout::SymbolLayout(const BucketParameters& parameters, - const std::vector<const RenderLayer*>& layers, + const std::vector<Immutable<style::LayerProperties>>& layers, std::unique_ptr<GeometryTileLayer> sourceLayer_, ImageDependencies& imageDependencies, GlyphDependencies& glyphDependencies) - : Layout(), - bucketLeaderID(layers.at(0)->getID()), + : bucketLeaderID(layers.front()->baseImpl->id), sourceLayer(std::move(sourceLayer_)), overscaling(parameters.tileID.overscaleFactor()), zoom(parameters.tileID.overscaledZ), @@ -57,11 +59,11 @@ SymbolLayout::SymbolLayout(const BucketParameters& parameters, pixelRatio(parameters.pixelRatio), tileSize(util::tileSize * overscaling), tilePixelRatio(float(util::EXTENT) / tileSize), - textSize(toRenderSymbolLayer(layers.at(0))->impl().layout.get<TextSize>()), - iconSize(toRenderSymbolLayer(layers.at(0))->impl().layout.get<IconSize>()) + textSize(toSymbolLayerProperties(layers.at(0)).layerImpl().layout.get<TextSize>()), + iconSize(toSymbolLayerProperties(layers.at(0)).layerImpl().layout.get<IconSize>()) { - const SymbolLayer::Impl& leader = toRenderSymbolLayer(layers.at(0))->impl(); + const SymbolLayer::Impl& leader = toSymbolLayerProperties(layers.at(0)).layerImpl(); layout = leader.layout.evaluate(PropertyEvaluationParameters(zoom)); @@ -104,7 +106,7 @@ SymbolLayout::SymbolLayout(const BucketParameters& parameters, layout.get<TextIgnorePlacement>() || layout.get<IconIgnorePlacement>()); for (const auto& layer : layers) { - layerPaintProperties.emplace(layer->getID(), toRenderSymbolLayer(layer)->evaluated); + layerPaintProperties.emplace(layer->baseImpl->id, toSymbolLayerProperties(layer).evaluated); } // Determine glyph dependencies diff --git a/src/mbgl/layout/symbol_layout.hpp b/src/mbgl/layout/symbol_layout.hpp index 9b8b0adfcc..9fc48d904c 100644 --- a/src/mbgl/layout/symbol_layout.hpp +++ b/src/mbgl/layout/symbol_layout.hpp @@ -16,7 +16,6 @@ namespace mbgl { class BucketParameters; class Anchor; -class RenderLayer; class PlacedSymbol; namespace style { @@ -26,7 +25,7 @@ class Filter; class SymbolLayout final : public Layout { public: SymbolLayout(const BucketParameters&, - const std::vector<const RenderLayer*>&, + const std::vector<Immutable<style::LayerProperties>>&, std::unique_ptr<GeometryTileLayer>, ImageDependencies&, GlyphDependencies&); diff --git a/src/mbgl/renderer/bucket.hpp b/src/mbgl/renderer/bucket.hpp index 1d775ede04..e345f0b5ec 100644 --- a/src/mbgl/renderer/bucket.hpp +++ b/src/mbgl/renderer/bucket.hpp @@ -31,9 +31,6 @@ public: const ImagePositions&, const PatternLayerMap&) {}; - virtual void populateFeatureBuffers(const ImagePositions&) {}; - virtual void addPatternDependencies(const std::vector<const RenderLayer*>&, ImageDependencies&) {}; - // As long as this bucket has a Prepare render pass, this function is getting called. Typically, // this only happens once when the bucket is being rendered for the first time. virtual void upload(gfx::Context&) = 0; diff --git a/src/mbgl/renderer/buckets/circle_bucket.cpp b/src/mbgl/renderer/buckets/circle_bucket.cpp index 54ed374069..376f4e682f 100644 --- a/src/mbgl/renderer/buckets/circle_bucket.cpp +++ b/src/mbgl/renderer/buckets/circle_bucket.cpp @@ -10,14 +10,14 @@ namespace mbgl { using namespace style; -CircleBucket::CircleBucket(const BucketParameters& parameters, const std::vector<const RenderLayer*>& layers) +CircleBucket::CircleBucket(const BucketParameters& parameters, const std::vector<Immutable<style::LayerProperties>>& layers) : mode(parameters.mode) { for (const auto& layer : layers) { paintPropertyBinders.emplace( std::piecewise_construct, - std::forward_as_tuple(layer->getID()), + std::forward_as_tuple(layer->baseImpl->id), std::forward_as_tuple( - toRenderCircleLayer(layer)->evaluated, + getEvaluated<CircleLayerProperties>(layer), parameters.tileID.overscaledZ)); } } @@ -99,20 +99,20 @@ void CircleBucket::addFeature(const GeometryTileFeature& feature, } template <class Property> -static float get(const RenderCircleLayer& layer, const std::map<std::string, CircleProgram::Binders>& paintPropertyBinders) { - auto it = paintPropertyBinders.find(layer.getID()); +static float get(const CirclePaintProperties::PossiblyEvaluated& evaluated, const std::string& id, const std::map<std::string, CircleProgram::Binders>& paintPropertyBinders) { + auto it = paintPropertyBinders.find(id); if (it == paintPropertyBinders.end() || !it->second.statistics<Property>().max()) { - return layer.evaluated.get<Property>().constantOr(Property::defaultValue()); + return evaluated.get<Property>().constantOr(Property::defaultValue()); } else { return *it->second.statistics<Property>().max(); } } float CircleBucket::getQueryRadius(const RenderLayer& layer) const { - const RenderCircleLayer* circleLayer = toRenderCircleLayer(&layer); - float radius = get<CircleRadius>(*circleLayer, paintPropertyBinders); - float stroke = get<CircleStrokeWidth>(*circleLayer, paintPropertyBinders); - auto translate = circleLayer->evaluated.get<CircleTranslate>(); + const auto& evaluated = getEvaluated<CircleLayerProperties>(layer.evaluatedProperties); + float radius = get<CircleRadius>(evaluated, layer.getID(), paintPropertyBinders); + float stroke = get<CircleStrokeWidth>(evaluated, layer.getID(), paintPropertyBinders); + auto translate = evaluated.get<CircleTranslate>(); return radius + stroke + util::length(translate[0], translate[1]); } diff --git a/src/mbgl/renderer/buckets/circle_bucket.hpp b/src/mbgl/renderer/buckets/circle_bucket.hpp index e9aceed2b1..58f76327ab 100644 --- a/src/mbgl/renderer/buckets/circle_bucket.hpp +++ b/src/mbgl/renderer/buckets/circle_bucket.hpp @@ -15,7 +15,7 @@ class BucketParameters; class CircleBucket final : public Bucket { public: - CircleBucket(const BucketParameters&, const std::vector<const RenderLayer*>&); + CircleBucket(const BucketParameters&, const std::vector<Immutable<style::LayerProperties>>&); ~CircleBucket() override; void addFeature(const GeometryTileFeature&, diff --git a/src/mbgl/renderer/buckets/fill_bucket.cpp b/src/mbgl/renderer/buckets/fill_bucket.cpp index 927cb4a307..2dffc555e2 100644 --- a/src/mbgl/renderer/buckets/fill_bucket.cpp +++ b/src/mbgl/renderer/buckets/fill_bucket.cpp @@ -141,10 +141,9 @@ bool FillBucket::supportsLayer(const style::Layer::Impl& impl) const { return style::FillLayer::Impl::staticTypeInfo() == impl.getTypeInfo(); } - float FillBucket::getQueryRadius(const RenderLayer& layer) const { - const RenderFillLayer* fillLayer = toRenderFillLayer(&layer); - const std::array<float, 2>& translate = fillLayer->evaluated.get<FillTranslate>(); + const auto& evaluated = getEvaluated<FillLayerProperties>(layer.evaluatedProperties); + const std::array<float, 2>& translate = evaluated.get<FillTranslate>(); return util::length(translate[0], translate[1]); } diff --git a/src/mbgl/renderer/buckets/fill_bucket.hpp b/src/mbgl/renderer/buckets/fill_bucket.hpp index e1869e08d2..5844625d2a 100644 --- a/src/mbgl/renderer/buckets/fill_bucket.hpp +++ b/src/mbgl/renderer/buckets/fill_bucket.hpp @@ -18,8 +18,6 @@ class RenderFillLayer; class FillBucket final : public Bucket { public: ~FillBucket() override; - // These aliases are used by the PatternLayout template - using RenderLayerType = RenderFillLayer; using PossiblyEvaluatedPaintProperties = style::FillPaintProperties::PossiblyEvaluated; using PossiblyEvaluatedLayoutProperties = style::Properties<>::PossiblyEvaluated; diff --git a/src/mbgl/renderer/buckets/fill_extrusion_bucket.cpp b/src/mbgl/renderer/buckets/fill_extrusion_bucket.cpp index e640cf504d..61fc6a1444 100644 --- a/src/mbgl/renderer/buckets/fill_extrusion_bucket.cpp +++ b/src/mbgl/renderer/buckets/fill_extrusion_bucket.cpp @@ -185,8 +185,8 @@ bool FillExtrusionBucket::supportsLayer(const style::Layer::Impl& impl) const { } float FillExtrusionBucket::getQueryRadius(const RenderLayer& layer) const { - const RenderFillExtrusionLayer* fillExtrusionLayer = toRenderFillExtrusionLayer(&layer); - const std::array<float, 2>& translate = fillExtrusionLayer->evaluated.get<FillExtrusionTranslate>(); + const auto& evaluated = getEvaluated<FillExtrusionLayerProperties>(layer.evaluatedProperties); + const std::array<float, 2>& translate = evaluated.get<FillExtrusionTranslate>(); return util::length(translate[0], translate[1]); } diff --git a/src/mbgl/renderer/buckets/fill_extrusion_bucket.hpp b/src/mbgl/renderer/buckets/fill_extrusion_bucket.hpp index 81685e2c42..9dc2681bac 100644 --- a/src/mbgl/renderer/buckets/fill_extrusion_bucket.hpp +++ b/src/mbgl/renderer/buckets/fill_extrusion_bucket.hpp @@ -16,8 +16,6 @@ class RenderFillExtrusionLayer; class FillExtrusionBucket final : public Bucket { public: ~FillExtrusionBucket() override; - // These aliases are used by the PatternLayout template - using RenderLayerType = RenderFillExtrusionLayer; using PossiblyEvaluatedPaintProperties = style::FillExtrusionPaintProperties::PossiblyEvaluated; using PossiblyEvaluatedLayoutProperties = style::Properties<>::PossiblyEvaluated; diff --git a/src/mbgl/renderer/buckets/heatmap_bucket.cpp b/src/mbgl/renderer/buckets/heatmap_bucket.cpp index 04fd58ec55..111911a88c 100644 --- a/src/mbgl/renderer/buckets/heatmap_bucket.cpp +++ b/src/mbgl/renderer/buckets/heatmap_bucket.cpp @@ -10,14 +10,14 @@ namespace mbgl { using namespace style; -HeatmapBucket::HeatmapBucket(const BucketParameters& parameters, const std::vector<const RenderLayer*>& layers) +HeatmapBucket::HeatmapBucket(const BucketParameters& parameters, const std::vector<Immutable<style::LayerProperties>>& layers) : mode(parameters.mode) { for (const auto& layer : layers) { paintPropertyBinders.emplace( std::piecewise_construct, - std::forward_as_tuple(layer->getID()), + std::forward_as_tuple(layer->baseImpl->id), std::forward_as_tuple( - toRenderHeatmapLayer(layer)->evaluated, + getEvaluated<HeatmapLayerProperties>(layer), parameters.tileID.overscaledZ)); } } diff --git a/src/mbgl/renderer/buckets/heatmap_bucket.hpp b/src/mbgl/renderer/buckets/heatmap_bucket.hpp index 62cb460e27..b11c1626cd 100644 --- a/src/mbgl/renderer/buckets/heatmap_bucket.hpp +++ b/src/mbgl/renderer/buckets/heatmap_bucket.hpp @@ -15,7 +15,7 @@ class BucketParameters; class HeatmapBucket final : public Bucket { public: - HeatmapBucket(const BucketParameters&, const std::vector<const RenderLayer*>&); + HeatmapBucket(const BucketParameters&, const std::vector<Immutable<style::LayerProperties>>&); ~HeatmapBucket() override; void addFeature(const GeometryTileFeature&, diff --git a/src/mbgl/renderer/buckets/line_bucket.cpp b/src/mbgl/renderer/buckets/line_bucket.cpp index 13f575ba38..9a5ed9e628 100644 --- a/src/mbgl/renderer/buckets/line_bucket.cpp +++ b/src/mbgl/renderer/buckets/line_bucket.cpp @@ -11,10 +11,10 @@ namespace mbgl { using namespace style; LineBucket::LineBucket(const style::LineLayoutProperties::PossiblyEvaluated layout_, - std::map<std::string, style::LinePaintProperties::PossiblyEvaluated> layerPaintProperties, + const std::map<std::string, style::LinePaintProperties::PossiblyEvaluated>& layerPaintProperties, const float zoom_, const uint32_t overscaling_) - : layout(layout_), + : layout(std::move(layout_)), zoom(zoom_), overscaling(overscaling_) { @@ -528,31 +528,26 @@ bool LineBucket::supportsLayer(const style::Layer::Impl& impl) const { } template <class Property> -static float get(const RenderLineLayer& layer, const std::map<std::string, LineProgram::Binders>& paintPropertyBinders) { - auto it = paintPropertyBinders.find(layer.getID()); +static float get(const LinePaintProperties::PossiblyEvaluated& evaluated, const std::string& id, const std::map<std::string, LineProgram::Binders>& paintPropertyBinders) { + auto it = paintPropertyBinders.find(id); if (it == paintPropertyBinders.end() || !it->second.statistics<Property>().max()) { - return layer.evaluated.get<Property>().constantOr(Property::defaultValue()); + return evaluated.get<Property>().constantOr(Property::defaultValue()); } else { return *it->second.statistics<Property>().max(); } } -float LineBucket::getLineWidth(const RenderLineLayer& layer) const { - float lineWidth = get<LineWidth>(layer, paintPropertyBinders); - float gapWidth = get<LineGapWidth>(layer, paintPropertyBinders); - +float LineBucket::getQueryRadius(const RenderLayer& layer) const { + const auto& evaluated = getEvaluated<LineLayerProperties>(layer.evaluatedProperties); + const std::array<float, 2>& translate = evaluated.get<LineTranslate>(); + float offset = get<LineOffset>(evaluated, layer.getID(), paintPropertyBinders); + float lineWidth = get<LineWidth>(evaluated, layer.getID(), paintPropertyBinders); + float gapWidth = get<LineGapWidth>(evaluated, layer.getID(), paintPropertyBinders); if (gapWidth) { - return gapWidth + 2 * lineWidth; - } else { - return lineWidth; + lineWidth = gapWidth + 2 * lineWidth; } -} -float LineBucket::getQueryRadius(const RenderLayer& layer) const { - const RenderLineLayer* lineLayer = toRenderLineLayer(&layer); - const std::array<float, 2>& translate = lineLayer->evaluated.get<LineTranslate>(); - float offset = get<LineOffset>(*lineLayer, paintPropertyBinders); - return getLineWidth(*lineLayer) / 2.0 + std::abs(offset) + util::length(translate[0], translate[1]); + return lineWidth / 2.0f + std::abs(offset) + util::length(translate[0], translate[1]); } } // namespace mbgl diff --git a/src/mbgl/renderer/buckets/line_bucket.hpp b/src/mbgl/renderer/buckets/line_bucket.hpp index 7ee8677e50..6717ee7446 100644 --- a/src/mbgl/renderer/buckets/line_bucket.hpp +++ b/src/mbgl/renderer/buckets/line_bucket.hpp @@ -17,14 +17,11 @@ class RenderLineLayer; class LineBucket final : public Bucket { public: - - // These aliases are used by the PatternLayout template - using RenderLayerType = RenderLineLayer; using PossiblyEvaluatedPaintProperties = style::LinePaintProperties::PossiblyEvaluated; using PossiblyEvaluatedLayoutProperties = style::LineLayoutProperties::PossiblyEvaluated; LineBucket(const PossiblyEvaluatedLayoutProperties layout, - std::map<std::string, PossiblyEvaluatedPaintProperties> layerPaintProperties, + const std::map<std::string, PossiblyEvaluatedPaintProperties>& layerPaintProperties, const float zoom, const uint32_t overscaling); ~LineBucket() override; @@ -77,8 +74,6 @@ private: const float zoom; const uint32_t overscaling; - - float getLineWidth(const RenderLineLayer& layer) const; }; } // namespace mbgl diff --git a/src/mbgl/renderer/group_by_layout.cpp b/src/mbgl/renderer/group_by_layout.cpp index 41a895902c..5f78dd0d2b 100644 --- a/src/mbgl/renderer/group_by_layout.cpp +++ b/src/mbgl/renderer/group_by_layout.cpp @@ -1,6 +1,4 @@ #include <mbgl/renderer/group_by_layout.hpp> -#include <mbgl/renderer/render_layer.hpp> -#include <mbgl/style/layer_impl.hpp> #include <mbgl/style/conversion/stringify.hpp> #include <mbgl/util/rapidjson.hpp> @@ -11,38 +9,24 @@ namespace mbgl { -std::string layoutKey(const RenderLayer& layer) { +std::string layoutKey(const style::Layer::Impl& impl) { using namespace style::conversion; rapidjson::StringBuffer s; rapidjson::Writer<rapidjson::StringBuffer> writer(s); writer.StartArray(); - writer.Uint64(reinterpret_cast<uint64_t>(layer.baseImpl->getTypeInfo())); - writer.String(layer.baseImpl->source); - writer.String(layer.baseImpl->sourceLayer); - writer.Double(layer.baseImpl->minZoom); - writer.Double(layer.baseImpl->maxZoom); - writer.Uint(static_cast<uint32_t>(layer.baseImpl->visibility)); - stringify(writer, layer.baseImpl->filter); - layer.baseImpl->stringifyLayout(writer); + writer.Uint64(reinterpret_cast<uint64_t>(impl.getTypeInfo())); + writer.String(impl.source); + writer.String(impl.sourceLayer); + writer.Double(impl.minZoom); + writer.Double(impl.maxZoom); + writer.Uint(static_cast<uint32_t>(impl.visibility)); + stringify(writer, impl.filter); + impl.stringifyLayout(writer); writer.EndArray(); return s.GetString(); } -std::vector<std::vector<const RenderLayer*>> groupByLayout(const std::vector<std::unique_ptr<RenderLayer>>& layers) { - std::unordered_map<std::string, std::vector<const RenderLayer*>> map; - for (auto& layer : layers) { - map[layoutKey(*layer)].push_back(layer.get()); - } - - std::vector<std::vector<const RenderLayer*>> result; - for (auto& pair : map) { - result.push_back(pair.second); - } - - return result; -} - } // namespace mbgl diff --git a/src/mbgl/renderer/group_by_layout.hpp b/src/mbgl/renderer/group_by_layout.hpp index bc3ecfae63..0a91465e92 100644 --- a/src/mbgl/renderer/group_by_layout.hpp +++ b/src/mbgl/renderer/group_by_layout.hpp @@ -1,12 +1,12 @@ #pragma once +#include <mbgl/style/layer_impl.hpp> + #include <vector> #include <memory> namespace mbgl { -class RenderLayer; - -std::vector<std::vector<const RenderLayer*>> groupByLayout(const std::vector<std::unique_ptr<RenderLayer>>&); +std::string layoutKey(const style::Layer::Impl& impl); } // namespace mbgl diff --git a/src/mbgl/renderer/layers/render_background_layer.cpp b/src/mbgl/renderer/layers/render_background_layer.cpp index b633ad0671..d5ba8c879f 100644 --- a/src/mbgl/renderer/layers/render_background_layer.cpp +++ b/src/mbgl/renderer/layers/render_background_layer.cpp @@ -14,25 +14,30 @@ namespace mbgl { using namespace style; -RenderBackgroundLayer::RenderBackgroundLayer(Immutable<style::BackgroundLayer::Impl> _impl) - : RenderLayer(std::move(_impl)), - unevaluated(impl().paint.untransitioned()) { +inline const BackgroundLayer::Impl& impl(const Immutable<style::Layer::Impl>& impl) { + return static_cast<const style::BackgroundLayer::Impl&>(*impl); } -const style::BackgroundLayer::Impl& RenderBackgroundLayer::impl() const { - return static_cast<const style::BackgroundLayer::Impl&>(*baseImpl); +RenderBackgroundLayer::RenderBackgroundLayer(Immutable<style::BackgroundLayer::Impl> _impl) + : RenderLayer(makeMutable<BackgroundLayerProperties>(std::move(_impl))), + unevaluated(impl(baseImpl).paint.untransitioned()) { } +RenderBackgroundLayer::~RenderBackgroundLayer() = default; + void RenderBackgroundLayer::transition(const TransitionParameters ¶meters) { - unevaluated = impl().paint.transitioned(parameters, std::move(unevaluated)); + unevaluated = impl(baseImpl).paint.transitioned(parameters, std::move(unevaluated)); } void RenderBackgroundLayer::evaluate(const PropertyEvaluationParameters ¶meters) { - evaluated = unevaluated.evaluate(parameters); - crossfade = parameters.getCrossfadeParameters(); - - passes = evaluated.get<style::BackgroundOpacity>() > 0 ? RenderPass::Translucent - : RenderPass::None; + auto properties = makeMutable<BackgroundLayerProperties>( + staticImmutableCast<BackgroundLayer::Impl>(baseImpl), + parameters.getCrossfadeParameters(), + unevaluated.evaluate(parameters)); + + passes = properties->evaluated.get<style::BackgroundOpacity>() > 0 ? RenderPass::Translucent + : RenderPass::None; + evaluatedProperties = std::move(properties); } bool RenderBackgroundLayer::hasTransition() const { @@ -40,7 +45,7 @@ bool RenderBackgroundLayer::hasTransition() const { } bool RenderBackgroundLayer::hasCrossfade() const { - return crossfade.t != 1; + return static_cast<const BackgroundLayerProperties&>(*evaluatedProperties).crossfade.t != 1; } void RenderBackgroundLayer::render(PaintParameters& parameters, RenderSource*) { @@ -81,7 +86,8 @@ void RenderBackgroundLayer::render(PaintParameters& parameters, RenderSource*) { getID() ); }; - + const auto& evaluated = static_cast<const BackgroundLayerProperties&>(*evaluatedProperties).evaluated; + const auto& crossfade = static_cast<const BackgroundLayerProperties&>(*evaluatedProperties).crossfade; if (!evaluated.get<BackgroundPattern>().to.empty()) { optional<ImagePosition> imagePosA = parameters.imageManager.getPattern(evaluated.get<BackgroundPattern>().from); optional<ImagePosition> imagePosB = parameters.imageManager.getPattern(evaluated.get<BackgroundPattern>().to); @@ -123,6 +129,7 @@ void RenderBackgroundLayer::render(PaintParameters& parameters, RenderSource*) { } optional<Color> RenderBackgroundLayer::getSolidBackground() const { + const auto& evaluated = static_cast<const BackgroundLayerProperties&>(*evaluatedProperties).evaluated; if (!evaluated.get<BackgroundPattern>().from.empty()) { return nullopt; } diff --git a/src/mbgl/renderer/layers/render_background_layer.hpp b/src/mbgl/renderer/layers/render_background_layer.hpp index 3cb30ac2a3..de553eef90 100644 --- a/src/mbgl/renderer/layers/render_background_layer.hpp +++ b/src/mbgl/renderer/layers/render_background_layer.hpp @@ -6,25 +6,21 @@ namespace mbgl { -class RenderBackgroundLayer: public RenderLayer { +class RenderBackgroundLayer final : public RenderLayer { public: - RenderBackgroundLayer(Immutable<style::BackgroundLayer::Impl>); - ~RenderBackgroundLayer() final = default; + explicit RenderBackgroundLayer(Immutable<style::BackgroundLayer::Impl>); + ~RenderBackgroundLayer() override; +private: void transition(const TransitionParameters&) override; void evaluate(const PropertyEvaluationParameters&) override; bool hasTransition() const override; bool hasCrossfade() const override; - optional<Color> getSolidBackground() const final; + optional<Color> getSolidBackground() const override; void render(PaintParameters&, RenderSource*) override; // Paint properties style::BackgroundPaintProperties::Unevaluated unevaluated; - style::BackgroundPaintProperties::PossiblyEvaluated evaluated; - - const style::BackgroundLayer::Impl& impl() const; -private: - CrossfadeParameters crossfade; }; } // namespace mbgl diff --git a/src/mbgl/renderer/layers/render_circle_layer.cpp b/src/mbgl/renderer/layers/render_circle_layer.cpp index ad4e6a020f..9df20cf874 100644 --- a/src/mbgl/renderer/layers/render_circle_layer.cpp +++ b/src/mbgl/renderer/layers/render_circle_layer.cpp @@ -15,21 +15,24 @@ namespace mbgl { using namespace style; -RenderCircleLayer::RenderCircleLayer(Immutable<style::CircleLayer::Impl> _impl) - : RenderLayer(std::move(_impl)), - unevaluated(impl().paint.untransitioned()) { +inline const style::CircleLayer::Impl& impl(const Immutable<style::Layer::Impl>& impl) { + return static_cast<const style::CircleLayer::Impl&>(*impl); } -const style::CircleLayer::Impl& RenderCircleLayer::impl() const { - return static_cast<const style::CircleLayer::Impl&>(*baseImpl); +RenderCircleLayer::RenderCircleLayer(Immutable<style::CircleLayer::Impl> _impl) + : RenderLayer(makeMutable<CircleLayerProperties>(std::move(_impl))), + unevaluated(impl(baseImpl).paint.untransitioned()) { } void RenderCircleLayer::transition(const TransitionParameters& parameters) { - unevaluated = impl().paint.transitioned(parameters, std::move(unevaluated)); + unevaluated = impl(baseImpl).paint.transitioned(parameters, std::move(unevaluated)); } void RenderCircleLayer::evaluate(const PropertyEvaluationParameters& parameters) { - evaluated = unevaluated.evaluate(parameters); + auto properties = makeMutable<CircleLayerProperties>( + staticImmutableCast<CircleLayer::Impl>(baseImpl), + unevaluated.evaluate(parameters)); + const auto& evaluated = properties->evaluated; passes = ((evaluated.get<style::CircleRadius>().constantOr(1) > 0 || evaluated.get<style::CircleStrokeWidth>().constantOr(1) > 0) @@ -38,6 +41,7 @@ void RenderCircleLayer::evaluate(const PropertyEvaluationParameters& parameters) && (evaluated.get<style::CircleOpacity>().constantOr(1) > 0 || evaluated.get<style::CircleStrokeOpacity>().constantOr(1) > 0)) ? RenderPass::Translucent : RenderPass::None; + evaluatedProperties = std::move(properties); } bool RenderCircleLayer::hasTransition() const { @@ -52,7 +56,7 @@ void RenderCircleLayer::render(PaintParameters& parameters, RenderSource*) { if (parameters.pass == RenderPass::Opaque) { return; } - + const auto& evaluated = static_cast<const CircleLayerProperties&>(*evaluatedProperties).evaluated; const bool scaleWithMap = evaluated.get<CirclePitchScale>() == CirclePitchScaleType::Map; const bool pitchWithMap = evaluated.get<CirclePitchAlignment>() == AlignmentType::Map; @@ -139,7 +143,7 @@ bool RenderCircleLayer::queryIntersectsFeature( const TransformState& transformState, const float pixelsToTileUnits, const mat4& posMatrix) const { - + const auto& evaluated = static_cast<const CircleLayerProperties&>(*evaluatedProperties).evaluated; // Translate query geometry const GeometryCoordinates& translatedQueryGeometry = FeatureIndex::translateQueryGeometry( queryGeometry, diff --git a/src/mbgl/renderer/layers/render_circle_layer.hpp b/src/mbgl/renderer/layers/render_circle_layer.hpp index 8b0678f6d8..fbe67c91ac 100644 --- a/src/mbgl/renderer/layers/render_circle_layer.hpp +++ b/src/mbgl/renderer/layers/render_circle_layer.hpp @@ -6,11 +6,12 @@ namespace mbgl { -class RenderCircleLayer: public RenderLayer { +class RenderCircleLayer final : public RenderLayer { public: - RenderCircleLayer(Immutable<style::CircleLayer::Impl>); + explicit RenderCircleLayer(Immutable<style::CircleLayer::Impl>); ~RenderCircleLayer() final = default; +private: void transition(const TransitionParameters&) override; void evaluate(const PropertyEvaluationParameters&) override; bool hasTransition() const override; @@ -27,13 +28,6 @@ public: // Paint properties style::CirclePaintProperties::Unevaluated unevaluated; - style::CirclePaintProperties::PossiblyEvaluated evaluated; - - const style::CircleLayer::Impl& impl() const; }; -inline const RenderCircleLayer* toRenderCircleLayer(const RenderLayer* layer) { - return static_cast<const RenderCircleLayer*>(layer); -} - } // namespace mbgl diff --git a/src/mbgl/renderer/layers/render_custom_layer.cpp b/src/mbgl/renderer/layers/render_custom_layer.cpp index 9284ed8238..4148de1ddd 100644 --- a/src/mbgl/renderer/layers/render_custom_layer.cpp +++ b/src/mbgl/renderer/layers/render_custom_layer.cpp @@ -14,8 +14,13 @@ namespace mbgl { using namespace style; +inline const CustomLayer::Impl& impl(const Immutable<style::Layer::Impl>& impl) { + return static_cast<const CustomLayer::Impl&>(*impl); +} + RenderCustomLayer::RenderCustomLayer(Immutable<style::CustomLayer::Impl> _impl) - : RenderLayer(std::move(_impl)), host(impl().host) { + : RenderLayer(makeMutable<CustomLayerProperties>(std::move(_impl))), + host(impl(baseImpl).host) { assert(gfx::BackendScope::exists()); MBGL_CHECK_ERROR(host->initialize()); } @@ -29,12 +34,9 @@ RenderCustomLayer::~RenderCustomLayer() { } } -const CustomLayer::Impl& RenderCustomLayer::impl() const { - return static_cast<const CustomLayer::Impl&>(*baseImpl); -} - void RenderCustomLayer::evaluate(const PropertyEvaluationParameters&) { passes = RenderPass::Translucent; + // It is fine to not update `evaluatedProperties`, as `baseImpl` should never be updated for this layer. } bool RenderCustomLayer::hasTransition() const { @@ -49,12 +51,12 @@ void RenderCustomLayer::markContextDestroyed() { } void RenderCustomLayer::render(PaintParameters& paintParameters, RenderSource*) { - if (host != impl().host) { + if (host != impl(baseImpl).host) { //If the context changed, deinitialize the previous one before initializing the new one. if (host && !contextDestroyed) { MBGL_CHECK_ERROR(host->deinitialize()); } - host = impl().host; + host = impl(baseImpl).host; MBGL_CHECK_ERROR(host->initialize()); } diff --git a/src/mbgl/renderer/layers/render_custom_layer.hpp b/src/mbgl/renderer/layers/render_custom_layer.hpp index 37b8592172..0c364cfc0c 100644 --- a/src/mbgl/renderer/layers/render_custom_layer.hpp +++ b/src/mbgl/renderer/layers/render_custom_layer.hpp @@ -5,22 +5,20 @@ namespace mbgl { -class RenderCustomLayer: public RenderLayer { +class RenderCustomLayer final : public RenderLayer { public: - RenderCustomLayer(Immutable<style::CustomLayer::Impl>); - ~RenderCustomLayer() final; + explicit RenderCustomLayer(Immutable<style::CustomLayer::Impl>); + ~RenderCustomLayer() override; - void transition(const TransitionParameters&) final {} +private: + void transition(const TransitionParameters&) override {} void evaluate(const PropertyEvaluationParameters&) override; bool hasTransition() const override; bool hasCrossfade() const override; - void markContextDestroyed() final; - - void render(PaintParameters&, RenderSource*) final; + void markContextDestroyed() override; - const style::CustomLayer::Impl& impl() const; + void render(PaintParameters&, RenderSource*) override; -private: bool contextDestroyed = false; std::shared_ptr<style::CustomLayerHost> host; }; diff --git a/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp b/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp index 4041e420df..a313f53f1c 100644 --- a/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp +++ b/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp @@ -20,26 +20,31 @@ namespace mbgl { using namespace style; -RenderFillExtrusionLayer::RenderFillExtrusionLayer(Immutable<style::FillExtrusionLayer::Impl> _impl) - : RenderLayer(std::move(_impl)), - unevaluated(impl().paint.untransitioned()) { +inline const FillExtrusionLayer::Impl& impl(const Immutable<style::Layer::Impl>& impl) { + return static_cast<const FillExtrusionLayer::Impl&>(*impl); } -const style::FillExtrusionLayer::Impl& RenderFillExtrusionLayer::impl() const { - return static_cast<const style::FillExtrusionLayer::Impl&>(*baseImpl); +RenderFillExtrusionLayer::RenderFillExtrusionLayer(Immutable<style::FillExtrusionLayer::Impl> _impl) + : RenderLayer(makeMutable<FillExtrusionLayerProperties>(std::move(_impl))), + unevaluated(impl(baseImpl).paint.untransitioned()) { } +RenderFillExtrusionLayer::~RenderFillExtrusionLayer() = default; + void RenderFillExtrusionLayer::transition(const TransitionParameters& parameters) { - unevaluated = impl().paint.transitioned(parameters, std::move(unevaluated)); + unevaluated = impl(baseImpl).paint.transitioned(parameters, std::move(unevaluated)); } void RenderFillExtrusionLayer::evaluate(const PropertyEvaluationParameters& parameters) { - evaluated = unevaluated.evaluate(parameters); - crossfade = parameters.getCrossfadeParameters(); + auto properties = makeMutable<FillExtrusionLayerProperties>( + staticImmutableCast<FillExtrusionLayer::Impl>(baseImpl), + parameters.getCrossfadeParameters(), + unevaluated.evaluate(parameters)); - passes = (evaluated.get<style::FillExtrusionOpacity>() > 0) + passes = (properties->evaluated.get<style::FillExtrusionOpacity>() > 0) ? (RenderPass::Translucent | RenderPass::Pass3D) : RenderPass::None; + evaluatedProperties = std::move(properties); } bool RenderFillExtrusionLayer::hasTransition() const { @@ -47,14 +52,15 @@ bool RenderFillExtrusionLayer::hasTransition() const { } bool RenderFillExtrusionLayer::hasCrossfade() const { - return crossfade.t != 1; + return static_cast<const FillExtrusionLayerProperties&>(*evaluatedProperties).crossfade.t != 1; } void RenderFillExtrusionLayer::render(PaintParameters& parameters, RenderSource*) { if (parameters.pass == RenderPass::Opaque) { return; } - + const auto& evaluated = static_cast<const FillExtrusionLayerProperties&>(*evaluatedProperties).evaluated; + const auto& crossfade = static_cast<const FillExtrusionLayerProperties&>(*evaluatedProperties).crossfade; if (parameters.pass == RenderPass::Pass3D) { const auto& size = parameters.staticData.backendSize; @@ -222,7 +228,7 @@ bool RenderFillExtrusionLayer::queryIntersectsFeature( const TransformState& transformState, const float pixelsToTileUnits, const mat4&) const { - + const auto& evaluated = static_cast<const FillExtrusionLayerProperties&>(*evaluatedProperties).evaluated; auto translatedQueryGeometry = FeatureIndex::translateQueryGeometry( queryGeometry, evaluated.get<style::FillExtrusionTranslate>(), diff --git a/src/mbgl/renderer/layers/render_fill_extrusion_layer.hpp b/src/mbgl/renderer/layers/render_fill_extrusion_layer.hpp index 6f14fcd7a8..fa50ac6f2c 100644 --- a/src/mbgl/renderer/layers/render_fill_extrusion_layer.hpp +++ b/src/mbgl/renderer/layers/render_fill_extrusion_layer.hpp @@ -7,19 +7,12 @@ namespace mbgl { -template <class B> -class PatternLayout; - -class FillExtrusionBucket; - -class RenderFillExtrusionLayer: public RenderLayer { +class RenderFillExtrusionLayer final : public RenderLayer { public: - using StyleLayerImpl = style::FillExtrusionLayer::Impl; - using PatternProperty = style::FillExtrusionPattern; - - RenderFillExtrusionLayer(Immutable<style::FillExtrusionLayer::Impl>); - ~RenderFillExtrusionLayer() final = default; + explicit RenderFillExtrusionLayer(Immutable<style::FillExtrusionLayer::Impl>); + ~RenderFillExtrusionLayer() override; +private: void transition(const TransitionParameters&) override; void evaluate(const PropertyEvaluationParameters&) override; bool hasTransition() const override; @@ -36,17 +29,8 @@ public: // Paint properties style::FillExtrusionPaintProperties::Unevaluated unevaluated; - style::FillExtrusionPaintProperties::PossiblyEvaluated evaluated; - - const style::FillExtrusionLayer::Impl& impl() const; std::unique_ptr<gfx::OffscreenTexture> renderTexture; -private: - CrossfadeParameters crossfade; }; -inline const RenderFillExtrusionLayer* toRenderFillExtrusionLayer(const RenderLayer* layer) { - return static_cast<const RenderFillExtrusionLayer*>(layer); -} - } // namespace mbgl diff --git a/src/mbgl/renderer/layers/render_fill_layer.cpp b/src/mbgl/renderer/layers/render_fill_layer.cpp index e6447c83a4..5b0f020290 100644 --- a/src/mbgl/renderer/layers/render_fill_layer.cpp +++ b/src/mbgl/renderer/layers/render_fill_layer.cpp @@ -20,22 +20,27 @@ namespace mbgl { using namespace style; -RenderFillLayer::RenderFillLayer(Immutable<style::FillLayer::Impl> _impl) - : RenderLayer(std::move(_impl)), - unevaluated(impl().paint.untransitioned()) { +inline const FillLayer::Impl& impl(const Immutable<style::Layer::Impl>& impl) { + return static_cast<const FillLayer::Impl&>(*impl); } -const style::FillLayer::Impl& RenderFillLayer::impl() const { - return static_cast<const style::FillLayer::Impl&>(*baseImpl); +RenderFillLayer::RenderFillLayer(Immutable<style::FillLayer::Impl> _impl) + : RenderLayer(makeMutable<FillLayerProperties>(std::move(_impl))), + unevaluated(impl(baseImpl).paint.untransitioned()) { } +RenderFillLayer::~RenderFillLayer() = default; + void RenderFillLayer::transition(const TransitionParameters& parameters) { - unevaluated = impl().paint.transitioned(parameters, std::move(unevaluated)); + unevaluated = impl(baseImpl).paint.transitioned(parameters, std::move(unevaluated)); } void RenderFillLayer::evaluate(const PropertyEvaluationParameters& parameters) { - evaluated = unevaluated.evaluate(parameters); - crossfade = parameters.getCrossfadeParameters(); + auto properties = makeMutable<FillLayerProperties>( + staticImmutableCast<FillLayer::Impl>(baseImpl), + parameters.getCrossfadeParameters(), + unevaluated.evaluate(parameters)); + auto& evaluated = properties->evaluated; if (unevaluated.get<style::FillOutlineColor>().isUndefined()) { evaluated.get<style::FillOutlineColor>() = evaluated.get<style::FillColor>(); @@ -54,6 +59,8 @@ void RenderFillLayer::evaluate(const PropertyEvaluationParameters& parameters) { } else { passes |= RenderPass::Opaque; } + + evaluatedProperties = std::move(properties); } bool RenderFillLayer::hasTransition() const { @@ -61,10 +68,12 @@ bool RenderFillLayer::hasTransition() const { } bool RenderFillLayer::hasCrossfade() const { - return crossfade.t != 1; + return static_cast<const FillLayerProperties&>(*evaluatedProperties).crossfade.t != 1; } void RenderFillLayer::render(PaintParameters& parameters, RenderSource*) { + const auto& evaluated = static_cast<const FillLayerProperties&>(*evaluatedProperties).evaluated; + const auto& crossfade = static_cast<const FillLayerProperties&>(*evaluatedProperties).crossfade; if (unevaluated.get<FillPattern>().isUndefined()) { for (const RenderTile& tile : renderTiles) { auto bucket_ = tile.tile.getBucket<FillBucket>(*baseImpl); @@ -240,7 +249,7 @@ bool RenderFillLayer::queryIntersectsFeature( const TransformState& transformState, const float pixelsToTileUnits, const mat4&) const { - + const auto& evaluated = static_cast<const FillLayerProperties&>(*evaluatedProperties).evaluated; auto translatedQueryGeometry = FeatureIndex::translateQueryGeometry( queryGeometry, evaluated.get<style::FillTranslate>(), diff --git a/src/mbgl/renderer/layers/render_fill_layer.hpp b/src/mbgl/renderer/layers/render_fill_layer.hpp index 1c7ee6556e..5d5206efe2 100644 --- a/src/mbgl/renderer/layers/render_fill_layer.hpp +++ b/src/mbgl/renderer/layers/render_fill_layer.hpp @@ -9,14 +9,12 @@ namespace mbgl { class FillBucket; -class RenderFillLayer: public RenderLayer { +class RenderFillLayer final : public RenderLayer { public: - using StyleLayerImpl = style::FillLayer::Impl; - using PatternProperty = style::FillPattern; - - RenderFillLayer(Immutable<style::FillLayer::Impl>); - ~RenderFillLayer() final = default; + explicit RenderFillLayer(Immutable<style::FillLayer::Impl>); + ~RenderFillLayer() override; +private: void transition(const TransitionParameters&) override; void evaluate(const PropertyEvaluationParameters&) override; bool hasTransition() const override; @@ -33,16 +31,6 @@ public: // Paint properties style::FillPaintProperties::Unevaluated unevaluated; - style::FillPaintProperties::PossiblyEvaluated evaluated; - - const style::FillLayer::Impl& impl() const; -private: - CrossfadeParameters crossfade; - }; -inline const RenderFillLayer* toRenderFillLayer(const RenderLayer* layer) { - return static_cast<const RenderFillLayer*>(layer); -} - } // namespace mbgl diff --git a/src/mbgl/renderer/layers/render_heatmap_layer.cpp b/src/mbgl/renderer/layers/render_heatmap_layer.cpp index 333b8f9890..92b54c6cc8 100644 --- a/src/mbgl/renderer/layers/render_heatmap_layer.cpp +++ b/src/mbgl/renderer/layers/render_heatmap_layer.cpp @@ -19,25 +19,31 @@ namespace mbgl { using namespace style; -RenderHeatmapLayer::RenderHeatmapLayer(Immutable<style::HeatmapLayer::Impl> _impl) - : RenderLayer(std::move(_impl)), - unevaluated(impl().paint.untransitioned()), colorRamp({256, 1}) { +inline const HeatmapLayer::Impl& impl(const Immutable<Layer::Impl>& impl) { + return static_cast<const HeatmapLayer::Impl&>(*impl); } -const style::HeatmapLayer::Impl& RenderHeatmapLayer::impl() const { - return static_cast<const style::HeatmapLayer::Impl&>(*baseImpl); +RenderHeatmapLayer::RenderHeatmapLayer(Immutable<HeatmapLayer::Impl> _impl) + : RenderLayer(makeMutable<HeatmapLayerProperties>(std::move(_impl))), + unevaluated(impl(baseImpl).paint.untransitioned()), colorRamp({256, 1}) { } +RenderHeatmapLayer::~RenderHeatmapLayer() = default; + void RenderHeatmapLayer::transition(const TransitionParameters& parameters) { - unevaluated = impl().paint.transitioned(parameters, std::move(unevaluated)); + unevaluated = impl(baseImpl).paint.transitioned(parameters, std::move(unevaluated)); } void RenderHeatmapLayer::evaluate(const PropertyEvaluationParameters& parameters) { - evaluated = unevaluated.evaluate(parameters); + auto properties = makeMutable<HeatmapLayerProperties>( + staticImmutableCast<HeatmapLayer::Impl>(baseImpl), + unevaluated.evaluate(parameters)); - passes = (evaluated.get<style::HeatmapOpacity>() > 0) + passes = (properties->evaluated.get<style::HeatmapOpacity>() > 0) ? (RenderPass::Translucent | RenderPass::Pass3D) : RenderPass::None; + + evaluatedProperties = std::move(properties); } bool RenderHeatmapLayer::hasTransition() const { @@ -52,7 +58,7 @@ void RenderHeatmapLayer::render(PaintParameters& parameters, RenderSource*) { if (parameters.pass == RenderPass::Opaque) { return; } - + const auto& evaluated = static_cast<const HeatmapLayerProperties&>(*evaluatedProperties).evaluated; if (parameters.pass == RenderPass::Pass3D) { const auto& viewportSize = parameters.staticData.backendSize; const auto size = Size{viewportSize.width / 4, viewportSize.height / 4}; diff --git a/src/mbgl/renderer/layers/render_heatmap_layer.hpp b/src/mbgl/renderer/layers/render_heatmap_layer.hpp index 22fe48f374..50a7d72e94 100644 --- a/src/mbgl/renderer/layers/render_heatmap_layer.hpp +++ b/src/mbgl/renderer/layers/render_heatmap_layer.hpp @@ -9,11 +9,12 @@ namespace mbgl { -class RenderHeatmapLayer: public RenderLayer { +class RenderHeatmapLayer final : public RenderLayer { public: - RenderHeatmapLayer(Immutable<style::HeatmapLayer::Impl>); - ~RenderHeatmapLayer() final = default; + explicit RenderHeatmapLayer(Immutable<style::HeatmapLayer::Impl>); + ~RenderHeatmapLayer() override; +private: void transition(const TransitionParameters&) override; void evaluate(const PropertyEvaluationParameters&) override; bool hasTransition() const override; @@ -31,20 +32,11 @@ public: // Paint properties style::HeatmapPaintProperties::Unevaluated unevaluated; - style::HeatmapPaintProperties::PossiblyEvaluated evaluated; - - const style::HeatmapLayer::Impl& impl() const; - PremultipliedImage colorRamp; std::unique_ptr<gfx::OffscreenTexture> renderTexture; optional<gfx::Texture> colorRampTexture; -private: void updateColorRamp(); }; -inline const RenderHeatmapLayer* toRenderHeatmapLayer(const RenderLayer* layer) { - return static_cast<const RenderHeatmapLayer*>(layer); -} - } // namespace mbgl diff --git a/src/mbgl/renderer/layers/render_hillshade_layer.cpp b/src/mbgl/renderer/layers/render_hillshade_layer.cpp index 08efa898f6..19af5b6202 100644 --- a/src/mbgl/renderer/layers/render_hillshade_layer.cpp +++ b/src/mbgl/renderer/layers/render_hillshade_layer.cpp @@ -17,36 +17,44 @@ namespace mbgl { using namespace style; -RenderHillshadeLayer::RenderHillshadeLayer(Immutable<style::HillshadeLayer::Impl> _impl) - : RenderLayer(std::move(_impl)), - unevaluated(impl().paint.untransitioned()) { + +inline const HillshadeLayer::Impl& impl(const Immutable<style::Layer::Impl>& impl) { + return static_cast<const HillshadeLayer::Impl&>(*impl); } -const style::HillshadeLayer::Impl& RenderHillshadeLayer::impl() const { - return static_cast<const style::HillshadeLayer::Impl&>(*baseImpl); +RenderHillshadeLayer::RenderHillshadeLayer(Immutable<style::HillshadeLayer::Impl> _impl) + : RenderLayer(makeMutable<HillshadeLayerProperties>(std::move(_impl))), + unevaluated(impl(baseImpl).paint.untransitioned()) { } +RenderHillshadeLayer::~RenderHillshadeLayer() = default; + const std::array<float, 2> RenderHillshadeLayer::getLatRange(const UnwrappedTileID& id) { const LatLng latlng0 = LatLng(id); const LatLng latlng1 = LatLng(UnwrappedTileID(id.canonical.z, id.canonical.x, id.canonical.y + 1)); return {{ (float)latlng0.latitude(), (float)latlng1.latitude() }}; } -const std::array<float, 2> RenderHillshadeLayer::getLight(const PaintParameters& parameters){ +const std::array<float, 2> RenderHillshadeLayer::getLight(const PaintParameters& parameters) { + const auto& evaluated = static_cast<const HillshadeLayerProperties&>(*evaluatedProperties).evaluated; float azimuthal = evaluated.get<HillshadeIlluminationDirection>() * util::DEG2RAD; if (evaluated.get<HillshadeIlluminationAnchor>() == HillshadeIlluminationAnchorType::Viewport) azimuthal = azimuthal - parameters.state.getBearing(); return {{evaluated.get<HillshadeExaggeration>(), azimuthal}}; } void RenderHillshadeLayer::transition(const TransitionParameters& parameters) { - unevaluated = impl().paint.transitioned(parameters, std::move(unevaluated)); + unevaluated = impl(baseImpl).paint.transitioned(parameters, std::move(unevaluated)); } void RenderHillshadeLayer::evaluate(const PropertyEvaluationParameters& parameters) { - evaluated = unevaluated.evaluate(parameters); - passes = (evaluated.get<style::HillshadeExaggeration >() > 0) + auto properties = makeMutable<HillshadeLayerProperties>( + staticImmutableCast<HillshadeLayer::Impl>(baseImpl), + unevaluated.evaluate(parameters)); + passes = (properties->evaluated.get<style::HillshadeExaggeration >() > 0) ? (RenderPass::Translucent | RenderPass::Pass3D) : RenderPass::None; + + evaluatedProperties = std::move(properties); } bool RenderHillshadeLayer::hasTransition() const { @@ -60,7 +68,7 @@ bool RenderHillshadeLayer::hasCrossfade() const { void RenderHillshadeLayer::render(PaintParameters& parameters, RenderSource* src) { if (parameters.pass != RenderPass::Translucent && parameters.pass != RenderPass::Pass3D) return; - + const auto& evaluated = static_cast<const HillshadeLayerProperties&>(*evaluatedProperties).evaluated; auto* demsrc = static_cast<RenderRasterDEMSource*>(src); const uint8_t TERRAIN_RGB_MAXZOOM = 15; const uint8_t maxzoom = demsrc != nullptr ? demsrc->getMaxZoom() : TERRAIN_RGB_MAXZOOM; diff --git a/src/mbgl/renderer/layers/render_hillshade_layer.hpp b/src/mbgl/renderer/layers/render_hillshade_layer.hpp index 3985389763..7c7bc10835 100644 --- a/src/mbgl/renderer/layers/render_hillshade_layer.hpp +++ b/src/mbgl/renderer/layers/render_hillshade_layer.hpp @@ -9,9 +9,10 @@ namespace mbgl { class RenderHillshadeLayer: public RenderLayer { public: - RenderHillshadeLayer(Immutable<style::HillshadeLayer::Impl>); - ~RenderHillshadeLayer() final = default; + explicit RenderHillshadeLayer(Immutable<style::HillshadeLayer::Impl>); + ~RenderHillshadeLayer() override; +private: void transition(const TransitionParameters&) override; void evaluate(const PropertyEvaluationParameters&) override; bool hasTransition() const override; @@ -21,10 +22,7 @@ public: // Paint properties style::HillshadePaintProperties::Unevaluated unevaluated; - style::HillshadePaintProperties::PossiblyEvaluated evaluated; - const style::HillshadeLayer::Impl& impl() const; -private: const std::array<float, 2> getLatRange(const UnwrappedTileID& id); const std::array<float, 2> getLight(const PaintParameters& parameters); }; diff --git a/src/mbgl/renderer/layers/render_line_layer.cpp b/src/mbgl/renderer/layers/render_line_layer.cpp index 2ea910f911..cf4d3ed9b2 100644 --- a/src/mbgl/renderer/layers/render_line_layer.cpp +++ b/src/mbgl/renderer/layers/render_line_layer.cpp @@ -18,28 +18,34 @@ namespace mbgl { using namespace style; +inline const LineLayer::Impl& impl(const Immutable<style::Layer::Impl>& impl) { + return static_cast<const LineLayer::Impl&>(*impl); +} + RenderLineLayer::RenderLineLayer(Immutable<style::LineLayer::Impl> _impl) - : RenderLayer(std::move(_impl)), - unevaluated(impl().paint.untransitioned()), + : RenderLayer(makeMutable<LineLayerProperties>(std::move(_impl))), + unevaluated(impl(baseImpl).paint.untransitioned()), colorRamp({256, 1}) { } -const style::LineLayer::Impl& RenderLineLayer::impl() const { - return static_cast<const style::LineLayer::Impl&>(*baseImpl); -} +RenderLineLayer::~RenderLineLayer() = default; void RenderLineLayer::transition(const TransitionParameters& parameters) { - unevaluated = impl().paint.transitioned(parameters, std::move(unevaluated)); + unevaluated = impl(baseImpl).paint.transitioned(parameters, std::move(unevaluated)); } void RenderLineLayer::evaluate(const PropertyEvaluationParameters& parameters) { - evaluated = unevaluated.evaluate(parameters); - crossfade = parameters.getCrossfadeParameters(); + auto properties = makeMutable<LineLayerProperties>( + staticImmutableCast<LineLayer::Impl>(baseImpl), + parameters.getCrossfadeParameters(), + unevaluated.evaluate(parameters)); + auto& evaluated = properties->evaluated; passes = (evaluated.get<style::LineOpacity>().constantOr(1.0) > 0 && evaluated.get<style::LineColor>().constantOr(Color::black()).a > 0 && evaluated.get<style::LineWidth>().constantOr(1.0) > 0) ? RenderPass::Translucent : RenderPass::None; + evaluatedProperties = std::move(properties); } bool RenderLineLayer::hasTransition() const { @@ -47,13 +53,15 @@ bool RenderLineLayer::hasTransition() const { } bool RenderLineLayer::hasCrossfade() const { - return crossfade.t != 1; + return static_cast<const LineLayerProperties&>(*evaluatedProperties).crossfade.t != 1; } void RenderLineLayer::render(PaintParameters& parameters, RenderSource*) { if (parameters.pass == RenderPass::Opaque) { return; } + const auto& evaluated = static_cast<const LineLayerProperties&>(*evaluatedProperties).evaluated; + const auto& crossfade = static_cast<const LineLayerProperties&>(*evaluatedProperties).crossfade; for (const RenderTile& tile : renderTiles) { auto bucket_ = tile.tile.getBucket<LineBucket>(*baseImpl); @@ -213,7 +221,7 @@ bool RenderLineLayer::queryIntersectsFeature( const TransformState& transformState, const float pixelsToTileUnits, const mat4&) const { - + const auto& evaluated = static_cast<const LineLayerProperties&>(*evaluatedProperties).evaluated; // Translate query geometry auto translatedQueryGeometry = FeatureIndex::translateQueryGeometry( queryGeometry, @@ -259,6 +267,7 @@ void RenderLineLayer::updateColorRamp() { } float RenderLineLayer::getLineWidth(const GeometryTileFeature& feature, const float zoom) const { + const auto& evaluated = static_cast<const LineLayerProperties&>(*evaluatedProperties).evaluated; float lineWidth = evaluated.get<style::LineWidth>() .evaluate(feature, zoom, style::LineWidth::defaultValue()); float gapWidth = evaluated.get<style::LineGapWidth>() diff --git a/src/mbgl/renderer/layers/render_line_layer.hpp b/src/mbgl/renderer/layers/render_line_layer.hpp index cb4492ebc3..da64f58455 100644 --- a/src/mbgl/renderer/layers/render_line_layer.hpp +++ b/src/mbgl/renderer/layers/render_line_layer.hpp @@ -10,20 +10,18 @@ namespace mbgl { -class RenderLineLayer: public RenderLayer { +class RenderLineLayer final : public RenderLayer { public: - using StyleLayerImpl = style::LineLayer::Impl; - using PatternProperty = style::LinePattern; - - RenderLineLayer(Immutable<style::LineLayer::Impl>); - ~RenderLineLayer() final = default; + explicit RenderLineLayer(Immutable<style::LineLayer::Impl>); + ~RenderLineLayer() override; +private: void transition(const TransitionParameters&) override; void evaluate(const PropertyEvaluationParameters&) override; bool hasTransition() const override; bool hasCrossfade() const override; void render(PaintParameters&, RenderSource*) override; - void update() final; + void update() override; bool queryIntersectsFeature( const GeometryCoordinates&, @@ -35,20 +33,12 @@ public: // Paint properties style::LinePaintProperties::Unevaluated unevaluated; - style::LinePaintProperties::PossiblyEvaluated evaluated; - - const style::LineLayer::Impl& impl() const; -private: float getLineWidth(const GeometryTileFeature&, const float) const; void updateColorRamp(); - CrossfadeParameters crossfade; + PremultipliedImage colorRamp; optional<gfx::Texture> colorRampTexture; }; -inline const RenderLineLayer* toRenderLineLayer(const RenderLayer* layer) { - return static_cast<const RenderLineLayer*>(layer); -} - } // namespace mbgl diff --git a/src/mbgl/renderer/layers/render_raster_layer.cpp b/src/mbgl/renderer/layers/render_raster_layer.cpp index 55caeaf5b0..48ca0584fc 100644 --- a/src/mbgl/renderer/layers/render_raster_layer.cpp +++ b/src/mbgl/renderer/layers/render_raster_layer.cpp @@ -14,23 +14,27 @@ namespace mbgl { using namespace style; -RenderRasterLayer::RenderRasterLayer(Immutable<style::RasterLayer::Impl> _impl) - : RenderLayer(std::move(_impl)), - unevaluated(impl().paint.untransitioned()) { +inline const RasterLayer::Impl& impl(const Immutable<style::Layer::Impl>& impl) { + return static_cast<const RasterLayer::Impl&>(*impl); } -const style::RasterLayer::Impl& RenderRasterLayer::impl() const { - return static_cast<const style::RasterLayer::Impl&>(*baseImpl); +RenderRasterLayer::RenderRasterLayer(Immutable<style::RasterLayer::Impl> _impl) + : RenderLayer(makeMutable<RasterLayerProperties>(std::move(_impl))), + unevaluated(impl(baseImpl).paint.untransitioned()) { } +RenderRasterLayer::~RenderRasterLayer() = default; + void RenderRasterLayer::transition(const TransitionParameters& parameters) { - unevaluated = impl().paint.transitioned(parameters, std::move(unevaluated)); + unevaluated = impl(baseImpl).paint.transitioned(parameters, std::move(unevaluated)); } void RenderRasterLayer::evaluate(const PropertyEvaluationParameters& parameters) { - evaluated = unevaluated.evaluate(parameters); - - passes = evaluated.get<style::RasterOpacity>() > 0 ? RenderPass::Translucent : RenderPass::None; + auto properties = makeMutable<RasterLayerProperties>( + staticImmutableCast<RasterLayer::Impl>(baseImpl), + unevaluated.evaluate(parameters)); + passes = properties->evaluated.get<style::RasterOpacity>() > 0 ? RenderPass::Translucent : RenderPass::None; + evaluatedProperties = std::move(properties); } bool RenderRasterLayer::hasTransition() const { @@ -72,7 +76,7 @@ static std::array<float, 3> spinWeights(float spin) { void RenderRasterLayer::render(PaintParameters& parameters, RenderSource* source) { if (parameters.pass != RenderPass::Translucent) return; - + const auto& evaluated = static_cast<const RasterLayerProperties&>(*evaluatedProperties).evaluated; RasterProgram::Binders paintAttributeData{ evaluated, 0 }; auto draw = [&] (const mat4& matrix, diff --git a/src/mbgl/renderer/layers/render_raster_layer.hpp b/src/mbgl/renderer/layers/render_raster_layer.hpp index 516c163c27..9d70e9fb4d 100644 --- a/src/mbgl/renderer/layers/render_raster_layer.hpp +++ b/src/mbgl/renderer/layers/render_raster_layer.hpp @@ -6,11 +6,12 @@ namespace mbgl { -class RenderRasterLayer: public RenderLayer { +class RenderRasterLayer final : public RenderLayer { public: - RenderRasterLayer(Immutable<style::RasterLayer::Impl>); - ~RenderRasterLayer() final = default; + explicit RenderRasterLayer(Immutable<style::RasterLayer::Impl>); + ~RenderRasterLayer() override; +private: void transition(const TransitionParameters&) override; void evaluate(const PropertyEvaluationParameters&) override; bool hasTransition() const override; @@ -20,9 +21,6 @@ public: // Paint properties style::RasterPaintProperties::Unevaluated unevaluated; - style::RasterPaintProperties::PossiblyEvaluated evaluated; - - const style::RasterLayer::Impl& impl() const; }; } // namespace mbgl diff --git a/src/mbgl/renderer/layers/render_symbol_layer.cpp b/src/mbgl/renderer/layers/render_symbol_layer.cpp index 634e0cf01b..95df9435f9 100644 --- a/src/mbgl/renderer/layers/render_symbol_layer.cpp +++ b/src/mbgl/renderer/layers/render_symbol_layer.cpp @@ -306,24 +306,29 @@ void drawText(const DrawFn& draw, }); } } + +inline const SymbolLayer::Impl& impl(const Immutable<style::Layer::Impl>& impl) { + return static_cast<const SymbolLayer::Impl&>(*impl); +} + } // namespace RenderSymbolLayer::RenderSymbolLayer(Immutable<style::SymbolLayer::Impl> _impl) - : RenderLayer(std::move(_impl)), - unevaluated(impl().paint.untransitioned()) { + : RenderLayer(makeMutable<SymbolLayerProperties>(std::move(_impl))), + unevaluated(impl(baseImpl).paint.untransitioned()) { } -const style::SymbolLayer::Impl& RenderSymbolLayer::impl() const { - return static_cast<const style::SymbolLayer::Impl&>(*baseImpl); -} +RenderSymbolLayer::~RenderSymbolLayer() = default; void RenderSymbolLayer::transition(const TransitionParameters& parameters) { - unevaluated = impl().paint.transitioned(parameters, std::move(unevaluated)); + unevaluated = impl(baseImpl).paint.transitioned(parameters, std::move(unevaluated)); } void RenderSymbolLayer::evaluate(const PropertyEvaluationParameters& parameters) { - evaluated = unevaluated.evaluate(parameters); - + auto properties = makeMutable<SymbolLayerProperties>( + staticImmutableCast<SymbolLayer::Impl>(baseImpl), + unevaluated.evaluate(parameters)); + const auto& evaluated = properties->evaluated; auto hasIconOpacity = evaluated.get<style::IconColor>().constantOr(Color::black()).a > 0 || evaluated.get<style::IconHaloColor>().constantOr(Color::black()).a > 0; auto hasTextOpacity = evaluated.get<style::TextColor>().constantOr(Color::black()).a > 0 || @@ -332,6 +337,7 @@ void RenderSymbolLayer::evaluate(const PropertyEvaluationParameters& parameters) passes = ((evaluated.get<style::IconOpacity>().constantOr(1) > 0 && hasIconOpacity && iconSize > 0) || (evaluated.get<style::TextOpacity>().constantOr(1) > 0 && hasTextOpacity && textSize > 0)) ? RenderPass::Translucent : RenderPass::None; + evaluatedProperties = std::move(properties); } bool RenderSymbolLayer::hasTransition() const { @@ -363,7 +369,7 @@ void RenderSymbolLayer::render(PaintParameters& parameters, RenderSource*) { return; } - const bool sortFeaturesByKey = !impl().layout.get<SymbolSortKey>().isUndefined(); + const bool sortFeaturesByKey = !impl(baseImpl).layout.get<SymbolSortKey>().isUndefined(); std::set<RenderableSegment> renderableSegments; const auto draw = [¶meters, this] (auto& programInstance, @@ -598,6 +604,7 @@ void RenderSymbolLayer::setRenderTiles(RenderTiles tiles, const TransformState& void RenderSymbolLayer::updateBucketPaintProperties(Bucket* bucket) const { assert(bucket->supportsLayer(*baseImpl)); + const auto& evaluated = static_cast<const SymbolLayerProperties&>(*evaluatedProperties).evaluated; static_cast<SymbolBucket*>(bucket)->updatePaintProperties(getID(), evaluated); } diff --git a/src/mbgl/renderer/layers/render_symbol_layer.hpp b/src/mbgl/renderer/layers/render_symbol_layer.hpp index 7b6d249b2e..552dd30ca2 100644 --- a/src/mbgl/renderer/layers/render_symbol_layer.hpp +++ b/src/mbgl/renderer/layers/render_symbol_layer.hpp @@ -53,15 +53,15 @@ public: } // namespace style -class BucketParameters; -class SymbolLayout; -class GeometryTileLayer; - class RenderSymbolLayer final: public RenderLayer, public RenderLayerSymbolInterface { public: - RenderSymbolLayer(Immutable<style::SymbolLayer::Impl>); - ~RenderSymbolLayer() final = default; + explicit RenderSymbolLayer(Immutable<style::SymbolLayer::Impl>); + ~RenderSymbolLayer() override; + static style::IconPaintProperties::PossiblyEvaluated iconPaintProperties(const style::SymbolPaintProperties::PossiblyEvaluated&); + static style::TextPaintProperties::PossiblyEvaluated textPaintProperties(const style::SymbolPaintProperties::PossiblyEvaluated&); + +private: void transition(const TransitionParameters&) override; void evaluate(const PropertyEvaluationParameters&) override; bool hasTransition() const override; @@ -69,30 +69,20 @@ public: void render(PaintParameters&, RenderSource*) override; void setRenderTiles(RenderTiles, const TransformState&) override; - static style::IconPaintProperties::PossiblyEvaluated iconPaintProperties(const style::SymbolPaintProperties::PossiblyEvaluated&); - static style::TextPaintProperties::PossiblyEvaluated textPaintProperties(const style::SymbolPaintProperties::PossiblyEvaluated&); - // RenderLayerSymbolInterface overrides - const RenderLayerSymbolInterface* getSymbolInterface() const final; - const std::string& layerID() const final; - const std::vector<std::reference_wrapper<RenderTile>>& getRenderTiles() const final; - SymbolBucket* getSymbolBucket(const RenderTile&) const final; + const RenderLayerSymbolInterface* getSymbolInterface() const override; + const std::string& layerID() const override; + const std::vector<std::reference_wrapper<RenderTile>>& getRenderTiles() const override; + SymbolBucket* getSymbolBucket(const RenderTile&) const override; // Paint properties style::SymbolPaintProperties::Unevaluated unevaluated; - style::SymbolPaintProperties::PossiblyEvaluated evaluated; float iconSize = 1.0f; float textSize = 16.0f; - const style::SymbolLayer::Impl& impl() const; - protected: void updateBucketPaintProperties(Bucket*) const final; }; -inline const RenderSymbolLayer* toRenderSymbolLayer(const RenderLayer* layer) { - return static_cast<const RenderSymbolLayer*>(layer); -} - } // namespace mbgl diff --git a/src/mbgl/renderer/render_layer.cpp b/src/mbgl/renderer/render_layer.cpp index 24a45b9146..c2719fef91 100644 --- a/src/mbgl/renderer/render_layer.cpp +++ b/src/mbgl/renderer/render_layer.cpp @@ -10,8 +10,9 @@ namespace mbgl { using namespace style; -RenderLayer::RenderLayer(Immutable<style::Layer::Impl> baseImpl_) - : baseImpl(std::move(baseImpl_)) { +RenderLayer::RenderLayer(Immutable<style::LayerProperties> properties) + : evaluatedProperties(std::move(properties)), + baseImpl(evaluatedProperties->baseImpl) { } void RenderLayer::setImpl(Immutable<style::Layer::Impl> impl) { diff --git a/src/mbgl/renderer/render_layer.hpp b/src/mbgl/renderer/render_layer.hpp index 98e151435a..9654b9213f 100644 --- a/src/mbgl/renderer/render_layer.hpp +++ b/src/mbgl/renderer/render_layer.hpp @@ -1,7 +1,7 @@ #pragma once #include <mbgl/layout/layout.hpp> #include <mbgl/renderer/render_pass.hpp> -#include <mbgl/style/layer_impl.hpp> +#include <mbgl/style/layer_properties.hpp> #include <mbgl/tile/geometry_tile_data.hpp> #include <mbgl/util/mat4.hpp> @@ -11,7 +11,6 @@ namespace mbgl { class Bucket; -class BucketParameters; class TransitionParameters; class PropertyEvaluationParameters; class PaintParameters; @@ -22,7 +21,7 @@ class TransformState; class RenderLayer { protected: - RenderLayer(Immutable<style::Layer::Impl>); + RenderLayer(Immutable<style::LayerProperties>); public: virtual ~RenderLayer() = default; @@ -31,6 +30,7 @@ public: virtual void transition(const TransitionParameters&) = 0; // Fully evaluate possibly-transitioning paint properties based on a zoom level. + // Updates the contained `evaluatedProperties` member. virtual void evaluate(const PropertyEvaluationParameters&) = 0; // Returns true if any paint properties have active transitions. @@ -65,6 +65,8 @@ public: using RenderTiles = std::vector<std::reference_wrapper<RenderTile>>; virtual void setRenderTiles(RenderTiles, const TransformState&); + // Latest evaluated properties. + Immutable<style::LayerProperties> evaluatedProperties; // Private implementation Immutable<style::Layer::Impl> baseImpl; void setImpl(Immutable<style::Layer::Impl>); diff --git a/src/mbgl/style/layers/custom_layer_impl.hpp b/src/mbgl/style/layers/custom_layer_impl.hpp index 1ebf1b53f1..d8b8a7f286 100644 --- a/src/mbgl/style/layers/custom_layer_impl.hpp +++ b/src/mbgl/style/layers/custom_layer_impl.hpp @@ -1,6 +1,7 @@ #pragma once #include <mbgl/style/layer_impl.hpp> +#include <mbgl/style/layer_properties.hpp> #include <mbgl/style/layers/custom_layer.hpp> #include <memory> @@ -24,5 +25,11 @@ public: DECLARE_LAYER_TYPE_INFO; }; +class CustomLayerProperties final : public LayerProperties { +public: + explicit CustomLayerProperties(Immutable<CustomLayer::Impl> impl) + : LayerProperties(std::move(impl)) {} +}; + } // namespace style } // namespace mbgl diff --git a/src/mbgl/tile/geometry_tile_worker.cpp b/src/mbgl/tile/geometry_tile_worker.cpp index 0c8b7a4ca1..56f6401ce7 100644 --- a/src/mbgl/tile/geometry_tile_worker.cpp +++ b/src/mbgl/tile/geometry_tile_worker.cpp @@ -312,22 +312,23 @@ void GeometryTileWorker::requestNewImages(const ImageDependencies& imageDependen } } -static std::vector<std::unique_ptr<RenderLayer>> toRenderLayers(const std::vector<Immutable<style::Layer::Impl>>& layers, float zoom) { - std::vector<std::unique_ptr<RenderLayer>> renderLayers; - renderLayers.reserve(layers.size()); +static std::vector<Immutable<style::LayerProperties>> toEvaluatedProperties(const std::vector<Immutable<style::Layer::Impl>>& layers, float zoom) { + std::vector<Immutable<style::LayerProperties>> result; + result.reserve(layers.size()); for (auto& layer : layers) { - renderLayers.push_back(LayerManager::get()->createRenderLayer(layer)); + auto renderLayer = LayerManager::get()->createRenderLayer(layer); - renderLayers.back()->transition(TransitionParameters { + renderLayer->transition(TransitionParameters { Clock::time_point::max(), TransitionOptions() }); - renderLayers.back()->evaluate(PropertyEvaluationParameters { + renderLayer->evaluate(PropertyEvaluationParameters { zoom }); + result.push_back(renderLayer->evaluatedProperties); } - return renderLayers; + return result; } void GeometryTileWorker::parse() { @@ -348,10 +349,14 @@ void GeometryTileWorker::parse() { ImageDependencies imageDependencies; // Create render layers and group by layout - std::vector<std::unique_ptr<RenderLayer>> renderLayers = toRenderLayers(*layers, id.overscaledZ); - std::vector<std::vector<const RenderLayer*>> groups = groupByLayout(renderLayers); + std::vector<Immutable<style::LayerProperties>> evaluatedProperties = toEvaluatedProperties(*layers, id.overscaledZ); + std::unordered_map<std::string, std::vector<Immutable<style::LayerProperties>>> groupMap; + for (auto layer : evaluatedProperties) { + groupMap[layoutKey(*layer->baseImpl)].push_back(std::move(layer)); + } - for (auto& group : groups) { + for (auto& pair : groupMap) { + const auto& group = pair.second; if (obsolete) { return; } @@ -360,35 +365,35 @@ void GeometryTileWorker::parse() { continue; // Tile has no data. } - const RenderLayer& leader = *group.at(0); - BucketParameters parameters { id, mode, pixelRatio, leader.baseImpl->getTypeInfo() }; + const style::Layer::Impl& leaderImpl = *(group.at(0)->baseImpl); + BucketParameters parameters { id, mode, pixelRatio, leaderImpl.getTypeInfo() }; - auto geometryLayer = (*data)->getLayer(leader.baseImpl->sourceLayer); + auto geometryLayer = (*data)->getLayer(leaderImpl.sourceLayer); if (!geometryLayer) { continue; } - std::vector<std::string> layerIDs; + std::vector<std::string> layerIDs(group.size()); for (const auto& layer : group) { - layerIDs.push_back(layer->getID()); + layerIDs.push_back(layer->baseImpl->id); } - featureIndex->setBucketLayerIDs(leader.getID(), layerIDs); + featureIndex->setBucketLayerIDs(leaderImpl.id, layerIDs); // Symbol layers and layers that support pattern properties have an extra step at layout time to figure out what images/glyphs // are needed to render the layer. They use the intermediate Layout data structure to accomplish this, // and either immediately create a bucket if no images/glyphs are used, or the Layout is stored until // the images/glyphs are available to add the features to the buckets. - if (leader.baseImpl->getTypeInfo()->layout == LayerTypeInfo::Layout::Required) { - auto layout = LayerManager::get()->createLayout({parameters, glyphDependencies, imageDependencies}, std::move(geometryLayer), group); + if (leaderImpl.getTypeInfo()->layout == LayerTypeInfo::Layout::Required) { + std::unique_ptr<Layout> layout = LayerManager::get()->createLayout({parameters, glyphDependencies, imageDependencies}, std::move(geometryLayer), group); if (layout->hasDependencies()) { layouts.push_back(std::move(layout)); } else { layout->createBucket({}, featureIndex, buckets, firstLoad, showCollisionBoxes); } } else { - const Filter& filter = leader.baseImpl->filter; - const std::string& sourceLayerID = leader.baseImpl->sourceLayer; + const Filter& filter = leaderImpl.filter; + const std::string& sourceLayerID = leaderImpl.sourceLayer; std::shared_ptr<Bucket> bucket = LayerManager::get()->createBucket(parameters, group); for (std::size_t i = 0; !obsolete && i < geometryLayer->featureCount(); i++) { @@ -399,7 +404,7 @@ void GeometryTileWorker::parse() { GeometryCollection geometries = feature->getGeometries(); bucket->addFeature(*feature, geometries, {}, PatternLayerMap ()); - featureIndex->insert(geometries, i, sourceLayerID, leader.getID()); + featureIndex->insert(geometries, i, sourceLayerID, leaderImpl.id); } if (!bucket->hasData()) { @@ -407,7 +412,7 @@ void GeometryTileWorker::parse() { } for (const auto& layer : group) { - buckets.emplace(layer->getID(), bucket); + buckets.emplace(layer->baseImpl->id, bucket); } } } diff --git a/src/mbgl/tile/geometry_tile_worker.hpp b/src/mbgl/tile/geometry_tile_worker.hpp index 4402875603..fb841c63be 100644 --- a/src/mbgl/tile/geometry_tile_worker.hpp +++ b/src/mbgl/tile/geometry_tile_worker.hpp @@ -20,9 +20,6 @@ class GeometryTile; class GeometryTileData; class Layout; -template <class B> -class PatternLayout; - namespace style { class Layer; } // namespace style |