diff --git a/packages/flutter/lib/src/rendering/view.dart b/packages/flutter/lib/src/rendering/view.dart index 260b97fedf5a..16654e6fc536 100644 --- a/packages/flutter/lib/src/rendering/view.dart +++ b/packages/flutter/lib/src/rendering/view.dart @@ -82,6 +82,7 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin /// The constraints used for the root layout. ViewConfiguration get configuration => _configuration; ViewConfiguration _configuration; + /// The configuration is initially set by the `configuration` argument /// passed to the constructor. /// @@ -90,8 +91,11 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin assert(value != null); if (configuration == value) return; + final ViewConfiguration oldConfiguration = _configuration; _configuration = value; - replaceRootLayer(_updateMatricesAndCreateNewRootLayer()); + if (oldConfiguration.toMatrix() != _configuration.toMatrix()) { + replaceRootLayer(_updateMatricesAndCreateNewRootLayer()); + } assert(_rootTransform != null); markNeedsLayout(); } diff --git a/packages/flutter/test/rendering/view_test.dart b/packages/flutter/test/rendering/view_test.dart index 3408c85ce69a..52e3de57f516 100644 --- a/packages/flutter/test/rendering/view_test.dart +++ b/packages/flutter/test/rendering/view_test.dart @@ -47,6 +47,20 @@ void main() { view.configuration = createViewConfiguration(devicePixelRatio: 5.0); expect(identical(view.debugLayer, firstLayer), false); }); + + test('does not replace the root layer unnecessarily when window resize', () { + final ui.FlutterView window = TestWindow(window: RendererBinding.instance.window); + final RenderView view = RenderView( + configuration: createViewConfiguration(size: const Size(100.0, 100.0)), + window: window, + ); + final PipelineOwner owner = PipelineOwner(); + view.attach(owner); + view.prepareInitialFrame(); + final ContainerLayer firstLayer = view.debugLayer!; + view.configuration = createViewConfiguration(size: const Size(100.0, 1117.0)); + expect(identical(view.debugLayer, firstLayer), true); + }); }); test('ViewConfiguration == and hashCode', () { diff --git a/packages/flutter_test/lib/src/binding.dart b/packages/flutter_test/lib/src/binding.dart index d5acb6467d0c..4c8f0093851d 100644 --- a/packages/flutter_test/lib/src/binding.dart +++ b/packages/flutter_test/lib/src/binding.dart @@ -1779,7 +1779,7 @@ class TestViewConfiguration extends ViewConfiguration { TestViewConfiguration._(Size size, ui.FlutterView window) : _paintMatrix = _getMatrix(size, window.devicePixelRatio, window), _hitTestMatrix = _getMatrix(size, 1.0, window), - super(size: size); + super(size: size, devicePixelRatio: window.devicePixelRatio); static Matrix4 _getMatrix(Size size, double devicePixelRatio, ui.FlutterView window) { final double inverseRatio = devicePixelRatio / window.devicePixelRatio;