Partially revert "[core] Source should receive a ref to MapData just once"
This partially reverts commit d55aa7929c.
This commit is contained in:
committed by
John Firebaugh
parent
60b0e78e0e
commit
f27c28b6c4
@@ -1,6 +1,5 @@
|
||||
#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>
|
||||
|
||||
@@ -11,8 +10,7 @@ namespace mbgl {
|
||||
const std::string AnnotationManager::SourceID = "com.mapbox.annotations";
|
||||
const std::string AnnotationManager::PointLayerID = "com.mapbox.annotations.points";
|
||||
|
||||
AnnotationManager::AnnotationManager(MapData& data_) : data(data_) {}
|
||||
|
||||
AnnotationManager::AnnotationManager() = default;
|
||||
AnnotationManager::~AnnotationManager() = default;
|
||||
|
||||
AnnotationIDs
|
||||
@@ -110,7 +108,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>(data);
|
||||
std::unique_ptr<Source> source = std::make_unique<Source>();
|
||||
source->info.type = SourceType::Annotations;
|
||||
source->info.source_id = SourceID;
|
||||
source->enabled = true;
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class MapData;
|
||||
class PointAnnotation;
|
||||
class ShapeAnnotation;
|
||||
class AnnotationTile;
|
||||
@@ -22,7 +21,7 @@ class Style;
|
||||
|
||||
class AnnotationManager : private util::noncopyable {
|
||||
public:
|
||||
AnnotationManager(MapData&);
|
||||
AnnotationManager();
|
||||
~AnnotationManager();
|
||||
|
||||
AnnotationIDs addPointAnnotations(const std::vector<PointAnnotation>&, const uint8_t maxZoom);
|
||||
@@ -43,7 +42,6 @@ public:
|
||||
private:
|
||||
std::unique_ptr<AnnotationTile> getTile(const TileID&);
|
||||
|
||||
MapData& data;
|
||||
AnnotationID nextID = 0;
|
||||
PointAnnotationImpl::Tree pointTree;
|
||||
PointAnnotationImpl::Map pointAnnotations;
|
||||
|
||||
@@ -24,7 +24,6 @@ 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(MapData& data_) : data(data_) {}
|
||||
Source::Source() {}
|
||||
|
||||
Source::~Source() = default;
|
||||
|
||||
@@ -246,7 +246,8 @@ bool Source::handlePartialTile(const TileID& id, Worker&) {
|
||||
});
|
||||
}
|
||||
|
||||
TileData::State Source::addTile(const TransformState& transformState,
|
||||
TileData::State Source::addTile(MapData& data,
|
||||
const TransformState& transformState,
|
||||
Style& style,
|
||||
TexturePool& texturePool,
|
||||
const TileID& id) {
|
||||
@@ -280,7 +281,7 @@ TileData::State Source::addTile(const TransformState& transformState,
|
||||
}
|
||||
|
||||
if (!new_tile.data) {
|
||||
auto callback = std::bind(&Source::tileLoadingCompleteCallback, this, normalized_id, transformState);
|
||||
auto callback = std::bind(&Source::tileLoadingCompleteCallback, this, normalized_id, transformState, data.getDebug() & MapDebugOptions::Collision);
|
||||
|
||||
// If we don't find working tile data, we're just going to load it.
|
||||
if (info.type == SourceType::Raster) {
|
||||
@@ -407,7 +408,8 @@ void Source::findLoadedParent(const TileID& id, int32_t minCoveringZoom, std::fo
|
||||
}
|
||||
}
|
||||
|
||||
bool Source::update(const TransformState& transformState,
|
||||
bool Source::update(MapData& data,
|
||||
const TransformState& transformState,
|
||||
Style& style,
|
||||
TexturePool& texturePool,
|
||||
bool shouldReparsePartialTiles) {
|
||||
@@ -447,7 +449,7 @@ bool Source::update(const TransformState& transformState,
|
||||
}
|
||||
break;
|
||||
case TileData::State::invalid:
|
||||
state = addTile(transformState, style, texturePool, id);
|
||||
state = addTile(data, transformState, style, texturePool, id);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -546,7 +548,7 @@ void Source::setObserver(Observer* observer) {
|
||||
observer_ = observer;
|
||||
}
|
||||
|
||||
void Source::tileLoadingCompleteCallback(const TileID& normalized_id, const TransformState& transformState) {
|
||||
void Source::tileLoadingCompleteCallback(const TileID& normalized_id, const TransformState& transformState, bool collisionDebug) {
|
||||
auto it = tileDataMap.find(normalized_id);
|
||||
if (it == tileDataMap.end()) {
|
||||
return;
|
||||
@@ -562,7 +564,7 @@ void Source::tileLoadingCompleteCallback(const TileID& normalized_id, const Tran
|
||||
return;
|
||||
}
|
||||
|
||||
tileData->redoPlacement({ transformState.getAngle(), transformState.getPitch(), data.getDebug() & MapDebugOptions::Collision});
|
||||
tileData->redoPlacement({ transformState.getAngle(), transformState.getPitch(), collisionDebug });
|
||||
emitTileLoaded(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ public:
|
||||
virtual void onTileLoadingFailed(std::exception_ptr error) = 0;
|
||||
};
|
||||
|
||||
Source(MapData&);
|
||||
Source();
|
||||
~Source();
|
||||
|
||||
void load();
|
||||
@@ -72,7 +72,8 @@ 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(const TransformState&,
|
||||
bool update(MapData&,
|
||||
const TransformState&,
|
||||
Style&,
|
||||
TexturePool&,
|
||||
bool shouldReparsePartialTiles);
|
||||
@@ -94,7 +95,7 @@ public:
|
||||
bool enabled;
|
||||
|
||||
private:
|
||||
void tileLoadingCompleteCallback(const TileID&, const TransformState&);
|
||||
void tileLoadingCompleteCallback(const TileID&, const TransformState&, bool collisionDebug);
|
||||
|
||||
void emitSourceLoaded();
|
||||
void emitSourceLoadingFailed(const std::string& message);
|
||||
@@ -107,7 +108,8 @@ private:
|
||||
int32_t coveringZoomLevel(const TransformState&) const;
|
||||
std::forward_list<TileID> coveringTiles(const TransformState&) const;
|
||||
|
||||
TileData::State addTile(const TransformState&,
|
||||
TileData::State addTile(MapData&,
|
||||
const TransformState&,
|
||||
Style&,
|
||||
TexturePool&,
|
||||
const TileID&);
|
||||
@@ -117,8 +119,6 @@ private:
|
||||
|
||||
double getZoom(const TransformState &state) const;
|
||||
|
||||
MapData& data;
|
||||
|
||||
bool loaded = false;
|
||||
|
||||
// Stores the time when this source was most recently updated.
|
||||
|
||||
@@ -43,7 +43,7 @@ void Style::setJSON(const std::string& json, const std::string&) {
|
||||
return;
|
||||
}
|
||||
|
||||
StyleParser parser(data);
|
||||
StyleParser parser;
|
||||
parser.parse(doc);
|
||||
|
||||
for (auto& source : parser.getSources()) {
|
||||
@@ -105,7 +105,7 @@ void Style::update(const TransformState& transform,
|
||||
TexturePool& texturePool) {
|
||||
bool allTilesUpdated = true;
|
||||
for (const auto& source : sources) {
|
||||
if (!source->update(transform, *this, texturePool, shouldReparsePartialTiles)) {
|
||||
if (!source->update(data, transform, *this, texturePool, shouldReparsePartialTiles)) {
|
||||
allTilesUpdated = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,12 @@
|
||||
#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();
|
||||
@@ -54,7 +49,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>(data);
|
||||
std::unique_ptr<Source> source = std::make_unique<Source>();
|
||||
|
||||
source->info.source_id = { nameVal.GetString(), nameVal.GetStringLength() };
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class MapData;
|
||||
class StyleLayer;
|
||||
class Source;
|
||||
|
||||
@@ -22,8 +21,6 @@ using JSVal = rapidjson::Value;
|
||||
|
||||
class StyleParser {
|
||||
public:
|
||||
StyleParser(MapData&);
|
||||
|
||||
void parse(const JSVal&);
|
||||
|
||||
std::vector<std::unique_ptr<Source>>&& getSources() {
|
||||
@@ -48,8 +45,6 @@ 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,6 +1,5 @@
|
||||
#include "../fixtures/util.hpp"
|
||||
|
||||
#include <mbgl/map/map_data.hpp>
|
||||
#include <mbgl/style/style_parser.hpp>
|
||||
#include <mbgl/util/io.hpp>
|
||||
|
||||
@@ -36,9 +35,7 @@ TEST_P(StyleParserTest, ParseStyle) {
|
||||
FixtureLogObserver* observer = new FixtureLogObserver();
|
||||
Log::setObserver(std::unique_ptr<Log::Observer>(observer));
|
||||
|
||||
double fakePixelRatio = 1.0;
|
||||
MapData data(MapMode::Continuous, GLContextMode::Unique, fakePixelRatio);
|
||||
StyleParser parser(data);
|
||||
StyleParser parser;
|
||||
parser.parse(styleDoc);
|
||||
|
||||
for (auto it = infoDoc.MemberBegin(), end = infoDoc.MemberEnd(); it != end; it++) {
|
||||
|
||||
Reference in New Issue
Block a user