diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-04-14 16:15:43 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-04-15 09:56:18 -0700 |
commit | ed489e764971b40b01e33e8505f2d31a72a0075e (patch) | |
tree | 34acdf5869430f30e27e8666af9d8fc8f7c77d21 | |
parent | 25ff2696a1c6741a5a61334f1bd965e9d5099f05 (diff) | |
download | qtlocation-mapboxgl-ed489e764971b40b01e33e8505f2d31a72a0075e.tar.gz |
[core] Remove MapData dependency from Style
-rw-r--r-- | src/mbgl/map/map.cpp | 25 | ||||
-rw-r--r-- | src/mbgl/style/style.cpp | 31 | ||||
-rw-r--r-- | src/mbgl/style/style.hpp | 18 | ||||
-rw-r--r-- | test/style/source.cpp | 8 | ||||
-rw-r--r-- | test/style/style.cpp | 18 |
5 files changed, 47 insertions, 53 deletions
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 55f0197dcb..8be4f1ebc0 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -9,6 +9,7 @@ #include <mbgl/style/style.hpp> #include <mbgl/style/style_layer.hpp> #include <mbgl/style/property_transition.hpp> +#include <mbgl/style/style_update_parameters.hpp> #include <mbgl/layer/custom_layer.hpp> #include <mbgl/renderer/painter.hpp> #include <mbgl/storage/file_source.hpp> @@ -209,14 +210,26 @@ void Map::Impl::update() { } if (updateFlags & Update::Classes) { - style->cascade(frameData.timePoint); + style->cascade(frameData.timePoint, data.mode); } if (updateFlags & Update::Classes || updateFlags & Update::RecalculateStyle) { - style->recalculate(transformState.getZoom(), frameData.timePoint); + style->recalculate(transformState.getZoom(), frameData.timePoint, data.mode); } - style->update(transformState, frameData.timePoint, *texturePool); + StyleUpdateParameters parameters(data.pixelRatio, + data.getDebug(), + frameData.timePoint, + transformState, + style->workers, + fileSource, + *texturePool, + style->shouldReparsePartialTiles, + data.mode, + *data.getAnnotationManager(), + *style); + + style->update(parameters); if (data.mode == MapMode::Continuous) { view.invalidate(); @@ -269,7 +282,7 @@ void Map::setStyleURL(const std::string& url) { impl->styleURL = url; impl->styleJSON.clear(); - impl->style = std::make_unique<Style>(impl->data, impl->fileSource); + impl->style = std::make_unique<Style>(impl->fileSource, impl->data.pixelRatio); const size_t pos = impl->styleURL.rfind('/'); std::string base = ""; @@ -304,7 +317,7 @@ void Map::setStyleJSON(const std::string& json, const std::string& base) { impl->styleURL.clear(); impl->styleJSON.clear(); - impl->style = std::make_unique<Style>(impl->data, impl->fileSource); + impl->style = std::make_unique<Style>(impl->fileSource, impl->data.pixelRatio); impl->loadStyleJSON(json, base); } @@ -315,7 +328,7 @@ void Map::Impl::loadStyleJSON(const std::string& json, const std::string& base) styleJSON = json; // force style cascade, causing all pending transitions to complete. - style->cascade(Clock::now()); + style->cascade(Clock::now(), data.mode); updateFlags |= Update::Classes | Update::RecalculateStyle | Update::Annotations; asyncUpdate.send(); diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index fc2bebdafc..1f674e07ad 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -57,13 +57,12 @@ std::vector<std::string> Style::getClasses() const { return classes; } -Style::Style(MapData& data_, FileSource& fileSource_) - : data(data_), - fileSource(fileSource_), +Style::Style(FileSource& fileSource_, float pixelRatio) + : fileSource(fileSource_), glyphStore(std::make_unique<GlyphStore>(fileSource)), glyphAtlas(std::make_unique<GlyphAtlas>(1024, 1024)), - spriteStore(std::make_unique<SpriteStore>(data.pixelRatio)), - spriteAtlas(std::make_unique<SpriteAtlas>(1024, 1024, data.pixelRatio, *spriteStore)), + spriteStore(std::make_unique<SpriteStore>(pixelRatio)), + spriteAtlas(std::make_unique<SpriteAtlas>(1024, 1024, pixelRatio, *spriteStore)), lineAtlas(std::make_unique<LineAtlas>(256, 512)), workers(4) { glyphStore->setObserver(this); @@ -147,20 +146,8 @@ void Style::removeLayer(const std::string& id) { layers.erase(it); } -void Style::update(const TransformState& transform, const TimePoint& timePoint, - gl::TexturePool& texturePool) { +void Style::update(const StyleUpdateParameters& parameters) { bool allTilesUpdated = true; - StyleUpdateParameters parameters(data.pixelRatio, - data.getDebug(), - timePoint, - transform, - workers, - fileSource, - texturePool, - shouldReparsePartialTiles, - data.mode, - *data.getAnnotationManager(), - *this); for (const auto& source : sources) { if (!source->update(parameters)) { @@ -175,7 +162,7 @@ void Style::update(const TransformState& transform, const TimePoint& timePoint, } } -void Style::cascade(const TimePoint& timePoint) { +void Style::cascade(const TimePoint& timePoint, MapMode mode) { // When in continuous mode, we can either have user- or style-defined // transitions. Still mode is always immediate. static const PropertyTransition immediateTransition; @@ -190,7 +177,7 @@ void Style::cascade(const TimePoint& timePoint) { const StyleCascadeParameters parameters { classIDs, timePoint, - data.mode == MapMode::Continuous ? transitionProperties.value_or(immediateTransition) : immediateTransition + mode == MapMode::Continuous ? transitionProperties.value_or(immediateTransition) : immediateTransition }; transitionProperties = {}; @@ -200,7 +187,7 @@ void Style::cascade(const TimePoint& timePoint) { } } -void Style::recalculate(float z, const TimePoint& timePoint) { +void Style::recalculate(float z, const TimePoint& timePoint, MapMode mode) { for (const auto& source : sources) { source->enabled = false; } @@ -211,7 +198,7 @@ void Style::recalculate(float z, const TimePoint& timePoint) { z, timePoint, zoomHistory, - data.mode == MapMode::Continuous ? util::DEFAULT_FADE_DURATION : Duration::zero() + mode == MapMode::Continuous ? util::DEFAULT_FADE_DURATION : Duration::zero() }; hasPendingTransitions = false; diff --git a/src/mbgl/style/style.hpp b/src/mbgl/style/style.hpp index e4ed7435b0..b3c06d8214 100644 --- a/src/mbgl/style/style.hpp +++ b/src/mbgl/style/style.hpp @@ -7,6 +7,7 @@ #include <mbgl/source/source.hpp> #include <mbgl/text/glyph_store.hpp> #include <mbgl/sprite/sprite_store.hpp> +#include <mbgl/map/mode.hpp> #include <mbgl/util/noncopyable.hpp> #include <mbgl/util/chrono.hpp> @@ -19,7 +20,6 @@ namespace mbgl { -class MapData; class FileSource; class GlyphAtlas; class GlyphStore; @@ -27,11 +27,9 @@ class SpriteStore; class SpriteAtlas; class LineAtlas; class StyleLayer; -class TransformState; class Tile; class Bucket; - -namespace gl { class TexturePool; } +class StyleUpdateParameters; struct RenderItem { inline RenderItem(const StyleLayer& layer_, @@ -56,7 +54,7 @@ class Style : public GlyphStore::Observer, public Source::Observer, public util::noncopyable { public: - Style(MapData&, FileSource&); + Style(FileSource&, float pixelRatio); ~Style(); class Observer : public GlyphStore::Observer, @@ -81,10 +79,10 @@ public: // Fetch the tiles needed by the current viewport and emit a signal when // a tile is ready so observers can render the tile. - void update(const TransformState&, const TimePoint&, gl::TexturePool&); + void update(const StyleUpdateParameters&); - void cascade(const TimePoint&); - void recalculate(float z, const TimePoint&); + void cascade(const TimePoint&, MapMode); + void recalculate(float z, const TimePoint&, MapMode); bool hasTransitions() const; @@ -114,7 +112,6 @@ public: void dumpDebugLogs() const; - MapData& data; FileSource& fileSource; std::unique_ptr<GlyphStore> glyphStore; std::unique_ptr<GlyphAtlas> glyphAtlas; @@ -145,8 +142,6 @@ private: void onTileError(Source&, const TileID&, std::exception_ptr) override; void onPlacementRedone() override; - bool shouldReparsePartialTiles = false; - Observer nullObserver; Observer* observer = &nullObserver; @@ -156,6 +151,7 @@ private: bool hasPendingTransitions = false; public: + bool shouldReparsePartialTiles = false; bool loaded = false; Worker workers; }; diff --git a/test/style/source.cpp b/test/style/source.cpp index 9c334c65d5..5ec2714b43 100644 --- a/test/style/source.cpp +++ b/test/style/source.cpp @@ -10,12 +10,12 @@ #include <mbgl/platform/log.hpp> #include <mbgl/map/transform.hpp> -#include <mbgl/map/map_data.hpp> #include <mbgl/util/worker.hpp> #include <mbgl/gl/texture_pool.hpp> #include <mbgl/style/style.hpp> #include <mbgl/style/style_update_parameters.hpp> #include <mbgl/layer/line_layer.hpp> +#include <mbgl/annotation/annotation_manager.hpp> using namespace mbgl; @@ -29,8 +29,8 @@ public: TransformState transformState; Worker worker { 1 }; gl::TexturePool texturePool; - MapData mapData { MapMode::Still, GLContextMode::Unique, 1.0 }; - Style style { mapData, fileSource }; + AnnotationManager annotationManager { 1.0 }; + Style style { fileSource, 1.0 }; StyleUpdateParameters updateParameters { 1.0, @@ -42,7 +42,7 @@ public: texturePool, true, MapMode::Continuous, - mapData, + annotationManager, style }; diff --git a/test/style/style.cpp b/test/style/style.cpp index 03e044ba76..831edfff94 100644 --- a/test/style/style.cpp +++ b/test/style/style.cpp @@ -10,15 +10,14 @@ using namespace mbgl; TEST(Style, UnusedSource) { util::RunLoop loop; - MapData data { MapMode::Still, GLContextMode::Unique, 1.0 }; StubFileSource fileSource; - Style style { data, fileSource }; + Style style { fileSource, 1.0 }; auto now = Clock::now(); style.setJSON(util::read_file("test/fixtures/resources/style-unused-sources.json"), ""); - style.cascade(now); - style.recalculate(0, now); + style.cascade(now, MapMode::Still); + style.recalculate(0, now, MapMode::Still); Source *usedSource = style.getSource("usedsource"); EXPECT_TRUE(usedSource); @@ -32,9 +31,8 @@ TEST(Style, UnusedSource) { TEST(Style, UnusedSourceActiveViaClassUpdate) { util::RunLoop loop; - MapData data { MapMode::Still, GLContextMode::Unique, 1.0 }; StubFileSource fileSource; - Style style { data, fileSource }; + Style style { fileSource, 1.0 }; style.setJSON(util::read_file("test/fixtures/resources/style-unused-sources.json"), ""); EXPECT_TRUE(style.addClass("visible")); @@ -42,8 +40,8 @@ TEST(Style, UnusedSourceActiveViaClassUpdate) { auto now = Clock::now(); - style.cascade(now); - style.recalculate(0, now); + style.cascade(now, MapMode::Still); + style.recalculate(0, now, MapMode::Still); Source *unusedSource = style.getSource("unusedsource"); EXPECT_TRUE(unusedSource); @@ -55,8 +53,8 @@ TEST(Style, UnusedSourceActiveViaClassUpdate) { now = Clock::now(); - style.cascade(now); - style.recalculate(0, now); + style.cascade(now, MapMode::Still); + style.recalculate(0, now, MapMode::Still); unusedSource = style.getSource("unusedsource"); EXPECT_TRUE(unusedSource); |