move TransformState to MapData object
This commit is contained in:
committed by
John Firebaugh
parent
c58c734ea0
commit
cc8f440c84
@@ -144,8 +144,8 @@ public:
|
||||
inline double getMetersPerPixelAtLatitude(const double lat, const double zoom) const { return Projection::getMetersPerPixelAtLatitude(lat, zoom); }
|
||||
inline const ProjectedMeters projectedMetersForLatLng(const LatLng latLng) const { return Projection::projectedMetersForLatLng(latLng); }
|
||||
inline const LatLng latLngForProjectedMeters(const ProjectedMeters projectedMeters) const { return Projection::latLngForProjectedMeters(projectedMeters); }
|
||||
inline const vec2<double> pixelForLatLng(const LatLng latLng) const { return state.pixelForLatLng(latLng); }
|
||||
inline const LatLng latLngForPixel(const vec2<double> pixel) const { return state.latLngForPixel(pixel); }
|
||||
inline const vec2<double> pixelForLatLng(const LatLng latLng) const { return transform.currentState().pixelForLatLng(latLng); }
|
||||
inline const LatLng latLngForPixel(const vec2<double> pixel) const { return transform.currentState().latLngForPixel(pixel); }
|
||||
|
||||
// Annotations
|
||||
void setDefaultPointAnnotationSymbol(const std::string&);
|
||||
@@ -168,8 +168,6 @@ public:
|
||||
void toggleDebug();
|
||||
bool getDebug() const;
|
||||
|
||||
inline const TransformState &getState() const { return state; }
|
||||
TimePoint getTime() const;
|
||||
inline AnnotationManager& getAnnotationManager() const { return *annotationManager; }
|
||||
|
||||
private:
|
||||
@@ -245,7 +243,6 @@ private:
|
||||
std::atomic_bool isStopped;
|
||||
|
||||
Transform transform;
|
||||
TransformState state;
|
||||
|
||||
FileSource& fileSource;
|
||||
|
||||
|
||||
@@ -450,7 +450,8 @@ std::string Map::getStyleJSON() const {
|
||||
}
|
||||
|
||||
util::ptr<Sprite> Map::getSprite() {
|
||||
const float pixelRatio = state.getPixelRatio();
|
||||
assert(Environment::currentlyOn(ThreadType::Map));
|
||||
const float pixelRatio = data->getTransformState().getPixelRatio();
|
||||
const std::string &sprite_url = style->getSpriteURL();
|
||||
if (!sprite || !sprite->hasPixelRatio(pixelRatio)) {
|
||||
sprite = Sprite::Create(sprite_url, pixelRatio, *env);
|
||||
@@ -672,10 +673,6 @@ bool Map::getDebug() const {
|
||||
return data->getDebug();
|
||||
}
|
||||
|
||||
TimePoint Map::getTime() const {
|
||||
return data->getAnimationTime();
|
||||
}
|
||||
|
||||
void Map::addClass(const std::string& klass) {
|
||||
if (data->addClass(klass)) {
|
||||
triggerUpdate(Update::Classes);
|
||||
@@ -717,7 +714,7 @@ void Map::updateTiles() {
|
||||
assert(Environment::currentlyOn(ThreadType::Map));
|
||||
if (!style) return;
|
||||
for (const auto& source : style->sources) {
|
||||
source->update(*this, getWorker(), style, *glyphAtlas, *glyphStore,
|
||||
source->update(*this, *data, getWorker(), style, *glyphAtlas, *glyphStore,
|
||||
*spriteAtlas, getSprite(), *texturePool, [this]() {
|
||||
assert(Environment::currentlyOn(ThreadType::Map));
|
||||
triggerUpdate();
|
||||
@@ -728,7 +725,7 @@ void Map::updateTiles() {
|
||||
void Map::update() {
|
||||
assert(Environment::currentlyOn(ThreadType::Map));
|
||||
|
||||
if (state.hasSize()) {
|
||||
if (data->getTransformState().hasSize()) {
|
||||
prepare();
|
||||
}
|
||||
}
|
||||
@@ -792,7 +789,7 @@ void Map::prepare() {
|
||||
u |= static_cast<UpdateType>(Update::StyleInfo);
|
||||
}
|
||||
|
||||
state = transform.currentState();
|
||||
data->setTransformState(transform.currentState());
|
||||
|
||||
if (u & static_cast<UpdateType>(Update::StyleInfo)) {
|
||||
reloadStyle();
|
||||
@@ -828,11 +825,11 @@ void Map::prepare() {
|
||||
if (u & static_cast<UpdateType>(Update::StyleInfo) ||
|
||||
u & static_cast<UpdateType>(Update::Classes) ||
|
||||
u & static_cast<UpdateType>(Update::Zoom)) {
|
||||
style->recalculate(state.getNormalizedZoom(), now);
|
||||
style->recalculate(data->getTransformState().getNormalizedZoom(), now);
|
||||
}
|
||||
|
||||
// Allow the sprite atlas to potentially pull new sprite images if needed.
|
||||
spriteAtlas->resize(state.getPixelRatio());
|
||||
spriteAtlas->resize(data->getTransformState().getPixelRatio());
|
||||
spriteAtlas->setSprite(getSprite());
|
||||
|
||||
updateTiles();
|
||||
@@ -854,7 +851,7 @@ void Map::render() {
|
||||
assert(style);
|
||||
assert(painter);
|
||||
|
||||
painter->render(*style, state, data->getAnimationTime());
|
||||
painter->render(*style, data->getTransformState(), data->getAnimationTime());
|
||||
|
||||
// Schedule another rerender when we definitely need a next frame.
|
||||
if (transform.needsTransition() || style->hasTransitions()) {
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
#include <mutex>
|
||||
#include <atomic>
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
|
||||
#include <mbgl/map/environment.hpp>
|
||||
#include <mbgl/map/transform_state.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
@@ -87,12 +91,23 @@ 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;
|
||||
}
|
||||
|
||||
private:
|
||||
mutable std::mutex mtx;
|
||||
|
||||
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;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <mbgl/map/source.hpp>
|
||||
#include <mbgl/map/map.hpp>
|
||||
#include <mbgl/map/map_data.hpp>
|
||||
#include <mbgl/map/environment.hpp>
|
||||
#include <mbgl/map/transform.hpp>
|
||||
#include <mbgl/map/tile.hpp>
|
||||
@@ -215,11 +216,17 @@ TileData::State Source::hasTile(const TileID& id) {
|
||||
return TileData::State::invalid;
|
||||
}
|
||||
|
||||
TileData::State Source::addTile(Map &map, Worker &worker,
|
||||
util::ptr<Style> style, GlyphAtlas &glyphAtlas,
|
||||
GlyphStore &glyphStore, SpriteAtlas &spriteAtlas,
|
||||
util::ptr<Sprite> sprite, TexturePool &texturePool,
|
||||
const TileID &id, std::function<void()> callback) {
|
||||
TileData::State Source::addTile(Map& map,
|
||||
MapData& data,
|
||||
Worker& worker,
|
||||
util::ptr<Style> style,
|
||||
GlyphAtlas& glyphAtlas,
|
||||
GlyphStore& glyphStore,
|
||||
SpriteAtlas& spriteAtlas,
|
||||
util::ptr<Sprite> sprite,
|
||||
TexturePool& texturePool,
|
||||
const TileID& id,
|
||||
std::function<void()> callback) {
|
||||
const TileData::State state = hasTile(id);
|
||||
|
||||
if (state != TileData::State::invalid) {
|
||||
@@ -254,10 +261,10 @@ TileData::State Source::addTile(Map &map, Worker &worker,
|
||||
new_tile.data =
|
||||
std::make_shared<VectorTileData>(normalized_id, map.getMaxZoom(), style, glyphAtlas,
|
||||
glyphStore, spriteAtlas, sprite, info);
|
||||
new_tile.data->request(worker, map.getState().getPixelRatio(), callback);
|
||||
new_tile.data->request(worker, data.getTransformState().getPixelRatio(), callback);
|
||||
} else if (info.type == SourceType::Raster) {
|
||||
new_tile.data = std::make_shared<RasterTileData>(normalized_id, texturePool, info);
|
||||
new_tile.data->request(worker, map.getState().getPixelRatio(), callback);
|
||||
new_tile.data->request(worker, data.getTransformState().getPixelRatio(), callback);
|
||||
} else if (info.type == SourceType::Annotations) {
|
||||
AnnotationManager& annotationManager = map.getAnnotationManager();
|
||||
new_tile.data = std::make_shared<LiveTileData>(normalized_id, annotationManager,
|
||||
@@ -353,20 +360,21 @@ bool Source::findLoadedParent(const TileID& id, int32_t minCoveringZoom, std::fo
|
||||
}
|
||||
|
||||
void Source::update(Map &map,
|
||||
Worker &worker,
|
||||
MapData& data,
|
||||
Worker& worker,
|
||||
util::ptr<Style> style,
|
||||
GlyphAtlas &glyphAtlas,
|
||||
GlyphStore &glyphStore,
|
||||
SpriteAtlas &spriteAtlas,
|
||||
GlyphAtlas& glyphAtlas,
|
||||
GlyphStore& glyphStore,
|
||||
SpriteAtlas& spriteAtlas,
|
||||
util::ptr<Sprite> sprite,
|
||||
TexturePool &texturePool,
|
||||
TexturePool& texturePool,
|
||||
std::function<void()> callback) {
|
||||
if (!loaded || map.getTime() <= updated) {
|
||||
if (!loaded || data.getAnimationTime() <= updated) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t zoom = std::floor(getZoom(map.getState()));
|
||||
std::forward_list<TileID> required = coveringTiles(map.getState());
|
||||
int32_t zoom = std::floor(getZoom(data.getTransformState()));
|
||||
std::forward_list<TileID> required = coveringTiles(data.getTransformState());
|
||||
|
||||
// Determine the overzooming/underzooming amounts.
|
||||
int32_t minCoveringZoom = util::clamp<int32_t>(zoom - 10, info.min_zoom, info.max_zoom);
|
||||
@@ -379,7 +387,7 @@ void Source::update(Map &map,
|
||||
|
||||
// Add existing child/parent tiles if the actual tile is not yet loaded
|
||||
for (const auto& id : required) {
|
||||
const TileData::State state = addTile(map, worker, style, glyphAtlas, glyphStore,
|
||||
const TileData::State state = addTile(map, data, worker, style, glyphAtlas, glyphStore,
|
||||
spriteAtlas, sprite, texturePool, id, callback);
|
||||
|
||||
if (state != TileData::State::parsed) {
|
||||
@@ -441,7 +449,7 @@ void Source::update(Map &map,
|
||||
}
|
||||
});
|
||||
|
||||
updated = map.getTime();
|
||||
updated = data.getAnimationTime();
|
||||
}
|
||||
|
||||
void Source::invalidateTiles(const std::vector<TileID>& ids) {
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
namespace mbgl {
|
||||
|
||||
class Map;
|
||||
class MapData;
|
||||
class Environment;
|
||||
class Worker;
|
||||
class GlyphAtlas;
|
||||
@@ -61,8 +62,16 @@ public:
|
||||
Environment&,
|
||||
std::function<void()> callback);
|
||||
|
||||
void update(Map &, Worker &, util::ptr<Style>, GlyphAtlas &, GlyphStore &,
|
||||
SpriteAtlas &, util::ptr<Sprite>, TexturePool &, std::function<void()> callback);
|
||||
void update(Map&,
|
||||
MapData&,
|
||||
Worker&,
|
||||
util::ptr<Style>,
|
||||
GlyphAtlas&,
|
||||
GlyphStore&,
|
||||
SpriteAtlas&,
|
||||
util::ptr<Sprite>,
|
||||
TexturePool&,
|
||||
std::function<void()> callback);
|
||||
|
||||
void invalidateTiles(const std::vector<TileID>&);
|
||||
|
||||
@@ -85,9 +94,17 @@ private:
|
||||
int32_t coveringZoomLevel(const TransformState&) const;
|
||||
std::forward_list<TileID> coveringTiles(const TransformState&) const;
|
||||
|
||||
TileData::State addTile(Map &, Worker &, util::ptr<Style>, GlyphAtlas &,
|
||||
GlyphStore &, SpriteAtlas &, util::ptr<Sprite>, TexturePool &,
|
||||
const TileID &, std::function<void()> callback);
|
||||
TileData::State addTile(Map&,
|
||||
MapData&,
|
||||
Worker&,
|
||||
util::ptr<Style>,
|
||||
GlyphAtlas&,
|
||||
GlyphStore&,
|
||||
SpriteAtlas&,
|
||||
util::ptr<Sprite>,
|
||||
TexturePool&,
|
||||
const TileID&,
|
||||
std::function<void()> callback);
|
||||
|
||||
TileData::State hasTile(const TileID& id);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user