Unverified Commit da8b340c authored by liyuqian's avatar liyuqian Committed by GitHub

Quick fix for shader warm up (#28951)

Fix issues in https://github.com/flutter/flutter/pull/28687
parent 440ce8fd
...@@ -67,8 +67,6 @@ abstract class ShaderWarmUp { ...@@ -67,8 +67,6 @@ abstract class ShaderWarmUp {
/// Trigger draw operations on a given canvas to warm up GPU shader /// Trigger draw operations on a given canvas to warm up GPU shader
/// compilation cache. /// compilation cache.
/// ///
/// Parameter [image] is to be used for drawImage related operations.
///
/// To decide which draw operations to be added to your custom warm up /// To decide which draw operations to be added to your custom warm up
/// process, try capture an skp using `flutter screenshot --observatory- /// process, try capture an skp using `flutter screenshot --observatory-
/// port=<port> --type=skia` and analyze it with https://debugger.skia.org. /// port=<port> --type=skia` and analyze it with https://debugger.skia.org.
...@@ -90,7 +88,7 @@ abstract class ShaderWarmUp { ...@@ -90,7 +88,7 @@ abstract class ShaderWarmUp {
final ui.Picture picture = recorder.endRecording(); final ui.Picture picture = recorder.endRecording();
final TimelineTask shaderWarmUpTask = TimelineTask(); final TimelineTask shaderWarmUpTask = TimelineTask();
shaderWarmUpTask.start('Warm-up shader'); shaderWarmUpTask.start('Warm-up shader');
picture.toImage(size.width.ceil(), size.height.ceil()).then((ui.Image _) { picture.toImage(size.width.ceil(), size.height.ceil()).then((ui.Image image) {
shaderWarmUpTask.finish(); shaderWarmUpTask.finish();
}); });
} }
...@@ -184,10 +182,9 @@ class DefaultShaderWarmUp extends ShaderWarmUp { ...@@ -184,10 +182,9 @@ class DefaultShaderWarmUp extends ShaderWarmUp {
..layout(const ui.ParagraphConstraints(width: 60.0)); ..layout(const ui.ParagraphConstraints(width: 60.0));
canvas.drawParagraph(paragraph, const ui.Offset(20.0, 20.0)); canvas.drawParagraph(paragraph, const ui.Offset(20.0, 20.0));
// Construct an image for drawImage related operations // Construct an image for drawImage related operations
const int imageWidth = 40; const int imageWidth = 10;
const int imageHeight = 40; const int imageHeight = 10;
final Uint8List pixels = Uint8List.fromList(List<int>.generate( final Uint8List pixels = Uint8List.fromList(List<int>.generate(
imageWidth * imageHeight * 4, imageWidth * imageHeight * 4,
(int i) => i % 4 < 2 ? 0x00 : 0xFF, // opaque blue (int i) => i % 4 < 2 ? 0x00 : 0xFF, // opaque blue
...@@ -201,9 +198,9 @@ class DefaultShaderWarmUp extends ShaderWarmUp { ...@@ -201,9 +198,9 @@ class DefaultShaderWarmUp extends ShaderWarmUp {
final ui.Rect srcRect = ui.Rect.fromLTWH(0.0, 0.0, image.width.toDouble(), image.height.toDouble()); final ui.Rect srcRect = ui.Rect.fromLTWH(0.0, 0.0, image.width.toDouble(), image.height.toDouble());
canvas.drawImage(image, const ui.Offset(20.0, 20.0), ui.Paint()); canvas.drawImage(image, const ui.Offset(20.0, 20.0), ui.Paint());
canvas.translate(80.0, 0.0); canvas.translate(80.0, 0.0);
canvas.drawImageRect(image, srcRect, ui.Rect.fromLTWH(20.0, 20.0, 20.0, 20.0), paints[0]); canvas.drawImageRect(image, srcRect, ui.Rect.fromLTWH(20.0, 20.0, imageWidth * 0.6, imageWidth * 0.6), paints[0]);
canvas.translate(80.0, 0.0); canvas.translate(80.0, 0.0);
canvas.drawImageRect(image, srcRect, ui.Rect.fromLTWH(10.0, 10.0, 60.0, 60.0), paints[0]); canvas.drawImageRect(image, srcRect, ui.Rect.fromLTWH(10.0, 10.0, imageWidth * 1.5, imageWidth * 1.5), paints[0]);
canvas.restore(); canvas.restore();
completer.complete(); completer.complete();
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment