Skip to content

Commit b20e27e

Browse files
authored
Does not replace the root layer unnecessarily (#101748)
1 parent 82afe3e commit b20e27e

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

packages/flutter/lib/src/rendering/view.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox>
8282
/// The constraints used for the root layout.
8383
ViewConfiguration get configuration => _configuration;
8484
ViewConfiguration _configuration;
85+
8586
/// The configuration is initially set by the `configuration` argument
8687
/// passed to the constructor.
8788
///
@@ -90,8 +91,11 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox>
9091
assert(value != null);
9192
if (configuration == value)
9293
return;
94+
final ViewConfiguration oldConfiguration = _configuration;
9395
_configuration = value;
94-
replaceRootLayer(_updateMatricesAndCreateNewRootLayer());
96+
if (oldConfiguration.toMatrix() != _configuration.toMatrix()) {
97+
replaceRootLayer(_updateMatricesAndCreateNewRootLayer());
98+
}
9599
assert(_rootTransform != null);
96100
markNeedsLayout();
97101
}

packages/flutter/test/rendering/view_test.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ void main() {
4747
view.configuration = createViewConfiguration(devicePixelRatio: 5.0);
4848
expect(identical(view.debugLayer, firstLayer), false);
4949
});
50+
51+
test('does not replace the root layer unnecessarily when window resize', () {
52+
final ui.FlutterView window = TestWindow(window: RendererBinding.instance.window);
53+
final RenderView view = RenderView(
54+
configuration: createViewConfiguration(size: const Size(100.0, 100.0)),
55+
window: window,
56+
);
57+
final PipelineOwner owner = PipelineOwner();
58+
view.attach(owner);
59+
view.prepareInitialFrame();
60+
final ContainerLayer firstLayer = view.debugLayer!;
61+
view.configuration = createViewConfiguration(size: const Size(100.0, 1117.0));
62+
expect(identical(view.debugLayer, firstLayer), true);
63+
});
5064
});
5165

5266
test('ViewConfiguration == and hashCode', () {

packages/flutter_test/lib/src/binding.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1779,7 +1779,7 @@ class TestViewConfiguration extends ViewConfiguration {
17791779
TestViewConfiguration._(Size size, ui.FlutterView window)
17801780
: _paintMatrix = _getMatrix(size, window.devicePixelRatio, window),
17811781
_hitTestMatrix = _getMatrix(size, 1.0, window),
1782-
super(size: size);
1782+
super(size: size, devicePixelRatio: window.devicePixelRatio);
17831783

17841784
static Matrix4 _getMatrix(Size size, double devicePixelRatio, ui.FlutterView window) {
17851785
final double inverseRatio = devicePixelRatio / window.devicePixelRatio;

0 commit comments

Comments
 (0)