| Flutter Impeller |

Typedefs | Functions
flutter::testing Namespace Reference

## Typedefs
using | DlGoldenTest = impeller::DlPlayground

## Functions
| TEST_P (DlGoldenTest, TextBlurMaskFilterRespectCTM)
| TEST_P (DlGoldenTest, TextBlurMaskFilterDisrespectCTM)
| TEST_P (DlGoldenTest, ShimmerTest)
| TEST_P (DlGoldenTest, StrokedRRectFastBlur)
| TEST_P (DlGoldenTest, LargeDownscaleRrect)
| INSTANTIATE_PLAYGROUND_SUITE (DlGoldenTest)
| TEST_P (DlGoldenTest, CanDrawPaint)
| TEST_P (DlGoldenTest, CanRenderImage)
| TEST_P (DlGoldenTest, Bug147807)
| TEST_P (DlGoldenTest, GaussianVsRRectBlur)
| TEST_P (DlGoldenTest, GaussianVsRRectBlurScaled)
| TEST_P (DlGoldenTest, GaussianVsRRectBlurScaledRotated)
| TEST_P (DlGoldenTest, FastVsGeneralGaussianMaskBlur)
| TEST_P (DlGoldenTest, DashedLinesTest)
| TEST_P (DlGoldenTest, SaveLayerAtFractionalValue)
| TEST_P (DlGoldenTest, BaselineHE)
| TEST_P (DlGoldenTest, MaintainsSpace)
| TEST_P (DlGoldenTest, Subpixel)
| TEST_P (DlGoldenTest, SubpixelScaled)
| TEST_P (DlGoldenTest, SubpixelScaledTranslated)

## Typedef Documentation

## ◆ DlGoldenTest

using flutter::testing::DlGoldenTest = typedef impeller::DlPlayground

Definition at line 17 of file dl_golden_unittests.h.

## Function Documentation

## ◆ INSTANTIATE_PLAYGROUND_SUITE()

flutter::testing::INSTANTIATE_PLAYGROUND_SUITE | ( | DlGoldenTest |  | ) |

## ◆ TEST_P() [1/19]

flutter::testing::TEST_P | ( | DlGoldenTest | ,
|  | BaselineHE |
| ) |  |

Definition at line 387 of file dl_golden_unittests.cc.

387 {
388 SetWindowSize(impeller::ISize(1024, 200));
389 impeller::Scalar font_size = 300;
390 auto callback = [&](const char* text,
391 impeller::Scalar scale) -> sk_sp<DisplayList> {
392 DisplayListBuilder builder;
393 DlPaint paint;
394 paint.setColor(DlColor::ARGB(1, 0, 0, 0));
395 builder.DrawPaint(paint);
396 builder.Scale(scale, scale);
397 RenderTextInCanvasSkia(&builder, text, "Roboto-Regular.ttf",
398 DlPoint::MakeXY(10, 300),
399 TextRenderOptions{
400 .font_size = font_size,
401 });
402 return builder.Build();
403 };
404
405 std::unique_ptr<impeller::testing::Screenshot> right =
406 MakeScreenshot(callback("h", 0.444));
407 if (!right) {
408 GTEST_SKIP() << "making screenshots not supported.";
409 }
410 std::unique_ptr<impeller::testing::Screenshot> left =
411 MakeScreenshot(callback("e", 0.444));
412
413 int32_t left_max_y = CalculateMaxY(left.get());
414 int32_t right_max_y = CalculateMaxY(right.get());
415 int32_t y_diff = std::abs(left_max_y - right_max_y);
416 EXPECT_TRUE(y_diff <= 2) << "y diff: " << y_diff;
417 }
impeller::testing::RenderTextInCanvasSkia
bool RenderTextInCanvasSkia(const std::shared_ptr< Context > &context, DisplayListBuilder &canvas, const std::string &text, const std::string_view &font_fixture, const TextRenderOptions &options={}, const std::optional< SkFont > &font=std::nullopt)
Definition: aiks_dl_text_unittests.cc:46
impeller::Scalar
float Scalar
Definition: scalar.h:19
impeller::TSize
Definition: size.h:25
font_size
Scalar font_size
Definition: text_contents_unittests.cc:27

References font_size, and impeller::testing::RenderTextInCanvasSkia().

## ◆ TEST_P() [2/19]

flutter::testing::TEST_P | ( | DlGoldenTest | ,
|  | Bug147807 |
| ) |  |

Definition at line 63 of file dl_golden_unittests.cc.

