@@ -156,7 +156,7 @@ void main() {
156
156
expect (identical (context.canvas.images[0 ], context.canvas.images[1 ]), true );
157
157
});
158
158
159
- test ('Changing color filter does not re-rasterize' , () async {
159
+ test ('Changing color filter does re-rasterize' , () async {
160
160
final RenderVectorGraphic renderVectorGraphic = RenderVectorGraphic (
161
161
pictureInfo,
162
162
'test' ,
@@ -175,11 +175,11 @@ void main() {
175
175
const ui.ColorFilter .mode (Colors .red, ui.BlendMode .colorBurn);
176
176
renderVectorGraphic.paint (context, Offset .zero);
177
177
178
- expect (firstImage.debugDisposed, false );
178
+ expect (firstImage.debugDisposed, true );
179
179
180
180
renderVectorGraphic.paint (context, Offset .zero);
181
181
182
- expect (context.canvas.lastImage, equals (firstImage));
182
+ expect (context.canvas.lastImage, isNot (firstImage));
183
183
});
184
184
185
185
test ('Changing device pixel ratio does re-rasterize and dispose old raster' ,
@@ -350,7 +350,8 @@ void main() {
350
350
final FakePaintingContext context = FakePaintingContext ();
351
351
renderVectorGraphic.paint (context, Offset .zero);
352
352
353
- expect (context.canvas.lastPaint? .color, const Color .fromRGBO (0 , 0 , 0 , 0.5 ));
353
+ // opaque is used to generate raster cache.
354
+ expect (context.canvas.lastPaint? .color, const Color .fromRGBO (0 , 0 , 0 , 1.0 ));
354
355
});
355
356
356
357
test ('Disposing render object disposes picture' , () async {
@@ -403,7 +404,9 @@ void main() {
403
404
final ui.PictureRecorder recorder = ui.PictureRecorder ();
404
405
ui.Canvas (recorder);
405
406
final ui.Image image = await recorder.endRecording ().toImage (1 , 1 );
406
- final RasterData data = RasterData (image, 1 , const RasterKey ('test' , 1 , 1 ));
407
+ final Paint paint = Paint ();
408
+ final RasterData data =
409
+ RasterData (image, 1 , RasterKey ('test' , 1 , 1 , paint));
407
410
408
411
data.dispose ();
409
412
@@ -426,6 +429,99 @@ void main() {
426
429
expect (context.canvas.totalSaves, 1 );
427
430
expect (context.canvas.totalSaveLayers, 1 );
428
431
});
432
+
433
+ testWidgets ('Changing offset does not re-rasterize in raster strategy' ,
434
+ (WidgetTester tester) async {
435
+ final RenderVectorGraphic renderVectorGraphic =
436
+ RenderVectorGraphic (pictureInfo, 'testOffset' , null , 1.0 , null , 1.0 );
437
+ renderVectorGraphic.layout (BoxConstraints .tight (const Size (50 , 50 )));
438
+ final FakePaintingContext context = FakePaintingContext ();
439
+
440
+ renderVectorGraphic.paint (context, Offset .zero);
441
+ expect (context.canvas.lastImage, isNotNull);
442
+
443
+ final ui.Image ? oldImage = context.canvas.lastImage;
444
+
445
+ renderVectorGraphic.paint (context, const Offset (20 , 30 ));
446
+ expect (context.canvas.lastImage, isNotNull);
447
+ expect (context.canvas.lastImage, equals (oldImage));
448
+
449
+ renderVectorGraphic.dispose ();
450
+ });
451
+
452
+ testWidgets ('RenderVectorGraphic re-rasterizes when opacity changes' ,
453
+ (WidgetTester tester) async {
454
+ final FixedOpacityAnimation opacity = FixedOpacityAnimation (0.2 );
455
+ final RenderVectorGraphic renderVectorGraphic = RenderVectorGraphic (
456
+ pictureInfo,
457
+ 'testOpacity' ,
458
+ null ,
459
+ 1.0 ,
460
+ opacity,
461
+ 1.0 ,
462
+ );
463
+
464
+ renderVectorGraphic.layout (BoxConstraints .tight (const Size (50 , 50 )));
465
+ final FakePaintingContext context = FakePaintingContext ();
466
+ renderVectorGraphic.paint (context, Offset .zero);
467
+
468
+ final ui.Image ? oldImage = context.canvas.lastImage;
469
+
470
+ opacity.value = 0.5 ;
471
+ opacity.notifyListeners ();
472
+
473
+ // Changing opacity requires painting.
474
+ expect (renderVectorGraphic.debugNeedsPaint, true );
475
+
476
+ // Changing opacity need create new raster cache.
477
+ renderVectorGraphic.paint (context, Offset .zero);
478
+ expect (context.canvas.lastImage, isNotNull);
479
+
480
+ expect (context.canvas.lastImage, isNot (oldImage));
481
+
482
+ renderVectorGraphic.dispose ();
483
+ });
484
+
485
+ testWidgets (
486
+ 'Identical widgets reuse raster cache when available in raster startegy' ,
487
+ (WidgetTester tester) async {
488
+ final RenderVectorGraphic renderVectorGraphic1 = RenderVectorGraphic (
489
+ pictureInfo,
490
+ 'testOffset' ,
491
+ null ,
492
+ 1.0 ,
493
+ null ,
494
+ 1.0 ,
495
+ );
496
+ final RenderVectorGraphic renderVectorGraphic2 = RenderVectorGraphic (
497
+ pictureInfo,
498
+ 'testOffset' ,
499
+ null ,
500
+ 1.0 ,
501
+ null ,
502
+ 1.0 ,
503
+ );
504
+ renderVectorGraphic1.layout (BoxConstraints .tight (const Size (50 , 50 )));
505
+ renderVectorGraphic2.layout (BoxConstraints .tight (const Size (50 , 50 )));
506
+
507
+ final FakePaintingContext context = FakePaintingContext ();
508
+
509
+ renderVectorGraphic1.paint (context, Offset .zero);
510
+
511
+ final ui.Image ? image1 = context.canvas.lastImage;
512
+
513
+ renderVectorGraphic2.paint (context, Offset .zero);
514
+
515
+ final ui.Image ? image2 = context.canvas.lastImage;
516
+
517
+ expect (image1, isNotNull);
518
+ expect (image2, isNotNull);
519
+
520
+ expect (image1, equals (image2));
521
+
522
+ renderVectorGraphic1.dispose ();
523
+ renderVectorGraphic2.dispose ();
524
+ });
429
525
}
430
526
431
527
class FakeCanvas extends Fake implements Canvas {
0 commit comments