This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] moved blur to unrotated local space, started respecting respect_ctm flag
#53377
Merged
Merged
Changes from 4 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
dabd931
[Impeller] moved blur to unrotated local space, started respecting `r…
gaaclarke 1550833
[Impeller] Respect the respect_ctm flag for mask blurred text & absor…
bdero 4349868
added golden tests
gaaclarke 298830f
updated docs
gaaclarke e7a6953
cleanup
gaaclarke eab54b0
fixed coverage test
gaaclarke b19a8ad
updated golden list
gaaclarke e6e87bc
tidy
gaaclarke 1099da1
license
gaaclarke 1ead6da
changed test background
gaaclarke 9787191
oops
gaaclarke a3a03f2
fixed solid blur style
gaaclarke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #include "impeller/display_list/dl_golden_unittests.h" | ||
|
|
||
| #include "flutter/display_list/dl_builder.h" | ||
| #include "flutter/display_list/effects/dl_mask_filter.h" | ||
| #include "flutter/testing/testing.h" | ||
| #include "gtest/gtest.h" | ||
| #include "impeller/typographer/backends/skia/text_frame_skia.h" | ||
| #include "txt/platform.h" | ||
|
|
||
| namespace flutter { | ||
| namespace testing { | ||
|
|
||
| using impeller::Font; | ||
|
|
||
| namespace { | ||
| struct TextRenderOptions { | ||
| bool stroke = false; | ||
| SkScalar font_size = 50; | ||
| DlColor color = DlColor::kYellow(); | ||
| std::shared_ptr<DlMaskFilter> mask_filter; | ||
| }; | ||
|
|
||
| bool RenderTextInCanvasSkia(DlCanvas* canvas, | ||
| const std::string& text, | ||
| const std::string_view& font_fixture, | ||
| SkPoint position, | ||
| TextRenderOptions options = {}) { | ||
| auto c_font_fixture = std::string(font_fixture); | ||
| auto mapping = flutter::testing::OpenFixtureAsSkData(c_font_fixture.c_str()); | ||
| if (!mapping) { | ||
| return false; | ||
| } | ||
| sk_sp<SkFontMgr> font_mgr = txt::GetDefaultFontManager(); | ||
| SkFont sk_font(font_mgr->makeFromData(mapping), options.font_size); | ||
| auto blob = SkTextBlob::MakeFromString(text.c_str(), sk_font); | ||
| if (!blob) { | ||
| return false; | ||
| } | ||
|
|
||
| auto frame = impeller::MakeTextFrameFromTextBlobSkia(blob); | ||
|
|
||
| DlPaint text_paint; | ||
| text_paint.setColor(options.color); | ||
| text_paint.setMaskFilter(options.mask_filter); | ||
| // text_paint.mask_blur_descriptor = options.mask_blur_descriptor; | ||
| // text_paint.stroke_width = 1; | ||
| // text_paint.style = | ||
| // options.stroke ? Paint::Style::kStroke : Paint::Style::kFill; | ||
| canvas->DrawTextFrame(frame, position.x(), position.y(), text_paint); | ||
| return true; | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| TEST_P(DlGoldenTest, TextBlurMaskFilterRespectCTM) { | ||
| impeller::Point content_scale = GetContentScale(); | ||
| auto draw = [&](DlCanvas* canvas, | ||
| const std::vector<std::unique_ptr<DlImage>>& images) { | ||
| canvas->Scale(content_scale.x, content_scale.y); | ||
| canvas->Scale(2, 2); | ||
| TextRenderOptions options; | ||
| options.mask_filter = | ||
| DlBlurMaskFilter::Make(DlBlurStyle::kNormal, /*sigma=*/10, | ||
| /*respect_ctm=*/true); | ||
| ASSERT_TRUE(RenderTextInCanvasSkia(canvas, "hello world", | ||
| "Roboto-Regular.ttf", | ||
| SkPoint::Make(100, 100), options)); | ||
| }; | ||
|
|
||
| DisplayListBuilder builder; | ||
| draw(&builder, /*images=*/{}); | ||
|
|
||
| ASSERT_TRUE(OpenPlaygroundHere(builder.Build())); | ||
| } | ||
|
|
||
| TEST_P(DlGoldenTest, TextBlurMaskFilterDisrespectCTM) { | ||
| impeller::Point content_scale = GetContentScale(); | ||
| auto draw = [&](DlCanvas* canvas, | ||
| const std::vector<std::unique_ptr<DlImage>>& images) { | ||
| canvas->Scale(content_scale.x, content_scale.y); | ||
| canvas->Scale(2, 2); | ||
| TextRenderOptions options; | ||
| options.mask_filter = | ||
| DlBlurMaskFilter::Make(DlBlurStyle::kNormal, /*sigma=*/10, | ||
| /*respect_ctm=*/false); | ||
| ASSERT_TRUE(RenderTextInCanvasSkia(canvas, "hello world", | ||
| "Roboto-Regular.ttf", | ||
| SkPoint::Make(100, 100), options)); | ||
| }; | ||
|
|
||
| DisplayListBuilder builder; | ||
| draw(&builder, /*images=*/{}); | ||
|
|
||
| ASSERT_TRUE(OpenPlaygroundHere(builder.Build())); | ||
| } | ||
|
|
||
| } // namespace testing | ||
| } // namespace flutter |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Matrix::Decompose here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked at that and it was way more calculations for things we just throw away. It's doing things like calculating the determinant. It returns an optional result probably for this reason. This one is guaranteed to have a result too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These matrix mults are just recomputing the basis vectors, which could just be pulled out of the matrix instead:
return Vector2(matrix.GetBasisX().Length(), matrix.GetBasisY().Length())Matrix::GetScaledoes the same thing, but includes the Z basis and returns aVector3. Adding aMatrix::GetScaleXYseems like a good idea since we're doing this in a few places now.