From 432578bfbe2431720086f37ed84aa84549534817 Mon Sep 17 00:00:00 2001 From: Aidan H Date: Tue, 2 Nov 2021 21:23:44 -0600 Subject: [PATCH 1/6] Invalidating terrain render cache on style.setFeatureState --- src/style/style.js | 1 + src/terrain/terrain.js | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/src/style/style.js b/src/style/style.js index f757ef8efa9..86c67fce5a6 100644 --- a/src/style/style.js +++ b/src/style/style.js @@ -1120,6 +1120,7 @@ class Style extends Evented { for (const sourceCache of sourceCaches) { sourceCache.setFeatureState(sourceLayer, target.id, state); } + this.fire(new Event('setfeaturestate')); } removeFeatureState(target: { source: string; sourceLayer?: string; id?: string | number; }, key?: string) { diff --git a/src/terrain/terrain.js b/src/terrain/terrain.js index 12f690566a1..a0a55422767 100644 --- a/src/terrain/terrain.js +++ b/src/terrain/terrain.js @@ -247,6 +247,7 @@ export class Terrain extends Elevation { set style(style: Style) { style.on('data', this._onStyleDataEvent.bind(this)); + style.on('setfeaturestate', this._onSetFeatureStateEvent.bind(this)); style.on('neworder', this._checkRenderCacheEfficiency.bind(this)); this._style = style; this._checkRenderCacheEfficiency(); @@ -327,6 +328,11 @@ export class Terrain extends Elevation { } } + _onSetFeatureStateEvent(event: any) { + this._invalidateRenderCache = true; + + } + // Terrain _disable() { if (!this.enabled) return; From bcf8cebc594e1df70f1d6de11ca95765418e4020 Mon Sep 17 00:00:00 2001 From: Aidan H Date: Tue, 2 Nov 2021 21:31:46 -0600 Subject: [PATCH 2/6] Trimming whitespace --- src/terrain/terrain.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/terrain/terrain.js b/src/terrain/terrain.js index a0a55422767..ae94695c965 100644 --- a/src/terrain/terrain.js +++ b/src/terrain/terrain.js @@ -330,7 +330,6 @@ export class Terrain extends Elevation { _onSetFeatureStateEvent(event: any) { this._invalidateRenderCache = true; - } // Terrain From b4cdedff6079530c811f6217c38e4e48f8232e90 Mon Sep 17 00:00:00 2001 From: Aidan H Date: Wed, 3 Nov 2021 17:06:57 -0600 Subject: [PATCH 3/6] Changed approach to directly clear render cache from Tile --- src/source/tile.js | 6 ++++++ src/style/style.js | 1 - src/terrain/terrain.js | 11 +++++------ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/source/tile.js b/src/source/tile.js index d37ee05ca06..71263384546 100644 --- a/src/source/tile.js +++ b/src/source/tile.js @@ -527,6 +527,12 @@ class Tile { if (!sourceLayer || !sourceLayerStates || Object.keys(sourceLayerStates).length === 0) continue; bucket.update(sourceLayerStates, sourceLayer, availableImages, this.imageAtlas && this.imageAtlas.patternPositions || {}); + if (painter._terrain && painter._terrain.enabled && bucket.programConfigurations && bucket.programConfigurations.needsUpload) { + const sourceCache = painter.style._getSourceCache(bucket.layers[0].source); + if (sourceCache && painter._terrain) { // Always happens, just making Flow happy + painter._terrain._clearRenderCacheForTile(sourceCache.id, this.tileID); + } + } const layer = painter && painter.style && painter.style.getLayer(id); if (layer) { this.queryPadding = Math.max(this.queryPadding, layer.queryRadius(bucket)); diff --git a/src/style/style.js b/src/style/style.js index 86c67fce5a6..f757ef8efa9 100644 --- a/src/style/style.js +++ b/src/style/style.js @@ -1120,7 +1120,6 @@ class Style extends Evented { for (const sourceCache of sourceCaches) { sourceCache.setFeatureState(sourceLayer, target.id, state); } - this.fire(new Event('setfeaturestate')); } removeFeatureState(target: { source: string; sourceLayer?: string; id?: string | number; }, key?: string) { diff --git a/src/terrain/terrain.js b/src/terrain/terrain.js index ae94695c965..09e2083f6c1 100644 --- a/src/terrain/terrain.js +++ b/src/terrain/terrain.js @@ -247,7 +247,6 @@ export class Terrain extends Elevation { set style(style: Style) { style.on('data', this._onStyleDataEvent.bind(this)); - style.on('setfeaturestate', this._onSetFeatureStateEvent.bind(this)); style.on('neworder', this._checkRenderCacheEfficiency.bind(this)); this._style = style; this._checkRenderCacheEfficiency(); @@ -328,10 +327,6 @@ export class Terrain extends Elevation { } } - _onSetFeatureStateEvent(event: any) { - this._invalidateRenderCache = true; - } - // Terrain _disable() { if (!this.enabled) return; @@ -987,7 +982,11 @@ export class Terrain extends Elevation { const tiles = current[source]; const prevTiles = prev[source]; if (!prevTiles || prevTiles.length !== tiles.length || - tiles.some((t, index) => (t !== prevTiles[index] || (dirty[source] && dirty[source].hasOwnProperty(t.key))))) { + tiles.some((t, index) => + (t !== prevTiles[index] || + (dirty[source] && dirty[source].hasOwnProperty(t.key) + ))) + ) { equal = -1; break; } From a47ab0661dbd52028e235fdbee05a799eea10e70 Mon Sep 17 00:00:00 2001 From: Aidan H Date: Wed, 3 Nov 2021 17:20:59 -0600 Subject: [PATCH 4/6] Fix flow errors --- src/source/tile.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/source/tile.js b/src/source/tile.js index 71263384546..b3bd31cd805 100644 --- a/src/source/tile.js +++ b/src/source/tile.js @@ -29,6 +29,10 @@ import SegmentVector from '../data/segment.js'; const CLOCK_SKEW_RETRY_TIMEOUT = 30000; import type {Bucket} from '../data/bucket.js'; +import CircleBucket from '../data/bucket/circle_bucket.js'; +import FillBucket from '../data/bucket/fill_bucket.js'; +import FillExtrusionBucket from '../data/bucket/fill_extrusion_bucket.js'; +import LineBucket from '../data/bucket/line_bucket.js'; import type StyleLayer from '../style/style_layer.js'; import type {WorkerTileResult} from './worker_source.js'; import type Actor from '../util/actor.js'; @@ -527,9 +531,15 @@ class Tile { if (!sourceLayer || !sourceLayerStates || Object.keys(sourceLayerStates).length === 0) continue; bucket.update(sourceLayerStates, sourceLayer, availableImages, this.imageAtlas && this.imageAtlas.patternPositions || {}); - if (painter._terrain && painter._terrain.enabled && bucket.programConfigurations && bucket.programConfigurations.needsUpload) { + if (painter._terrain && painter._terrain.enabled && + (bucket instanceof LineBucket || + bucket instanceof FillBucket || + bucket instanceof FillExtrusionBucket || + bucket instanceof CircleBucket) + // Symbol bucket has no programConfigurations. This has to be spelled out for Flow. + ) { const sourceCache = painter.style._getSourceCache(bucket.layers[0].source); - if (sourceCache && painter._terrain) { // Always happens, just making Flow happy + if (sourceCache && painter._terrain && bucket.programConfigurations.needsUpload) { painter._terrain._clearRenderCacheForTile(sourceCache.id, this.tileID); } } From 1e1c07793ee5c3d850e6eef83fd31688b39bd997 Mon Sep 17 00:00:00 2001 From: Aidan H Date: Thu, 4 Nov 2021 10:07:14 -0600 Subject: [PATCH 5/6] Removing double check for terrain --- src/source/source_state.js | 1 - src/source/tile.js | 10 ++-------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/source/source_state.js b/src/source/source_state.js index ceb78178b7e..be69889419d 100644 --- a/src/source/source_state.js +++ b/src/source/source_state.js @@ -80,7 +80,6 @@ class SourceFeatureState { } else { this.deletedStates[sourceLayer] = null; } - } getState(sourceLayer: string, featureId: number | string) { diff --git a/src/source/tile.js b/src/source/tile.js index b3bd31cd805..3a8f1018eee 100644 --- a/src/source/tile.js +++ b/src/source/tile.js @@ -531,15 +531,9 @@ class Tile { if (!sourceLayer || !sourceLayerStates || Object.keys(sourceLayerStates).length === 0) continue; bucket.update(sourceLayerStates, sourceLayer, availableImages, this.imageAtlas && this.imageAtlas.patternPositions || {}); - if (painter._terrain && painter._terrain.enabled && - (bucket instanceof LineBucket || - bucket instanceof FillBucket || - bucket instanceof FillExtrusionBucket || - bucket instanceof CircleBucket) - // Symbol bucket has no programConfigurations. This has to be spelled out for Flow. - ) { + if (bucket instanceof LineBucket || bucket instanceof FillBucket || bucket instanceof FillExtrusionBucket || bucket instanceof CircleBucket) { const sourceCache = painter.style._getSourceCache(bucket.layers[0].source); - if (sourceCache && painter._terrain && bucket.programConfigurations.needsUpload) { + if (painter._terrain && painter._terrain.enabled && sourceCache && bucket.programConfigurations.needsUpload) { painter._terrain._clearRenderCacheForTile(sourceCache.id, this.tileID); } } From 295cb5c430e9c78ec0a8d8743613db8961a26a00 Mon Sep 17 00:00:00 2001 From: Aidan H Date: Thu, 4 Nov 2021 11:21:24 -0600 Subject: [PATCH 6/6] Only on LineBucket and FillBucket --- src/source/tile.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/source/tile.js b/src/source/tile.js index 3a8f1018eee..f3444baaf1b 100644 --- a/src/source/tile.js +++ b/src/source/tile.js @@ -29,9 +29,7 @@ import SegmentVector from '../data/segment.js'; const CLOCK_SKEW_RETRY_TIMEOUT = 30000; import type {Bucket} from '../data/bucket.js'; -import CircleBucket from '../data/bucket/circle_bucket.js'; import FillBucket from '../data/bucket/fill_bucket.js'; -import FillExtrusionBucket from '../data/bucket/fill_extrusion_bucket.js'; import LineBucket from '../data/bucket/line_bucket.js'; import type StyleLayer from '../style/style_layer.js'; import type {WorkerTileResult} from './worker_source.js'; @@ -531,7 +529,7 @@ class Tile { if (!sourceLayer || !sourceLayerStates || Object.keys(sourceLayerStates).length === 0) continue; bucket.update(sourceLayerStates, sourceLayer, availableImages, this.imageAtlas && this.imageAtlas.patternPositions || {}); - if (bucket instanceof LineBucket || bucket instanceof FillBucket || bucket instanceof FillExtrusionBucket || bucket instanceof CircleBucket) { + if (bucket instanceof LineBucket || bucket instanceof FillBucket) { const sourceCache = painter.style._getSourceCache(bucket.layers[0].source); if (painter._terrain && painter._terrain.enabled && sourceCache && bucket.programConfigurations.needsUpload) { painter._terrain._clearRenderCacheForTile(sourceCache.id, this.tileID);