Skip to content

Commit 6d44559

Browse files
authored
Remove the dummy rasterizer delegate now that flutter_runner is in tree, and cleanup ctor params (flutter#20486)
1 parent 0c504da commit 6d44559

File tree

12 files changed

+38
-118
lines changed

12 files changed

+38
-118
lines changed

shell/common/animator_unittests.cc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,7 @@ TEST_F(ShellTest, VSyncTargetTime) {
5858
std::move(create_vsync_waiter),
5959
ShellTestPlatformView::BackendType::kDefaultBackend, nullptr);
6060
},
61-
[](Shell& shell) {
62-
return std::make_unique<Rasterizer>(
63-
shell, shell.GetTaskRunners(),
64-
shell.GetIsGpuDisabledSyncSwitch());
65-
});
61+
[](Shell& shell) { return std::make_unique<Rasterizer>(shell); });
6662
ASSERT_TRUE(DartVMRef::IsInstanceRunning());
6763

6864
auto configuration = RunConfiguration::InferFromSettings(settings);

shell/common/rasterizer.cc

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,38 +25,18 @@ namespace flutter {
2525
// used within this interval.
2626
static constexpr std::chrono::milliseconds kSkiaCleanupExpiration(15000);
2727

28-
// TODO(dnfield): Remove this once internal embedders have caught up.
29-
static Rasterizer::DummyDelegate dummy_delegate_;
30-
Rasterizer::Rasterizer(
31-
TaskRunners task_runners,
32-
std::unique_ptr<flutter::CompositorContext> compositor_context,
33-
std::shared_ptr<fml::SyncSwitch> is_gpu_disabled_sync_switch)
34-
: Rasterizer(dummy_delegate_,
35-
std::move(task_runners),
36-
std::move(compositor_context),
37-
is_gpu_disabled_sync_switch) {}
38-
39-
Rasterizer::Rasterizer(
40-
Delegate& delegate,
41-
TaskRunners task_runners,
42-
std::shared_ptr<fml::SyncSwitch> is_gpu_disabled_sync_switch)
28+
Rasterizer::Rasterizer(Delegate& delegate)
4329
: Rasterizer(delegate,
44-
std::move(task_runners),
4530
std::make_unique<flutter::CompositorContext>(
46-
delegate.GetFrameBudget()),
47-
is_gpu_disabled_sync_switch) {}
31+
delegate.GetFrameBudget())) {}
4832

