Unverified Commit b20e27e7 authored by xubaolin's avatar xubaolin Committed by GitHub

Does not replace the root layer unnecessarily (#101748)

parent 82afe3ea
......@@ -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.
///
......@@ -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();
}
......
......@@ -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', () {
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment