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

Delay the vsync callback till the frame start time specified by embedder. #8072

Merged
merged 2 commits into from
Mar 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions shell/common/vsync_waiter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void VsyncWaiter::FireCallback(fml::TimePoint frame_start_time,
return;
}

task_runners_.GetUITaskRunner()->PostTask(
task_runners_.GetUITaskRunner()->PostTaskForTime(
[callback, frame_start_time, frame_target_time]() {
#if defined(OS_FUCHSIA)
// In general, traces on Fuchsia are recorded across the whole system.
Expand All @@ -49,7 +49,8 @@ void VsyncWaiter::FireCallback(fml::TimePoint frame_start_time,
TRACE_EVENT0("flutter", "VSYNC");
#endif
callback(frame_start_time, frame_target_time);
});
},
frame_start_time);
}

float VsyncWaiter::GetDisplayRefreshRate() const {
Expand Down
26 changes: 18 additions & 8 deletions shell/platform/embedder/embedder.h
Original file line number Diff line number Diff line change
Expand Up @@ -549,13 +549,15 @@ typedef struct {
// Flutter application (such as compiled shader programs used by Skia).
// This is optional. The string must be NULL terminated.
const char* persistent_cache_path;
// A callback that gets invoked by the engine when it attempts to wait for
// a platform vsync event. The engine will give the platform a baton that
// needs to be returned back to the engine via |FlutterEngineOnVsync|. All
// vsync operations must occur on the thread that made the call to
// |FlutterEngineRun|. All batons must be retured to the engine before
// initializing a |FlutterEngineShutdown|. Not doing the same will result in a
// memory leak.
// A callback that gets invoked by the engine when it attempts to wait for a
// platform vsync event. The engine will give the platform a baton that needs
// to be returned back to the engine via |FlutterEngineOnVsync|. All batons
// must be retured to the engine before initializing a
// |FlutterEngineShutdown|. Not doing the same will result in a memory leak.
// While the call to |FlutterEngineOnVsync| must occur on the thread that made
// the call to |FlutterEngineRun|, the engine will make this callback on an
// internal engine-managed thread. If the components accessed on the embedder
// are not thread safe, the appropriate re-threading must be done.
VsyncCallback vsync_callback;
} FlutterProjectArgs;

Expand Down Expand Up @@ -645,7 +647,15 @@ FlutterEngineResult FlutterEngineDispatchSemanticsAction(
size_t data_length);

// Notify the engine that a vsync event occurred. A baton passed to the
// platform via the vsync callback must be returned.
// platform via the vsync callback must be returned. This call must be made on
// the thread on which the call to |FlutterEngineRun| was made.
//
// |frame_start_time_nanos| is the point at which the vsync event occurred.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we change 'occurred' to 'occured or will occur' as now it could be a future time?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good call. #8093

// |frame_target_time_nanos| is the point at which the embedder anticipates the
// next vsync to occur. This is a hint the engine uses to schedule Dart VM
// garbage collection in periods in which the various threads are most likely to
// be idle. For example, for a 60Hz display, embedders should add 16.6 * 1e6 to
// the frame time field.
FLUTTER_EXPORT
FlutterEngineResult FlutterEngineOnVsync(FlutterEngine engine,
intptr_t baton,
Expand Down