summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2015-04-23 17:16:00 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2015-04-28 14:32:26 -0400
commitcdb466e7f7c5d4d527c65595e77c0dd948a128fc (patch)
treec2aef22ab700dfb2d22227c280255b5983cd0eb9 /src
parent0c280adebcb9b1dd050aacb1dda1ad3715128ced (diff)
downloadqtlocation-mapboxgl-cdb466e7f7c5d4d527c65595e77c0dd948a128fc.tar.gz
Convert Style to unique_ptr and pass by reference
Fixes #1277 Fixes #1309
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/map/live_tile_data.cpp13
-rw-r--r--src/mbgl/map/live_tile_data.hpp2
-rw-r--r--src/mbgl/map/map_context.cpp4
-rw-r--r--src/mbgl/map/map_context.hpp2
-rw-r--r--src/mbgl/map/source.cpp10
-rw-r--r--src/mbgl/map/source.hpp4
-rw-r--r--src/mbgl/map/tile_parser.cpp5
-rw-r--r--src/mbgl/map/tile_parser.hpp4
-rw-r--r--src/mbgl/map/vector_tile_data.cpp10
-rw-r--r--src/mbgl/map/vector_tile_data.hpp4
10 files changed, 19 insertions, 39 deletions
diff --git a/src/mbgl/map/live_tile_data.cpp b/src/mbgl/map/live_tile_data.cpp
index d45b973a98..1582b0190e 100644
--- a/src/mbgl/map/live_tile_data.cpp
+++ b/src/mbgl/map/live_tile_data.cpp
@@ -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) {
diff --git a/src/mbgl/map/live_tile_data.hpp b/src/mbgl/map/live_tile_data.hpp
index d40cfdfd69..e56a7bf7e1 100644
--- a/src/mbgl/map/live_tile_data.hpp
+++ b/src/mbgl/map/live_tile_data.hpp
@@ -12,7 +12,7 @@ public:
LiveTileData(const TileID&,
AnnotationManager&,
float mapMaxZoom,
- util::ptr<Style>,
+ Style&,
GlyphAtlas&,
GlyphStore&,
SpriteAtlas&,
diff --git a/src/mbgl/map/map_context.cpp b/src/mbgl/map/map_context.cpp
index 15541a84d1..6640fddd9a 100644
--- a/src/mbgl/map/map_context.cpp
+++ b/src/mbgl/map/map_context.cpp
@@ -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();
diff --git a/src/mbgl/map/map_context.hpp b/src/mbgl/map/map_context.hpp
index ba8a4db9d7..93670fd1f2 100644
--- a/src/mbgl/map/map_context.hpp
+++ b/src/mbgl/map/map_context.hpp
@@ -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;
diff --git a/src/mbgl/map/source.cpp b/src/mbgl/map/source.cpp
index 2d4c4ec50c..12684bb6c4 100644
--- a/src/mbgl/map/source.cpp
+++ b/src/mbgl/map/source.cpp
@@ -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,
diff --git a/src/mbgl/map/source.hpp b/src/mbgl/map/source.hpp
index 2e889ccd74..f7b675d160 100644
--- a/src/mbgl/map/source.hpp
+++ b/src/mbgl/map/source.hpp
@@ -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&,
diff --git a/src/mbgl/map/tile_parser.cpp b/src/mbgl/map/tile_parser.cpp
index 60228974b0..35c504ab29 100644
--- a/src/mbgl/map/tile_parser.cpp
+++ b/src/mbgl/map/tile_parser.cpp
@@ -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;
diff --git a/src/mbgl/map/tile_parser.hpp b/src/mbgl/map/tile_parser.hpp
index 2c16d2a2fd..2dbb8cb17f 100644
--- a/src/mbgl/map/tile_parser.hpp
+++ b/src/mbgl/map/tile_parser.hpp
@@ -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;
diff --git a/src/mbgl/map/vector_tile_data.cpp b/src/mbgl/map/vector_tile_data.cpp
index 39c2d9fce3..555e1851f4 100644
--- a/src/mbgl/map/vector_tile_data.cpp
+++ b/src/mbgl/map/vector_tile_data.cpp
@@ -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());
diff --git a/src/mbgl/map/vector_tile_data.hpp b/src/mbgl/map/vector_tile_data.hpp
index e87978c24c..935ff90878 100644
--- a/src/mbgl/map/vector_tile_data.hpp
+++ b/src/mbgl/map/vector_tile_data.hpp
@@ -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;