Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[core] Polymorphic bucket creation #2873

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions src/mbgl/annotation/annotation_manager.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <mbgl/annotation/annotation_manager.hpp>
#include <mbgl/annotation/annotation_tile.hpp>
#include <mbgl/style/style.hpp>
#include <mbgl/style/style_bucket.hpp>
#include <mbgl/layer/symbol_layer.hpp>

#include <boost/function_output_iterator.hpp>
Expand Down Expand Up @@ -119,12 +118,10 @@ void AnnotationManager::updateStyle(Style& style) {
layer->id = PointLayerID;
layer->type = StyleLayerType::Symbol;

layer->bucket = std::make_shared<StyleBucket>(layer->type);
layer->bucket->name = layer->id;
layer->bucket->source = SourceID;
layer->bucket->source_layer = PointLayerID;
layer->bucket->layout.set(PropertyKey::IconImage, ConstantFunction<std::string>("{sprite}"));
layer->bucket->layout.set(PropertyKey::IconAllowOverlap, ConstantFunction<bool>(true));
layer->source = SourceID;
layer->sourceLayer = PointLayerID;
layer->layout.set(PropertyKey::IconImage, ConstantFunction<std::string>("{sprite}"));
layer->layout.set(PropertyKey::IconAllowOverlap, ConstantFunction<bool>(true));

style.addLayer(std::move(layer));
}
Expand All @@ -138,7 +135,19 @@ void AnnotationManager::updateStyle(Style& style) {
}

obsoleteShapeAnnotationLayers.clear();
style.getSource(SourceID)->invalidateTiles();

for (auto& monitor : monitors) {
monitor->update(getTile(monitor->tileID));
}
}

void AnnotationManager::addTileMonitor(AnnotationTileMonitor& monitor) {
monitors.insert(&monitor);
monitor.update(getTile(monitor.tileID));
}

void AnnotationManager::removeTileMonitor(AnnotationTileMonitor& monitor) {
monitors.erase(&monitor);
}

}
9 changes: 8 additions & 1 deletion src/mbgl/annotation/annotation_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@

#include <string>
#include <vector>
#include <set>

namespace mbgl {

class PointAnnotation;
class ShapeAnnotation;
class AnnotationTile;
class AnnotationTileMonitor;
class Style;

class AnnotationManager : private util::noncopyable {
Expand All @@ -30,17 +32,22 @@ class AnnotationManager : private util::noncopyable {
LatLngBounds getBoundsForAnnotations(const AnnotationIDs&) const;

void updateStyle(Style&);
std::unique_ptr<AnnotationTile> getTile(const TileID&);

void addTileMonitor(AnnotationTileMonitor&);
void removeTileMonitor(AnnotationTileMonitor&);

static const std::string SourceID;
static const std::string PointLayerID;

private:
std::unique_ptr<AnnotationTile> getTile(const TileID&);

AnnotationID nextID = 0;
PointAnnotationImpl::Tree pointTree;
PointAnnotationImpl::Map pointAnnotations;
ShapeAnnotationImpl::Map shapeAnnotations;
std::vector<std::string> obsoleteShapeAnnotationLayers;
std::set<AnnotationTileMonitor*> monitors;
};

}
Expand Down
18 changes: 14 additions & 4 deletions src/mbgl/annotation/annotation_tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,23 @@ util::ptr<GeometryTileLayer> AnnotationTile::getLayer(const std::string& name) c
return nullptr;
}

AnnotationTileMonitor::AnnotationTileMonitor(const TileID& id, MapData& data)
: tile(data.getAnnotationManager()->getTile(id)) {
AnnotationTileMonitor::AnnotationTileMonitor(const TileID& tileID_, MapData& data_)
: tileID(tileID_),
data(data_) {
}

Request* AnnotationTileMonitor::monitorTile(std::function<void (std::exception_ptr, std::unique_ptr<GeometryTile>)> callback) {
callback(nullptr, std::move(tile));
AnnotationTileMonitor::~AnnotationTileMonitor() {
data.getAnnotationManager()->removeTileMonitor(*this);
}

Request* AnnotationTileMonitor::monitorTile(std::function<void (std::exception_ptr, std::unique_ptr<GeometryTile>)> callback_) {
callback = callback_;
data.getAnnotationManager()->addTileMonitor(*this);
return nullptr;
}

void AnnotationTileMonitor::update(std::unique_ptr<GeometryTile> tile) {
callback(nullptr, std::move(tile));
}

}
7 changes: 6 additions & 1 deletion src/mbgl/annotation/annotation_tile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,16 @@ class MapData;
class AnnotationTileMonitor : public GeometryTileMonitor {
public:
AnnotationTileMonitor(const TileID&, MapData&);
~AnnotationTileMonitor();

void update(std::unique_ptr<GeometryTile>);
Request* monitorTile(std::function<void (std::exception_ptr, std::unique_ptr<GeometryTile>)>) override;

TileID tileID;

private:
std::unique_ptr<AnnotationTile> tile;
MapData& data;
std::function<void (std::exception_ptr, std::unique_ptr<GeometryTile>)> callback;
};

}
Expand Down
15 changes: 5 additions & 10 deletions src/mbgl/annotation/shape_annotation_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <mbgl/util/constants.hpp>
#include <mbgl/util/string.hpp>
#include <mbgl/style/style.hpp>
#include <mbgl/style/style_bucket.hpp>
#include <mbgl/layer/line_layer.hpp>
#include <mbgl/layer/fill_layer.hpp>

