Visitar URL original
Adds switch for sdf rendering plus golden tests (#183543) · mboetger/flutter@34f23f3 · GitHub
Skip to content

Commit 34f23f3

Browse files
gaaclarkemboetger
authored andcommitted
Adds switch for sdf rendering plus golden tests (flutter#183543)
The golden's for MetalSDF should be identical right now. Then we can get a baseline. This setup makes the flag available to canvas.cc via `renderer_.GetContext()->GetFlags().use_sdf`. fixes flutter#183040 fixes flutter#183042 ## 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 documentation (doc comments with `///`). - [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]. **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/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines [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 [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 31a2046 commit 34f23f3

21 files changed

Lines changed: 99 additions & 47 deletions

‎engine/src/flutter/common/settings.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ struct Settings {
241241
// An experimental mode that antialiases lines.
242242
bool impeller_antialiased_lines = false;
243243

244+
// Whether to use SDFs for rendering in Impeller.
245+
bool impeller_use_sdfs = false;
246+
244247
// Log a warning during shell initialization if Impeller is not enabled.
245248
bool warn_on_impeller_opt_out = false;
246249

‎engine/src/flutter/impeller/base/flags.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ namespace impeller {
99
struct Flags {
1010
/// When turned on DrawLine will use the experimental antialiased path.
1111
bool antialiased_lines = false;
12+
/// Use SDFs for rendering.
13+
bool use_sdfs = false;
1214
};
1315
} // namespace impeller
1416

‎engine/src/flutter/impeller/display_list/canvas_unittests.cc‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,8 @@ TEST_P(AiksTest, SupportsBlitToOnscreen) {
381381
auto canvas = CreateTestCanvas(context, Rect::MakeLTRB(0, 0, 100, 100),
382382
/*requires_readback=*/true);
383383

384-
if (GetBackend() != PlaygroundBackend::kMetal) {
384+
if (GetBackend() != PlaygroundBackend::kMetal &&
385+
GetBackend() != PlaygroundBackend::kMetalSDF) {
385386
EXPECT_FALSE(canvas->SupportsBlitToOnscreen());
386387
} else {
387388
EXPECT_TRUE(canvas->SupportsBlitToOnscreen());

‎engine/src/flutter/impeller/golden_tests/golden_playground_test_mac.cc‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ void GoldenPlaygroundTest::SetUp() {
167167
test_name.find("ExperimentAntialiasLines_") != std::string::npos;
168168
switch (GetParam()) {
169169
case PlaygroundBackend::kMetal:
170+
case PlaygroundBackend::kMetalSDF:
170171
if (!DoesSupportWideGamutTests()) {
171172
GTEST_SKIP()
172173
<< "This metal device doesn't support wide gamut golden tests.";

‎engine/src/flutter/impeller/playground/playground.cc‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ std::string PlaygroundBackendToString(PlaygroundBackend backend) {
4848
switch (backend) {
4949
case PlaygroundBackend::kMetal:
5050
return "Metal";
51+
case PlaygroundBackend::kMetalSDF:
52+
return "MetalSDF";
5153
case PlaygroundBackend::kOpenGLES:
5254
return "OpenGLES";
5355
case PlaygroundBackend::kVulkan:
@@ -102,6 +104,7 @@ std::shared_ptr<Context> Playground::MakeContext() const {
102104
bool Playground::SupportsBackend(PlaygroundBackend backend) {
103105
switch (backend) {
104106
case PlaygroundBackend::kMetal:
107+
case PlaygroundBackend::kMetalSDF:
105108
#if IMPELLER_ENABLE_METAL
106109
return true;
107110
#else // IMPELLER_ENABLE_METAL

‎engine/src/flutter/impeller/playground/playground.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class PlaygroundImpl;
2525

2626
enum class PlaygroundBackend {
2727
kMetal,
28+
kMetalSDF,
2829
kOpenGLES,
2930
kVulkan,
3031
};

‎engine/src/flutter/impeller/playground/playground_impl.cc‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ std::unique_ptr<PlaygroundImpl> PlaygroundImpl::Create(
2929
#if IMPELLER_ENABLE_METAL
3030
case PlaygroundBackend::kMetal:
3131
return std::make_unique<PlaygroundImplMTL>(switches);
32+
case PlaygroundBackend::kMetalSDF:
33+
switches.flags.use_sdfs = true;
34+
return std::make_unique<PlaygroundImplMTL>(switches);
3235
#endif // IMPELLER_ENABLE_METAL
3336
#if IMPELLER_ENABLE_OPENGLES
3437
case PlaygroundBackend::kOpenGLES:

‎engine/src/flutter/impeller/playground/playground_test.cc‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ std::string PlaygroundTest::GetWindowTitle() const {
103103
<< flutter::testing::GetCurrentTestName() << "' ";
104104
switch (GetBackend()) {
105105
case PlaygroundBackend::kMetal:
106+
case PlaygroundBackend::kMetalSDF:
106107
break;
107108
case PlaygroundBackend::kOpenGLES:
108109
if (switches_.use_angle) {

‎engine/src/flutter/impeller/playground/playground_test.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ class PlaygroundTest : public Playground,
6161
""; \
6262
INSTANTIATE_TEST_SUITE_P( \
6363
Play, playground, \
64-
::testing::Values(PlaygroundBackend::kMetal, \
65-
PlaygroundBackend::kOpenGLES, \
66-
PlaygroundBackend::kVulkan), \
64+
::testing::Values( \
65+
PlaygroundBackend::kMetal, PlaygroundBackend::kMetalSDF, \
66+
PlaygroundBackend::kOpenGLES, PlaygroundBackend::kVulkan), \
6767
[](const ::testing::TestParamInfo<PlaygroundTest::ParamType>& info) { \
6868
return PlaygroundBackendToString(info.param); \
6969
});

‎engine/src/flutter/impeller/runtime_stage/runtime_stage_unittests.cc‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ TEST_P(RuntimeStageTest, CanReadUniforms) {
8585
switch (GetBackend()) {
8686
case PlaygroundBackend::kMetal:
8787
[[fallthrough]];
88+
case PlaygroundBackend::kMetalSDF:
89+
[[fallthrough]];
8890
case PlaygroundBackend::kOpenGLES: {
8991
ASSERT_EQ(stage->GetUniforms().size(), 14u);
9092
{
@@ -116,7 +118,8 @@ TEST_P(RuntimeStageTest, CanReadUniforms) {
116118
EXPECT_EQ(uni->location, 2u);
117119
EXPECT_EQ(uni->type, RuntimeUniformType::kFloat);
118120
auto padding = uni->padding_layout;
119-
if (GetBackend() == PlaygroundBackend::kMetal) {
121+
if (GetBackend() == PlaygroundBackend::kMetal ||
122+
GetBackend() == PlaygroundBackend::kMetalSDF) {
120123
EXPECT_EQ(padding.size(), 4u);
121124
EXPECT_EQ(padding[0], RuntimePaddingType::kFloat);
122125
EXPECT_EQ(padding[1], RuntimePaddingType::kFloat);

0 commit comments

Comments
 (0)