| 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)
| 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/18]

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

Definition at line 372 of file dl_golden_unittests.cc.

372 {
373 SetWindowSize(impeller::ISize(1024, 200));
374 impeller::Scalar font_size = 300;
375 auto callback = [&](const char* text,
376 impeller::Scalar scale) -> sk_sp<DisplayList> {
377 DisplayListBuilder builder;
378 DlPaint paint;
379 paint.setColor(DlColor::ARGB(1, 0, 0, 0));
380 builder.DrawPaint(paint);
381 builder.Scale(scale, scale);
382 RenderTextInCanvasSkia(&builder, text, "Roboto-Regular.ttf",
383 DlPoint::MakeXY(10, 300),
384 TextRenderOptions{
385 .font_size = font_size,
386 });
387 return builder.Build();
388 };
389
390 std::unique_ptr<impeller::testing::Screenshot> right =
391 MakeScreenshot(callback("h", 0.444));
392 if (!right) {
393 GTEST_SKIP() << "making screenshots not supported.";
394 }
395 std::unique_ptr<impeller::testing::Screenshot> left =
396 MakeScreenshot(callback("e", 0.444));
397
398 int32_t left_max_y = CalculateMaxY(left.get());
399 int32_t right_max_y = CalculateMaxY(right.get());
400 int32_t y_diff = std::abs(left_max_y - right_max_y);
401 EXPECT_TRUE(y_diff <= 2) << "y diff: " << y_diff;
402 }

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

## ◆ TEST_P() [2/18]

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(SkRect::MakeLTRB(0, 0, 375, 667), paint);
71 paint.setColor(DlColor(0xffff9800));
72 canvas->DrawRect(SkRect::MakeLTRB(0, 0, 187.5, 333.5), paint);
73 paint.setColor(DlColor(0xff9c27b0));
74 canvas->DrawRect(SkRect::MakeLTRB(187.5, 0, 375, 333.5), paint);
75 paint.setColor(DlColor(0xff4caf50));
76 canvas->DrawRect(SkRect::MakeLTRB(0, 333.5, 187.5, 667), paint);
77 paint.setColor(DlColor(0xfff44336));
78 canvas->DrawRect(SkRect::MakeLTRB(187.5, 333.5, 375, 667), paint);
79
80 canvas->Save();
81 {
82 canvas->ClipRRect(
83 SkRRect::MakeOval(SkRect::MakeLTRB(201.25, 10, 361.25, 170)),
84 DlCanvas::ClipOp::kIntersect, true);
85 SkRect save_layer_bounds = SkRect::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(SkPoint::Make(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 }

## ◆ TEST_P() [3/18]

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/18]

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], SkPoint::Make(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/18]

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

Definition at line 255 of file dl_golden_unittests.cc.

255 {
256 Point content_scale = GetContentScale();
257 auto draw = [content_scale](DlCanvas* canvas,
258 const std::vector<sk_sp<DlImage>>& images) {
259 canvas->Scale(content_scale.x, content_scale.y);
260 canvas->DrawPaint(DlPaint().setColor(DlColor::kWhite()));
261
262 auto draw_one = [canvas](DlStrokeCap cap, Scalar x, Scalar y,
263 Scalar dash_on, Scalar dash_off) {
264 Point center = Point(x, y);
265 Scalar inner = 20.0f;
266 Scalar outer = 100.0f;
267 DlPaint thick_paint = DlPaint()
268 .setColor(DlColor::kBlue())
269 .setStrokeCap(cap)
270 .setStrokeWidth(8.0f);
271 DlPaint middle_paint = DlPaint()
272 .setColor(DlColor::kGreen())
273 .setStrokeCap(cap)
274 .setStrokeWidth(5.0f);
275 DlPaint thin_paint = DlPaint()
276 .setColor(DlColor::kMagenta())
277 .setStrokeCap(cap)
278 .setStrokeWidth(2.0f);
279 for (int degrees = 0; degrees < 360; degrees += 30) {
280 Point delta = Point(1.0f, 0.0f).Rotate(Degrees(degrees));
281 canvas->DrawDashedLine(center + inner * delta, center + outer * delta,
282 dash_on, dash_off, thick_paint);
283 canvas->DrawDashedLine(center + inner * delta, center + outer * delta,
284 dash_on, dash_off, middle_paint);
285 canvas->DrawDashedLine(center + inner * delta, center + outer * delta,
286 dash_on, dash_off, thin_paint);
287 }
288 };
289
290 draw_one(DlStrokeCap::kButt, 150.0f, 150.0f, 15.0f, 10.0f);
291 draw_one(DlStrokeCap::kSquare, 400.0f, 150.0f, 15.0f, 10.0f);
292 draw_one(DlStrokeCap::kRound, 150.0f, 400.0f, 15.0f, 10.0f);
293 draw_one(DlStrokeCap::kRound, 400.0f, 400.0f, 0.0f, 11.0f);
294
295 // Make sure the rendering op responds appropriately to clipping
296 canvas->Save();
297 SkPath clip_path = SkPath();
298 clip_path.moveTo(275.0f, 225.0f);
299 clip_path.lineTo(325.0f, 275.0f);
300 clip_path.lineTo(275.0f, 325.0f);
301 clip_path.lineTo(225.0f, 275.0f);
302 canvas->ClipPath(clip_path);
303 canvas->DrawColor(DlColor::kYellow());
304 draw_one(DlStrokeCap::kRound, 275.0f, 275.0f, 15.0f, 10.0f);
305 canvas->Restore();
306 };
307
308 DisplayListBuilder builder;
309 std::vector<sk_sp<DlImage>> images;
310 draw(&builder, images);
311
312 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
313 }

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

