[core] Source should receive a ref to MapData just once
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include <mbgl/annotation/annotation_manager.hpp>
|
||||
#include <mbgl/annotation/annotation_tile.hpp>
|
||||
#include <mbgl/map/map_data.hpp>
|
||||
#include <mbgl/style/style.hpp>
|
||||
#include <mbgl/layer/symbol_layer.hpp>
|
||||
|
||||
@@ -10,7 +11,8 @@ namespace mbgl {
|
||||
const std::string AnnotationManager::SourceID = "com.mapbox.annotations";
|
||||
const std::string AnnotationManager::PointLayerID = "com.mapbox.annotations.points";
|
||||
|
||||
AnnotationManager::AnnotationManager() = default;
|
||||
AnnotationManager::AnnotationManager(MapData& data_) : data(data_) {}
|
||||
|
||||
AnnotationManager::~AnnotationManager() = default;
|
||||
|
||||
AnnotationIDs
|
||||
@@ -108,7 +110,7 @@ std::unique_ptr<AnnotationTile> AnnotationManager::getTile(const TileID& tileID)
|
||||
void AnnotationManager::updateStyle(Style& style) {
|
||||
// Create annotation source, point layer, and point bucket
|
||||
if (!style.getSource(SourceID)) {
|
||||
std::unique_ptr<Source> source = std::make_unique<Source>();
|
||||
std::unique_ptr<Source> source = std::make_unique<Source>(data);
|
||||
source->info.type = SourceType::Annotations;
|
||||
source->info.source_id = SourceID;
|
||||
source->enabled = true;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class MapData;
|
||||
class PointAnnotation;
|
||||
class ShapeAnnotation;
|
||||
class AnnotationTile;
|
||||
@@ -21,7 +22,7 @@ class Style;
|
||||
|
||||
class AnnotationManager : private util::noncopyable {
|
||||
public:
|
||||
AnnotationManager();
|
||||
AnnotationManager(MapData&);
|
||||
~AnnotationManager();
|
||||
|
||||
AnnotationIDs addPointAnnotations(const std::vector<PointAnnotation>&, const uint8_t maxZoom);
|
||||
@@ -42,6 +43,7 @@ public:
|
||||
private:
|
||||
std::unique_ptr<AnnotationTile> getTile(const TileID&);
|
||||
|
||||
MapData& data;
|
||||
AnnotationID nextID = 0;
|
||||
PointAnnotationImpl::Tree pointTree;
|
||||
PointAnnotationImpl::Map pointAnnotations;
|
||||
|
||||
@@ -24,6 +24,7 @@ public:
|
||||
: mode(mode_)
|
||||
, contextMode(contextMode_)
|
||||
, pixelRatio(pixelRatio_)
|
||||
, annotationManager(*this)
|
||||
, animationTime(Duration::zero())
|
||||
, defaultFadeDuration(mode_ == MapMode::Continuous ? std::chrono::milliseconds(300) : Duration::zero())
|
||||
, defaultTransitionDuration(Duration::zero())
|
||||
|
||||
@@ -119,7 +119,7 @@ std::string SourceInfo::tileURL(const TileID& id, float pixelRatio) const {
|
||||
return result;
|
||||
}
|
||||
|
||||
Source::Source() {}
|
||||
Source::Source(MapData& data_) : data(data_) {}
|
||||
|
||||
Source::~Source() = default;
|
||||
|
||||
@@ -231,23 +231,22 @@ TileData::State Source::hasTile(const TileID& id) {
|
||||
bool Source::handlePartialTile(const TileID& id, Worker&) {
|
||||
const TileID normalized_id = id.normalized();
|
||||
|
||||
auto it = tile_data.find(normalized_id);
|
||||
if (it == tile_data.end()) {
|
||||
auto it = tileDataMap.find(normalized_id);
|
||||
if (it == tileDataMap.end()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto data = it->second.lock();
|
||||
if (!data) {
|
||||
auto tileData = it->second.lock();
|
||||
if (!tileData) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return data->parsePending([this]() {
|
||||
return tileData->parsePending([this]() {
|
||||
emitTileLoaded(false);
|
||||
});
|
||||
}
|
||||
|
||||
TileData::State Source::addTile(MapData& data,
|
||||
const TransformState& transformState,
|
||||
TileData::State Source::addTile(const TransformState& transformState,
|
||||
Style& style,
|
||||
TexturePool& texturePool,
|
||||
const TileID& id) {
|
||||
@@ -265,8 +264,8 @@ TileData::State Source::addTile(MapData& data,
|
||||
// Try to find the associated TileData object.
|
||||
const TileID normalized_id = id.normalized();
|
||||
|
||||
auto it = tile_data.find(normalized_id);
|
||||
if (it != tile_data.end()) {
|
||||
auto it = tileDataMap.find(normalized_id);
|
||||
if (it != tileDataMap.end()) {
|
||||
// Create a shared_ptr handle. Note that this might be empty!
|
||||
new_tile.data = it->second.lock();
|
||||
}
|
||||
@@ -281,7 +280,7 @@ TileData::State Source::addTile(MapData& data,
|
||||
}
|
||||
|
||||
if (!new_tile.data) {
|
||||
auto callback = std::bind(&Source::tileLoadingCompleteCallback, this, normalized_id, transformState, data.getCollisionDebug());
|
||||
auto callback = std::bind(&Source::tileLoadingCompleteCallback, this, normalized_id, transformState);
|
||||
|
||||
// If we don't find working tile data, we're just going to load it.
|
||||
if (info.type == SourceType::Raster) {
|
||||
@@ -310,7 +309,7 @@ TileData::State Source::addTile(MapData& data,
|
||||
callback);
|
||||
}
|
||||
|
||||
tile_data.emplace(new_tile.data->id, new_tile.data);
|
||||
tileDataMap.emplace(new_tile.data->id, new_tile.data);
|
||||
}
|
||||
|
||||
return new_tile.data->getState();
|
||||
@@ -408,8 +407,7 @@ void Source::findLoadedParent(const TileID& id, int32_t minCoveringZoom, std::fo
|
||||
}
|
||||
}
|
||||
|
||||
bool Source::update(MapData& data,
|
||||
const TransformState& transformState,
|
||||
bool Source::update(const TransformState& transformState,
|
||||
Style& style,
|
||||
TexturePool& texturePool,
|
||||
bool shouldReparsePartialTiles) {
|
||||
@@ -449,7 +447,7 @@ bool Source::update(MapData& data,
|
||||
}
|
||||
break;
|
||||
case TileData::State::invalid:
|
||||
state = addTile(data, transformState, style, texturePool, id);
|
||||
state = addTile(transformState, style, texturePool, id);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -500,7 +498,7 @@ bool Source::update(MapData& data,
|
||||
});
|
||||
|
||||
// Remove all the expired pointers from the set.
|
||||
util::erase_if(tile_data, [&retain_data, &tileCache](std::pair<const TileID, std::weak_ptr<TileData>> &pair) {
|
||||
util::erase_if(tileDataMap, [&retain_data, &tileCache](std::pair<const TileID, std::weak_ptr<TileData>> &pair) {
|
||||
const util::ptr<TileData> tile = pair.second.lock();
|
||||
if (!tile) {
|
||||
return true;
|
||||
@@ -548,23 +546,23 @@ void Source::setObserver(Observer* observer) {
|
||||
observer_ = observer;
|
||||
}
|
||||
|
||||
void Source::tileLoadingCompleteCallback(const TileID& normalized_id, const TransformState& transformState, bool collisionDebug) {
|
||||
auto it = tile_data.find(normalized_id);
|
||||
if (it == tile_data.end()) {
|
||||
void Source::tileLoadingCompleteCallback(const TileID& normalized_id, const TransformState& transformState) {
|
||||
auto it = tileDataMap.find(normalized_id);
|
||||
if (it == tileDataMap.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
util::ptr<TileData> data = it->second.lock();
|
||||
if (!data) {
|
||||
util::ptr<TileData> tileData = it->second.lock();
|
||||
if (!tileData) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (data->getState() == TileData::State::obsolete && !data->getError().empty()) {
|
||||
emitTileLoadingFailed(data->getError());
|
||||
if (tileData->getState() == TileData::State::obsolete && !tileData->getError().empty()) {
|
||||
emitTileLoadingFailed(tileData->getError());
|
||||
return;
|
||||
}
|
||||
|
||||
data->redoPlacement({ transformState.getAngle(), transformState.getPitch(), collisionDebug });
|
||||
tileData->redoPlacement({ transformState.getAngle(), transformState.getPitch(), data.getCollisionDebug() });
|
||||
emitTileLoaded(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ public:
|
||||
virtual void onTileLoadingFailed(std::exception_ptr error) = 0;
|
||||
};
|
||||
|
||||
Source();
|
||||
Source(MapData&);
|
||||
~Source();
|
||||
|
||||
void load();
|
||||
@@ -72,8 +72,7 @@ public:
|
||||
// will return true if all the tiles were scheduled for updating of false if
|
||||
// they were not. shouldReparsePartialTiles must be set to "true" if there is
|
||||
// new data available that a tile in the "partial" state might be interested at.
|
||||
bool update(MapData&,
|
||||
const TransformState&,
|
||||
bool update(const TransformState&,
|
||||
Style&,
|
||||
TexturePool&,
|
||||
bool shouldReparsePartialTiles);
|
||||
@@ -95,7 +94,7 @@ public:
|
||||
bool enabled;
|
||||
|
||||
private:
|
||||
void tileLoadingCompleteCallback(const TileID& normalized_id, const TransformState& transformState, bool collisionDebug);
|
||||
void tileLoadingCompleteCallback(const TileID&, const TransformState&);
|
||||
|
||||
void emitSourceLoaded();
|
||||
void emitSourceLoadingFailed(const std::string& message);
|
||||
@@ -108,8 +107,7 @@ private:
|
||||
int32_t coveringZoomLevel(const TransformState&) const;
|
||||
std::forward_list<TileID> coveringTiles(const TransformState&) const;
|
||||
|
||||
TileData::State addTile(MapData&,
|
||||
const TransformState&,
|
||||
TileData::State addTile(const TransformState&,
|
||||
Style&,
|
||||
TexturePool&,
|
||||
const TileID&);
|
||||
@@ -119,6 +117,8 @@ private:
|
||||
|
||||
double getZoom(const TransformState &state) const;
|
||||
|
||||
MapData& data;
|
||||
|
||||
bool loaded = false;
|
||||
|
||||
// Stores the time when this source was most recently updated.
|
||||
@@ -126,7 +126,7 @@ private:
|
||||
|
||||
std::map<TileID, std::unique_ptr<Tile>> tiles;
|
||||
std::vector<Tile*> tilePtrs;
|
||||
std::map<TileID, std::weak_ptr<TileData>> tile_data;
|
||||
std::map<TileID, std::weak_ptr<TileData>> tileDataMap;
|
||||
TileCache cache;
|
||||
|
||||
std::unique_ptr<FileRequest> req;
|
||||
|
||||
@@ -44,7 +44,7 @@ void Style::setJSON(const std::string& json, const std::string&) {
|
||||
return;
|
||||
}
|
||||
|
||||
StyleParser parser;
|
||||
StyleParser parser(data);
|
||||
parser.parse(doc);
|
||||
|
||||
for (auto& source : parser.getSources()) {
|
||||
@@ -106,7 +106,7 @@ void Style::update(const TransformState& transform,
|
||||
TexturePool& texturePool) {
|
||||
bool allTilesUpdated = true;
|
||||
for (const auto& source : sources) {
|
||||
if (!source->update(data, transform, *this, texturePool, shouldReparsePartialTiles)) {
|
||||
if (!source->update(transform, *this, texturePool, shouldReparsePartialTiles)) {
|
||||
allTilesUpdated = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
#include <mbgl/style/style_parser.hpp>
|
||||
#include <mbgl/style/style_layer.hpp>
|
||||
|
||||
#include <mbgl/map/map_data.hpp>
|
||||
#include <mbgl/platform/log.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
StyleParser::StyleParser(MapData& data_)
|
||||
: data(data_) {
|
||||
}
|
||||
|
||||
void StyleParser::parse(const JSVal& document) {
|
||||
if (document.HasMember("version")) {
|
||||
version = document["version"].GetInt();
|
||||
@@ -49,7 +54,7 @@ void StyleParser::parseSources(const JSVal& value) {
|
||||
const JSVal& nameVal = itr->name;
|
||||
const JSVal& sourceVal = itr->value;
|
||||
|
||||
std::unique_ptr<Source> source = std::make_unique<Source>();
|
||||
std::unique_ptr<Source> source = std::make_unique<Source>(data);
|
||||
|
||||
source->info.source_id = { nameVal.GetString(), nameVal.GetStringLength() };
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class MapData;
|
||||
class StyleLayer;
|
||||
class Source;
|
||||
|
||||
@@ -21,6 +22,8 @@ using JSVal = rapidjson::Value;
|
||||
|
||||
class StyleParser {
|
||||
public:
|
||||
StyleParser(MapData&);
|
||||
|
||||
void parse(const JSVal&);
|
||||
|
||||
std::vector<std::unique_ptr<Source>>&& getSources() {
|
||||
@@ -45,6 +48,8 @@ private:
|
||||
void parseLayer(const std::string& id, const JSVal&, util::ptr<StyleLayer>&);
|
||||
void parseVisibility(StyleLayer&, const JSVal& value);
|
||||
|
||||
MapData& data;
|
||||
|
||||
std::uint8_t version;
|
||||
|
||||
std::vector<std::unique_ptr<Source>> sources;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "../fixtures/util.hpp"
|
||||
|
||||
#include <mbgl/map/map_data.hpp>
|
||||
#include <mbgl/style/style_parser.hpp>
|
||||
#include <mbgl/util/io.hpp>
|
||||
|
||||
@@ -35,7 +36,9 @@ TEST_P(StyleParserTest, ParseStyle) {
|
||||
FixtureLogObserver* observer = new FixtureLogObserver();
|
||||
Log::setObserver(std::unique_ptr<Log::Observer>(observer));
|
||||
|
||||
StyleParser parser;
|
||||
double fakePixelRatio = 1.0;
|
||||
MapData data(MapMode::Continuous, GLContextMode::Unique, fakePixelRatio);
|
||||
StyleParser parser(data);
|
||||
parser.parse(styleDoc);
|
||||
|
||||
for (auto it = infoDoc.MemberBegin(), end = infoDoc.MemberEnd(); it != end; it++) {
|
||||
|
||||
Reference in New Issue
Block a user