Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 5487eff

Browse files
authored
Add a pixel test to cover multiple clips with a BDF (#51431)
Same test as in #51416. This test should pass without the revert here because the StC related changes make the optimized path work again.
1 parent 95e6c17 commit 5487eff

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

testing/dart/painting_test.dart

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import 'dart:ui';
77

88
import 'package:litetest/litetest.dart';
99

10+
typedef CanvasCallback = void Function(Canvas canvas);
11+
1012
void main() {
1113
test('Vertices checks', () {
1214
try {
@@ -60,4 +62,45 @@ void main() {
6062
indices: Uint16List.fromList(const <int>[0, 2, 1, 2, 0, 1, 2, 0]),
6163
).dispose();
6264
});
65+
66+
test('BackdropFilter with multiple clips', () async {
67+
// Regression test for https://github.com/flutter/flutter/issues/144211
68+
Picture makePicture(CanvasCallback callback) {
69+
final PictureRecorder recorder = PictureRecorder();
70+
final Canvas canvas = Canvas(recorder);
71+
callback(canvas);
72+
return recorder.endRecording();
73+
}
74+
final SceneBuilder sceneBuilder = SceneBuilder();
75+
76+
final Picture redClippedPicture = makePicture((Canvas canvas) {
77+
canvas.clipRect(const Rect.fromLTRB(10, 10, 200, 200));
78+
canvas.clipRect(const Rect.fromLTRB(11, 10, 300, 200));
79+
canvas.drawPaint(Paint()..color = const Color(0xFFFF0000));
80+
});
81+
sceneBuilder.addPicture(Offset.zero, redClippedPicture);
82+
83+
final Float64List matrix = Float64List(16);
84+
sceneBuilder.pushBackdropFilter(ImageFilter.matrix(matrix));
85+
86+
final Picture whitePicture = makePicture((Canvas canvas) {
87+
canvas.drawPaint(Paint()..color = const Color(0xFFFFFFFF));
88+
});
89+
sceneBuilder.addPicture(Offset.zero, whitePicture);
90+
91+
final Scene scene = sceneBuilder.build();
92+
final Image image = scene.toImageSync(20, 20);
93+
94+
final ByteData data = (await image.toByteData())!;
95+
expect(data.buffer.asUint32List().length, 20 * 20);
96+
// If clipping went wrong as in the linked issue, there will be red pixels.
97+
for (final int color in data.buffer.asUint32List()) {
98+
expect(color, 0xFFFFFFFF);
99+
}
100+
101+
scene.dispose();
102+
image.dispose();
103+
whitePicture.dispose();
104+
redClippedPicture.dispose();
105+
});
63106
}

0 commit comments

Comments
 (0)