[core] Introduce StyleUpdateParameters
This commit is contained in:
committed by
John Firebaugh
parent
f27c28b6c4
commit
40ebf5d0d0
@@ -42,6 +42,7 @@ class MapData;
|
||||
|
||||
class AnnotationTileMonitor : public GeometryTileMonitor {
|
||||
public:
|
||||
// TODO: should just take AnnotationManager&, but we need to eliminate util::exclusive<AnnotationManager> from MapData first.
|
||||
AnnotationTileMonitor(const TileID&, MapData&);
|
||||
~AnnotationTileMonitor();
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <mbgl/util/mapbox.hpp>
|
||||
#include <mbgl/storage/file_source.hpp>
|
||||
#include <mbgl/style/style_layer.hpp>
|
||||
#include <mbgl/style/style_update_parameters.hpp>
|
||||
#include <mbgl/platform/log.hpp>
|
||||
#include <mbgl/util/std.hpp>
|
||||
#include <mbgl/util/token.hpp>
|
||||
@@ -246,11 +247,7 @@ bool Source::handlePartialTile(const TileID& id, Worker&) {
|
||||
});
|
||||
}
|
||||
|
||||
TileData::State Source::addTile(MapData& data,
|
||||
const TransformState& transformState,
|
||||
Style& style,
|
||||
TexturePool& texturePool,
|
||||
const TileID& id) {
|
||||
TileData::State Source::addTile(const TileID& id, const StyleUpdateParameters& parameters) {
|
||||
const TileData::State state = hasTile(id);
|
||||
|
||||
if (state != TileData::State::invalid) {
|
||||
@@ -281,24 +278,24 @@ TileData::State Source::addTile(MapData& data,
|
||||
}
|
||||
|
||||
if (!new_tile.data) {
|
||||
auto callback = std::bind(&Source::tileLoadingCompleteCallback, this, normalized_id, transformState, data.getDebug() & MapDebugOptions::Collision);
|
||||
auto callback = std::bind(&Source::tileLoadingCompleteCallback, this, normalized_id, parameters.transformState, parameters.debugOptions & MapDebugOptions::Collision);
|
||||
|
||||
// If we don't find working tile data, we're just going to load it.
|
||||
if (info.type == SourceType::Raster) {
|
||||
auto tileData = std::make_shared<RasterTileData>(normalized_id,
|
||||
texturePool,
|
||||
parameters.texturePool,
|
||||
info,
|
||||
style.workers);
|
||||
parameters.worker);
|
||||
|
||||
tileData->request(data.pixelRatio, callback);
|
||||
tileData->request(parameters.pixelRatio, callback);
|
||||
new_tile.data = tileData;
|
||||
} else {
|
||||
std::unique_ptr<GeometryTileMonitor> monitor;
|
||||
|
||||
if (info.type == SourceType::Vector) {
|
||||
monitor = std::make_unique<VectorTileMonitor>(info, normalized_id, data.pixelRatio);
|
||||
monitor = std::make_unique<VectorTileMonitor>(info, normalized_id, parameters.pixelRatio);
|
||||
} else if (info.type == SourceType::Annotations) {
|
||||
monitor = std::make_unique<AnnotationTileMonitor>(normalized_id, data);
|
||||
monitor = std::make_unique<AnnotationTileMonitor>(normalized_id, parameters.data);
|
||||
} else {
|
||||
throw std::runtime_error("source type not implemented");
|
||||
}
|
||||
@@ -306,7 +303,7 @@ TileData::State Source::addTile(MapData& data,
|
||||
new_tile.data = std::make_shared<VectorTileData>(normalized_id,
|
||||
std::move(monitor),
|
||||
info.source_id,
|
||||
style,
|
||||
parameters.style,
|
||||
callback);
|
||||
}
|
||||
|
||||
@@ -408,24 +405,20 @@ void Source::findLoadedParent(const TileID& id, int32_t minCoveringZoom, std::fo
|
||||
}
|
||||
}
|
||||
|
||||
bool Source::update(MapData& data,
|
||||
const TransformState& transformState,
|
||||
Style& style,
|
||||
TexturePool& texturePool,
|
||||
bool shouldReparsePartialTiles) {
|
||||
bool Source::update(const StyleUpdateParameters& parameters) {
|
||||
bool allTilesUpdated = true;
|
||||
|
||||
if (!loaded || data.getAnimationTime() <= updated) {
|
||||
if (!loaded || parameters.animationTime <= updated) {
|
||||
return allTilesUpdated;
|
||||
}
|
||||
|
||||
double zoom = getZoom(transformState);
|
||||
double zoom = getZoom(parameters.transformState);
|
||||
if (info.type == SourceType::Raster || info.type == SourceType::Video) {
|
||||
zoom = ::round(zoom);
|
||||
} else {
|
||||
zoom = std::floor(zoom);
|
||||
}
|
||||
std::forward_list<TileID> required = coveringTiles(transformState);
|
||||
std::forward_list<TileID> required = coveringTiles(parameters.transformState);
|
||||
|
||||
// Determine the overzooming/underzooming amounts.
|
||||
int32_t minCoveringZoom = util::clamp<int32_t>(zoom - 10, info.min_zoom, info.max_zoom);
|
||||
@@ -442,14 +435,14 @@ bool Source::update(MapData& data,
|
||||
|
||||
switch (state) {
|
||||
case TileData::State::partial:
|
||||
if (shouldReparsePartialTiles) {
|
||||
if (!handlePartialTile(id, style.workers)) {
|
||||
if (parameters.shouldReparsePartialTiles) {
|
||||
if (!handlePartialTile(id, parameters.worker)) {
|
||||
allTilesUpdated = false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TileData::State::invalid:
|
||||
state = addTile(data, transformState, style, texturePool, id);
|
||||
state = addTile(id, parameters);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -472,9 +465,9 @@ bool Source::update(MapData& data,
|
||||
}
|
||||
|
||||
if (info.type != SourceType::Raster && cache.getSize() == 0) {
|
||||
size_t conservativeCacheSize = ((float)transformState.getWidth() / util::tileSize) *
|
||||
((float)transformState.getHeight() / util::tileSize) *
|
||||
(transformState.getMaxZoom() - transformState.getMinZoom() + 1) *
|
||||
size_t conservativeCacheSize = ((float)parameters.transformState.getWidth() / util::tileSize) *
|
||||
((float)parameters.transformState.getHeight() / util::tileSize) *
|
||||
(parameters.transformState.getMaxZoom() - parameters.transformState.getMinZoom() + 1) *
|
||||
0.5;
|
||||
cache.setSize(conservativeCacheSize);
|
||||
}
|
||||
@@ -521,10 +514,10 @@ bool Source::update(MapData& data,
|
||||
|
||||
for (auto& tilePtr : tilePtrs) {
|
||||
tilePtr->data->redoPlacement(
|
||||
{ transformState.getAngle(), transformState.getPitch(), data.getDebug() & MapDebugOptions::Collision });
|
||||
{ parameters.transformState.getAngle(), parameters.transformState.getPitch(), parameters.debugOptions & MapDebugOptions::Collision });
|
||||
}
|
||||
|
||||
updated = data.getAnimationTime();
|
||||
updated = parameters.animationTime;
|
||||
|
||||
return allTilesUpdated;
|
||||
}
|
||||
|
||||
@@ -22,9 +22,7 @@
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class MapData;
|
||||
class TexturePool;
|
||||
class Style;
|
||||
class StyleUpdateParameters;
|
||||
class Painter;
|
||||
class FileRequest;
|
||||
class TransformState;
|
||||
@@ -72,11 +70,7 @@ public:
|
||||
// will return true if all the tiles were scheduled for updating of false if
|
||||
// they were not. shouldReparsePartialTiles must be set to "true" if there is
|
||||
// new data available that a tile in the "partial" state might be interested at.
|
||||
bool update(MapData&,
|
||||
const TransformState&,
|
||||
Style&,
|
||||
TexturePool&,
|
||||
bool shouldReparsePartialTiles);
|
||||
bool update(const StyleUpdateParameters&);
|
||||
|
||||
void updateMatrices(const mat4 &projMatrix, const TransformState &transform);
|
||||
void drawClippingMasks(Painter &painter);
|
||||
@@ -108,13 +102,8 @@ private:
|
||||
int32_t coveringZoomLevel(const TransformState&) const;
|
||||
std::forward_list<TileID> coveringTiles(const TransformState&) const;
|
||||
|
||||
TileData::State addTile(MapData&,
|
||||
const TransformState&,
|
||||
Style&,
|
||||
TexturePool&,
|
||||
const TileID&);
|
||||
|
||||
TileData::State hasTile(const TileID& id);
|
||||
TileData::State addTile(const TileID&, const StyleUpdateParameters&);
|
||||
TileData::State hasTile(const TileID&);
|
||||
void updateTilePtrs();
|
||||
|
||||
double getZoom(const TransformState &state) const;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <mbgl/style/style_parser.hpp>
|
||||
#include <mbgl/style/property_transition.hpp>
|
||||
#include <mbgl/style/class_dictionary.hpp>
|
||||
#include <mbgl/style/style_update_parameters.hpp>
|
||||
#include <mbgl/style/style_cascade_parameters.hpp>
|
||||
#include <mbgl/style/style_calculation_parameters.hpp>
|
||||
#include <mbgl/geometry/glyph_atlas.hpp>
|
||||
@@ -104,8 +105,18 @@ void Style::removeLayer(const std::string& id) {
|
||||
void Style::update(const TransformState& transform,
|
||||
TexturePool& texturePool) {
|
||||
bool allTilesUpdated = true;
|
||||
StyleUpdateParameters parameters(data.pixelRatio,
|
||||
data.getDebug(),
|
||||
data.getAnimationTime(),
|
||||
transform,
|
||||
workers,
|
||||
texturePool,
|
||||
shouldReparsePartialTiles,
|
||||
data,
|
||||
*this);
|
||||
|
||||
for (const auto& source : sources) {
|
||||
if (!source->update(data, transform, *this, texturePool, shouldReparsePartialTiles)) {
|
||||
if (!source->update(parameters)) {
|
||||
allTilesUpdated = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,12 +19,15 @@
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class MapData;
|
||||
class GlyphAtlas;
|
||||
class GlyphStore;
|
||||
class SpriteStore;
|
||||
class SpriteAtlas;
|
||||
class LineAtlas;
|
||||
class StyleLayer;
|
||||
class TransformState;
|
||||
class TexturePool;
|
||||
|
||||
class Style : public GlyphStore::Observer,
|
||||
public SpriteStore::Observer,
|
||||
|
||||
50
src/mbgl/style/style_update_parameters.hpp
Normal file
50
src/mbgl/style/style_update_parameters.hpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#ifndef STYLE_UPDATE_PARAMETERS
|
||||
#define STYLE_UPDATE_PARAMETERS
|
||||
|
||||
#include <mbgl/map/mode.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class TransformState;
|
||||
class Worker;
|
||||
class TexturePool;
|
||||
class MapData;
|
||||
class Style;
|
||||
|
||||
class StyleUpdateParameters {
|
||||
public:
|
||||
StyleUpdateParameters(float pixelRatio_,
|
||||
MapDebugOptions debugOptions_,
|
||||
TimePoint animationTime_,
|
||||
const TransformState& transformState_,
|
||||
Worker& worker_,
|
||||
TexturePool& texturePool_,
|
||||
bool shouldReparsePartialTiles_,
|
||||
MapData& data_,
|
||||
Style& style_)
|
||||
: pixelRatio(pixelRatio_),
|
||||
debugOptions(debugOptions_),
|
||||
animationTime(animationTime_),
|
||||
transformState(transformState_),
|
||||
worker(worker_),
|
||||
texturePool(texturePool_),
|
||||
shouldReparsePartialTiles(shouldReparsePartialTiles_),
|
||||
data(data_),
|
||||
style(style_) {}
|
||||
|
||||
float pixelRatio;
|
||||
MapDebugOptions debugOptions;
|
||||
TimePoint animationTime;
|
||||
const TransformState& transformState;
|
||||
Worker& worker;
|
||||
TexturePool& texturePool;
|
||||
bool shouldReparsePartialTiles;
|
||||
|
||||
// TODO: remove
|
||||
MapData& data;
|
||||
Style& style;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user