Generate only one "Frame Request Pending" event for each pending call to BeginFrame (flutter/engine#51857)

Fixes https://github.com/flutter/flutter/issues/145853
This commit is contained in:
Jason Simmons
2024-04-04 07:33:19 -07:00
committed by GitHub
parent fa120ff220
commit 84b23fcb89
3 changed files with 79 additions and 2 deletions

View File

@@ -237,7 +237,7 @@ void Animator::DrawLastLayerTrees(
}
void Animator::RequestFrame(bool regenerate_layer_trees) {
if (regenerate_layer_trees) {
if (regenerate_layer_trees && !regenerate_layer_trees_) {
// This event will be closed by BeginFrame. BeginFrame will only be called
// if regenerating the layer trees. If a frame has been requested to update
// an external texture, this will be false and no BeginFrame call will

View File

@@ -13,6 +13,7 @@ import 'package:vm_service/vm_service_io.dart';
import 'package:vm_service_protos/vm_service_protos.dart';
import '../impeller_enabled.dart';
import '../serialized_test_suite.dart';
Future<void> _testChromeFormatTrace(vms.VmService vmService) async {
final vms.Timeline timeline = await vmService.getVMTimeline();
@@ -69,7 +70,9 @@ Future<void> _testPerfettoFormatTrace(vms.VmService vmService) async {
}
void main() {
test('Canvas.saveLayer emits tracing', () async {
final SerializedTestSuite suite = SerializedTestSuite();
suite.test('Canvas.saveLayer emits tracing', () async {
final developer.ServiceProtocolInfo info = await developer.Service.getInfo();
if (info.serverUri == null) {
@@ -79,6 +82,7 @@ void main() {
final vms.VmService vmService = await vmServiceConnectUri(
'ws://localhost:${info.serverUri!.port}${info.serverUri!.path}ws',
);
await vmService.clearVMTimeline();
final Completer<void> completer = Completer<void>();
PlatformDispatcher.instance.onBeginFrame = (Duration timeStamp) async {
@@ -111,4 +115,50 @@ void main() {
await _testPerfettoFormatTrace(vmService);
await vmService.dispose();
});
suite.test('Frame request pending begin/end pairs are matched', () async {
final developer.ServiceProtocolInfo info = await developer.Service.getInfo();
if (info.serverUri == null) {
fail('This test must not be run with --disable-vm-service.');
}
final vms.VmService vmService = await vmServiceConnectUri(
'ws://localhost:${info.serverUri!.port}${info.serverUri!.path}ws',
);
await vmService.clearVMTimeline();
final Completer<void> completer = Completer<void>();
PlatformDispatcher.instance.onBeginFrame = (Duration timeStamp) async {
completer.complete();
};
// Schedule some frames.
for (int i = 0; i < 5; i++) {
PlatformDispatcher.instance.scheduleFrame();
}
await completer.future;
// Check that each "Frame Request Pending" event is ended before the next
// one begins.
final vms.Timeline timeline = await vmService.getVMTimeline();
bool eventStarted = false;
int frameCount = 0;
for (final vms.TimelineEvent event in timeline.traceEvents!) {
final Map<String, dynamic> json = event.json!;
if (json['name'] == 'Frame Request Pending') {
if (json['ph'] == 'b') {
expect(eventStarted, false);
eventStarted = true;
frameCount++;
} else if (json['ph'] == 'e') {
expect(eventStarted, true);
eventStarted = false;
}
}
}
expect(frameCount, greaterThan(0));
await vmService.dispose();
});
}

View File

@@ -0,0 +1,27 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'package:litetest/litetest.dart' as litetest;
// A group of tests that must be run without concurrency.
// This is useful for tests that modify global state.
class SerializedTestSuite {
Completer<void>? _previousTestCompleter;
void test(String name, Future<void> Function() body) {
final Completer<void>? lastTestCompleter = _previousTestCompleter;
final Completer<void> currentTestCompleter = Completer<void>();
_previousTestCompleter = currentTestCompleter;
Future<void> wrappedBody() async {
if (lastTestCompleter != null) {
await lastTestCompleter.future;
}
await body();
currentTestCompleter.complete();
}
litetest.test(name, wrappedBody);
}
}