@@ -14,7 +14,6 @@ class CanvasPainter extends CustomPainter {
1414
1515 CanvasRenderingContext2D ? context;
1616
17- final Paint _saveLayerPaint = Paint ();
1817 final Paint _snapshotPaint = Paint ();
1918
2019 // Cache the last paint image.
@@ -49,62 +48,23 @@ class CanvasPainter extends CustomPainter {
4948 }
5049
5150 @override
52- void paint (Canvas canvas, Size size) async {
53- if (_hasSnapshot && ! _shouldPainting) {
54- return canvas.drawImage (_snapshot! , Offset .zero, _snapshotPaint);
55- }
56-
57- final PictureRecorder pictureRecorder = PictureRecorder ();
58- final Canvas recordCanvas = Canvas (pictureRecorder);
59-
51+ void paint (Canvas canvas, Size size) {
6052 if (_scaleX != 1.0 || _scaleY != 1.0 ) {
61- recordCanvas.scale (_scaleX, _scaleY);
62- }
63-
64- // This lets you create composite effects, for example making a group of drawing commands semi-transparent.
65- // Without using saveLayer, each part of the group would be painted individually,
66- // so where they overlap would be darker than where they do not. By using saveLayer to group them together,
67- // they can be drawn with an opaque color at first,
68- // and then the entire group can be made transparent using the saveLayer's paint.
69- recordCanvas.saveLayer (null , _saveLayerPaint);
70-
71- // Paint last content
72- if (_hasSnapshot) {
73- recordCanvas.drawImage (_snapshot! , Offset .zero, _snapshotPaint);
74- _disposeSnapshot ();
53+ canvas.scale (_scaleX, _scaleY);
7554 }
7655
7756 // Paint new actions
7857 List <CanvasAction >? actions;
7958 if (_shouldPainting) {
80- actions = context! .performActions (recordCanvas , size);
59+ actions = context! .performActions (canvas , size);
8160 }
8261
83- // Must pair each call to save()/saveLayer() with a later matching call to restore().
84- recordCanvas.restore ();
85-
86- // After calling this function, both the picture recorder
87- // and the canvas objects are invalid and cannot be used further.
88- final Picture picture = pictureRecorder.endRecording ();
89- canvas.drawPicture (picture);
90-
91- // Must flat picture to image, or raster will accept a growing command buffer.
92- await _createSnapshot (picture, size);
93-
94- // Dispose the used picture.
95- picture.dispose ();
9662 // Clear actions after snapshot was created, or next frame call may empty.
9763 if (actions != null ) {
9864 context! .clearActions (actions);
9965 }
10066 }
10167
102- Future <void > _createSnapshot (Picture picture, Size size) async {
103- _updatingSnapshot = true ;
104- _snapshot = await picture.toImage (size.width.toInt (), size.height.toInt ());
105- _updatingSnapshot = false ;
106- }
107-
10868 @override
10969 bool shouldRepaint (CanvasPainter oldDelegate) {
11070 if (_shouldRepaint) {
0 commit comments