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] implement blur style solid #50892
Merged
gaaclarke
merged 5 commits into
flutter-team-archive:main
from
gaaclarke:blur-style-solid
Mar 5, 2024
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -204,31 +204,12 @@ int ScaleBlurRadius(Scalar radius, Scalar scalar) { | |
| return static_cast<int>(std::round(radius * scalar)); | ||
| } | ||
|
|
||
| Entity ApplyBlurStyle(FilterContents::BlurStyle blur_style, | ||
| const Entity& entity, | ||
| const std::shared_ptr<FilterInput>& input, | ||
| const Snapshot& input_snapshot, | ||
| Entity blur_entity, | ||
| const std::shared_ptr<Geometry>& geometry) { | ||
| if (blur_style == FilterContents::BlurStyle::kNormal) { | ||
| return blur_entity; | ||
| } | ||
| Entity::ClipOperation clip_operation; | ||
| switch (blur_style) { | ||
| case FilterContents::BlurStyle::kNormal: | ||
| FML_UNREACHABLE(); | ||
| break; | ||
| case FilterContents::BlurStyle::kInner: | ||
| clip_operation = Entity::ClipOperation::kIntersect; | ||
| break; | ||
| case FilterContents::BlurStyle::kOuter: | ||
| clip_operation = Entity::ClipOperation::kDifference; | ||
| break; | ||
| case FilterContents::BlurStyle::kSolid: | ||
| FML_DLOG(ERROR) << "Unimplemented blur style"; | ||
| return blur_entity; | ||
| } | ||
|
|
||
| Entity ApplyClippedBlurStyle(Entity::ClipOperation clip_operation, | ||
| const Entity& entity, | ||
| const std::shared_ptr<FilterInput>& input, | ||
| const Snapshot& input_snapshot, | ||
| Entity blur_entity, | ||
| const std::shared_ptr<Geometry>& geometry) { | ||
| auto shared_blur_entity = std::make_shared<Entity>(std::move(blur_entity)); | ||
| shared_blur_entity->SetNewClipDepth(entity.GetNewClipDepth()); | ||
| auto clipper = std::make_unique<ClipContents>(); | ||
|
|
@@ -255,6 +236,50 @@ Entity ApplyBlurStyle(FilterContents::BlurStyle blur_style, | |
| })); | ||
| return result; | ||
| } | ||
|
|
||
| Entity ApplyBlurStyle(FilterContents::BlurStyle blur_style, | ||
| const Entity& entity, | ||
| const std::shared_ptr<FilterInput>& input, | ||
| const Snapshot& input_snapshot, | ||
| Entity blur_entity, | ||
| const std::shared_ptr<Geometry>& geometry) { | ||
| switch (blur_style) { | ||
| case FilterContents::BlurStyle::kNormal: | ||
| return blur_entity; | ||
| case FilterContents::BlurStyle::kInner: | ||
| return ApplyClippedBlurStyle(Entity::ClipOperation::kIntersect, entity, | ||
| input, input_snapshot, | ||
| std::move(blur_entity), geometry); | ||
| break; | ||
| case FilterContents::BlurStyle::kOuter: | ||
| return ApplyClippedBlurStyle(Entity::ClipOperation::kDifference, entity, | ||
| input, input_snapshot, | ||
| std::move(blur_entity), geometry); | ||
| case FilterContents::BlurStyle::kSolid: { | ||
| Entity blurred = ApplyClippedBlurStyle(Entity::ClipOperation::kIntersect, | ||
| entity, input, input_snapshot, | ||
| std::move(blur_entity), geometry); | ||
| Entity snapshot_entity = Entity::FromSnapshot( | ||
| input_snapshot, entity.GetBlendMode(), entity.GetClipDepth()); | ||
| Entity result; | ||
| result.SetContents(Contents::MakeAnonymous( | ||
| fml::MakeCopyable([blurred = blurred.Clone(), | ||
| snapshot_entity = std::move(snapshot_entity)]( | ||
| const ContentContext& renderer, | ||
| const Entity& entity, | ||
| RenderPass& pass) mutable { | ||
| bool did_render = true; | ||
| did_render = blurred.Render(renderer, pass) && did_render; | ||
| did_render = snapshot_entity.Render(renderer, pass) && did_render; | ||
| return did_render; | ||
| }), | ||
| fml::MakeCopyable([blurred = blurred.Clone()](const Entity& entity) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be simpler to grab the coverage here and pass it in?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| return blurred.GetCoverage(); | ||
| }))); | ||
| return result; | ||
| } | ||
| } | ||
| } | ||
| } // namespace | ||
|
|
||
| std::string_view GaussianBlurFilterContents::kNoMipsError = | ||
|
|
@@ -499,7 +524,7 @@ std::optional<Entity> GaussianBlurFilterContents::RenderFilter( | |
| SamplerDescriptor sampler_desc = MakeSamplerDescriptor( | ||
| MinMagFilter::kLinear, SamplerAddressMode::kClampToEdge); | ||
|
|
||
| auto blur_output_entity = Entity::FromSnapshot( | ||
| Entity blur_output_entity = Entity::FromSnapshot( | ||
| Snapshot{.texture = pass3_out.value().GetRenderTargetTexture(), | ||
| .transform = input_snapshot->transform * | ||
| padding_snapshot_adjustment * | ||
|
|
@@ -508,13 +533,9 @@ std::optional<Entity> GaussianBlurFilterContents::RenderFilter( | |
| .opacity = input_snapshot->opacity}, | ||
| entity.GetBlendMode(), entity.GetClipDepth()); | ||
|
|
||
| if (!blur_output_entity.has_value()) { | ||
| return std::nullopt; | ||
| } | ||
|
|
||
| return ApplyBlurStyle(mask_blur_style_, entity, inputs[0], | ||
| input_snapshot.value(), | ||
| std::move(blur_output_entity.value()), mask_geometry_); | ||
| input_snapshot.value(), std::move(blur_output_entity), | ||
| mask_geometry_); | ||
| } | ||
|
|
||
| Scalar GaussianBlurFilterContents::CalculateBlurRadius(Scalar sigma) { | ||
|
|
||
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
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.
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.
That's not functionally equivalent because of short-circuiting. I was thinking we still want to render the snapshot even if the blurred draw fails for some reason.
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.
If part of rendering fails then we should almost always be bailing out to a toplevel VALIDATION_LOG handler or error. partially correct is still wrong, so I'd prefer the simpler approach.
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 think those validation errors are noops in release builds though, right? Not a huge deal, done.