summaryrefslogtreecommitdiff
path: root/src/mbgl/style/layers/symbol_layer_impl.cpp
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-09-08 12:31:36 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-09-14 13:41:56 -0700
commitc8217a873940264387a7d8101f968798ac7d543e (patch)
treebf3e32b78cad4681974afa99eb14b6b579dd0343 /src/mbgl/style/layers/symbol_layer_impl.cpp
parent0bdd968d2b6eb0a12c5f2879a6a8801c96a35d85 (diff)
downloadqtlocation-mapboxgl-c8217a873940264387a7d8101f968798ac7d543e.tar.gz
[core] Extract SymbolLayout from SymbolBucket
SymbolLayout lives on the worker thread and contains the persistent data needed for repeated placement. SymbolBucket contains the data generated during placement, and is transferred to the main thread for rendering. This eliminates the risky sharing of GeometryTile::buckets between the main thread and worker thread during TileWorker::redoPlacement. While here, rationalize the names of states a SymbolLayout may be in: * Pending: Waiting for the necessary glyphs or icons to be available. * Prepared: The potential positions of text and icons have been determined. * Placed: The final positions have been determined, taking into account prior layers. In TileWorker, all SymbolLayouts are stored in a single vector. Each SymbolLayout knows what state it is in, and TileWorker can easily determine how much progress it can make toward a final result.
Diffstat (limited to 'src/mbgl/style/layers/symbol_layer_impl.cpp')
-rw-r--r--src/mbgl/style/layers/symbol_layer_impl.cpp71
1 files changed, 31 insertions, 40 deletions
diff --git a/src/mbgl/style/layers/symbol_layer_impl.cpp b/src/mbgl/style/layers/symbol_layer_impl.cpp
index 0243b1dfa5..1039951f5e 100644
--- a/src/mbgl/style/layers/symbol_layer_impl.cpp
+++ b/src/mbgl/style/layers/symbol_layer_impl.cpp
@@ -1,6 +1,7 @@
#include <mbgl/style/layers/symbol_layer_impl.hpp>
-#include <mbgl/renderer/symbol_bucket.hpp>
#include <mbgl/style/bucket_parameters.hpp>
+#include <mbgl/layout/symbol_layout.hpp>
+#include <mbgl/renderer/bucket.hpp>
namespace mbgl {
namespace style {
@@ -25,54 +26,44 @@ bool SymbolLayer::Impl::recalculate(const CalculationParameters& parameters) {
return hasTransitions;
}
-std::unique_ptr<Bucket> SymbolLayer::Impl::createBucket(BucketParameters& parameters) const {
- auto bucket = std::make_unique<SymbolBucket>(parameters.tileID.overscaleFactor(),
- parameters.tileID.overscaledZ,
- parameters.mode,
- id,
- parameters.layer.getName());
+std::unique_ptr<Bucket> SymbolLayer::Impl::createBucket(BucketParameters&) const {
+ assert(false); // Should be calling createLayout() instead.
+ return nullptr;
+}
- bucket->layout = layout;
+std::unique_ptr<SymbolLayout> SymbolLayer::Impl::createLayout(BucketParameters& parameters) const {
+ SymbolLayoutProperties layoutProperties = layout;
CalculationParameters p(parameters.tileID.overscaledZ);
- bucket->layout.symbolPlacement.calculate(p);
- if (bucket->layout.symbolPlacement.value == SymbolPlacementType::Line) {
- bucket->layout.iconRotationAlignment.value = AlignmentType::Map;
- bucket->layout.textRotationAlignment.value = AlignmentType::Map;
- };
+ layoutProperties.symbolPlacement.calculate(p);
+ if (layoutProperties.symbolPlacement.value == SymbolPlacementType::Line) {
+ layoutProperties.iconRotationAlignment.value = AlignmentType::Map;
+ layoutProperties.textRotationAlignment.value = AlignmentType::Map;
+ }
// If unspecified `text-pitch-alignment` inherits `text-rotation-alignment`
- if (bucket->layout.textPitchAlignment.value == AlignmentType::Undefined) {
- bucket->layout.textPitchAlignment.value = bucket->layout.textRotationAlignment.value;
- };
-
- bucket->layout.recalculate(p);
-
- bucket->layout.iconSize.calculate(CalculationParameters(18));
- bucket->layout.textSize.calculate(CalculationParameters(18));
- bucket->iconMaxSize = bucket->layout.iconSize;
- bucket->textMaxSize = bucket->layout.textSize;
- bucket->layout.iconSize.calculate(CalculationParameters(p.z + 1));
- bucket->layout.textSize.calculate(CalculationParameters(p.z + 1));
+ if (layoutProperties.textPitchAlignment.value == AlignmentType::Undefined) {
+ layoutProperties.textPitchAlignment.value = layoutProperties.textRotationAlignment.value;
+ }
- bucket->parseFeatures(parameters.layer, filter);
+ layoutProperties.recalculate(p);
- if (bucket->needsDependencies(parameters.glyphStore, parameters.spriteStore)) {
- parameters.partialParse = true;
- }
+ layoutProperties.textSize.calculate(CalculationParameters(18));
+ float textMaxSize = layoutProperties.textSize;
- // We do not add features if the parser is in a "partial" state because
- // the layer ordering needs to be respected when calculating text
- // collisions. Although, at this point, we requested all the resources
- // needed by this tile.
- if (!parameters.partialParse) {
- bucket->addFeatures(parameters.tileUID,
- *spriteAtlas,
- parameters.glyphAtlas,
- parameters.glyphStore);
- }
+ layoutProperties.iconSize.calculate(CalculationParameters(p.z + 1));
+ layoutProperties.textSize.calculate(CalculationParameters(p.z + 1));
- return std::move(bucket);
+ return std::make_unique<SymbolLayout>(id,
+ parameters.layer.getName(),
+ parameters.tileID.overscaleFactor(),
+ parameters.tileID.overscaledZ,
+ parameters.mode,
+ parameters.layer,
+ filter,
+ layoutProperties,
+ textMaxSize,
+ *spriteAtlas);
}
} // namespace style