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

Commit 82b27c5

Browse files
uysalereEmircan Uysaler
authored andcommitted
fuchsia: Add scaffolding for flatland migration
1 parent 19f853d commit 82b27c5

18 files changed

+427
-209
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,21 +1374,25 @@ FILE: ../../../flutter/shell/platform/fuchsia/flutter/accessibility_bridge_unitt
13741374
FILE: ../../../flutter/shell/platform/fuchsia/flutter/component.cc
13751375
FILE: ../../../flutter/shell/platform/fuchsia/flutter/component.h
13761376
FILE: ../../../flutter/shell/platform/fuchsia/flutter/component_unittest.cc
1377-
FILE: ../../../flutter/shell/platform/fuchsia/flutter/default_session_connection.cc
1378-
FILE: ../../../flutter/shell/platform/fuchsia/flutter/default_session_connection.h
13791377
FILE: ../../../flutter/shell/platform/fuchsia/flutter/engine.cc
13801378
FILE: ../../../flutter/shell/platform/fuchsia/flutter/engine.h
1379+
FILE: ../../../flutter/shell/platform/fuchsia/flutter/flatland_connection.cc
1380+
FILE: ../../../flutter/shell/platform/fuchsia/flutter/flatland_connection.h
1381+
FILE: ../../../flutter/shell/platform/fuchsia/flutter/flatland_external_view_embedder.cc
1382+
FILE: ../../../flutter/shell/platform/fuchsia/flutter/flatland_external_view_embedder.h
13811383
FILE: ../../../flutter/shell/platform/fuchsia/flutter/flutter_runner_fakes.h
13821384
FILE: ../../../flutter/shell/platform/fuchsia/flutter/flutter_runner_product_configuration.cc
13831385
FILE: ../../../flutter/shell/platform/fuchsia/flutter/flutter_runner_product_configuration.h
13841386
FILE: ../../../flutter/shell/platform/fuchsia/flutter/focus_delegate.cc
13851387
FILE: ../../../flutter/shell/platform/fuchsia/flutter/focus_delegate.h
13861388
FILE: ../../../flutter/shell/platform/fuchsia/flutter/focus_delegate_unittests.cc
1387-
FILE: ../../../flutter/shell/platform/fuchsia/flutter/fuchsia_external_view_embedder.cc
1388-
FILE: ../../../flutter/shell/platform/fuchsia/flutter/fuchsia_external_view_embedder.h
13891389
FILE: ../../../flutter/shell/platform/fuchsia/flutter/fuchsia_intl.cc
13901390
FILE: ../../../flutter/shell/platform/fuchsia/flutter/fuchsia_intl.h
13911391
FILE: ../../../flutter/shell/platform/fuchsia/flutter/fuchsia_intl_unittest.cc
1392+
FILE: ../../../flutter/shell/platform/fuchsia/flutter/gfx_connection.cc
1393+
FILE: ../../../flutter/shell/platform/fuchsia/flutter/gfx_connection.h
1394+
FILE: ../../../flutter/shell/platform/fuchsia/flutter/gfx_external_view_embedder.cc
1395+
FILE: ../../../flutter/shell/platform/fuchsia/flutter/gfx_external_view_embedder.h
13921396
FILE: ../../../flutter/shell/platform/fuchsia/flutter/isolate_configurator.cc
13931397
FILE: ../../../flutter/shell/platform/fuchsia/flutter/isolate_configurator.h
13941398
FILE: ../../../flutter/shell/platform/fuchsia/flutter/kernel/extract_far.dart

