Skip to content

Commit

Permalink
add fallback_vsync_target_time to Animator::Render flutter#6137
Browse files Browse the repository at this point in the history
  • Loading branch information
fzyzcjy committed Oct 10, 2022
1 parent ce412a7 commit b19bdb9
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 18 deletions.
2 changes: 1 addition & 1 deletion lib/ui/dart_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ typedef CanvasPath Path;
V(PlatformConfigurationNativeApi::ScheduleFrame, 0) \
/*V(LastVsyncInfo::ReadToDart, 0)*/ \
V(PlatformConfigurationNativeApi::PointerDataPacketStorageReadPendingAndClear, 0) \
V(PlatformConfigurationNativeApi::Render, 1) \
V(PlatformConfigurationNativeApi::Render, 2) \
V(PlatformConfigurationNativeApi::UpdateSemantics, 1) \
V(PlatformConfigurationNativeApi::SetNeedsReportTimings, 1) \
V(PlatformConfigurationNativeApi::SetIsolateDebugName, 1) \
Expand Down
6 changes: 3 additions & 3 deletions lib/ui/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,10 @@ abstract class FlutterView {
/// scheduling of frames.
/// * [RendererBinding], the Flutter framework class which manages layout and
/// painting.
void render(Scene scene) => _render(scene);
void render(Scene scene, {Duration? fallbackVsyncTargetTime}) => _render(scene, fallbackVsyncTargetTime?.inMicroseconds ?? -1);

@FfiNative<Void Function(Pointer<Void>)>('PlatformConfigurationNativeApi::Render')
external static void _render(Scene scene);
@FfiNative<Void Function(Pointer<Void>, Int64)>('PlatformConfigurationNativeApi::Render')
external static void _render(Scene scene, int fallbackVsyncTargetTime);
}

/// A top-level platform window displaying a Flutter layer tree drawn from a
Expand Down
7 changes: 5 additions & 2 deletions lib/ui/window/platform_configuration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,12 @@ void PlatformConfiguration::CompletePlatformMessageResponse(
response->Complete(std::make_unique<fml::DataMapping>(std::move(data)));
}

