Convert Style to unique_ptr and pass by reference
Fixes #1277 Fixes #1309
This commit is contained in:
@@ -11,7 +11,7 @@ using namespace mbgl;
|
||||
LiveTileData::LiveTileData(const TileID& id_,
|
||||
AnnotationManager& annotationManager_,
|
||||
float mapMaxZoom,
|
||||
util::ptr<Style> style_,
|
||||
Style& style_,
|
||||
GlyphAtlas& glyphAtlas_,
|
||||
GlyphStore& glyphStore_,
|
||||
SpriteAtlas& spriteAtlas_,
|
||||
@@ -35,27 +35,16 @@ void LiveTileData::parse() {
|
||||
|
||||
if (tile) {
|
||||
try {
|
||||
if (!style) {
|
||||
throw std::runtime_error("style isn't present in LiveTileData object anymore");
|
||||
}
|
||||
|
||||
// Parsing creates state that is encapsulated in TileParser. While parsing,
|
||||
// the TileParser object writes results into this objects. All other state
|
||||
// is going to be discarded afterwards.
|
||||
TileParser parser(*tile, *this, style, glyphAtlas, glyphStore, spriteAtlas, sprite);
|
||||
|
||||
// Clear the style so that we don't have a cycle in the shared_ptr references.
|
||||
style.reset();
|
||||
|
||||
parser.parse();
|
||||
} catch (const std::exception& ex) {
|
||||
Log::Error(Event::ParseTile, "Live-parsing [%d/%d/%d] failed: %s", id.z, id.x, id.y, ex.what());
|
||||
state = State::obsolete;
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// Clear the style so that we don't have a cycle in the shared_ptr references.
|
||||
style.reset();
|
||||
}
|
||||
|
||||
if (state != State::obsolete) {
|
||||
|
||||
@@ -12,7 +12,7 @@ public:
|
||||
LiveTileData(const TileID&,
|
||||
AnnotationManager&,
|
||||
float mapMaxZoom,
|
||||
util::ptr<Style>,
|
||||
Style&,
|
||||
GlyphAtlas&,
|
||||
GlyphStore&,
|
||||
SpriteAtlas&,
|
||||
|
||||
@@ -139,7 +139,7 @@ void MapContext::loadStyleJSON(const std::string& json, const std::string& base)
|
||||
assert(Environment::currentlyOn(ThreadType::Map));
|
||||
|
||||
sprite.reset();
|
||||
style = std::make_shared<Style>();
|
||||
style = util::make_unique<Style>();
|
||||
style->base = base;
|
||||
style->loadJSON((const uint8_t *)json.c_str());
|
||||
style->cascade(data.getClasses());
|
||||
@@ -162,7 +162,7 @@ void MapContext::updateTiles() {
|
||||
assert(Environment::currentlyOn(ThreadType::Map));
|
||||
if (!style) return;
|
||||
for (const auto& source : style->sources) {
|
||||
source->update(data, transformState, style, *glyphAtlas, *glyphStore, *spriteAtlas,
|
||||
source->update(data, transformState, *style, *glyphAtlas, *glyphStore, *spriteAtlas,
|
||||
getSprite(), *texturePool, [this]() {
|
||||
assert(Environment::currentlyOn(ThreadType::Map));
|
||||
triggerUpdate();
|
||||
|
||||
@@ -83,9 +83,9 @@ private:
|
||||
std::unique_ptr<LineAtlas> lineAtlas;
|
||||
std::unique_ptr<TexturePool> texturePool;
|
||||
std::unique_ptr<Painter> painter;
|
||||
std::unique_ptr<Style> style;
|
||||
|
||||
util::ptr<Sprite> sprite;
|
||||
util::ptr<Style> style;
|
||||
|
||||
std::string styleURL;
|
||||
std::string styleJSON;
|
||||
|
||||
@@ -227,7 +227,7 @@ TileData::State Source::hasTile(const TileID& id) {
|
||||
|
||||
TileData::State Source::addTile(MapData& data,
|
||||
const TransformState& transformState,
|
||||
util::ptr<Style> style,
|
||||
Style& style,
|
||||
GlyphAtlas& glyphAtlas,
|
||||
GlyphStore& glyphStore,
|
||||
SpriteAtlas& spriteAtlas,
|
||||
@@ -269,15 +269,15 @@ TileData::State Source::addTile(MapData& data,
|
||||
new_tile.data =
|
||||
std::make_shared<VectorTileData>(normalized_id, data.transform.getMaxZoom(), style, glyphAtlas,
|
||||
glyphStore, spriteAtlas, sprite, info);
|
||||
new_tile.data->request(style->workers, transformState.getPixelRatio(), callback);
|
||||
new_tile.data->request(style.workers, transformState.getPixelRatio(), callback);
|
||||
} else if (info.type == SourceType::Raster) {
|
||||
new_tile.data = std::make_shared<RasterTileData>(normalized_id, texturePool, info);
|
||||
new_tile.data->request(style->workers, transformState.getPixelRatio(), callback);
|
||||
new_tile.data->request(style.workers, transformState.getPixelRatio(), callback);
|
||||
} else if (info.type == SourceType::Annotations) {
|
||||
new_tile.data = std::make_shared<LiveTileData>(normalized_id, data.annotationManager,
|
||||
data.transform.getMaxZoom(), style, glyphAtlas,
|
||||
glyphStore, spriteAtlas, sprite, info);
|
||||
new_tile.data->reparse(style->workers, callback);
|
||||
new_tile.data->reparse(style.workers, callback);
|
||||
} else {
|
||||
throw std::runtime_error("source type not implemented");
|
||||
}
|
||||
@@ -368,7 +368,7 @@ bool Source::findLoadedParent(const TileID& id, int32_t minCoveringZoom, std::fo
|
||||
|
||||
void Source::update(MapData& data,
|
||||
const TransformState& transformState,
|
||||
util::ptr<Style> style,
|
||||
Style& style,
|
||||
GlyphAtlas& glyphAtlas,
|
||||
GlyphStore& glyphStore,
|
||||
SpriteAtlas& spriteAtlas,
|
||||
|
||||
@@ -64,7 +64,7 @@ public:
|
||||
void load(MapData&, Environment&, std::function<void()> callback);
|
||||
void update(MapData&,
|
||||
const TransformState&,
|
||||
util::ptr<Style>,
|
||||
Style&,
|
||||
GlyphAtlas&,
|
||||
GlyphStore&,
|
||||
SpriteAtlas&,
|
||||
@@ -95,7 +95,7 @@ private:
|
||||
|
||||
TileData::State addTile(MapData&,
|
||||
const TransformState&,
|
||||
util::ptr<Style>,
|
||||
Style&,
|
||||
GlyphAtlas&,
|
||||
GlyphStore&,
|
||||
SpriteAtlas&,
|
||||
|
||||
@@ -22,7 +22,7 @@ TileParser::~TileParser() = default;
|
||||
|
||||
TileParser::TileParser(const GeometryTile& geometryTile_,
|
||||
VectorTileData& tile_,
|
||||
const util::ptr<const Style>& style_,
|
||||
const Style& style_,
|
||||
GlyphAtlas& glyphAtlas_,
|
||||
GlyphStore& glyphStore_,
|
||||
SpriteAtlas& spriteAtlas_,
|
||||
@@ -35,7 +35,6 @@ TileParser::TileParser(const GeometryTile& geometryTile_,
|
||||
spriteAtlas(spriteAtlas_),
|
||||
sprite(sprite_),
|
||||
collision(util::make_unique<Collision>(tile.id.z, 4096, tile.source.tile_size, tile.depth)) {
|
||||
assert(style);
|
||||
assert(sprite);
|
||||
assert(collision);
|
||||
}
|
||||
@@ -43,7 +42,7 @@ TileParser::TileParser(const GeometryTile& geometryTile_,
|
||||
bool TileParser::obsolete() const { return tile.state == TileData::State::obsolete; }
|
||||
|
||||
void TileParser::parse() {
|
||||
for (const auto& layer_desc : style->layers) {
|
||||
for (const auto& layer_desc : style.layers) {
|
||||
// Cancel early when parsing.
|
||||
if (obsolete()) {
|
||||
return;
|
||||
|
||||
@@ -35,7 +35,7 @@ class TileParser : private util::noncopyable {
|
||||
public:
|
||||
TileParser(const GeometryTile& geometryTile,
|
||||
VectorTileData& tile,
|
||||
const util::ptr<const Style>& style,
|
||||
const Style& style,
|
||||
GlyphAtlas& glyphAtlas,
|
||||
GlyphStore& glyphStore,
|
||||
SpriteAtlas& spriteAtlas,
|
||||
@@ -60,7 +60,7 @@ private:
|
||||
VectorTileData& tile;
|
||||
|
||||
// Cross-thread shared data.
|
||||
util::ptr<const Style> style;
|
||||
const Style& style;
|
||||
GlyphAtlas& glyphAtlas;
|
||||
GlyphStore& glyphStore;
|
||||
SpriteAtlas& spriteAtlas;
|
||||
|
||||
@@ -12,7 +12,7 @@ using namespace mbgl;
|
||||
|
||||
VectorTileData::VectorTileData(const TileID& id_,
|
||||
float mapMaxZoom,
|
||||
util::ptr<Style> style_,
|
||||
Style& style_,
|
||||
GlyphAtlas& glyphAtlas_,
|
||||
GlyphStore& glyphStore_,
|
||||
SpriteAtlas& spriteAtlas_,
|
||||
@@ -37,20 +37,12 @@ void VectorTileData::parse() {
|
||||
}
|
||||
|
||||
try {
|
||||
if (!style) {
|
||||
throw std::runtime_error("style isn't present in VectorTileData object anymore");
|
||||
}
|
||||
|
||||
// Parsing creates state that is encapsulated in TileParser. While parsing,
|
||||
// the TileParser object writes results into this objects. All other state
|
||||
// is going to be discarded afterwards.
|
||||
VectorTile vectorTile(pbf((const uint8_t *)data.data(), data.size()));
|
||||
const VectorTile* vt = &vectorTile;
|
||||
TileParser parser(*vt, *this, style, glyphAtlas, glyphStore, spriteAtlas, sprite);
|
||||
|
||||
// Clear the style so that we don't have a cycle in the shared_ptr references.
|
||||
style.reset();
|
||||
|
||||
parser.parse();
|
||||
} catch (const std::exception& ex) {
|
||||
Log::Error(Event::ParseTile, "Parsing [%d/%d/%d] failed: %s", id.z, id.x, id.y, ex.what());
|
||||
|
||||
@@ -31,7 +31,7 @@ class VectorTileData : public TileData {
|
||||
public:
|
||||
VectorTileData(const TileID&,
|
||||
float mapMaxZoom,
|
||||
util::ptr<Style>,
|
||||
Style&,
|
||||
GlyphAtlas&,
|
||||
GlyphStore&,
|
||||
SpriteAtlas&,
|
||||
@@ -59,7 +59,7 @@ protected:
|
||||
GlyphStore& glyphStore;
|
||||
SpriteAtlas& spriteAtlas;
|
||||
util::ptr<Sprite> sprite;
|
||||
util::ptr<Style> style;
|
||||
Style& style;
|
||||
|
||||
public:
|
||||
const float depth;
|
||||
|
||||
Reference in New Issue
Block a user