summaryrefslogtreecommitdiff
path: root/src/mbgl/algorithm
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-06-06 11:26:52 +0300
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-06-10 19:36:47 +0300
commit737665bc070e9db4544b5d78ca69baf72ec958dc (patch)
treeb16f5e0c771765362ade518e4b440d4b8fabc322 /src/mbgl/algorithm
parentf5631d8ef5a1307e50975ab2f767dd7ee544f466 (diff)
downloadqtlocation-mapboxgl-737665bc070e9db4544b5d78ca69baf72ec958dc.tar.gz
[core] Refactor tile pyramid
Tile pyramid is no longer operating with `RenderTiles` and does not perform rendering operations (upload, finish render). Render tiles belong to rendering, and tile pyramid belongs to orchestration.
Diffstat (limited to 'src/mbgl/algorithm')
-rw-r--r--src/mbgl/algorithm/update_tile_masks.hpp70
1 files changed, 38 insertions, 32 deletions
diff --git a/src/mbgl/algorithm/update_tile_masks.hpp b/src/mbgl/algorithm/update_tile_masks.hpp
index c475473cb6..80e0a39be1 100644
--- a/src/mbgl/algorithm/update_tile_masks.hpp
+++ b/src/mbgl/algorithm/update_tile_masks.hpp
@@ -11,26 +11,38 @@ namespace algorithm {
namespace {
-template <typename Renderable>
+template <typename T>
+bool tileNeedsMask(const std::reference_wrapper<T>& tile) { return tile.get().usedByRenderedLayers; }
+template <typename T>
+void setTileMask(const std::reference_wrapper<T>& tile, TileMask&& mask ) { return tile.get().setMask(std::move(mask)); }
+
+// Overloads for tests
+template <typename T> bool tileNeedsMask(const T& tile) { return tile.usedByRenderedLayers; }
+template <typename T> void setTileMask(T& tile, TileMask&& mask ) { return tile.setMask(std::move(mask)); }
+
+template <typename Iterator>
void computeTileMasks(
const CanonicalTileID& root,
- const UnwrappedTileID ref,
- typename std::vector<std::reference_wrapper<Renderable>>::const_iterator it,
- const typename std::vector<std::reference_wrapper<Renderable>>::const_iterator end,
+ const UnwrappedTileID& ref,
+ const Iterator begin,
+ const Iterator end,
TileMask& mask) {
// If the reference or any of its children is found in the list, we need to recurse.
- for (; it != end; ++it) {
- auto& renderable = it->get();
- if (!renderable.used) {
+ for (auto it = begin; it != end; ++it) {
+ const UnwrappedTileID& id = it->first;
+ if (!tileNeedsMask(it->second)) {
continue;
}
- if (ref == renderable.id) {
+
+ if (ref == id) {
// The current tile is masked out, so we don't need to add them to the mask set.
return;
- } else if (renderable.id.isChildOf(ref)) {
+ }
+
+ if (id.isChildOf(ref)) {
// There's at least one child tile that is masked out, so recursively descend.
for (const auto& child : ref.children()) {
- computeTileMasks<Renderable>(root, child, it, end, mask);
+ computeTileMasks(root, child, it, end, mask);
}
return;
}
@@ -45,10 +57,10 @@ void computeTileMasks(
} // namespace
-// Updates the TileMasks for all renderables. Renderables are objects that have an UnwrappedTileID
-// property indicating where they should be rendered on the screen. A TileMask describes all regions
-// within that tile that are *not* covered by other Renderables.
-// Example: Renderables in our list are 2/1/3, 3/3/6, and 4/5/13. The schematic for creating the
+// Updates the TileMasks for all renderable tiles. Each renderable tile has a corresponding UnwrappedTileID
+// indicating where it should be rendered on the screen. A TileMask describes all regions
+// within a renderable tile that are *not* covered by other renderable tiles.
+// Example: Renderable tiles in our list are 2/1/3, 3/3/6, and 4/5/13. The schematic for creating the
// TileMask for 2/1/3 looks like this:
//
// ┌────────┬────────┬─────────────────┐
@@ -70,7 +82,7 @@ void computeTileMasks(
// └─────────────────┴─────────────────┘
//
// The TileMask for 2/1/3 thus consists of the tiles 4/4/12, 4/5/12, 4/4/13, 3/2/7, and 3/3/7,
-// but it does *not* include 4/5/13, and 3/3/6, since these are other Renderables.
+// but it does *not* include 4/5/13, and 3/3/6, since these are other renderable tiles.
// A TileMask always contains TileIDs *relative* to the tile it is generated for, so 2/1/3 is
// "subtracted" from these TileIDs. The final TileMask for 2/1/3 will thus be:
//
@@ -92,21 +104,16 @@ void computeTileMasks(
// │ │ │
// └─────────────────┴─────────────────┘
//
-// Only other Renderables that are *children* of the Renderable we are generating the mask for will
-// be considered. For example, adding a Renderable with TileID 4/8/13 won't affect the TileMask for
+// Only other renderable tiles that are *children* of the renderable tile we are generating the mask for will
+// will be considered. For example, adding a renderable tile with TileID 4/8/13 won't affect the TileMask for
// 2/1/3, since it is not a descendant of it.
-//
-// The given |renderables| must be sorted by id.
-template <typename Renderable>
-void updateTileMasks(std::vector<std::reference_wrapper<Renderable>> renderables) {
- assert(std::is_sorted(renderables.begin(), renderables.end(),
- [](const Renderable& a, const Renderable& b) { return a.id < b.id; }));
-
+template <typename RenderableTilesMap>
+void updateTileMasks(RenderableTilesMap& renderables) {
TileMask mask;
const auto end = renderables.end();
- for (auto it = renderables.begin(); it != end; it++) {
- auto& renderable = it->get();
- if (!renderable.used) {
+ for (auto it = renderables.begin(); it != end; ++it) {
+ const UnwrappedTileID& id = it->first;
+ if (!tileNeedsMask(it->second)) {
continue;
}
// Try to add all remaining ids as children. We sorted the tile list
@@ -116,13 +123,12 @@ void updateTileMasks(std::vector<std::reference_wrapper<Renderable>> renderables
auto child_it = std::next(it);
const auto children_end = std::lower_bound(
child_it, end,
- UnwrappedTileID{ static_cast<int16_t>(renderable.id.wrap + 1), { 0, 0, 0 } },
- [](auto& a, auto& b) { return a.get().id < b; });
+ UnwrappedTileID{ static_cast<int16_t>(id.wrap + 1), { 0, 0, 0 } },
+ [](auto& a, auto& b) { return a.first < b; });
mask.clear();
- computeTileMasks<Renderable>(renderable.id.canonical, renderable.id, child_it, children_end,
- mask);
- renderable.setMask(std::move(mask));
+ computeTileMasks(id.canonical, id, child_it, children_end, mask);
+ setTileMask(it->second, std::move(mask));
}
}