Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
aiks_dl_atlas_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
11
23
24namespace impeller {
25namespace testing {
26
27using namespace flutter;
28
29namespace {
30RSTransform MakeTranslation(Scalar tx, Scalar ty) {
31 return RSTransform::Make({tx, ty}, 1, DlDegrees(0));
32}
33
34std::tuple<std::vector<DlRect>, //
35 std::vector<RSTransform>, //
36 sk_sp<DlImageImpeller>>
37CreateTestData(const AiksTest* test) {
38 // Draws the image as four squares stiched together.
39 auto atlas =
40 DlImageImpeller::Make(test->CreateTextureForFixture("bay_bridge.jpg"));
41 auto size = atlas->GetImpellerTexture(test->GetContext())->GetSize();
42 // Divide image into four quadrants.
43 Scalar half_width = size.width / 2;
44 Scalar half_height = size.height / 2;
45 std::vector<DlRect> texture_coordinates = {
46 DlRect::MakeLTRB(0, 0, half_width, half_height),
47 DlRect::MakeLTRB(half_width, 0, size.width, half_height),
48 DlRect::MakeLTRB(0, half_height, half_width, size.height),
49 DlRect::MakeLTRB(half_width, half_height, size.width, size.height)};
50 // Position quadrants adjacent to eachother.
51 std::vector<RSTransform> transforms = {
52 MakeTranslation(0, 0), MakeTranslation(half_width, 0),
53 MakeTranslation(0, half_height),
54 MakeTranslation(half_width, half_height)};
55 return std::make_tuple(texture_coordinates, transforms, atlas);
56}
57
58} // namespace
59
60TEST_P(AiksTest, DrawAtlasNoColor) {
61 DisplayListBuilder builder;
62 auto [texture_coordinates, transforms, atlas] = CreateTestData(this);
63
64 builder.Scale(GetContentScale().x, GetContentScale().y);
65 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
66 /*colors=*/nullptr, /*count=*/4, DlBlendMode::kSrcOver,
67 DlImageSampling::kNearestNeighbor, nullptr);
68
69 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
70}
71
72TEST_P(AiksTest, DrawAtlasWithColorAdvanced) {
73 DisplayListBuilder builder;
74 auto [texture_coordinates, transforms, atlas] = CreateTestData(this);
75
76 std::vector<DlColor> colors = {DlColor::kRed(), DlColor::kGreen(),
78
79 builder.Scale(GetContentScale().x, GetContentScale().y);
80 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
81 colors.data(), /*count=*/4, DlBlendMode::kModulate,
82 DlImageSampling::kNearestNeighbor, /*cullRect=*/nullptr);
83
84 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
85}
86
87TEST_P(AiksTest, DrawAtlasWithColorSimple) {
88 DisplayListBuilder builder;
89 // Draws the image as four squares stiched together.
90 auto [texture_coordinates, transforms, atlas] = CreateTestData(this);
91
92 std::vector<DlColor> colors = {DlColor::kRed(), DlColor::kGreen(),
94
95 builder.Scale(GetContentScale().x, GetContentScale().y);
96 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
97 colors.data(), /*count=*/4, DlBlendMode::kSrcATop,
98 DlImageSampling::kNearestNeighbor, /*cullRect=*/nullptr);
99
100 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
101}
102
103TEST_P(AiksTest, DrawAtlasWithOpacity) {
104 DisplayListBuilder builder;
105 // Draws the image as four squares stiched together slightly
106 // opaque
107 auto [texture_coordinates, transforms, atlas] = CreateTestData(this);
108
109 DlPaint paint;
110 paint.setAlpha(128);
111 builder.Scale(GetContentScale().x, GetContentScale().y);
112 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
113 /*colors=*/nullptr, 4, DlBlendMode::kSrcOver,
114 DlImageSampling::kNearestNeighbor, /*cullRect=*/nullptr,
115 &paint);
116
117 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
118}
119
120TEST_P(AiksTest, DrawAtlasNoColorFullSize) {
121 auto atlas = DlImageImpeller::Make(CreateTextureForFixture("bay_bridge.jpg"));
122 auto size = atlas->GetImpellerTexture(GetContext())->GetSize();
123 std::vector<DlRect> texture_coordinates = {
124 DlRect::MakeLTRB(0, 0, size.width, size.height)};
125 std::vector<RSTransform> transforms = {MakeTranslation(0, 0)};
126
127 DisplayListBuilder builder;
128 builder.Scale(GetContentScale().x, GetContentScale().y);
129 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
130 /*colors=*/nullptr, /*count=*/1, DlBlendMode::kSrcOver,
131 DlImageSampling::kNearestNeighbor, /*cullRect=*/nullptr);
132
133 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
134}
135
136// Regression test for https://github.com/flutter/flutter/issues/127374.
137TEST_P(AiksTest, DrawAtlasAdvancedAndTransform) {
138 DisplayListBuilder builder;
139 // Draws the image as four squares stiched together.
140 auto [texture_coordinates, transforms, atlas] = CreateTestData(this);
141
142 builder.Scale(0.25, 0.25);
143 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
144 /*colors=*/nullptr, /*count=*/4, DlBlendMode::kModulate,
145 DlImageSampling::kNearestNeighbor, /*cullRect=*/nullptr);
146
147 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
148}
149
150// Regression test for https://github.com/flutter/flutter/issues/127374.
151TEST_P(AiksTest, DrawAtlasWithColorAdvancedAndTransform) {
152 DisplayListBuilder builder;
153 // Draws the image as four squares stiched together.
154 auto [texture_coordinates, transforms, atlas] = CreateTestData(this);
155 std::vector<DlColor> colors = {DlColor::kRed(), DlColor::kGreen(),
157
158 builder.Scale(0.25, 0.25);
159 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
160 colors.data(), /*count=*/4, DlBlendMode::kModulate,
161 DlImageSampling::kNearestNeighbor, /*cullRect=*/nullptr);
162
163 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
164}
165
166TEST_P(AiksTest, DrawAtlasPlusWideGamut) {
167 DisplayListBuilder builder;
168 EXPECT_EQ(GetContext()->GetCapabilities()->GetDefaultColorFormat(),
170
171 // Draws the image as four squares stiched together.
172 auto [texture_coordinates, transforms, atlas] = CreateTestData(this);
173 std::vector<DlColor> colors = {DlColor::kRed(), DlColor::kGreen(),
175
176 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
177 colors.data(), /*count=*/4, DlBlendMode::kPlus,
178 DlImageSampling::kNearestNeighbor, /*cullRect=*/nullptr);
179
180 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
181}
182
183TEST_P(AiksTest, DlAtlasGeometryNoBlendRenamed) {
184 auto [texture_coordinates, transforms, atlas] = CreateTestData(this);
185
186 DlAtlasGeometry geom(atlas->GetImpellerTexture(GetContext()),
187 transforms.data(), texture_coordinates.data(), nullptr,
188 transforms.size(), BlendMode::kSrcOver, {},
189 std::nullopt);
190
191 EXPECT_FALSE(geom.ShouldUseBlend());
192 EXPECT_FALSE(geom.ShouldSkip());
193
194 ContentContext context(GetContext(), nullptr);
195 auto vertex_buffer =
197
198 EXPECT_EQ(vertex_buffer.index_type, IndexType::kNone);
199 EXPECT_EQ(vertex_buffer.vertex_count, texture_coordinates.size() * 6);
200}
201
202TEST_P(AiksTest, DlAtlasGeometryBlend) {
203 auto [texture_coordinates, transforms, atlas] = CreateTestData(this);
204
205 std::vector<DlColor> colors;
206 colors.reserve(texture_coordinates.size());
207 for (auto i = 0u; i < texture_coordinates.size(); i++) {
208 colors.push_back(DlColor::ARGB(0.5, 1, 1, 1));
209 }
210 DlAtlasGeometry geom(atlas->GetImpellerTexture(GetContext()),
211 transforms.data(), texture_coordinates.data(),
212 colors.data(), transforms.size(), BlendMode::kSrcOver,
213 {}, std::nullopt);
214
215 EXPECT_TRUE(geom.ShouldUseBlend());
216 EXPECT_FALSE(geom.ShouldSkip());
217
218 ContentContext context(GetContext(), nullptr);
219 auto vertex_buffer =
221
222 EXPECT_EQ(vertex_buffer.index_type, IndexType::kNone);
223 EXPECT_EQ(vertex_buffer.vertex_count, texture_coordinates.size() * 6);
224}
225
226TEST_P(AiksTest, DlAtlasGeometryColorButNoBlend) {
227 auto [texture_coordinates, transforms, atlas] = CreateTestData(this);
228
229 std::vector<DlColor> colors;
230 colors.reserve(texture_coordinates.size());
231 for (auto i = 0u; i < texture_coordinates.size(); i++) {
232 colors.push_back(DlColor::ARGB(0.5, 1, 1, 1));
233 }
234 DlAtlasGeometry geom(atlas->GetImpellerTexture(GetContext()),
235 transforms.data(), texture_coordinates.data(),
236 colors.data(), transforms.size(), BlendMode::kSrc, {},
237 std::nullopt);
238
239 // Src blend mode means that colors would be ignored, even if provided.
240 EXPECT_FALSE(geom.ShouldUseBlend());
241 EXPECT_FALSE(geom.ShouldSkip());
242}
243
244TEST_P(AiksTest, DlAtlasGeometrySkip) {
245 auto [texture_coordinates, transforms, atlas] = CreateTestData(this);
246
247 std::vector<DlColor> colors;
248 colors.reserve(texture_coordinates.size());
249 for (auto i = 0u; i < texture_coordinates.size(); i++) {
250 colors.push_back(DlColor::ARGB(0.5, 1, 1, 1));
251 }
252 DlAtlasGeometry geom(atlas->GetImpellerTexture(GetContext()),
253 transforms.data(), texture_coordinates.data(),
254 colors.data(), transforms.size(), BlendMode::kClear, {},
255 std::nullopt);
256 EXPECT_TRUE(geom.ShouldSkip());
257}
258
259TEST_P(AiksTest, DrawImageRectWithBlendColorFilter) {
260 sk_sp<DlImageImpeller> texture =
261 DlImageImpeller::Make(CreateTextureForFixture("bay_bridge.jpg"));
262
263 DisplayListBuilder builder;
265 DlColor::kRed().withAlphaF(0.4), DlBlendMode::kSrcOver));
266
267 DlMatrix filter_matrix = DlMatrix();
268 auto filter = flutter::DlMatrixImageFilter(filter_matrix,
270 DlPaint paint_with_filter = paint;
271 paint_with_filter.setImageFilter(&filter);
272
273 // Compare porter-duff blend modes.
274 builder.DrawPaint(DlPaint().setColor(DlColor::kWhite()));
275 // Uses image filter to disable atlas conversion.
276 builder.DrawImageRect(texture, DlRect::MakeSize(texture->GetSize()),
277 DlRect::MakeLTRB(0, 0, 500, 500), {},
278 &paint_with_filter);
279
280 // Uses atlas conversion.
281 builder.Translate(600, 0);
282 builder.DrawImageRect(texture, DlRect::MakeSize(texture->GetSize()),
283 DlRect::MakeLTRB(0, 0, 500, 500), {}, &paint);
284
285 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
286}
287
288TEST_P(AiksTest, DrawImageRectWithMatrixColorFilter) {
289 sk_sp<DlImageImpeller> texture =
290 DlImageImpeller::Make(CreateTextureForFixture("bay_bridge.jpg"));
291
292 DisplayListBuilder builder;
293 static const constexpr ColorMatrix kColorInversion = {
294 .array = {
295 -1.0, 0, 0, 1.0, 0, //
296 0, -1.0, 0, 1.0, 0, //
297 0, 0, -1.0, 1.0, 0, //
298 1.0, 1.0, 1.0, 1.0, 0 //
299 }};
302
303 DlMatrix filter_matrix = DlMatrix();
304 auto filter = flutter::DlMatrixImageFilter(filter_matrix,
306 DlPaint paint_with_filter = paint;
307 paint_with_filter.setImageFilter(&filter);
308
309 // Compare inverting color matrix filter.
310 builder.DrawPaint(DlPaint().setColor(DlColor::kWhite()));
311 // Uses image filter to disable atlas conversion.
312 builder.DrawImageRect(texture, DlRect::MakeSize(texture->GetSize()),
313 DlRect::MakeLTRB(0, 0, 500, 500), {},
314 &paint_with_filter);
315
316 // Uses atlas conversion.
317 builder.Translate(600, 0);
318 builder.DrawImageRect(texture, DlRect::MakeSize(texture->GetSize()),
319 DlRect::MakeLTRB(0, 0, 500, 500), {}, &paint);
320
321 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
322}
323
324TEST_P(AiksTest, DrawAtlasWithColorBurn) {
325 DisplayListBuilder builder;
326 auto [texture_coordinates, transforms, atlas] = CreateTestData(this);
327
328 std::vector<DlColor> colors = {DlColor::kDarkGrey(), DlColor::kBlack(),
330
331 builder.Scale(GetContentScale().x, GetContentScale().y);
332 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
333 colors.data(), /*count=*/4, DlBlendMode::kColorBurn,
334 DlImageSampling::kNearestNeighbor, /*cullRect=*/nullptr);
335
336 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
337}
338
339} // namespace testing
340} // namespace impeller
void DrawImageRect(const sk_sp< DlImage > &image, const DlRect &src, const DlRect &dst, DlImageSampling sampling, const DlPaint *paint=nullptr, DlSrcRectConstraint constraint=DlSrcRectConstraint::kFast) override
void DrawAtlas(const sk_sp< DlImage > &atlas, const DlRSTransform xform[], const DlRect tex[], const DlColor colors[], int count, DlBlendMode mode, DlImageSampling sampling, const DlRect *cullRect, const DlPaint *paint=nullptr) override
void Scale(DlScalar sx, DlScalar sy) override
void Translate(DlScalar tx, DlScalar ty) override
void DrawPaint(const DlPaint &paint) override
sk_sp< DisplayList > Build()
static std::shared_ptr< const DlColorFilter > MakeBlend(DlColor color, DlBlendMode mode)
static std::shared_ptr< const DlColorFilter > MakeMatrix(const float matrix[20])
DlPaint & setAlpha(uint8_t alpha)
Definition dl_paint.h:76
DlPaint & setImageFilter(std::nullptr_t filter)
Definition dl_paint.h:167
DlPaint & setColorFilter(std::nullptr_t filter)
Definition dl_paint.h:149
HostBuffer & GetTransientsDataBuffer() const
Retrieve the current host buffer for transient storage of other non-index data.
A wrapper around data provided by a drawAtlas call.
VertexBuffer CreateBlendVertexBuffer(HostBuffer &host_buffer) const override
bool ShouldUseBlend() const override
Whether the blend shader should be used.
bool ShouldSkip() const override
VertexBuffer CreateSimpleVertexBuffer(HostBuffer &host_buffer) const override
static sk_sp< DlImageImpeller > Make(std::shared_ptr< Texture > texture, OwningContext owning_context=OwningContext::kIO)
int32_t x
FlTexture * texture
double y
impeller::Matrix DlMatrix
impeller::Degrees DlDegrees
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
AiksPlayground AiksTest
TEST_P(AiksTest, DrawAtlasNoColor)
float Scalar
Definition scalar.h:19
@ kNone
Does not use the index buffer.
static const constexpr ColorMatrix kColorInversion
A color matrix which inverts colors.
static constexpr DlColor kWhite()
Definition dl_color.h:70
static constexpr DlColor kBlue()
Definition dl_color.h:73
static constexpr DlColor kBlack()
Definition dl_color.h:69
static constexpr DlColor ARGB(DlScalar a, DlScalar r, DlScalar g, DlScalar b)
Construct a 32 bit color from floating point A, R, G, and B color channels.
Definition dl_color.h:57
static constexpr DlColor kYellow()
Definition dl_color.h:76
static constexpr DlColor kLightGrey()
Definition dl_color.h:79
static constexpr DlColor kRed()
Definition dl_color.h:71
static constexpr DlColor kGreen()
Definition dl_color.h:72
static constexpr DlColor kDarkGrey()
Definition dl_color.h:77
Scalar array[20]
Definition color.h:118
A 4x4 matrix using column-major storage.
Definition matrix.h:37
static RSTransform Make(Point origin, Scalar scale, Radians radians)
Definition rstransform.h:38
static constexpr TRect MakeSize(const TSize< U > &size)
Definition rect.h:150
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition rect.h:129