Skip to content

Commit 72f018b

Browse files
authored
Adds manifest flag to turn on SDFs for Android. (flutter#196056)
This matches the existing flag for iOS, FLTEnableSDFs. The SDF renderer hasn't been optimized for Android yet. But for people who are targeting low DPI, higher power Android devices, like TV's, we want them to be able to try this out and it may work for them. fixes flutter#187757 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant in-code documentation (doc comments with `///`). - [x] If this PR introduces a new feature or capability, I created and linked a website documentation issue or PR in [flutter/website] (or verified none is needed). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/CONTRIBUTING.ai.md [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [flutter/website]: https://github.com/flutter/website [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent 86ab98d commit 72f018b

8 files changed

Lines changed: 49 additions & 13 deletions

File tree

‎engine/src/flutter/shell/platform/android/android_context_dynamic_impeller.cc‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ GetActualRenderingAPIForImpeller(
139139
#endif // FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG
140140
.enable_gpu_tracing = settings.enable_gpu_tracing,
141141
.enable_surface_control = settings.enable_surface_control,
142+
.impeller_flags = settings.impeller_flags,
142143
});
143144
if (!vulkan_backend->IsValid()) {
144145
FML_LOG(INFO)
@@ -208,7 +209,8 @@ void AndroidContextDynamicImpeller::SetupImpellerContext() {
208209
if (!vk_context_) {
209210
gl_context_ = std::make_shared<AndroidContextGLImpeller>(
210211
std::make_unique<impeller::egl::Display>(),
211-
settings_.enable_gpu_tracing, io_task_runner_);
212+
settings_.enable_gpu_tracing, settings_.impeller_flags,
213+
io_task_runner_);
212214
}
213215
// The id is only meaningful while setup is in flight. Cleared before the
214216
// signal so a waiter can never observe a completed setup alongside a stale

‎engine/src/flutter/shell/platform/android/android_context_gl_impeller.cc‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class AndroidContextGLImpeller::ReactorWorker final
5252
static std::shared_ptr<impeller::Context> CreateImpellerContext(
5353
const std::shared_ptr<impeller::ReactorGLES::Worker>& worker,
5454
bool enable_gpu_tracing,
55+
const impeller::Flags& impeller_flags,
5556
std::shared_ptr<fml::BasicTaskRunner> io_task_runner) {
5657
auto proc_table = std::make_unique<impeller::ProcTableGLES>(
5758
impeller::egl::CreateProcAddressResolver());
@@ -84,12 +85,12 @@ static std::shared_ptr<impeller::Context> CreateImpellerContext(
8485
};
8586

8687
auto context = impeller::ContextGLES::Create(
87-
impeller::Flags{}, std::move(proc_table),
88+
impeller_flags, std::move(proc_table),
8889
is_gles3 ? gles3_shader_mappings : gles2_shader_mappings,
8990
enable_gpu_tracing, std::move(io_task_runner));
9091
#else
9192
auto context = impeller::ContextGLES::Create(
92-
impeller::Flags{}, std::move(proc_table), gles2_shader_mappings,
93+
impeller_flags, std::move(proc_table), gles2_shader_mappings,
9394
enable_gpu_tracing, std::move(io_task_runner));
9495
#endif // !SLIMPELLER
9596

@@ -102,13 +103,18 @@ static std::shared_ptr<impeller::Context> CreateImpellerContext(
102103
FML_LOG(ERROR) << "Could not add reactor worker.";
103104
return nullptr;
104105
}
105-
FML_LOG(IMPORTANT) << "Using the Impeller rendering backend (OpenGLES).";
106+
if (impeller_flags.use_sdfs) {
107+
FML_LOG(IMPORTANT) << "Using the Impeller rendering backend (OpenGLESSDF).";
108+
} else {
109+
FML_LOG(IMPORTANT) << "Using the Impeller rendering backend (OpenGLES).";
110+
}
106111
return context;
107112
}
108113

109114
AndroidContextGLImpeller::AndroidContextGLImpeller(
110115
std::unique_ptr<impeller::egl::Display> display,
111116
bool enable_gpu_tracing,
117+
const impeller::Flags& impeller_flags,
112118
std::shared_ptr<fml::BasicTaskRunner> io_task_runner)
113119
: AndroidContext(AndroidRenderingAPI::kImpellerOpenGLES),
114120
reactor_worker_(std::shared_ptr<ReactorWorker>(new ReactorWorker())),
@@ -178,7 +184,7 @@ AndroidContextGLImpeller::AndroidContextGLImpeller(
178184
}
179185

180186
auto impeller_context = CreateImpellerContext(
181-
reactor_worker_, enable_gpu_tracing, io_task_runner_);
187+
reactor_worker_, enable_gpu_tracing, impeller_flags, io_task_runner_);
182188