63 {
64 Point content_scale = GetContentScale();
65 auto draw = [content_scale](DlCanvas* canvas,
66 const std::vector<sk_sp<DlImage>>& images) {
67 canvas->Scale(content_scale.x, content_scale.y);
68 DlPaint paint;
69 paint.setColor(DlColor(0xfffef7ff));
70 canvas->DrawRect(DlRect::MakeLTRB(0, 0, 375, 667), paint);
71 paint.setColor(DlColor(0xffff9800));
72 canvas->DrawRect(DlRect::MakeLTRB(0, 0, 187.5, 333.5), paint);
73 paint.setColor(DlColor(0xff9c27b0));
74 canvas->DrawRect(DlRect::MakeLTRB(187.5, 0, 375, 333.5), paint);
75 paint.setColor(DlColor(0xff4caf50));
76 canvas->DrawRect(DlRect::MakeLTRB(0, 333.5, 187.5, 667), paint);
77 paint.setColor(DlColor(0xfff44336));
78 canvas->DrawRect(DlRect::MakeLTRB(187.5, 333.5, 375, 667), paint);
79
80 canvas->Save();
81 {
82 canvas->ClipRoundRect(
83 DlRoundRect::MakeOval(DlRect::MakeLTRB(201.25, 10, 361.25, 170)),
84 DlClipOp::kIntersect, true);
85 DlRect save_layer_bounds = DlRect::MakeLTRB(201.25, 10, 361.25, 170);
86 auto backdrop =
87 DlImageFilter::MakeMatrix(DlMatrix::MakeRow(3, 0, 0.0, -280, //
88 0, 3, 0.0, -920, //
89 0, 0, 1.0, 0.0, //
90 0, 0, 0.0, 1.0),
91 DlImageSampling::kLinear);
92 canvas->SaveLayer(save_layer_bounds, /*paint=*/nullptr, backdrop.get());
93 {
94 canvas->Translate(201.25, 10);
95 auto paint = DlPaint()
96 .setAntiAlias(true)
97 .setColor(DlColor(0xff2196f3))
98 .setStrokeWidth(5)
99 .setDrawStyle(DlDrawStyle::kStroke);
100 canvas->DrawCircle(DlPoint(80, 80), 80, paint);
101 }
102 canvas->Restore();
103 }
104 canvas->Restore();
105 };
106
107 DisplayListBuilder builder;
108 std::vector<sk_sp<DlImage>> images;
109 draw(&builder, images);
110
111 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
112 }
impeller::DlRect
flutter::DlRect DlRect
Definition: dl_dispatcher.h:25
impeller::Point
TPoint< Scalar > Point
Definition: point.h:425
impeller::DlPoint
flutter::DlPoint DlPoint
Definition: dl_dispatcher.h:24

## ◆ TEST_P() [3/19]

flutter::testing::TEST_P | ( | DlGoldenTest | ,
|  | CanDrawPaint |
| ) |  |

Definition at line 29 of file dl_golden_unittests.cc.

29 {
30 auto draw = [](DlCanvas* canvas,
31 const std::vector<std::unique_ptr<DlImage>>& images) {
32 canvas->Scale(0.2, 0.2);
33 DlPaint paint;
34 paint.setColor(DlColor::kCyan());
35 canvas->DrawPaint(paint);
36 };
37
38 DisplayListBuilder builder;
39 draw(&builder, /*images=*/{});
40
41 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
42 }

## ◆ TEST_P() [4/19]

flutter::testing::TEST_P | ( | DlGoldenTest | ,
|  | CanRenderImage |
| ) |  |

Definition at line 44 of file dl_golden_unittests.cc.

44 {
45 auto draw = [](DlCanvas* canvas, const std::vector<sk_sp<DlImage>>& images) {
46 FML_CHECK(images.size() >= 1);
47 DlPaint paint;
48 paint.setColor(DlColor::kRed());
49 canvas->DrawImage(images[0], DlPoint(100.0, 100.0),
50 DlImageSampling::kLinear, &paint);
51 };
52
53 DisplayListBuilder builder;
54 std::vector<sk_sp<DlImage>> images;
55 images.emplace_back(CreateDlImageForFixture("kalimba.jpg"));
56 draw(&builder, images);
57
58 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
59 }

## ◆ TEST_P() [5/19]

flutter::testing::TEST_P | ( | DlGoldenTest | ,
|  | DashedLinesTest |
| ) |  |

Definition at line 270 of file dl_golden_unittests.cc.

