Avoid the overhead of instantiating a generator in paintImage (#28736)
This function is called frequently with non-repeating images during many animations
This commit is contained in:
@@ -438,22 +438,25 @@ void paintImage({
|
||||
final Rect sourceRect = alignment.inscribe(
|
||||
sourceSize, Offset.zero & inputSize,
|
||||
);
|
||||
for (Rect tileRect in _generateImageTileRects(rect, destinationRect, repeat))
|
||||
canvas.drawImageRect(image, sourceRect, tileRect, paint);
|
||||
if (repeat == ImageRepeat.noRepeat) {
|
||||
canvas.drawImageRect(image, sourceRect, destinationRect, paint);
|
||||
} else {
|
||||
for (Rect tileRect in _generateImageTileRects(rect, destinationRect, repeat))
|
||||
canvas.drawImageRect(image, sourceRect, tileRect, paint);
|
||||
}
|
||||
} else {
|
||||
for (Rect tileRect in _generateImageTileRects(rect, destinationRect, repeat))
|
||||
canvas.drawImageNine(image, centerSlice, tileRect, paint);
|
||||
if (repeat == ImageRepeat.noRepeat) {
|
||||
canvas.drawImageNine(image, centerSlice, destinationRect, paint);
|
||||
} else {
|
||||
for (Rect tileRect in _generateImageTileRects(rect, destinationRect, repeat))
|
||||
canvas.drawImageNine(image, centerSlice, tileRect, paint);
|
||||
}
|
||||
}
|
||||
if (needSave)
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
Iterable<Rect> _generateImageTileRects(Rect outputRect, Rect fundamentalRect, ImageRepeat repeat) sync* {
|
||||
if (repeat == ImageRepeat.noRepeat) {
|
||||
yield fundamentalRect;
|
||||
return;
|
||||
}
|
||||
|
||||
int startX = 0;
|
||||
int startY = 0;
|
||||
int stopX = 0;
|
||||
|
||||
Reference in New Issue
Block a user