Add a compositing update phase
We need to compute whether a RenderObject has a composited descendant so that we can decide whether to use canvas.saveLayer or to create a new composited layer while walking down the tree during painting. The compositing update walks the tree from the root only to places where the tree's structure has been mutated. In the common case during an animation loop, we won't need to visit any render object beyond the root.
This commit is contained in:
@@ -120,6 +120,7 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget {
|
||||
setupParentData(child);
|
||||
super.adoptChild(child);
|
||||
markNeedsLayout();
|
||||
markNeedsCompositingUpdate();
|
||||
}
|
||||
void dropChild(RenderObject child) { // only for use by subclasses
|
||||
assert(debugCanPerformMutations);
|
||||
@@ -129,6 +130,7 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget {
|
||||
child.parentData.detach();
|
||||
super.dropChild(child);
|
||||
markNeedsLayout();
|
||||
markNeedsCompositingUpdate();
|
||||
}
|
||||
|
||||
// Override in subclasses with children and call the visitor for each child.
|
||||
@@ -367,15 +369,46 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget {
|
||||
|
||||
static List<RenderObject> _nodesNeedingPaint = new List<RenderObject>();
|
||||
|
||||
bool _needsPaint = true;
|
||||
bool get needsPaint => _needsPaint;
|
||||
|
||||
PictureLayer _layer;
|
||||
PictureLayer get layer {
|
||||
assert(requiresCompositing);
|
||||
return _layer;
|
||||
}
|
||||
|
||||
bool get requiresCompositing => false;
|
||||
|
||||
bool _hasCompositedDescendant = false;
|
||||
bool get hasCompositedDescendant {
|
||||
assert(!_needsCompositingUpdate);
|
||||
return _hasCompositedDescendant;
|
||||
}
|
||||
|
||||
bool _needsCompositingUpdate = false;
|
||||
void markNeedsCompositingUpdate() {
|
||||
if (_needsCompositingUpdate)
|
||||
return;
|
||||
_needsCompositingUpdate = true;
|
||||
final AbstractNode parent = this.parent;
|
||||
if (parent is RenderObject)
|
||||
parent.markNeedsCompositingUpdate();
|
||||
}
|
||||
|
||||
void updateCompositing() {
|
||||
if (!_needsCompositingUpdate)
|
||||
return;
|
||||
visitChildren((RenderObject child) {
|
||||
child.updateCompositing();
|
||||
if (child.hasCompositedDescendant)
|
||||
_hasCompositedDescendant = true;
|
||||
});
|
||||
if (requiresCompositing)
|
||||
_hasCompositedDescendant = true;
|
||||
_needsCompositingUpdate = false;
|
||||
}
|
||||
|
||||
bool _needsPaint = true;
|
||||
bool get needsPaint => _needsPaint;
|
||||
|
||||
void markNeedsPaint() {
|
||||
assert(!debugDoingPaint);
|
||||
if (!attached) return; // Don't try painting things that aren't in the hierarchy
|
||||
@@ -461,7 +494,6 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget {
|
||||
assert(!_needsPaint);
|
||||
}
|
||||
|
||||
bool get requiresCompositing => false;
|
||||
Rect get paintBounds;
|
||||
void debugPaint(PaintingContext context, Offset offset) { }
|
||||
void paint(PaintingContext context, Offset offset) { }
|
||||
|
||||
@@ -71,6 +71,7 @@ class SkyBinding {
|
||||
}
|
||||
void beginFrame(double timeStamp) {
|
||||
RenderObject.flushLayout();
|
||||
_renderView.updateCompositing();
|
||||
RenderObject.flushPaint();
|
||||
_renderView.paintFrame();
|
||||
_renderView.compositeFrame();
|
||||
|
||||
Reference in New Issue
Block a user