Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
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
Doc
  • Loading branch information
dkwingsmt committed Feb 13, 2024
commit 40b269ba013734fb6a5b03669b2f45e490ebdbd4
35 changes: 19 additions & 16 deletions lib/ui/platform_dispatcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -808,29 +808,32 @@ class PlatformDispatcher {
@Native<Void Function()>(symbol: 'PlatformConfigurationNativeApi::ScheduleFrame')
external static void _scheduleFrame();

/// Immediately render a frame by invoking the [onBeginFrame] and
/// [onDrawFrame] callbacks synchronously.
/// Schedule a frame to run as soon as possible, rather than waiting for the
/// engine to request a frame in response to a system "Vsync" signal.
///
/// This method performs the same computation for a frame as [scheduleFrame]
/// does, but instead of doing so at an appropriate opportunity, the render is
/// completed synchronously within this call.
/// This method is used during application startup so that the first frame
/// (which is likely to be quite expensive) can start a few extra milliseconds
/// earlier. Using it in other situations might lead to unintended results,
/// such as screen tearing. Depending on the platform, the warm up frame
/// might or might not be actually rendered to the screen.
///
/// Prefer [scheduleFrame] to update the display in normal operation. The
/// [scheduleWarmUpFrame] method is designed for situations that require a frame is
/// rendered as soon as possible, even at the cost of rendering quality. An
/// example of using this method is [SchedulerBinding.scheduleWarmUpFrame],
/// which is called during application startup so that the first frame can be
/// presented to the screen a few extra milliseconds earlier.
/// For more introduction to the warm up frame, see
/// [SchedulerBinding.scheduleWarmUpFrame].
///
/// This method uses the provided callbacks as the begin frame callback and
/// the draw frame callback instead of [onBeginFrame] and [onDrawFrame].
///
/// See also:
///
/// * [SchedulerBinding.scheduleWarmUpFrame], which uses this method.
/// * [scheduleFrame].
void scheduleWarmUpFrame(VoidCallback beginFrameCallback, VoidCallback drawFrameCallback) {
/// * [SchedulerBinding.scheduleWarmUpFrame], which uses this method, and
/// introduces the warm up frame in more details.
/// * [scheduleFrame], which schedules the frame at the next appropriate
/// opportunity and should be used to render regular frames.
void scheduleWarmUpFrame({required VoidCallback beginFrame, required VoidCallback drawFrame}) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is meant for first frame only, why not call it scheduleFirstFrame?

Copy link
Contributor Author

@dkwingsmt dkwingsmt Feb 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The biggest reason, in my opinion, is that this frame is not guaranteed to be rendered, for example if Animator::BeginFrame is not called before, or on Web (if you agree with my other comment). Therefore this might not be the first frame.

Besides, I don't want to give developers the impression that scheduling the first frame using scheduleFrame is wrong. The scheduleWarmUpFrame really is for warming up. An app doesn't need warm-ups to perform correctly, but will perform better. It's probably the same reason why SchedulerBinding.scheduleWarmUpFrame is not called scheduleFirstFrame.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to what Tong said: The warmup frame is also used in hot reload scenarios where it isn't the first frame of the app.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The semantics of this method sound pretty complicated. I guess warm up is fine then. Should we have some assertions in the engine for this method? For example, should we make sure it's only called for the first frame, and is never called after a scheduleFrame is called? Simply exposing this as a sibling to scheduleFrame seems to contain footguns.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it's possible, since SchedulerBinding.scheduleWarmUpFrame is also called right after hot reloading. I think it's better leave it to the app, i.e. the framework.

// We use timers here to ensure that microtasks flush in between.
Timer.run(beginFrameCallback);
Timer.run(beginFrame);
Timer.run(() {
drawFrameCallback();
drawFrame();
_endWarmUpFrame();
});
}
Expand Down