Re-land "Add option to delay rendering the first frame (#45135)" (#45588)

This commit is contained in:
Michael Goderbauer
2019-12-02 13:33:45 -08:00
committed by Kate Lovett
parent 088fa24463
commit c59151b1cd
6 changed files with 319 additions and 37 deletions

View File

@@ -687,6 +687,9 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
runApp(Container(key: UniqueKey(), child: _preTestMessage)); // Reset the tree to a known state.
await pump();
// Pretend that the first frame produced in the test body is the first frame
// sent to the engine.
resetFirstFrameSent();
final bool autoUpdateGoldensBeforeTest = autoUpdateGoldenFiles && !isBrowser;
final TestExceptionReporter reportTestExceptionBeforeTest = reportTestException;
@@ -963,6 +966,31 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
return result;
}
int _firstFrameDeferredCount = 0;
bool _firstFrameSent = false;
@override
bool get sendFramesToEngine => _firstFrameSent || _firstFrameDeferredCount == 0;
@override
void deferFirstFrame() {
assert(_firstFrameDeferredCount >= 0);
_firstFrameDeferredCount += 1;
}
@override
void allowFirstFrame() {
assert(_firstFrameDeferredCount > 0);
_firstFrameDeferredCount -= 1;
// Unlike in RendererBinding.allowFirstFrame we do not force a frame her
// to give the test full control over frame scheduling.
}
@override
void resetFirstFrameSent() {
_firstFrameSent = false;
}
EnginePhase _phase = EnginePhase.sendSemanticsUpdate;
// Cloned from RendererBinding.drawFrame() but with early-exit semantics.
@@ -979,7 +1007,8 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
pipelineOwner.flushCompositingBits();
if (_phase != EnginePhase.compositingBits) {
pipelineOwner.flushPaint();
if (_phase != EnginePhase.paint) {
if (_phase != EnginePhase.paint && sendFramesToEngine) {
_firstFrameSent = true;
renderView.compositeFrame(); // this sends the bits to the GPU
if (_phase != EnginePhase.composite) {
pipelineOwner.flushSemantics();