diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2014-11-25 16:35:27 -0800 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2014-11-26 15:13:14 -0800 |
commit | 23b61f808cca8d926c11bbb738f384522e41dbbd (patch) | |
tree | fb93d18c0454628b6f320ca08562cfabfc488a66 | |
parent | 9af3b033bf41cd32635172864d58dc169168f9e6 (diff) | |
download | qtlocation-mapboxgl-23b61f808cca8d926c11bbb738f384522e41dbbd.tar.gz |
Eliminate remaining uses of Map in TileData
-rw-r--r-- | include/mbgl/map/raster_tile_data.hpp | 3 | ||||
-rw-r--r-- | include/mbgl/map/source.hpp | 9 | ||||
-rw-r--r-- | include/mbgl/map/tile_data.hpp | 10 | ||||
-rw-r--r-- | include/mbgl/map/vector_tile_data.hpp | 5 | ||||
-rw-r--r-- | include/mbgl/util/uv_detail.hpp | 4 | ||||
-rw-r--r-- | src/map/map.cpp | 2 | ||||
-rw-r--r-- | src/map/raster_tile_data.cpp | 4 | ||||
-rw-r--r-- | src/map/source.cpp | 20 | ||||
-rw-r--r-- | src/map/tile_data.cpp | 20 | ||||
-rw-r--r-- | src/map/vector_tile_data.cpp | 8 |
10 files changed, 44 insertions, 41 deletions
diff --git a/include/mbgl/map/raster_tile_data.hpp b/include/mbgl/map/raster_tile_data.hpp index c73897289f..c3bd2fbe3a 100644 --- a/include/mbgl/map/raster_tile_data.hpp +++ b/include/mbgl/map/raster_tile_data.hpp @@ -7,7 +7,6 @@ namespace mbgl { -class Map; class Painter; class SourceInfo; class StyleLayer; @@ -17,7 +16,7 @@ class RasterTileData : public TileData { friend class TileParser; public: - RasterTileData(Tile::ID const& id, Map &map, Texturepool&, const util::ptr<SourceInfo> &source); + RasterTileData(Tile::ID const& id, Texturepool&, const util::ptr<SourceInfo> &source); ~RasterTileData(); virtual void parse(); diff --git a/include/mbgl/map/source.hpp b/include/mbgl/map/source.hpp index 8de02735c6..6356238790 100644 --- a/include/mbgl/map/source.hpp +++ b/include/mbgl/map/source.hpp @@ -39,7 +39,8 @@ public: util::ptr<Style>, GlyphAtlas&, GlyphStore&, SpriteAtlas&, util::ptr<Sprite>, - Texturepool&, FileSource&); + Texturepool&, FileSource&, + std::function<void ()> callback); void updateMatrices(const mat4 &projMatrix, const TransformState &transform); void drawClippingMasks(Painter &painter); @@ -62,14 +63,16 @@ private: util::ptr<Style>, GlyphAtlas&, GlyphStore&, SpriteAtlas&, util::ptr<Sprite>, - Texturepool&, FileSource&); + Texturepool&, FileSource&, + std::function<void ()> callback); TileData::State addTile(Map&, uv::worker&, util::ptr<Style>, GlyphAtlas&, GlyphStore&, SpriteAtlas&, util::ptr<Sprite>, FileSource&, Texturepool&, - const Tile::ID&); + const Tile::ID&, + std::function<void ()> callback); TileData::State hasTile(const Tile::ID& id); diff --git a/include/mbgl/map/tile_data.hpp b/include/mbgl/map/tile_data.hpp index 3907ac10ce..7fbb5d5068 100644 --- a/include/mbgl/map/tile_data.hpp +++ b/include/mbgl/map/tile_data.hpp @@ -12,6 +12,7 @@ #include <exception> #include <iosfwd> #include <string> +#include <functional> namespace uv { class worker; @@ -45,11 +46,11 @@ public: }; public: - TileData(Tile::ID const& id, Map &map, const util::ptr<SourceInfo> &source); + TileData(Tile::ID const& id, const util::ptr<SourceInfo> &source); ~TileData(); - void request(uv::worker&, FileSource&); - void reparse(uv::worker&); + void request(uv::worker&, FileSource&, float pixelRatio, std::function<void ()> callback); + void reparse(uv::worker&, std::function<void ()> callback); void cancel(); const std::string toString() const; @@ -67,9 +68,6 @@ public: const Tile::ID id; std::atomic<State> state; -protected: - Map ↦ - public: util::ptr<SourceInfo> source; diff --git a/include/mbgl/map/vector_tile_data.hpp b/include/mbgl/map/vector_tile_data.hpp index 9fa9e4c84f..53dbb7eeb1 100644 --- a/include/mbgl/map/vector_tile_data.hpp +++ b/include/mbgl/map/vector_tile_data.hpp @@ -16,7 +16,6 @@ namespace mbgl { class Bucket; -class Map; class Painter; class SourceInfo; class StyleLayer; @@ -32,8 +31,8 @@ class VectorTileData : public TileData { friend class TileParser; public: - VectorTileData(Tile::ID const&, Map&, - util::ptr<Style>, + VectorTileData(Tile::ID const&, + float mapMaxZoom, util::ptr<Style>, GlyphAtlas&, GlyphStore&, SpriteAtlas&, util::ptr<Sprite>, Texturepool&, diff --git a/include/mbgl/util/uv_detail.hpp b/include/mbgl/util/uv_detail.hpp index 5da222b045..2501a9f3e0 100644 --- a/include/mbgl/util/uv_detail.hpp +++ b/include/mbgl/util/uv_detail.hpp @@ -144,8 +144,8 @@ private: template <typename T> class work { public: - typedef void (*work_callback)(T &object); - typedef void (*after_work_callback)(T &object); + typedef std::function<void (T&)> work_callback; + typedef std::function<void (T&)> after_work_callback; template<typename... Args> work(worker &worker, work_callback work_cb_, after_work_callback after_work_cb_, Args&&... args) diff --git a/src/map/map.cpp b/src/map/map.cpp index f2822f3967..eb0a48d8d6 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -645,7 +645,7 @@ void Map::updateTiles() { source->source->update(*this, getWorker(), style, glyphAtlas, *glyphStore, spriteAtlas, getSprite(), - *texturepool, *fileSource); + *texturepool, *fileSource, [this](){ update(); }); } } diff --git a/src/map/raster_tile_data.cpp b/src/map/raster_tile_data.cpp index 04e89d9e37..b2d0cf6a6b 100644 --- a/src/map/raster_tile_data.cpp +++ b/src/map/raster_tile_data.cpp @@ -5,8 +5,8 @@ using namespace mbgl; -RasterTileData::RasterTileData(Tile::ID const& id_, Map &map_, Texturepool& texturepool, const util::ptr<SourceInfo> &source_) - : TileData(id_, map_, source_), +RasterTileData::RasterTileData(Tile::ID const& id_, Texturepool& texturepool, const util::ptr<SourceInfo> &source_) + : TileData(id_, source_), bucket(texturepool, properties) { } diff --git a/src/map/source.cpp b/src/map/source.cpp index 0348e02513..d617d2cdee 100644 --- a/src/map/source.cpp +++ b/src/map/source.cpp @@ -65,12 +65,14 @@ bool Source::update(Map& map, uv::worker& worker, util::ptr<Style> style, GlyphAtlas& glyphAtlas, GlyphStore& glyphStore, SpriteAtlas& spriteAtlas, util::ptr<Sprite> sprite, - Texturepool& texturepool, FileSource& fileSource) { + Texturepool& texturepool, FileSource& fileSource, + std::function<void ()> callback) { if (loaded && map.getTime() > updated) { return updateTiles(map, worker, style, glyphAtlas, glyphStore, spriteAtlas, sprite, - texturepool, fileSource); + texturepool, fileSource, + callback); } else { return false; } @@ -171,7 +173,8 @@ TileData::State Source::addTile(Map& map, uv::worker& worker, GlyphAtlas& glyphAtlas, GlyphStore& glyphStore, SpriteAtlas& spriteAtlas, util::ptr<Sprite> sprite, FileSource& fileSource, Texturepool& texturepool, - const Tile::ID& id) { + const Tile::ID& id, + std::function<void ()> callback) { const TileData::State state = hasTile(id); if (state != TileData::State::invalid) { @@ -199,17 +202,17 @@ TileData::State Source::addTile(Map& map, uv::worker& worker, if (!new_tile.data) { // If we don't find working tile data, we're just going to load it. if (info->type == SourceType::Vector) { - new_tile.data = std::make_shared<VectorTileData>(normalized_id, map, style, + new_tile.data = std::make_shared<VectorTileData>(normalized_id, map.getMaxZoom(), style, glyphAtlas, glyphStore, spriteAtlas, sprite, texturepool, info); } else if (info->type == SourceType::Raster) { - new_tile.data = std::make_shared<RasterTileData>(normalized_id, map, texturepool, info); + new_tile.data = std::make_shared<RasterTileData>(normalized_id, texturepool, info); } else { throw std::runtime_error("source type not implemented"); } - new_tile.data->request(worker, fileSource); + new_tile.data->request(worker, fileSource, map.getState().getPixelRatio(), callback); tile_data.emplace(new_tile.data->id, new_tile.data); } @@ -299,7 +302,8 @@ bool Source::findLoadedParent(const Tile::ID& id, int32_t minCoveringZoom, std:: bool Source::updateTiles(Map& map, uv::worker& worker, util::ptr<Style> style, GlyphAtlas& glyphAtlas, GlyphStore& glyphStore, SpriteAtlas& spriteAtlas, util::ptr<Sprite> sprite, - Texturepool& texturepool, FileSource& fileSource) { + Texturepool& texturepool, FileSource& fileSource, + std::function<void ()> callback) { bool changed = false; int32_t zoom = std::floor(getZoom(map.getState())); @@ -320,7 +324,7 @@ bool Source::updateTiles(Map& map, uv::worker& worker, util::ptr<Style> style, glyphAtlas, glyphStore, spriteAtlas, sprite, fileSource, texturepool, - id); + id, callback); 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 3be8b3788b..1cbcf00825 100644 --- a/src/map/tile_data.cpp +++ b/src/map/tile_data.cpp @@ -9,10 +9,9 @@ using namespace mbgl; -TileData::TileData(Tile::ID const& id_, Map &map_, const util::ptr<SourceInfo> &source_) +TileData::TileData(Tile::ID const& id_, const util::ptr<SourceInfo> &source_) : id(id_), state(State::initial), - map(map_), source(source_), debugBucket(debugFontBuffer) { // Initialize tile debug coordinates @@ -28,7 +27,8 @@ const std::string TileData::toString() const { return util::sprintf<32>("[tile %d/%d/%d]", id.z, id.x, id.y); } -void TileData::request(uv::worker& worker, FileSource& fileSource) { +void TileData::request(uv::worker& worker, FileSource& fileSource, + float pixelRatio, std::function<void ()> callback) { if (source->tiles.empty()) return; @@ -43,7 +43,7 @@ void TileData::request(uv::worker& worker, FileSource& fileSource) { prefix[1] = "0123456789abcdef"[id.y % 16]; return prefix; } - if (token == "ratio") return (map.getState().getPixelRatio() > 1.0 ? "@2x" : ""); + if (token == "ratio") return pixelRatio > 1.0 ? "@2x" : ""; return ""; }); @@ -52,7 +52,7 @@ void TileData::request(uv::worker& worker, 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, &worker](const Response &res) { + req->onload([weak_tile, url, callback, &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(uv::worker& worker, FileSource& fileSource) { tile->data = res.data; // Schedule tile parsing in another thread - tile->reparse(worker); + tile->reparse(worker, callback); } else { #if defined(DEBUG) fprintf(stderr, "[%s] tile loading failed: %ld, %s\n", url.c_str(), res.code, res.message.c_str()); @@ -88,17 +88,17 @@ void TileData::cancel() { } } -void TileData::reparse(uv::worker& worker) +void TileData::reparse(uv::worker& worker, std::function<void()> callback) { // 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>>( worker, - [](util::ptr<TileData> &tile) { + [](util::ptr<TileData>& tile) { tile->parse(); }, - [](util::ptr<TileData> &tile) { - tile->map.update(); + [callback](util::ptr<TileData>&) { + callback(); }, shared_from_this()); } diff --git a/src/map/vector_tile_data.cpp b/src/map/vector_tile_data.cpp index e662379abb..8193f7e8a5 100644 --- a/src/map/vector_tile_data.cpp +++ b/src/map/vector_tile_data.cpp @@ -8,20 +8,20 @@ using namespace mbgl; -VectorTileData::VectorTileData(Tile::ID const& id_, Map &map_, - util::ptr<Style> style_, +VectorTileData::VectorTileData(Tile::ID const& id_, + float mapMaxZoom, util::ptr<Style> style_, GlyphAtlas& glyphAtlas_, GlyphStore& glyphStore_, SpriteAtlas& spriteAtlas_, util::ptr<Sprite> sprite_, Texturepool& texturepool_, const util::ptr<SourceInfo> &source_) - : TileData(id_, map_, source_), + : TileData(id_, source_), glyphAtlas(glyphAtlas_), glyphStore(glyphStore_), spriteAtlas(spriteAtlas_), sprite(sprite_), texturepool(texturepool_), style(style_), - depth(id.z >= source->max_zoom ? map.getMaxZoom() - id.z : 1) { + depth(id.z >= source->max_zoom ? mapMaxZoom - id.z : 1) { } VectorTileData::~VectorTileData() { |