Skip to content

Commit 9f08f4c

Browse files
impeller: add impeller initial implementation (sony#355)
Signed-off-by: Hidenori Matsubayashi <[email protected]>
1 parent a172143 commit 9f08f4c

22 files changed

+155
-48
lines changed

src/flutter/shell/platform/common/engine_switches.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ std::vector<std::string> GetSwitchesFromEnvironment() {
1616
// Read engine switches from the environment in debug/profile. If release mode
1717
// support is needed in the future, it should likely use a whitelist.
1818
#ifndef FLUTTER_RELEASE
19-
#ifndef WINUWP
2019
const char* switch_count_key = "FLUTTER_ENGINE_SWITCHES";
2120
const int kMaxSwitchCount = 50;
2221
const char* switch_count_string = std::getenv(switch_count_key);
@@ -37,7 +36,6 @@ std::vector<std::string> GetSwitchesFromEnvironment() {
3736
<< ", but " << switch_key.str() << " is missing." << std::endl;
3837
}
3938
}
40-
#endif // !WINUWP
4139
#endif // !FLUTTER_RELEASE
4240
return switches;
4341
}

src/flutter/shell/platform/linux_embedded/flutter_elinux.cc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,10 @@ FlutterDesktopViewControllerRef FlutterDesktopViewControllerCreate(
9292
auto state = std::make_unique<FlutterDesktopViewControllerState>();
9393
state->view =
9494
std::make_unique<flutter::FlutterELinuxView>(std::move(window_wrapper));
95-
if (!state->view->CreateRenderSurface()) {
96-
return nullptr;
97-
}
98-
9995
// Take ownership of the engine, starting it if necessary.
10096
state->view->SetEngine(
10197
std::unique_ptr<flutter::FlutterELinuxEngine>(EngineFromHandle(engine)));
98+
state->view->CreateRenderSurface();
10299
if (!state->view->GetEngine()->running()) {
103100
if (!state->view->GetEngine()->RunWithEntrypoint(nullptr)) {
104101
return nullptr;

src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ FlutterELinuxEngine::FlutterELinuxEngine(const FlutterProjectBundle& project)
142142
}
143143
});
144144