shell/platform/fuchsia/flutter/BUILD.gn

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,22 @@ template("runner_sources") {
5353
"accessibility_bridge.h",
5454
"component.cc",
5555
"component.h",
56-
"default_session_connection.cc",
57-
"default_session_connection.h",
5856
"engine.cc",
5957
"engine.h",
58+
"flatland_connection.cc",
59+
"flatland_connection.h",
60+
"flatland_external_view_embedder.cc",
61+
"flatland_external_view_embedder.h",
6062
"flutter_runner_product_configuration.cc",
6163
"flutter_runner_product_configuration.h",
6264
"focus_delegate.cc",
6365
"focus_delegate.h",
64-
"fuchsia_external_view_embedder.cc",
65-
"fuchsia_external_view_embedder.h",
6666
"fuchsia_intl.cc",
6767
"fuchsia_intl.h",
68+
"gfx_connection.cc",
69+
"gfx_connection.h",
70+
"gfx_external_view_embedder.cc",
71+
"gfx_external_view_embedder.h",
6872
"isolate_configurator.cc",
6973
"isolate_configurator.h",
7074
"keyboard.cc",
@@ -505,7 +509,7 @@ executable("flutter_runner_scenic_unittests") {
505509

506510
output_name = "flutter_runner_scenic_tests"
507511

508-
sources = [ "tests/default_session_connection_unittests.cc" ]
512+
sources = [ "tests/gfx_connection_unittests.cc" ]
509513

510514
# This is needed for //third_party/googletest for linking zircon symbols.
511515
libs = [ "$fuchsia_sdk_path/arch/$target_cpu/sysroot/lib/libzircon.so" ]

shell/platform/fuchsia/flutter/engine.cc

Lines changed: 55 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -133,25 +133,45 @@ Engine::Engine(Delegate& delegate,
133133
// thread. We also need to wait for the external view embedder to be set up
134134
// before creating the shell.
135135
fml::AutoResetWaitableEvent view_embedder_latch;
136-
task_runners.GetRasterTaskRunner()->PostTask(fml::MakeCopyable(
137-
[this, session = std::move(session),
138-
session_error_callback = std::move(session_error_callback),
139-
view_token = std::move(view_token),
140-
view_ref_pair = std::move(view_ref_pair),
141-
max_frames_in_flight = product_config.get_max_frames_in_flight(),
142-
&view_embedder_latch,
143-
vsync_offset = product_config.get_vsync_offset()]() mutable {
144-
session_connection_ = std::make_shared<DefaultSessionConnection>(
145-
thread_label_, std::move(session),
146-
std::move(session_error_callback), [](auto) {},
147-
max_frames_in_flight, vsync_offset);
148-
surface_producer_.emplace(session_connection_->get());
149-
external_view_embedder_ = std::make_shared<FuchsiaExternalViewEmbedder>(
150-
thread_label_, std::move(view_token), std::move(view_ref_pair),
151-
*session_connection_.get(), surface_producer_.value(),
152-
intercept_all_input_);
153-
view_embedder_latch.Signal();
154-
}));
136+
if (product_config.use_flatland()) {
137+
task_runners.GetRasterTaskRunner()->PostTask(fml::MakeCopyable(
138+
[this, session_error_callback = std::move(session_error_callback),
139+
view_token = std::move(view_token),
140+
view_ref_pair = std::move(view_ref_pair),
141+
max_frames_in_flight = product_config.get_max_frames_in_flight(),
142+
&view_embedder_latch,
143+
vsync_offset = product_config.get_vsync_offset()]() mutable {
144+
flatland_connection_ = std::make_shared<FlatlandConnection>(
145+
thread_label_, std::move(session_error_callback), [](auto) {},
146+
max_frames_in_flight, vsync_offset);
147+
flatland_view_embedder_ =
148+
std::make_shared<FlatlandExternalViewEmbedder>(
149+
thread_label_, std::move(view_token),
150+
std::move(view_ref_pair), *flatland_connection_.get(),
151+
surface_producer_.value(), intercept_all_input_);
152+
view_embedder_latch.Signal();
153+
}));
154+
} else {
155+
task_runners.GetRasterTaskRunner()->PostTask(fml::MakeCopyable(
156+
[this, session = std::move(session),
157+
session_error_callback = std::move(session_error_callback),
158+
view_token = std::move(view_token),
159+
view_ref_pair = std::move(view_ref_pair),
160+
max_frames_in_flight = product_config.get_max_frames_in_flight(),
161+
&view_embedder_latch,
162+
vsync_offset = product_config.get_vsync_offset()]() mutable {
163+
gfx_connection_ = std::make_shared<GfxConnection>(
164+
thread_label_, std::move(session),
165+
std::move(session_error_callback), [](auto) {},
166+
max_frames_in_flight, vsync_offset);
167+
surface_producer_.emplace(gfx_connection_->get());
168+
gfx_view_embedder_ = std::make_shared<GfxExternalViewEmbedder>(
169+
thread_label_, std::move(view_token), std::move(view_ref_pair),
170+
*gfx_connection_.get(), surface_producer_.value(),
171+
intercept_all_input_);
172+
view_embedder_latch.Signal();
173+
}));
174+
}
155175
view_embedder_latch.Wait();
156176

157177
// Grab the parent environment services. The platform view may want to
@@ -279,11 +299,11 @@ Engine::Engine(Delegate& delegate,
279299
keyboard_listener_request = std::move(keyboard_listener_request),
280300
await_vsync_callback =
281301
[this](FireCallbackCallback cb) {
282-
session_connection_->AwaitVsync(cb);
302+
gfx_connection_->AwaitVsync(cb);
283303
},
284304
await_vsync_for_secondary_callback_callback =
285305
[this](FireCallbackCallback cb) {
286-
session_connection_->AwaitVsyncForSecondaryCallback(cb);
306+
gfx_connection_->AwaitVsyncForSecondaryCallback(cb);
287307
},
288308
product_config](flutter::Shell& shell) mutable {
289309
OnShaderWarmup on_shader_warmup = nullptr;
@@ -529,8 +549,8 @@ void Engine::DebugWireframeSettingsChanged(bool enabled) {
529549
FML_CHECK(shell_);
530550

531551
shell_->GetTaskRunners().GetRasterTaskRunner()->PostTask([this, enabled]() {
532-
FML_CHECK(external_view_embedder_);
533-
external_view_embedder_->EnableWireframe(enabled);
552+
FML_CHECK(gfx_view_embedder_);
553+
gfx_view_embedder_->EnableWireframe(enabled);
534554
});
535555
}
536556

@@ -545,11 +565,11 @@ void Engine::CreateView(int64_t view_id,
545565
[this, view_id, hit_testable, focusable,
546566
on_view_created = std::move(on_view_created),
547567
on_view_bound = std::move(on_view_bound)]() {
548-
FML_CHECK(external_view_embedder_);
549-
external_view_embedder_->CreateView(view_id, std::move(on_view_created),
550-
std::move(on_view_bound));
551-
external_view_embedder_->SetViewProperties(view_id, SkRect::MakeEmpty(),
552-
hit_testable, focusable);
568+
FML_CHECK(gfx_view_embedder_);
569+
gfx_view_embedder_->CreateView(view_id, std::move(on_view_created),
570+
std::move(on_view_bound));
571+
gfx_view_embedder_->SetViewProperties(view_id, SkRect::MakeEmpty(),
572+
hit_testable, focusable);
553573
});
554574
}
555575

@@ -561,9 +581,9 @@ void Engine::UpdateView(int64_t view_id,
561581

562582
shell_->GetTaskRunners().GetRasterTaskRunner()->PostTask(
563583
[this, view_id, occlusion_hint, hit_testable, focusable]() {
564-
FML_CHECK(external_view_embedder_);
565-
external_view_embedder_->SetViewProperties(view_id, occlusion_hint,
566-
hit_testable, focusable);
584+
FML_CHECK(gfx_view_embedder_);
585+
gfx_view_embedder_->SetViewProperties(view_id, occlusion_hint,
586+
hit_testable, focusable);
567587
});
568588
}
569589

@@ -572,9 +592,8 @@ void Engine::DestroyView(int64_t view_id, ViewIdCallback on_view_unbound) {
572592

573593
shell_->GetTaskRunners().GetRasterTaskRunner()->PostTask(
574594
[this, view_id, on_view_unbound = std::move(on_view_unbound)]() {
575-
FML_CHECK(external_view_embedder_);
576-
external_view_embedder_->DestroyView(view_id,
577-
std::move(on_view_unbound));
595+
FML_CHECK(gfx_view_embedder_);
596+
gfx_view_embedder_->DestroyView(view_id, std::move(on_view_unbound));
578597
});
579598
}
580599

@@ -585,9 +604,9 @@ std::unique_ptr<flutter::Surface> Engine::CreateSurface() {
585604

586605
std::shared_ptr<flutter::ExternalViewEmbedder>
587606
Engine::GetExternalViewEmbedder() {
588-
FML_CHECK(external_view_embedder_);
607+
FML_CHECK(gfx_view_embedder_);
589608

590-
return external_view_embedder_;
609+
return gfx_view_embedder_;
591610
}
592611

593612
#if !defined(DART_PRODUCT)

shell/platform/fuchsia/flutter/engine.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@
2323
#include "flutter/shell/common/shell.h"
2424
#include "flutter/shell/platform/fuchsia/flutter/accessibility_bridge.h"
2525

26-
#include "default_session_connection.h"
26+
#include "flatland_connection.h"
27+
#include "flatland_external_view_embedder.h"
2728
#include "flutter_runner_product_configuration.h"
28-
#include "fuchsia_external_view_embedder.h"
29+
#include "gfx_connection.h"
30+
#include "gfx_external_view_embedder.h"
2931
#include "isolate_configurator.h"
3032
#include "vulkan_surface_producer.h"
3133

@@ -70,9 +72,11 @@ class Engine final {
7072
const std::string thread_label_;
7173
std::array<fml::Thread, 3> threads_;
7274

73-
std::shared_ptr<DefaultSessionConnection> session_connection_;
75+
std::shared_ptr<GfxConnection> gfx_connection_;
76+
std::shared_ptr<FlatlandConnection> flatland_connection_;
7477
std::optional<VulkanSurfaceProducer> surface_producer_;
75-
std::shared_ptr<FuchsiaExternalViewEmbedder> external_view_embedder_;
78+
std::shared_ptr<GfxExternalViewEmbedder> gfx_view_embedder_;
79+
std::shared_ptr<FlatlandExternalViewEmbedder> flatland_view_embedder_;
7680

7781
std::unique_ptr<IsolateConfigurator> isolate_configurator_;
7882
std::unique_ptr<flutter::Shell> shell_;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2021 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 "flatland_connection.h"
6+
7+
namespace flutter_runner {
8+
9+
FlatlandConnection::FlatlandConnection(
10+
std::string debug_label,
11+
fml::closure error_callback,
12+
on_frame_presented_event on_frame_presented_callback,
13+
uint64_t max_frames_in_flight,
14+
fml::TimeDelta vsync_offset) {}
15+
16+
FlatlandConnection::~FlatlandConnection() = default;
17+
18+
} // namespace flutter_runner
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2021 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+
#ifndef FLUTTER_SHELL_PLATFORM_FUCHSIA_DEFAULT_FLATLAND_CONNECTION_H_
6+
#define FLUTTER_SHELL_PLATFORM_FUCHSIA_DEFAULT_FLATLAND_CONNECTION_H_
7+
8+
#include <fuchsia/scenic/scheduling/cpp/fidl.h>
9+
#include <fuchsia/ui/composition/cpp/fidl.h>
10+
11+
#include "flutter/fml/closure.h"
12+
#include "flutter/fml/macros.h"
13+
#include "flutter/fml/time/time_delta.h"
14+
15+
#include <string>
16+
17+
namespace flutter_runner {
18+
19+
using on_frame_presented_event =
20+
std::function<void(fuchsia::scenic::scheduling::FramePresentedInfo)>;
21+
22+
// The component residing on the raster thread that is responsible for
23+
// maintaining the Flatland instance connection and presenting updates.
24+
class FlatlandConnection final {
25+
public:
26+
FlatlandConnection(std::string debug_label,
27+
fml::closure error_callback,
28+
on_frame_presented_event on_frame_presented_callback,
29+
uint64_t max_frames_in_flight,
30+
fml::TimeDelta vsync_offset);
31+
32+
~FlatlandConnection();
33+
34+
FML_DISALLOW_COPY_AND_ASSIGN(FlatlandConnection);
35+
};
36+
37+
} // namespace flutter_runner
38+
39+
#endif // FLUTTER_SHELL_PLATFORM_FUCHSIA_DEFAULT_FLATLAND_CONNECTION_H_
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright 2021 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 "flatland_external_view_embedder.h"
6+
7+
namespace flutter_runner {
8+
9+
FlatlandExternalViewEmbedder::FlatlandExternalViewEmbedder(
10+
std::string debug_label,
11+
fuchsia::ui::views::ViewToken view_token,
12+
scenic::ViewRefPair view_ref_pair,
13+
FlatlandConnection& session,
14+
VulkanSurfaceProducer& surface_producer,
15+
bool intercept_all_input) {}
16+
17+
FlatlandExternalViewEmbedder::~FlatlandExternalViewEmbedder() = default;
18+
19+
SkCanvas* FlatlandExternalViewEmbedder::GetRootCanvas() {
20+
return nullptr;
21+
}
22+
23+
std::vector<SkCanvas*> FlatlandExternalViewEmbedder::GetCurrentCanvases() {
24+
return std::vector<SkCanvas*>();
25+
}
26+
27+
void FlatlandExternalViewEmbedder::PrerollCompositeEmbeddedView(
28+
int view_id,
29+
std::unique_ptr<flutter::EmbeddedViewParams> params) {}
30+
31+
SkCanvas* FlatlandExternalViewEmbedder::CompositeEmbeddedView(int view_id) {
32+
return nullptr;
33+
}
34+
35+
flutter::PostPrerollResult FlatlandExternalViewEmbedder::PostPrerollAction(
36+
fml::RefPtr<fml::RasterThreadMerger> raster_thread_merger) {
37+
return flutter::PostPrerollResult::kSuccess;
38+
}
39+
40+
void FlatlandExternalViewEmbedder::BeginFrame(
41+
SkISize frame_size,
42+
GrDirectContext* context,
43+
double device_pixel_ratio,
44+
fml::RefPtr<fml::RasterThreadMerger> raster_thread_merger) {}
45+
46+
void FlatlandExternalViewEmbedder::EndFrame(
47+
bool should_resubmit_frame,
48+
fml::RefPtr<fml::RasterThreadMerger> raster_thread_merger) {}
49+
50+
void FlatlandExternalViewEmbedder::SubmitFrame(
51+
GrDirectContext* context,
52+
std::unique_ptr<flutter::SurfaceFrame> frame,
53+
const std::shared_ptr<const fml::SyncSwitch>& gpu_disable_sync_switch) {}
54+
55+
void FlatlandExternalViewEmbedder::CancelFrame() {}
56+
57+
bool FlatlandExternalViewEmbedder::SupportsDynamicThreadMerging() {
58+
return false;
59+
}
60+
61+
} // namespace flutter_runner

0 commit comments

Comments
 (0)