summaryrefslogtreecommitdiff
path: root/src/mbgl/map
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/map')
-rw-r--r--src/mbgl/map/map_context.cpp38
-rw-r--r--src/mbgl/map/map_context.hpp16
-rw-r--r--src/mbgl/map/resource_loader.cpp160
-rw-r--r--src/mbgl/map/resource_loader.hpp91
4 files changed, 9 insertions, 296 deletions
diff --git a/src/mbgl/map/map_context.cpp b/src/mbgl/map/map_context.cpp
index c8948097f7..a834f50655 100644
--- a/src/mbgl/map/map_context.cpp
+++ b/src/mbgl/map/map_context.cpp
@@ -2,19 +2,12 @@
#include <mbgl/map/map_data.hpp>
#include <mbgl/map/view.hpp>
#include <mbgl/map/environment.hpp>
-#include <mbgl/map/source.hpp>
#include <mbgl/map/still_image.hpp>
#include <mbgl/platform/log.hpp>
#include <mbgl/renderer/painter.hpp>
-#include <mbgl/text/glyph_store.hpp>
-
-#include <mbgl/geometry/glyph_atlas.hpp>
-#include <mbgl/geometry/sprite_atlas.hpp>
-#include <mbgl/geometry/line_atlas.hpp>
-
#include <mbgl/storage/resource.hpp>
#include <mbgl/storage/response.hpp>
@@ -34,10 +27,6 @@ MapContext::MapContext(uv_loop_t* loop, View& view_, FileSource& fileSource, Map
envScope(env, ThreadType::Map, "Map"),
updated(static_cast<UpdateType>(Update::Nothing)),
asyncUpdate(std::make_unique<uv::async>(loop, [this] { update(); })),
- glyphStore(std::make_unique<GlyphStore>(loop, env)),
- glyphAtlas(std::make_unique<GlyphAtlas>(1024, 1024)),
- spriteAtlas(std::make_unique<SpriteAtlas>(512, 512)),
- lineAtlas(std::make_unique<LineAtlas>(512, 512)),
texturePool(std::make_unique<TexturePool>()) {
assert(Environment::currentlyOn(ThreadType::Map));
@@ -51,14 +40,9 @@ MapContext::~MapContext() {
// Explicit resets currently necessary because these abandon resources that need to be
// cleaned up by env.performCleanup();
- resourceLoader.reset();
style.reset();
painter.reset();
texturePool.reset();
- lineAtlas.reset();
- spriteAtlas.reset();
- glyphAtlas.reset();
- glyphStore.reset();
env.performCleanup();
@@ -116,21 +100,11 @@ void MapContext::setStyleJSON(const std::string& json, const std::string& base)
void MapContext::loadStyleJSON(const std::string& json, const std::string& base) {
assert(Environment::currentlyOn(ThreadType::Map));
- resourceLoader.reset();
style.reset();
-
- style = std::make_unique<Style>();
- style->base = base;
- style->loadJSON((const uint8_t *)json.c_str());
+ style = std::make_unique<Style>(json, base, asyncUpdate->get()->loop, env);
style->cascade(data.getClasses());
style->setDefaultTransitionDuration(data.getDefaultTransitionDuration());
-
- glyphStore->setURL(style->glyph_url);
-
- resourceLoader = std::make_unique<ResourceLoader>();
- resourceLoader->setObserver(this);
- resourceLoader->setStyle(style.get());
- resourceLoader->setGlyphStore(glyphStore.get());
+ style->setObserver(this);
triggerUpdate(Update::Zoom);
}
@@ -138,7 +112,7 @@ void MapContext::loadStyleJSON(const std::string& json, const std::string& base)
void MapContext::updateTiles() {
assert(Environment::currentlyOn(ThreadType::Map));
- resourceLoader->update(data, transformState, *glyphAtlas, *spriteAtlas, *texturePool);
+ style->update(data, transformState, *texturePool);
}
void MapContext::updateAnnotationTiles(const std::vector<TileID>& ids) {
@@ -177,7 +151,7 @@ void MapContext::update() {
updateTiles();
- if (style->isLoaded() && resourceLoader->getSprite()->isLoaded()) {
+ if (style->isLoaded()) {
if (!data.getFullyLoaded()) {
data.setFullyLoaded(true);
}
@@ -220,7 +194,7 @@ void MapContext::render() {
assert(style);
if (!painter) {
- painter = std::make_unique<Painter>(*spriteAtlas, *glyphAtlas, *lineAtlas);
+ painter = std::make_unique<Painter>();
painter->setup();
}
@@ -240,7 +214,7 @@ void MapContext::render() {
double MapContext::getTopOffsetPixelsForAnnotationSymbol(const std::string& symbol) {
assert(Environment::currentlyOn(ThreadType::Map));
- const SpritePosition pos = resourceLoader->getSprite()->getSpritePosition(symbol);
+ const SpritePosition pos = style->sprite->getSpritePosition(symbol);
return -pos.height / pos.pixelRatio / 2;
}
diff --git a/src/mbgl/map/map_context.hpp b/src/mbgl/map/map_context.hpp
index fb9fdb4d4b..8894434242 100644
--- a/src/mbgl/map/map_context.hpp
+++ b/src/mbgl/map/map_context.hpp
@@ -4,8 +4,8 @@
#include <mbgl/map/tile_id.hpp>
#include <mbgl/map/update.hpp>
#include <mbgl/map/environment.hpp>
-#include <mbgl/map/resource_loader.hpp>
#include <mbgl/map/transform_state.hpp>
+#include <mbgl/style/style.hpp>
#include <mbgl/util/ptr.hpp>
#include <vector>
@@ -20,20 +20,15 @@ namespace mbgl {
class View;
class MapData;
-class GlyphStore;
-class GlyphAtlas;
-class SpriteAtlas;
-class LineAtlas;
class TexturePool;
class Painter;
class Sprite;
-class Style;
class Worker;
class StillImage;
struct LatLng;
struct LatLngBounds;
-class MapContext : public ResourceLoader::Observer {
+class MapContext : public Style::Observer {
public:
MapContext(uv_loop_t*, View&, FileSource&, MapData&);
~MapContext();
@@ -59,7 +54,7 @@ public:
void setSourceTileCacheSize(size_t size);
void onLowMemory();
- // ResourceLoader::Observer implementation.
+ // Style::Observer implementation.
void onTileDataChanged() override;
void onResourceLoadingFailed(std::exception_ptr error) override;
@@ -81,14 +76,9 @@ private:
UpdateType updated { static_cast<UpdateType>(Update::Nothing) };
std::unique_ptr<uv::async> asyncUpdate;
- std::unique_ptr<GlyphStore> glyphStore;
- std::unique_ptr<GlyphAtlas> glyphAtlas;
- std::unique_ptr<SpriteAtlas> spriteAtlas;
- std::unique_ptr<LineAtlas> lineAtlas;
std::unique_ptr<TexturePool> texturePool;
std::unique_ptr<Painter> painter;
std::unique_ptr<Style> style;
- std::unique_ptr<ResourceLoader> resourceLoader;
std::string styleURL;
std::string styleJSON;
diff --git a/src/mbgl/map/resource_loader.cpp b/src/mbgl/map/resource_loader.cpp
deleted file mode 100644
index 8e054c0d82..0000000000
--- a/src/mbgl/map/resource_loader.cpp
+++ /dev/null
@@ -1,160 +0,0 @@
-#include <mbgl/map/resource_loader.hpp>
-
-#include <mbgl/geometry/sprite_atlas.hpp>
-#include <mbgl/map/environment.hpp>
-#include <mbgl/map/source.hpp>
-#include <mbgl/map/sprite.hpp>
-#include <mbgl/map/transform.hpp>
-#include <mbgl/style/style.hpp>
-
-#include <cassert>
-
-namespace mbgl {
-
-ResourceLoader::ResourceLoader() {
- assert(Environment::currentlyOn(ThreadType::Map));
-}
-
-ResourceLoader::~ResourceLoader() {
- assert(Environment::currentlyOn(ThreadType::Map));
-
- for (const auto& source : style_->sources) {
- source->setObserver(nullptr);
- }
-
- if (sprite_) {
- sprite_->setObserver(nullptr);
- }
-
- if (glyphStore_) {
- glyphStore_->setObserver(nullptr);
- }
-}
-
-void ResourceLoader::setObserver(Observer* observer) {
- assert(Environment::currentlyOn(ThreadType::Map));
- assert(!observer_);
-
- observer_ = observer;
-}
-
-void ResourceLoader::setStyle(Style* style) {
- assert(style);
-
- style_ = style;
-
- for (const auto& source : style->sources) {
- source->setObserver(this);
- source->load();
- }
-}
-
-void ResourceLoader::setGlyphStore(GlyphStore* glyphStore) {
- assert(glyphStore);
-
- if (glyphStore_) {
- glyphStore_->setObserver(nullptr);
- }
-
- glyphStore_ = glyphStore;
- glyphStore_->setObserver(this);
-}
-
-void ResourceLoader::update(MapData& data,
- const TransformState& transform,
- GlyphAtlas& glyphAtlas,
- SpriteAtlas& spriteAtlas,
- TexturePool& texturePool) {
- if (!style_) {
- return;
- }
-
- const float pixelRatio = transform.getPixelRatio();
- if (!sprite_ || !sprite_->hasPixelRatio(pixelRatio)) {
- sprite_ = std::make_unique<Sprite>(style_->getSpriteURL(), pixelRatio);
- sprite_->setObserver(this);
-
- spriteAtlas.resize(pixelRatio);
- spriteAtlas.setSprite(sprite_);
- }
-
- bool allTilesUpdated = true;
- for (const auto& source : style_->sources) {
- if (!source->update(data, transform, *style_, glyphAtlas, *glyphStore_,
- spriteAtlas, sprite_, texturePool, shouldReparsePartialTiles_)) {
- allTilesUpdated = false;
- }
- }
-
- // We can only stop updating "partial" tiles when all of them
- // were notified of the arrival of the new resources.
- if (allTilesUpdated) {
- shouldReparsePartialTiles_ = false;
- }
-}
-
-void ResourceLoader::onGlyphRangeLoaded() {
- shouldReparsePartialTiles_ = true;
-
- emitTileDataChanged();
-}
-
-void ResourceLoader::onGlyphRangeLoadingFailed(std::exception_ptr error) {
- emitResourceLoadingFailed(error);
-}
-
-void ResourceLoader::onSourceLoaded() {
- emitTileDataChanged();
-}
-
-void ResourceLoader::onSourceLoadingFailed(std::exception_ptr error) {
- emitResourceLoadingFailed(error);
-}
-
-void ResourceLoader::onTileLoaded(bool isNewTile) {
- if (isNewTile) {
- shouldReparsePartialTiles_ = true;
- }
-
- emitTileDataChanged();
-}
-
-void ResourceLoader::onTileLoadingFailed(std::exception_ptr error) {
- emitResourceLoadingFailed(error);
-}
-
-void ResourceLoader::onSpriteLoaded() {
- shouldReparsePartialTiles_ = true;
-
- emitTileDataChanged();
-}
-
-void ResourceLoader::onSpriteLoadingFailed(std::exception_ptr error) {
- emitResourceLoadingFailed(error);
-}
-
-void ResourceLoader::emitTileDataChanged() {
- assert(Environment::currentlyOn(ThreadType::Map));
-
- if (observer_) {
- observer_->onTileDataChanged();
- }
-}
-
-void ResourceLoader::emitResourceLoadingFailed(std::exception_ptr error) {
- assert(Environment::currentlyOn(ThreadType::Map));
-
- try {
- if (error) {
- std::rethrow_exception(error);
- }
- } catch(const std::exception& e) {
- Log::Error(Event::ResourceLoader, e.what());
- }
-
- if (observer_) {
- observer_->onResourceLoadingFailed(error);
- }
-}
-
-}
diff --git a/src/mbgl/map/resource_loader.hpp b/src/mbgl/map/resource_loader.hpp
deleted file mode 100644
index 525e4653a0..0000000000
--- a/src/mbgl/map/resource_loader.hpp
+++ /dev/null
@@ -1,91 +0,0 @@
-#ifndef MBGL_MAP_RESOURCE_LOADER
-#define MBGL_MAP_RESOURCE_LOADER
-
-#include <mbgl/map/source.hpp>
-#include <mbgl/map/sprite.hpp>
-#include <mbgl/text/glyph_store.hpp>
-#include <mbgl/util/noncopyable.hpp>
-
-#include <string>
-
-namespace mbgl {
-
-class GlyphAtlas;
-class GlyphStore;
-class MapData;
-class SpriteAtlas;
-class Style;
-class TexturePool;
-class TransformState;
-
-// ResourceLoader is responsible for loading and updating the Source(s) owned
-// by the Style. The Source object currently owns all the tiles, thus this
-// class will notify its observers of any change on these tiles which will
-// ultimately cause a new rendering to be triggered.
-class ResourceLoader : public GlyphStore::Observer,
- public Source::Observer,
- public Sprite::Observer,
- private util::noncopyable {
-public:
- class Observer {
- public:
- virtual ~Observer() = default;
-
- virtual void onTileDataChanged() = 0;
- virtual void onResourceLoadingFailed(std::exception_ptr error) = 0;
- };
-
- ResourceLoader();
- ~ResourceLoader();
-
- void setObserver(Observer* observer);
-
- // The style object currently owns all the sources. When setting
- // a new style we will go through all of them and try to load.
- void setStyle(Style* style);
-
- // TODO: Move GlyphStore to ResourceLoader. We cannot do it now
- // because we reset the ResourceLoader every time we change the
- // style.
- void setGlyphStore(GlyphStore* glyphStore);
-
- // Fetch the tiles needed by the current viewport and emit a signal when
- // a tile is ready so observers can render the tile.
- void update(MapData&, const TransformState&, GlyphAtlas&, SpriteAtlas&, TexturePool&);
-
- // FIXME: There is probably a better place for this.
- inline util::ptr<Sprite> getSprite() const {
- return sprite_;
- }
-
- // GlyphStore::Observer implementation.
- void onGlyphRangeLoaded() override;
- void onGlyphRangeLoadingFailed(std::exception_ptr error) override;
-
- // Source::Observer implementation.
- void onSourceLoaded() override;
- void onSourceLoadingFailed(std::exception_ptr error) override;
- void onTileLoaded(bool isNewTile) override;
- void onTileLoadingFailed(std::exception_ptr error) override;
-
- // Sprite::Observer implementation.
- void onSpriteLoaded() override;
- void onSpriteLoadingFailed(std::exception_ptr error) override;
-
-private:
- void emitTileDataChanged();
- void emitResourceLoadingFailed(std::exception_ptr error);
-
- bool shouldReparsePartialTiles_ = false;
-
- util::ptr<Sprite> sprite_;
-
- GlyphStore* glyphStore_ = nullptr;
- Style* style_ = nullptr;
-
- Observer* observer_ = nullptr;
-};
-
-}
-
-#endif