collectReplayMaskRects static method

List<Map<String, int>> collectReplayMaskRects(
  1. double pixRatio, {
  2. Set<String> types = const {},
})

Pixel rects of every auto-masked widget plus every PlotlineSensitive, for session replay masking.

Implementation

static List<Map<String, int>> collectReplayMaskRects(double pixRatio, {Set<String> types = const {}}) {
  final rects = <Map<String, int>>[];
  void add(BuildContext c) {
    final box = c.findRenderObject();
    if (box is! RenderBox || !box.attached || !box.hasSize) return;
    final r = box.localToGlobal(Offset.zero) & box.size;
    rects.add({
      "x": (r.left * pixRatio).round(),
      "y": (r.top * pixRatio).round(),
      "w": (r.width * pixRatio).round(),
      "h": (r.height * pixRatio).round(),
    });
  }
  void walk(Element e) {
    if (_isAutoMasked(e.widget, types)) { add(e); return; }
    e.visitChildren(walk);
  }
  // ponytail: full tree walk once per capture; cache per frame if a huge tree ever shows up in profiles
  if (types.isNotEmpty) WidgetsBinding.instance.rootElement?.visitChildren(walk);
  PlotlineSensitive.contexts.forEach(add);
  return rects;
}