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

Commit eb381cc

Browse files
Capture the layer tree pipeline as a weak pointer in the OnAnimatorDraw task (#26210)
1 parent 74774ea commit eb381cc

File tree

9 files changed

+27
-23
lines changed

9 files changed

+27
-23
lines changed

shell/common/animator.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ Animator::Animator(Delegate& delegate,
2929
waiter_(std::move(waiter)),
3030
dart_frame_deadline_(0),
3131
#if SHELL_ENABLE_METAL
32-
layer_tree_pipeline_(fml::MakeRefCounted<LayerTreePipeline>(2)),
32+
layer_tree_pipeline_(std::make_shared<LayerTreePipeline>(2)),
3333
#else // SHELL_ENABLE_METAL
3434
// TODO(dnfield): We should remove this logic and set the pipeline depth
3535
// back to 2 in this case. See
3636
// https://github.com/flutter/engine/pull/9132 for discussion.
37-
layer_tree_pipeline_(fml::MakeRefCounted<LayerTreePipeline>(
37+
layer_tree_pipeline_(std::make_shared<LayerTreePipeline>(
3838
task_runners.GetPlatformTaskRunner() ==
3939
task_runners.GetRasterTaskRunner()
4040
? 1

shell/common/animator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Animator final {
3636
virtual void OnAnimatorNotifyIdle(int64_t deadline) = 0;
3737

3838
virtual void OnAnimatorDraw(
39-
fml::RefPtr<Pipeline<flutter::LayerTree>> pipeline,
39+
std::shared_ptr<Pipeline<flutter::LayerTree>> pipeline,
4040
std::unique_ptr<FrameTimingsRecorder> frame_timings_recorder) = 0;
4141

4242
virtual void OnAnimatorDrawLastLayerTree(
@@ -106,7 +106,7 @@ class Animator final {
106106
std::unique_ptr<FrameTimingsRecorder> frame_timings_recorder_;
107107
uint64_t frame_request_number_ = 1;
108108
int64_t dart_frame_deadline_;
109-
fml::RefPtr<LayerTreePipeline> layer_tree_pipeline_;
109+
std::shared_ptr<LayerTreePipeline> layer_tree_pipeline_;
110110
fml::Semaphore pending_frame_semaphore_;
111111
LayerTreePipeline::ProducerContinuation producer_continuation_;
112112
bool paused_;

shell/common/pipeline.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ size_t GetNextPipelineTraceID();
2727
/// A thread-safe queue of resources for a single consumer and a single
2828
/// producer.
2929
template <class R>
30-
class Pipeline : public fml::RefCountedThreadSafe<Pipeline<R>> {
30+
class Pipeline {
3131
public:
3232
using Resource = R;
3333
using ResourcePtr = std::unique_ptr<Resource>;

shell/common/pipeline_unittests.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ using IntPipeline = Pipeline<int>;
1919
using Continuation = IntPipeline::ProducerContinuation;
2020

2121
TEST(PipelineTest, ConsumeOneVal) {
22-
fml::RefPtr<IntPipeline> pipeline = fml::MakeRefCounted<IntPipeline>(2);
22+
std::shared_ptr<IntPipeline> pipeline = std::make_shared<IntPipeline>(2);
2323

2424
Continuation continuation = pipeline->Produce();
2525

@@ -34,7 +34,7 @@ TEST(PipelineTest, ConsumeOneVal) {
3434
}
3535

3636
TEST(PipelineTest, ContinuationCanOnlyBeUsedOnce) {
37-
fml::RefPtr<IntPipeline> pipeline = fml::MakeRefCounted<IntPipeline>(2);
37+
std::shared_ptr<IntPipeline> pipeline = std::make_shared<IntPipeline>(2);
3838

3939
Continuation continuation = pipeline->Produce();
4040

@@ -59,7 +59,7 @@ TEST(PipelineTest, ContinuationCanOnlyBeUsedOnce) {
5959

6060
TEST(PipelineTest, PushingMoreThanDepthCompletesFirstSubmission) {
6161
const int depth = 1;
62-
fml::RefPtr<IntPipeline> pipeline = fml::MakeRefCounted<IntPipeline>(depth);
62+
std::shared_ptr<IntPipeline> pipeline = std::make_shared<IntPipeline>(depth);
6363

6464
Continuation continuation_1 = pipeline->Produce();
6565
Continuation continuation_2 = pipeline->Produce();
@@ -78,7 +78,7 @@ TEST(PipelineTest, PushingMoreThanDepthCompletesFirstSubmission) {
7878

7979
TEST(PipelineTest, PushingMultiProcessesInOrder) {
8080
const int depth = 2;
81-
fml::RefPtr<IntPipeline> pipeline = fml::MakeRefCounted<IntPipeline>(depth);
81+
std::shared_ptr<IntPipeline> pipeline = std::make_shared<IntPipeline>(depth);
8282

8383
Continuation continuation_1 = pipeline->Produce();
8484
Continuation continuation_2 = pipeline->Produce();
@@ -100,7 +100,7 @@ TEST(PipelineTest, PushingMultiProcessesInOrder) {
100100

101101
TEST(PipelineTest, ProduceIfEmptyDoesNotConsumeWhenQueueIsNotEmpty) {
102102
const int depth = 2;
103-
fml::RefPtr<IntPipeline> pipeline = fml::MakeRefCounted<IntPipeline>(depth);
103+
std::shared_ptr<IntPipeline> pipeline = std::make_shared<IntPipeline>(depth);
104104

105105
Continuation continuation_1 = pipeline->Produce();
106106
Continuation continuation_2 = pipeline->ProduceIfEmpty();
@@ -118,7 +118,7 @@ TEST(PipelineTest, ProduceIfEmptyDoesNotConsumeWhenQueueIsNotEmpty) {
118118

119119
TEST(PipelineTest, ProduceIfEmptySuccessfulIfQueueIsEmpty) {
120120
const int depth = 1;
121-
fml::RefPtr<IntPipeline> pipeline = fml::MakeRefCounted<IntPipeline>(depth);
121+
std::shared_ptr<IntPipeline> pipeline = std::make_shared<IntPipeline>(depth);
122122

123123
Continuation continuation_1 = pipeline->ProduceIfEmpty();
124124

shell/common/rasterizer.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ void Rasterizer::DrawLastLayerTree(
158158

159159
void Rasterizer::Draw(
160160
std::unique_ptr<FrameTimingsRecorder> frame_timings_recorder,
161-
fml::RefPtr<Pipeline<flutter::LayerTree>> pipeline,
161+
std::shared_ptr<Pipeline<flutter::LayerTree>> pipeline,
162162
LayerTreeDiscardCallback discardCallback) {
163163
TRACE_EVENT_WITH_FRAME_NUMBER(frame_timings_recorder, "flutter",
164164
"GPURasterizer::Draw");

shell/common/rasterizer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ class Rasterizer final : public SnapshotDelegate {
244244
/// is discarded instead of being rendered
245245
///
246246
void Draw(std::unique_ptr<FrameTimingsRecorder> frame_timings_recorder,
247-
fml::RefPtr<Pipeline<flutter::LayerTree>> pipeline,
247+
std::shared_ptr<Pipeline<flutter::LayerTree>> pipeline,
248248
LayerTreeDiscardCallback discardCallback = NoDiscard);
249249

250250
//----------------------------------------------------------------------------

shell/common/rasterizer_unittests.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ TEST(RasterizerTest, drawEmptyPipeline) {
105105
rasterizer->Setup(std::move(surface));
106106
fml::AutoResetWaitableEvent latch;
107107
thread_host.raster_thread->GetTaskRunner()->PostTask([&] {
108-
auto pipeline = fml::AdoptRef(new Pipeline<LayerTree>(/*depth=*/10));
108+
auto pipeline = std::make_shared<Pipeline<LayerTree>>(/*depth=*/10);
109109
rasterizer->Draw(CreateFinishedBuildRecorder(), pipeline, nullptr);
110110
latch.Signal();
111111
});
@@ -157,7 +157,7 @@ TEST(RasterizerTest,
157157
rasterizer->Setup(std::move(surface));
158158
fml::AutoResetWaitableEvent latch;
159159
thread_host.raster_thread->GetTaskRunner()->PostTask([&] {
160-
auto pipeline = fml::AdoptRef(new Pipeline<LayerTree>(/*depth=*/10));
160+
auto pipeline = std::make_shared<Pipeline<LayerTree>>(/*depth=*/10);
161161
auto layer_tree = std::make_unique<LayerTree>(/*frame_size=*/SkISize(),
162162
/*device_pixel_ratio=*/2.0f);
163163
bool result = pipeline->Produce().Complete(std::move(layer_tree));
@@ -211,7 +211,7 @@ TEST(
211211
rasterizer->Setup(std::move(surface));
212212
fml::AutoResetWaitableEvent latch;
213213
thread_host.raster_thread->GetTaskRunner()->PostTask([&] {
214-
auto pipeline = fml::AdoptRef(new Pipeline<LayerTree>(/*depth=*/10));
214+
auto pipeline = std::make_shared<Pipeline<LayerTree>>(/*depth=*/10);
215215
auto layer_tree = std::make_unique<LayerTree>(/*frame_size=*/SkISize(),
216216
/*device_pixel_ratio=*/2.0f);
217217
bool result = pipeline->Produce().Complete(std::move(layer_tree));
@@ -270,7 +270,7 @@ TEST(
270270

271271
rasterizer->Setup(std::move(surface));
272272

273-
auto pipeline = fml::AdoptRef(new Pipeline<LayerTree>(/*depth=*/10));
273+
auto pipeline = std::make_shared<Pipeline<LayerTree>>(/*depth=*/10);
274274
auto layer_tree = std::make_unique<LayerTree>(/*frame_size=*/SkISize(),
275275
/*device_pixel_ratio=*/2.0f);
276276
bool result = pipeline->Produce().Complete(std::move(layer_tree));
@@ -307,7 +307,7 @@ TEST(RasterizerTest, externalViewEmbedderDoesntEndFrameWhenNoSurfaceIsSet) {
307307

308308
fml::AutoResetWaitableEvent latch;
309309
thread_host.raster_thread->GetTaskRunner()->PostTask([&] {
310-
auto pipeline = fml::AdoptRef(new Pipeline<LayerTree>(/*depth=*/10));
310+
auto pipeline = std::make_shared<Pipeline<LayerTree>>(/*depth=*/10);
311311
auto no_discard = [](LayerTree&) { return false; };
312312
rasterizer->Draw(CreateFinishedBuildRecorder(), pipeline, no_discard);
313313
latch.Signal();

shell/common/shell.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,7 @@ void Shell::OnAnimatorNotifyIdle(int64_t deadline) {
11281128

11291129
// |Animator::Delegate|
11301130
void Shell::OnAnimatorDraw(
1131-
fml::RefPtr<Pipeline<flutter::LayerTree>> pipeline,
1131+
std::shared_ptr<Pipeline<flutter::LayerTree>> pipeline,
11321132
std::unique_ptr<FrameTimingsRecorder> frame_timings_recorder) {
11331133
FML_DCHECK(is_setup_);
11341134

@@ -1153,12 +1153,16 @@ void Shell::OnAnimatorDraw(
11531153
task_runners_.GetRasterTaskRunner()->PostTask(fml::MakeCopyable(
11541154
[&waiting_for_first_frame = waiting_for_first_frame_,
11551155
&waiting_for_first_frame_condition = waiting_for_first_frame_condition_,
1156-
rasterizer = rasterizer_->GetWeakPtr(), pipeline = std::move(pipeline),
1156+
rasterizer = rasterizer_->GetWeakPtr(),
1157+
weak_pipeline = std::weak_ptr<Pipeline<LayerTree>>(pipeline),
11571158
discard_callback = std::move(discard_callback),
11581159
frame_timings_recorder = std::move(frame_timings_recorder)]() mutable {
11591160
if (rasterizer) {
1160-
rasterizer->Draw(std::move(frame_timings_recorder), pipeline,
1161-
std::move(discard_callback));
1161+
std::shared_ptr<Pipeline<LayerTree>> pipeline = weak_pipeline.lock();
1162+
if (pipeline) {
1163+
rasterizer->Draw(std::move(frame_timings_recorder),
1164+
std::move(pipeline), std::move(discard_callback));
1165+
}
11621166

11631167
if (waiting_for_first_frame.load()) {
11641168
waiting_for_first_frame.store(false);

shell/common/shell.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ class Shell final : public PlatformView::Delegate,
539539

540540
// |Animator::Delegate|
541541
void OnAnimatorDraw(
542-
fml::RefPtr<Pipeline<flutter::LayerTree>> pipeline,
542+
std::shared_ptr<Pipeline<flutter::LayerTree>> pipeline,
543543
std::unique_ptr<FrameTimingsRecorder> frame_timings_recorder) override;
544544

545545
// |Animator::Delegate|

0 commit comments

Comments
 (0)