270 {
271 Point content_scale = GetContentScale();
272 auto draw = [content_scale](DlCanvas* canvas,
273 const std::vector<sk_sp<DlImage>>& images) {
274 canvas->Scale(content_scale.x, content_scale.y);
275 canvas->DrawPaint(DlPaint().setColor(DlColor::kWhite()));
276
277 auto draw_one = [canvas](DlStrokeCap cap, Scalar x, Scalar y,
278 Scalar dash_on, Scalar dash_off) {
279 Point center = Point(x, y);
280 Scalar inner = 20.0f;
281 Scalar outer = 100.0f;
282 DlPaint thick_paint = DlPaint()
283 .setColor(DlColor::kBlue())
284 .setStrokeCap(cap)
285 .setStrokeWidth(8.0f);
286 DlPaint middle_paint = DlPaint()
287 .setColor(DlColor::kGreen())
288 .setStrokeCap(cap)
289 .setStrokeWidth(5.0f);
290 DlPaint thin_paint = DlPaint()
291 .setColor(DlColor::kMagenta())
292 .setStrokeCap(cap)
293 .setStrokeWidth(2.0f);
294 for (int degrees = 0; degrees < 360; degrees += 30) {
295 Point delta = Point(1.0f, 0.0f).Rotate(Degrees(degrees));
296 canvas->DrawDashedLine(center + inner * delta, center + outer * delta,
297 dash_on, dash_off, thick_paint);
298 canvas->DrawDashedLine(center + inner * delta, center + outer * delta,
299 dash_on, dash_off, middle_paint);
300 canvas->DrawDashedLine(center + inner * delta, center + outer * delta,
301 dash_on, dash_off, thin_paint);
302 }
303 };
304
305 draw_one(DlStrokeCap::kButt, 150.0f, 150.0f, 15.0f, 10.0f);
306 draw_one(DlStrokeCap::kSquare, 400.0f, 150.0f, 15.0f, 10.0f);
307 draw_one(DlStrokeCap::kRound, 150.0f, 400.0f, 15.0f, 10.0f);
308 draw_one(DlStrokeCap::kRound, 400.0f, 400.0f, 0.0f, 11.0f);
309
310 // Make sure the rendering op responds appropriately to clipping
311 canvas->Save();
312 DlPathBuilder path_builder;
313 path_builder.MoveTo(DlPoint(275.0f, 225.0f));
314 path_builder.LineTo(DlPoint(325.0f, 275.0f));
315 path_builder.LineTo(DlPoint(275.0f, 325.0f));
316 path_builder.LineTo(DlPoint(225.0f, 275.0f));
317 canvas->ClipPath(path_builder.TakePath());
318 canvas->DrawColor(DlColor::kYellow());
319 draw_one(DlStrokeCap::kRound, 275.0f, 275.0f, 15.0f, 10.0f);
320 canvas->Restore();
321 };
322
323 DisplayListBuilder builder;
324 std::vector<sk_sp<DlImage>> images;
325 draw(&builder, images);
326
327 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
328 }
x
int32_t x
Definition: dl_golden_unittests.cc:458
impeller::TPoint::Rotate
constexpr TPoint Rotate(const Radians &angle) const
Definition: point.h:314

References impeller::TPoint< T >::Rotate(), and x.

## ◆ TEST_P() [6/19]

flutter::testing::TEST_P | ( | DlGoldenTest | ,
|  | FastVsGeneralGaussianMaskBlur |
| ) |  |

Definition at line 195 of file dl_golden_unittests.cc.

