Introduce the ResourceLoader

ResourceLoader will handle all the tile changes and notifications
through the Source object owned by the Style. This object lives
entirely on the Map thread and should be only accessed by it.

The observer will receive notifications every time the tile data changes
and this will probably trigger a new rendering operation.

This first patch will delegate Source loading to the ResourceLoader.
This commit is contained in:
Thiago Marcos P. Santos
2015-04-21 12:05:37 +02:00
parent fab65e75d0
commit 4956da61b9
4 changed files with 112 additions and 7 deletions

View File

@@ -0,0 +1,48 @@
#include <mbgl/map/resource_loader.hpp>
#include <mbgl/map/environment.hpp>
#include <mbgl/map/source.hpp>
#include <mbgl/style/style.hpp>
#include <cassert>
#include <functional>
namespace mbgl {
ResourceLoader::ResourceLoader() {
assert(Environment::currentlyOn(ThreadType::Map));
}
ResourceLoader::~ResourceLoader() {
assert(Environment::currentlyOn(ThreadType::Map));
}
void ResourceLoader::setObserver(Observer* observer) {
assert(Environment::currentlyOn(ThreadType::Map));
assert(!observer_);
observer_ = observer;
}
void ResourceLoader::setStyle(Style* style) {
style_ = style;
Environment& env = Environment::Get();
for (const auto& source : style->sources) {
source->load(accessToken_, env, std::bind(&ResourceLoader::emitTileDataChanged, this));
}
}
void ResourceLoader::setAccessToken(const std::string& accessToken) {
accessToken_ = accessToken;
}
void ResourceLoader::emitTileDataChanged() {
assert(Environment::currentlyOn(ThreadType::Map));
if (observer_) {
observer_->onTileDataChanged();
}
}
}