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

Start animator paused #29007

Merged
merged 2 commits into from
Oct 4, 2021
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
15 changes: 5 additions & 10 deletions shell/common/animator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ Animator::Animator(Delegate& delegate,
: delegate_(delegate),
task_runners_(std::move(task_runners)),
waiter_(std::move(waiter)),
dart_frame_deadline_(0),
#if SHELL_ENABLE_METAL
layer_tree_pipeline_(std::make_shared<LayerTreePipeline>(2)),
#else // SHELL_ENABLE_METAL
Expand All @@ -41,11 +40,6 @@ Animator::Animator(Delegate& delegate,
: 2)),
#endif // SHELL_ENABLE_METAL
pending_frame_semaphore_(1),
paused_(false),
regenerate_layer_tree_(false),
frame_scheduled_(false),
notify_idle_task_id_(0),
dimension_change_pending_(false),
weak_factory_(this) {
}

Expand Down Expand Up @@ -92,10 +86,10 @@ const char* Animator::FrameParity() {
return (frame_number % 2) ? "even" : "odd";
}

static int64_t FxlToDartOrEarlier(fml::TimePoint time) {
int64_t dart_now = Dart_TimelineGetMicros();
static fml::TimePoint FxlToDartOrEarlier(fml::TimePoint time) {
auto dart_now = fml::TimeDelta::FromMicroseconds(Dart_TimelineGetMicros());
fml::TimePoint fxl_now = fml::TimePoint::Now();
return (time - fxl_now).ToMicroseconds() + dart_now;
return fml::TimePoint::FromEpochDelta(time - fxl_now + dart_now);
}

void Animator::BeginFrame(
Expand Down Expand Up @@ -275,7 +269,8 @@ void Animator::AwaitVSync() {
}
});

delegate_.OnAnimatorNotifyIdle(dart_frame_deadline_);
delegate_.OnAnimatorNotifyIdle(
dart_frame_deadline_.ToEpochDelta().ToMicroseconds());
}

void Animator::ScheduleSecondaryVsyncCallback(uintptr_t id,
Expand Down
12 changes: 6 additions & 6 deletions shell/common/animator.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ class Animator final {

std::unique_ptr<FrameTimingsRecorder> frame_timings_recorder_;
uint64_t frame_request_number_ = 1;
int64_t dart_frame_deadline_;
fml::TimePoint dart_frame_deadline_;
std::shared_ptr<LayerTreePipeline> layer_tree_pipeline_;
fml::Semaphore pending_frame_semaphore_;
LayerTreePipeline::ProducerContinuation producer_continuation_;
bool paused_;
bool regenerate_layer_tree_;
bool frame_scheduled_;
int notify_idle_task_id_;
bool dimension_change_pending_;
bool paused_ = true;
bool regenerate_layer_tree_ = false;
bool frame_scheduled_ = false;
int notify_idle_task_id_ = 0;
bool dimension_change_pending_ = false;
SkISize last_layer_tree_size_ = {0, 0};
std::deque<uint64_t> trace_flow_ids_;

Expand Down
26 changes: 26 additions & 0 deletions shell/common/animator_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ TEST_F(ShellTest, VSyncTargetTime) {
fml::TaskRunner::RunNowOrPostTask(shell->GetTaskRunners().GetUITaskRunner(),
[engine = shell->GetEngine()]() {
if (engine) {
// Engine needs a surface for frames to
// be scheduled.
engine->OnOutputSurfaceCreated();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a slight change in behavior here that broke this test - before, the test never created a surface so it never actually scheduled frames and the call below this was a no-op. Now, there's an implicit call to RequestFrame(false) in this call. @iskakaushik

// this implies we can re-use the last
// frame to trigger begin frame rather
// than re-generating the layer tree.
Expand All @@ -94,5 +97,28 @@ TEST_F(ShellTest, VSyncTargetTime) {
ASSERT_FALSE(DartVMRef::IsInstanceRunning());
}

TEST_F(ShellTest, AnimatorStartsPaused) {
// Create all te prerequisites for a shell.
ASSERT_FALSE(DartVMRef::IsInstanceRunning());
auto settings = CreateSettingsForFixture();
TaskRunners task_runners = GetTaskRunnersForFixture();

auto shell = CreateShell(std::move(settings), task_runners);
ASSERT_TRUE(DartVMRef::IsInstanceRunning());

auto configuration = RunConfiguration::InferFromSettings(settings);
ASSERT_TRUE(configuration.IsValid());

configuration.SetEntrypoint("emptyMain");

RunEngine(shell.get(), std::move(configuration));

ASSERT_FALSE(IsAnimatorRunning(shell.get()));

// teardown.
DestroyShell(std::move(shell), std::move(task_runners));
ASSERT_FALSE(DartVMRef::IsInstanceRunning());
}

} // namespace testing
} // namespace flutter
2 changes: 1 addition & 1 deletion shell/common/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ tonic::DartErrorHandleType Engine::GetUIIsolateLastError() {

void Engine::OnOutputSurfaceCreated() {
have_surface_ = true;
StartAnimatorIfPossible();
ScheduleFrame();
}

Expand Down Expand Up @@ -465,6 +464,7 @@ std::string Engine::DefaultRouteName() {
}

void Engine::ScheduleFrame(bool regenerate_layer_tree) {
StartAnimatorIfPossible();
animator_->RequestFrame(regenerate_layer_tree);
}

Expand Down
17 changes: 17 additions & 0 deletions shell/common/shell_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -381,5 +381,22 @@ void ShellTest::DestroyShell(std::unique_ptr<Shell> shell,
latch.Wait();
}

bool ShellTest::IsAnimatorRunning(Shell* shell) {
fml::AutoResetWaitableEvent latch;
bool running = false;
if (!shell) {
return running;
}
fml::TaskRunner::RunNowOrPostTask(
shell->GetTaskRunners().GetUITaskRunner(), [shell, &running, &latch]() {
if (shell && shell->engine_ && shell->engine_->animator_) {
running = !shell->engine_->animator_->paused_;
}
latch.Signal();
});
latch.Wait();
return running;
}

} // namespace testing
} // namespace flutter
2 changes: 2 additions & 0 deletions shell/common/shell_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ class ShellTest : public FixtureTest {
const SkData& key,
const SkData& value);

static bool IsAnimatorRunning(Shell* shell);

enum ServiceProtocolEnum {
kGetSkSLs,
kEstimateRasterCacheMemory,
Expand Down