shader warm up with canvaskit and corresponding test (#113060)
diff --git a/packages/flutter/lib/src/foundation/constants.dart b/packages/flutter/lib/src/foundation/constants.dart
index 576de1e..0e5ccb6 100644
--- a/packages/flutter/lib/src/foundation/constants.dart
+++ b/packages/flutter/lib/src/foundation/constants.dart
@@ -69,3 +69,6 @@
/// A constant that is true if the application was compiled to run on the web.
const bool kIsWeb = bool.fromEnvironment('dart.library.js_util');
+
+/// A constant that is true if the application is using canvasKit
+const bool isCanvasKit = bool.fromEnvironment('FLUTTER_WEB_USE_SKIA');
diff --git a/packages/flutter/lib/src/painting/shader_warm_up.dart b/packages/flutter/lib/src/painting/shader_warm_up.dart
index 890a375..6a28c25 100644
--- a/packages/flutter/lib/src/painting/shader_warm_up.dart
+++ b/packages/flutter/lib/src/painting/shader_warm_up.dart
@@ -87,7 +87,7 @@
await warmUpOnCanvas(canvas);
final ui.Picture picture = recorder.endRecording();
assert(debugCaptureShaderWarmUpPicture(picture));
- if (!kIsWeb) { // Picture.toImage is not yet implemented on the web.
+ if (!kIsWeb || isCanvasKit) { // Picture.toImage is not yet implemented on the web.
final TimelineTask shaderWarmUpTask = TimelineTask();
shaderWarmUpTask.start('Warm-up shader');
try {
diff --git a/packages/flutter/test/painting/shader_warm_up_test.dart b/packages/flutter/test/painting/shader_warm_up_test.dart
new file mode 100644
index 0000000..8028dd0
--- /dev/null
+++ b/packages/flutter/test/painting/shader_warm_up_test.dart
@@ -0,0 +1,29 @@
+// Copyright 2014 The Flutter Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+import 'dart:ui' as ui;
+
+import 'package:flutter/foundation.dart';
+import 'package:flutter/widgets.dart';
+import 'package:flutter_test/flutter_test.dart';
+
+Future<void> main() async {
+ test('ShaderWarmUp', () {
+ final FakeShaderWarmUp shaderWarmUp = FakeShaderWarmUp();
+ PaintingBinding.shaderWarmUp = shaderWarmUp;
+ debugCaptureShaderWarmUpImage = expectAsync1((ui.Image image) => true);
+ WidgetsFlutterBinding.ensureInitialized();
+ expect(shaderWarmUp.ranWarmUp, true);
+ }, skip: kIsWeb && !isCanvasKit); // [intended] Testing only for canvasKit
+}
+
+class FakeShaderWarmUp extends ShaderWarmUp {
+ bool ranWarmUp = false;
+
+ @override
+ Future<bool> warmUpOnCanvas(ui.Canvas canvas) {
+ ranWarmUp = true;
+ return Future<bool>.delayed(Duration.zero, () => true);
+ }
+}