Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a pixel test to cover multiple clips with a BDF #51431

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions testing/dart/painting_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import 'dart:ui';

import 'package:litetest/litetest.dart';

typedef CanvasCallback = void Function(Canvas canvas);

void main() {
test('Vertices checks', () {
try {
Expand Down Expand Up @@ -60,4 +62,45 @@ void main() {
indices: Uint16List.fromList(const <int>[0, 2, 1, 2, 0, 1, 2, 0]),
).dispose();
});

test('BackdropFilter with multiple clips', () async {
// Regression test for https://github.com/flutter/flutter/issues/144211
Picture makePicture(CanvasCallback callback) {
final PictureRecorder recorder = PictureRecorder();
final Canvas canvas = Canvas(recorder);
callback(canvas);
return recorder.endRecording();
}
final SceneBuilder sceneBuilder = SceneBuilder();

final Picture redClippedPicture = makePicture((Canvas canvas) {
canvas.clipRect(const Rect.fromLTRB(10, 10, 200, 200));
canvas.clipRect(const Rect.fromLTRB(11, 10, 300, 200));
canvas.drawPaint(Paint()..color = const Color(0xFFFF0000));
});
sceneBuilder.addPicture(Offset.zero, redClippedPicture);

final Float64List matrix = Float64List(16);
sceneBuilder.pushBackdropFilter(ImageFilter.matrix(matrix));

final Picture whitePicture = makePicture((Canvas canvas) {
canvas.drawPaint(Paint()..color = const Color(0xFFFFFFFF));
});
sceneBuilder.addPicture(Offset.zero, whitePicture);

final Scene scene = sceneBuilder.build();
final Image image = scene.toImageSync(20, 20);

final ByteData data = (await image.toByteData())!;
expect(data.buffer.asUint32List().length, 20 * 20);
// If clipping went wrong as in the linked issue, there will be red pixels.
for (final int color in data.buffer.asUint32List()) {
expect(color, 0xFFFFFFFF);
}

scene.dispose();
image.dispose();
whitePicture.dispose();
redClippedPicture.dispose();
});
}