screenshotLayerBounds function

Rect screenshotLayerBounds({
  1. required Size physicalSize,
  2. required Rect paintBounds,
})

Layer-local rectangle to pass to OffsetLayer.toImageSync for a RenderView.

RenderView.paintBounds is already size × devicePixelRatio. The root TransformLayer applies DPR when compositing, so this must be captured at screenshotLayerPixelRatio (1.0). Passing the view DPR again zooms into the top-left of the screen and clips the right/bottom of the UI.

Implementation

Rect screenshotLayerBounds({
  required Size physicalSize,
  required Rect paintBounds,
}) {
  if (paintBounds.isFinite && !paintBounds.isEmpty) {
    return paintBounds;
  }
  if (physicalSize.isFinite && !physicalSize.isEmpty) {
    return Offset.zero & physicalSize;
  }
  return Rect.zero;
}