195 {
196 DisplayListBuilder builder;
197 builder.Scale(GetContentScale().x, GetContentScale().y);
198 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
199
200 auto blur_sigmas = std::array{5.0f, 10.0f, 20.0f};
201 auto blur_colors = std::array{
202 DlColor::kBlue(),
203 DlColor::kGreen(),
204 DlColor::kMaroon(),
205 };
206
207 auto make_rrect_path = [](const DlRect& rect, DlScalar rx,
208 DlScalar ry) -> DlPath {
209 auto add_corner = [](DlPathBuilder& path_builder, DlPoint corner,
210 DlVector2 relative_from, DlVector2 relative_to,
211 bool first) {
212 static const auto magic = DlPathBuilder::kArcApproximationMagic;
213
214 if (first) {
215 path_builder.MoveTo(corner + relative_from);
216 } else {
217 path_builder.LineTo(corner + relative_from);
218 }
219 // These fractions should be (1 - magic) to make a proper rrect
220 // path, but historically these equations were as written here.
221 // On the plus side, they ensure that we will not optimize this
222 // path as "Hey, look, it's an RRect", but the DrawPath gaussians
223 // will otherwise not be identical to the versions drawn with
224 // DrawRoundRect
225 path_builder.CubicCurveTo(corner + relative_from * magic,
226 corner + relative_to * magic,
227 corner + relative_to);
228 };
229
230 DlPathBuilder path_builder;
231 add_corner(path_builder, rect.GetRightTop(), //
232 DlVector2(-rx, 0.0f), DlVector2(0.0f, ry), true);
233 add_corner(path_builder, rect.GetRightBottom(), //
234 DlVector2(0.0f, -ry), DlVector2(-rx, 0.0f), false);
235 add_corner(path_builder, rect.GetLeftBottom(), //
236 DlVector2(rx, 0.0f), DlVector2(0.0f, -ry), false);
237 add_corner(path_builder, rect.GetLeftTop(), //
238 DlVector2(0.0f, ry), DlVector2(rx, 0.0f), false);
239 return path_builder.TakePath();
240 };
241
242 for (size_t i = 0; i < blur_sigmas.size(); i++) {
243 auto rect = DlRect::MakeXYWH(i * 320.0f + 50.0f, 50.0f, 100.0f, 100.0f);
244 DlPaint paint = DlPaint() //
245 .setColor(blur_colors[i])
246 .setMaskFilter(DlBlurMaskFilter::Make(
247 DlBlurStyle::kNormal, blur_sigmas[i]));
248
249 builder.DrawRoundRect(DlRoundRect::MakeRectXY(rect, 10.0f, 10.0f), paint);
250 rect = rect.Shift(150.0f, 0.0f);
251 builder.DrawPath(make_rrect_path(rect, 10.0f, 10.0f), paint);
252 rect = rect.Shift(-150.0f, 0.0f);
253
254 rect = rect.Shift(0.0f, 200.0f);
255 builder.DrawRoundRect(DlRoundRect::MakeRectXY(rect, 10.0f, 30.0f), paint);
256 rect = rect.Shift(150.0f, 0.0f);
257 builder.DrawPath(make_rrect_path(rect, 10.0f, 20.0f), paint);
258 rect = rect.Shift(-150.0f, 0.0f);
259
260 rect = rect.Shift(0.0f, 200.0f);
261 builder.DrawRoundRect(DlRoundRect::MakeRectXY(rect, 30.0f, 10.0f), paint);
262 rect = rect.Shift(150.0f, 0.0f);
263 builder.DrawPath(make_rrect_path(rect, 20.0f, 10.0f), paint);
264 rect = rect.Shift(-150.0f, 0.0f);
265 }
266
267 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
268 }
impeller::DlPath
flutter::DlPath DlPath
Definition: dl_dispatcher.h:29
impeller::DlScalar
flutter::DlScalar DlScalar
Definition: dl_dispatcher.h:23

References x.

## ◆ TEST_P() [7/19]

flutter::testing::TEST_P | ( | DlGoldenTest | ,
|  | GaussianVsRRectBlur |
| ) |  |

Definition at line 141 of file dl_golden_unittests.cc.

141 {
142 Point content_scale = GetContentScale();
143 auto draw = [content_scale](DlCanvas* canvas,
144 const std::vector<sk_sp<DlImage>>& images) {
145 canvas->Scale(content_scale.x, content_scale.y);
146 canvas->DrawPaint(DlPaint().setColor(DlColor(0xff112233)));
147 DrawBlurGrid(canvas);
148 };
149
150 DisplayListBuilder builder;
151 std::vector<sk_sp<DlImage>> images;
152 draw(&builder, images);
153
154 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
155 }

## ◆ TEST_P() [8/19]

flutter::testing::TEST_P | ( | DlGoldenTest | ,
|  | GaussianVsRRectBlurScaled |
| ) |  |

Definition at line 157 of file dl_golden_unittests.cc.

157 {
158 Point content_scale = GetContentScale();
159 auto draw = [content_scale](DlCanvas* canvas,
160 const std::vector<sk_sp<DlImage>>& images) {
161 canvas->Scale(content_scale.x, content_scale.y);
162 canvas->DrawPaint(DlPaint().setColor(DlColor(0xff112233)));
163 canvas->Scale(0.33, 0.33);
164 DrawBlurGrid(canvas);
165 };
166
167 DisplayListBuilder builder;
168 std::vector<sk_sp<DlImage>> images;
169 draw(&builder, images);
170
171 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
172 }

## ◆ TEST_P() [9/19]

flutter::testing::TEST_P | ( | DlGoldenTest | ,
|  | GaussianVsRRectBlurScaledRotated |
| ) |  |

Definition at line 174 of file dl_golden_unittests.cc.

174 {
175 Point content_scale = GetContentScale();
176 auto draw = [content_scale](DlCanvas* canvas,
177 const std::vector<sk_sp<DlImage>>& images) {
178 canvas->Scale(content_scale.x, content_scale.y);
179 canvas->Translate(200, 200);
180 canvas->DrawPaint(DlPaint().setColor(DlColor(0xff112233)));
181 canvas->Scale(0.33, 0.33);
182 canvas->Translate(300, 300);
183 canvas->Rotate(45);
184 canvas->Translate(-300, -300);
185 DrawBlurGrid(canvas);
186 };
187
188 DisplayListBuilder builder;
189 std::vector<sk_sp<DlImage>> images;
190 draw(&builder, images);
191
192 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
193 }

