- override
Pump the rendering pipeline to generate a frame.
This method is called by handleBeginFrame, which itself is called
automatically by the engine when when it is time to lay out and paint a
frame.
Each frame consists of the following phases:
- The animation phase: The
handleBeginFramemethod, which is registeredwithui.window.onBeginFrame, invokes all the transient frame callbacksregistered withscheduleFrameCallbackandaddFrameCallback, inregistration order. This includes all theTickerinstances that aredrivingAnimationControllerobjects, which means all of the activeAnimationobjects tick at this point.
handleBeginFrame then invokes all the persistent frame callbacks, of which
the most notable is this method, beginFrame, which proceeds as follows:
-
The layout phase: All the dirty
RenderObjects in the system are laidout (seeRenderObject.performLayout). SeeRenderObject.markNeedsLayoutfor further details on marking an object dirty for layout. -
The compositing bits phase: The compositing bits on any dirty
RenderObjectobjects are updated. SeeRenderObject.markNeedsCompositingBitsUpdate. -
The paint phase: All the dirty
RenderObjects in the system arerepainted (seeRenderObject.paint). This generates theLayertree. SeeRenderObject.markNeedsPaintfor further details on marking an objectdirty for paint. -
The compositing phase: The layer tree is turned into a
ui.Sceneandsent to the GPU. -
The semantics phase: All the dirty
RenderObjects in the system havetheir semantics updated (seeRenderObject.SemanticsAnnotator). Thisgenerates theSemanticsNodetree. SeeRenderObject.markNeedsSemanticsUpdatefor further details on marking anobject dirty for semantics.
For more details on steps 2-6, see PipelineOwner.
- The finalization phase: After
beginFramereturns,handleBeginFramethen invokes post-frame callbacks (registered withaddPostFrameCallback.
Some bindings (for example, the WidgetsBinding) add extra steps to this
list (for example, see WidgetsBinding.beginFrame).
Source
@override
void beginFrame() {
assert(inTest);
try {
debugBuildingDirtyElements = true;
buildOwner.buildScope(renderViewElement);
if (_phase == EnginePhase.build)
return;
assert(renderView != null);
pipelineOwner.flushLayout();
if (_phase == EnginePhase.layout)
return;
pipelineOwner.flushCompositingBits();
if (_phase == EnginePhase.compositingBits)
return;
pipelineOwner.flushPaint();
if (_phase == EnginePhase.paint)
return;
renderView.compositeFrame(); // this sends the bits to the GPU
if (_phase == EnginePhase.composite)
return;
pipelineOwner.flushSemantics();
if (_phase == EnginePhase.flushSemantics)
return;
} finally {
buildOwner.finalizeTree();
debugBuildingDirtyElements = false;
}
}