From cb9ce54b77bf1e9f25427e651487b377e3bbb2b2 Mon Sep 17 00:00:00 2001 From: Yegor Date: Mon, 13 Sep 2021 13:07:01 -0700 Subject: [PATCH] [web] fix the last matrix element in CkPath.shift (flutter/engine#28589) --- .../web_ui/lib/src/engine/canvaskit/path.dart | 16 ++++++++++------ .../lib/web_ui/test/canvaskit/path_test.dart | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/path.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/path.dart index a9ed3864198..c11233ad639 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/path.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/path.dart @@ -257,12 +257,16 @@ class CkPath extends ManagedSkiaObject implements ui.Path { } @override - ui.Path shift(ui.Offset offset) { - // Since CanvasKit does not expose `SkPath.offset`, create a copy of this - // path and call `transform` on it. - final SkPath newPath = skiaObject.copy(); - newPath.transform(1.0, 0.0, offset.dx, 0.0, 1.0, offset.dy, 0.0, 0.0, 0.0); - return CkPath.fromSkPath(newPath, _fillType); + CkPath shift(ui.Offset offset) { + // `SkPath.transform` mutates the existing path, so create a copy and call + // `transform` on the copy. + final SkPath shiftedPath = skiaObject.copy(); + shiftedPath.transform( + 1.0, 0.0, offset.dx, + 0.0, 1.0, offset.dy, + 0.0, 0.0, 1.0, + ); + return CkPath.fromSkPath(shiftedPath, _fillType); } static CkPath combine( diff --git a/engine/src/flutter/lib/web_ui/test/canvaskit/path_test.dart b/engine/src/flutter/lib/web_ui/test/canvaskit/path_test.dart index 40f93595678..5ef031f9aa9 100644 --- a/engine/src/flutter/lib/web_ui/test/canvaskit/path_test.dart +++ b/engine/src/flutter/lib/web_ui/test/canvaskit/path_test.dart @@ -85,6 +85,21 @@ void testMain() { expect(path.contains(const ui.Offset(5, 5)), isFalse); }); + test('CkPath.shift creates a shifted copy of the path', () { + const ui.Rect testRect = ui.Rect.fromLTRB(0, 0, 10, 10); + final CkPath path = CkPath(); + path.addRect(testRect); + expect(path.getBounds(), testRect); + + expect( + path.shift(const ui.Offset(20, 20)).getBounds(), + testRect.shift(const ui.Offset(20, 20)), + ); + + // Make sure the original path wasn't mutated. + expect(path.getBounds(), testRect); + }); + test('CkPath resurrection', () { const ui.Rect rect = ui.Rect.fromLTRB(0, 0, 10, 10); final CkPath path = CkPath();