Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1950e72
Impl engine
dkwingsmt Feb 12, 2024
f55dfdf
Web
dkwingsmt Feb 12, 2024
7f76c5f
Rename to RequestWarmUpFrame and add web time
dkwingsmt Feb 13, 2024
31a5ea3
Change to scheduleWarmUpFrame and EndWarmUpFrame
dkwingsmt Feb 13, 2024
590287d
Comment
dkwingsmt Feb 13, 2024
40b269b
Doc
dkwingsmt Feb 13, 2024
2d70a0f
Simplify web implementation
dkwingsmt Feb 14, 2024
4af9f06
Fix comment
dkwingsmt Feb 14, 2024
bfe5570
More doc
dkwingsmt Feb 14, 2024
21439c4
Fix doc
dkwingsmt Feb 14, 2024
1bd21db
More doc
dkwingsmt Feb 14, 2024
4f41658
Fix linter
dkwingsmt Feb 14, 2024
eeac064
Fix comment
dkwingsmt Feb 14, 2024
9c5bce4
Add test
dkwingsmt Feb 15, 2024
cdcf71a
Fix test
dkwingsmt Feb 15, 2024
7ab7d8e
Better test
dkwingsmt Feb 15, 2024
afbcfae
Merge remote-tracking branch 'origin/main' into force-sync-frame
dkwingsmt Feb 15, 2024
7381087
Simplify test and add platformdispatcher test
dkwingsmt Feb 15, 2024
05d3d2d
Better structure
dkwingsmt Feb 15, 2024
06957bb
Better name
dkwingsmt Feb 15, 2024
68953c0
Merge branch 'main' into force-sync-frame
dkwingsmt Feb 15, 2024
a9b7511
Merge branch 'main' into force-sync-frame
dkwingsmt Feb 20, 2024
8731e47
Add web platform dispatcher test
dkwingsmt Feb 20, 2024
cdeffd9
Merge branch 'main' into force-sync-frame
dkwingsmt Feb 20, 2024
5d9f48b
Web comments
dkwingsmt Feb 21, 2024
1589c59
Merge remote-tracking branch 'origin/main' into force-sync-frame
dkwingsmt Feb 21, 2024
556984f
Fix test
dkwingsmt Feb 21, 2024
2b6d3b2
Revert timer run change
dkwingsmt Feb 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Simplify test and add platformdispatcher test
  • Loading branch information