Expand Down Expand Up @@ -69,32 +68,28 @@ void ShapeAnnotationImpl::updateStyle(Style& style) {
}

layer->paints.paints = sourceLayer->paints.paints;
layer->bucket->layout = sourceLayer->bucket->layout;
layer->layout = sourceLayer->layout;
}

layer->bucket->name = layer->id;
layer->bucket->source = AnnotationManager::SourceID;
layer->bucket->source_layer = layer->id;
layer->id = layerID;
layer->source = AnnotationManager::SourceID;
layer->sourceLayer = layer->id;

style.addLayer(std::move(layer), beforeLayerID);
}

std::unique_ptr<StyleLayer> ShapeAnnotationImpl::createLineLayer() {
type = ProjectedFeatureType::LineString;
std::unique_ptr<LineLayer> layer = std::make_unique<LineLayer>();
layer->id = layerID;
layer->type = StyleLayerType::Line;
layer->bucket = std::make_shared<StyleBucket>(layer->type);
layer->bucket->layout.set(PropertyKey::LineJoin, ConstantFunction<JoinType>(JoinType::Round));
layer->layout.set(PropertyKey::LineJoin, ConstantFunction<JoinType>(JoinType::Round));
return std::move(layer);
}

std::unique_ptr<StyleLayer> ShapeAnnotationImpl::createFillLayer() {
type = ProjectedFeatureType::Polygon;
std::unique_ptr<FillLayer> layer = std::make_unique<FillLayer>();
layer->id = layerID;
layer->type = StyleLayerType::Fill;
layer->bucket = std::make_shared<StyleBucket>(layer->type);
return std::move(layer);
}

Expand Down
4 changes: 4 additions & 0 deletions src/mbgl/layer/background_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ void BackgroundLayer::recalculate(const StyleCalculationParameters& parameters)
passes = properties.isVisible() ? RenderPass::Translucent : RenderPass::None;
}

std::unique_ptr<Bucket> BackgroundLayer::createBucket(StyleBucketParameters&) const {
return nullptr;
}

}
2 changes: 2 additions & 0 deletions src/mbgl/layer/background_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class BackgroundLayer : public StyleLayer {

void recalculate(const StyleCalculationParameters&) override;

std::unique_ptr<Bucket> createBucket(StyleBucketParameters&) const override;

BackgroundPaintProperties properties;
};

Expand Down
12 changes: 12 additions & 0 deletions src/mbgl/layer/circle_layer.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <mbgl/layer/circle_layer.hpp>
#include <mbgl/style/property_parsing.hpp>
#include <mbgl/style/style_bucket_parameters.hpp>
#include <mbgl/renderer/circle_bucket.hpp>

namespace mbgl {

Expand Down Expand Up @@ -27,4 +29,14 @@ void CircleLayer::recalculate(const StyleCalculationParameters& parameters) {
passes = properties.isVisible() ? RenderPass::Translucent : RenderPass::None;
}

std::unique_ptr<Bucket> CircleLayer::createBucket(StyleBucketParameters& parameters) const {
auto bucket = std::make_unique<CircleBucket>();

parameters.eachFilteredFeature(filter, [&] (const auto& feature) {
bucket->addGeometry(feature.getGeometries());
});

return std::move(bucket);
}

}
2 changes: 2 additions & 0 deletions src/mbgl/layer/circle_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class CircleLayer : public StyleLayer {

void recalculate(const StyleCalculationParameters&) override;

std::unique_ptr<Bucket> createBucket(StyleBucketParameters&) const override;

CirclePaintProperties properties;
};

