move Style to MapContext

This commit is contained in:
Konstantin Käfer
2015-03-24 11:07:03 +01:00
committed by John Firebaugh
parent f272d13dea
commit 9580ec7b08
3 changed files with 30 additions and 33 deletions

View File

@@ -25,7 +25,6 @@ namespace uv { class async; }
namespace mbgl {
class Sprite;
class Style;
class FileSource;
class View;
class Environment;
@@ -236,8 +235,6 @@ private:
// Stores whether the map thread has been stopped already.
std::atomic_bool isStopped;
util::ptr<Style> style;
std::atomic<UpdateType> updated;
std::mutex mutexTask;

View File

@@ -85,7 +85,7 @@ Map::~Map() {
"MapandMain");
// Explicitly reset all pointers.
style.reset();
context->style.reset();
context.reset();
uv_run(env->loop, UV_RUN_DEFAULT);
@@ -109,7 +109,7 @@ void Map::start(bool startPaused, Mode renderMode) {
assert(Environment::currentlyOn(ThreadType::Map));
// Remove all of these to make sure they are destructed in the correct thread.
style.reset();
context->style.reset();
// It's now safe to destroy/join the workers since there won't be any more callbacks that
// could dispatch to the worker pool.
@@ -433,7 +433,7 @@ std::string Map::getStyleJSON() const {
util::ptr<Sprite> Map::getSprite() {
assert(Environment::currentlyOn(ThreadType::Map));
const float pixelRatio = data->getTransformState().getPixelRatio();
const std::string &sprite_url = style->getSpriteURL();
const std::string &sprite_url = context->style->getSpriteURL();
if (!context->sprite || !context->sprite->hasPixelRatio(pixelRatio)) {
context->sprite = Sprite::Create(sprite_url, pixelRatio, *env);
}
@@ -672,8 +672,8 @@ LatLngBounds Map::getBoundsForAnnotations(const std::vector<uint32_t>& annotatio
void Map::updateAnnotationTiles(const std::vector<TileID>& ids) {
assert(Environment::currentlyOn(ThreadType::Main));
if (!style) return;
for (const auto &source : style->sources) {
if (!context->style) return;
for (const auto &source : context->style->sources) {
if (source->info.type == SourceType::Annotations) {
source->invalidateTiles(ids);
}
@@ -736,9 +736,9 @@ Duration Map::getDefaultTransitionDuration() {
void Map::updateTiles() {
assert(Environment::currentlyOn(ThreadType::Map));
if (!style) return;
for (const auto& source : style->sources) {
source->update(*data, context->getWorker(), style, *context->glyphAtlas, *context->glyphStore,
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]() {
assert(Environment::currentlyOn(ThreadType::Map));
triggerUpdate();
@@ -757,7 +757,7 @@ void Map::update() {
void Map::reloadStyle() {
assert(Environment::currentlyOn(ThreadType::Map));
style = std::make_shared<Style>();
context->style = std::make_shared<Style>();
const auto styleInfo = data->getStyleInfo();
@@ -781,16 +781,16 @@ void Map::loadStyleJSON(const std::string& json, const std::string& base) {
assert(Environment::currentlyOn(ThreadType::Map));
context->sprite.reset();
style = std::make_shared<Style>();
style->base = base;
style->loadJSON((const uint8_t *)json.c_str());
style->cascade(data->getClasses());
style->setDefaultTransitionDuration(data->getDefaultTransitionDuration());
context->style = std::make_shared<Style>();
context->style->base = base;
context->style->loadJSON((const uint8_t *)json.c_str());
context->style->cascade(data->getClasses());
context->style->setDefaultTransitionDuration(data->getDefaultTransitionDuration());
const std::string glyphURL = util::mapbox::normalizeGlyphsURL(style->glyph_url, getAccessToken());
const std::string glyphURL = util::mapbox::normalizeGlyphsURL(context->style->glyph_url, getAccessToken());
context->glyphStore->setURL(glyphURL);
for (const auto& source : style->sources) {
for (const auto& source : context->style->sources) {
source->load(getAccessToken(), *env, [this]() {
assert(Environment::currentlyOn(ThreadType::Map));
triggerUpdate();
@@ -809,7 +809,7 @@ void Map::prepare() {
auto u = updated.exchange(static_cast<UpdateType>(Update::Nothing)) |
data->transform.updateTransitions(now);
if (!style) {
if (!context->style) {
u |= static_cast<UpdateType>(Update::StyleInfo);
}
@@ -837,19 +837,19 @@ void Map::prepare() {
asyncRender->unref();
}
if (style) {
if (context->style) {
if (u & static_cast<UpdateType>(Update::DefaultTransitionDuration)) {
style->setDefaultTransitionDuration(data->getDefaultTransitionDuration());
context->style->setDefaultTransitionDuration(data->getDefaultTransitionDuration());
}
if (u & static_cast<UpdateType>(Update::Classes)) {
style->cascade(data->getClasses());
context->style->cascade(data->getClasses());
}
if (u & static_cast<UpdateType>(Update::StyleInfo) ||
u & static_cast<UpdateType>(Update::Classes) ||
u & static_cast<UpdateType>(Update::Zoom)) {
style->recalculate(data->getTransformState().getNormalizedZoom(), now);
context->style->recalculate(data->getTransformState().getNormalizedZoom(), now);
}
// Allow the sprite atlas to potentially pull new sprite images if needed.
@@ -872,13 +872,13 @@ void Map::render() {
// Cleanup OpenGL objects that we abandoned since the last render call.
env->performCleanup();
assert(style);
assert(context->style);
assert(context->painter);
context->painter->render(*style, data->getTransformState(), data->getAnimationTime());
context->painter->render(*context->style, data->getTransformState(), data->getAnimationTime());
// Schedule another rerender when we definitely need a next frame.
if (data->transform.needsTransition() || style->hasTransitions()) {
if (data->transform.needsTransition() || context->style->hasTransitions()) {
triggerUpdate();
}
}
@@ -887,8 +887,8 @@ void Map::setSourceTileCacheSize(size_t size) {
if (size != getSourceTileCacheSize()) {
invokeTask([=] {
sourceCacheSize = size;
if (!style) return;
for (const auto &source : style->sources) {
if (!context->style) return;
for (const auto &source : context->style->sources) {
source->setCacheSize(sourceCacheSize);
}
env->performCleanup();
@@ -898,8 +898,8 @@ void Map::setSourceTileCacheSize(size_t size) {
void Map::onLowMemory() {
invokeTask([=] {
if (!style) return;
for (const auto &source : style->sources) {
if (!context->style) return;
for (const auto &source : context->style->sources) {
source->onLowMemory();
}
env->performCleanup();

View File

@@ -15,8 +15,7 @@ class LineAtlas;
class TexturePool;
class Painter;
class Sprite;
class StyleSource;
class StyleLayerGroup;
class Style;
class Worker;
class MapContext {
@@ -34,6 +33,7 @@ public:
const std::unique_ptr<TexturePool> texturePool;
const std::unique_ptr<Painter> painter;
util::ptr<Sprite> sprite;
util::ptr<Style> style;
};
}