Skip to content

Commit

Permalink
Does not replace the root layer unnecessarily (#101748)
Browse files Browse the repository at this point in the history
  • Loading branch information
xu-baolin committed May 6, 2022
1 parent 82afe3e commit b20e27e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
6 changes: 5 additions & 1 deletion packages/flutter/lib/src/rendering/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox>
/// 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.
///
Expand All @@ -90,8 +91,11 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox>
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();
}
Expand Down
14 changes: 14 additions & 0 deletions packages/flutter/test/rendering/view_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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', () {
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter_test/lib/src/binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit b20e27e

Please sign in to comment.