Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit b5f59ed

Browse files
chinmaygardecbracken
authored andcommitted
Delay the vsync callback till the frame start time specified by embedder. (#8072)
The current assumption is that the embedder will wait till the vsync event and then fire the callback. However, some embedders have that information upfront. Since the time point has already been specified by the embedder, there is no reason to burden the embedder with having to setup a wait either.
1 parent 7426305 commit b5f59ed

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

shell/common/vsync_waiter.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void VsyncWaiter::FireCallback(fml::TimePoint frame_start_time,
3535
return;
3636
}
3737

38-
task_runners_.GetUITaskRunner()->PostTask(
38+
task_runners_.GetUITaskRunner()->PostTaskForTime(
3939
[callback, frame_start_time, frame_target_time]() {
4040
#if defined(OS_FUCHSIA)
4141
// In general, traces on Fuchsia are recorded across the whole system.
@@ -49,7 +49,8 @@ void VsyncWaiter::FireCallback(fml::TimePoint frame_start_time,
4949
TRACE_EVENT0("flutter", "VSYNC");
5050
#endif
5151
callback(frame_start_time, frame_target_time);
52-
});
52+
},
53+
frame_start_time);
5354
}
5455

5556
float VsyncWaiter::GetDisplayRefreshRate() const {

shell/platform/embedder/embedder.h

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -549,13 +549,15 @@ typedef struct {
549549
// Flutter application (such as compiled shader programs used by Skia).
550550
// This is optional. The string must be NULL terminated.
551551
const char* persistent_cache_path;
552-
// A callback that gets invoked by the engine when it attempts to wait for
553-
// a platform vsync event. The engine will give the platform a baton that
554-
// needs to be returned back to the engine via |FlutterEngineOnVsync|. All
555-
// vsync operations must occur on the thread that made the call to
556-
// |FlutterEngineRun|. All batons must be retured to the engine before
557-
// initializing a |FlutterEngineShutdown|. Not doing the same will result in a
558-
// memory leak.
552+
// A callback that gets invoked by the engine when it attempts to wait for a
553+
// platform vsync event. The engine will give the platform a baton that needs
554+
// to be returned back to the engine via |FlutterEngineOnVsync|. All batons
555+
// must be retured to the engine before initializing a
556+
// |FlutterEngineShutdown|. Not doing the same will result in a memory leak.
557+
// While the call to |FlutterEngineOnVsync| must occur on the thread that made
558+
// the call to |FlutterEngineRun|, the engine will make this callback on an
559+
// internal engine-managed thread. If the components accessed on the embedder
560+
// are not thread safe, the appropriate re-threading must be done.
559561
VsyncCallback vsync_callback;
560562
} FlutterProjectArgs;
561563

@@ -645,7 +647,15 @@ FlutterEngineResult FlutterEngineDispatchSemanticsAction(
645647
size_t data_length);
646648

647649
// Notify the engine that a vsync event occurred. A baton passed to the
648-
// platform via the vsync callback must be returned.
650+
// platform via the vsync callback must be returned. This call must be made on
651+
// the thread on which the call to |FlutterEngineRun| was made.
652+
//
653+
// |frame_start_time_nanos| is the point at which the vsync event occurred.
654+
// |frame_target_time_nanos| is the point at which the embedder anticipates the
655+
// next vsync to occur. This is a hint the engine uses to schedule Dart VM
656+
// garbage collection in periods in which the various threads are most likely to
657+
// be idle. For example, for a 60Hz display, embedders should add 16.6 * 1e6 to
658+
// the frame time field.
649659
FLUTTER_EXPORT
650660
FlutterEngineResult FlutterEngineOnVsync(FlutterEngine engine,
651661
intptr_t baton,

0 commit comments

Comments
 (0)