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
Fixes MatrixFilterContents rendering/coverage #52880
Merged
Merged
Changes from 19 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
2f9ad87
[Impeller] fixed matrix transform
gaaclarke d127c47
cleaned up test
gaaclarke 464a8c6
[Impeller] Fix MatrixFilter multiplication ordering for subpasses. (#…
bdero a6fddde
started adding coverage tests
gaaclarke 7100e5c
expanded tests
gaaclarke 0f18297
added test
gaaclarke a63c263
added more tests
gaaclarke e22fa1b
expanded tests
gaaclarke 05fcaf0
added test that breaks
gaaclarke c2aecb2
format
gaaclarke 62c200a
removed stray comments
gaaclarke 93043dc
added scale test for non subpass
gaaclarke c44f4cb
hackfix
gaaclarke a6c8b2a
removed some test code
gaaclarke 3b53a74
cleaned up hack
gaaclarke a5d4d18
tweaked golden
gaaclarke aaae45e
cleanup
gaaclarke 228b5a6
license
gaaclarke 4097c92
updated golden
gaaclarke 4f4845b
fixes MatrixImageFilterMagnify
gaaclarke 49b23cb
fix attempt 2
gaaclarke 8cc1df6
introduced the new render modes for the matrix filter
gaaclarke 4960576
updated tests
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
198 changes: 198 additions & 0 deletions
198
impeller/entity/contents/filters/matrix_filter_contents_unittests.cc
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,198 @@ | ||
| // 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/filters/matrix_filter_contents.h" | ||
| #include "impeller/entity/entity_playground.h" | ||
| #include "impeller/geometry/geometry_asserts.h" | ||
|
|
||
| namespace impeller { | ||
| namespace testing { | ||
|
|
||
| class MatrixFilterContentsTest : public EntityPlayground { | ||
| public: | ||
| /// Create a texture that has been cleared to transparent black. | ||
| std::shared_ptr<Texture> MakeTexture(ISize size) { | ||
| std::shared_ptr<CommandBuffer> command_buffer = | ||
| GetContentContext()->GetContext()->CreateCommandBuffer(); | ||
| if (!command_buffer) { | ||
| return nullptr; | ||
| } | ||
|
|
||
| auto render_target = GetContentContext()->MakeSubpass( | ||
| "Clear Subpass", size, command_buffer, | ||
| [](const ContentContext&, RenderPass&) { return true; }); | ||
|
|
||
| if (!GetContentContext() | ||
| ->GetContext() | ||
| ->GetCommandQueue() | ||
| ->Submit(/*buffers=*/{command_buffer}) | ||
| .ok()) { | ||
| return nullptr; | ||
| } | ||
|
|
||
| if (render_target.ok()) { | ||
| return render_target.value().GetRenderTargetTexture(); | ||
| } | ||
| return nullptr; | ||
| } | ||
| }; | ||
|
|
||
| INSTANTIATE_PLAYGROUND_SUITE(MatrixFilterContentsTest); | ||
|
|
||
| TEST(MatrixFilterContentsTest, Create) { | ||
| MatrixFilterContents contents; | ||
| EXPECT_TRUE(contents.IsTranslationOnly()); | ||
| } | ||
|
|
||
| TEST(MatrixFilterContentsTest, CoverageEmpty) { | ||
| MatrixFilterContents contents; | ||
| FilterInput::Vector inputs = {}; | ||
| Entity entity; | ||
| std::optional<Rect> coverage = | ||
| contents.GetFilterCoverage(inputs, entity, /*effect_transform=*/Matrix()); | ||
| ASSERT_FALSE(coverage.has_value()); | ||
| } | ||
|
|
||
| TEST(MatrixFilterContentsTest, CoverageSimple) { | ||
| MatrixFilterContents contents; | ||
| FilterInput::Vector inputs = { | ||
| FilterInput::Make(Rect::MakeLTRB(10, 10, 110, 110))}; | ||
| Entity entity; | ||
| std::optional<Rect> coverage = | ||
| contents.GetFilterCoverage(inputs, entity, /*effect_transform=*/Matrix()); | ||
|
|
||
| ASSERT_EQ(coverage, Rect::MakeLTRB(10, 10, 110, 110)); | ||
| } | ||
|
|
||
| TEST(MatrixFilterContentsTest, Coverage2x) { | ||
| MatrixFilterContents contents; | ||
| contents.SetMatrix(Matrix::MakeScale({2.0, 2.0, 1.0})); | ||
| FilterInput::Vector inputs = { | ||
| FilterInput::Make(Rect::MakeXYWH(10, 10, 100, 100))}; | ||
| Entity entity; | ||
| std::optional<Rect> coverage = | ||
| contents.GetFilterCoverage(inputs, entity, /*effect_transform=*/Matrix()); | ||
|
|
||
| ASSERT_EQ(coverage, Rect::MakeXYWH(20, 20, 200, 200)); | ||
| } | ||
|
|
||
| TEST(MatrixFilterContentsTest, Coverage2xEffect) { | ||
| MatrixFilterContents contents; | ||
| FilterInput::Vector inputs = { | ||
| FilterInput::Make(Rect::MakeXYWH(10, 10, 100, 100))}; | ||
| Entity entity; | ||
| std::optional<Rect> coverage = contents.GetFilterCoverage( | ||
| inputs, entity, /*effect_transform=*/Matrix::MakeScale({2.0, 2.0, 1.0})); | ||
|
|
||
| ASSERT_EQ(coverage, Rect::MakeXYWH(10, 10, 100, 100)); | ||
| } | ||
|
|
||
| namespace { | ||
| void expectRenderCoverageEqual(const std::optional<Entity>& result, | ||
| const std::optional<Rect> contents_coverage, | ||
| const Rect& expected) { | ||
| EXPECT_TRUE(result.has_value()); | ||
| if (result.has_value()) { | ||
| EXPECT_EQ(result.value().GetBlendMode(), BlendMode::kSourceOver); | ||
| std::optional<Rect> result_coverage = result.value().GetCoverage(); | ||
| EXPECT_TRUE(result_coverage.has_value()); | ||
| EXPECT_TRUE(contents_coverage.has_value()); | ||
| if (result_coverage.has_value() && contents_coverage.has_value()) { | ||
| EXPECT_TRUE(RectNear(contents_coverage.value(), expected)); | ||
| EXPECT_TRUE(RectNear(result_coverage.value(), expected)); | ||
| } | ||
| } | ||
| } | ||
| } // namespace | ||
|
|
||
| TEST_P(MatrixFilterContentsTest, RenderCoverageMatchesGetCoverageIdentity) { | ||
| std::shared_ptr<Texture> texture = MakeTexture(ISize(100, 100)); | ||
| MatrixFilterContents contents; | ||
| contents.SetInputs({FilterInput::Make(texture)}); | ||
|
|
||
| Entity entity; | ||
| entity.SetTransform(Matrix::MakeTranslation({100, 200, 0})); | ||
|
|
||
| std::shared_ptr<ContentContext> renderer = GetContentContext(); | ||
| std::optional<Entity> result = | ||
| contents.GetEntity(*renderer, entity, /*coverage_hint=*/{}); | ||
| expectRenderCoverageEqual(result, contents.GetCoverage(entity), | ||
| Rect::MakeXYWH(100, 200, 100, 100)); | ||
| } | ||
|
|
||
| TEST_P(MatrixFilterContentsTest, RenderCoverageMatchesGetCoverageTranslate) { | ||
| std::shared_ptr<Texture> texture = MakeTexture(ISize(100, 100)); | ||
| MatrixFilterContents contents; | ||
| contents.SetInputs({FilterInput::Make(texture)}); | ||
| contents.SetMatrix(Matrix::MakeTranslation({50, 100, 0})); | ||
| contents.SetEffectTransform(Matrix::MakeScale({2, 2, 1})); | ||
|
|
||
| Entity entity; | ||
| entity.SetTransform(Matrix::MakeTranslation({100, 200, 0})); | ||
|
|
||
| std::shared_ptr<ContentContext> renderer = GetContentContext(); | ||
| std::optional<Entity> result = | ||
| contents.GetEntity(*renderer, entity, /*coverage_hint=*/{}); | ||
| expectRenderCoverageEqual(result, contents.GetCoverage(entity), | ||
| Rect::MakeXYWH(150, 300, 100, 100)); | ||
| } | ||
|
|
||
| TEST_P(MatrixFilterContentsTest, | ||
| RenderCoverageMatchesGetCoverageSubpassTranslate) { | ||
| std::shared_ptr<Texture> texture = MakeTexture(ISize(100, 100)); | ||
| MatrixFilterContents contents; | ||
| contents.SetInputs({FilterInput::Make(texture)}); | ||
| contents.SetMatrix(Matrix::MakeTranslation({50, 100, 0})); | ||
| contents.SetEffectTransform(Matrix::MakeScale({2, 2, 1})); | ||
| contents.SetRenderingMode(Entity::RenderingMode::kSubpass); | ||
|
|
||
| Entity entity; | ||
| entity.SetTransform(Matrix::MakeTranslation({100, 200, 0})); | ||
|
|
||
| std::shared_ptr<ContentContext> renderer = GetContentContext(); | ||
| std::optional<Entity> result = | ||
| contents.GetEntity(*renderer, entity, /*coverage_hint=*/{}); | ||
| expectRenderCoverageEqual(result, contents.GetCoverage(entity), | ||
| Rect::MakeXYWH(200, 400, 100, 100)); | ||
| } | ||
|
|
||
| TEST_P(MatrixFilterContentsTest, RenderCoverageMatchesGetCoverageScale) { | ||
| std::shared_ptr<Texture> texture = MakeTexture(ISize(100, 100)); | ||
| MatrixFilterContents contents; | ||
| contents.SetInputs({FilterInput::Make(texture)}); | ||
| contents.SetMatrix(Matrix::MakeScale({3, 3, 1})); | ||
| contents.SetEffectTransform(Matrix::MakeScale({2, 2, 1})); | ||
|
|
||
| Entity entity; | ||
| entity.SetTransform(Matrix::MakeTranslation({100, 200, 0})); | ||
|
|
||
| std::shared_ptr<ContentContext> renderer = GetContentContext(); | ||
| std::optional<Entity> result = | ||
| contents.GetEntity(*renderer, entity, /*coverage_hint=*/{}); | ||
| expectRenderCoverageEqual(result, contents.GetCoverage(entity), | ||
| Rect::MakeXYWH(100, 200, 300, 300)); | ||
| } | ||
|
|
||
| TEST_P(MatrixFilterContentsTest, RenderCoverageMatchesGetCoverageSubpassScale) { | ||
| std::shared_ptr<Texture> texture = MakeTexture(ISize(100, 100)); | ||
| MatrixFilterContents contents; | ||
| contents.SetInputs({FilterInput::Make(texture)}); | ||
| contents.SetMatrix(Matrix::MakeScale({3, 3, 1})); | ||
| contents.SetEffectTransform(Matrix::MakeScale({2, 2, 1})); | ||
| contents.SetRenderingMode(Entity::RenderingMode::kSubpass); | ||
|
|
||
| Entity entity; | ||
| entity.SetTransform(Matrix::MakeTranslation({100, 200, 0})); | ||
|
|
||
| std::shared_ptr<ContentContext> renderer = GetContentContext(); | ||
| std::optional<Entity> result = | ||
| contents.GetEntity(*renderer, entity, /*coverage_hint=*/{}); | ||
| expectRenderCoverageEqual(result, contents.GetCoverage(entity), | ||
| Rect::MakeXYWH(100, 200, 300, 300)); | ||
| } | ||
|
|
||
| } // namespace testing | ||
| } // namespace impeller |
Oops, something went wrong.
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.
@bdero this is what I was talking about the other day. We should be sharing the math between rendering and coverage.