summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-02-18 10:48:51 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-02-18 15:15:24 -0800
commit7b39ce95210ceb6640b3a3399dacd1d0e826ac1f (patch)
treeeb97fdc8a284826d3a3fe9426a8a10f88a654799 /src
parentd5eb5240f8c35016927e89bf9d186addc09b83fa (diff)
downloadqtlocation-mapboxgl-7b39ce95210ceb6640b3a3399dacd1d0e826ac1f.tar.gz
[core] Remove ThreadContext::getFileSource; instead thread FileSource through
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/map/map_context.cpp11
-rw-r--r--src/mbgl/map/map_context.hpp1
-rw-r--r--src/mbgl/source/source.cpp11
-rw-r--r--src/mbgl/source/source.hpp3
-rw-r--r--src/mbgl/sprite/sprite_store.cpp8
-rw-r--r--src/mbgl/sprite/sprite_store.hpp4
-rw-r--r--src/mbgl/style/style.cpp12
-rw-r--r--src/mbgl/style/style.hpp4
-rw-r--r--src/mbgl/style/style_update_parameters.hpp4
-rw-r--r--src/mbgl/text/glyph_pbf.cpp7
-rw-r--r--src/mbgl/text/glyph_pbf.hpp4
-rw-r--r--src/mbgl/text/glyph_store.cpp7
-rw-r--r--src/mbgl/text/glyph_store.hpp4
-rw-r--r--src/mbgl/tile/raster_tile_data.cpp3
-rw-r--r--src/mbgl/tile/raster_tile_data.hpp2
-rw-r--r--src/mbgl/tile/vector_tile.cpp8
-rw-r--r--src/mbgl/tile/vector_tile.hpp4
-rw-r--r--src/mbgl/util/thread_context.cpp16
-rw-r--r--src/mbgl/util/thread_context.hpp4
19 files changed, 58 insertions, 59 deletions
diff --git a/src/mbgl/map/map_context.cpp b/src/mbgl/map/map_context.cpp
index d9a7f47125..a4c6abdb21 100644
--- a/src/mbgl/map/map_context.cpp
+++ b/src/mbgl/map/map_context.cpp
@@ -28,8 +28,9 @@
namespace mbgl {
-MapContext::MapContext(View& view_, FileSource& fileSource, MapMode mode_, GLContextMode contextMode_, const float pixelRatio_)
+MapContext::MapContext(View& view_, FileSource& fileSource_, MapMode mode_, GLContextMode contextMode_, const float pixelRatio_)
: view(view_),
+ fileSource(fileSource_),
dataPtr(std::make_unique<MapData>(mode_, contextMode_, pixelRatio_)),
data(*dataPtr),
asyncUpdate([this] { update(); }),
@@ -37,7 +38,6 @@ MapContext::MapContext(View& view_, FileSource& fileSource, MapMode mode_, GLCon
texturePool(std::make_unique<gl::TexturePool>()) {
assert(util::ThreadContext::currentlyOn(util::ThreadType::Map));
- util::ThreadContext::setFileSource(&fileSource);
util::ThreadContext::setGLObjectStore(&glObjectStore);
view.activate();
@@ -96,7 +96,7 @@ void MapContext::setStyleURL(const std::string& url) {
styleURL = url;
styleJSON.clear();
- style = std::make_unique<Style>(data);
+ style = std::make_unique<Style>(data, fileSource);
const size_t pos = styleURL.rfind('/');
std::string base = "";
@@ -104,8 +104,7 @@ void MapContext::setStyleURL(const std::string& url) {
base = styleURL.substr(0, pos + 1);
}
- FileSource* fs = util::ThreadContext::getFileSource();
- styleRequest = fs->request(Resource::style(styleURL), [this, base](Response res) {
+ styleRequest = fileSource.request(Resource::style(styleURL), [this, base](Response res) {
if (res.error) {
if (res.error->reason == Response::Error::Reason::NotFound &&
util::mapbox::isMapboxURL(styleURL)) {
@@ -130,7 +129,7 @@ void MapContext::setStyleJSON(const std::string& json, const std::string& base)
styleURL.clear();
styleJSON.clear();
- style = std::make_unique<Style>(data);
+ style = std::make_unique<Style>(data, fileSource);
loadStyleJSON(json, base);
}
diff --git a/src/mbgl/map/map_context.hpp b/src/mbgl/map/map_context.hpp
index 128d94dc3c..83ab71c86e 100644
--- a/src/mbgl/map/map_context.hpp
+++ b/src/mbgl/map/map_context.hpp
@@ -78,6 +78,7 @@ private:
void loadStyleJSON(const std::string& json, const std::string& base);
View& view;
+ FileSource& fileSource;
std::unique_ptr<MapData> dataPtr;
MapData& data;
diff --git a/src/mbgl/source/source.cpp b/src/mbgl/source/source.cpp
index c98b87c33f..8947e4f988 100644
--- a/src/mbgl/source/source.cpp
+++ b/src/mbgl/source/source.cpp
@@ -68,10 +68,7 @@ bool Source::isLoading() const {
return !loaded && req.operator bool();
}
-// Note: This is a separate function that must be called exactly once after creation
-// The reason this isn't part of the constructor is that calling shared_from_this() in
-// the constructor fails.
-void Source::load() {
+void Source::load(FileSource& fileSource) {
if (url.empty()) {
// In case there is no URL set, we assume that we already have all of the data because the
// TileJSON was specified inline in the stylesheet.
@@ -86,8 +83,7 @@ void Source::load() {
}
// URL may either be a TileJSON file, or a GeoJSON file.
- FileSource* fs = util::ThreadContext::getFileSource();
- req = fs->request(Resource::source(url), [this](Response res) {
+ req = fileSource.request(Resource::source(url), [this](Response res) {
if (res.error) {
observer->onSourceError(*this, std::make_exception_ptr(std::runtime_error(res.error->message)));
} else if (res.notModified) {
@@ -259,12 +255,13 @@ TileData::State Source::addTile(const TileID& tileID, const StyleUpdateParameter
info->tiles.at(0),
parameters.texturePool,
parameters.worker,
+ parameters.fileSource,
callback);
} else {
std::unique_ptr<GeometryTileMonitor> monitor;
if (type == SourceType::Vector) {
- monitor = std::make_unique<VectorTileMonitor>(normalizedID, parameters.pixelRatio, info->tiles.at(0));
+ monitor = std::make_unique<VectorTileMonitor>(normalizedID, parameters.pixelRatio, info->tiles.at(0), parameters.fileSource);
} else if (type == SourceType::Annotations) {
monitor = std::make_unique<AnnotationTileMonitor>(normalizedID, parameters.data);
} else if (type == SourceType::GeoJSON) {
diff --git a/src/mbgl/source/source.hpp b/src/mbgl/source/source.hpp
index 3c265e8e7b..52c7d76baf 100644
--- a/src/mbgl/source/source.hpp
+++ b/src/mbgl/source/source.hpp
@@ -22,6 +22,7 @@ namespace mbgl {
class StyleUpdateParameters;
class Painter;
+class FileSource;
class FileRequest;
class TransformState;
class Tile;
@@ -51,7 +52,7 @@ public:
~Source();
bool loaded = false;
- void load();
+ void load(FileSource&);
bool isLoading() const;
bool isLoaded() const;
diff --git a/src/mbgl/sprite/sprite_store.cpp b/src/mbgl/sprite/sprite_store.cpp
index 38aa7009ca..869abab39f 100644
--- a/src/mbgl/sprite/sprite_store.cpp
+++ b/src/mbgl/sprite/sprite_store.cpp
@@ -5,7 +5,6 @@
#include <mbgl/storage/resource.hpp>
#include <mbgl/storage/response.hpp>
#include <mbgl/util/exception.hpp>
-#include <mbgl/util/thread_context.hpp>
#include <cassert>
#include <string>
@@ -25,7 +24,7 @@ SpriteStore::SpriteStore(float pixelRatio_)
SpriteStore::~SpriteStore() = default;
-void SpriteStore::setURL(const std::string& url) {
+void SpriteStore::load(const std::string& url, FileSource& fileSource) {
if (url.empty()) {
// Treat a non-existent sprite as a successfully loaded empty sprite.
loaded = true;
@@ -34,8 +33,7 @@ void SpriteStore::setURL(const std::string& url) {
loader = std::make_unique<Loader>();
- FileSource* fs = util::ThreadContext::getFileSource();
- loader->jsonRequest = fs->request(Resource::spriteJSON(url, pixelRatio), [this](Response res) {
+ loader->jsonRequest = fileSource.request(Resource::spriteJSON(url, pixelRatio), [this](Response res) {
if (res.error) {
observer->onSpriteError(std::make_exception_ptr(std::runtime_error(res.error->message)));
} else if (res.notModified) {
@@ -50,7 +48,7 @@ void SpriteStore::setURL(const std::string& url) {
}
});
- loader->spriteRequest = fs->request(Resource::spriteImage(url, pixelRatio), [this](Response res) {
+ loader->spriteRequest = fileSource.request(Resource::spriteImage(url, pixelRatio), [this](Response res) {
if (res.error) {
observer->onSpriteError(std::make_exception_ptr(std::runtime_error(res.error->message)));
} else if (res.notModified) {
diff --git a/src/mbgl/sprite/sprite_store.hpp b/src/mbgl/sprite/sprite_store.hpp
index 7c5fe71802..995cb81900 100644
--- a/src/mbgl/sprite/sprite_store.hpp
+++ b/src/mbgl/sprite/sprite_store.hpp
@@ -10,6 +10,8 @@
namespace mbgl {
+class FileSource;
+
class SpriteStore : private util::noncopyable {
public:
using Sprites = std::map<std::string, std::shared_ptr<const SpriteImage>>;
@@ -25,7 +27,7 @@ public:
SpriteStore(float pixelRatio);
~SpriteStore();
- void setURL(const std::string&);
+ void load(const std::string& url, FileSource&);
bool isLoaded() const {
return loaded;
diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp
index bf35d17c97..e5ba08e57f 100644
--- a/src/mbgl/style/style.cpp
+++ b/src/mbgl/style/style.cpp
@@ -27,9 +27,10 @@
namespace mbgl {
-Style::Style(MapData& data_)
+Style::Style(MapData& data_, FileSource& fileSource_)
: data(data_),
- glyphStore(std::make_unique<GlyphStore>()),
+ fileSource(fileSource_),
+ glyphStore(std::make_unique<GlyphStore>(fileSource)),
glyphAtlas(std::make_unique<GlyphAtlas>(1024, 1024)),
spriteStore(std::make_unique<SpriteStore>(data.pixelRatio)),
spriteAtlas(std::make_unique<SpriteAtlas>(1024, 1024, data.pixelRatio, *spriteStore)),
@@ -55,7 +56,7 @@ void Style::setJSON(const std::string& json, const std::string&) {
}
glyphStore->setURL(parser.glyphURL);
- spriteStore->setURL(parser.spriteURL);
+ spriteStore->load(parser.spriteURL, fileSource);
loaded = true;
}
@@ -123,6 +124,7 @@ void Style::update(const TransformState& transform,
data.getAnimationTime(),
transform,
workers,
+ fileSource,
texturePool,
shouldReparsePartialTiles,
data.mode,
@@ -180,7 +182,9 @@ void Style::recalculate(float z) {
Source* source = getSource(layer->source);
if (source && layer->needsRendering()) {
source->enabled = true;
- if (!source->loaded && !source->isLoading()) source->load();
+ if (!source->loaded && !source->isLoading()) {
+ source->load(fileSource);
+ }
}
}
}
diff --git a/src/mbgl/style/style.hpp b/src/mbgl/style/style.hpp
index f42578f923..82c048b195 100644
--- a/src/mbgl/style/style.hpp
+++ b/src/mbgl/style/style.hpp
@@ -19,6 +19,7 @@
namespace mbgl {
class MapData;
+class FileSource;
class GlyphAtlas;
class GlyphStore;
class SpriteStore;
@@ -54,7 +55,7 @@ class Style : public GlyphStore::Observer,
public Source::Observer,
public util::noncopyable {
public:
- Style(MapData&);
+ Style(MapData&, FileSource&);
~Style();
class Observer : public GlyphStore::Observer,
@@ -107,6 +108,7 @@ public:
void dumpDebugLogs() const;
MapData& data;
+ FileSource& fileSource;
std::unique_ptr<GlyphStore> glyphStore;
std::unique_ptr<GlyphAtlas> glyphAtlas;
std::unique_ptr<SpriteStore> spriteStore;
diff --git a/src/mbgl/style/style_update_parameters.hpp b/src/mbgl/style/style_update_parameters.hpp
index f9557fdf1b..9ea7e112eb 100644
--- a/src/mbgl/style/style_update_parameters.hpp
+++ b/src/mbgl/style/style_update_parameters.hpp
@@ -7,6 +7,7 @@ namespace mbgl {
class TransformState;
class Worker;
+class FileSource;
class MapData;
class Style;
namespace gl { class TexturePool; }
@@ -18,6 +19,7 @@ public:
TimePoint animationTime_,
const TransformState& transformState_,
Worker& worker_,
+ FileSource& fileSource_,
gl::TexturePool& texturePool_,
bool shouldReparsePartialTiles_,
const MapMode mode_,
@@ -28,6 +30,7 @@ public:
animationTime(animationTime_),
transformState(transformState_),
worker(worker_),
+ fileSource(fileSource_),
texturePool(texturePool_),
shouldReparsePartialTiles(shouldReparsePartialTiles_),
mode(mode_),
@@ -39,6 +42,7 @@ public:
TimePoint animationTime;
const TransformState& transformState;
Worker& worker;
+ FileSource& fileSource;
gl::TexturePool& texturePool;
bool shouldReparsePartialTiles;
const MapMode mode;
diff --git a/src/mbgl/text/glyph_pbf.cpp b/src/mbgl/text/glyph_pbf.cpp
index 5973c0ce14..c9466e8652 100644
--- a/src/mbgl/text/glyph_pbf.cpp
+++ b/src/mbgl/text/glyph_pbf.cpp
@@ -8,7 +8,6 @@
#include <mbgl/util/exception.hpp>
#include <mbgl/util/pbf.hpp>
#include <mbgl/util/string.hpp>
-#include <mbgl/util/thread_context.hpp>
#include <mbgl/util/token.hpp>
#include <mbgl/util/url.hpp>
@@ -64,11 +63,11 @@ namespace mbgl {
GlyphPBF::GlyphPBF(GlyphStore* store,
const std::string& fontStack,
const GlyphRange& glyphRange,
- GlyphStore::Observer* observer_)
+ GlyphStore::Observer* observer_,
+ FileSource& fileSource)
: parsed(false),
observer(observer_) {
- FileSource* fs = util::ThreadContext::getFileSource();
- req = fs->request(Resource::glyphs(store->getURL(), fontStack, glyphRange), [this, store, fontStack, glyphRange](Response res) {
+ req = fileSource.request(Resource::glyphs(store->getURL(), fontStack, glyphRange), [this, store, fontStack, glyphRange](Response res) {
if (res.error) {
observer->onGlyphsError(fontStack, glyphRange, std::make_exception_ptr(std::runtime_error(res.error->message)));
} else if (res.notModified) {
diff --git a/src/mbgl/text/glyph_pbf.hpp b/src/mbgl/text/glyph_pbf.hpp
index 9e2ee4eacf..016792aae8 100644
--- a/src/mbgl/text/glyph_pbf.hpp
+++ b/src/mbgl/text/glyph_pbf.hpp
@@ -14,13 +14,15 @@ namespace mbgl {
class FontStack;
class FileRequest;
+class FileSource;
class GlyphPBF : private util::noncopyable {
public:
GlyphPBF(GlyphStore* store,
const std::string& fontStack,
const GlyphRange&,
- GlyphStore::Observer*);
+ GlyphStore::Observer*,
+ FileSource&);
~GlyphPBF();
bool isParsed() const {
diff --git a/src/mbgl/text/glyph_store.cpp b/src/mbgl/text/glyph_store.cpp
index a3d1530e3d..1c75f7191e 100644
--- a/src/mbgl/text/glyph_store.cpp
+++ b/src/mbgl/text/glyph_store.cpp
@@ -7,7 +7,10 @@
namespace mbgl {
-GlyphStore::GlyphStore() = default;
+GlyphStore::GlyphStore(FileSource& fileSource_)
+ : fileSource(fileSource_) {
+}
+
GlyphStore::~GlyphStore() = default;
void GlyphStore::requestGlyphRange(const std::string& fontStackName, const GlyphRange& range) {
@@ -22,7 +25,7 @@ void GlyphStore::requestGlyphRange(const std::string& fontStackName, const Glyph
}
rangeSets.emplace(range,
- std::make_unique<GlyphPBF>(this, fontStackName, range, observer));
+ std::make_unique<GlyphPBF>(this, fontStackName, range, observer, fileSource));
}
diff --git a/src/mbgl/text/glyph_store.hpp b/src/mbgl/text/glyph_store.hpp
index 2236bce38c..6829397851 100644
--- a/src/mbgl/text/glyph_store.hpp
+++ b/src/mbgl/text/glyph_store.hpp
@@ -14,6 +14,7 @@
namespace mbgl {
+class FileSource;
class GlyphPBF;
// The GlyphStore manages the loading and storage of Glyphs
@@ -29,7 +30,7 @@ public:
virtual void onGlyphsError(const std::string& /* fontStack */, const GlyphRange&, std::exception_ptr) {};
};
- GlyphStore();
+ GlyphStore(FileSource&);
~GlyphStore();
util::exclusive<FontStack> getFontStack(const std::string& fontStack);
@@ -54,6 +55,7 @@ public:
private:
void requestGlyphRange(const std::string& fontStackName, const GlyphRange& range);
+ FileSource& fileSource;
std::string glyphURL;
std::unordered_map<std::string, std::map<GlyphRange, std::unique_ptr<GlyphPBF>>> ranges;
diff --git a/src/mbgl/tile/raster_tile_data.cpp b/src/mbgl/tile/raster_tile_data.cpp
index 25b20e42c2..3f26bbdfdd 100644
--- a/src/mbgl/tile/raster_tile_data.cpp
+++ b/src/mbgl/tile/raster_tile_data.cpp
@@ -13,6 +13,7 @@ RasterTileData::RasterTileData(const TileID& id_,
const std::string& urlTemplate,
gl::TexturePool &texturePool_,
Worker& worker_,
+ FileSource& fileSource,
const std::function<void(std::exception_ptr)>& callback)
: TileData(id_),
texturePool(texturePool_),
@@ -20,7 +21,7 @@ RasterTileData::RasterTileData(const TileID& id_,
state = State::loading;
const Resource resource = Resource::tile(urlTemplate, pixelRatio, id.x, id.y, id.sourceZ);
- req = util::ThreadContext::getFileSource()->request(resource, [callback, this](Response res) {
+ req = fileSource.request(resource, [callback, this](Response res) {
if (res.error) {
callback(std::make_exception_ptr(std::runtime_error(res.error->message)));
} else if (res.notModified) {
diff --git a/src/mbgl/tile/raster_tile_data.hpp b/src/mbgl/tile/raster_tile_data.hpp
index 8d5e901d99..59eee88496 100644
--- a/src/mbgl/tile/raster_tile_data.hpp
+++ b/src/mbgl/tile/raster_tile_data.hpp
@@ -6,6 +6,7 @@
namespace mbgl {
+class FileSource;
class FileRequest;
class StyleLayer;
class WorkRequest;
@@ -18,6 +19,7 @@ public:
const std::string& urlTemplate,
gl::TexturePool&,
Worker&,
+ FileSource&,
const std::function<void(std::exception_ptr)>& callback);
~RasterTileData();
diff --git a/src/mbgl/tile/vector_tile.cpp b/src/mbgl/tile/vector_tile.cpp
index da070abe2e..9e35debbff 100644
--- a/src/mbgl/tile/vector_tile.cpp
+++ b/src/mbgl/tile/vector_tile.cpp
@@ -3,7 +3,6 @@
#include <mbgl/storage/resource.hpp>
#include <mbgl/storage/response.hpp>
#include <mbgl/storage/file_source.hpp>
-#include <mbgl/util/thread_context.hpp>
#include <mbgl/util/url.hpp>
#include <utility>
@@ -182,15 +181,16 @@ util::ptr<const GeometryTileFeature> VectorTileLayer::getFeature(std::size_t i)
return std::make_shared<VectorTileFeature>(features.at(i), *this);
}
-VectorTileMonitor::VectorTileMonitor(const TileID& tileID_, float pixelRatio_, const std::string& urlTemplate_)
+VectorTileMonitor::VectorTileMonitor(const TileID& tileID_, float pixelRatio_, const std::string& urlTemplate_, FileSource& fileSource_)
: tileID(tileID_),
pixelRatio(pixelRatio_),
- urlTemplate(urlTemplate_) {
+ urlTemplate(urlTemplate_),
+ fileSource(fileSource_) {
}
std::unique_ptr<FileRequest> VectorTileMonitor::monitorTile(const GeometryTileMonitor::Callback& callback) {
const Resource resource = Resource::tile(urlTemplate, pixelRatio, tileID.x, tileID.y, tileID.sourceZ);
- return util::ThreadContext::getFileSource()->request(resource, [callback, this](Response res) {
+ return fileSource.request(resource, [callback, this](Response res) {
if (res.error) {
callback(std::make_exception_ptr(std::runtime_error(res.error->message)), nullptr, res.modified, res.expires);
} else if (res.notModified) {
diff --git a/src/mbgl/tile/vector_tile.hpp b/src/mbgl/tile/vector_tile.hpp
index 15cd70a9d4..48e501cbd7 100644
--- a/src/mbgl/tile/vector_tile.hpp
+++ b/src/mbgl/tile/vector_tile.hpp
@@ -59,10 +59,11 @@ private:
};
class TileID;
+class FileSource;
class VectorTileMonitor : public GeometryTileMonitor {
public:
- VectorTileMonitor(const TileID&, float pixelRatio, const std::string& urlTemplate);
+ VectorTileMonitor(const TileID&, float pixelRatio, const std::string& urlTemplate, FileSource&);
std::unique_ptr<FileRequest> monitorTile(const GeometryTileMonitor::Callback&) override;
@@ -70,6 +71,7 @@ private:
TileID tileID;
float pixelRatio;
std::string urlTemplate;
+ FileSource& fileSource;
};
} // namespace mbgl
diff --git a/src/mbgl/util/thread_context.cpp b/src/mbgl/util/thread_context.cpp
index 4853388661..a60f2c9ab5 100644
--- a/src/mbgl/util/thread_context.cpp
+++ b/src/mbgl/util/thread_context.cpp
@@ -44,22 +44,6 @@ ThreadPriority ThreadContext::getPriority() {
}
}
-FileSource* ThreadContext::getFileSource() {
- if (current.get() != nullptr) {
- return current.get()->fileSource;
- } else {
- return nullptr;
- }
-}
-
-void ThreadContext::setFileSource(FileSource* fileSource) {
- if (current.get() != nullptr) {
- current.get()->fileSource = fileSource;
- } else {
- throw std::runtime_error("Current thread has no current ThreadContext.");
- }
-}
-
gl::GLObjectStore* ThreadContext::getGLObjectStore() {
if (current.get() != nullptr) {
return current.get()->glObjectStore;
diff --git a/src/mbgl/util/thread_context.hpp b/src/mbgl/util/thread_context.hpp
index 8601cddbe1..7558400184 100644
--- a/src/mbgl/util/thread_context.hpp
+++ b/src/mbgl/util/thread_context.hpp
@@ -7,7 +7,6 @@
namespace mbgl {
-class FileSource;
namespace gl { class GLObjectStore; }
namespace util {
@@ -34,8 +33,6 @@ public:
static std::string getName();
static ThreadPriority getPriority();
- static FileSource* getFileSource();
- static void setFileSource(FileSource* fileSource);
static gl::GLObjectStore* getGLObjectStore();
static void setGLObjectStore(gl::GLObjectStore* glObjectStore);
@@ -43,7 +40,6 @@ public:
ThreadType type;
ThreadPriority priority;
- FileSource* fileSource = nullptr;
gl::GLObjectStore* glObjectStore = nullptr;
};