execute method

Future<void> execute()

Construct an offscreen image of size, and execute warmUpOnCanvas on a canvas associated with that image.

Currently, this has no effect when kIsWeb is true.

Implementation

Future<void> execute() async {
  final ui.PictureRecorder recorder = ui.PictureRecorder();
  final ui.Canvas canvas = ui.Canvas(recorder);
  await warmUpOnCanvas(canvas);
  final ui.Picture picture = recorder.endRecording();
  assert(debugCaptureShaderWarmUpPicture(picture));
  if (!kIsWeb || isSkiaWeb) { // Picture.toImage is not implemented on the html renderer.
    TimelineTask? debugShaderWarmUpTask;
    if (!kReleaseMode) {
      debugShaderWarmUpTask = TimelineTask()..start('Warm-up shader');
    }
    try {
      final ui.Image image = await picture.toImage(size.width.ceil(), size.height.ceil());
      assert(debugCaptureShaderWarmUpImage(image));
      image.dispose();
    } finally {
      if (!kReleaseMode) {
        debugShaderWarmUpTask!.finish();
      }
    }
  }
  picture.dispose();
}