diff --git a/src/mbgl/renderer/layers/render_heatmap_layer.cpp b/src/mbgl/renderer/layers/render_heatmap_layer.cpp
index 17d18e0e6..280f9151b 100644
--- a/src/mbgl/renderer/layers/render_heatmap_layer.cpp
+++ b/src/mbgl/renderer/layers/render_heatmap_layer.cpp
@@ -253,29 +253,10 @@ void RenderHeatmapLayer::update(gfx::ShaderRegistry& shaders,
}
return true;
};
-#if MLN_RENDER_BACKEND_WEBGPU
- bool anyUpdated = false;
- bool skippedDrawables = false;
- tileLayerGroup->visitDrawables(renderPass, tileID, [&](gfx::Drawable& drawable) {
- if (updateExisting(drawable)) {
- anyUpdated = true;
- } else {
- skippedDrawables = true;
- }
- });
- if (!anyUpdated && skippedDrawables) {
- removeTile(renderPass, tileID);
- }
-
- if (anyUpdated) {
+ if (updateTile(tileLayerGroup, renderPass, tileID, std::move(updateExisting))) {
continue;
}
-#else
- if (updateTile(renderPass, tileID, std::move(updateExisting))) {
- continue;
- }
-#endif
if (!propertiesAsUniforms) {
propertiesAsUniforms.emplace();
diff --git a/src/mbgl/renderer/render_layer.hpp b/src/mbgl/renderer/render_layer.hpp
index 418f19a67..181f8cc30 100644
--- a/src/mbgl/renderer/render_layer.hpp
+++ b/src/mbgl/renderer/render_layer.hpp
@@ -208,6 +208,39 @@ protected:
/// Change the layer index on a layer group associated with this layer
void changeLayerIndex(const LayerGroupBasePtr&, int32_t newLayerIndex, UniqueChangeRequestVec&);
+ /// Update the drawables for a tile.
+ /// @param tileGroup The tile layer group to consider
+ /// @param renderPass The pass to consider
+ /// @param tileID The tile to consider
+ /// @param updateFunction A function that updates a single drawable. Should return true if the drawable
+ /// was updated or false if it was skipped because it's for a previous style.
+ /// @return true if drawables were updated
+ template
+ bool updateTile(TileLayerGroup* tileGroup, RenderPass renderPass, const OverscaledTileID& tileID, Func update) {
+ if (!tileGroup) {
+ return false;
+ }
+
+ bool anyUpdated = false;
+ bool unUpdatedDrawables = false;
+ tileGroup->visitDrawables(renderPass, tileID, [&](gfx::Drawable& drawable) {
+ if (update(drawable)) {
+ anyUpdated = true;
+ } else {
+ unUpdatedDrawables = true;
+ }
+ });
+
+ // If any are updated, the caller shouldn't add new ones.
+ // If none are updated and some were skipped, remove those.
+ // This is to handle the case that the style layer changes but the bucket is not re-created.
+ if (!anyUpdated && unUpdatedDrawables) {
+ removeTile(renderPass, tileID);
+ }
+
+ return anyUpdated;
+ }
+
/// Update the drawables for a tile.
/// @param renderPass The pass to consider
/// @param tileID The tile to consider
@@ -216,25 +249,13 @@ protected:
/// @return true if drawables were updated
template
bool updateTile(RenderPass renderPass, const OverscaledTileID& tileID, Func update) {
- bool anyUpdated = false;
- if (const auto tileGroup = static_cast(layerGroup.get())) {
- bool unUpdatedDrawables = false;
- tileGroup->visitDrawables(renderPass, tileID, [&](gfx::Drawable& drawable) {
- if (update(drawable)) {
- anyUpdated = true;
- } else {
- unUpdatedDrawables = true;
- }
- });
-
- // If any are updated, the caller shouldn't add new ones.
- // If none are updated and some were skipped, remove those.
- // This is to handle the case that the style layer changes but the bucket is not re-created.
- if (!anyUpdated && unUpdatedDrawables) {
- removeTile(renderPass, tileID);
- }
+ if (!layerGroup) {
+ return false;
}
- return anyUpdated;
+
+ assert(layerGroup->getType() == LayerGroupBase::Type::TileLayerGroup);
+ const auto tileGroup = static_cast(layerGroup.get());
+ return updateTile(tileGroup, renderPass, tileID, update);
}
/// Remove all drawables for the tile from the layer group