Make shader warm-up async so it can handle image (#28687)
## Description This moves another 15-20ms from the animation jank of one of our important client to the startup latency. Unfortunately, this is probably not captured in our current benchmarks (presumably some other bottlenecks overshadow this shader compilation in the worst_frame benchmark). Considering that drawing images is such a common operation, maybe we should add one in the future to benchmark this. We need this PR to land soon for our client because this changes the API to return Future. ## Related Issues https://github.com/flutter/flutter/issues/813
This commit is contained in:
@@ -9,14 +9,14 @@ import 'dart:ui' as ui;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/painting.dart' show DefaultShaderWarmUp;
|
||||
|
||||
void beginFrame(Duration timeStamp) {
|
||||
Future<void> beginFrame(Duration timeStamp) async {
|
||||
// PAINT
|
||||
final ui.PictureRecorder recorder = ui.PictureRecorder();
|
||||
final ui.Rect paintBounds = ui.Rect.fromLTRB(0, 0, 1000, 1000);
|
||||
final ui.Canvas canvas = ui.Canvas(recorder, paintBounds);
|
||||
final ui.Paint backgroundPaint = ui.Paint()..color = Colors.white;
|
||||
canvas.drawRect(paintBounds, backgroundPaint);
|
||||
const DefaultShaderWarmUp().warmUpOnCanvas(canvas);
|
||||
await const DefaultShaderWarmUp().warmUpOnCanvas(canvas);
|
||||
final ui.Picture picture = recorder.endRecording();
|
||||
|
||||
// COMPOSITE
|
||||
@@ -27,7 +27,7 @@ void beginFrame(Duration timeStamp) {
|
||||
ui.window.render(sceneBuilder.build());
|
||||
}
|
||||
|
||||
void main() {
|
||||
Future<void> main() async {
|
||||
ui.window.onBeginFrame = beginFrame;
|
||||
ui.window.scheduleFrame();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user