183189
if (!impeller_context) {
184190
FML_LOG(ERROR) << "Could not create Impeller context.";

‎engine/src/flutter/shell/platform/android/android_context_gl_impeller.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class AndroidContextGLImpeller : public AndroidContext {
1717
AndroidContextGLImpeller(
1818
std::unique_ptr<impeller::egl::Display> display,
1919
bool enable_gpu_tracing,
20+
const impeller::Flags& impeller_flags,
2021
std::shared_ptr<fml::BasicTaskRunner> io_task_runner);
2122

2223
~AndroidContextGLImpeller();

‎engine/src/flutter/shell/platform/android/android_context_gl_impeller_unittests.cc‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ TEST_F(AndroidContextGLImpellerTest, MSAAFirstAttempt) {
8484
.WillOnce(Return(ByMove(std::move(second_result))));
8585
ON_CALL(*display, ChooseConfig(_))
8686
.WillByDefault(Return(ByMove(std::unique_ptr<Config>())));
87-
auto context = std::make_unique<AndroidContextGLImpeller>(std::move(display),
88-
true, nullptr);
87+
auto context = std::make_unique<AndroidContextGLImpeller>(
88+
std::move(display), true, impeller::Flags{}, nullptr);
8989
ASSERT_TRUE(context);
9090
}
9191

@@ -131,8 +131,8 @@ TEST_F(AndroidContextGLImpellerTest, FallbackForEmulator) {
131131
.WillOnce(Return(ByMove(std::move(fourth_result))));
132132
ON_CALL(*display, ChooseConfig(_))
133133
.WillByDefault(Return(ByMove(std::unique_ptr<Config>())));
134-
auto context = std::make_unique<AndroidContextGLImpeller>(std::move(display),
135-
true, nullptr);
134+
auto context = std::make_unique<AndroidContextGLImpeller>(
135+
std::move(display), true, impeller::Flags{}, nullptr);
136136
ASSERT_TRUE(context);
137137
}
138138

‎engine/src/flutter/shell/platform/android/android_context_vk_impeller.cc‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,15 @@ static std::shared_ptr<impeller::Context> CreateImpellerContext(
7373
}
7474

7575
if (!p_settings.quiet) {
76+
const char* backend_name =
77+
p_settings.impeller_flags.use_sdfs ? "VulkanSDF" : "Vulkan";
7678
if (impeller::CapabilitiesVK::Cast(*context->GetCapabilities())
7779
.AreValidationsEnabled()) {
78-
FML_LOG(IMPORTANT) << "Using the Impeller rendering backend (Vulkan with "
79-
"Validation Layers).";
80+
FML_LOG(IMPORTANT) << "Using the Impeller rendering backend ("
81+
<< backend_name << " with Validation Layers).";
8082
} else {
81-
FML_LOG(IMPORTANT) << "Using the Impeller rendering backend (Vulkan).";
83+
FML_LOG(IMPORTANT) << "Using the Impeller rendering backend ("
84+
<< backend_name << ").";
8285
}
8386
}
8487

‎engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/flags/FlutterEngineFlags.java‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,17 @@ public boolean hasCommandLineValue() {
245245
private static final Flag IMPELLER_LAZY_SHADER_MODER =
246246
new Flag("--impeller-lazy-shader-mode", "ImpellerLazyShaderInitialization", true);
247247

248+
/**
249+
* Enables rendering with signed distance fields (SDFs) in Impeller.
250+
*
251+
* <p>SDF rendering produces higher quality anti-aliasing for shapes like rounded rectangles at
252+
* the cost of additional GPU work.
253+
*
254+
* <p>Allowed in release so that developers can opt-in to SDF rendering in production. Settable
255+
* via the command line and the manifest.
256+
*/
257+
private static final Flag IMPELLER_USE_SDFS = new Flag("--impeller-use-sdfs", "EnableSDFs", true);
258+
248259
/**
249260
* Fake flag used for integration testing of the Android embedding processing engine flags.
250261
*
@@ -479,6 +490,7 @@ public boolean hasCommandLineValue() {
479490
TEST_FLAG,
480491
ENABLE_FLUTTER_GPU,
481492
IMPELLER_LAZY_SHADER_MODER,
493+
IMPELLER_USE_SDFS,
482494
IMPELLER_OPENGL_GPU_TRACING,
483495
IMPELLER_VULKAN_GPU_TRACING,
484496
ENABLE_HCPP));

‎engine/src/flutter/shell/platform/android/platform_view_android.cc‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ AndroidContext::ContextSettings CreateContextSettings(
6060
settings.enable_gpu_tracing = p_settings.enable_vulkan_gpu_tracing;
6161
settings.enable_validation = p_settings.enable_vulkan_validation;
6262
settings.enable_surface_control = p_settings.enable_surface_control;
63+
settings.impeller_flags.use_sdfs = p_settings.impeller_use_sdfs;
6364
return settings;
6465
}
6566
} // namespace
@@ -124,7 +125,7 @@ static std::shared_ptr<flutter::AndroidContext> CreateAndroidContext(
124125
case AndroidRenderingAPI::kImpellerOpenGLES:
125126
return std::make_unique<AndroidContextGLImpeller>(
126127
std::make_unique<impeller::egl::Display>(), enable_opengl_gpu_tracing,
127-
std::move(io_task_runner));
128+
settings.impeller_flags, std::move(io_task_runner));
128129
case AndroidRenderingAPI::kImpellerAutoselect:
129130
// Determine if we're using GL or Vulkan.
130131
return std::make_unique<AndroidContextDynamicImpeller>(

‎engine/src/flutter/shell/platform/android/test/io/flutter/embedding/engine/loader/FlutterLoaderTest.java‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,17 @@ public void itSetsImpellerLazyShaderModeFromMetadata() {
12381238
"--impeller-lazy-shader-mode");
12391239
}
12401240

1241+
@Test
1242+
public void itSetsEnableSDFsFromMetadata() {
1243+
// Test debug mode.
1244+
testFlagFromMetadataPresent(
1245+
"io.flutter.embedding.android.EnableSDFs", defaultFlagTestValue, "--impeller-use-sdfs");
1246+
1247+
// Test release mode.
1248+
testFlagFromMetadataPresentInReleaseMode(
1249+
"io.flutter.embedding.android.EnableSDFs", defaultFlagTestValue, "--impeller-use-sdfs");
1250+
}
1251+
12411252
@Test
12421253
public void itSetsEnableOpenGLGPUTracingFromMetadata() {
12431254
testFlagFromMetadataPresent(

0 commit comments

Comments
 (0)