Enforce that transformState belongs to Map thread
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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&,
|
||||
|
||||
Reference in New Issue
Block a user