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] scales blur coverage to match rendered output #47621
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
9554a95
[Impeller] added new gaussian blur
gaaclarke 3d86c8f
added directional_gaussian unittests to help
gaaclarke 48c754e
added filtersourcecoverage
gaaclarke d61ac96
added more tests
gaaclarke 789a5da
got a possitive rendering test
gaaclarke 348f8ee
refactor
gaaclarke b7a328e
added coverage fix
gaaclarke 88e7f35
removed stray gaussian blur files
gaaclarke 33c3faf
license
gaaclarke 05711b8
moved to entityplayground
gaaclarke 9bade3d
renamed test
gaaclarke d46a891
license
gaaclarke 6017a65
lint fix
gaaclarke 19f7381
tidy
gaaclarke a2b8868
lint
gaaclarke f46ff8c
lint, sorry really should have checked these locally
gaaclarke 20f2fc8
removed mocks
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 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 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 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
129 changes: 129 additions & 0 deletions
129
impeller/entity/contents/filters/directional_gaussian_blur_filter_contents_unittests.cc
This file contains 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,129 @@ | ||
// 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 "flutter/testing/testing.h" | ||
#include "gmock/gmock.h" | ||
#include "impeller/entity/contents/content_context.h" | ||
#include "impeller/entity/contents/filters/directional_gaussian_blur_filter_contents.h" | ||
#include "impeller/entity/entity_playground.h" | ||
#include "impeller/renderer/testing/mocks.h" | ||
|
||
namespace impeller { | ||
namespace testing { | ||
|
||
using ::testing::Return; | ||
|
||
namespace { | ||
|
||
Scalar CalculateSigmaForBlurRadius(Scalar blur_radius) { | ||
// See Sigma.h | ||
return (blur_radius / kKernelRadiusPerSigma) + 0.5; | ||
} | ||
} // namespace | ||
|
||
class DirectionalGaussianBlurFilterContentsTest : public EntityPlayground { | ||
public: | ||
// Stubs in the minimal support to make rendering pass. | ||
void SetupMinimalMockContext() { | ||
// This mocking code was removed since it wasn't strictly needed yet. If it | ||
// is needed you can find it here: | ||
// https://gist.github.com/gaaclarke/c2f6bf5fc6ecb10678da03789abc5843. | ||
} | ||
}; | ||
|
||
INSTANTIATE_PLAYGROUND_SUITE(DirectionalGaussianBlurFilterContentsTest); | ||
|
||
TEST_P(DirectionalGaussianBlurFilterContentsTest, CoverageWithEffectTransform) { | ||
TextureDescriptor desc = { | ||
.format = PixelFormat::kB8G8R8A8UNormInt, | ||
.size = ISize(100, 100), | ||
}; | ||
Scalar sigma_radius_1 = CalculateSigmaForBlurRadius(1.0); | ||
auto contents = std::make_unique<DirectionalGaussianBlurFilterContents>(); | ||
contents->SetSigma(Sigma{sigma_radius_1}); | ||
contents->SetDirection({1.0, 0.0}); | ||
std::shared_ptr<Texture> texture = | ||
GetContentContext()->GetContext()->GetResourceAllocator()->CreateTexture( | ||
desc); | ||
FilterInput::Vector inputs = {FilterInput::Make(texture)}; | ||
Entity entity; | ||
entity.SetTransformation(Matrix::MakeTranslation({100, 100, 0})); | ||
std::optional<Rect> coverage = contents->GetFilterCoverage( | ||
inputs, entity, /*effect_transform=*/Matrix::MakeScale({2.0, 2.0, 1.0})); | ||
EXPECT_TRUE(coverage.has_value()); | ||
if (coverage.has_value()) { | ||
EXPECT_NEAR(coverage->GetLeft(), 100 - 2, | ||
0.5); // Higher tolerance for sigma scaling. | ||
EXPECT_NEAR(coverage->GetTop(), 100, 0.01); | ||
EXPECT_NEAR(coverage->GetRight(), 200 + 2, | ||
0.5); // Higher tolerance for sigma scaling. | ||
EXPECT_NEAR(coverage->GetBottom(), 200, 0.01); | ||
} | ||
} | ||
|
||
TEST(DirectionalGaussianBlurFilterContentsTest, FilterSourceCoverage) { | ||
Scalar sigma_radius_1 = CalculateSigmaForBlurRadius(1.0); | ||
auto contents = std::make_unique<DirectionalGaussianBlurFilterContents>(); | ||
contents->SetSigma(Sigma{sigma_radius_1}); | ||
contents->SetDirection({1.0, 0.0}); | ||
std::optional<Rect> coverage = contents->GetFilterSourceCoverage( | ||
/*effect_transform=*/Matrix::MakeScale({2.0, 2.0, 1.0}), | ||
/*output_limit=*/Rect::MakeLTRB(100, 100, 200, 200)); | ||
ASSERT_EQ(coverage, Rect::MakeLTRB(100 - 2, 100, 200 + 2, 200)); | ||
} | ||
|
||
TEST_P(DirectionalGaussianBlurFilterContentsTest, RenderNoCoverage) { | ||
Scalar sigma_radius_1 = CalculateSigmaForBlurRadius(1.0); | ||
auto contents = std::make_unique<DirectionalGaussianBlurFilterContents>(); | ||
contents->SetSigma(Sigma{sigma_radius_1}); | ||
contents->SetDirection({1.0, 0.0}); | ||
std::shared_ptr<ContentContext> renderer = GetContentContext(); | ||
Entity entity; | ||
Rect coverage_hint = Rect::MakeLTRB(0, 0, 0, 0); | ||
std::optional<Entity> result = | ||
contents->GetEntity(*renderer, entity, coverage_hint); | ||
ASSERT_FALSE(result.has_value()); | ||
} | ||
|
||
TEST_P(DirectionalGaussianBlurFilterContentsTest, | ||
RenderCoverageMatchesGetCoverage) { | ||
TextureDescriptor desc = { | ||
.format = PixelFormat::kB8G8R8A8UNormInt, | ||
.size = ISize(100, 100), | ||
}; | ||
std::shared_ptr<Texture> texture = | ||
GetContentContext()->GetContext()->GetResourceAllocator()->CreateTexture( | ||
desc); | ||
Scalar sigma_radius_1 = CalculateSigmaForBlurRadius(1.0); | ||
auto contents = std::make_unique<DirectionalGaussianBlurFilterContents>(); | ||
contents->SetSigma(Sigma{sigma_radius_1}); | ||
contents->SetDirection({1.0, 0.0}); | ||
contents->SetInputs({FilterInput::Make(texture)}); | ||
std::shared_ptr<ContentContext> renderer = GetContentContext(); | ||
|
||
Entity entity; | ||
std::optional<Entity> result = | ||
contents->GetEntity(*renderer, entity, /*coverage_hint=*/{}); | ||
EXPECT_TRUE(result.has_value()); | ||
if (result.has_value()) { | ||
EXPECT_EQ(result.value().GetBlendMode(), BlendMode::kSourceOver); | ||
std::optional<Rect> result_coverage = result.value().GetCoverage(); | ||
std::optional<Rect> contents_coverage = contents->GetCoverage(entity); | ||
EXPECT_TRUE(result_coverage.has_value()); | ||
EXPECT_TRUE(contents_coverage.has_value()); | ||
if (result_coverage.has_value() && contents_coverage.has_value()) { | ||
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. Consider adding an Expect_rect_near macro 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. That'll problem happen if the new blur has better test coverage like i hope. |
||
EXPECT_NEAR(result_coverage.value().GetLeft(), | ||
contents_coverage.value().GetLeft(), kEhCloseEnough); | ||
EXPECT_NEAR(result_coverage.value().GetTop(), | ||
contents_coverage.value().GetTop(), kEhCloseEnough); | ||
EXPECT_NEAR(result_coverage.value().GetRight(), | ||
contents_coverage.value().GetRight(), kEhCloseEnough); | ||
EXPECT_NEAR(result_coverage.value().GetBottom(), | ||
contents_coverage.value().GetBottom(), kEhCloseEnough); | ||
} | ||
} | ||
} | ||
|
||
} // namespace testing | ||
} // namespace impeller |
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.
Oh, missed this!