## ◆ TEST_P() [10/19]

flutter::testing::TEST_P | ( | DlGoldenTest | ,
|  | LargeDownscaleRrect |
| ) |  |

Definition at line 181 of file dl_golden_blur_unittests.cc.

181 {
182 impeller::Point content_scale = GetContentScale();
183 auto draw = [&](DlCanvas* canvas, const std::vector<sk_sp<DlImage>>& images) {
184 canvas->Scale(content_scale.x, content_scale.y);
185 canvas->DrawColor(DlColor(0xff111111));
186 {
187 canvas->Save();
188 canvas->Scale(0.25, 0.25);
189 DlPaint paint;
190 paint.setColor(DlColor::kYellow());
191 paint.setMaskFilter(
192 DlBlurMaskFilter::Make(DlBlurStyle::kNormal, /*sigma=*/1000));
193 canvas->DrawCircle(DlPoint(0, 0), 1200, paint);
194 canvas->Restore();
195 }
196
197 DlPaint paint;
198 paint.setColor(DlColor::kYellow());
199 paint.setMaskFilter(
200 DlBlurMaskFilter::Make(DlBlurStyle::kNormal, /*sigma=*/250));
201 canvas->DrawCircle(DlPoint(1024, 768), 300, paint);
202 };
203
204 DisplayListBuilder builder;
205 draw(&builder, /*images=*/{});
206
207 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
208 }
impeller::TPoint< Scalar >
impeller::TPoint::y
Type y
Definition: point.h:32
impeller::TPoint::x
Type x
Definition: point.h:31

References impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

## ◆ TEST_P() [11/19]

flutter::testing::TEST_P | ( | DlGoldenTest | ,
|  | MaintainsSpace |
| ) |  |

Definition at line 419 of file dl_golden_unittests.cc.

419 {
420 SetWindowSize(impeller::ISize(1024, 200));
421 impeller::Scalar font_size = 300;
422 auto callback = [&](const char* text,
423 impeller::Scalar scale) -> sk_sp<DisplayList> {
424 DisplayListBuilder builder;
425 DlPaint paint;
426 paint.setColor(DlColor::ARGB(1, 0, 0, 0));
427 builder.DrawPaint(paint);
428 builder.Scale(scale, scale);
429 RenderTextInCanvasSkia(&builder, text, "Roboto-Regular.ttf",
430 DlPoint::MakeXY(10, 300),
431 TextRenderOptions{
432 .font_size = font_size,
433 });
434 return builder.Build();
435 };
436
437 std::optional<int32_t> last_space;
438 for (int i = 0; i <= 100; ++i) {
439 Scalar scale = 0.440 + i / 1000.0;
440 std::unique_ptr<impeller::testing::Screenshot> right =
441 MakeScreenshot(callback("ui", scale));
442 if (!right) {
443 GTEST_SKIP() << "making screenshots not supported.";
444 }
445
446 int32_t space = CalculateSpaceBetweenUI(right.get());
447 if (last_space.has_value()) {
448 int32_t diff = abs(space - *last_space);
449 EXPECT_TRUE(diff <= 1)
450 << "i:" << i << " space:" << space << " last_space:" << *last_space;
451 }
452 last_space = space;
453 }
454 }

References font_size, and impeller::testing::RenderTextInCanvasSkia().

## ◆ TEST_P() [12/19]

flutter::testing::TEST_P | ( | DlGoldenTest | ,
|  | SaveLayerAtFractionalValue |
| ) |  |

Definition at line 330 of file dl_golden_unittests.cc.

330 {
331 // Draws a stroked rounded rect at a fractional pixel value. The coverage must
332 // be adjusted so that we still have room to draw it, even though it lies on
333 // the fractional bounds of the saveLayer.
334 DisplayListBuilder builder;
335 builder.DrawPaint(DlPaint().setColor(DlColor::kWhite()));
336 auto save_paint = DlPaint().setAlpha(100);
337 builder.SaveLayer(std::nullopt, &save_paint);
338
339 builder.DrawRoundRect(DlRoundRect::MakeRectRadius(
340 DlRect::MakeLTRB(10.5, 10.5, 200.5, 200.5), 10),
341 DlPaint()
342 .setDrawStyle(DlDrawStyle::kStroke)
343 .setStrokeWidth(1.5)
344 .setColor(DlColor::kBlack()));
345 builder.DrawCircle(DlPoint::MakeXY(100, 100), 50.5,
346 DlPaint().setColor(DlColor::kAqua()));
347 builder.DrawCircle(DlPoint::MakeXY(110, 110), 50.5,
348 DlPaint().setColor(DlColor::kCyan()));
349
350 builder.Restore();
351
352 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
353 }

