summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2015-04-22 15:30:39 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2015-04-28 14:32:23 -0400
commit7cd55a33331420b4f573770e39a625292e228d43 (patch)
treeeb541ed52d019791ee84a4e87396168d5a663bda
parent9e4a03fd9dc64f0ed474064484e813018c7b2d29 (diff)
downloadqtlocation-mapboxgl-7cd55a33331420b4f573770e39a625292e228d43.tar.gz
Enforce that transformState belongs to Map thread
-rw-r--r--src/mbgl/map/map.cpp4
-rw-r--r--src/mbgl/map/map_context.cpp12
-rw-r--r--src/mbgl/map/map_context.hpp2
-rw-r--r--src/mbgl/map/map_data.hpp11
-rw-r--r--src/mbgl/map/source.cpp16
-rw-r--r--src/mbgl/map/source.hpp2
6 files changed, 21 insertions, 26 deletions
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index a9a83bc736..0bf4f11a67 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -261,11 +261,11 @@ double Map::getMaxZoom() const {
#pragma mark - Size
uint16_t Map::getWidth() const {
- return data->getTransformState().getWidth();
+ return data->transform.currentState().getWidth();
}
uint16_t Map::getHeight() const {
- return data->getTransformState().getHeight();
+ return data->transform.currentState().getHeight();
}
diff --git a/src/mbgl/map/map_context.cpp b/src/mbgl/map/map_context.cpp
index e6f3b5984f..3ab3f284a9 100644
--- a/src/mbgl/map/map_context.cpp
+++ b/src/mbgl/map/map_context.cpp
@@ -98,7 +98,7 @@ Worker& MapContext::getWorker() {
util::ptr<Sprite> MapContext::getSprite() {
assert(Environment::currentlyOn(ThreadType::Map));
- const float pixelRatio = data.getTransformState().getPixelRatio();
+ const float pixelRatio = transformState.getPixelRatio();
const std::string &sprite_url = style->getSpriteURL();
if (!sprite || !sprite->hasPixelRatio(pixelRatio)) {
sprite = std::make_shared<Sprite>(sprite_url, pixelRatio, env, [this] {
@@ -160,7 +160,7 @@ void MapContext::updateTiles() {
assert(Environment::currentlyOn(ThreadType::Map));
if (!style) return;
for (const auto& source : style->sources) {
- source->update(data, getWorker(), style, *glyphAtlas, *glyphStore, *spriteAtlas,
+ source->update(data, transformState, getWorker(), style, *glyphAtlas, *glyphStore, *spriteAtlas,
getSprite(), *texturePool, [this]() {
assert(Environment::currentlyOn(ThreadType::Map));
triggerUpdate();
@@ -192,7 +192,7 @@ void MapContext::update() {
u |= static_cast<UpdateType>(Update::StyleInfo);
}
- data.setTransformState(data.transform.currentState());
+ transformState = data.transform.currentState();
if (u & static_cast<UpdateType>(Update::StyleInfo)) {
reloadStyle();
@@ -215,11 +215,11 @@ void MapContext::update() {
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);
+ style->recalculate(transformState.getNormalizedZoom(), now);
}
// Allow the sprite atlas to potentially pull new sprite images if needed.
- spriteAtlas->resize(data.getTransformState().getPixelRatio());
+ spriteAtlas->resize(transformState.getPixelRatio());
spriteAtlas->setSprite(getSprite());
updateTiles();
@@ -237,7 +237,7 @@ void MapContext::render() {
assert(style);
assert(painter);
- painter->render(*style, data.getTransformState(), data.getAnimationTime());
+ painter->render(*style, transformState, data.getAnimationTime());
if (data.mode == MapMode::Still && data.callback && style->isLoaded() && getSprite()->isLoaded()) {
auto image = view.readStillImage();
diff --git a/src/mbgl/map/map_context.hpp b/src/mbgl/map/map_context.hpp
index 4808010637..bdebdb1b66 100644
--- a/src/mbgl/map/map_context.hpp
+++ b/src/mbgl/map/map_context.hpp
@@ -4,6 +4,7 @@
#include <mbgl/map/tile_id.hpp>
#include <mbgl/map/update.hpp>
#include <mbgl/map/environment.hpp>
+#include <mbgl/map/transform_state.hpp>
#include <mbgl/util/ptr.hpp>
#include <vector>
@@ -86,6 +87,7 @@ private:
util::ptr<Style> style;
size_t sourceCacheSize;
+ TransformState transformState;
};
}
diff --git a/src/mbgl/map/map_data.hpp b/src/mbgl/map/map_data.hpp
index 4eaefa563d..089eb3b9f2 100644
--- a/src/mbgl/map/map_data.hpp
+++ b/src/mbgl/map/map_data.hpp
@@ -97,16 +97,6 @@ public:
defaultTransitionDuration = duration;
};
- // Make sure the state is only accessible/modifiable from the Map thread.
- inline const TransformState& getTransformState() const {
- assert(Environment::currentlyOn(ThreadType::Map));
- return transformState;
- }
- inline void setTransformState(const TransformState& state) {
- assert(Environment::currentlyOn(ThreadType::Map));
- transformState = state;
- }
-
public:
Transform transform;
AnnotationManager annotationManager;
@@ -118,7 +108,6 @@ private:
StyleInfo styleInfo;
std::string accessToken;
std::vector<std::string> classes;
- TransformState transformState;
std::atomic<uint8_t> debug { false };
std::atomic<Duration> animationTime;
std::atomic<Duration> defaultTransitionDuration;
diff --git a/src/mbgl/map/source.cpp b/src/mbgl/map/source.cpp
index 52152764c9..93761255bf 100644
--- a/src/mbgl/map/source.cpp
+++ b/src/mbgl/map/source.cpp
@@ -225,6 +225,7 @@ TileData::State Source::hasTile(const TileID& id) {
}
TileData::State Source::addTile(MapData& data,
+ const TransformState& transformState,
Worker& worker,
util::ptr<Style> style,
GlyphAtlas& glyphAtlas,
@@ -268,10 +269,10 @@ TileData::State Source::addTile(MapData& data,
new_tile.data =
std::make_shared<VectorTileData>(normalized_id, data.transform.getMaxZoom(), style, glyphAtlas,
glyphStore, spriteAtlas, sprite, info);
- new_tile.data->request(worker, data.getTransformState().getPixelRatio(), callback);
+ new_tile.data->request(worker, transformState.getPixelRatio(), callback);
} else if (info.type == SourceType::Raster) {
new_tile.data = std::make_shared<RasterTileData>(normalized_id, texturePool, info);
- new_tile.data->request(worker, data.getTransformState().getPixelRatio(), callback);
+ new_tile.data->request(worker, transformState.getPixelRatio(), callback);
} else if (info.type == SourceType::Annotations) {
new_tile.data = std::make_shared<LiveTileData>(normalized_id, data.annotationManager,
data.transform.getMaxZoom(), style, glyphAtlas,
@@ -366,6 +367,7 @@ bool Source::findLoadedParent(const TileID& id, int32_t minCoveringZoom, std::fo
}
void Source::update(MapData& data,
+ const TransformState& transformState,
Worker& worker,
util::ptr<Style> style,
GlyphAtlas& glyphAtlas,
@@ -378,8 +380,8 @@ void Source::update(MapData& data,
return;
}
- int32_t zoom = std::floor(getZoom(data.getTransformState()));
- std::forward_list<TileID> required = coveringTiles(data.getTransformState());
+ int32_t zoom = std::floor(getZoom(transformState));
+ std::forward_list<TileID> required = coveringTiles(transformState);
// Determine the overzooming/underzooming amounts.
int32_t minCoveringZoom = util::clamp<int32_t>(zoom - 10, info.min_zoom, info.max_zoom);
@@ -392,7 +394,7 @@ void Source::update(MapData& data,
// Add existing child/parent tiles if the actual tile is not yet loaded
for (const auto& id : required) {
- const TileData::State state = addTile(data, worker, style, glyphAtlas, glyphStore,
+ const TileData::State state = addTile(data, transformState, worker, style, glyphAtlas, glyphStore,
spriteAtlas, sprite, texturePool, id, callback);
if (state != TileData::State::parsed) {
@@ -412,8 +414,8 @@ void Source::update(MapData& data,
}
if (info.type != SourceType::Raster && cache.getSize() == 0) {
- size_t conservativeCacheSize = ((float)data.getTransformState().getWidth() / util::tileSize) *
- ((float)data.getTransformState().getHeight() / util::tileSize) *
+ size_t conservativeCacheSize = ((float)transformState.getWidth() / util::tileSize) *
+ ((float)transformState.getHeight() / util::tileSize) *
(data.transform.getMaxZoom() - data.transform.getMinZoom() + 1) *
0.5;
cache.setSize(conservativeCacheSize);
diff --git a/src/mbgl/map/source.hpp b/src/mbgl/map/source.hpp
index 342d414e2e..6383e101fd 100644
--- a/src/mbgl/map/source.hpp
+++ b/src/mbgl/map/source.hpp
@@ -64,6 +64,7 @@ public:
void load(MapData&, Environment&, std::function<void()> callback);
void update(MapData&,
+ const TransformState&,
Worker&,
util::ptr<Style>,
GlyphAtlas&,
@@ -95,6 +96,7 @@ private:
std::forward_list<TileID> coveringTiles(const TransformState&) const;
TileData::State addTile(MapData&,
+ const TransformState&,
Worker&,
util::ptr<Style>,
GlyphAtlas&,