[core] Copy only the necessary style layers to the worker
This commit is contained in:
@@ -120,11 +120,11 @@ void Style::removeSource(const std::string& id) {
|
||||
sources.erase(it);
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<Layer>> Style::getLayers() const {
|
||||
std::vector<std::unique_ptr<Layer>> result;
|
||||
std::vector<const Layer*> Style::getLayers() const {
|
||||
std::vector<const Layer*> result;
|
||||
result.reserve(layers.size());
|
||||
for (const auto& layer : layers) {
|
||||
result.push_back(layer->baseImpl->clone());
|
||||
result.push_back(layer.get());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public:
|
||||
void addSource(std::unique_ptr<Source>);
|
||||
void removeSource(const std::string& sourceID);
|
||||
|
||||
std::vector<std::unique_ptr<Layer>> getLayers() const;
|
||||
std::vector<const Layer*> getLayers() const;
|
||||
Layer* getLayer(const std::string& id) const;
|
||||
void addLayer(std::unique_ptr<Layer>,
|
||||
optional<std::string> beforeLayerID = {});
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
#include <mbgl/tile/tile_observer.hpp>
|
||||
#include <mbgl/tile/geometry_tile_data.hpp>
|
||||
#include <mbgl/style/layer_impl.hpp>
|
||||
#include <mbgl/style/layers/background_layer.hpp>
|
||||
#include <mbgl/style/layers/custom_layer.hpp>
|
||||
#include <mbgl/util/worker.hpp>
|
||||
#include <mbgl/util/work_request.hpp>
|
||||
#include <mbgl/style/style.hpp>
|
||||
@@ -12,15 +14,17 @@
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
using namespace style;
|
||||
|
||||
GeometryTile::GeometryTile(const OverscaledTileID& id_,
|
||||
std::string sourceID,
|
||||
style::Style& style_,
|
||||
std::string sourceID_,
|
||||
Style& style_,
|
||||
const MapMode mode_)
|
||||
: Tile(id_),
|
||||
sourceID(std::move(sourceID_)),
|
||||
style(style_),
|
||||
worker(style_.workers),
|
||||
tileWorker(id_,
|
||||
sourceID,
|
||||
*style_.spriteStore,
|
||||
*style_.glyphAtlas,
|
||||
*style_.glyphStore,
|
||||
@@ -28,10 +32,34 @@ GeometryTile::GeometryTile(const OverscaledTileID& id_,
|
||||
mode_) {
|
||||
}
|
||||
|
||||
GeometryTile::~GeometryTile() {
|
||||
cancel();
|
||||
}
|
||||
|
||||
void GeometryTile::setError(std::exception_ptr err) {
|
||||
observer->onTileError(*this, err);
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<Layer>> GeometryTile::cloneStyleLayers() const {
|
||||
std::vector<std::unique_ptr<Layer>> result;
|
||||
|
||||
for (const Layer* layer : style.getLayers()) {
|
||||
// Avoid cloning and including irrelevant layers.
|
||||
if (layer->is<BackgroundLayer>() ||
|
||||
layer->is<CustomLayer>() ||
|
||||
layer->baseImpl->source != sourceID ||
|
||||
id.overscaledZ < std::floor(layer->baseImpl->minZoom) ||
|
||||
id.overscaledZ >= std::ceil(layer->baseImpl->maxZoom) ||
|
||||
layer->baseImpl->visibility == VisibilityType::None) {
|
||||
continue;
|
||||
}
|
||||
|
||||
result.push_back(layer->baseImpl->clone());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void GeometryTile::setData(std::unique_ptr<GeometryTileData> data_) {
|
||||
if (!data_) {
|
||||
// This is a 404 response. We're treating these as empty tiles.
|
||||
@@ -53,7 +81,7 @@ void GeometryTile::setData(std::unique_ptr<GeometryTileData> data_) {
|
||||
// when tile data changed. Replacing the workdRequest will cancel a pending work
|
||||
// request in case there is one.
|
||||
workRequest.reset();
|
||||
workRequest = worker.parseGeometryTile(tileWorker, style.getLayers(), std::move(data_), targetConfig, [this, config = targetConfig] (TileParseResult result) {
|
||||
workRequest = worker.parseGeometryTile(tileWorker, cloneStyleLayers(), std::move(data_), targetConfig, [this, config = targetConfig] (TileParseResult result) {
|
||||
workRequest.reset();
|
||||
|
||||
if (result.is<TileParseResultData>()) {
|
||||
@@ -82,10 +110,6 @@ void GeometryTile::setData(std::unique_ptr<GeometryTileData> data_) {
|
||||
});
|
||||
}
|
||||
|
||||
GeometryTile::~GeometryTile() {
|
||||
cancel();
|
||||
}
|
||||
|
||||
bool GeometryTile::parsePending() {
|
||||
if (workRequest) {
|
||||
// There's already parsing or placement going on.
|
||||
@@ -126,7 +150,7 @@ bool GeometryTile::parsePending() {
|
||||
return true;
|
||||
}
|
||||
|
||||
Bucket* GeometryTile::getBucket(const style::Layer& layer) {
|
||||
Bucket* GeometryTile::getBucket(const Layer& layer) {
|
||||
const auto it = buckets.find(layer.baseImpl->bucketName());
|
||||
if (it == buckets.end()) {
|
||||
return nullptr;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
@@ -17,6 +18,7 @@ class FeatureIndex;
|
||||
|
||||
namespace style {
|
||||
class Style;
|
||||
class Layer;
|
||||
} // namespace style
|
||||
|
||||
class GeometryTile : public Tile {
|
||||
@@ -46,8 +48,10 @@ public:
|
||||
void cancel() override;
|
||||
|
||||
private:
|
||||
std::vector<std::unique_ptr<style::Layer>> cloneStyleLayers() const;
|
||||
void redoPlacement();
|
||||
|
||||
const std::string sourceID;
|
||||
style::Style& style;
|
||||
Worker& worker;
|
||||
TileWorker tileWorker;
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
#include <mbgl/tile/tile_worker.hpp>
|
||||
#include <mbgl/tile/geometry_tile_data.hpp>
|
||||
#include <mbgl/style/bucket_parameters.hpp>
|
||||
#include <mbgl/style/layers/background_layer.hpp>
|
||||
#include <mbgl/style/layers/custom_layer.hpp>
|
||||
#include <mbgl/style/layers/symbol_layer.hpp>
|
||||
#include <mbgl/style/layers/symbol_layer_impl.hpp>
|
||||
#include <mbgl/sprite/sprite_atlas.hpp>
|
||||
@@ -13,6 +11,7 @@
|
||||
#include <mbgl/util/constants.hpp>
|
||||
#include <mbgl/util/string.hpp>
|
||||
#include <mbgl/util/exception.hpp>
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace mbgl {
|
||||
@@ -20,14 +19,12 @@ namespace mbgl {
|
||||
using namespace mbgl::style;
|
||||
|
||||
TileWorker::TileWorker(OverscaledTileID id_,
|
||||
std::string sourceID_,
|
||||
SpriteStore& spriteStore_,
|
||||
GlyphAtlas& glyphAtlas_,
|
||||
GlyphStore& glyphStore_,
|
||||
const util::Atomic<bool>& obsolete_,
|
||||
const MapMode mode_)
|
||||
: id(std::move(id_)),
|
||||
sourceID(std::move(sourceID_)),
|
||||
spriteStore(spriteStore_),
|
||||
glyphAtlas(glyphAtlas_),
|
||||
glyphStore(glyphStore_),
|
||||
@@ -135,18 +132,6 @@ void TileWorker::parseLayer(const Layer* layer) {
|
||||
if (obsolete)
|
||||
return;
|
||||
|
||||
// Background and custom layers are special cases.
|
||||
if (layer->is<BackgroundLayer>() || layer->is<CustomLayer>())
|
||||
return;
|
||||
|
||||
// Skip this bucket if we are to not render this
|
||||
if ((layer->baseImpl->source != sourceID) ||
|
||||
(id.overscaledZ < std::floor(layer->baseImpl->minZoom)) ||
|
||||
(id.overscaledZ >= std::ceil(layer->baseImpl->maxZoom)) ||
|
||||
(layer->baseImpl->visibility == VisibilityType::None)) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto geometryLayer = tileData->getLayer(layer->baseImpl->sourceLayer);
|
||||
if (!geometryLayer) {
|
||||
// The layer specified in the bucket does not exist. Do nothing.
|
||||
|
||||
@@ -46,7 +46,6 @@ using TileParseResult = variant<
|
||||
class TileWorker : public util::noncopyable {
|
||||
public:
|
||||
TileWorker(OverscaledTileID,
|
||||
std::string sourceID,
|
||||
SpriteStore&,
|
||||
GlyphAtlas&,
|
||||
GlyphStore&,
|
||||
@@ -70,7 +69,6 @@ private:
|
||||
std::unique_ptr<CollisionTile> placeLayers(PlacementConfig);
|
||||
|
||||
const OverscaledTileID id;
|
||||
const std::string sourceID;
|
||||
|
||||
SpriteStore& spriteStore;
|
||||
GlyphAtlas& glyphAtlas;
|
||||
|
||||
Reference in New Issue
Block a user