4933
Rasterizer::Rasterizer(
5034
Delegate& delegate,
51-
TaskRunners task_runners,
52-
std::unique_ptr<flutter::CompositorContext> compositor_context,
53-
std::shared_ptr<fml::SyncSwitch> is_gpu_disabled_sync_switch)
35+
std::unique_ptr<flutter::CompositorContext> compositor_context)
5436
: delegate_(delegate),
55-
task_runners_(std::move(task_runners)),
5637
compositor_context_(std::move(compositor_context)),
5738
user_override_resource_cache_bytes_(false),
58-
weak_factory_(this),
59-
is_gpu_disabled_sync_switch_(is_gpu_disabled_sync_switch) {
39+
weak_factory_(this) {
6040
FML_DCHECK(compositor_context_);
6141
}
6242

@@ -83,8 +63,9 @@ void Rasterizer::Setup(std::unique_ptr<Surface> surface) {
8363
// support for raster thread merger for Fuchsia.
8464
if (surface_->GetExternalViewEmbedder()) {
8565
const auto platform_id =
86-
task_runners_.GetPlatformTaskRunner()->GetTaskQueueId();
87-
const auto gpu_id = task_runners_.GetRasterTaskRunner()->GetTaskQueueId();
66+
delegate_.GetTaskRunners().GetPlatformTaskRunner()->GetTaskQueueId();
67+
const auto gpu_id =
68+
delegate_.GetTaskRunners().GetRasterTaskRunner()->GetTaskQueueId();
8869
raster_thread_merger_ =
8970
fml::MakeRefCounted<fml::RasterThreadMerger>(platform_id, gpu_id);
9071
}
@@ -134,7 +115,9 @@ void Rasterizer::Draw(fml::RefPtr<Pipeline<flutter::LayerTree>> pipeline) {
134115
// we yield and let this frame be serviced on the right thread.
135116
return;
136117
}
137-
FML_DCHECK(task_runners_.GetRasterTaskRunner()->RunsTasksOnCurrentThread());
118+
FML_DCHECK(delegate_.GetTaskRunners()
119+
.GetRasterTaskRunner()
120+
->RunsTasksOnCurrentThread());
138121

139122
RasterStatus raster_status = RasterStatus::kFailed;
140123
Pipeline<flutter::LayerTree>::Consumer consumer =
@@ -168,7 +151,7 @@ void Rasterizer::Draw(fml::RefPtr<Pipeline<flutter::LayerTree>> pipeline) {
168151
// between successive tries.
169152
switch (consume_result) {
170153
case PipelineConsumeResult::MoreAvailable: {
171-
task_runners_.GetRasterTaskRunner()->PostTask(
154+
delegate_.GetTaskRunners().GetRasterTaskRunner()->PostTask(
172155
[weak_this = weak_factory_.GetWeakPtr(), pipeline]() {
173156
if (weak_this) {
174157
weak_this->Draw(pipeline);
@@ -226,7 +209,7 @@ sk_sp<SkImage> Rasterizer::DoMakeRasterSnapshot(
226209
sk_sp<SkSurface> surface = SkSurface::MakeRaster(image_info);
227210
result = DrawSnapshot(surface, draw_callback);
228211
} else {
229-
is_gpu_disabled_sync_switch_->Execute(
212+
delegate_.GetIsGpuDisabledSyncSwitch()->Execute(
230213
fml::SyncSwitch::Handlers()
231214
.SetIfTrue([&] {
232215
sk_sp<SkSurface> surface = SkSurface::MakeRaster(image_info);
@@ -282,7 +265,9 @@ sk_sp<SkImage> Rasterizer::ConvertToRasterImage(sk_sp<SkImage> image) {
282265

283266
RasterStatus Rasterizer::DoDraw(
284267
std::unique_ptr<flutter::LayerTree> layer_tree) {
285-
FML_DCHECK(task_runners_.GetRasterTaskRunner()->RunsTasksOnCurrentThread());
268+
FML_DCHECK(delegate_.GetTaskRunners()
269+
.GetRasterTaskRunner()
270+
->RunsTasksOnCurrentThread());
286271

287272
if (!layer_tree || !surface_) {
288273
return RasterStatus::kFailed;

shell/common/rasterizer.h

Lines changed: 12 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -74,82 +74,41 @@ class Rasterizer final : public SnapshotDelegate {
7474
/// Target time for the latest frame. See also `Shell::OnAnimatorBeginFrame`
7575
/// for when this time gets updated.
7676
virtual fml::TimePoint GetLatestFrameTargetTime() const = 0;
77-
};
7877

79-
// TODO(dnfield): remove once embedders have caught up.
80-
class DummyDelegate : public Delegate {
81-
void OnFrameRasterized(const FrameTiming&) override {}
82-
fml::Milliseconds GetFrameBudget() override {
83-
return fml::kDefaultFrameBudget;
84-
}
85-
// Returning a time in the past so we don't add additional trace
86-
// events when exceeding the frame budget for other embedders.
87-
fml::TimePoint GetLatestFrameTargetTime() const override {
88-
return fml::TimePoint::FromEpochDelta(fml::TimeDelta::Zero());
89-
}
90-
};
78+
/// Task runners used by the shell.
79+
virtual const TaskRunners& GetTaskRunners() const = 0;
9180

92-
//----------------------------------------------------------------------------
93-
/// @brief Creates a new instance of a rasterizer. Rasterizers may only
94-
/// be created on the GPU task runner. Rasterizers are currently
95-
/// only created by the shell. Usually, the shell also sets itself
96-
/// up as the rasterizer delegate. But, this constructor sets up a
97-
/// dummy rasterizer delegate.
98-
///
99-
// TODO(chinmaygarde): The rasterizer does not use the task runners for
100-
// anything other than thread checks. Remove the same as an argument.
101-
///
102-
/// @param[in] task_runners The task runners used by the shell.
103-
/// @param[in] compositor_context The compositor context used to hold all
104-
/// the GPU state used by the rasterizer.
105-
/// @param[in] is_gpu_disabled_sync_switch
106-
/// A `SyncSwitch` for handling disabling of the GPU (typically happens
107-
/// when an app is backgrounded)
108-
///
109-
Rasterizer(TaskRunners task_runners,
110-
std::unique_ptr<flutter::CompositorContext> compositor_context,
111-
std::shared_ptr<fml::SyncSwitch> is_gpu_disabled_sync_switch);
81+
/// Accessor for the shell's GPU sync switch, which determines whether GPU
82+
/// operations are allowed on the current thread.
83+
///
84+
/// For example, on some platforms when the application is backgrounded it
85+
/// is critical that GPU operations are not processed.
86+
virtual std::shared_ptr<fml::SyncSwitch> GetIsGpuDisabledSyncSwitch()
87+
const = 0;
88+
};
11289

11390
//----------------------------------------------------------------------------
11491
/// @brief Creates a new instance of a rasterizer. Rasterizers may only
11592
/// be created on the GPU task runner. Rasterizers are currently
11693
/// only created by the shell (which also sets itself up as the
11794
/// rasterizer delegate).
11895
///
119-
// TODO(chinmaygarde): The rasterizer does not use the task runners for
120-
// anything other than thread checks. Remove the same as an argument.
121-
///
12296
/// @param[in] delegate The rasterizer delegate.
123-
/// @param[in] task_runners The task runners used by the shell.
124-
/// @param[in] is_gpu_disabled_sync_switch
125-
/// A `SyncSwitch` for handling disabling of the GPU (typically happens
126-
/// when an app is backgrounded)
12797
///
128-
Rasterizer(Delegate& delegate,
129-
TaskRunners task_runners,
130-
std::shared_ptr<fml::SyncSwitch> is_gpu_disabled_sync_switch);
98+
Rasterizer(Delegate& delegate);
13199

132100
//----------------------------------------------------------------------------
133101
/// @brief Creates a new instance of a rasterizer. Rasterizers may only
134102
/// be created on the GPU task runner. Rasterizers are currently
135103
/// only created by the shell (which also sets itself up as the
136104
/// rasterizer delegate).
137105
///
138-
// TODO(chinmaygarde): The rasterizer does not use the task runners for
139-
// anything other than thread checks. Remove the same as an argument.
140-
///
141106
/// @param[in] delegate The rasterizer delegate.
142-
/// @param[in] task_runners The task runners used by the shell.
143107
/// @param[in] compositor_context The compositor context used to hold all
144108
/// the GPU state used by the rasterizer.
145-
/// @param[in] is_gpu_disabled_sync_switch
146-
/// A `SyncSwitch` for handling disabling of the GPU (typically happens
147-
/// when an app is backgrounded)
148109
///
149110
Rasterizer(Delegate& delegate,
150-
TaskRunners task_runners,
151-
std::unique_ptr<flutter::CompositorContext> compositor_context,
152-
std::shared_ptr<fml::SyncSwitch> is_gpu_disabled_sync_switch);
111+
std::unique_ptr<flutter::CompositorContext> compositor_context);
153112

154113
//----------------------------------------------------------------------------
155114
/// @brief Destroys the rasterizer. This must happen on the GPU task
@@ -432,7 +391,6 @@ class Rasterizer final : public SnapshotDelegate {
432391

433392
private:
434393
Delegate& delegate_;
435-
TaskRunners task_runners_;
436394
std::unique_ptr<Surface> surface_;
437395
std::unique_ptr<flutter::CompositorContext> compositor_context_;
438396
// This is the last successfully rasterized layer tree.
@@ -446,7 +404,6 @@ class Rasterizer final : public SnapshotDelegate {
446404
std::optional<size_t> max_cache_bytes_;
447405
fml::TaskRunnerAffineWeakPtrFactory<Rasterizer> weak_factory_;
448406
fml::RefPtr<fml::RasterThreadMerger> raster_thread_merger_;
449-
std::shared_ptr<fml::SyncSwitch> is_gpu_disabled_sync_switch_;
450407

451408
// |SnapshotDelegate|
452409
sk_sp<SkImage> MakeRasterSnapshot(sk_sp<SkPicture> picture,

shell/common/shell.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ class Shell final : public PlatformView::Delegate,
248248
///
249249
/// @return The task runners current in use by the shell.
250250
///
251-
const TaskRunners& GetTaskRunners() const;
251+
const TaskRunners& GetTaskRunners() const override;
252252

253253
//----------------------------------------------------------------------------
254254
/// @brief Rasterizers may only be accessed on the GPU task runner.
@@ -352,7 +352,7 @@ class Shell final : public PlatformView::Delegate,
352352

353353
//----------------------------------------------------------------------------
354354
/// @brief Accessor for the disable GPU SyncSwitch
355-
std::shared_ptr<fml::SyncSwitch> GetIsGpuDisabledSyncSwitch() const;
355+
std::shared_ptr<fml::SyncSwitch> GetIsGpuDisabledSyncSwitch() const override;
356356

357357
//----------------------------------------------------------------------------
358358
/// @brief Get a pointer to the Dart VM used by this running shell

shell/common/shell_benchmarks.cc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,7 @@ static void StartupAndShutdownShell(benchmark::State& state,
5858
[](Shell& shell) {
5959
return std::make_unique<PlatformView>(shell, shell.GetTaskRunners());
6060
},
61-
[](Shell& shell) {
62-
return std::make_unique<Rasterizer>(
63-
shell, shell.GetTaskRunners(),
64-
shell.GetIsGpuDisabledSyncSwitch());
65-
});
61+
[](Shell& shell) { return std::make_unique<Rasterizer>(shell); });
6662
}
6763

6864
FML_CHECK(shell);

shell/common/shell_test.cc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,7 @@ std::unique_ptr<Shell> ShellTest::CreateShell(
268268
ShellTestPlatformView::BackendType::kDefaultBackend,
269269
shell_test_external_view_embedder);
270270
},
271-
[](Shell& shell) {
272-
return std::make_unique<Rasterizer>(shell, shell.GetTaskRunners(),
273-
shell.GetIsGpuDisabledSyncSwitch());
274-
});
271+
[](Shell& shell) { return std::make_unique<Rasterizer>(shell); });
275272
}
276273
void ShellTest::DestroyShell(std::unique_ptr<Shell> shell) {
277274
DestroyShell(std::move(shell), GetTaskRunnersForFixture());

shell/common/shell_unittests.cc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,7 @@ TEST_F(ShellTest,
149149
},
150150
ShellTestPlatformView::BackendType::kDefaultBackend, nullptr);
151151
},
152-
[](Shell& shell) {
153-
return std::make_unique<Rasterizer>(shell, shell.GetTaskRunners(),
154-
shell.GetIsGpuDisabledSyncSwitch());
155-
});
152+
[](Shell& shell) { return std::make_unique<Rasterizer>(shell); });
156153
ASSERT_TRUE(ValidateShell(shell.get()));
157154
ASSERT_TRUE(DartVMRef::IsInstanceRunning());
158155
DestroyShell(std::move(shell), std::move(task_runners));

shell/platform/android/android_shell_holder.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ AndroidShellHolder::AndroidShellHolder(
8181
};
8282

8383
Shell::CreateCallback<Rasterizer> on_create_rasterizer = [](Shell& shell) {
84-
return std::make_unique<Rasterizer>(shell, shell.GetTaskRunners(),
85-
shell.GetIsGpuDisabledSyncSwitch());
84+
return std::make_unique<Rasterizer>(shell);
8685
};
8786

8887
// The current thread will be used as the platform thread. Ensure that the

shell/platform/darwin/ios/framework/Source/FlutterEngine.mm

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -506,10 +506,7 @@ - (BOOL)createShell:(NSString*)entrypoint
506506
};
507507

508508
flutter::Shell::CreateCallback<flutter::Rasterizer> on_create_rasterizer =
509-
[](flutter::Shell& shell) {
510-
return std::make_unique<flutter::Rasterizer>(shell, shell.GetTaskRunners(),
511-
shell.GetIsGpuDisabledSyncSwitch());
512-
};
509+
[](flutter::Shell& shell) { return std::make_unique<flutter::Rasterizer>(shell); };
513510

514511
if (flutter::IsIosEmbeddedViewsPreviewEnabled()) {
515512
// Embedded views requires the gpu and the platform views to be the same.

shell/platform/embedder/embedder.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -991,8 +991,7 @@ FlutterEngineResult FlutterEngineInitialize(size_t version,
991991

992992
flutter::Shell::CreateCallback<flutter::Rasterizer> on_create_rasterizer =
993993
[](flutter::Shell& shell) {
994-
return std::make_unique<flutter::Rasterizer>(
995-
shell, shell.GetTaskRunners(), shell.GetIsGpuDisabledSyncSwitch());
994+
return std::make_unique<flutter::Rasterizer>(shell);
996995
};
997996

998997
// TODO(chinmaygarde): This is the wrong spot for this. It belongs in the

shell/platform/fuchsia/flutter/engine.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,7 @@ Engine::Engine(Delegate& delegate,
230230
}
231231

232232
return std::make_unique<flutter::Rasterizer>(
233-
/*task_runners=*/shell.GetTaskRunners(),
234-
/*compositor_context=*/std::move(compositor_context),
235-
/*is_gpu_disabled_sync_switch=*/shell.GetIsGpuDisabledSyncSwitch());
233+
shell, std::move(compositor_context));
236234
});
237235

238236
UpdateNativeThreadLabelNames(thread_label_, task_runners);

shell/testing/tester_main.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,7 @@ int RunTester(const flutter::Settings& settings,
140140
};
141141

142142
Shell::CreateCallback<Rasterizer> on_create_rasterizer = [](Shell& shell) {
143-
return std::make_unique<Rasterizer>(shell, shell.GetTaskRunners(),
144-
shell.GetIsGpuDisabledSyncSwitch());
143+
return std::make_unique<Rasterizer>(shell);
145144
};
146145

147146
auto shell = Shell::Create(task_runners, //

0 commit comments

Comments
 (0)