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

[core] Extract SymbolLayout from SymbolBucket #6298

Merged
merged 2 commits into from
Sep 14, 2016
Merged

Conversation

jfirebaugh
Copy link
Contributor

I still need to debug this, but I want to get @ansis and @kkaefer 👀 on it as soon as possible.

This PR splits SymbolBucket in two. The new class SymbolLayout lives on the worker thread only 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. SymbolBucket::swapRenderData is no longer necessary.

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.

The related SymbolLayout methods reflect this terminology, which fixes #2884.

In TileWorker, all SymbolLayouts are now stored in a single vector. Each SymbolLayout knows what state it is in, and TileWorker can more straightforwardly determine how much progress it can make toward a final result. I think the advancement of a tile through the stages of processing is clearer now, making further progress towards #2851.

@mention-bot
Copy link

@jfirebaugh, thanks for your PR! By analyzing this pull request, we identified @ansis, @yhahn and @tmpsantos to be potential reviewers.

@jfirebaugh jfirebaugh added ⚠️ DO NOT MERGE Work in progress, proof of concept, or on hold Core The cross-platform C++ core, aka mbgl labels Sep 9, 2016
@jfirebaugh jfirebaugh force-pushed the symbol-layout branch 5 times, most recently from 86dee78 to 03dd84e Compare September 9, 2016 16:09
@jfirebaugh jfirebaugh added ✓ ready for review and removed ⚠️ DO NOT MERGE Work in progress, proof of concept, or on hold labels Sep 9, 2016
@jfirebaugh
Copy link
Contributor Author

I'd like to merge this today, so I can continue progress on fixing #6263. Reviews appreciated!

@jfirebaugh
Copy link
Contributor Author

@ansis @kkaefer Please review.

@kkaefer
Copy link
Member

kkaefer commented Sep 14, 2016

Moving most of the code + changes in one commit makes this really hard to review.

@kkaefer
Copy link
Member

kkaefer commented Sep 14, 2016

The new class SymbolLayout lives on the worker thread only 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.

Really liking this separation. While reviewing, I didn't spot any logic errors. I think this is good to go.

@kkaefer
Copy link
Member

kkaefer commented Sep 14, 2016

Here's a suggestion for reducing the number of `SymbolBuckets that are gratuitously created, then discarded:

diff --git a/src/mbgl/tile/tile_worker.cpp b/src/mbgl/tile/tile_worker.cpp
index f079847..53f6acb 100644
--- a/src/mbgl/tile/tile_worker.cpp
+++ b/src/mbgl/tile/tile_worker.cpp
@@ -164,9 +164,9 @@ TilePlacementResult TileWorker::redoPlacement(const PlacementConfig& config) {

     for (auto& symbolLayout : symbolLayouts) {
         symbolLayout->state = SymbolLayout::Placed;
-        std::unique_ptr<Bucket> bucket = symbolLayout->place(*result.collisionTile);
-        if (bucket->hasData() || symbolLayout->hasSymbolInstances()) {
-            result.buckets.emplace(symbolLayout->bucketName, std::move(bucket));
+        if (symbolLayout->hasSymbolInstances()) {
+            result.buckets.emplace(symbolLayout->bucketName,
+                                   symbolLayout->place(*result.collisionTile));
         }
     }

@jfirebaugh
Copy link
Contributor Author

jfirebaugh commented Sep 14, 2016

Sorry for the poor diff. Here is a diff between symbol_bucket.cpp before and symbol_layout.cpp after, so you can see what changed in the moved code:

  • Updated #include lists
  • Changed constructor arguments
  • Constructor now runs the code that was parseFeatures
  • Changed some variables to camel-case
  • needsDependenciescanPrepare (and negated the sense of the return value)
  • addFeaturesprepare
  • placeFeaturesplace, and it returns a bucket
  • addToDebugBuffers gets passed SymbolBucket& rather than updating a member variable

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.
@jfirebaugh jfirebaugh merged commit a9f5224 into master Sep 14, 2016
@jfirebaugh jfirebaugh deleted the symbol-layout branch September 14, 2016 20:43
@@ -40,7 +40,8 @@ void SymbolBucket::render(Painter& painter,
}

bool SymbolBucket::hasData() const {
return hasTextData() || hasIconData();
assert(false); // Should be calling SymbolLayout::hasSymbolInstances() instead.
return false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could move hasSymbolInstances() to this function.

Copy link
Member

@kkaefer kkaefer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

@mourner
Copy link
Member

mourner commented Sep 15, 2016

@jfirebaugh nice! Does it make sense to split the two in GL JS as well?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Core The cross-platform C++ core, aka mbgl
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rename SymbolBucket::addFeatures and SymbolBucket::placeFeatures
5 participants