summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2015-12-15 16:06:34 -0800
committerBruno de Oliveira Abinader <bruno@mapbox.com>2015-12-17 16:53:37 -0800
commit93725e062a3f506fc829c9da4649c9ce032b4067 (patch)
tree9fbe1a9019f360da3c1a4f3afa0434e4ed5722e3 /src
parent5a63ce557629eee8436b004d6940d52e758949d4 (diff)
downloadqtlocation-mapboxgl-93725e062a3f506fc829c9da4649c9ce032b4067.tar.gz
[core] Load sources only if there is at least one visible layer
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/map/source.cpp8
-rw-r--r--src/mbgl/map/source.hpp5
-rw-r--r--src/mbgl/style/style.cpp14
-rw-r--r--src/mbgl/style/style_layer.cpp4
-rw-r--r--src/mbgl/style/style_layer.hpp3
5 files changed, 20 insertions, 14 deletions
diff --git a/src/mbgl/map/source.cpp b/src/mbgl/map/source.cpp
index adbd7d6ad0..f09d6db85a 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 dd94dc1fe2..dc939113b2 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 d82689f220..77a544714e 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) {
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 c9d2733fae..defdfca110 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 052b4c3566..764906576f 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;