145+
// Check for impeller support.
146+
auto& switches = project_->GetSwitches();
147+
enable_impeller_ = std::find(switches.begin(), switches.end(),
148+
"--enable-impeller=true") != switches.end();
149+
145150
// Set up the legacy structs backing the API handles.
146151
messenger_ = FlutterDesktopMessengerReferenceOwner(
147152
FlutterDesktopMessengerAddRef(new FlutterDesktopMessenger()),
@@ -173,6 +178,11 @@ FlutterELinuxEngine::~FlutterELinuxEngine() {
173178
Stop();
174179
}
175180

181+
void FlutterELinuxEngine::SetSwitches(
182+
const std::vector<std::string>& switches) {
183+
project_->SetSwitches(switches);
184+
}
185+
176186
bool FlutterELinuxEngine::RunWithEntrypoint(const char* entrypoint) {
177187
if (!project_->HasValidPaths()) {
178188
ELINUX_LOG(ERROR) << "Missing or unresolvable paths to assets.";

src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ class FlutterELinuxEngine {
6868
void SetPluginRegistrarDestructionCallback(
6969
FlutterDesktopOnPluginRegistrarDestroyed callback);
7070

71+
// Sets switches member to the given switches.
72+
void SetSwitches(const std::vector<std::string>& switches);
73+
7174
FlutterDesktopMessengerRef messenger() { return messenger_.get(); }
7275

7376
IncomingMessageDispatcher* message_dispatcher() {
@@ -121,6 +124,9 @@ class FlutterELinuxEngine {
121124
void OnVsync(uint64_t last_frame_time_nanos,
122125
uint64_t vsync_interval_time_nanos);
123126

127+
// Gets the status whether Impeller is enabled.
128+
bool IsImpellerEnabled() const { return enable_impeller_; }
129+
124130
private:
125131
// Allows swapping out embedder_api_ calls in tests.
126132
friend class EngineEmbedderApiModifier;
@@ -176,6 +182,8 @@ class FlutterELinuxEngine {
176182

177183
// The vsync waiter.
178184
std::unique_ptr<VsyncWaiter> vsync_waiter_;
185+
186+
bool enable_impeller_ = false;
179187
};
180188

181189
} // namespace flutter

src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,10 @@ bool FlutterELinuxView::MakeResourceCurrent() {
434434

435435
bool FlutterELinuxView::CreateRenderSurface() {
436436
PhysicalWindowBounds bounds = binding_handler_->GetPhysicalWindowBounds();
437-
return binding_handler_->CreateRenderSurface(bounds.width, bounds.height);
437+
auto impeller_enable = engine_.get()->IsImpellerEnabled();
438+
std::cout << "impeller: " << impeller_enable << std::endl;
439+
return binding_handler_->CreateRenderSurface(bounds.width, bounds.height,
440+
impeller_enable);
438441
}
439442

440443
void FlutterELinuxView::DestroyRenderSurface() {

src/flutter/shell/platform/linux_embedded/flutter_project_bundle.cc

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,23 @@ UniqueAotDataPtr FlutterProjectBundle::LoadAotData(
8585
return UniqueAotDataPtr(data);
8686
}
8787

88+
void FlutterProjectBundle::SetSwitches(
89+
const std::vector<std::string>& switches) {
90+
engine_switches_ = switches;
91+
}
92+
8893
const std::vector<std::string> FlutterProjectBundle::GetSwitches() {
89-
return GetSwitchesFromEnvironment();
94+
if (engine_switches_.size() == 0) {
95+
return GetSwitchesFromEnvironment();
96+
}
97+
std::vector<std::string> switches;
98+
switches.insert(switches.end(), engine_switches_.begin(),
99+
engine_switches_.end());
100+
101+
auto env_switches = GetSwitchesFromEnvironment();
102+
switches.insert(switches.end(), env_switches.begin(), env_switches.end());
103+
104+
return switches;
90105
}
91106

92107
const std::string FlutterProjectBundle::GetExecutableDirectory() {

src/flutter/shell/platform/linux_embedded/flutter_project_bundle.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ class FlutterProjectBundle {
4545
// Returns any switches that should be passed to the engine.
4646
const std::vector<std::string> GetSwitches();
4747

48+
// Sets engine switches.
49+
void SetSwitches(const std::vector<std::string>& switches);
50+
4851
// Attempts to load AOT data for this bundle. The returned data must be
4952
// retained until any engine instance it is passed to has been shut down.
5053
//
@@ -69,6 +72,9 @@ class FlutterProjectBundle {
6972

7073
// Dart entrypoint arguments.
7174
std::vector<std::string> dart_entrypoint_arguments_;
75+
76+
// Engine switches.
77+
std::vector<std::string> engine_switches_;
7278
};
7379

7480
} // namespace flutter

src/flutter/shell/platform/linux_embedded/surface/context_egl.cc

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace flutter {
1111

1212
ContextEgl::ContextEgl(std::unique_ptr<EnvironmentEgl> environment,
13+
bool enable_impeller,
1314
EGLint egl_surface_type)
1415
: environment_(std::move(environment)), config_(nullptr) {
1516
EGLint config_count = 0;
@@ -28,11 +29,57 @@ ContextEgl::ContextEgl(std::unique_ptr<EnvironmentEgl> environment,
2829
EGL_NONE
2930
// clang-format on
3031
};
31-
if (eglChooseConfig(environment_->Display(), attribs, &config_, 1,
32-
&config_count) != EGL_TRUE) {
33-
ELINUX_LOG(ERROR) << "Failed to choose EGL surface config: "
34-
<< get_egl_error_cause();
35-
return;
32+
const EGLint impeller_config_attributes[] = {
33+
// clang-format off
34+
EGL_RED_SIZE, 8,
35+
EGL_GREEN_SIZE, 8,
36+
EGL_BLUE_SIZE, 8,
37+
#if defined(ENABLE_EGL_ALPHA_COMPONENT_OF_COLOR_BUFFER)
38+
EGL_ALPHA_SIZE, 8,
39+
#endif
40+
EGL_DEPTH_SIZE, 0,
41+
EGL_STENCIL_SIZE, 8,
42+
EGL_SAMPLE_BUFFERS, 1,
43+
EGL_SAMPLES, 4,
44+
EGL_NONE
45+
// clang-format on
46+
};
47+
const EGLint impeller_config_attributes_no_msaa[] = {
48+
// clang-format off
49+
EGL_RED_SIZE, 8,
50+
EGL_GREEN_SIZE, 8,
51+
EGL_BLUE_SIZE, 8,
52+
#if defined(ENABLE_EGL_ALPHA_COMPONENT_OF_COLOR_BUFFER)
53+
EGL_ALPHA_SIZE, 8,
54+
#endif
55+
EGL_DEPTH_SIZE, 0,
56+
EGL_STENCIL_SIZE, 8,
57+
EGL_NONE
58+
// clang-format on
59+
};
60+
61+
if (enable_impeller) {
62+
// First try the MSAA configuration.
63+
if ((eglChooseConfig(environment_->Display(), impeller_config_attributes,
64+
&config_, 1, &config_count) == EGL_FALSE) ||
65+
(config_count == 0)) {
66+
// Next fall back to disabled MSAA.
67+
if ((eglChooseConfig(environment_->Display(),
68+
impeller_config_attributes_no_msaa, &config_, 1,
69+
&config_count) == EGL_FALSE) ||
70+
(config_count == 0)) {
71+
ELINUX_LOG(ERROR) << "Failed to choose EGL surface config: "
72+
<< get_egl_error_cause();
73+
return;
74+
}
75+
}
76+
} else {
77+
if (eglChooseConfig(environment_->Display(), attribs, &config_, 1,
78+
&config_count) != EGL_TRUE) {
79+
ELINUX_LOG(ERROR) << "Failed to choose EGL surface config: "
80+
<< get_egl_error_cause();
81+
return;
82+
}
3683
}
3784

3885
if (config_count == 0 || config_ == nullptr) {

src/flutter/shell/platform/linux_embedded/surface/context_egl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ namespace flutter {
1818
class ContextEgl {
1919
public:
2020
ContextEgl(std::unique_ptr<EnvironmentEgl> environment,
21+
bool enable_impeller,
2122
EGLint egl_surface_type = EGL_WINDOW_BIT);
2223
~ContextEgl() = default;
2324

src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2021 Sony Corporation. All rights reserved.
1+
// Copyright 2023 Sony Corporation. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

@@ -109,7 +109,9 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler {
109109
}
110110

111111
// |FlutterWindowBindingHandler|
112-
bool CreateRenderSurface(int32_t width, int32_t height) override {
112+
bool CreateRenderSurface(int32_t width,
113+
int32_t height,
114+
bool enable_impeller) override {
113115
std::vector<std::string> devices;
114116
auto device_filename = std::getenv(kFlutterDrmDeviceEnvironmentKey);
115117
if (device_filename && device_filename[0] != '\0') {
@@ -148,7 +150,7 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler {
148150

149151
display_valid_ = true;
150152

151-
render_surface_ = native_window_->CreateRenderSurface();
153+
render_surface_ = native_window_->CreateRenderSurface(enable_impeller);
152154
if (!render_surface_->SetNativeWindow(native_window_.get())) {
153155
return false;
154156
}

0 commit comments

Comments
 (0)