summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2015-11-27 10:35:09 +0200
committerBruno de Oliveira Abinader <bruno@mapbox.com>2015-11-27 17:47:02 +0200
commitd55aa7929cb10d40a58b6b7a8ed73bddd4f0a407 (patch)
treeb2ce29bdba9df471693d4e7ac6e6dfe4b8adfe63 /src
parent1f0820c8e82810fb957cb1cd17fb4327debfc0e5 (diff)
downloadqtlocation-mapboxgl-d55aa7929cb10d40a58b6b7a8ed73bddd4f0a407.tar.gz
[core] Source should receive a ref to MapData just once
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/annotation/annotation_manager.cpp6
-rw-r--r--src/mbgl/annotation/annotation_manager.hpp4
-rw-r--r--src/mbgl/map/map_data.hpp1
-rw-r--r--src/mbgl/map/source.cpp46
-rw-r--r--src/mbgl/map/source.hpp14
-rw-r--r--src/mbgl/style/style.cpp4
-rw-r--r--src/mbgl/style/style_parser.cpp7
-rw-r--r--src/mbgl/style/style_parser.hpp5
8 files changed, 50 insertions, 37 deletions
diff --git a/src/mbgl/annotation/annotation_manager.cpp b/src/mbgl/annotation/annotation_manager.cpp
index 5b1138a14a..c6d5413ec0 100644
--- a/src/mbgl/annotation/annotation_manager.cpp
+++ b/src/mbgl/annotation/annotation_manager.cpp
@@ -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;
diff --git a/src/mbgl/annotation/annotation_manager.hpp b/src/mbgl/annotation/annotation_manager.hpp
index f1b41c9ccc..16ebd16716 100644
--- a/src/mbgl/annotation/annotation_manager.hpp
+++ b/src/mbgl/annotation/annotation_manager.hpp
@@ -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;
diff --git a/src/mbgl/map/map_data.hpp b/src/mbgl/map/map_data.hpp
index 597048167c..9b02d372de 100644
--- a/src/mbgl/map/map_data.hpp
+++ b/src/mbgl/map/map_data.hpp
@@ -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())
diff --git a/src/mbgl/map/source.cpp b/src/mbgl/map/source.cpp
index 112d57115a..62014bd05d 100644
--- a/src/mbgl/map/source.cpp
+++ b/src/mbgl/map/source.cpp
@@ -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);
}
diff --git a/src/mbgl/map/source.hpp b/src/mbgl/map/source.hpp
index 661aa09e84..5f4bfe0c61 100644
--- a/src/mbgl/map/source.hpp
+++ b/src/mbgl/map/source.hpp
@@ -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;
diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp
index 3523a72079..1932d9064b 100644
--- a/src/mbgl/style/style.cpp
+++ b/src/mbgl/style/style.cpp
@@ -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;
}
}
diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp
index dc14827dc6..2eb9562c90 100644
--- a/src/mbgl/style/style_parser.cpp
+++ b/src/mbgl/style/style_parser.cpp
@@ -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() };
diff --git a/src/mbgl/style/style_parser.hpp b/src/mbgl/style/style_parser.hpp
index 489c9959f2..126a3781db 100644
--- a/src/mbgl/style/style_parser.hpp
+++ b/src/mbgl/style/style_parser.hpp
@@ -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;