Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
morphology_filter_contents_unittests.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
10
11namespace impeller {
12namespace testing {
13
15 public:
16 std::shared_ptr<Texture> MakeTexture(ISize size) {
17 std::shared_ptr<CommandBuffer> command_buffer =
18 GetContentContext()->GetContext()->CreateCommandBuffer();
19 if (!command_buffer) {
20 return nullptr;
21 }
22
23 auto render_target = GetContentContext()->MakeSubpass(
24 "Clear Subpass", size, command_buffer,
25 [](const ContentContext&, RenderPass&) { return true; });
26
28 ->GetContext()
29 ->GetCommandQueue()
30 ->Submit(/*buffers=*/{command_buffer})
31 .ok()) {
32 return nullptr;
33 }
34
35 if (render_target.ok()) {
36 return render_target.value().GetRenderTargetTexture();
37 }
38 return nullptr;
39 }
40};
41
43
44TEST_P(MorphologyFilterContentsTest, RenderCoverageMatchesGetCoverage) {
45 std::shared_ptr<Texture> texture = MakeTexture(ISize(100, 100));
46 ASSERT_NE(texture, nullptr);
50
51 Entity entity;
52 std::shared_ptr<ContentContext> renderer = GetContentContext();
53 std::optional<Entity> result =
54 contents->GetEntity(*renderer, entity, /*coverage_hint=*/{});
55
56 ASSERT_TRUE(result.has_value());
57 if (result.has_value()) {
58 std::optional<Rect> result_coverage = result.value().GetCoverage();
59 std::optional<Rect> contents_coverage = contents->GetCoverage(entity);
60 Rect expected = Rect::MakeLTRB(-2, 0, 102, 100);
61 ASSERT_TRUE(result_coverage.has_value());
62 ASSERT_TRUE(contents_coverage.has_value());
63 if (result_coverage.has_value() && contents_coverage.has_value()) {
64 EXPECT_TRUE(RectNear(result_coverage.value(), expected));
65 EXPECT_TRUE(RectNear(contents_coverage.value(), expected));
66 }
67 }
68}
69
71 RenderDilateWithFractionalCoverageIsSymmetric) {
72 // Non-integer scale and radius produce a fractional pixel expansion
73 // 1.5 * 2.625 = 3.9375, exercising the render target ceiling logic.
74 Scalar radius = 1.5;
75 Scalar scale = 2.625;
76
77 std::shared_ptr<Texture> texture = MakeTexture(ISize(100, 100));
78 ASSERT_NE(texture, nullptr);
80 FilterInput::Make(texture), Radius{radius}, Vector2(1, 0),
82 contents->SetEffectTransform(Matrix::MakeScale(Vector2(scale, scale)));
83
84 Entity entity;
85 std::shared_ptr<ContentContext> renderer = GetContentContext();
86 std::optional<Entity> result =
87 contents->GetEntity(*renderer, entity, /*coverage_hint=*/{});
88
89 ASSERT_TRUE(result.has_value());
90 if (result.has_value()) {
91 std::optional<Rect> result_coverage = result->GetCoverage();
92 ASSERT_TRUE(result_coverage.has_value());
93 if (result_coverage.has_value()) {
94 Scalar expected_expansion = radius * scale;
95 EXPECT_TRUE(result_coverage->Contains(Rect::MakeLTRB(
96 -expected_expansion, 0, 100 + expected_expansion, 100)));
97 Scalar left_expansion = 0 - result_coverage->GetLeft();
98 Scalar right_expansion = result_coverage->GetRight() - 100;
99 EXPECT_NEAR(left_expansion, right_expansion, 0.5);
100 }
101 }
102}
103
105 RenderDilateYWithFractionalCoverageIsSymmetric) {
106 // Non-integer scale and radius produce a fractional pixel expansion
107 // 1.5 * 2.625 = 3.9375, exercising the render target ceiling logic.
108 Scalar radius = 1.5;
109 Scalar scale = 2.625;
110
111 std::shared_ptr<Texture> texture = MakeTexture(ISize(100, 100));
112 ASSERT_NE(texture, nullptr);
114 FilterInput::Make(texture), Radius{radius}, Vector2(0, 1),
116 contents->SetEffectTransform(Matrix::MakeScale(Vector2(scale, scale)));
117
118 Entity entity;
119 std::shared_ptr<ContentContext> renderer = GetContentContext();
120 std::optional<Entity> result =
121 contents->GetEntity(*renderer, entity, /*coverage_hint=*/{});
122
123 ASSERT_TRUE(result.has_value());
124 if (result.has_value()) {
125 std::optional<Rect> result_coverage = result->GetCoverage();
126 ASSERT_TRUE(result_coverage.has_value());
127 if (result_coverage.has_value()) {
128 Scalar expected_expansion = radius * scale;
129 EXPECT_TRUE(result_coverage->Contains(Rect::MakeLTRB(
130 0, -expected_expansion, 100, 100 + expected_expansion)));
131 Scalar top_expansion = 0 - result_coverage->GetTop();
132 Scalar bottom_expansion = result_coverage->GetBottom() - 100;
133 EXPECT_NEAR(top_expansion, bottom_expansion, 0.5);
134 }
135 }
136}
137
138} // namespace testing
139} // namespace impeller
std::shared_ptr< ContentContext > GetContentContext() const
static std::shared_ptr< FilterContents > MakeDirectionalMorphology(FilterInput::Ref input, Radius radius, Vector2 direction, MorphType morph_type)
static FilterInput::Ref Make(Variant input, bool msaa_enabled=true)
std::shared_ptr< Context > GetContext() const
Definition playground.cc:94
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition render_pass.h:30
inline ::testing::AssertionResult RectNear(impeller::Rect a, impeller::Rect b)
FlTexture * texture
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
TEST_P(AiksTest, DrawAtlasNoColor)
Point Vector2
Definition point.h:430
float Scalar
Definition scalar.h:19
ISize64 ISize
Definition size.h:162
#define INSTANTIATE_PLAYGROUND_SUITE(playground)
static constexpr Matrix MakeScale(const Vector3 &s)
Definition matrix.h:104
For convolution filters, the "radius" is the size of the convolution kernel to use on the local space...
Definition sigma.h:48
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition rect.h:129