dkwingsmt committed Feb 15, 2024
commit 7381087ac5acf78802308e4b0ce9e4362a8b1847
29 changes: 15 additions & 14 deletions shell/common/engine_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ TEST_F(EngineTest, AnimatorSubmitWarmUpImplicitView) {
EXPECT_CALL(delegate_, GetPlatformMessageHandler)
.WillOnce(ReturnRef(platform_message_handler));

fml::AutoResetWaitableEvent continuation_ready_latch;
fml::AutoResetWaitableEvent draw_latch;
EXPECT_CALL(animator_delegate, OnAnimatorDraw)
.WillOnce(Invoke([&draw_latch](
Expand All @@ -594,17 +595,14 @@ TEST_F(EngineTest, AnimatorSubmitWarmUpImplicitView) {
draw_latch.Signal();
}));
EXPECT_CALL(animator_delegate, OnAnimatorBeginFrame)
.WillRepeatedly(Invoke([&engine_context](fml::TimePoint frame_target_time,
uint64_t frame_number) {
engine_context->EngineTaskSync([&](Engine& engine) {
engine.BeginFrame(frame_target_time, frame_number);
});
}));

static fml::AutoResetWaitableEvent continuation_ready_latch;
continuation_ready_latch.Reset();
AddNativeCallback("NotifyNative",
[](auto args) { continuation_ready_latch.Signal(); });
.WillRepeatedly(
Invoke([&engine_context, &continuation_ready_latch](
fml::TimePoint frame_target_time, uint64_t frame_number) {
continuation_ready_latch.Signal();
engine_context->EngineTaskSync([&](Engine& engine) {
engine.BeginFrame(frame_target_time, frame_number);
});
}));

std::unique_ptr<Animator> animator;
PostSync(task_runners_.GetUITaskRunner(),
Expand All @@ -619,12 +617,15 @@ TEST_F(EngineTest, AnimatorSubmitWarmUpImplicitView) {
engine_context = EngineContext::Create(delegate_, settings_, task_runners_,
std::move(animator));

auto configuration = RunConfiguration::InferFromSettings(settings_);
configuration.SetEntrypoint("renderWarmUpImplicitViewAfterMetricsChanged");
engine_context->Run(std::move(configuration));
engine_context->EngineTaskSync(
[](Engine& engine) { engine.ScheduleFrame(true); });

continuation_ready_latch.Wait();

auto configuration = RunConfiguration::InferFromSettings(settings_);
configuration.SetEntrypoint("renderWarmUpImplicitView");
engine_context->Run(std::move(configuration));

// Set metrics, which notifies the Dart isolate to render the views.
engine_context->EngineTaskSync([](Engine& engine) {
engine.AddView(kFlutterImplicitViewId, ViewportMetrics{1.0, 10, 10, 1, 0});
Expand Down
58 changes: 22 additions & 36 deletions shell/common/fixtures/shell_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -533,43 +533,29 @@ void testReportViewWidths() {
}

@pragma('vm:entry-point')
void renderWarmUpImplicitViewAfterMetricsChanged() {
PlatformDispatcher.instance.onBeginFrame = (Duration beginTime) {
// Make sure onBeginFrame and onDrawFrame are not used later.
PlatformDispatcher.instance.onBeginFrame = null;
PlatformDispatcher.instance.onDrawFrame = null;
// Let the test know that a continuation is available.
notifyNative();
};

void renderWarmUpImplicitView() {
bool beginFrameDone = false;

// As soon as 2 views are added, render these views.
PlatformDispatcher.instance.onMetricsChanged = () {
PlatformDispatcher.instance.scheduleWarmUpFrame(
beginFrame: () {
expect(beginFrameDone, false);
beginFrameDone = true;
},
drawFrame: () {
expect(beginFrameDone, true);

final SceneBuilder builder = SceneBuilder();
final PictureRecorder recorder = PictureRecorder();
final Canvas canvas = Canvas(recorder);
canvas.drawPaint(Paint()..color = const Color(0xFFABCDEF));
final Picture picture = recorder.endRecording();
builder.addPicture(Offset.zero, picture);

final Scene scene = builder.build();
PlatformDispatcher.instance.implicitView!.render(scene);

scene.dispose();
picture.dispose();
},
);
};
PlatformDispatcher.instance.scheduleWarmUpFrame(
beginFrame: () {
expect(beginFrameDone, false);
beginFrameDone = true;
},
drawFrame: () {
expect(beginFrameDone, true);

// Schedule a frame to produce an Animator continuation.
PlatformDispatcher.instance.scheduleFrame();
final SceneBuilder builder = SceneBuilder();
final PictureRecorder recorder = PictureRecorder();
final Canvas canvas = Canvas(recorder);
canvas.drawPaint(Paint()..color = const Color(0xFFABCDEF));
final Picture picture = recorder.endRecording();
builder.addPicture(Offset.zero, picture);

final Scene scene = builder.build();
PlatformDispatcher.instance.implicitView!.render(scene);

scene.dispose();
picture.dispose();
},
);
}
28 changes: 28 additions & 0 deletions testing/dart/platform_dispatcher_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';
import 'dart:ui';

import 'package:litetest/litetest.dart';
Expand Down Expand Up @@ -46,4 +47,31 @@ void main() {
expect(constraints.isSatisfiedBy(const Size(400, 500)), false);
expect(constraints / 2, const ViewConstraints(minWidth: 50, maxWidth: 100, minHeight: 150, maxHeight: 200));
});

test('scheduleWarmupFrame should call both callbacks and flush microtasks', () async {
bool microtaskFlushed = false;
bool beginFrameCalled = false;
final Completer<void> drawFrameCalled = Completer<void>();
PlatformDispatcher.instance.scheduleWarmUpFrame(beginFrame: () {
expect(microtaskFlushed, false);
expect(drawFrameCalled.isCompleted, false);
expect(beginFrameCalled, false);
beginFrameCalled = true;
scheduleMicrotask(() {
expect(microtaskFlushed, false);
expect(drawFrameCalled.isCompleted, false);
microtaskFlushed = true;
});
expect(microtaskFlushed, false);
}, drawFrame: () {
expect(beginFrameCalled, true);
expect(microtaskFlushed, true);
expect(drawFrameCalled.isCompleted, false);
drawFrameCalled.complete();
});
await drawFrameCalled.future;
expect(beginFrameCalled, true);
expect(drawFrameCalled.isCompleted, true);
expect(microtaskFlushed, true);
});
}