diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2015-03-24 11:20:17 +0100 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2015-04-28 14:32:20 -0400 |
commit | f8600d8d9771c4869087d97b30e574441d9a1a1b (patch) | |
tree | 193026b21c02b53648a87096e1c91b00abbf054a | |
parent | 9580ec7b08470de0578f8d21f74ac039c83acdfc (diff) | |
download | qtlocation-mapboxgl-f8600d8d9771c4869087d97b30e574441d9a1a1b.tar.gz |
move getSprite to MapContext
-rw-r--r-- | include/mbgl/map/map.hpp | 2 | ||||
-rw-r--r-- | src/mbgl/map/map.cpp | 17 | ||||
-rw-r--r-- | src/mbgl/map/map_context.cpp | 23 | ||||
-rw-r--r-- | src/mbgl/map/map_context.hpp | 8 |
4 files changed, 30 insertions, 20 deletions
diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 0db726b51b..6f7c52cca1 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -173,8 +173,6 @@ private: void resize(uint16_t width, uint16_t height, float ratio = 1); void resize(uint16_t width, uint16_t height, float ratio, uint16_t fbWidth, uint16_t fbHeight); - util::ptr<Sprite> getSprite(); - // Checks if render thread needs to pause void checkForPause(); diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index a8a5d15ff1..208ca92f1f 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -66,7 +66,7 @@ Map::Map(View& view_, FileSource& fileSource_) scope(util::make_unique<EnvironmentScope>(*env, ThreadType::Main, "Main")), view(view_), data(util::make_unique<MapData>(view_)), - context(util::make_unique<MapContext>(*env)), + context(util::make_unique<MapContext>(*env, *data)), updated(static_cast<UpdateType>(Update::Nothing)) { view.initialize(this); @@ -430,17 +430,6 @@ std::string Map::getStyleJSON() const { return data->getStyleInfo().json; } -util::ptr<Sprite> Map::getSprite() { - assert(Environment::currentlyOn(ThreadType::Map)); - const float pixelRatio = data->getTransformState().getPixelRatio(); - const std::string &sprite_url = context->style->getSpriteURL(); - if (!context->sprite || !context->sprite->hasPixelRatio(pixelRatio)) { - context->sprite = Sprite::Create(sprite_url, pixelRatio, *env); - } - - return context->sprite; -} - #pragma mark - Size void Map::resize(uint16_t width, uint16_t height, float ratio) { @@ -739,7 +728,7 @@ void Map::updateTiles() { if (!context->style) return; for (const auto& source : context->style->sources) { source->update(*data, context->getWorker(), context->style, *context->glyphAtlas, *context->glyphStore, - *context->spriteAtlas, getSprite(), *context->texturePool, [this]() { + *context->spriteAtlas, context->getSprite(), *context->texturePool, [this]() { assert(Environment::currentlyOn(ThreadType::Map)); triggerUpdate(); }); @@ -854,7 +843,7 @@ void Map::prepare() { // Allow the sprite atlas to potentially pull new sprite images if needed. context->spriteAtlas->resize(data->getTransformState().getPixelRatio()); - context->spriteAtlas->setSprite(getSprite()); + context->spriteAtlas->setSprite(context->getSprite()); updateTiles(); } diff --git a/src/mbgl/map/map_context.cpp b/src/mbgl/map/map_context.cpp index cad2bd8991..1380667ea8 100644 --- a/src/mbgl/map/map_context.cpp +++ b/src/mbgl/map/map_context.cpp @@ -1,5 +1,7 @@ #include <mbgl/map/map_context.hpp> +#include <mbgl/map/map_data.hpp> #include <mbgl/map/environment.hpp> +#include <mbgl/map/sprite.hpp> #include <mbgl/renderer/painter.hpp> @@ -9,6 +11,8 @@ #include <mbgl/geometry/sprite_atlas.hpp> #include <mbgl/geometry/line_atlas.hpp> +#include <mbgl/style/style.hpp> + #include <mbgl/util/std.hpp> #include <mbgl/util/uv_detail.hpp> #include <mbgl/util/worker.hpp> @@ -16,8 +20,10 @@ namespace mbgl { -MapContext::MapContext(Environment& env) - : glyphStore(util::make_unique<GlyphStore>(env)), +MapContext::MapContext(Environment& env_, MapData& data_) + : env(env_), + data(data_), + glyphStore(util::make_unique<GlyphStore>(env)), glyphAtlas(util::make_unique<GlyphAtlas>(1024, 1024)), spriteAtlas(util::make_unique<SpriteAtlas>(512, 512)), lineAtlas(util::make_unique<LineAtlas>(512, 512)), @@ -30,4 +36,15 @@ Worker& MapContext::getWorker() { return *workers; } -}
\ No newline at end of file +util::ptr<Sprite> MapContext::getSprite() { + assert(Environment::currentlyOn(ThreadType::Map)); + const float pixelRatio = data.getTransformState().getPixelRatio(); + const std::string &sprite_url = style->getSpriteURL(); + if (!sprite || !sprite->hasPixelRatio(pixelRatio)) { + sprite = Sprite::Create(sprite_url, pixelRatio, env); + } + + return sprite; +} + +} diff --git a/src/mbgl/map/map_context.hpp b/src/mbgl/map/map_context.hpp index c927a931c2..d1eadb045a 100644 --- a/src/mbgl/map/map_context.hpp +++ b/src/mbgl/map/map_context.hpp @@ -8,6 +8,7 @@ namespace mbgl { class Environment; +class MapData; class GlyphStore; class GlyphAtlas; class SpriteAtlas; @@ -20,12 +21,17 @@ class Worker; class MapContext { public: - MapContext(Environment&); + MapContext(Environment&, MapData&); Worker& getWorker(); + util::ptr<Sprite> getSprite(); public: std::unique_ptr<Worker> workers; + +public: + Environment& env; + MapData& data; const std::unique_ptr<GlyphStore> glyphStore; const std::unique_ptr<GlyphAtlas> glyphAtlas; const std::unique_ptr<SpriteAtlas> spriteAtlas; |