Start animator paused (flutter/engine#29007)

This commit is contained in:
Dan Field
2021-10-04 15:48:01 -07:00
committed by GitHub
parent 951c5f2e64
commit 542896d8c9
6 changed files with 57 additions and 17 deletions

View File

@@ -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
@@ -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) {
}
@@ -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(
@@ -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,

View File

@@ -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_;

View File

@@ -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();
// this implies we can re-use the last
// frame to trigger begin frame rather
// than re-generating the layer tree.
@@ -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

View File

@@ -272,7 +272,6 @@ tonic::DartErrorHandleType Engine::GetUIIsolateLastError() {
void Engine::OnOutputSurfaceCreated() {
have_surface_ = true;
StartAnimatorIfPossible();
ScheduleFrame();
}
@@ -472,6 +471,7 @@ std::string Engine::DefaultRouteName() {
}
void Engine::ScheduleFrame(bool regenerate_layer_tree) {
StartAnimatorIfPossible();
animator_->RequestFrame(regenerate_layer_tree);
}

View File

@@ -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

View File

@@ -96,6 +96,8 @@ class ShellTest : public FixtureTest {
const SkData& key,
const SkData& value);
static bool IsAnimatorRunning(Shell* shell);
enum ServiceProtocolEnum {
kGetSkSLs,
kEstimateRasterCacheMemory,