Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[core] Introduce StyleUpdateParameters #3157

Merged
merged 2 commits into from
Dec 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/mbgl/annotation/annotation_manager.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <mbgl/annotation/annotation_manager.hpp>
#include <mbgl/annotation/annotation_tile.hpp>
#include <mbgl/map/map_data.hpp>
#include <mbgl/style/style.hpp>
#include <mbgl/layer/symbol_layer.hpp>

Expand All @@ -11,8 +10,7 @@ namespace mbgl {
const std::string AnnotationManager::SourceID = "com.mapbox.annotations";
const std::string AnnotationManager::PointLayerID = "com.mapbox.annotations.points";

AnnotationManager::AnnotationManager(MapData& data_) : data(data_) {}

AnnotationManager::AnnotationManager() = default;
AnnotationManager::~AnnotationManager() = default;

AnnotationIDs
Expand Down Expand Up @@ -110,7 +108,7 @@ std::unique_ptr<AnnotationTile> AnnotationManager::getTile(const TileID& tileID)
void AnnotationManager::updateStyle(Style& style) {
// Create annotation source, point layer, and point bucket
if (!style.getSource(SourceID)) {
std::unique_ptr<Source> source = std::make_unique<Source>(data);
std::unique_ptr<Source> source = std::make_unique<Source>();
source->info.type = SourceType::Annotations;
source->info.source_id = SourceID;
source->enabled = true;
Expand Down
4 changes: 1 addition & 3 deletions src/mbgl/annotation/annotation_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace mbgl {

class MapData;
class PointAnnotation;
class ShapeAnnotation;
class AnnotationTile;
Expand All @@ -22,7 +21,7 @@ class Style;

class AnnotationManager : private util::noncopyable {
public:
AnnotationManager(MapData&);
AnnotationManager();
~AnnotationManager();

AnnotationIDs addPointAnnotations(const std::vector<PointAnnotation>&, const uint8_t maxZoom);
Expand All @@ -43,7 +42,6 @@ class AnnotationManager : private util::noncopyable {
private:
std::unique_ptr<AnnotationTile> getTile(const TileID&);

MapData& data;
AnnotationID nextID = 0;
PointAnnotationImpl::Tree pointTree;
PointAnnotationImpl::Map pointAnnotations;
Expand Down
1 change: 1 addition & 0 deletions src/mbgl/annotation/annotation_tile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
1 change: 0 additions & 1 deletion src/mbgl/map/map_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class MapData {
: mode(mode_)
, contextMode(contextMode_)
, pixelRatio(pixelRatio_)
, annotationManager(*this)
, animationTime(Duration::zero())
, defaultFadeDuration(mode_ == MapMode::Continuous ? std::chrono::milliseconds(300) : Duration::zero())
, defaultTransitionDuration(Duration::zero())
Expand Down
53 changes: 24 additions & 29 deletions src/mbgl/map/source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -119,7 +120,7 @@ std::string SourceInfo::tileURL(const TileID& id, float pixelRatio) const {
return result;
}

Source::Source(MapData& data_) : data(data_) {}
Source::Source() {}

Source::~Source() = default;

Expand Down Expand Up @@ -246,10 +247,7 @@ bool Source::handlePartialTile(const TileID& id, Worker&) {
});
}

TileData::State Source::addTile(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) {
Expand Down Expand Up @@ -280,32 +278,32 @@ TileData::State Source::addTile(const TransformState& transformState,
}

if (!new_tile.data) {
auto callback = std::bind(&Source::tileLoadingCompleteCallback, this, normalized_id, transformState);
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");
}

new_tile.data = std::make_shared<VectorTileData>(normalized_id,
std::move(monitor),
info.source_id,
style,
parameters.style,
callback);
}

Expand Down Expand Up @@ -407,23 +405,20 @@ void Source::findLoadedParent(const TileID& id, int32_t minCoveringZoom, std::fo
}
}

bool Source::update(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);
Expand All @@ -440,14 +435,14 @@ bool Source::update(const TransformState& transformState,

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(transformState, style, texturePool, id);
state = addTile(id, parameters);
break;
default:
break;
Expand All @@ -470,9 +465,9 @@ bool Source::update(const TransformState& transformState,
}

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);
}
Expand Down Expand Up @@ -519,10 +514,10 @@ bool Source::update(const TransformState& transformState,

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;
}
Expand All @@ -546,7 +541,7 @@ void Source::setObserver(Observer* observer) {
observer_ = observer;
}

void Source::tileLoadingCompleteCallback(const TileID& normalized_id, const TransformState& transformState) {
void Source::tileLoadingCompleteCallback(const TileID& normalized_id, const TransformState& transformState, bool collisionDebug) {
auto it = tileDataMap.find(normalized_id);
if (it == tileDataMap.end()) {
return;
Expand All @@ -562,7 +557,7 @@ void Source::tileLoadingCompleteCallback(const TileID& normalized_id, const Tran
return;
}

tileData->redoPlacement({ transformState.getAngle(), transformState.getPitch(), data.getDebug() & MapDebugOptions::Collision});
tileData->redoPlacement({ transformState.getAngle(), transformState.getPitch(), collisionDebug });
emitTileLoaded(true);
}

Expand Down
23 changes: 6 additions & 17 deletions src/mbgl/map/source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@

namespace mbgl {

class MapData;
class TexturePool;
class Style;
class StyleUpdateParameters;
class Painter;
class FileRequest;
class TransformState;
Expand Down Expand Up @@ -62,7 +60,7 @@ class Source : private util::noncopyable {
virtual void onTileLoadingFailed(std::exception_ptr error) = 0;
};

Source(MapData&);
Source();
~Source();

void load();
Expand All @@ -72,10 +70,7 @@ class Source : private util::noncopyable {
// 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(const TransformState&,
Style&,
TexturePool&,
bool shouldReparsePartialTiles);
bool update(const StyleUpdateParameters&);

void updateMatrices(const mat4 &projMatrix, const TransformState &transform);
void drawClippingMasks(Painter &painter);
Expand All @@ -94,7 +89,7 @@ class Source : private util::noncopyable {
bool enabled;

private:
void tileLoadingCompleteCallback(const TileID&, const TransformState&);
void tileLoadingCompleteCallback(const TileID&, const TransformState&, bool collisionDebug);

void emitSourceLoaded();
void emitSourceLoadingFailed(const std::string& message);
Expand All @@ -107,18 +102,12 @@ class Source : private util::noncopyable {
int32_t coveringZoomLevel(const TransformState&) const;
std::forward_list<TileID> coveringTiles(const TransformState&) const;

TileData::State addTile(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;

MapData& data;

bool loaded = false;

// Stores the time when this source was most recently updated.
Expand Down
15 changes: 13 additions & 2 deletions src/mbgl/style/style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -43,7 +44,7 @@ void Style::setJSON(const std::string& json, const std::string&) {
return;
}

StyleParser parser(data);
StyleParser parser;
parser.parse(doc);

for (auto& source : parser.getSources()) {
Expand Down Expand Up @@ -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(transform, *this, texturePool, shouldReparsePartialTiles)) {
if (!source->update(parameters)) {
allTilesUpdated = false;
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/mbgl/style/style.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 1 addition & 6 deletions src/mbgl/style/style_parser.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
#include <mbgl/style/style_parser.hpp>
#include <mbgl/style/style_layer.hpp>

#include <mbgl/map/map_data.hpp>
#include <mbgl/platform/log.hpp>

#include <algorithm>

namespace mbgl {

StyleParser::StyleParser(MapData& data_)
: data(data_) {
}

void StyleParser::parse(const JSVal& document) {
if (document.HasMember("version")) {
version = document["version"].GetInt();
Expand Down Expand Up @@ -54,7 +49,7 @@ void StyleParser::parseSources(const JSVal& value) {
const JSVal& nameVal = itr->name;
const JSVal& sourceVal = itr->value;

std::unique_ptr<Source> source = std::make_unique<Source>(data);
std::unique_ptr<Source> source = std::make_unique<Source>();

source->info.source_id = { nameVal.GetString(), nameVal.GetStringLength() };

Expand Down
5 changes: 0 additions & 5 deletions src/mbgl/style/style_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@

namespace mbgl {

class MapData;
class StyleLayer;
class Source;

using JSVal = rapidjson::Value;

class StyleParser {
public:
StyleParser(MapData&);

void parse(const JSVal&);

std::vector<std::unique_ptr<Source>>&& getSources() {
Expand All @@ -48,8 +45,6 @@ class StyleParser {
void parseLayer(const std::string& id, const JSVal&, util::ptr<StyleLayer>&);
void parseVisibility(StyleLayer&, const JSVal& value);

MapData& data;

std::uint8_t version;

std::vector<std::unique_ptr<Source>> sources;
Expand Down
Loading