Expand Down
12 changes: 12 additions & 0 deletions src/mbgl/layer/fill_layer.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <mbgl/layer/fill_layer.hpp>
#include <mbgl/style/property_parsing.hpp>
#include <mbgl/style/style_bucket_parameters.hpp>
#include <mbgl/renderer/fill_bucket.hpp>

namespace mbgl {

Expand Down Expand Up @@ -43,4 +45,14 @@ void FillLayer::recalculate(const StyleCalculationParameters& parameters) {
}
}

std::unique_ptr<Bucket> FillLayer::createBucket(StyleBucketParameters& parameters) const {
auto bucket = std::make_unique<FillBucket>();

parameters.eachFilteredFeature(filter, [&] (const auto& feature) {
bucket->addGeometry(feature.getGeometries());
});

return std::move(bucket);
}

}
2 changes: 2 additions & 0 deletions src/mbgl/layer/fill_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class FillLayer : public StyleLayer {

void recalculate(const StyleCalculationParameters&) override;

std::unique_ptr<Bucket> createBucket(StyleBucketParameters&) const override;

FillPaintProperties properties;
};

Expand Down
28 changes: 23 additions & 5 deletions src/mbgl/layer/line_layer.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#include <mbgl/layer/line_layer.hpp>
#include <mbgl/style/style_bucket.hpp>
#include <mbgl/style/property_parsing.hpp>
#include <mbgl/style/style_bucket_parameters.hpp>
#include <mbgl/renderer/line_bucket.hpp>
#include <mbgl/map/tile_id.hpp>

namespace mbgl {

void LineLayer::parseLayout(const JSVal& value) {
parseProperty<Function<CapType>>("line-cap", PropertyKey::LineCap, bucket->layout, value);
parseProperty<Function<JoinType>>("line-join", PropertyKey::LineJoin, bucket->layout, value);
parseProperty<Function<float>>("line-miter-limit", PropertyKey::LineMiterLimit, bucket->layout, value);
parseProperty<Function<float>>("line-round-limit", PropertyKey::LineRoundLimit, bucket->layout, value);
parseProperty<Function<CapType>>("line-cap", PropertyKey::LineCap, layout, value);
parseProperty<Function<JoinType>>("line-join", PropertyKey::LineJoin, layout, value);
parseProperty<Function<float>>("line-miter-limit", PropertyKey::LineMiterLimit, layout, value);
parseProperty<Function<float>>("line-round-limit", PropertyKey::LineRoundLimit, layout, value);
}

void LineLayer::parsePaints(const JSVal& layer) {
Expand Down Expand Up @@ -53,4 +54,21 @@ void LineLayer::recalculate(const StyleCalculationParameters& parameters) {
passes = properties.isVisible() ? RenderPass::Translucent : RenderPass::None;
}

std::unique_ptr<Bucket> LineLayer::createBucket(StyleBucketParameters& parameters) const {
auto bucket = std::make_unique<LineBucket>();

const float z = parameters.tileID.z;

layout.calculate(PropertyKey::LineCap, bucket->layout.cap, z);
layout.calculate(PropertyKey::LineJoin, bucket->layout.join, z);
layout.calculate(PropertyKey::LineMiterLimit, bucket->layout.miter_limit, z);
layout.calculate(PropertyKey::LineRoundLimit, bucket->layout.round_limit, z);

parameters.eachFilteredFeature(filter, [&] (const auto& feature) {
bucket->addGeometry(feature.getGeometries());
});

return std::move(bucket);
}

}
2 changes: 2 additions & 0 deletions src/mbgl/layer/line_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class LineLayer : public StyleLayer {

void recalculate(const StyleCalculationParameters&) override;

std::unique_ptr<Bucket> createBucket(StyleBucketParameters&) const override;

LinePaintProperties properties;
};

Expand Down
5 changes: 5 additions & 0 deletions src/mbgl/layer/raster_layer.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <mbgl/layer/raster_layer.hpp>
#include <mbgl/style/property_parsing.hpp>
#include <mbgl/renderer/bucket.hpp>

namespace mbgl {

Expand Down Expand Up @@ -35,4 +36,8 @@ void RasterLayer::recalculate(const StyleCalculationParameters& parameters) {
passes = properties.isVisible() ? RenderPass::Translucent : RenderPass::None;
}

std::unique_ptr<Bucket> RasterLayer::createBucket(StyleBucketParameters&) const {
return nullptr;
}

}
2 changes: 2 additions & 0 deletions src/mbgl/layer/raster_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class RasterLayer : public StyleLayer {

void recalculate(const StyleCalculationParameters&) override;

std::unique_ptr<Bucket> createBucket(StyleBucketParameters&) const override;

RasterPaintProperties properties;
};

Expand Down
Loading