## ◆ TEST_P() [6/18]

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

Definition at line 193 of file dl_golden_unittests.cc.

193 {
194 DisplayListBuilder builder;
195 builder.Scale(GetContentScale().x, GetContentScale().y);
196 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
197
198 auto blur_sigmas = std::array{5.0f, 10.0f, 20.0f};
199 auto blur_colors = std::array{
200 DlColor::kBlue(),
201 DlColor::kGreen(),
202 DlColor::kMaroon(),
203 };
204
205 auto make_rrect_path = [](const SkRect& rect, DlScalar rx,
206 DlScalar ry) -> SkPath {
207 auto add_corner = [](SkPath& path, SkPoint rCorner, SkPoint rEnd) {
208 static const auto magic = impeller::PathBuilder::kArcApproximationMagic;
209 path.rCubicTo(rCorner.fX * (1.0f - magic), rCorner.fY * (1.0f - magic),
210 rCorner.fX + rEnd.fX * magic, rCorner.fY + rEnd.fY * magic,
211 rCorner.fX + rEnd.fX, rCorner.fY + rEnd.fY);
212 };
213
214 SkPath path;
215 path.moveTo(rect.fRight - rx, rect.fTop);
216 add_corner(path, {rx, 0.0f}, {0.0f, ry});
217 path.lineTo(rect.fRight, rect.fBottom - ry);
218 add_corner(path, {0.0f, ry}, {-rx, 0.0f});
219 path.lineTo(rect.fLeft + rx, rect.fBottom);
220 add_corner(path, {-rx, 0.0f}, {0.0f, -ry});
221 path.lineTo(rect.fLeft, rect.fTop + ry);
222 add_corner(path, {0.0f, -ry}, {rx, 0.0f});
223 path.close();
224 return path;
225 };
226
227 for (size_t i = 0; i < blur_sigmas.size(); i++) {
228 auto rect = SkRect::MakeXYWH(i * 320.0f + 50.0f, 50.0f, 100.0f, 100.0f);
229 DlPaint paint = DlPaint() //
230 .setColor(blur_colors[i])
231 .setMaskFilter(DlBlurMaskFilter::Make(
232 DlBlurStyle::kNormal, blur_sigmas[i]));
233
234 builder.DrawRRect(SkRRect::MakeRectXY(rect, 10.0f, 10.0f), paint);
235 rect = rect.makeOffset(150.0f, 0.0f);
236 builder.DrawPath(make_rrect_path(rect, 10.0f, 10.0f), paint);
237 rect = rect.makeOffset(-150.0f, 0.0f);
238
239 rect = rect.makeOffset(0.0f, 200.0f);
240 builder.DrawRRect(SkRRect::MakeRectXY(rect, 10.0f, 30.0f), paint);
241 rect = rect.makeOffset(150.0f, 0.0f);
242 builder.DrawPath(make_rrect_path(rect, 10.0f, 20.0f), paint);
243 rect = rect.makeOffset(-150.0f, 0.0f);
244
245 rect = rect.makeOffset(0.0f, 200.0f);
246 builder.DrawRRect(SkRRect::MakeRectXY(rect, 30.0f, 10.0f), paint);
247 rect = rect.makeOffset(150.0f, 0.0f);
248 builder.DrawPath(make_rrect_path(rect, 20.0f, 10.0f), paint);
249 rect = rect.makeOffset(-150.0f, 0.0f);
250 }
251
252 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
253 }

