summaryrefslogtreecommitdiff
path: root/src/mbgl/layout/symbol_layout.hpp
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/layout/symbol_layout.hpp
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/layout/symbol_layout.hpp')
-rw-r--r--src/mbgl/layout/symbol_layout.hpp127
1 files changed, 127 insertions, 0 deletions
diff --git a/src/mbgl/layout/symbol_layout.hpp b/src/mbgl/layout/symbol_layout.hpp
new file mode 100644
index 0000000000..83a3735061
--- /dev/null
+++ b/src/mbgl/layout/symbol_layout.hpp
@@ -0,0 +1,127 @@
+#pragma once
+
+#include <mbgl/tile/geometry_tile_data.hpp>
+#include <mbgl/map/mode.hpp>
+#include <mbgl/text/collision_feature.hpp>
+#include <mbgl/text/quads.hpp>
+#include <mbgl/style/layers/symbol_layer_properties.hpp>
+
+#include <memory>
+#include <map>
+#include <set>
+#include <vector>
+
+namespace mbgl {
+
+class CollisionTile;
+class SpriteAtlas;
+class SpriteStore;
+class GlyphAtlas;
+class GlyphStore;
+class IndexedSubfeature;
+class SymbolBucket;
+
+namespace style {
+class Filter;
+} // namespace style
+
+class SymbolFeature {
+public:
+ GeometryCollection geometry;
+ std::u32string label;
+ std::string sprite;
+ std::size_t index;
+};
+
+struct Anchor;
+
+class SymbolInstance {
+public:
+ explicit SymbolInstance(Anchor& anchor, const GeometryCoordinates& line,
+ const Shaping& shapedText, const PositionedIcon& shapedIcon,
+ const style::SymbolLayoutProperties&, const bool inside, const uint32_t index,
+ const float textBoxScale, const float textPadding, style::SymbolPlacementType textPlacement,
+ const float iconBoxScale, const float iconPadding, style::SymbolPlacementType iconPlacement,
+ const GlyphPositions& face, const IndexedSubfeature& indexedfeature);
+
+ Point<float> point;
+ uint32_t index;
+ bool hasText;
+ bool hasIcon;
+ SymbolQuads glyphQuads;
+ SymbolQuads iconQuads;
+ CollisionFeature textCollisionFeature;
+ CollisionFeature iconCollisionFeature;
+};
+
+class SymbolLayout {
+public:
+ SymbolLayout(std::string bucketName_,
+ std::string sourceLayerName_,
+ uint32_t overscaling,
+ float zoom,
+ const MapMode,
+ const GeometryTileLayer&,
+ const style::Filter&,
+ style::SymbolLayoutProperties,
+ float textMaxSize,
+ SpriteAtlas&);
+
+ bool canPrepare(GlyphStore&, SpriteStore&);
+
+ void prepare(uintptr_t tileUID,
+ GlyphAtlas&,
+ GlyphStore&);
+
+ std::unique_ptr<SymbolBucket> place(CollisionTile&);
+
+ bool hasSymbolInstances() const;
+
+ enum State {
+ 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.
+ };
+
+ State state = Pending;
+
+ const std::string bucketName;
+ const std::string sourceLayerName;
+
+private:
+ void addFeature(const GeometryCollection&,
+ const Shaping& shapedText,
+ const PositionedIcon& shapedIcon,
+ const GlyphPositions& face,
+ const size_t index);
+
+ bool anchorIsTooClose(const std::u32string& text, const float repeatDistance, Anchor&);
+ std::map<std::u32string, std::vector<Anchor>> compareText;
+
+ void addToDebugBuffers(CollisionTile&, SymbolBucket&);
+
+ // Adds placed items to the buffer.
+ template <typename Buffer, typename GroupType>
+ void addSymbols(Buffer&, const SymbolQuads&, float scale,
+ const bool keepUpright, const style::SymbolPlacementType, const float placementAngle);
+
+ const float overscaling;
+ const float zoom;
+ const MapMode mode;
+ const style::SymbolLayoutProperties layout;
+ const float textMaxSize;
+
+ SpriteAtlas& spriteAtlas;
+
+ const uint32_t tileSize;
+ const float tilePixelRatio;
+
+ bool sdfIcons = false;
+ bool iconsNeedLinear = false;
+
+ std::set<GlyphRange> ranges;
+ std::vector<SymbolInstance> symbolInstances;
+ std::vector<SymbolFeature> features;
+};
+
+} // namespace mbgl