Read pixels and release unused caches through the Cesium renderer

The shared Cesium ports gain readPixels and releaseUnused, on both the
conformance renderer and the application's.

readPixels reads the drawn frame off the canvas at once, cropped in CSS
pixels and scaled from the canvas's CSS size, through one reused 2D canvas.
A canvas with no size reads blank.

releaseUnused trims every 3D tileset's cache, and after the next drawn frame
frees the globe tiles that frame did not draw. Cesium trims the globe's
cache only while tiles load, so a settled view would otherwise free nothing;
the trim goes through internals.js. The reader canvas is dropped too.

Two new checks, renderer.readPixels and renderer.releaseUnused, run on
Cesium and the stub.
This commit is contained in:
Sameh Khamis committed 2026-11-06 17:42:13 -08:00
1 parent 035276aa32
commit b9daac73c6
9 files changed
+184 -7

No files matched your search

+35
View File
@@ -770,3 +770,38 @@ test('whenSettled settles once shown tiles have loaded under a hidden globe', as
ports.dispose();
}
});
test('releaseUnused trims the tiles caches, the globe after the next drawn frame', () => {
const { widget, scene, raise } = tickingWidget();
const list = [];
scene.primitives = listedPrimitives(list);
const trimmed = [];
scene.globe = {
show: true,
_surface: {
_tileReplacementQueue: { trimTiles: (n) => trimmed.push(`globe ${n}`) },
},
};
const tileset = Object.create(Cesium.Cesium3DTileset.prototype);
tileset.trimLoadedTiles = () => trimmed.push('tileset');
list.push(tileset);
const ports = createCesiumPorts(widget, { capabilities: all });
ports.releaseUnused();
ports.releaseUnused();
assert.deepEqual(trimmed, ['tileset', 'tileset'], 'the globe waits');
assert.ok(ports.frame.diagnostics().pendingReasons.includes('releaseUnused'));
raise('postRender');
raise('postRender');
assert.deepEqual(trimmed, ['tileset', 'tileset', 'globe 0'], 'once');
scene.globe.show = false;
ports.releaseUnused();
raise('postRender');
assert.equal(trimmed.at(-1), 'tileset', 'a hidden globe is left alone');
scene.globe.show = true;
ports.releaseUnused();
ports.dispose();
raise('postRender');
assert.equal(trimmed.at(-1), 'tileset', 'nothing once disposed');
ports.releaseUnused();
assert.equal(trimmed.length, 5, 'nor a release after');
});