References impeller::PathBuilder::kArcApproximationMagic, and x.

## ◆ TEST_P() [7/18]

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

Definition at line 139 of file dl_golden_unittests.cc.

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

## ◆ TEST_P() [8/18]

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

Definition at line 155 of file dl_golden_unittests.cc.

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

## ◆ TEST_P() [9/18]

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

Definition at line 172 of file dl_golden_unittests.cc.

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

## ◆ TEST_P() [10/18]

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

Definition at line 404 of file dl_golden_unittests.cc.

404 {
405 SetWindowSize(impeller::ISize(1024, 200));
406 impeller::Scalar font_size = 300;
407 auto callback = [&](const char* text,
408 impeller::Scalar scale) -> sk_sp<DisplayList> {
409 DisplayListBuilder builder;
410 DlPaint paint;
411 paint.setColor(DlColor::ARGB(1, 0, 0, 0));
412 builder.DrawPaint(paint);
413 builder.Scale(scale, scale);
414 RenderTextInCanvasSkia(&builder, text, "Roboto-Regular.ttf",
415 DlPoint::MakeXY(10, 300),
416 TextRenderOptions{
417 .font_size = font_size,
418 });
419 return builder.Build();
420 };
421
422 std::optional<int32_t> last_space;
423 for (int i = 0; i <= 100; ++i) {
424 Scalar scale = 0.440 + i / 1000.0;
425 std::unique_ptr<impeller::testing::Screenshot> right =
426 MakeScreenshot(callback("ui", scale));
427 if (!right) {
428 GTEST_SKIP() << "making screenshots not supported.";
429 }
430
431 int32_t space = CalculateSpaceBetweenUI(right.get());
432 if (last_space.has_value()) {
433 int32_t diff = abs(space - *last_space);
434 EXPECT_TRUE(diff <= 1)
435 << "i:" << i << " space:" << space << " last_space:" << *last_space;
436 }
437 last_space = space;
438 }
439 }

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

## ◆ TEST_P() [11/18]

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

Definition at line 315 of file dl_golden_unittests.cc.

315 {
316 // Draws a stroked rounded rect at a fractional pixel value. The coverage must
317 // be adjusted so that we still have room to draw it, even though it lies on
318 // the fractional bounds of the saveLayer.
319 DisplayListBuilder builder;
320 builder.DrawPaint(DlPaint().setColor(DlColor::kWhite()));
321 auto save_paint = DlPaint().setAlpha(100);
322 builder.SaveLayer(nullptr, &save_paint);
323
324 builder.DrawRoundRect(DlRoundRect::MakeRectRadius(
325 DlRect::MakeLTRB(10.5, 10.5, 200.5, 200.5), 10),
326 DlPaint()
327 .setDrawStyle(DlDrawStyle::kStroke)
328 .setStrokeWidth(1.5)
329 .setColor(DlColor::kBlack()));
330 builder.DrawCircle(DlPoint::MakeXY(100, 100), 50.5,
331 DlPaint().setColor(DlColor::kAqua()));
332 builder.DrawCircle(DlPoint::MakeXY(110, 110), 50.5,
333 DlPaint().setColor(DlColor::kCyan()));
334
335 builder.Restore();
336
337 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
338 }

