[core] Load sources only if there is at least one visible layer
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -77,7 +77,6 @@ Style::~Style() {
|
||||
|
||||
void Style::addSource(std::unique_ptr<Source> 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()) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
4
test/fixtures/resources/style.json
vendored
4
test/fixtures/resources/style.json
vendored
@@ -32,5 +32,9 @@
|
||||
"text-font": ["Open Sans Regular", "Arial Unicode MS Regular"],
|
||||
"icon-image": "{maki}_icon"
|
||||
}
|
||||
}, {
|
||||
"id": "rasterlayer",
|
||||
"type": "fill",
|
||||
"source": "rastersource"
|
||||
}]
|
||||
}
|
||||
|
||||
@@ -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.";
|
||||
});
|
||||
|
||||
|
||||
@@ -51,6 +51,8 @@ public:
|
||||
data_.setAnimationTime(now);
|
||||
transform_.updateTransitions(now);
|
||||
|
||||
style_->cascade();
|
||||
style_->recalculate(16);
|
||||
style_->update(transform_.getState(), texturePool_);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user