// A page-side census of the backdrop blurs on screen, for the glass scroll // bench (tool/perf/glass_scroll_bench.mjs): `window.__backdropCensus()` // returns `{ blurs, reads }`: the backdrop filter layers in the current scene // (offstage routes are not in it), and how many reads of the content behind // they take where the engine shares a `BackdropGroup`'s read (Impeller; the // web renderer ignores the grouping and reads once per blur). import 'dart:js_interop'; import 'package:flutter/rendering.dart'; @JS('__backdropCensus') external set _backdropCensus(JSFunction census); void installBackdropCensus() { _backdropCensus = (() { var blurs = 0; var ungrouped = 0; final keys = {}; void visit(Layer layer) { if (layer is BackdropFilterLayer) { blurs++; final key = layer.backdropKey; if (key == null) { ungrouped++; } else { keys.add(key); } } if (layer is ContainerLayer) { for ( var child = layer.firstChild; child != null; child = child.nextSibling ) { visit(child); } } } for (final view in RendererBinding.instance.renderViews) { // The scene's root layer. // ignore: invalid_use_of_protected_member final root = view.layer; if (root != null) visit(root); } return {'blurs': blurs, 'reads': ungrouped + keys.length}.jsify(); }).toJS; }