Skip to content

Commit

Permalink
Add a test for 3D transform with needsCompositing
Browse files Browse the repository at this point in the history
The test was first written in
flutter#41654 (comment)

This will ensure that flutter#41654
won't have regressions.

This test would fail without flutter/engine#18160
  • Loading branch information
liyuqian committed Jul 23, 2020
1 parent 9b35933 commit 64e578a
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions packages/flutter/test/widgets/transform_test.dart
Expand Up @@ -5,6 +5,7 @@
// @dart = 2.8

import 'dart:math' as math;
import 'dart:ui' as ui;

import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/rendering.dart';
Expand Down Expand Up @@ -360,4 +361,48 @@ void main() {
await tester.tap(find.byKey(key1));
expect(_pointerDown, isTrue);
});

Widget _generateTransform(bool needsCompositing, double angle) {
final Widget customPaint = CustomPaint(painter: TestRectPainter());
return Transform(
transform: MatrixUtils.createCylindricalProjectionTransform(
radius: 100,
angle: angle,
perspective: 0.003,
),
// A RepaintBoundary child forces the Transform to needsCompositing
child: needsCompositing ? RepaintBoundary(child: customPaint) : customPaint,
);
}

testWidgets(
'3D transform renders the same with or without needsCompositing',
(WidgetTester tester) async {
for (double angle = 0; angle <= math.pi/4; angle += 0.01) {
await tester.pumpWidget(RepaintBoundary(child: _generateTransform(true, angle)));
final RenderBox renderBox = tester.binding.renderView.child;
final OffsetLayer layer = renderBox.debugLayer as OffsetLayer;
final ui.Image imageWithCompositing = await layer.toImage(renderBox.paintBounds);

await tester.pumpWidget(RepaintBoundary(child: _generateTransform(false, angle)));
try {
await expectLater(find.byType(RepaintBoundary).first, matchesReferenceImage(imageWithCompositing));
} catch (e) {
print(angle);
}
}
},
);
}

class TestRectPainter extends CustomPainter {
@override
void paint(ui.Canvas canvas, ui.Size size) {
canvas.drawRect(
const Offset(200, 200) & const Size(10, 10),
Paint()..color = const Color(0xFFFF0000),
);
}
@override
bool shouldRepaint(CustomPainter oldDelegate) => true;
}

0 comments on commit 64e578a

Please sign in to comment.