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

Commit 04afdad

Browse files
authored
Revert "Reland "Remove pipeline in favor of layer tree holder (#18901)" (#24387)" (#24456)
This reverts commit f3fe33b.
1 parent cd686a1 commit 04afdad

17 files changed

+536
-281
lines changed

ci/licenses_golden/licenses_flutter

+3-3
Original file line numberDiff line numberDiff line change
@@ -638,10 +638,10 @@ FILE: ../../../flutter/shell/common/engine_unittests.cc
638638
FILE: ../../../flutter/shell/common/fixtures/shell_test.dart
639639
FILE: ../../../flutter/shell/common/fixtures/shelltest_screenshot.png
640640
FILE: ../../../flutter/shell/common/input_events_unittests.cc
641-
FILE: ../../../flutter/shell/common/layer_tree_holder.cc
642-
FILE: ../../../flutter/shell/common/layer_tree_holder.h
643-
FILE: ../../../flutter/shell/common/layer_tree_holder_unittests.cc
644641
FILE: ../../../flutter/shell/common/persistent_cache_unittests.cc
642+
FILE: ../../../flutter/shell/common/pipeline.cc
643+
FILE: ../../../flutter/shell/common/pipeline.h
644+
FILE: ../../../flutter/shell/common/pipeline_unittests.cc
645645
FILE: ../../../flutter/shell/common/platform_view.cc
646646
FILE: ../../../flutter/shell/common/platform_view.h
647647
FILE: ../../../flutter/shell/common/pointer_data_dispatcher.cc

shell/common/BUILD.gn

+3-3
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ source_set("common") {
6969
"display_manager.h",
7070
"engine.cc",
7171
"engine.h",
72-
"layer_tree_holder.cc",
73-
"layer_tree_holder.h",
72+
"pipeline.cc",
73+
"pipeline.h",
7474
"platform_view.cc",
7575
"platform_view.h",
7676
"pointer_data_dispatcher.cc",
@@ -242,8 +242,8 @@ if (enable_unittests) {
242242
"canvas_spy_unittests.cc",
243243
"engine_unittests.cc",
244244
"input_events_unittests.cc",
245-
"layer_tree_holder_unittests.cc",
246245
"persistent_cache_unittests.cc",
246+
"pipeline_unittests.cc",
247247
"rasterizer_unittests.cc",
248248
"shell_unittests.cc",
249249
"skp_shader_warmup_unittests.cc",

shell/common/animator.cc

+40-4
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,27 @@ Animator::Animator(Delegate& delegate,
2929
last_vsync_start_time_(),
3030
last_frame_target_time_(),
3131
dart_frame_deadline_(0),
32-
layer_tree_holder_(std::make_shared<LayerTreeHolder>()),
32+
#if SHELL_ENABLE_METAL
33+
layer_tree_pipeline_(fml::MakeRefCounted<LayerTreePipeline>(2)),
34+
#else // SHELL_ENABLE_METAL
35+
// TODO(dnfield): We should remove this logic and set the pipeline depth
36+
// back to 2 in this case. See
37+
// https://github.com/flutter/engine/pull/9132 for discussion.
38+
layer_tree_pipeline_(fml::MakeRefCounted<LayerTreePipeline>(
39+
task_runners.GetPlatformTaskRunner() ==
40+
task_runners.GetRasterTaskRunner()
41+
? 1
42+
: 2)),
43+
#endif // SHELL_ENABLE_METAL
3344
pending_frame_semaphore_(1),
3445
frame_number_(1),
3546
paused_(false),
3647
regenerate_layer_tree_(false),
3748
frame_scheduled_(false),
3849
notify_idle_task_id_(0),
3950
dimension_change_pending_(false),
40-
weak_factory_(this) {}
51+
weak_factory_(this) {
52+
}
4153

4254
Animator::~Animator() = default;
4355

@@ -99,6 +111,25 @@ void Animator::BeginFrame(fml::TimePoint vsync_start_time,
99111
regenerate_layer_tree_ = false;
100112
pending_frame_semaphore_.Signal();
101113

114+
if (!producer_continuation_) {
115+
// We may already have a valid pipeline continuation in case a previous
116+
// begin frame did not result in an Animation::Render. Simply reuse that
117+
// instead of asking the pipeline for a fresh continuation.
118+
producer_continuation_ = layer_tree_pipeline_->Produce();
119+
120+
if (!producer_continuation_) {
121+
// If we still don't have valid continuation, the pipeline is currently
122+
// full because the consumer is being too slow. Try again at the next
123+
// frame interval.
124+
RequestFrame();
125+
return;
126+
}
127+
}
128+
129+
// We have acquired a valid continuation from the pipeline and are ready
130+
// to service potential frame.
131+
FML_DCHECK(producer_continuation_);
132+
102133
last_frame_begin_time_ = fml::TimePoint::Now();
103134
last_vsync_start_time_ = vsync_start_time;
104135
fml::tracing::TraceEventAsyncComplete("flutter", "VsyncSchedulingOverhead",
@@ -152,8 +183,13 @@ void Animator::Render(std::unique_ptr<flutter::LayerTree> layer_tree) {
152183
layer_tree->RecordBuildTime(last_vsync_start_time_, last_frame_begin_time_,
153184
last_frame_target_time_);
154185

155-
layer_tree_holder_->PushIfNewer(std::move(layer_tree));
156-
delegate_.OnAnimatorDraw(layer_tree_holder_, last_frame_target_time_);
186+
// Commit the pending continuation.
187+
bool result = producer_continuation_.Complete(std::move(layer_tree));
188+
if (!result) {
189+
FML_DLOG(INFO) << "No pending continuation to commit";
190+
}
191+
192+
delegate_.OnAnimatorDraw(layer_tree_pipeline_, last_frame_target_time_);
157193
}
158194

159195
bool Animator::CanReuseLastLayerTree() {

shell/common/animator.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66
#define FLUTTER_SHELL_COMMON_ANIMATOR_H_
77

88
#include <deque>
9-
#include <memory>
109

1110
#include "flutter/common/task_runners.h"
1211
#include "flutter/fml/memory/ref_ptr.h"
1312
#include "flutter/fml/memory/weak_ptr.h"
1413
#include "flutter/fml/synchronization/semaphore.h"
1514
#include "flutter/fml/time/time_point.h"
16-
#include "flutter/shell/common/layer_tree_holder.h"
15+
#include "flutter/shell/common/pipeline.h"
1716
#include "flutter/shell/common/rasterizer.h"
1817
#include "flutter/shell/common/vsync_waiter.h"
1918

@@ -36,7 +35,7 @@ class Animator final {
3635
virtual void OnAnimatorNotifyIdle(int64_t deadline) = 0;
3736

3837
virtual void OnAnimatorDraw(
39-
std::shared_ptr<LayerTreeHolder> layer_tree_holder,
38+
fml::RefPtr<Pipeline<flutter::LayerTree>> pipeline,
4039
fml::TimePoint frame_target_time) = 0;
4140

4241
virtual void OnAnimatorDrawLastLayerTree() = 0;
@@ -80,6 +79,8 @@ class Animator final {
8079
void EnqueueTraceFlowId(uint64_t trace_flow_id);
8180

8281
private:
82+
using LayerTreePipeline = Pipeline<flutter::LayerTree>;
83+
8384
void BeginFrame(fml::TimePoint frame_start_time,
8485
fml::TimePoint frame_target_time);
8586

@@ -98,8 +99,9 @@ class Animator final {
9899
fml::TimePoint last_vsync_start_time_;
99100
fml::TimePoint last_frame_target_time_;
100101
int64_t dart_frame_deadline_;
101-
std::shared_ptr<LayerTreeHolder> layer_tree_holder_;
102+
fml::RefPtr<LayerTreePipeline> layer_tree_pipeline_;
102103
fml::Semaphore pending_frame_semaphore_;
104+
LayerTreePipeline::ProducerContinuation producer_continuation_;
103105
int64_t frame_number_;
104106
bool paused_;
105107
bool regenerate_layer_tree_;

shell/common/engine.h

+14-7
Original file line numberDiff line numberDiff line change
@@ -476,18 +476,25 @@ class Engine final : public RuntimeDelegate,
476476
/// will cause the jank in the Flutter application:
477477
/// * The time taken by this method to create a layer-tree exceeds
478478
/// on frame interval (for example, 16.66 ms on a 60Hz display).
479-
/// * A new layer-tree produced by this method replaces a stale
480-
/// layer tree in `LayerTreeHolder`. See:
481-
/// `LayerTreeHolder::ReplaceIfNewer`. This could happen if
482-
/// rasterizer takes more than one frame interval to rasterize a
483-
/// layer tree. This would cause some frames to be skipped and
484-
/// could result in perceptible jank.
479+
/// * The time take by this method to generate a new layer-tree
480+
/// causes the current layer-tree pipeline depth to change. To
481+
/// illustrate this point, note that maximum pipeline depth used
482+
/// by layer tree in the engine is 2. If both the UI and GPU
483+
/// task runner tasks finish within one frame interval, the
484+
/// pipeline depth is one. If the UI thread happens to be
485+
/// working on a frame when the raster thread is still not done
486+
/// with the previous frame, the pipeline depth is 2. When the
487+
/// pipeline depth changes from 1 to 2, animations and UI
488+
/// interactions that cause the generation of the new layer tree
489+
/// appropriate for (frame_time + one frame interval) will
490+
/// actually end up at (frame_time + two frame intervals). This
491+
/// is not what code running on the UI thread expected would
492+
/// happen. This causes perceptible jank.
485493
///
486494
/// @param[in] frame_time The point at which the current frame interval
487495
/// began. May be used by animation interpolators,
488496
/// physics simulations, etc..
489497
///
490-
/// @see `LayerTreeHolder::ReplaceIfNewer`
491498
void BeginFrame(fml::TimePoint frame_time);
492499

493500
// |HintFreedDelegate|

shell/common/layer_tree_holder.cc

-32
This file was deleted.

shell/common/layer_tree_holder.h

-55
This file was deleted.

shell/common/layer_tree_holder_unittests.cc

-76
This file was deleted.

shell/common/pipeline.cc

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "flutter/shell/common/pipeline.h"
6+
7+
namespace flutter {
8+
9+
size_t GetNextPipelineTraceID() {
10+
static std::atomic_size_t PipelineLastTraceID = {0};
11+
return ++PipelineLastTraceID;
12+
}
13+
14+
} // namespace flutter

0 commit comments

Comments
 (0)