present method

  1. @override
Widget present(
  1. TextureHandle frame, {
  2. BoxFit fit = BoxFit.fill,
  3. FilterQuality quality = FilterQuality.none,
})

The canvas, in the widget tree, with frame copied into it.

A copy rather than a render, because getCurrentTexture is valid only for the task it was asked in and cannot be held across an await. The engine's target already exists and the copy is one command on an encoder submitted immediately — the same one GPU copy the WebGL2 backend's presenting blit is, arrived at from the other side.

fit and quality are honoured through CSS on the element rather than by Flutter, since Flutter does not composite these pixels.

Implementation

@override
Widget present(
  TextureHandle frame, {
  BoxFit fit = BoxFit.fill,
  FilterQuality quality = FilterQuality.none,
}) {
  _copyToCanvas(frame);
  _canvas.style
    ..width = '100%'
    ..height = '100%'
    // A display surface, not a control. Left interactive, the canvas takes
    // the pointer events over it and the Flutter widgets above the platform
    // view never see them — which reads as an application whose camera does
    // not turn while its keyboard works fine.
    ..pointerEvents = 'none'
    ..objectFit = switch (fit) {
      BoxFit.contain => 'contain',
      BoxFit.cover => 'cover',
      BoxFit.fill => 'fill',
      BoxFit.fitWidth ||
      BoxFit.fitHeight ||
      BoxFit.none ||
      BoxFit.scaleDown => 'contain',
    }
    ..imageRendering = quality == FilterQuality.none ? 'pixelated' : 'auto';
  return HtmlElementView(viewType: viewType);
}