Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 185635b

Browse files
committed
update comment related to how OpacityLayer might end up with multiple children
1 parent 698e3a8 commit 185635b

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

flow/layers/opacity_layer.h

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,16 @@ class OpacityLayer : public ContainerLayer {
4242
* @brief Returns the ContainerLayer used to hold all of the children
4343
* of the OpacityLayer.
4444
*
45-
* Typically these layers should only have a single child according to
46-
* the contract of the associated Flutter widget, but the engine API
47-
* cannot enforce that contract and must be prepared to support the
48-
* possibility of adding more than one child. In either case, the
49-
* child container will hold all children. Note that since the child
50-
* container is created fresh with each new OpacityLayer, it may not
51-
* be the best choice to cache to speed up rendering during an animation.
45+
* Often opacity layers will only have a single child since the associated
46+
* Flutter widget is specified with only a single child widget pointer.
47+
* But depending on the structure of the child tree that single widget at
48+
* the framework level can turn into multiple children at the engine
49+
* API level since there is no guarantee of a 1:1 correspondence of widgets
50+
* to engine layers. This synthetic child container layer is established to
51+
* hold all of the children in a single layer so that we can cache their
52+
* output, but this synthetic layer will typically not be the best choice
53+
* for the layer cache since the synthetic container is created fresh with
54+
* each new OpacityLayer, and so may not be stable from frame to frame.
5255
*
5356
* @see GetCacheableChild()
5457
* @return the ContainerLayer child used to hold the children
@@ -61,13 +64,17 @@ class OpacityLayer : public ContainerLayer {
6164
*
6265
* The returned Layer must represent all children and try to remain stable
6366
* if the OpacityLayer is reconstructed in subsequent frames of the scene.
64-
* The OpacityLayer needs to be recreated on frames where its opacity
65-
* values change, but it often contains the same child on each such frame.
66-
* Since the child container is created fresh each time the OpacityLayer
67-
* is constructed, the return value from GetChildContainer will be different
68-
* on each such frame even if the same child is used. This method will
69-
* determine if there is a (single) stable child and return that Layer
70-
* so that caching will be more successful.
67+
*
68+
* Note that since the synthetic child container returned from the
69+
* GetChildContainer() method is created fresh with each new OpacityLayer,
70+
* its return value will not be a good candidate for caching. But if the
71+
* standard recommendations for animations are followed and the child widget
72+
* is wrapped with a RepaintBoundary widget at the framework level, then
73+
* the synthetic child container should contain the same single child layer
74+
* on each frame. Under those conditions, that single child of the child
75+
* container will be the best candidate for caching in the RasterCache
76+
* and this method will return that single child if possible to improve
77+
* the performance of caching the children.
7178
*
7279
* @see GetChildContainer()
7380
* @return the best candidate Layer for caching the children

0 commit comments

Comments
 (0)