## ◆ TEST_P() [13/19]

flutter::testing::TEST_P | ( | DlGoldenTest | ,
|  | ShimmerTest |
| ) |  |

Definition at line 81 of file dl_golden_blur_unittests.cc.

81 {
82 impeller::Point content_scale = GetContentScale();
83 auto draw = [&](DlCanvas* canvas, const std::vector<sk_sp<DlImage>>& images,
84 float sigma) {
85 canvas->DrawColor(DlColor(0xff111111));
86 canvas->Scale(content_scale.x, content_scale.y);
87
88 DlPaint paint;
89 canvas->DrawImage(images[0], DlPoint(10.135, 10.36334),
90 DlImageSampling::kLinear, &paint);
91
92 DlRect save_layer_bounds = DlRect::MakeLTRB(0, 0, 1024, 768);
93 auto blur = DlImageFilter::MakeBlur(sigma, sigma, DlTileMode::kDecal);
94 canvas->ClipRect(DlRect::MakeLTRB(11.125, 10.3737, 911.25, 755.3333));
95 canvas->SaveLayer(save_layer_bounds, /*paint=*/nullptr, blur.get());
96 canvas->Restore();
97 };
98
99 std::vector<sk_sp<DlImage>> images;
100 images.emplace_back(CreateDlImageForFixture("boston.jpg"));
101
102 auto make_screenshot = [&](float sigma) {
103 DisplayListBuilder builder;
104 draw(&builder, images, sigma);
105
106 std::unique_ptr<impeller::testing::Screenshot> screenshot =
107 MakeScreenshot(builder.Build());
108 return screenshot;
109 };
110
111 float start_sigma = 10.0f;
112 std::unique_ptr<impeller::testing::Screenshot> left =
113 make_screenshot(start_sigma);
114 if (!left) {
115 GTEST_SKIP() << "making screenshots not supported.";
116 }
117
118 double average_rmse = 0.0;
119 const int32_t sample_count = 200;
120 for (int i = 1; i <= sample_count; ++i) {
121 float sigma = start_sigma + (i / 2.f);
122 std::unique_ptr<impeller::testing::Screenshot> right =
123 make_screenshot(sigma);
124 double rmse = RMSE(left.get(), right.get());
125 average_rmse += rmse;
126
127 // To debug this output the frames can be written out to disk then
128 // transformed to a video with ffmpeg.
129 //
130 // ## save images command
131 // std::stringstream ss;
132 // ss << "_" << std::setw(3) << std::setfill('0') << (i - 1);
133 // SaveScreenshot(std::move(left), ss.str());
134 //
135 // ## ffmpeg command
136 // ```
137 // ffmpeg -framerate 30 -pattern_type glob -i '*.png' \
138 // -c:v libx264 -pix_fmt yuv420p out.mp4
139 // ```
140 left = std::move(right);
141 }
142
143 average_rmse = average_rmse / sample_count;
144
145 // This is a somewhat arbitrary threshold. It could be increased if we wanted.
146 // In the problematic cases previously we should values like 28. Before
147 // increasing this you should manually inspect the behavior in
148 // `AiksTest.GaussianBlurAnimatedBackdrop`. Average RMSE is a able to catch
149 // shimmer but it isn't perfect.
150 EXPECT_TRUE(average_rmse < 1.0) << "average_rmse: " << average_rmse;
151 // An average rmse of 0 would mean that the blur isn't blurring.
152 EXPECT_TRUE(average_rmse >= 0.0) << "average_rmse: " << average_rmse;
153 }

References impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

## ◆ TEST_P() [14/19]

flutter::testing::TEST_P | ( | DlGoldenTest | ,
|  | StrokedRRectFastBlur |
| ) |  |

Definition at line 155 of file dl_golden_blur_unittests.cc.

155 {
156 impeller::Point content_scale = GetContentScale();
157 DlRect rect = DlRect::MakeXYWH(50, 50, 100, 100);
158 DlRoundRect rrect = DlRoundRect::MakeRectRadius(rect, 10.0f);
159 DlPaint fill = DlPaint().setColor(DlColor::kBlue());
160 DlPaint stroke =
161 DlPaint(fill).setDrawStyle(DlDrawStyle::kStroke).setStrokeWidth(10.0f);
162 DlPaint blur = DlPaint(fill).setMaskFilter(
163 DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 5.0, true));
164 DlPaint blur_stroke =
165 DlPaint(blur).setDrawStyle(DlDrawStyle::kStroke).setStrokeWidth(10.0f);
166
167 DisplayListBuilder builder;
168 builder.DrawColor(DlColor(0xff111111), DlBlendMode::kSrc);
169 builder.Scale(content_scale.x, content_scale.y);
170 builder.DrawRoundRect(rrect, fill);
171 builder.DrawRoundRect(rrect.Shift(150, 0), stroke);
172 builder.DrawRoundRect(rrect.Shift(0, 150), blur);
173 builder.DrawRoundRect(rrect.Shift(150, 150), blur_stroke);
174
175 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
176 }
impeller::DlRoundRect
flutter::DlRoundRect DlRoundRect
Definition: dl_dispatcher.h:27

References impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

## ◆ TEST_P() [15/19]

flutter::testing::TEST_P | ( | DlGoldenTest | ,
|  | Subpixel |
| ) |  |

Definition at line 489 of file dl_golden_unittests.cc.

489 {
490 SetWindowSize(impeller::ISize(1024, 200));
491 impeller::Scalar font_size = 200;
492 auto callback = [&](Scalar offset_x) -> sk_sp<DisplayList> {
493 DisplayListBuilder builder;
494 DlPaint paint;
495 paint.setColor(DlColor::ARGB(1, 0, 0, 0));
496 builder.DrawPaint(paint);
497 RenderTextInCanvasSkia(&builder, "ui", "Roboto-Regular.ttf",
498 DlPoint::MakeXY(offset_x, 180),
499 TextRenderOptions{
500 .font_size = font_size,
501 .is_subpixel = true,
502 });
503 return builder.Build();
504 };
505
506 LeftmostIntensity intensity[5];
507 for (int i = 0; i <= 4; ++i) {
508 Scalar offset = 10 + (i / 4.0);
509 std::unique_ptr<impeller::testing::Screenshot> right =
510 MakeScreenshot(callback(offset));
511 if (!right) {
512 GTEST_SKIP() << "making screenshots not supported.";
513 }
514 intensity[i] = CalculateLeftmostIntensity(right.get());
515 ASSERT_NE(intensity[i].value, 0);
516 }
517 for (int i = 1; i < 5; ++i) {
518 EXPECT_TRUE(intensity[i].x - intensity[i - 1].x == 1 ||
519 intensity[i].value < intensity[i - 1].value)
520 << i;
521 }
522 EXPECT_EQ(intensity[4].x - intensity[0].x, 1);
523 }
value
int32_t value
Definition: dl_golden_unittests.cc:459

References font_size, impeller::testing::RenderTextInCanvasSkia(), value, and x.

## ◆ TEST_P() [16/19]

flutter::testing::TEST_P | ( | DlGoldenTest | ,
|  | SubpixelScaled |
| ) |  |

Definition at line 527 of file dl_golden_unittests.cc.

527 {
528 SetWindowSize(impeller::ISize(1024, 200));
529 impeller::Scalar font_size = 200;
530 Scalar scalar = 0.75;
531 auto callback = [&](Scalar offset_x) -> sk_sp<DisplayList> {
532 DisplayListBuilder builder;
533 builder.Scale(scalar, scalar);
534 DlPaint paint;
535 paint.setColor(DlColor::ARGB(1, 0, 0, 0));
536 builder.DrawPaint(paint);
537 RenderTextInCanvasSkia(&builder, "ui", "Roboto-Regular.ttf",
538 DlPoint::MakeXY(offset_x, 180),
539 TextRenderOptions{
540 .font_size = font_size,
541 .is_subpixel = true,
542 });
543 return builder.Build();
544 };
545
546 LeftmostIntensity intensity[5];
547 Scalar offset_fraction = 0.25 / scalar;
548 for (int i = 0; i <= 4; ++i) {
549 Scalar offset = 10 + (offset_fraction * i);
550 std::unique_ptr<impeller::testing::Screenshot> right =
551 MakeScreenshot(callback(offset));
552 if (!right) {
553 GTEST_SKIP() << "making screenshots not supported.";
554 }
555 intensity[i] = CalculateLeftmostIntensity(right.get());
556 ASSERT_NE(intensity[i].value, 0);
557 }
558 for (int i = 1; i < 5; ++i) {
559 EXPECT_TRUE(intensity[i].x - intensity[i - 1].x == 1 ||
560 intensity[i].value < intensity[i - 1].value)
561 << i;
562 }
563 EXPECT_EQ(intensity[4].x - intensity[0].x, 1);
564 }

References font_size, impeller::testing::RenderTextInCanvasSkia(), value, and x.

## ◆ TEST_P() [17/19]

flutter::testing::TEST_P | ( | DlGoldenTest | ,
|  | SubpixelScaledTranslated |
| ) |  |

Definition at line 568 of file dl_golden_unittests.cc.

