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

Commit 46bea73

Browse files
Don't pause Animator when lifecycle state paused (#30969)
1 parent c5ee2e4 commit 46bea73

File tree

7 files changed

+6
-177
lines changed

7 files changed

+6
-177
lines changed

shell/common/animator.cc

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,6 @@ Animator::Animator(Delegate& delegate,
4545

4646
Animator::~Animator() = default;
4747

48-
void Animator::Stop() {
49-
paused_ = true;
50-
}
51-
52-
void Animator::Start() {
53-
if (!paused_) {
54-
return;
55-
}
56-
57-
paused_ = false;
58-
RequestFrame();
59-
}
60-
61-
// Indicate that screen dimensions will be changing in order to force rendering
62-
// of an updated frame even if the animator is currently paused.
63-
void Animator::SetDimensionChangePending() {
64-
dimension_change_pending_ = true;
65-
}
66-
6748
void Animator::EnqueueTraceFlowId(uint64_t trace_flow_id) {
6849
fml::TaskRunner::RunNowOrPostTask(
6950
task_runners_.GetUITaskRunner(),
@@ -179,10 +160,6 @@ void Animator::BeginFrame(
179160

180161
void Animator::Render(std::unique_ptr<flutter::LayerTree> layer_tree) {
181162
has_rendered_ = true;
182-
if (dimension_change_pending_ &&
183-
layer_tree->frame_size() != last_layer_tree_size_) {
184-
dimension_change_pending_ = false;
185-
}
186163
last_layer_tree_size_ = layer_tree->frame_size();
187164

188165
if (!frame_timings_recorder_) {
@@ -232,9 +209,6 @@ void Animator::RequestFrame(bool regenerate_layer_tree) {
232209
if (regenerate_layer_tree) {
233210
regenerate_layer_tree_ = true;
234211
}
235-
if (paused_ && !dimension_change_pending_) {
236-
return;
237-
}
238212

239213
if (!pending_frame_semaphore_.TryWait()) {
240214
// Multiple calls to Animator::RequestFrame will still result in a

shell/common/animator.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,6 @@ class Animator final {
7474
void ScheduleSecondaryVsyncCallback(uintptr_t id,
7575
const fml::closure& callback);
7676

77-
void Start();
78-
79-
void Stop();
80-
81-
void SetDimensionChangePending();
82-
8377
// Enqueue |trace_flow_id| into |trace_flow_ids_|. The flow event will be
8478
// ended at either the next frame, or the next vsync interval with no active
8579
// active rendering.
@@ -112,11 +106,9 @@ class Animator final {
112106
std::shared_ptr<LayerTreePipeline> layer_tree_pipeline_;
113107
fml::Semaphore pending_frame_semaphore_;
114108
LayerTreePipeline::ProducerContinuation producer_continuation_;
115-
bool paused_ = true;
116109
bool regenerate_layer_tree_ = false;
117110
bool frame_scheduled_ = false;
118111
int notify_idle_task_id_ = 0;
119-
bool dimension_change_pending_ = false;
120112
SkISize last_layer_tree_size_ = {0, 0};
121113
std::deque<uint64_t> trace_flow_ids_;
122114
bool has_rendered_ = false;

shell/common/animator_unittests.cc

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,6 @@ TEST_F(ShellTest, VSyncTargetTime) {
9292
fml::TaskRunner::RunNowOrPostTask(shell->GetTaskRunners().GetUITaskRunner(),
9393
[engine = shell->GetEngine()]() {
9494
if (engine) {
95-
// Engine needs a surface for frames to
96-
// be scheduled.
97-
engine->OnOutputSurfaceCreated();
9895
// this implies we can re-use the last
9996
// frame to trigger begin frame rather
10097
// than re-generating the layer tree.
@@ -116,30 +113,6 @@ TEST_F(ShellTest, VSyncTargetTime) {
116113
ASSERT_FALSE(DartVMRef::IsInstanceRunning());
117114
}
118115

119-
TEST_F(ShellTest, AnimatorStartsPaused) {
120-
// Create all te prerequisites for a shell.
121-
ASSERT_FALSE(DartVMRef::IsInstanceRunning());
122-
auto settings = CreateSettingsForFixture();
123-
TaskRunners task_runners = GetTaskRunnersForFixture();
124-
125-
auto shell = CreateShell(std::move(settings), task_runners,
126-
/* simulate_vsync=*/true);
127-
ASSERT_TRUE(DartVMRef::IsInstanceRunning());
128-
129-
auto configuration = RunConfiguration::InferFromSettings(settings);
130-
ASSERT_TRUE(configuration.IsValid());
131-
132-
configuration.SetEntrypoint("emptyMain");
133-
134-
RunEngine(shell.get(), std::move(configuration));
135-
136-
ASSERT_FALSE(IsAnimatorRunning(shell.get()));
137-
138-
// teardown.
139-
DestroyShell(std::move(shell), std::move(task_runners));
140-
ASSERT_FALSE(DartVMRef::IsInstanceRunning());
141-
}
142-
143116
TEST_F(ShellTest, AnimatorDoesNotNotifyIdleBeforeRender) {
144117
FakeAnimatorDelegate delegate;
145118
TaskRunners task_runners = {
@@ -176,7 +149,6 @@ TEST_F(ShellTest, AnimatorDoesNotNotifyIdleBeforeRender) {
176149
// Validate it has not notified idle and start it. This will request a frame.
177150
task_runners.GetUITaskRunner()->PostTask([&] {
178151
ASSERT_FALSE(delegate.notify_idle_called_);
179-
animator->Start();
180152
// Immediately request a frame saying it can reuse the last layer tree to
181153
// avoid more calls to BeginFrame by the animator.
182154
animator->RequestFrame(false);
@@ -211,8 +183,6 @@ TEST_F(ShellTest, AnimatorDoesNotNotifyIdleBeforeRender) {
211183
// Now it should notify idle. Make sure it is destroyed on the UI thread.
212184
ASSERT_TRUE(delegate.notify_idle_called_);
213185

214-
// Stop and do one more flush so we can safely clean up on the UI thread.
215-
animator->Stop();
216186
task_runners.GetPlatformTaskRunner()->PostTask(flush_vsync_task);
217187
latch.Wait();
218188

shell/common/engine.cc

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ Engine::Engine(
5050
settings_(std::move(settings)),
5151
animator_(std::move(animator)),
5252
runtime_controller_(std::move(runtime_controller)),
53-
activity_running_(true),
54-
have_surface_(false),
5553
font_collection_(font_collection),
5654
image_decoder_(task_runners, image_decoder_task_runner, io_manager),
5755
task_runners_(std::move(task_runners)),
@@ -280,30 +278,11 @@ tonic::DartErrorHandleType Engine::GetUIIsolateLastError() {
280278
return runtime_controller_->GetLastError();
281279
}
282280

283-
void Engine::OnOutputSurfaceCreated() {
284-
have_surface_ = true;
285-
ScheduleFrame();
286-
}
287-
288-
void Engine::OnOutputSurfaceDestroyed() {
289-
have_surface_ = false;
290-
StopAnimator();
291-
}
292-
293281
void Engine::SetViewportMetrics(const ViewportMetrics& metrics) {
294-
bool dimensions_changed =
295-
viewport_metrics_.physical_height != metrics.physical_height ||
296-
viewport_metrics_.physical_width != metrics.physical_width ||
297-
viewport_metrics_.device_pixel_ratio != metrics.device_pixel_ratio;
298282
viewport_metrics_ = metrics;
299283
runtime_controller_->SetViewportMetrics(viewport_metrics_);
300284
if (animator_) {
301-
if (dimensions_changed) {
302-
animator_->SetDimensionChangePending();
303-
}
304-
if (have_surface_) {
305-
ScheduleFrame();
306-
}
285+
ScheduleFrame();
307286
}
308287
}
309288

@@ -339,20 +318,12 @@ bool Engine::HandleLifecyclePlatformMessage(PlatformMessage* message) {
339318
const auto& data = message->data();
340319
std::string state(reinterpret_cast<const char*>(data.GetMapping()),
341320
data.GetSize());
342-
if (state == "AppLifecycleState.paused" ||
343-
state == "AppLifecycleState.detached") {
344-
activity_running_ = false;
345-
StopAnimator();
346-
} else if (state == "AppLifecycleState.resumed" ||
347-
state == "AppLifecycleState.inactive") {
348-
activity_running_ = true;
349-
StartAnimatorIfPossible();
350-
}
351321

352322
// Always schedule a frame when the app does become active as per API
353323
// recommendation
354324
// https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1622956-applicationdidbecomeactive?language=objc
355-
if (state == "AppLifecycleState.resumed" && have_surface_) {
325+
if (state == "AppLifecycleState.resumed" ||
326+
state == "AppLifecycleState.inactive") {
356327
ScheduleFrame();
357328
}
358329
runtime_controller_->SetLifecycleState(state);
@@ -455,16 +426,6 @@ void Engine::SetAccessibilityFeatures(int32_t flags) {
455426
runtime_controller_->SetAccessibilityFeatures(flags);
456427
}
457428

458-
void Engine::StopAnimator() {
459-
animator_->Stop();
460-
}
461-
462-
void Engine::StartAnimatorIfPossible() {
463-
if (activity_running_ && have_surface_) {
464-
animator_->Start();
465-
}
466-
}
467-
468429
std::string Engine::DefaultRouteName() {
469430
if (!initial_route_.empty()) {
470431
return initial_route_;
@@ -473,7 +434,6 @@ std::string Engine::DefaultRouteName() {
473434
}
474435

475436
void Engine::ScheduleFrame(bool regenerate_layer_tree) {
476-
StartAnimatorIfPossible();
477437
animator_->RequestFrame(regenerate_layer_tree);
478438
}
479439

shell/common/engine.h

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -658,36 +658,6 @@ class Engine final : public RuntimeDelegate, PointerDataDispatcher::Delegate {
658658
///
659659
std::optional<uint32_t> GetUIIsolateReturnCode();
660660

661-
//----------------------------------------------------------------------------
662-
/// @brief Indicates to the Flutter application that it has obtained a
663-
/// rendering surface. This is a good opportunity for the engine
664-
/// to start servicing any outstanding frame requests from the
665-
/// Flutter applications. Flutter application that have no
666-
/// rendering concerns may never get a rendering surface. In such
667-
/// cases, while their root isolate can perform as normal, any
668-
/// frame requests made by them will never be serviced and layer
669-
/// trees produced outside of frame workloads will be dropped.
670-
///
671-
/// Very close to when this call is made, the application can
672-
/// expect the updated viewport metrics. Rendering only begins
673-
/// when the Flutter application gets an output surface and a
674-
/// valid set of viewport metrics.
675-
///
676-
/// @see `OnOutputSurfaceDestroyed`
677-
///
678-
void OnOutputSurfaceCreated();
679-
680-
//----------------------------------------------------------------------------
681-
/// @brief Indicates to the Flutter application that a previously
682-
/// acquired rendering surface has been lost. Further frame
683-
/// requests will no longer be serviced and any layer tree
684-
/// submitted for rendering will be dropped. If/when a new surface
685-
/// is acquired, a new layer tree must be generated.
686-
///
687-
/// @see `OnOutputSurfaceCreated`
688-
///
689-
void OnOutputSurfaceDestroyed();
690-
691661
//----------------------------------------------------------------------------
692662
/// @brief Updates the viewport metrics for the currently running Flutter
693663
/// application. The viewport metrics detail the size of the
@@ -932,10 +902,6 @@ class Engine final : public RuntimeDelegate, PointerDataDispatcher::Delegate {
932902

933903
void SetNeedsReportTimings(bool value) override;
934904

935-
void StopAnimator();
936-
937-
void StartAnimatorIfPossible();
938-
939905
bool HandleLifecyclePlatformMessage(PlatformMessage* message);
940906

941907
bool HandleNavigationPlatformMessage(

shell/common/shell.cc

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -762,12 +762,9 @@ void Shell::OnPlatformViewCreated(std::unique_ptr<Surface> surface) {
762762
waiting_for_first_frame.store(true);
763763
});
764764

765-
// TODO(91717): This probably isn't necessary. The engine should be able to
766-
// handle things here via normal lifecycle messages.
767-
// https://github.com/flutter/flutter/issues/91717
768765
auto ui_task = [engine = engine_->GetWeakPtr()] {
769766
if (engine) {
770-
engine->OnOutputSurfaceCreated();
767+
engine->ScheduleFrame();
771768
}
772769
};
773770

@@ -863,24 +860,11 @@ void Shell::OnPlatformViewDestroyed() {
863860
rasterizer->EnableThreadMergerIfNeeded();
864861
rasterizer->Teardown();
865862
}
866-
// Step 3: Tell the IO thread to complete its remaining work.
863+
// Step 2: Tell the IO thread to complete its remaining work.
867864
fml::TaskRunner::RunNowOrPostTask(io_task_runner, io_task);
868865
};
869866

870-
// TODO(91717): This probably isn't necessary. The engine should be able to
871-
// handle things here via normal lifecycle messages.
872-
// https://github.com/flutter/flutter/issues/91717
873-
auto ui_task = [engine = engine_->GetWeakPtr()]() {
874-
if (engine) {
875-
engine->OnOutputSurfaceDestroyed();
876-
}
877-
};
878-
879-
// Step 1: Post a task onto the UI thread to tell the engine that its output
880-
// surface is about to go away.
881-
fml::TaskRunner::RunNowOrPostTask(task_runners_.GetUITaskRunner(), ui_task);
882-
883-
// Step 2: Post a task to the Raster thread (possibly this thread) to tell the
867+
// Step 1: Post a task to the Raster thread (possibly this thread) to tell the
884868
// rasterizer the output surface is going away.
885869
fml::TaskRunner::RunNowOrPostTask(task_runners_.GetRasterTaskRunner(),
886870
raster_task);

shell/common/shell_test.cc

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -385,23 +385,6 @@ void ShellTest::DestroyShell(std::unique_ptr<Shell> shell,
385385
latch.Wait();
386386
}
387387

388-
bool ShellTest::IsAnimatorRunning(Shell* shell) {
389-
fml::AutoResetWaitableEvent latch;
390-
bool running = false;
391-
if (!shell) {
392-
return running;
393-
}
394-
fml::TaskRunner::RunNowOrPostTask(
395-
shell->GetTaskRunners().GetUITaskRunner(), [shell, &running, &latch]() {
396-
if (shell && shell->engine_ && shell->engine_->animator_) {
397-
running = !shell->engine_->animator_->paused_;
398-
}
399-
latch.Signal();
400-
});
401-
latch.Wait();
402-
return running;
403-
}
404-
405388
size_t ShellTest::GetLiveTrackedPathCount(
406389
std::shared_ptr<VolatilePathTracker> tracker) {
407390
return std::count_if(

0 commit comments

Comments
 (0)