## ◆ TEST_P() [12/18]

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], SkPoint::Make(10.135, 10.36334),
90 DlImageSampling::kLinear, &paint);
91
92 SkRect save_layer_bounds = SkRect::MakeLTRB(0, 0, 1024, 768);
93 auto blur = DlImageFilter::MakeBlur(sigma, sigma, DlTileMode::kDecal);
94 canvas->ClipRect(SkRect::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() [13/18]

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
158 DlRect rect = DlRect::MakeXYWH(50, 50, 100, 100);
159 DlRoundRect rrect = DlRoundRect::MakeRectRadius(rect, 10.0f);
160 DlPaint fill = DlPaint().setColor(DlColor::kBlue());
161 DlPaint stroke =
162 DlPaint(fill).setDrawStyle(DlDrawStyle::kStroke).setStrokeWidth(10.0f);
163 DlPaint blur = DlPaint(fill).setMaskFilter(
164 DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 5.0, true));
165 DlPaint blur_stroke =
166 DlPaint(blur).setDrawStyle(DlDrawStyle::kStroke).setStrokeWidth(10.0f);
167
168 DisplayListBuilder builder;
169 builder.DrawColor(DlColor(0xff111111), DlBlendMode::kSrc);
170 builder.Scale(content_scale.x, content_scale.y);
171 builder.DrawRoundRect(rrect, fill);
172 builder.DrawRoundRect(rrect.Shift(150, 0), stroke);
173 builder.DrawRoundRect(rrect.Shift(0, 150), blur);
174 builder.DrawRoundRect(rrect.Shift(150, 150), blur_stroke);
175
176 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
177 }

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

## ◆ TEST_P() [14/18]

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

Definition at line 474 of file dl_golden_unittests.cc.

474 {
475 SetWindowSize(impeller::ISize(1024, 200));
476 impeller::Scalar font_size = 200;
477 auto callback = [&](Scalar offset_x) -> sk_sp<DisplayList> {
478 DisplayListBuilder builder;
479 DlPaint paint;
480 paint.setColor(DlColor::ARGB(1, 0, 0, 0));
481 builder.DrawPaint(paint);
482 RenderTextInCanvasSkia(&builder, "ui", "Roboto-Regular.ttf",
483 DlPoint::MakeXY(offset_x, 180),
484 TextRenderOptions{
485 .font_size = font_size,
486 .is_subpixel = true,
487 });
488 return builder.Build();
489 };
490
491 LeftmostIntensity intensity[5];
492 for (int i = 0; i <= 4; ++i) {
493 Scalar offset = 10 + (i / 4.0);
494 std::unique_ptr<impeller::testing::Screenshot> right =
495 MakeScreenshot(callback(offset));
496 if (!right) {
497 GTEST_SKIP() << "making screenshots not supported.";
498 }
499 intensity[i] = CalculateLeftmostIntensity(right.get());
500 ASSERT_NE(intensity[i].value, 0);
501 }
502 for (int i = 1; i < 5; ++i) {
503 EXPECT_TRUE(intensity[i].x - intensity[i - 1].x == 1 ||
504 intensity[i].value < intensity[i - 1].value)
505 << i;
506 }
507 EXPECT_EQ(intensity[4].x - intensity[0].x, 1);
508 }

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

## ◆ TEST_P() [15/18]

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

Definition at line 512 of file dl_golden_unittests.cc.

512 {
513 SetWindowSize(impeller::ISize(1024, 200));
514 impeller::Scalar font_size = 200;
515 Scalar scalar = 0.75;
516 auto callback = [&](Scalar offset_x) -> sk_sp<DisplayList> {
517 DisplayListBuilder builder;
518 builder.Scale(scalar, scalar);
519 DlPaint paint;
520 paint.setColor(DlColor::ARGB(1, 0, 0, 0));
521 builder.DrawPaint(paint);
522 RenderTextInCanvasSkia(&builder, "ui", "Roboto-Regular.ttf",
523 DlPoint::MakeXY(offset_x, 180),
524 TextRenderOptions{
525 .font_size = font_size,
526 .is_subpixel = true,
527 });
528 return builder.Build();
529 };
530
531 LeftmostIntensity intensity[5];
532 Scalar offset_fraction = 0.25 / scalar;
533 for (int i = 0; i <= 4; ++i) {
534 Scalar offset = 10 + (offset_fraction * i);
535 std::unique_ptr<impeller::testing::Screenshot> right =
536 MakeScreenshot(callback(offset));
537 if (!right) {
538 GTEST_SKIP() << "making screenshots not supported.";
539 }
540 intensity[i] = CalculateLeftmostIntensity(right.get());
541 ASSERT_NE(intensity[i].value, 0);
542 }
543 for (int i = 1; i < 5; ++i) {
544 EXPECT_TRUE(intensity[i].x - intensity[i - 1].x == 1 ||
545 intensity[i].value < intensity[i - 1].value)
546 << i;
547 }
548 EXPECT_EQ(intensity[4].x - intensity[0].x, 1);
549 }

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