568 {
569 SetWindowSize(impeller::ISize(1024, 200));
570 impeller::Scalar font_size = 200;
571 Scalar scalar = 0.75;
572 auto callback = [&](Scalar offset_x) -> sk_sp<DisplayList> {
573 DisplayListBuilder builder;
574 builder.Scale(scalar, scalar);
575 DlPaint paint;
576 paint.setColor(DlColor::ARGB(1, 0, 0, 0));
577 builder.DrawPaint(paint);
578 builder.Translate(offset_x, 180);
579 RenderTextInCanvasSkia(&builder, "ui", "Roboto-Regular.ttf",
580 DlPoint::MakeXY(0, 0),
581 TextRenderOptions{
582 .font_size = font_size,
583 .is_subpixel = true,
584 });
585 return builder.Build();
586 };
587
588 LeftmostIntensity intensity[5];
589 Scalar offset_fraction = 0.25 / scalar;
590 for (int i = 0; i <= 4; ++i) {
591 Scalar offset = 10 + (offset_fraction * i);
592 std::unique_ptr<impeller::testing::Screenshot> right =
593 MakeScreenshot(callback(offset));
594 if (!right) {
595 GTEST_SKIP() << "making screenshots not supported.";
596 }
597 intensity[i] = CalculateLeftmostIntensity(right.get());
598 ASSERT_NE(intensity[i].value, 0);
599 }
600 for (int i = 1; i < 5; ++i) {
601 EXPECT_TRUE(intensity[i].x - intensity[i - 1].x == 1 ||
602 intensity[i].value < intensity[i - 1].value)
603 << i;
604 }
605 EXPECT_EQ(intensity[4].x - intensity[0].x, 1);
606 }

References font_size, impeller::testing::RenderTextInCanvasSkia(), value, and x.

## ◆ TEST_P() [18/19]

flutter::testing::TEST_P | ( | DlGoldenTest | ,
|  | TextBlurMaskFilterDisrespectCTM |
| ) |  |

Definition at line 48 of file dl_golden_blur_unittests.cc.

48 {
49 impeller::Point content_scale = GetContentScale();
50 auto draw = [&](DlCanvas* canvas,
51 const std::vector<std::unique_ptr<DlImage>>& images) {
52 canvas->DrawColor(DlColor(0xff111111));
53 canvas->Scale(content_scale.x, content_scale.y);
54 canvas->Scale(2, 2);
55 TextRenderOptions options;
56 options.mask_filter =
57 DlBlurMaskFilter::Make(DlBlurStyle::kNormal, /*sigma=*/10,
58 /*respect_ctm=*/false);
59 ASSERT_TRUE(RenderTextInCanvasSkia(canvas, "hello world",
60 "Roboto-Regular.ttf", //
61 DlPoint(101, 101), options));
62 options.mask_filter = nullptr;
63 options.color = DlColor::kRed();
64 ASSERT_TRUE(RenderTextInCanvasSkia(canvas, "hello world",
65 "Roboto-Regular.ttf", //
66 DlPoint(100, 100), options));
67 };
68
69 DisplayListBuilder builder;
70 draw(&builder, /*images=*/{});
71
72 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
73 }

References impeller::testing::RenderTextInCanvasSkia(), impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

## ◆ TEST_P() [19/19]

flutter::testing::TEST_P | ( | DlGoldenTest | ,
|  | TextBlurMaskFilterRespectCTM |
| ) |  |

Definition at line 21 of file dl_golden_blur_unittests.cc.

21 {
22 impeller::Point content_scale = GetContentScale();
23 auto draw = [&](DlCanvas* canvas,
24 const std::vector<std::unique_ptr<DlImage>>& images) {
25 canvas->DrawColor(DlColor(0xff111111));
26 canvas->Scale(content_scale.x, content_scale.y);
27 canvas->Scale(2, 2);
28 TextRenderOptions options;
29 options.mask_filter =
30 DlBlurMaskFilter::Make(DlBlurStyle::kNormal, /*sigma=*/10,
31 /*respect_ctm=*/true);
32 ASSERT_TRUE(RenderTextInCanvasSkia(canvas, "hello world",
33 "Roboto-Regular.ttf", //
34 DlPoint(101, 101), options));
35 options.mask_filter = nullptr;
36 options.color = DlColor::kRed();
37 ASSERT_TRUE(RenderTextInCanvasSkia(canvas, "hello world",
38 "Roboto-Regular.ttf", //
39 DlPoint(100, 100), options));
40 };
41
42 DisplayListBuilder builder;
43 draw(&builder, /*images=*/{});
44
45 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
46 }

References impeller::testing::RenderTextInCanvasSkia(), impeller::TPoint< T >::x, and impeller::TPoint< T >::y.