Unverified Commit 6ba2f526 authored by Jim Graham's avatar Jim Graham Committed by GitHub

Fix alignment of matrix for Transform+filterQuality when offset (#95432)

parent 57196a9e
......@@ -2398,8 +2398,10 @@ class RenderTransform extends RenderProxyBox {
layer = null;
}
} else {
final Matrix4 effectiveTransform = Matrix4.translationValues(offset.dx, offset.dy, 0.0)
..multiply(transform)..translate(-offset.dx, -offset.dy);
final ui.ImageFilter filter = ui.ImageFilter.matrix(
transform.storage,
effectiveTransform.storage,
filterQuality: filterQuality!,
);
if (layer is ImageFilterLayer) {
......
......@@ -393,6 +393,11 @@ void main() {
skip: isBrowser, // due to https://github.com/flutter/flutter/issues/49857
);
List<double> extractMatrix(ui.ImageFilter? filter) {
final List<String> numbers = filter.toString().split('[').last.split(']').first.split(',');
return numbers.map<double>((String str) => double.parse(str.trim())).toList();
}
testWidgets('Transform.translate with FilterQuality produces filter layer', (WidgetTester tester) async {
await tester.pumpWidget(
Transform.translate(
......@@ -402,6 +407,13 @@ void main() {
),
);
expect(tester.layers.whereType<ImageFilterLayer>().length, 1);
final ImageFilterLayer layer = tester.layers.whereType<ImageFilterLayer>().first;
expect(extractMatrix(layer.imageFilter), <double>[
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
25.0, 25.0, 0.0, 1.0]
);
});
testWidgets('Transform.scale with FilterQuality produces filter layer', (WidgetTester tester) async {
......@@ -413,6 +425,13 @@ void main() {
),
);
expect(tester.layers.whereType<ImageFilterLayer>().length, 1);
final ImageFilterLayer layer = tester.layers.whereType<ImageFilterLayer>().first;
expect(extractMatrix(layer.imageFilter), <double>[
3.14159, 0.0, 0.0, 0.0,
0.0, 3.14159, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
-856.636, -642.477, 0.0, 1.0]
);
});
testWidgets('Transform.rotate with FilterQuality produces filter layer', (WidgetTester tester) async {
......@@ -424,6 +443,35 @@ void main() {
),
);
expect(tester.layers.whereType<ImageFilterLayer>().length, 1);
final ImageFilterLayer layer = tester.layers.whereType<ImageFilterLayer>().first;
expect(extractMatrix(layer.imageFilter), <dynamic>[
moreOrLessEquals(0.7071067811865476), moreOrLessEquals(0.7071067811865475), 0.0, 0.0,
moreOrLessEquals(-0.7071067811865475), moreOrLessEquals(0.7071067811865476), 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
moreOrLessEquals(329.28932188134524), moreOrLessEquals(-194.97474683058329), 0.0, 1.0]
);
});
testWidgets('Offset Transform.rotate with FilterQuality produces filter layer', (WidgetTester tester) async {
await tester.pumpWidget(
SizedBox(width: 400, height: 400,
child: Center(
child: Transform.rotate(
angle: math.pi / 4,
filterQuality: FilterQuality.low,
child: const SizedBox(width: 100, height: 100),
),
),
),
);
expect(tester.layers.whereType<ImageFilterLayer>().length, 1);
final ImageFilterLayer layer = tester.layers.whereType<ImageFilterLayer>().first;
expect(extractMatrix(layer.imageFilter), <dynamic>[
moreOrLessEquals(0.7071067811865476), moreOrLessEquals(0.7071067811865475), 0.0, 0.0,
moreOrLessEquals(-0.7071067811865475), moreOrLessEquals(0.7071067811865476), 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
moreOrLessEquals(329.28932188134524), moreOrLessEquals(-194.97474683058329), 0.0, 1.0]
);
});
testWidgets('Transform layers update to match child and filterQuality', (WidgetTester tester) async {
......
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