diff --git a/src/mbgl/map/source.cpp b/src/mbgl/map/source.cpp index adbd7d6ad..f09d6db85 100644 --- a/src/mbgl/map/source.cpp +++ b/src/mbgl/map/source.cpp @@ -39,9 +39,7 @@ Source::Source() {} Source::~Source() = default; bool Source::isLoaded() const { - if (!loaded) { - return false; - } + if (!loaded) return false; for (const auto& tile : tiles) { if (tile.second->data->getState() != TileData::State::parsed) { @@ -52,6 +50,10 @@ bool Source::isLoaded() const { return true; } +bool Source::isLoading() const { + return !loaded && req.operator bool(); +} + // Note: This is a separate function that must be called exactly once after creation // The reason this isn't part of the constructor is that calling shared_from_this() in // the constructor fails. diff --git a/src/mbgl/map/source.hpp b/src/mbgl/map/source.hpp index dd94dc1fe..dc939113b 100644 --- a/src/mbgl/map/source.hpp +++ b/src/mbgl/map/source.hpp @@ -35,7 +35,9 @@ public: Source(); ~Source(); + bool loaded = false; void load(); + bool isLoading() const; bool isLoaded() const; // Request or parse all the tiles relevant for the "TransformState". This method @@ -58,7 +60,7 @@ public: void dumpDebugLogs() const; SourceInfo info; - bool enabled; + bool enabled = false; private: void tileLoadingCompleteCallback(const TileID&, const TransformState&, bool collisionDebug); @@ -80,7 +82,6 @@ private: double getZoom(const TransformState &state) const; - bool loaded = false; // Stores the time when this source was most recently updated. TimePoint updated = TimePoint::min(); diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index d82689f22..77a544714 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -77,7 +77,6 @@ Style::~Style() { void Style::addSource(std::unique_ptr source) { source->setObserver(this); - source->load(); sources.emplace_back(std::move(source)); } @@ -184,11 +183,10 @@ void Style::recalculate(float z) { hasPendingTransitions |= layer->recalculate(parameters); Source* source = getSource(layer->source); - if (!source) { - continue; + if (source && layer->needsRendering()) { + source->enabled = true; + if (!source->loaded && !source->isLoading()) source->load(); } - - source->enabled = true; } } @@ -209,10 +207,8 @@ bool Style::isLoaded() const { return false; } - for (const auto& source : sources) { - if (!source->isLoaded()) { - return false; - } + for (const auto& source: sources) { + if (source->enabled && !source->isLoaded()) return false; } if (!spriteStore->isLoaded()) { diff --git a/src/mbgl/style/style_layer.cpp b/src/mbgl/style/style_layer.cpp index c9d2733fa..defdfca11 100644 --- a/src/mbgl/style/style_layer.cpp +++ b/src/mbgl/style/style_layer.cpp @@ -10,4 +10,8 @@ bool StyleLayer::hasRenderPass(RenderPass pass) const { return bool(passes & pass); } +bool StyleLayer::needsRendering() const { + return passes != RenderPass::None && visibility != VisibilityType::None; +} + } // namespace mbgl diff --git a/src/mbgl/style/style_layer.hpp b/src/mbgl/style/style_layer.hpp index 052b4c356..764906576 100644 --- a/src/mbgl/style/style_layer.hpp +++ b/src/mbgl/style/style_layer.hpp @@ -50,6 +50,9 @@ public: // Checks whether this layer needs to be rendered in the given render pass. bool hasRenderPass(RenderPass) const; + // Checks whether this layer can be rendered. + bool needsRendering() const; + public: std::string id; std::string ref; diff --git a/test/fixtures/resources/style.json b/test/fixtures/resources/style.json index fc5f9c973..f794d54fa 100644 --- a/test/fixtures/resources/style.json +++ b/test/fixtures/resources/style.json @@ -32,5 +32,9 @@ "text-font": ["Open Sans Regular", "Arial Unicode MS Regular"], "icon-image": "{maki}_icon" } + }, { + "id": "rasterlayer", + "type": "fill", + "source": "rastersource" }] } diff --git a/test/style/pending_resources.cpp b/test/style/pending_resources.cpp index 7f665e85e..e87de1a31 100644 --- a/test/style/pending_resources.cpp +++ b/test/style/pending_resources.cpp @@ -39,7 +39,7 @@ TEST_P(PendingResources, DeleteMapObjectWithPendingRequest) { const std::string style = util::read_file("test/fixtures/resources/style.json"); map->setStyleJSON(style, "."); - map->renderStill([&endTest](std::exception_ptr, PremultipliedImage&&) { + map->renderStill([](std::exception_ptr, PremultipliedImage&&) { EXPECT_TRUE(false) << "Should never happen."; }); diff --git a/test/style/resource_loading.cpp b/test/style/resource_loading.cpp index c646f0372..ba6a138b5 100644 --- a/test/style/resource_loading.cpp +++ b/test/style/resource_loading.cpp @@ -51,6 +51,8 @@ public: data_.setAnimationTime(now); transform_.updateTransitions(now); + style_->cascade(); + style_->recalculate(16); style_->update(transform_.getState(), texturePool_); }