void PlatformConfigurationNativeApi::Render(Scene* scene) {
void PlatformConfigurationNativeApi::Render(
Scene* scene,
int64_t fallback_vsync_target_time) {
UIDartState::ThrowIfUIOperationsProhibited();
UIDartState::Current()->platform_configuration()->client()->Render(scene);
UIDartState::Current()->platform_configuration()->client()->Render(
scene, fml::TimePoint::FromTicks(fallback_vsync_target_time));
}

void PlatformConfigurationNativeApi::SetNeedsReportTimings(bool value) {
Expand Down
5 changes: 3 additions & 2 deletions lib/ui/window/platform_configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ class PlatformConfigurationClient {
/// @brief Updates the client's rendering on the GPU with the newly
/// provided Scene.
///
virtual void Render(Scene* scene) = 0;
virtual void Render(Scene* scene,
fml::TimePoint fallback_vsync_target_time) = 0;

//--------------------------------------------------------------------------
/// @brief Receives a updated semantics tree from the Framework.
Expand Down Expand Up @@ -477,7 +478,7 @@ class PlatformConfigurationNativeApi {

static Dart_Handle PointerDataPacketStorageReadPendingAndClear();

static void Render(Scene* scene);
static void Render(Scene* scene, int64_t fallback_vsync_target_time);

static void UpdateSemantics(SemanticsUpdate* update);

Expand Down
5 changes: 3 additions & 2 deletions runtime/runtime_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,9 @@ Dart_Handle RuntimeController::PointerDataPacketStorageReadPendingAndClear() {
}

// |PlatformConfigurationClient|
void RuntimeController::Render(Scene* scene) {
client_.Render(scene->takeLayerTree());
void RuntimeController::Render(Scene* scene,
fml::TimePoint fallback_vsync_target_time) {
client_.Render(scene->takeLayerTree(), fallback_vsync_target_time);
}

// |PlatformConfigurationClient|
Expand Down
2 changes: 1 addition & 1 deletion runtime/runtime_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ class RuntimeController : public PlatformConfigurationClient {
Dart_Handle PointerDataPacketStorageReadPendingAndClear() override;

// |PlatformConfigurationClient|
void Render(Scene* scene) override;
void Render(Scene* scene, fml::TimePoint fallback_vsync_target_time) override;

// |PlatformConfigurationClient|
void UpdateSemantics(SemanticsUpdate* update) override;
Expand Down
3 changes: 2 additions & 1 deletion runtime/runtime_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class RuntimeDelegate {

virtual Dart_Handle PointerDataPacketStorageReadPendingAndClear() = 0;

virtual void Render(std::shared_ptr<flutter::LayerTree> layer_tree) = 0;
virtual void Render(std::shared_ptr<flutter::LayerTree> layer_tree,
fml::TimePoint fallback_vsync_target_time) = 0;

virtual void UpdateSemantics(SemanticsNodeUpdates update,
CustomAccessibilityActionUpdates actions) = 0;
Expand Down
13 changes: 11 additions & 2 deletions shell/common/animator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ void Animator::BeginFrame(
FML_DLOG(INFO) << "hi Animator::BeginFrame end normally";
}

void Animator::Render(std::shared_ptr<flutter::LayerTree> layer_tree) {
void Animator::Render(std::shared_ptr<flutter::LayerTree> layer_tree,
fml::TimePoint fallback_vsync_target_time) {
FML_DLOG(INFO) << "hi Animator::Render start";

has_rendered_ = true;
Expand All @@ -176,7 +177,15 @@ void Animator::Render(std::shared_ptr<flutter::LayerTree> layer_tree) {
if (!frame_timings_recorder_) {
// Framework can directly call render with a built scene.
frame_timings_recorder_ = std::make_unique<FrameTimingsRecorder>();
const fml::TimePoint placeholder_time = fml::TimePoint::Now();

// NOTE MODIFIED
// "<0" means not provided
const fml::TimePoint placeholder_time =
fallback_vsync_target_time.ToEpochDelta().ToMicroseconds() < 0
? fml::TimePoint::Now()
: fallback_vsync_target_time;
// const fml::TimePoint placeholder_time = fml::TimePoint::Now();

frame_timings_recorder_->RecordVsync(placeholder_time, placeholder_time);
frame_timings_recorder_->RecordBuildStart(placeholder_time);
}
Expand Down
3 changes: 2 additions & 1 deletion shell/common/animator.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ class Animator final {

void RequestFrame(bool regenerate_layer_tree = true);

void Render(std::shared_ptr<flutter::LayerTree> layer_tree);
void Render(std::shared_ptr<flutter::LayerTree> layer_tree,
fml::TimePoint fallback_vsync_target_time);

const std::weak_ptr<VsyncWaiter> GetVsyncWaiter() const;

Expand Down
5 changes: 3 additions & 2 deletions shell/common/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,8 @@ Dart_Handle Engine::PointerDataPacketStorageReadPendingAndClear() {
return PointerDataPacketStorage::ReadPendingAndClearStatic();
}

void Engine::Render(std::shared_ptr<flutter::LayerTree> layer_tree) {
void Engine::Render(std::shared_ptr<flutter::LayerTree> layer_tree,
fml::TimePoint fallback_vsync_target_time) {
if (!layer_tree) {
return;
}
Expand All @@ -454,7 +455,7 @@ void Engine::Render(std::shared_ptr<flutter::LayerTree> layer_tree) {
return;
}

animator_->Render(std::move(layer_tree));
animator_->Render(std::move(layer_tree), fallback_vsync_target_time);
}

void Engine::UpdateSemantics(SemanticsNodeUpdates update,
Expand Down
3 changes: 2 additions & 1 deletion shell/common/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,8 @@ class Engine final : public RuntimeDelegate, PointerDataDispatcher::Delegate {
std::string DefaultRouteName() override;

// |RuntimeDelegate|
void Render(std::shared_ptr<flutter::LayerTree> layer_tree) override;
void Render(std::shared_ptr<flutter::LayerTree> layer_tree,
fml::TimePoint fallback_vsync_target_time) override;

// |RuntimeDelegate|
void UpdateSemantics(SemanticsNodeUpdates update,
Expand Down

0 comments on commit b19bdb9

Please sign in to comment.