summaryrefslogtreecommitdiff
path: root/src/mbgl/style
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2015-11-06 15:26:12 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2015-12-01 11:16:57 -0800
commitb7674040ab768318c5accce50067550a7da4bea9 (patch)
tree500ae9289c8024c55c1406fe9ff6689247055fff /src/mbgl/style
parentbafbf6c04b1bfd5da84411f52a72e26783f3bcb7 (diff)
downloadqtlocation-mapboxgl-b7674040ab768318c5accce50067550a7da4bea9.tar.gz
[core] Privatize layers and sources
Diffstat (limited to 'src/mbgl/style')
-rw-r--r--src/mbgl/style/style.cpp82
-rw-r--r--src/mbgl/style/style.hpp28
2 files changed, 109 insertions, 1 deletions
diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp
index 7faa4b254a..b22aa546f7 100644
--- a/src/mbgl/style/style.cpp
+++ b/src/mbgl/style/style.cpp
@@ -1,6 +1,7 @@
#include <mbgl/style/style.hpp>
#include <mbgl/map/map_data.hpp>
#include <mbgl/map/source.hpp>
+#include <mbgl/map/tile.hpp>
#include <mbgl/map/transform_state.hpp>
#include <mbgl/layer/symbol_layer.hpp>
#include <mbgl/sprite/sprite_store.hpp>
@@ -16,6 +17,8 @@
#include <mbgl/geometry/line_atlas.hpp>
#include <mbgl/util/constants.hpp>
#include <mbgl/platform/log.hpp>
+#include <mbgl/layer/background_layer.hpp>
+
#include <csscolorparser/csscolorparser.hpp>
#include <rapidjson/document.h>
@@ -220,6 +223,85 @@ bool Style::isLoaded() const {
return true;
}
+RenderData Style::getRenderData() const {
+ RenderData result;
+
+ for (const auto& source : sources) {
+ if (source->enabled) {
+ result.sources.insert(source.get());
+ }
+ }
+
+ for (const auto& layer : layers) {
+ if (layer->visibility == VisibilityType::None)
+ continue;
+
+ if (const BackgroundLayer* background = dynamic_cast<const BackgroundLayer*>(layer.get())) {
+ if (background->paint.pattern.value.from.empty()) {
+ // This is a solid background. We can use glClear().
+ result.backgroundColor = background->paint.color;
+ result.backgroundColor[0] *= background->paint.opacity;
+ result.backgroundColor[1] *= background->paint.opacity;
+ result.backgroundColor[2] *= background->paint.opacity;
+ result.backgroundColor[3] *= background->paint.opacity;
+ } else {
+ // This is a textured background. We need to render it with a quad.
+ result.order.emplace_back(*layer);
+ }
+ continue;
+ }
+
+ Source* source = getSource(layer->source);
+ if (!source) {
+ Log::Warning(Event::Render, "can't find source for layer '%s'", layer->id.c_str());
+ continue;
+ }
+
+ for (auto tile : source->getTiles()) {
+ if (!tile->data || !tile->data->isReady())
+ continue;
+
+ // We're not clipping symbol layers, so when we have both parents and children of symbol
+ // layers, we drop all children in favor of their parent to avoid duplicate labels.
+ // See https://github.com/mapbox/mapbox-gl-native/issues/2482
+ if (layer->type == StyleLayerType::Symbol) {
+ bool skip = false;
+ // Look back through the buckets we decided to render to find out whether there is
+ // already a bucket from this layer that is a parent of this tile. Tiles are ordered
+ // by zoom level when we obtain them from getTiles().
+ for (auto it = result.order.rbegin(); it != result.order.rend() && (&it->layer == layer.get()); ++it) {
+ if (tile->id.isChildOf(it->tile->id)) {
+ skip = true;
+ break;
+ }
+ }
+ if (skip) {
+ continue;
+ }
+ }
+
+ auto bucket = tile->data->getBucket(*layer);
+ if (bucket) {
+ result.order.emplace_back(*layer, tile, bucket);
+ }
+ }
+ }
+
+ return result;
+}
+
+void Style::setSourceTileCacheSize(size_t size) {
+ for (const auto& source : sources) {
+ source->setCacheSize(size);
+ }
+}
+
+void Style::onLowMemory() {
+ for (const auto& source : sources) {
+ source->onLowMemory();
+ }
+}
+
void Style::setObserver(Observer* observer_) {
assert(util::ThreadContext::currentlyOn(util::ThreadType::Map));
assert(!observer);
diff --git a/src/mbgl/style/style.hpp b/src/mbgl/style/style.hpp
index d9cd137767..9afd933ffc 100644
--- a/src/mbgl/style/style.hpp
+++ b/src/mbgl/style/style.hpp
@@ -29,6 +29,27 @@ class StyleLayer;
class TransformState;
class TexturePool;
+class Tile;
+class Bucket;
+
+struct RenderItem {
+ inline RenderItem(const StyleLayer& layer_,
+ const Tile* tile_ = nullptr,
+ Bucket* bucket_ = nullptr)
+ : tile(tile_), bucket(bucket_), layer(layer_) {
+ }
+
+ const Tile* const tile;
+ Bucket* const bucket;
+ const StyleLayer& layer;
+};
+
+struct RenderData {
+ Color backgroundColor = {{ 0, 0, 0, 0 }};
+ std::set<Source*> sources;
+ std::vector<RenderItem> order;
+};
+
class Style : public GlyphStore::Observer,
public SpriteStore::Observer,
public Source::Observer,
@@ -73,6 +94,11 @@ public:
void addLayer(std::unique_ptr<StyleLayer>, const std::string& beforeLayerID);
void removeLayer(const std::string& layerID);
+ RenderData getRenderData() const;
+
+ void setSourceTileCacheSize(size_t);
+ void onLowMemory();
+
void dumpDebugLogs() const;
MapData& data;
@@ -82,10 +108,10 @@ public:
std::unique_ptr<SpriteAtlas> spriteAtlas;
std::unique_ptr<LineAtlas> lineAtlas;
+private:
std::vector<std::unique_ptr<Source>> sources;
std::vector<std::unique_ptr<StyleLayer>> layers;
-private:
std::vector<std::unique_ptr<StyleLayer>>::const_iterator findLayer(const std::string& layerID) const;
// GlyphStore::Observer implementation.