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

Commit 07e2520

Browse files
authored
fuchsia: create new flutter_runner render path (#19584)
1 parent 80a1cac commit 07e2520

12 files changed

+872
-245
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,8 @@ FILE: ../../../flutter/shell/platform/fuchsia/flutter/engine.h
11621162
FILE: ../../../flutter/shell/platform/fuchsia/flutter/flutter_runner_fakes.h
11631163
FILE: ../../../flutter/shell/platform/fuchsia/flutter/flutter_runner_product_configuration.cc
11641164
FILE: ../../../flutter/shell/platform/fuchsia/flutter/flutter_runner_product_configuration.h
1165+
FILE: ../../../flutter/shell/platform/fuchsia/flutter/fuchsia_external_view_embedder.cc
1166+
FILE: ../../../flutter/shell/platform/fuchsia/flutter/fuchsia_external_view_embedder.h
11651167
FILE: ../../../flutter/shell/platform/fuchsia/flutter/fuchsia_intl.cc
11661168
FILE: ../../../flutter/shell/platform/fuchsia/flutter/fuchsia_intl.h
11671169
FILE: ../../../flutter/shell/platform/fuchsia/flutter/fuchsia_intl_unittest.cc

shell/platform/fuchsia/flutter/BUILD.gn

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ template("runner_sources") {
5353
"accessibility_bridge.h",
5454
"component.cc",
5555
"component.h",
56-
"compositor_context.cc",
57-
"compositor_context.h",
5856
"engine.cc",
5957
"engine.h",
6058
"flutter_runner_product_configuration.cc",
6159
"flutter_runner_product_configuration.h",
60+
"fuchsia_external_view_embedder.cc",
61+
"fuchsia_external_view_embedder.h",
6262
"fuchsia_intl.cc",
6363
"fuchsia_intl.h",
6464
"isolate_configurator.cc",
@@ -92,6 +92,12 @@ template("runner_sources") {
9292
"vulkan_surface_producer.cc",
9393
"vulkan_surface_producer.h",
9494
]
95+
if (flutter_enable_legacy_fuchsia_embedder) {
96+
sources += [
97+
"compositor_context.cc",
98+
"compositor_context.h",
99+
]
100+
}
95101

96102
public_configs = runner_configs
97103

shell/platform/fuchsia/flutter/component.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ constexpr char kDataKey[] = "data";
5454
constexpr char kAssetsKey[] = "assets";
5555
constexpr char kTmpPath[] = "/tmp";
5656
constexpr char kServiceRootPath[] = "/svc";
57+
constexpr char kRunnerConfigPath[] = "/config/data/flutter_runner_config";
5758

5859
// static
5960
void Application::ParseProgramMetadata(
@@ -346,11 +347,13 @@ Application::Application(
346347
}
347348
}
348349

349-
// Load and use product-specific configuration, if it exists.
350+
// Load and use runner-specific configuration, if it exists.
350351
std::string json_string;
351-
if (dart_utils::ReadFileToString(
352-
"/config/data/frame_scheduling_performance_values", &json_string)) {
352+
if (dart_utils::ReadFileToString(kRunnerConfigPath, &json_string)) {
353353
product_config_ = FlutterRunnerProductConfiguration(json_string);
354+
} else {
355+
FML_LOG(WARNING) << "Failed to load runner configuration from "
356+
<< kRunnerConfigPath << "; using default config values.";
354357
}
355358

356359
#if defined(DART_PRODUCT)

shell/platform/fuchsia/flutter/engine.cc

Lines changed: 124 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,27 @@
88
#include <zircon/status.h>
99

1010
#include "../runtime/dart/utils/files.h"
11-
#include "compositor_context.h"
1211
#include "flutter/common/task_runners.h"
1312
#include "flutter/fml/make_copyable.h"
1413
#include "flutter/fml/synchronization/waitable_event.h"
1514
#include "flutter/fml/task_runner.h"
1615
#include "flutter/runtime/dart_vm_lifecycle.h"
1716
#include "flutter/shell/common/rasterizer.h"
1817
#include "flutter/shell/common/run_configuration.h"
18+
#include "third_party/skia/include/ports/SkFontMgr_fuchsia.h"
19+
1920
#include "flutter_runner_product_configuration.h"
21+
#include "fuchsia_external_view_embedder.h"
2022
#include "fuchsia_intl.h"
2123
#include "platform_view.h"
24+
#include "surface.h"
2225
#include "task_runner_adapter.h"
23-
#include "third_party/skia/include/ports/SkFontMgr_fuchsia.h"
2426
#include "thread.h"
2527

28+
#if defined(LEGACY_FUCHSIA_EMBEDDER)
29+
#include "compositor_context.h" // nogncheck
30+
#endif
31+
2632
namespace flutter_runner {
2733
namespace {
2834

@@ -65,6 +71,9 @@ Engine::Engine(Delegate& delegate,
6571
FlutterRunnerProductConfiguration product_config)
6672
: delegate_(delegate),
6773
thread_label_(std::move(thread_label)),
74+
#if defined(LEGACY_FUCHSIA_EMBEDDER)
75+
use_legacy_renderer_(product_config.use_legacy_renderer()),
76+
#endif
6877
weak_factory_(this) {
6978
if (zx::event::create(0, &vsync_event_) != ZX_OK) {
7079
FML_DLOG(ERROR) << "Could not create the vsync event.";
@@ -124,9 +133,18 @@ Engine::Engine(Delegate& delegate,
124133
thread_label_, std::move(session),
125134
std::move(session_error_callback), [](auto) {}, vsync_handle);
126135
surface_producer_.emplace(session_connection_->get());
127-
scene_update_context_.emplace(thread_label_, std::move(view_token),
128-
std::move(view_ref_pair),
129-
session_connection_.value());
136+
#if defined(LEGACY_FUCHSIA_EMBEDDER)
137+
if (use_legacy_renderer_) {
138+
legacy_external_view_embedder_.emplace(
139+
thread_label_, std::move(view_token), std::move(view_ref_pair),
140+
session_connection_.value());
141+
} else
142+
#endif
143+
{
144+
external_view_embedder_.emplace(
145+
thread_label_, std::move(view_token), std::move(view_ref_pair),
146+
session_connection_.value(), surface_producer_.value());
147+
}
130148
}));
131149

132150
// Grab the parent environment services. The platform view may want to
@@ -152,11 +170,8 @@ Engine::Engine(Delegate& delegate,
152170
OnDestroyView on_destroy_view_callback =
153171
std::bind(&Engine::DestroyView, this, std::placeholders::_1);
154172

155-
OnGetViewEmbedder on_get_view_embedder_callback =
156-
std::bind(&Engine::GetViewEmbedder, this);
157-
158-
OnGetGrContext on_get_gr_context_callback =
159-
std::bind(&Engine::GetGrContext, this);
173+
OnCreateSurface on_create_surface_callback =
174+
std::bind(&Engine::CreateSurface, this);
160175

161176
// SessionListener has a OnScenicError method; invoke this callback on the
162177
// platform thread when that happens. The Session itself should also be
@@ -187,11 +202,9 @@ Engine::Engine(Delegate& delegate,
187202
on_create_view_callback = std::move(on_create_view_callback),
188203
on_update_view_callback = std::move(on_update_view_callback),
189204
on_destroy_view_callback = std::move(on_destroy_view_callback),
190-
on_get_view_embedder_callback =
191-
std::move(on_get_view_embedder_callback),
192-
on_get_gr_context_callback = std::move(on_get_gr_context_callback),
193-
vsync_handle = vsync_event_.get(),
194-
product_config = product_config](flutter::Shell& shell) mutable {
205+
on_create_surface_callback = std::move(on_create_surface_callback),
206+
vsync_offset = product_config.get_vsync_offset(),
207+
vsync_handle = vsync_event_.get()](flutter::Shell& shell) mutable {
195208
return std::make_unique<flutter_runner::PlatformView>(
196209
shell, // delegate
197210
debug_label, // debug label
@@ -206,27 +219,35 @@ Engine::Engine(Delegate& delegate,
206219
std::move(on_create_view_callback),
207220
std::move(on_update_view_callback),
208221
std::move(on_destroy_view_callback),
209-
std::move(on_get_view_embedder_callback),
210-
std::move(on_get_gr_context_callback),
211-
vsync_handle, // vsync handle
212-
product_config);
222+
std::move(on_create_surface_callback),
223+
std::move(vsync_offset), // vsync offset
224+
vsync_handle);
213225
});
214226

215227
// Setup the callback that will instantiate the rasterizer.
216-
flutter::Shell::CreateCallback<flutter::Rasterizer> on_create_rasterizer =
217-
fml::MakeCopyable([this](flutter::Shell& shell) mutable {
218-
FML_DCHECK(session_connection_);
219-
FML_DCHECK(surface_producer_);
220-
FML_DCHECK(scene_update_context_);
221-
222-
std::unique_ptr<flutter_runner::CompositorContext> compositor_context =
223-
std::make_unique<flutter_runner::CompositorContext>(
224-
session_connection_.value(), surface_producer_.value(),
225-
scene_update_context_.value());
226-
227-
return std::make_unique<flutter::Rasterizer>(
228-
shell, std::move(compositor_context));
229-
});
228+
flutter::Shell::CreateCallback<flutter::Rasterizer> on_create_rasterizer;
229+
#if defined(LEGACY_FUCHSIA_EMBEDDER)
230+
on_create_rasterizer = [this](flutter::Shell& shell) {
231+
if (use_legacy_renderer_) {
232+
FML_DCHECK(session_connection_);
233+
FML_DCHECK(surface_producer_);
234+
FML_DCHECK(legacy_external_view_embedder_);
235+
236+
auto compositor_context =
237+
std::make_unique<flutter_runner::CompositorContext>(
238+
session_connection_.value(), surface_producer_.value(),
239+
legacy_external_view_embedder_.value());
240+
return std::make_unique<flutter::Rasterizer>(
241+
shell, std::move(compositor_context));
242+
} else {
243+
return std::make_unique<flutter::Rasterizer>(shell);
244+
}
245+
};
246+
#else
247+
on_create_rasterizer = [](flutter::Shell& shell) {
248+
return std::make_unique<flutter::Rasterizer>(shell);
249+
};
250+
#endif
230251

231252
settings.root_isolate_create_callback =
232253
std::bind(&Engine::OnMainIsolateStart, this);
@@ -479,59 +500,97 @@ void Engine::Terminate() {
479500
}
480501

481502
void Engine::DebugWireframeSettingsChanged(bool enabled) {
482-
if (!shell_ || !scene_update_context_) {
483-
return;
484-
}
485-
486-
shell_->GetTaskRunners().GetRasterTaskRunner()->PostTask(
487-
[this, enabled]() { scene_update_context_->EnableWireframe(enabled); });
503+
FML_CHECK(shell_);
504+
505+
shell_->GetTaskRunners().GetRasterTaskRunner()->PostTask([this, enabled]() {
506+
#if defined(LEGACY_FUCHSIA_EMBEDDER)
507+
if (use_legacy_renderer_) {
508+
FML_CHECK(legacy_external_view_embedder_);
509+
legacy_external_view_embedder_->EnableWireframe(enabled);
510+
} else
511+
#endif
512+
{
513+
FML_CHECK(external_view_embedder_);
514+
external_view_embedder_->EnableWireframe(enabled);
515+
}
516+
});
488517
}
489518

490519
void Engine::CreateView(int64_t view_id, bool hit_testable, bool focusable) {
491-
if (!shell_ || !scene_update_context_) {
492-
return;
493-
}
520+
FML_CHECK(shell_);
494521

495522
shell_->GetTaskRunners().GetRasterTaskRunner()->PostTask(
496523
[this, view_id, hit_testable, focusable]() {
497-
scene_update_context_->CreateView(view_id, hit_testable, focusable);
524+
#if defined(LEGACY_FUCHSIA_EMBEDDER)
525+
if (use_legacy_renderer_) {
526+
FML_CHECK(legacy_external_view_embedder_);
527+
legacy_external_view_embedder_->CreateView(view_id, hit_testable,
528+
focusable);
529+
} else
530+
#endif
531+
{
532+
FML_CHECK(external_view_embedder_);
533+
external_view_embedder_->CreateView(view_id);
534+
external_view_embedder_->SetViewProperties(view_id, hit_testable,
535+
focusable);
536+
}
498537
});
499538
}
500539

501540
void Engine::UpdateView(int64_t view_id, bool hit_testable, bool focusable) {
502-
if (!shell_ || !scene_update_context_) {
503-
return;
504-
}
541+
FML_CHECK(shell_);
505542

506543
shell_->GetTaskRunners().GetRasterTaskRunner()->PostTask(
507544
[this, view_id, hit_testable, focusable]() {
508-
scene_update_context_->UpdateView(view_id, hit_testable, focusable);
545+
#if defined(LEGACY_FUCHSIA_EMBEDDER)
546+
if (use_legacy_renderer_) {
547+
FML_CHECK(legacy_external_view_embedder_);
548+
legacy_external_view_embedder_->UpdateView(view_id, hit_testable,
549+
focusable);
550+
} else
551+
#endif
552+
{
553+
FML_CHECK(external_view_embedder_);
554+
external_view_embedder_->SetViewProperties(view_id, hit_testable,
555+
focusable);
556+
}
509557
});
510558
}
511559

512560
void Engine::DestroyView(int64_t view_id) {
513-
if (!shell_ || !scene_update_context_) {
514-
return;
515-
}
516-
517-
shell_->GetTaskRunners().GetRasterTaskRunner()->PostTask(
518-
[this, view_id]() { scene_update_context_->DestroyView(view_id); });
561+
FML_CHECK(shell_);
562+
563+
shell_->GetTaskRunners().GetRasterTaskRunner()->PostTask([this, view_id]() {
564+
#if defined(LEGACY_FUCHSIA_EMBEDDER)
565+
if (use_legacy_renderer_) {
566+
FML_CHECK(legacy_external_view_embedder_);
567+
legacy_external_view_embedder_->DestroyView(view_id);
568+
} else
569+
#endif
570+
{
571+
FML_CHECK(external_view_embedder_);
572+
external_view_embedder_->DestroyView(view_id);
573+
}
574+
});
519575
}
520576

521-
flutter::ExternalViewEmbedder* Engine::GetViewEmbedder() {
522-
if (!scene_update_context_) {
523-
return nullptr;
524-
}
525-
526-
return &scene_update_context_.value();
527-
}
577+
std::unique_ptr<flutter::Surface> Engine::CreateSurface() {
578+
flutter::ExternalViewEmbedder* external_view_embedder = nullptr;
528579

529-
GrDirectContext* Engine::GetGrContext() {
530-
// GetGrContext should be called only after rasterizer is created.
531-
FML_DCHECK(shell_);
532-
FML_DCHECK(shell_->GetRasterizer());
580+
#if defined(LEGACY_FUCHSIA_EMBEDDER)
581+
if (use_legacy_renderer_) {
582+
FML_CHECK(legacy_external_view_embedder_);
583+
external_view_embedder = &legacy_external_view_embedder_.value();
584+
} else
585+
#endif
586+
{
587+
FML_CHECK(external_view_embedder_);
588+
external_view_embedder = &external_view_embedder_.value();
589+
}
590+
FML_CHECK(external_view_embedder);
533591

534-
return surface_producer_->gr_context();
592+
return std::make_unique<Surface>(thread_label_, external_view_embedder,
593+
surface_producer_->gr_context());
535594
}
536595

537596
#if !defined(DART_PRODUCT)

shell/platform/fuchsia/flutter/engine.h

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,21 @@
1414
#include <lib/ui/scenic/cpp/view_ref_pair.h>
1515
#include <lib/zx/event.h>
1616

17-
#include "flutter/flow/embedded_views.h"
18-
#include "flutter/flow/scene_update_context.h"
17+
#include "flutter/flow/surface.h"
1918
#include "flutter/fml/macros.h"
2019
#include "flutter/shell/common/shell.h"
2120

2221
#include "flutter_runner_product_configuration.h"
22+
#include "fuchsia_external_view_embedder.h"
2323
#include "isolate_configurator.h"
2424
#include "session_connection.h"
2525
#include "thread.h"
2626
#include "vulkan_surface_producer.h"
2727

28+
#if defined(LEGACY_FUCHSIA_EMBEDDER)
29+
#include "flutter/flow/scene_update_context.h" // nogncheck
30+
#endif
31+
2832
namespace flutter_runner {
2933

3034
// Represents an instance of running Flutter engine along with the threads
@@ -65,7 +69,10 @@ class Engine final {
6569

6670
std::optional<SessionConnection> session_connection_;
6771
std::optional<VulkanSurfaceProducer> surface_producer_;
68-
std::optional<flutter::SceneUpdateContext> scene_update_context_;
72+
std::optional<FuchsiaExternalViewEmbedder> external_view_embedder_;
73+
#if defined(LEGACY_FUCHSIA_EMBEDDER)
74+
std::optional<flutter::SceneUpdateContext> legacy_external_view_embedder_;
75+
#endif
6976

7077
std::unique_ptr<IsolateConfigurator> isolate_configurator_;
7178
std::unique_ptr<flutter::Shell> shell_;
@@ -74,6 +81,10 @@ class Engine final {
7481

7582
zx::event vsync_event_;
7683

84+
#if defined(LEGACY_FUCHSIA_EMBEDDER)
85+
bool use_legacy_renderer_ = true;
86+
#endif
87+
7788
fml::WeakPtrFactory<Engine> weak_factory_;
7889

7990
void OnMainIsolateStart();
@@ -87,9 +98,7 @@ class Engine final {
8798
void UpdateView(int64_t view_id, bool hit_testable, bool focusable);
8899
void DestroyView(int64_t view_id);
89100

90-
flutter::ExternalViewEmbedder* GetViewEmbedder();
91-
92-
GrDirectContext* GetGrContext();
101+
std::unique_ptr<flutter::Surface> CreateSurface();
93102

94103
FML_DISALLOW_COPY_AND_ASSIGN(Engine);
95104
};

0 commit comments

Comments
 (0)