diff options
-rw-r--r-- | src/mbgl/map/map_context.cpp | 11 | ||||
-rw-r--r-- | src/mbgl/map/map_context.hpp | 1 | ||||
-rw-r--r-- | src/mbgl/source/source.cpp | 11 | ||||
-rw-r--r-- | src/mbgl/source/source.hpp | 3 | ||||
-rw-r--r-- | src/mbgl/sprite/sprite_store.cpp | 8 | ||||
-rw-r--r-- | src/mbgl/sprite/sprite_store.hpp | 4 | ||||
-rw-r--r-- | src/mbgl/style/style.cpp | 12 | ||||
-rw-r--r-- | src/mbgl/style/style.hpp | 4 | ||||
-rw-r--r-- | src/mbgl/style/style_update_parameters.hpp | 4 | ||||
-rw-r--r-- | src/mbgl/text/glyph_pbf.cpp | 7 | ||||
-rw-r--r-- | src/mbgl/text/glyph_pbf.hpp | 4 | ||||
-rw-r--r-- | src/mbgl/text/glyph_store.cpp | 7 | ||||
-rw-r--r-- | src/mbgl/text/glyph_store.hpp | 4 | ||||
-rw-r--r-- | src/mbgl/tile/raster_tile_data.cpp | 3 | ||||
-rw-r--r-- | src/mbgl/tile/raster_tile_data.hpp | 2 | ||||
-rw-r--r-- | src/mbgl/tile/vector_tile.cpp | 8 | ||||
-rw-r--r-- | src/mbgl/tile/vector_tile.hpp | 4 | ||||
-rw-r--r-- | src/mbgl/util/thread_context.cpp | 16 | ||||
-rw-r--r-- | src/mbgl/util/thread_context.hpp | 4 | ||||
-rw-r--r-- | test/sprite/sprite_store.cpp | 6 | ||||
-rw-r--r-- | test/style/glyph_store.cpp | 3 | ||||
-rw-r--r-- | test/style/source.cpp | 24 | ||||
-rw-r--r-- | test/style/style.cpp | 9 |
23 files changed, 79 insertions, 80 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; }; diff --git a/test/sprite/sprite_store.cpp b/test/sprite/sprite_store.cpp index ee6ea2e9e0..ec7b91b875 100644 --- a/test/sprite/sprite_store.cpp +++ b/test/sprite/sprite_store.cpp @@ -156,7 +156,6 @@ public: SpriteStoreTest() : spriteStore(1.0) {} - util::ThreadContext context { "Map", util::ThreadType::Map, util::ThreadPriority::Regular }; util::RunLoop loop; StubFileSource fileSource; StubStyleObserver observer; @@ -166,11 +165,8 @@ public: // Squelch logging. Log::setObserver(std::make_unique<Log::NullObserver>()); - util::ThreadContext::Set(&context); - util::ThreadContext::setFileSource(&fileSource); - spriteStore.setObserver(&observer); - spriteStore.setURL("test/fixtures/resources/sprite"); + spriteStore.load("test/fixtures/resources/sprite", fileSource); loop.run(); } diff --git a/test/style/glyph_store.cpp b/test/style/glyph_store.cpp index 55f19672af..ff88841450 100644 --- a/test/style/glyph_store.cpp +++ b/test/style/glyph_store.cpp @@ -17,14 +17,13 @@ public: util::RunLoop loop; StubFileSource fileSource; StubStyleObserver observer; - GlyphStore glyphStore; + GlyphStore glyphStore { fileSource }; void run(const std::string& url, const std::string& fontStack, const std::set<GlyphRange>& glyphRanges) { // Squelch logging. Log::setObserver(std::make_unique<Log::NullObserver>()); util::ThreadContext::Set(&context); - util::ThreadContext::setFileSource(&fileSource); glyphStore.setObserver(&observer); glyphStore.setURL(url); diff --git a/test/style/source.cpp b/test/style/source.cpp index 993d827ce1..bbe37fcf05 100644 --- a/test/style/source.cpp +++ b/test/style/source.cpp @@ -31,7 +31,7 @@ public: Worker worker { 1 }; gl::TexturePool texturePool; MapData mapData { MapMode::Still, GLContextMode::Unique, 1.0 }; - Style style { mapData }; + Style style { mapData, fileSource }; StyleUpdateParameters updateParameters { 1.0, @@ -39,6 +39,7 @@ public: TimePoint(), transformState, worker, + fileSource, texturePool, true, MapMode::Continuous, @@ -51,7 +52,6 @@ public: Log::setObserver(std::make_unique<Log::NullObserver>()); util::ThreadContext::Set(&context); - util::ThreadContext::setFileSource(&fileSource); transform.resize({{ 512, 512 }}); transform.setLatLngZoom({0, 0}, 0); @@ -88,7 +88,7 @@ TEST(Source, LoadingFail) { Source source(SourceType::Vector, "source", "url", 512, nullptr, nullptr); source.setObserver(&test.observer); - source.load(); + source.load(test.fileSource); test.run(); } @@ -111,7 +111,7 @@ TEST(Source, LoadingCorrupt) { Source source(SourceType::Vector, "source", "url", 512, nullptr, nullptr); source.setObserver(&test.observer); - source.load(); + source.load(test.fileSource); test.run(); } @@ -139,7 +139,7 @@ TEST(Source, RasterTileEmpty) { Source source(SourceType::Raster, "source", "", 512, std::move(info), nullptr); source.setObserver(&test.observer); - source.load(); + source.load(test.fileSource); source.update(test.updateParameters); test.run(); @@ -168,7 +168,7 @@ TEST(Source, VectorTileEmpty) { Source source(SourceType::Vector, "source", "", 512, std::move(info), nullptr); source.setObserver(&test.observer); - source.load(); + source.load(test.fileSource); source.update(test.updateParameters); test.run(); @@ -197,7 +197,7 @@ TEST(Source, RasterTileFail) { Source source(SourceType::Raster, "source", "", 512, std::move(info), nullptr); source.setObserver(&test.observer); - source.load(); + source.load(test.fileSource); source.update(test.updateParameters); test.run(); @@ -226,7 +226,7 @@ TEST(Source, VectorTileFail) { Source source(SourceType::Vector, "source", "", 512, std::move(info), nullptr); source.setObserver(&test.observer); - source.load(); + source.load(test.fileSource); source.update(test.updateParameters); test.run(); @@ -254,7 +254,7 @@ TEST(Source, RasterTileCorrupt) { Source source(SourceType::Raster, "source", "", 512, std::move(info), nullptr); source.setObserver(&test.observer); - source.load(); + source.load(test.fileSource); source.update(test.updateParameters); test.run(); @@ -287,7 +287,7 @@ TEST(Source, VectorTileCorrupt) { Source source(SourceType::Vector, "source", "", 512, std::move(info), nullptr); source.setObserver(&test.observer); - source.load(); + source.load(test.fileSource); source.update(test.updateParameters); test.run(); @@ -314,7 +314,7 @@ TEST(Source, RasterTileCancel) { Source source(SourceType::Raster, "source", "", 512, std::move(info), nullptr); source.setObserver(&test.observer); - source.load(); + source.load(test.fileSource); source.update(test.updateParameters); test.run(); @@ -341,7 +341,7 @@ TEST(Source, VectorTileCancel) { Source source(SourceType::Vector, "source", "", 512, std::move(info), nullptr); source.setObserver(&test.observer); - source.load(); + source.load(test.fileSource); source.update(test.updateParameters); test.run(); diff --git a/test/style/style.cpp b/test/style/style.cpp index 59366ea7dd..b4211cb071 100644 --- a/test/style/style.cpp +++ b/test/style/style.cpp @@ -1,4 +1,5 @@ #include "../fixtures/util.hpp" +#include "../fixtures/stub_file_source.hpp" #include <mbgl/map/map_data.hpp> #include <mbgl/style/style.hpp> @@ -7,11 +8,13 @@ using namespace mbgl; TEST(Style, UnusedSource) { + util::RunLoop loop; util::ThreadContext context { "Map", util::ThreadType::Map, util::ThreadPriority::Regular }; util::ThreadContext::Set(&context); MapData data { MapMode::Still, GLContextMode::Unique, 1.0 }; - Style style { data }; + StubFileSource fileSource; + Style style { data, fileSource }; style.setJSON(util::read_file("test/fixtures/resources/style-unused-sources.json"), ""); style.cascade(); @@ -27,11 +30,13 @@ TEST(Style, UnusedSource) { } TEST(Style, UnusedSourceActiveViaClassUpdate) { + util::RunLoop loop; util::ThreadContext context { "Map", util::ThreadType::Map, util::ThreadPriority::Regular }; util::ThreadContext::Set(&context); MapData data { MapMode::Still, GLContextMode::Unique, 1.0 }; - Style style { data }; + StubFileSource fileSource; + Style style { data, fileSource }; data.addClass("visible"); |