summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2015-03-24 11:07:03 +0100
committerJohn Firebaugh <john.firebaugh@gmail.com>2015-04-28 14:32:20 -0400
commit9580ec7b08470de0578f8d21f74ac039c83acdfc (patch)
tree573e287e4de5dc14bb8e502f38f938f2271495a5
parentf272d13dead2b2cccc58d9c55697b9cac3c71e68 (diff)
downloadqtlocation-mapboxgl-9580ec7b08470de0578f8d21f74ac039c83acdfc.tar.gz
move Style to MapContext
-rw-r--r--include/mbgl/map/map.hpp3
-rw-r--r--src/mbgl/map/map.cpp56
-rw-r--r--src/mbgl/map/map_context.hpp4
3 files changed, 30 insertions, 33 deletions
diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp
index 1ec12eb255..0db726b51b 100644
--- a/include/mbgl/map/map.hpp
+++ b/include/mbgl/map/map.hpp
@@ -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;
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index da16f2d8da..a8a5d15ff1 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -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();
diff --git a/src/mbgl/map/map_context.hpp b/src/mbgl/map/map_context.hpp
index cbe5994aed..c927a931c2 100644
--- a/src/mbgl/map/map_context.hpp
+++ b/src/mbgl/map/map_context.hpp
@@ -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;
};
}