## ◆ TEST_P() [16/18]

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

Definition at line 553 of file dl_golden_unittests.cc.

553 {
554 SetWindowSize(impeller::ISize(1024, 200));
555 impeller::Scalar font_size = 200;
556 Scalar scalar = 0.75;
557 auto callback = [&](Scalar offset_x) -> sk_sp<DisplayList> {
558 DisplayListBuilder builder;
559 builder.Scale(scalar, scalar);
560 DlPaint paint;
561 paint.setColor(DlColor::ARGB(1, 0, 0, 0));
562 builder.DrawPaint(paint);
563 builder.Translate(offset_x, 180);
564 RenderTextInCanvasSkia(&builder, "ui", "Roboto-Regular.ttf",
565 DlPoint::MakeXY(0, 0),
566 TextRenderOptions{
567 .font_size = font_size,
568 .is_subpixel = true,
569 });
570 return builder.Build();
571 };
572
573 LeftmostIntensity intensity[5];
574 Scalar offset_fraction = 0.25 / scalar;
575 for (int i = 0; i <= 4; ++i) {
576 Scalar offset = 10 + (offset_fraction * i);
577 std::unique_ptr<impeller::testing::Screenshot> right =
578 MakeScreenshot(callback(offset));
579 if (!right) {
580 GTEST_SKIP() << "making screenshots not supported.";
581 }
582 intensity[i] = CalculateLeftmostIntensity(right.get());
583 ASSERT_NE(intensity[i].value, 0);
584 }
585 for (int i = 1; i < 5; ++i) {
586 EXPECT_TRUE(intensity[i].x - intensity[i - 1].x == 1 ||
587 intensity[i].value < intensity[i - 1].value)
588 << i;
589 }
590 EXPECT_EQ(intensity[4].x - intensity[0].x, 1);
591 }

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

## ◆ TEST_P() [17/18]

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", DlPoint(101, 101),
61 options));
62 options.mask_filter = nullptr;
63 options.color = DlColor::kRed();
64 ASSERT_TRUE(RenderTextInCanvasSkia(canvas, "hello world",
65 "Roboto-Regular.ttf", DlPoint(100, 100),
66 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() [18/18]

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", DlPoint(101, 101),
34 options));
35 options.mask_filter = nullptr;
36 options.color = DlColor::kRed();
37 ASSERT_TRUE(RenderTextInCanvasSkia(canvas, "hello world",
38 "Roboto-Regular.ttf", DlPoint(100, 100),
39 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.

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={})
Definition: aiks_dl_text_unittests.cc:39
impeller::TPoint::y
Type y
Definition: point.h:31
impeller::Scalar
float Scalar
Definition: scalar.h:18
value
int32_t value
Definition: dl_golden_unittests.cc:444
impeller::PathBuilder::kArcApproximationMagic
constexpr static const Scalar kArcApproximationMagic
Definition: path_builder.h:24
x
int32_t x
Definition: dl_golden_unittests.cc:443
offset
SeparatedVector2 offset
Definition: stroke_path_geometry.cc:319
impeller::TSize
Definition: size.h:25
impeller::Point
TPoint< Scalar > Point
Definition: point.h:327
impeller::DlRect
flutter::DlRect DlRect
Definition: dl_dispatcher.h:25
impeller::TPoint::x
Type x
Definition: point.h:30
impeller::DlPoint
flutter::DlPoint DlPoint
Definition: dl_dispatcher.h:24
impeller::TPoint< Scalar >
scale
const Scalar scale
Definition: stroke_path_geometry.cc:316
impeller::TPoint::Rotate
constexpr TPoint Rotate(const Radians &angle) const
Definition: point.h:226
impeller::DlRoundRect
flutter::DlRoundRect DlRoundRect
Definition: dl_dispatcher.h:27
impeller::DlScalar
flutter::DlScalar DlScalar
Definition: dl_dispatcher.h:23