Skip to content

Commit a13f771

Browse files
authored
Public nodes needing paint or layout (#166148)
<!-- Thanks for filing a pull request! Reviewers are typically assigned within a week of filing a request. To learn more about code review, see our documentation on Tree Hygiene: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md --> This PR adds 2 new `@protected` fields to `PipelineOwner` which list the RenderObjects currently needing paint or layout for the next frame. This PR addresses flutter/flutter#166147, which has further discussion of the motivation. ## Pre-launch Checklist - [X] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [X] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [X] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [X] I signed the [CLA]. - [X] I listed at least one issue that this PR fixes in the description above. - [X] I updated/added relevant documentation (doc comments with `///`). - [X] I added new tests to check the change I am making, or this PR is [test-exempt]. - [X] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [X] All existing and new tests are passing. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent 0cc606c commit a13f771

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,21 @@ base class PipelineOwner with DiagnosticableTreeMixin {
10881088
bool _shouldMergeDirtyNodes = false;
10891089
List<RenderObject> _nodesNeedingLayout = <RenderObject>[];
10901090

1091+
/// The [RenderObject]s representing relayout boundaries which need to be laid out
1092+
/// in the next [flushLayout] pass.
1093+
///
1094+
/// Relayout boundaries are added when they are marked for layout.
1095+
/// Subclasses of [PipelineOwner] may use them to invalidate caches or
1096+
/// otherwise make performance optimizations. Since nodes may be marked for
1097+
/// layout at any time, they are best checked during [flushLayout].
1098+
///
1099+
/// Relayout boundaries owned by child [PipelineOwner]s are not included here.
1100+
///
1101+
/// Boundaries appear in an arbitrary order, and may appear multiple times.
1102+
@protected
1103+
@nonVirtual
1104+
Iterable<RenderObject> get nodesNeedingLayout => _nodesNeedingLayout;
1105+
10911106
/// Whether this pipeline is currently in the layout phase.
10921107
///
10931108
/// Specifically, whether [flushLayout] is currently running.
@@ -1232,6 +1247,19 @@ base class PipelineOwner with DiagnosticableTreeMixin {
12321247

12331248
List<RenderObject> _nodesNeedingPaint = <RenderObject>[];
12341249

1250+
/// The [RenderObject]s which need to be painted in the next [flushPaint] pass.
1251+
///
1252+
/// [RenderObject]s marked with [RenderObject.isRepaintBoundary] are added
1253+
/// when they are marked needing paint. Subclasses of [PipelineOwner] may use them
1254+
/// to invalidate caches or otherwise make performance optimizations.
1255+
/// Since nodes may be marked for layout at any time, they are best checked during
1256+
/// [flushPaint].
1257+
///
1258+
/// Marked children of child [PipelineOwner]s are not included here.
1259+
@protected
1260+
@nonVirtual
1261+
Iterable<RenderObject> get nodesNeedingPaint => _nodesNeedingPaint;
1262+
12351263
/// Whether this pipeline is currently in the paint phase.
12361264
///
12371265
/// Specifically, whether [flushPaint] is currently running.

packages/flutter/test/rendering/object_test.dart

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,37 @@ void main() {
2222
);
2323
});
2424

25+
test('nodesNeedingLayout updated with layout changes', () {
26+
final _TestPipelineOwner owner = _TestPipelineOwner();
27+
final TestRenderObject renderObject = TestRenderObject()..isRepaintBoundary = true;
28+
renderObject.attach(owner);
29+
expect(owner.needLayout, isEmpty);
30+
31+
renderObject.layout(const BoxConstraints.tightForFinite());
32+
renderObject.markNeedsLayout();
33+
expect(owner.needLayout, contains(renderObject));
34+
35+
owner.flushLayout();
36+
expect(owner.needLayout, isEmpty);
37+
});
38+
39+
test('nodesNeedingPaint updated with paint changes', () {
40+
final _TestPipelineOwner owner = _TestPipelineOwner();
41+
final TestRenderObject renderObject = TestRenderObject(allowPaintBounds: true)
42+
..isRepaintBoundary = true;
43+
final OffsetLayer layer = OffsetLayer();
44+
layer.attach(owner);
45+
renderObject.attach(owner);
46+
expect(owner.needPaint, isEmpty);
47+
48+
renderObject.markNeedsPaint();
49+
renderObject.scheduleInitialPaint(layer);
50+
expect(owner.needPaint, contains(renderObject));
51+
52+
owner.flushPaint();
53+
expect(owner.needPaint, isEmpty);
54+
});
55+
2556
test('ensure frame is scheduled for markNeedsSemanticsUpdate', () {
2657
// Initialize all bindings because owner.flushSemantics() requires a window
2758
final TestRenderObject renderObject = TestRenderObject();
@@ -686,3 +717,10 @@ class TestThrowingRenderObject extends RenderObject {
686717
return Rect.zero;
687718
}
688719
}
720+
721+
final class _TestPipelineOwner extends PipelineOwner {
722+
// Make these protected fields visible for testing.
723+
Iterable<RenderObject> get needLayout => super.nodesNeedingLayout;
724+
725+
Iterable<RenderObject> get needPaint => super.nodesNeedingPaint;
726+
}

0 commit comments

Comments
 (0)