summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-06-16 15:51:47 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-06-17 11:38:03 -0700
commite2f52a1dd8020e8665c55650c75d4e5a5e1423a6 (patch)
tree94e9ee3fdc377c2af12416059e0f74895961da94
parenta3318c2ced80a3b79dd898afb9f0fe27f0ce7571 (diff)
downloadqtlocation-mapboxgl-e2f52a1dd8020e8665c55650c75d4e5a5e1423a6.tar.gz
[core] Copy only the necessary style layers to the worker
-rw-r--r--src/mbgl/style/style.cpp6
-rw-r--r--src/mbgl/style/style.hpp2
-rw-r--r--src/mbgl/tile/geometry_tile.cpp42
-rw-r--r--src/mbgl/tile/geometry_tile.hpp4
-rw-r--r--src/mbgl/tile/tile_worker.cpp17
-rw-r--r--src/mbgl/tile/tile_worker.hpp2
6 files changed, 42 insertions, 31 deletions
diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp
index d825e57640..eade8c51c9 100644
--- a/src/mbgl/style/style.cpp
+++ b/src/mbgl/style/style.cpp
@@ -120,11 +120,11 @@ void Style::removeSource(const std::string& id) {
sources.erase(it);
}
-std::vector<std::unique_ptr<Layer>> Style::getLayers() const {
- std::vector<std::unique_ptr<Layer>> result;
+std::vector<const Layer*> Style::getLayers() const {
+ std::vector<const Layer*> result;
result.reserve(layers.size());
for (const auto& layer : layers) {
- result.push_back(layer->baseImpl->clone());
+ result.push_back(layer.get());
}
return result;
}
diff --git a/src/mbgl/style/style.hpp b/src/mbgl/style/style.hpp
index e83cab8050..1a41c4ce40 100644
--- a/src/mbgl/style/style.hpp
+++ b/src/mbgl/style/style.hpp
@@ -62,7 +62,7 @@ public:
void addSource(std::unique_ptr<Source>);
void removeSource(const std::string& sourceID);
- std::vector<std::unique_ptr<Layer>> getLayers() const;
+ std::vector<const Layer*> getLayers() const;
Layer* getLayer(const std::string& id) const;
void addLayer(std::unique_ptr<Layer>,
optional<std::string> beforeLayerID = {});
diff --git a/src/mbgl/tile/geometry_tile.cpp b/src/mbgl/tile/geometry_tile.cpp
index 41673a79c6..daa358420b 100644
--- a/src/mbgl/tile/geometry_tile.cpp
+++ b/src/mbgl/tile/geometry_tile.cpp
@@ -2,6 +2,8 @@
#include <mbgl/tile/tile_observer.hpp>
#include <mbgl/tile/geometry_tile_data.hpp>
#include <mbgl/style/layer_impl.hpp>
+#include <mbgl/style/layers/background_layer.hpp>
+#include <mbgl/style/layers/custom_layer.hpp>
#include <mbgl/util/worker.hpp>
#include <mbgl/util/work_request.hpp>
#include <mbgl/style/style.hpp>
@@ -12,15 +14,17 @@
namespace mbgl {
+using namespace style;
+
GeometryTile::GeometryTile(const OverscaledTileID& id_,
- std::string sourceID,
- style::Style& style_,
+ std::string sourceID_,
+ Style& style_,
const MapMode mode_)
: Tile(id_),
+ sourceID(std::move(sourceID_)),
style(style_),
worker(style_.workers),
tileWorker(id_,
- sourceID,
*style_.spriteStore,
*style_.glyphAtlas,
*style_.glyphStore,
@@ -28,10 +32,34 @@ GeometryTile::GeometryTile(const OverscaledTileID& id_,
mode_) {
}
+GeometryTile::~GeometryTile() {
+ cancel();
+}
+
void GeometryTile::setError(std::exception_ptr err) {
observer->onTileError(*this, err);
}
+std::vector<std::unique_ptr<Layer>> GeometryTile::cloneStyleLayers() const {
+ std::vector<std::unique_ptr<Layer>> result;
+
+ for (const Layer* layer : style.getLayers()) {
+ // Avoid cloning and including irrelevant layers.
+ if (layer->is<BackgroundLayer>() ||
+ layer->is<CustomLayer>() ||
+ layer->baseImpl->source != sourceID ||
+ id.overscaledZ < std::floor(layer->baseImpl->minZoom) ||
+ id.overscaledZ >= std::ceil(layer->baseImpl->maxZoom) ||
+ layer->baseImpl->visibility == VisibilityType::None) {
+ continue;
+ }
+
+ result.push_back(layer->baseImpl->clone());
+ }
+
+ return result;
+}
+
void GeometryTile::setData(std::unique_ptr<GeometryTileData> data_) {
if (!data_) {
// This is a 404 response. We're treating these as empty tiles.
@@ -53,7 +81,7 @@ void GeometryTile::setData(std::unique_ptr<GeometryTileData> data_) {
// when tile data changed. Replacing the workdRequest will cancel a pending work
// request in case there is one.
workRequest.reset();
- workRequest = worker.parseGeometryTile(tileWorker, style.getLayers(), std::move(data_), targetConfig, [this, config = targetConfig] (TileParseResult result) {
+ workRequest = worker.parseGeometryTile(tileWorker, cloneStyleLayers(), std::move(data_), targetConfig, [this, config = targetConfig] (TileParseResult result) {
workRequest.reset();
if (result.is<TileParseResultData>()) {
@@ -82,10 +110,6 @@ void GeometryTile::setData(std::unique_ptr<GeometryTileData> data_) {
});
}
-GeometryTile::~GeometryTile() {
- cancel();
-}
-
bool GeometryTile::parsePending() {
if (workRequest) {
// There's already parsing or placement going on.
@@ -126,7 +150,7 @@ bool GeometryTile::parsePending() {
return true;
}
-Bucket* GeometryTile::getBucket(const style::Layer& layer) {
+Bucket* GeometryTile::getBucket(const Layer& layer) {
const auto it = buckets.find(layer.baseImpl->bucketName());
if (it == buckets.end()) {
return nullptr;
diff --git a/src/mbgl/tile/geometry_tile.hpp b/src/mbgl/tile/geometry_tile.hpp
index 71b7db3cf4..6072e2b1da 100644
--- a/src/mbgl/tile/geometry_tile.hpp
+++ b/src/mbgl/tile/geometry_tile.hpp
@@ -8,6 +8,7 @@
#include <memory>
#include <unordered_map>
+#include <vector>
namespace mbgl {
@@ -17,6 +18,7 @@ class FeatureIndex;
namespace style {
class Style;
+class Layer;
} // namespace style
class GeometryTile : public Tile {
@@ -46,8 +48,10 @@ public:
void cancel() override;
private:
+ std::vector<std::unique_ptr<style::Layer>> cloneStyleLayers() const;
void redoPlacement();
+ const std::string sourceID;
style::Style& style;
Worker& worker;
TileWorker tileWorker;
diff --git a/src/mbgl/tile/tile_worker.cpp b/src/mbgl/tile/tile_worker.cpp
index ea8cc5b1ed..c21a4a4ad7 100644
--- a/src/mbgl/tile/tile_worker.cpp
+++ b/src/mbgl/tile/tile_worker.cpp
@@ -2,8 +2,6 @@
#include <mbgl/tile/tile_worker.hpp>
#include <mbgl/tile/geometry_tile_data.hpp>
#include <mbgl/style/bucket_parameters.hpp>
-#include <mbgl/style/layers/background_layer.hpp>
-#include <mbgl/style/layers/custom_layer.hpp>
#include <mbgl/style/layers/symbol_layer.hpp>
#include <mbgl/style/layers/symbol_layer_impl.hpp>
#include <mbgl/sprite/sprite_atlas.hpp>
@@ -13,6 +11,7 @@
#include <mbgl/util/constants.hpp>
#include <mbgl/util/string.hpp>
#include <mbgl/util/exception.hpp>
+
#include <utility>
namespace mbgl {
@@ -20,14 +19,12 @@ namespace mbgl {
using namespace mbgl::style;
TileWorker::TileWorker(OverscaledTileID id_,
- std::string sourceID_,
SpriteStore& spriteStore_,
GlyphAtlas& glyphAtlas_,
GlyphStore& glyphStore_,
const util::Atomic<bool>& obsolete_,
const MapMode mode_)
: id(std::move(id_)),
- sourceID(std::move(sourceID_)),
spriteStore(spriteStore_),
glyphAtlas(glyphAtlas_),
glyphStore(glyphStore_),
@@ -135,18 +132,6 @@ void TileWorker::parseLayer(const Layer* layer) {
if (obsolete)
return;
- // Background and custom layers are special cases.
- if (layer->is<BackgroundLayer>() || layer->is<CustomLayer>())
- return;
-
- // Skip this bucket if we are to not render this
- if ((layer->baseImpl->source != sourceID) ||
- (id.overscaledZ < std::floor(layer->baseImpl->minZoom)) ||
- (id.overscaledZ >= std::ceil(layer->baseImpl->maxZoom)) ||
- (layer->baseImpl->visibility == VisibilityType::None)) {
- return;
- }
-
auto geometryLayer = tileData->getLayer(layer->baseImpl->sourceLayer);
if (!geometryLayer) {
// The layer specified in the bucket does not exist. Do nothing.
diff --git a/src/mbgl/tile/tile_worker.hpp b/src/mbgl/tile/tile_worker.hpp
index 34588645a4..b25858c955 100644
--- a/src/mbgl/tile/tile_worker.hpp
+++ b/src/mbgl/tile/tile_worker.hpp
@@ -46,7 +46,6 @@ using TileParseResult = variant<
class TileWorker : public util::noncopyable {
public:
TileWorker(OverscaledTileID,
- std::string sourceID,
SpriteStore&,
GlyphAtlas&,
GlyphStore&,
@@ -70,7 +69,6 @@ private:
std::unique_ptr<CollisionTile> placeLayers(PlacementConfig);
const OverscaledTileID id;
- const std::string sourceID;
SpriteStore& spriteStore;
GlyphAtlas& glyphAtlas;