From 4eff674c1d4caaf0ce624fe5db086f0d79d0d31f Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 18 Jun 2015 18:23:03 -0700 Subject: [PATCH] Revert "Do not hold a reference to the Style at the [Live|Vector]TileData" This reverts commit 044454417b61bdd102a376c1125ad6ee3a5eacd4. --- src/mbgl/map/live_tile_data.cpp | 7 +++---- src/mbgl/map/live_tile_data.hpp | 3 +-- src/mbgl/map/source.cpp | 4 ++-- src/mbgl/map/tile_parser.cpp | 7 ++++--- src/mbgl/map/tile_parser.hpp | 7 +++---- src/mbgl/map/vector_tile_data.cpp | 16 ++++++++-------- src/mbgl/map/vector_tile_data.hpp | 7 +++---- 7 files changed, 24 insertions(+), 27 deletions(-) diff --git a/src/mbgl/map/live_tile_data.cpp b/src/mbgl/map/live_tile_data.cpp index ccae542ee..4935c0134 100644 --- a/src/mbgl/map/live_tile_data.cpp +++ b/src/mbgl/map/live_tile_data.cpp @@ -10,8 +10,7 @@ using namespace mbgl; LiveTileData::LiveTileData(const TileID& id_, AnnotationManager& annotationManager_, - const std::vector>& layers_, - Worker& workers_, + Style& style_, GlyphAtlas& glyphAtlas_, GlyphStore& glyphStore_, SpriteAtlas& spriteAtlas_, @@ -19,7 +18,7 @@ LiveTileData::LiveTileData(const TileID& id_, const SourceInfo& source_, float angle_, bool collisionDebug_) - : VectorTileData::VectorTileData(id_, layers_, workers_, glyphAtlas_, glyphStore_, + : VectorTileData::VectorTileData(id_, style_, glyphAtlas_, glyphStore_, spriteAtlas_, sprite_, source_, angle_, collisionDebug_), annotationManager(annotationManager_) { // live features are always ready @@ -44,7 +43,7 @@ void LiveTileData::parse() { // 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, layers, glyphAtlas, glyphStore, spriteAtlas, sprite); + TileParser parser(*tile, *this, style, glyphAtlas, glyphStore, spriteAtlas, sprite); 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()); diff --git a/src/mbgl/map/live_tile_data.hpp b/src/mbgl/map/live_tile_data.hpp index 57d2e8c0d..162067123 100644 --- a/src/mbgl/map/live_tile_data.hpp +++ b/src/mbgl/map/live_tile_data.hpp @@ -11,8 +11,7 @@ class LiveTileData : public VectorTileData { public: LiveTileData(const TileID&, AnnotationManager&, - const std::vector>&, - Worker&, + Style&, GlyphAtlas&, GlyphStore&, SpriteAtlas&, diff --git a/src/mbgl/map/source.cpp b/src/mbgl/map/source.cpp index b073321a7..7dd91804b 100644 --- a/src/mbgl/map/source.cpp +++ b/src/mbgl/map/source.cpp @@ -295,7 +295,7 @@ TileData::State Source::addTile(MapData& data, // If we don't find working tile data, we're just going to load it. if (info.type == SourceType::Vector) { new_tile.data = - std::make_shared(normalized_id, style.layers, style.workers, glyphAtlas, + std::make_shared(normalized_id, style, glyphAtlas, glyphStore, spriteAtlas, sprite, info, transformState.getAngle(), data.getCollisionDebug()); new_tile.data->request(style.workers, transformState.getPixelRatio(), callback); @@ -305,7 +305,7 @@ TileData::State Source::addTile(MapData& data, style.workers, transformState.getPixelRatio(), callback); } else if (info.type == SourceType::Annotations) { new_tile.data = std::make_shared(normalized_id, data.annotationManager, - style.layers, style.workers, glyphAtlas, + style, glyphAtlas, glyphStore, spriteAtlas, sprite, info, transformState.getAngle(), data.getCollisionDebug()); new_tile.data->reparse(style.workers, callback); diff --git a/src/mbgl/map/tile_parser.cpp b/src/mbgl/map/tile_parser.cpp index 1ddf07ae9..61af22703 100644 --- a/src/mbgl/map/tile_parser.cpp +++ b/src/mbgl/map/tile_parser.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include @@ -20,14 +21,14 @@ TileParser::~TileParser() = default; TileParser::TileParser(const GeometryTile& geometryTile_, VectorTileData& tile_, - const std::vector>& layers_, + const Style& style_, GlyphAtlas& glyphAtlas_, GlyphStore& glyphStore_, SpriteAtlas& spriteAtlas_, const util::ptr& sprite_) : geometryTile(geometryTile_), tile(tile_), - layers(layers_), + style(style_), glyphAtlas(glyphAtlas_), glyphStore(glyphStore_), spriteAtlas(spriteAtlas_), @@ -41,7 +42,7 @@ bool TileParser::obsolete() const { } void TileParser::parse() { - for (const auto& layer_desc : layers) { + for (const auto& layer_desc : style.layers) { // Cancel early when parsing. if (obsolete()) { return; diff --git a/src/mbgl/map/tile_parser.hpp b/src/mbgl/map/tile_parser.hpp index 7eadc45d4..88e568780 100644 --- a/src/mbgl/map/tile_parser.hpp +++ b/src/mbgl/map/tile_parser.hpp @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -23,6 +22,7 @@ class GlyphAtlas; class GlyphStore; class SpriteAtlas; class Sprite; +class Style; class StyleBucket; class StyleLayoutFill; class StyleLayoutRaster; @@ -34,7 +34,7 @@ class TileParser : private util::noncopyable { public: TileParser(const GeometryTile& geometryTile, VectorTileData& tile, - const std::vector>& layers, + const Style& style, GlyphAtlas& glyphAtlas, GlyphStore& glyphStore, SpriteAtlas& spriteAtlas, @@ -61,9 +61,8 @@ private: const GeometryTile& geometryTile; VectorTileData& tile; - std::vector> layers; - // Cross-thread shared data. + const Style& style; GlyphAtlas& glyphAtlas; GlyphStore& glyphStore; SpriteAtlas& spriteAtlas; diff --git a/src/mbgl/map/vector_tile_data.cpp b/src/mbgl/map/vector_tile_data.cpp index 017d3ecb7..6dc6e8e9b 100644 --- a/src/mbgl/map/vector_tile_data.cpp +++ b/src/mbgl/map/vector_tile_data.cpp @@ -9,12 +9,12 @@ #include #include #include +#include using namespace mbgl; VectorTileData::VectorTileData(const TileID& id_, - const std::vector>& layers_, - Worker& workers_, + Style& style_, GlyphAtlas& glyphAtlas_, GlyphStore& glyphStore_, SpriteAtlas& spriteAtlas_, @@ -23,12 +23,11 @@ VectorTileData::VectorTileData(const TileID& id_, float angle, bool collisionDebug) : TileData(id_, source_), - layers(layers_), - workers(workers_), glyphAtlas(glyphAtlas_), glyphStore(glyphStore_), spriteAtlas(spriteAtlas_), sprite(sprite_), + style(style_), collision(std::make_unique(id_.z, 4096, source_.tile_size * id.overscaling, angle, collisionDebug)), lastAngle(angle), currentAngle(angle) { @@ -52,7 +51,7 @@ void VectorTileData::parse() { // is going to be discarded afterwards. VectorTile vectorTile(pbf((const uint8_t *)data.data(), data.size())); const VectorTile* vt = &vectorTile; - TileParser parser(*vt, *this, layers, glyphAtlas, glyphStore, spriteAtlas, sprite); + TileParser parser(*vt, *this, style, glyphAtlas, glyphStore, spriteAtlas, sprite); parser.parse(); if (getState() == State::obsolete) { @@ -129,14 +128,15 @@ void VectorTileData::redoPlacement(float angle, bool collisionDebug) { currentCollisionDebug = collisionDebug; auto callback = std::bind(&VectorTileData::endRedoPlacement, this); - workRequest = workers.send([this, angle, collisionDebug] { workerRedoPlacement(angle, collisionDebug); }, callback); + workRequest = style.workers.send([this, angle, collisionDebug] { workerRedoPlacement(angle, collisionDebug); }, callback); + } } void VectorTileData::workerRedoPlacement(float angle, bool collisionDebug) { collision->reset(angle, 0); collision->setDebug(collisionDebug); - for (const auto& layer_desc : layers) { + for (const auto& layer_desc : style.layers) { auto bucket = getBucket(*layer_desc); if (bucket) { bucket->placeFeatures(); @@ -145,7 +145,7 @@ void VectorTileData::workerRedoPlacement(float angle, bool collisionDebug) { } void VectorTileData::endRedoPlacement() { - for (const auto& layer_desc : layers) { + for (const auto& layer_desc : style.layers) { auto bucket = getBucket(*layer_desc); if (bucket) { bucket->swapRenderData(); diff --git a/src/mbgl/map/vector_tile_data.hpp b/src/mbgl/map/vector_tile_data.hpp index 51a627d7b..5a6f448c6 100644 --- a/src/mbgl/map/vector_tile_data.hpp +++ b/src/mbgl/map/vector_tile_data.hpp @@ -26,14 +26,14 @@ class GlyphAtlas; class GlyphStore; class SpriteAtlas; class Sprite; +class Style; class VectorTileData : public TileData { friend class TileParser; public: VectorTileData(const TileID&, - const std::vector>&, - Worker&, + Style&, GlyphAtlas&, GlyphStore&, SpriteAtlas&, @@ -66,12 +66,11 @@ protected: TriangleElementsBuffer triangleElementsBuffer; LineElementsBuffer lineElementsBuffer; - std::vector> layers; - Worker& workers; GlyphAtlas& glyphAtlas; GlyphStore& glyphStore; SpriteAtlas& spriteAtlas; util::ptr sprite; + Style& style; private: // Contains all the Bucket objects for the tile. Buckets are render