@@ -9,7 +9,6 @@ import 'package:fake_async/fake_async.dart';
9
9
import 'package:flutter/foundation.dart' ;
10
10
import 'package:flutter/painting.dart' ;
11
11
import 'package:flutter_test/flutter_test.dart' ;
12
- import 'package:vector_math/vector_math_64.dart' ;
13
12
14
13
import '../image_data.dart' ;
15
14
import '../painting/mocks_for_image_cache.dart' ;
@@ -679,8 +678,7 @@ void main() {
679
678
final TestCanvas canvas = TestCanvas ();
680
679
681
680
// Paint a square image into an output rect that is twice as wide as it is
682
- // tall. One copy of the image should be painted, aligned so that a repeating
683
- // tile mode causes it to appear twice.
681
+ // tall. Two copies of the image should be painted, one next to the other.
684
682
const Rect outputRect = Rect .fromLTWH (30.0 , 30.0 , 400.0 , 200.0 );
685
683
final ui.Image image = await createTestImage (width: 100 , height: 100 );
686
684
@@ -693,29 +691,34 @@ void main() {
693
691
repeat: ImageRepeat .repeatX,
694
692
);
695
693
696
- final List < Invocation > calls = canvas.invocations. where (( Invocation call) => call.memberName == #drawRect). toList ( );
694
+ const Size imageSize = Size ( 100.0 , 100.0 );
697
695
698
- expect (calls, hasLength (1 ));
699
- final Invocation call = calls[0 ];
700
- expect (call.isMethod, isTrue);
701
- expect (call.positionalArguments, hasLength (2 ));
696
+ final List <Invocation > calls = canvas.invocations.where ((Invocation call) => call.memberName == #drawImageRect).toList ();
697
+ final Set <Rect > tileRects = < Rect > {};
698
+
699
+ expect (calls, hasLength (2 ));
700
+ for (final Invocation call in calls) {
701
+ expect (call.isMethod, isTrue);
702
+ expect (call.positionalArguments, hasLength (4 ));
702
703
703
- // A tiled image is drawn as a rect with a shader.
704
- expect (call.positionalArguments[0 ], isA <Rect >());
705
- expect (call.positionalArguments[1 ], isA <Paint >());
704
+ expect (call.positionalArguments[0 ], isA< ui.Image > ());
705
+
706
+ // sourceRect should contain all pixels of the source image
707
+ expect (call.positionalArguments[1 ], Offset .zero & imageSize);
706
708
707
- final Paint paint = call.positionalArguments[1 ] as Paint ;
709
+ tileRects. add ( call.positionalArguments[2 ] as Rect ) ;
708
710
709
- expect (paint.shader, isA <ImageShader >());
710
- expect (call.positionalArguments[0 ], outputRect);
711
+ expect (call.positionalArguments[3 ], isA <Paint >());
712
+ }
713
+
714
+ expect (tileRects, < Rect > {const Rect .fromLTWH (30.0 , 30.0 , 200.0 , 200.0 ), const Rect .fromLTWH (230.0 , 30.0 , 200.0 , 200.0 )});
711
715
});
712
716
713
717
test ('paintImage with repeatY and fitWidth' , () async {
714
718
final TestCanvas canvas = TestCanvas ();
715
719
716
720
// Paint a square image into an output rect that is twice as tall as it is
717
- // wide. One copy of the image should be painted, aligned so that a repeating
718
- // tile mode causes it to appear twice.
721
+ // wide. Two copies of the image should be painted, one above the other.
719
722
const Rect outputRect = Rect .fromLTWH (30.0 , 30.0 , 200.0 , 400.0 );
720
723
final ui.Image image = await createTestImage (width: 100 , height: 100 );
721
724
@@ -727,21 +730,28 @@ void main() {
727
730
fit: BoxFit .fitWidth,
728
731
repeat: ImageRepeat .repeatY,
729
732
);
730
- final List <Invocation > calls = canvas.invocations.where ((Invocation call) => call.memberName == #drawRect).toList ();
731
733
732
- expect (calls, hasLength (1 ));
733
- final Invocation call = calls[0 ];
734
- expect (call.isMethod, isTrue);
735
- expect (call.positionalArguments, hasLength (2 ));
734
+ const Size imageSize = Size (100.0 , 100.0 );
736
735
737
- // A tiled image is drawn as a rect with a shader.
738
- expect (call.positionalArguments[0 ], isA <Rect >());
739
- expect (call.positionalArguments[1 ], isA <Paint >());
736
+ final List <Invocation > calls = canvas.invocations.where ((Invocation call) => call.memberName == #drawImageRect).toList ();
737
+ final Set <Rect > tileRects = < Rect > {};
740
738
741
- final Paint paint = call.positionalArguments[1 ] as Paint ;
739
+ expect (calls, hasLength (2 ));
740
+ for (final Invocation call in calls) {
741
+ expect (call.isMethod, isTrue);
742
+ expect (call.positionalArguments, hasLength (4 ));
742
743
743
- expect (paint.shader, isA <ImageShader >());
744
- expect (call.positionalArguments[0 ], outputRect);
744
+ expect (call.positionalArguments[0 ], isA< ui.Image > ());
745
+
746
+ // sourceRect should contain all pixels of the source image
747
+ expect (call.positionalArguments[1 ], Offset .zero & imageSize);
748
+
749
+ tileRects.add (call.positionalArguments[2 ] as Rect );
750
+
751
+ expect (call.positionalArguments[3 ], isA <Paint >());
752
+ }
753
+
754
+ expect (tileRects, < Rect > {const Rect .fromLTWH (30.0 , 30.0 , 200.0 , 200.0 ), const Rect .fromLTWH (30.0 , 230.0 , 200.0 , 200.0 )});
745
755
});
746
756
747
757
test ('DecorationImage scale test' , () async {
@@ -790,52 +800,4 @@ void main() {
790
800
791
801
info.dispose ();
792
802
}, skip: kIsWeb); // https://github.com/flutter/flutter/issues/87442
793
-
794
- test ('Compute image tiling' , () {
795
- expect (() => createTilingInfo (ImageRepeat .noRepeat, Rect .zero, Rect .zero, Rect .zero), throwsAssertionError);
796
-
797
- // These tests draw a 16x9 image into a 100x50 container with a destination
798
- // size of and make assertions based on observed behavior and the original
799
- // rectangles from https://github.com/flutter/flutter/pull/119495/
800
-
801
- final ImageTilingInfo repeatX = createTilingInfo (
802
- ImageRepeat .repeatX,
803
- const Rect .fromLTRB (0.0 , 0.0 , 100.0 , 50.0 ),
804
- const Rect .fromLTRB (84.0 , 0.0 , 100.0 , 9.0 ),
805
- const Rect .fromLTRB (0.0 , 0.0 , 16.0 , 9.0 ),
806
- );
807
-
808
- expect (repeatX.tmx, TileMode .repeated);
809
- expect (repeatX.tmy, TileMode .decal);
810
- expect (repeatX.transform, matrixMoreOrLessEquals (Matrix4 .identity ()
811
- ..scale (1.0 , 1.0 )
812
- ..setTranslationRaw (- 12.0 , 0.0 , 0.0 )
813
- ));
814
-
815
- final ImageTilingInfo repeatY = createTilingInfo (
816
- ImageRepeat .repeatY,
817
- const Rect .fromLTRB (0.0 , 0.0 , 100.0 , 50.0 ),
818
- const Rect .fromLTRB (84.0 , 0.0 , 100.0 , 9.0 ),
819
- const Rect .fromLTRB (0.0 , 0.0 , 16.0 , 9.0 ),
820
- );
821
- expect (repeatY.tmx, TileMode .decal);
822
- expect (repeatY.tmy, TileMode .repeated);
823
- expect (repeatY.transform, matrixMoreOrLessEquals (Matrix4 .identity ()
824
- ..scale (1.0 , 1.0 )
825
- ..setTranslationRaw (84.0 , 0.0 , 0.0 )
826
- ));
827
-
828
- final ImageTilingInfo repeat = createTilingInfo (
829
- ImageRepeat .repeat,
830
- const Rect .fromLTRB (0.0 , 0.0 , 100.0 , 50.0 ),
831
- const Rect .fromLTRB (84.0 , 0.0 , 100.0 , 9.0 ),
832
- const Rect .fromLTRB (0.0 , 0.0 , 16.0 , 9.0 ),
833
- );
834
- expect (repeat.tmx, TileMode .repeated);
835
- expect (repeat.tmy, TileMode .repeated);
836
- expect (repeat.transform, matrixMoreOrLessEquals (Matrix4 .identity ()
837
- ..scale (1.0 , 1.0 )
838
- ..setTranslationRaw (- 12.0 , 0.0 , 0.0 )
839
- ));
840
- });
841
803
}
0 commit comments