Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[core] make{Glyph,Image}Atlas only once for any number of symbol layers #9355

Merged
merged 1 commit into from
Jul 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions src/mbgl/layout/symbol_layout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,6 @@ class SymbolLayout {

bool hasSymbolInstances() const;

enum State {
Pending, // Waiting for the necessary glyphs or icons to be available.
Placed // The final positions have been determined, taking into account prior layers.
};

State state = Pending;

std::map<std::string,
std::pair<style::IconPaintProperties::PossiblyEvaluated, style::TextPaintProperties::PossiblyEvaluated>> layerPaintProperties;

Expand Down
49 changes: 23 additions & 26 deletions src/mbgl/tile/geometry_tile_worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,14 @@ void GeometryTileWorker::symbolDependenciesChanged() {
try {
switch (state) {
case Idle:
if (hasPendingSymbolLayouts()) {
if (symbolLayoutsNeedPreparation) {
attemptPlacement();
coalesce();
}
break;

case Coalescing:
if (hasPendingSymbolLayouts()) {
if (symbolLayoutsNeedPreparation) {
state = NeedPlacement;
}
break;
Expand Down Expand Up @@ -312,6 +312,7 @@ void GeometryTileWorker::redoLayout() {
auto layout = leader.as<RenderSymbolLayer>()->createLayout(
parameters, group, std::move(geometryLayer), glyphDependencies, imageDependencies);
symbolLayoutMap.emplace(leader.getID(), std::move(layout));
symbolLayoutsNeedPreparation = true;
} else {
const Filter& filter = leader.baseImpl->filter;
const std::string& sourceLayerID = leader.baseImpl->sourceLayer;
Expand Down Expand Up @@ -359,16 +360,6 @@ void GeometryTileWorker::redoLayout() {
attemptPlacement();
}

bool GeometryTileWorker::hasPendingSymbolLayouts() const {
for (const auto& symbolLayout : symbolLayouts) {
if (symbolLayout->state == SymbolLayout::Pending) {
return true;
}
}

return false;
}

bool GeometryTileWorker::hasPendingSymbolDependencies() const {
for (auto& glyphDependency : pendingGlyphDependencies) {
if (!glyphDependency.second.empty()) {
Expand All @@ -378,33 +369,39 @@ bool GeometryTileWorker::hasPendingSymbolDependencies() const {
return !pendingImageDependencies.empty();
}


void GeometryTileWorker::attemptPlacement() {
if (!data || !layers || !placementConfig || hasPendingSymbolDependencies()) {
return;
}

auto collisionTile = std::make_unique<CollisionTile>(*placementConfig);
std::unordered_map<std::string, std::shared_ptr<Bucket>> buckets;

optional<AlphaImage> glyphAtlasImage;
optional<PremultipliedImage> iconAtlasImage;

for (auto& symbolLayout : symbolLayouts) {
if (obsolete) {
return;
}
if (symbolLayoutsNeedPreparation) {
GlyphAtlas glyphAtlas = makeGlyphAtlas(glyphMap);
ImageAtlas imageAtlas = makeImageAtlas(imageMap);

glyphAtlasImage = std::move(glyphAtlas.image);
iconAtlasImage = std::move(imageAtlas.image);

if (symbolLayout->state == SymbolLayout::Pending) {
GlyphAtlas glyphAtlas = makeGlyphAtlas(glyphMap);
ImageAtlas imageAtlas = makeImageAtlas(imageMap);
for (auto& symbolLayout : symbolLayouts) {
if (obsolete) {
return;
}

symbolLayout->prepare(glyphMap, glyphAtlas.positions,
imageMap, imageAtlas.positions);
symbolLayout->state = SymbolLayout::Placed;
}

symbolLayoutsNeedPreparation = false;
}

glyphAtlasImage = std::move(glyphAtlas.image);
iconAtlasImage = std::move(imageAtlas.image);
auto collisionTile = std::make_unique<CollisionTile>(*placementConfig);
std::unordered_map<std::string, std::shared_ptr<Bucket>> buckets;

for (auto& symbolLayout : symbolLayouts) {
if (obsolete) {
return;
}

if (!symbolLayout->hasSymbolInstances()) {
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/tile/geometry_tile_worker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class GeometryTileWorker {

void symbolDependenciesChanged();
bool hasPendingSymbolDependencies() const;
bool hasPendingSymbolLayouts() const;

ActorRef<GeometryTileWorker> self;
ActorRef<GeometryTile> parent;
Expand All @@ -77,6 +76,7 @@ class GeometryTileWorker {
optional<std::unique_ptr<const GeometryTileData>> data;
optional<PlacementConfig> placementConfig;

bool symbolLayoutsNeedPreparation = false;
std::vector<std::unique_ptr<SymbolLayout>> symbolLayouts;
GlyphDependencies pendingGlyphDependencies;
ImageDependencies pendingImageDependencies;
Expand Down