diff options
-rw-r--r-- | include/mbgl/map/map.hpp | 3 | ||||
-rw-r--r-- | include/mbgl/map/source.hpp | 6 | ||||
-rw-r--r-- | include/mbgl/map/tile_data.hpp | 8 | ||||
-rw-r--r-- | src/map/map.cpp | 2 | ||||
-rw-r--r-- | src/map/source.cpp | 12 | ||||
-rw-r--r-- | src/map/tile_data.cpp | 10 |
6 files changed, 23 insertions, 18 deletions
diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index fca3619c0c..e56a0f81c1 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -129,12 +129,13 @@ public: inline util::ptr<Style> getStyle() const { return style; } util::ptr<Sprite> getSprite(); inline util::ptr<Texturepool> getTexturepool() { return texturepool; } - uv::worker &getWorker(); inline timestamp getAnimationTime() const { return animationTime; } inline timestamp getTime() const { return animationTime; } void updateTiles(); private: + uv::worker& getWorker(); + // uv async callbacks static void render(uv_async_t *async); static void terminate(uv_async_t *async); diff --git a/include/mbgl/map/source.hpp b/include/mbgl/map/source.hpp index b515d26f0a..1ceb04d326 100644 --- a/include/mbgl/map/source.hpp +++ b/include/mbgl/map/source.hpp @@ -32,7 +32,7 @@ public: Source(const util::ptr<SourceInfo>& info); void load(Map&, FileSource&); - bool update(Map&, GlyphAtlas&, GlyphStore&, SpriteAtlas&, FileSource&); + bool update(Map&, uv::worker&, GlyphAtlas&, GlyphStore&, SpriteAtlas&, FileSource&); void updateMatrices(const mat4 &projMatrix, const TransformState &transform); void drawClippingMasks(Painter &painter); @@ -51,9 +51,9 @@ private: int32_t coveringZoomLevel(const TransformState&) const; std::forward_list<Tile::ID> coveringTiles(const TransformState&) const; - bool updateTiles(Map&, GlyphAtlas&, GlyphStore&, SpriteAtlas&, FileSource&); + bool updateTiles(Map&, uv::worker&, GlyphAtlas&, GlyphStore&, SpriteAtlas&, FileSource&); - TileData::State addTile(Map&, GlyphAtlas&, GlyphStore&, SpriteAtlas&, FileSource&, const Tile::ID&); + TileData::State addTile(Map&, uv::worker&, GlyphAtlas&, GlyphStore&, SpriteAtlas&, FileSource&, const Tile::ID&); TileData::State hasTile(const Tile::ID& id); double getZoom(const TransformState &state) const; diff --git a/include/mbgl/map/tile_data.hpp b/include/mbgl/map/tile_data.hpp index baae542e49..3907ac10ce 100644 --- a/include/mbgl/map/tile_data.hpp +++ b/include/mbgl/map/tile_data.hpp @@ -13,6 +13,10 @@ #include <iosfwd> #include <string> +namespace uv { +class worker; +} + namespace mbgl { class Map; @@ -44,9 +48,9 @@ public: TileData(Tile::ID const& id, Map &map, const util::ptr<SourceInfo> &source); ~TileData(); - void request(FileSource&); + void request(uv::worker&, FileSource&); + void reparse(uv::worker&); void cancel(); - void reparse(); const std::string toString() const; inline bool ready() const { diff --git a/src/map/map.cpp b/src/map/map.cpp index fbfc6abd3a..750061e082 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -642,7 +642,7 @@ void Map::updateSources(const util::ptr<StyleLayerGroup> &group) { void Map::updateTiles() { for (const util::ptr<StyleSource> &source : getActiveSources()) { - source->source->update(*this, glyphAtlas, *glyphStore, spriteAtlas, *fileSource); + source->source->update(*this, getWorker(), glyphAtlas, *glyphStore, spriteAtlas, *fileSource); } } diff --git a/src/map/source.cpp b/src/map/source.cpp index b11b9dd460..72e63f9e17 100644 --- a/src/map/source.cpp +++ b/src/map/source.cpp @@ -61,11 +61,11 @@ void Source::load(Map& map, FileSource& fileSource) { }); } -bool Source::update(Map& map, +bool Source::update(Map& map, uv::worker& worker, GlyphAtlas& glyphAtlas, GlyphStore& glyphStore, SpriteAtlas& spriteAtlas, FileSource& fileSource) { if (loaded && map.getTime() > updated) { - return updateTiles(map, glyphAtlas, glyphStore, spriteAtlas, fileSource); + return updateTiles(map, worker, glyphAtlas, glyphStore, spriteAtlas, fileSource); } else { return false; } @@ -161,7 +161,7 @@ TileData::State Source::hasTile(const Tile::ID& id) { return TileData::State::invalid; } -TileData::State Source::addTile(Map& map, +TileData::State Source::addTile(Map& map, uv::worker& worker, GlyphAtlas& glyphAtlas, GlyphStore& glyphStore, SpriteAtlas& spriteAtlas, FileSource& fileSource, const Tile::ID& id) { @@ -199,7 +199,7 @@ TileData::State Source::addTile(Map& map, throw std::runtime_error("source type not implemented"); } - new_tile.data->request(fileSource); + new_tile.data->request(worker, fileSource); tile_data.emplace(new_tile.data->id, new_tile.data); } @@ -286,7 +286,7 @@ bool Source::findLoadedParent(const Tile::ID& id, int32_t minCoveringZoom, std:: return false; } -bool Source::updateTiles(Map& map, +bool Source::updateTiles(Map& map, uv::worker& worker, GlyphAtlas& glyphAtlas, GlyphStore& glyphStore, SpriteAtlas& spriteAtlas, FileSource& fileSource) { bool changed = false; @@ -305,7 +305,7 @@ bool Source::updateTiles(Map& map, // Add existing child/parent tiles if the actual tile is not yet loaded for (const Tile::ID& id : required) { - const TileData::State state = addTile(map, glyphAtlas, glyphStore, spriteAtlas, fileSource, id); + const TileData::State state = addTile(map, worker, glyphAtlas, glyphStore, spriteAtlas, fileSource, id); if (state != TileData::State::parsed) { // The tile we require is not yet loaded. Try to find a parent or diff --git a/src/map/tile_data.cpp b/src/map/tile_data.cpp index 0a59bdc62b..3be8b3788b 100644 --- a/src/map/tile_data.cpp +++ b/src/map/tile_data.cpp @@ -28,7 +28,7 @@ const std::string TileData::toString() const { return util::sprintf<32>("[tile %d/%d/%d]", id.z, id.x, id.y); } -void TileData::request(FileSource& fileSource) { +void TileData::request(uv::worker& worker, FileSource& fileSource) { if (source->tiles.empty()) return; @@ -52,7 +52,7 @@ void TileData::request(FileSource& fileSource) { // Note: Somehow this feels slower than the change to request_http() std::weak_ptr<TileData> weak_tile = shared_from_this(); req = fileSource.request(ResourceType::Tile, url); - req->onload([weak_tile, url](const Response &res) { + req->onload([weak_tile, url, &worker](const Response &res) { util::ptr<TileData> tile = weak_tile.lock(); if (!tile || tile->state == State::obsolete) { // noop. Tile is obsolete and we're now just waiting for the refcount @@ -69,7 +69,7 @@ void TileData::request(FileSource& fileSource) { tile->data = res.data; // Schedule tile parsing in another thread - tile->reparse(); + tile->reparse(worker); } else { #if defined(DEBUG) fprintf(stderr, "[%s] tile loading failed: %ld, %s\n", url.c_str(), res.code, res.message.c_str()); @@ -88,12 +88,12 @@ void TileData::cancel() { } } -void TileData::reparse() +void TileData::reparse(uv::worker& worker) { // We're creating a new work request. The work request deletes itself after it executed // the after work handler new uv::work<util::ptr<TileData>>( - map.getWorker(), + worker, [](util::ptr<TileData> &tile) { tile->parse(); }, |