From 48cf2b9378d2c3718d11bde2c638ae4044a4d8b6 Mon Sep 17 00:00:00 2001 From: Yegor Date: Fri, 12 Feb 2021 16:01:19 -0800 Subject: [PATCH] [canvaskit] fix Path.from (#24382) --- lib/web_ui/lib/src/engine/canvaskit/path.dart | 2 +- lib/web_ui/test/canvaskit/path_test.dart | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/web_ui/lib/src/engine/canvaskit/path.dart b/lib/web_ui/lib/src/engine/canvaskit/path.dart index e8518dc6e6828..d2d1a333d92ee 100644 --- a/lib/web_ui/lib/src/engine/canvaskit/path.dart +++ b/lib/web_ui/lib/src/engine/canvaskit/path.dart @@ -13,7 +13,7 @@ class CkPath extends ManagedSkiaObject implements ui.Path { CkPath.from(CkPath other) : _fillType = other.fillType, - super(SkPath(other.skiaObject)) { + super(other.skiaObject.copy()) { skiaObject.setFillType(toSkFillType(_fillType)); } diff --git a/lib/web_ui/test/canvaskit/path_test.dart b/lib/web_ui/test/canvaskit/path_test.dart index 151323f5303eb..5c5072ce0c8ae 100644 --- a/lib/web_ui/test/canvaskit/path_test.dart +++ b/lib/web_ui/test/canvaskit/path_test.dart @@ -157,6 +157,25 @@ void testMain() { expect(measure1.contourIndex, 1); expect(measure1.extractPath(0, 15).getBounds(), ui.Rect.fromLTRB(20, 20, 30, 25)); }); + + test('Path.from', () { + final ui.Rect rect1 = ui.Rect.fromLTRB(0, 0, 10, 10); + final ui.Rect rect2 = ui.Rect.fromLTRB(10, 10, 20, 20); + + final ui.Path original = ui.Path(); + original.addRect(rect1); + expect(original, isA()); + expect(original.getBounds(), rect1); + + final ui.Path copy = ui.Path.from(original); + expect(copy, isA()); + expect(copy.getBounds(), rect1); + + // Test that when copy is mutated, the original is not affected + copy.addRect(rect2); + expect(original.getBounds(), rect1); + expect(copy.getBounds(), rect1.expandToInclude(rect2)); + }); }, skip: isIosSafari); // TODO: https://github.com/flutter/flutter/issues/60040