| 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)
| 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)

## 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/11]

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

Definition at line 58 of file dl_golden_unittests.cc.

58 {
59 Point content_scale = GetContentScale();
60 auto draw = [content_scale](DlCanvas* canvas,
61 const std::vector<sk_sp<DlImage>>& images) {
62 canvas->Scale(content_scale.x, content_scale.y);
63 DlPaint paint;
64 paint.setColor(DlColor(0xfffef7ff));
65 canvas->DrawRect(SkRect::MakeLTRB(0, 0, 375, 667), paint);
66 paint.setColor(DlColor(0xffff9800));
67 canvas->DrawRect(SkRect::MakeLTRB(0, 0, 187.5, 333.5), paint);
68 paint.setColor(DlColor(0xff9c27b0));
69 canvas->DrawRect(SkRect::MakeLTRB(187.5, 0, 375, 333.5), paint);
70 paint.setColor(DlColor(0xff4caf50));
71 canvas->DrawRect(SkRect::MakeLTRB(0, 333.5, 187.5, 667), paint);
72 paint.setColor(DlColor(0xfff44336));
73 canvas->DrawRect(SkRect::MakeLTRB(187.5, 333.5, 375, 667), paint);
74
75 canvas->Save();
76 {
77 canvas->ClipRRect(
78 SkRRect::MakeOval(SkRect::MakeLTRB(201.25, 10, 361.25, 170)),
79 DlCanvas::ClipOp::kIntersect, true);
80 SkRect save_layer_bounds = SkRect::MakeLTRB(201.25, 10, 361.25, 170);
81 DlMatrixImageFilter backdrop(SkMatrix::MakeAll(3, 0, -280, //
82 0, 3, -920, //
83 0, 0, 1),
84 DlImageSampling::kLinear);
85 canvas->SaveLayer(&save_layer_bounds, /*paint=*/nullptr, &backdrop);
86 {
87 canvas->Translate(201.25, 10);
88 auto paint = DlPaint()
89 .setAntiAlias(true)
90 .setColor(DlColor(0xff2196f3))
91 .setStrokeWidth(5)
92 .setDrawStyle(DlDrawStyle::kStroke);
93 canvas->DrawCircle(SkPoint::Make(80, 80), 80, paint);
94 }
95 canvas->Restore();
96 }
97 canvas->Restore();
98 };
99
100 DisplayListBuilder builder;
101 std::vector<sk_sp<DlImage>> images;
102 draw(&builder, images);
103
104 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
105 }

## ◆ TEST_P() [2/11]

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

Definition at line 24 of file dl_golden_unittests.cc.

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

## ◆ TEST_P() [3/11]

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

Definition at line 39 of file dl_golden_unittests.cc.

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

## ◆ TEST_P() [4/11]

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

Definition at line 248 of file dl_golden_unittests.cc.

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

References impeller::TPoint< T >::Rotate().

## ◆ TEST_P() [5/11]

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

Definition at line 186 of file dl_golden_unittests.cc.

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

References impeller::PathBuilder::kArcApproximationMagic.

## ◆ TEST_P() [6/11]

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

Definition at line 132 of file dl_golden_unittests.cc.

132 {
133 Point content_scale = GetContentScale();
134 auto draw = [content_scale](DlCanvas* canvas,
135 const std::vector<sk_sp<DlImage>>& images) {
136 canvas->Scale(content_scale.x, content_scale.y);
137 canvas->DrawPaint(DlPaint().setColor(DlColor(0xff112233)));
138 DrawBlurGrid(canvas);
139 };
140
141 DisplayListBuilder builder;
142 std::vector<sk_sp<DlImage>> images;
143 draw(&builder, images);
144
145 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
146 }

## ◆ TEST_P() [7/11]

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

Definition at line 148 of file dl_golden_unittests.cc.

148 {
149 Point content_scale = GetContentScale();
150 auto draw = [content_scale](DlCanvas* canvas,
151 const std::vector<sk_sp<DlImage>>& images) {
152 canvas->Scale(content_scale.x, content_scale.y);
153 canvas->DrawPaint(DlPaint().setColor(DlColor(0xff112233)));
154 canvas->Scale(0.33, 0.33);
155 DrawBlurGrid(canvas);
156 };
157
158 DisplayListBuilder builder;
159 std::vector<sk_sp<DlImage>> images;
160 draw(&builder, images);
161
162 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
163 }

## ◆ TEST_P() [8/11]

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

Definition at line 165 of file dl_golden_unittests.cc.

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

## ◆ TEST_P() [9/11]

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

Definition at line 155 of file dl_golden_blur_unittests.cc.

155 {
156 impeller::Point content_scale = GetContentScale();
157 auto draw = [&](DlCanvas* canvas, const std::vector<sk_sp<DlImage>>& images,
158 float sigma) {
159 canvas->DrawColor(DlColor(0xff111111));
160 canvas->Scale(content_scale.x, content_scale.y);
161
162 DlPaint paint;
163 canvas->DrawImage(images[0], SkPoint::Make(10.135, 10.36334),
164 DlImageSampling::kLinear, &paint);
165
166 SkRect save_layer_bounds = SkRect::MakeLTRB(0, 0, 1024, 768);
167 DlBlurImageFilter blur(sigma, sigma, DlTileMode::kDecal);
168 canvas->ClipRect(SkRect::MakeLTRB(11.125, 10.3737, 911.25, 755.3333));
169 canvas->SaveLayer(&save_layer_bounds, /*paint=*/nullptr, &blur);
170 canvas->Restore();
171 };
172
173 std::vector<sk_sp<DlImage>> images;
174 images.emplace_back(CreateDlImageForFixture("boston.jpg"));
175
176 auto make_screenshot = [&](float sigma) {
177 DisplayListBuilder builder;
178 draw(&builder, images, sigma);
179
180 std::unique_ptr<impeller::testing::Screenshot> screenshot =
181 MakeScreenshot(builder.Build());
182 return screenshot;
183 };
184
185 float start_sigma = 10.0f;
186 std::unique_ptr<impeller::testing::Screenshot> left =
187 make_screenshot(start_sigma);
188 if (!left) {
189 GTEST_SKIP() << "making screenshots not supported.";
190 }
191
192 double average_rmse = 0.0;
193 const int32_t sample_count = 200;
194 for (int i = 1; i <= sample_count; ++i) {
195 float sigma = start_sigma + (i / 2.f);
196 std::unique_ptr<impeller::testing::Screenshot> right =
197 make_screenshot(sigma);
198 double rmse = RMSE(left.get(), right.get());
199 average_rmse += rmse;
200
201 // To debug this output the frames can be written out to disk then
202 // transformed to a video with ffmpeg.
203 //
204 // ## save images command
205 // std::stringstream ss;
206 // ss << "_" << std::setw(3) << std::setfill('0') << (i - 1);
207 // SaveScreenshot(std::move(left), ss.str());
208 //
209 // ## ffmpeg command
210 // ```
211 // ffmpeg -framerate 30 -pattern_type glob -i '*.png' \
212 // -c:v libx264 -pix_fmt yuv420p out.mp4
213 // ```
214 left = std::move(right);
215 }
216
217 average_rmse = average_rmse / sample_count;
218
219 // This is a somewhat arbitrary threshold. It could be increased if we wanted.
220 // In the problematic cases previously we should values like 28. Before
221 // increasing this you should manually inspect the behavior in
222 // `AiksTest.GaussianBlurAnimatedBackdrop`. Average RMSE is a able to catch
223 // shimmer but it isn't perfect.
224 EXPECT_TRUE(average_rmse < 1.0) << "average_rmse: " << average_rmse;
225 // An average rmse of 0 would mean that the blur isn't blurring.
226 EXPECT_TRUE(average_rmse >= 0.0) << "average_rmse: " << average_rmse;
227 }

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

## ◆ TEST_P() [10/11]

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

Definition at line 87 of file dl_golden_blur_unittests.cc.

87 {
88 impeller::Point content_scale = GetContentScale();
89 auto draw = [&](DlCanvas* canvas,
90 const std::vector<std::unique_ptr<DlImage>>& images) {
91 canvas->DrawColor(DlColor(0xff111111));
92 canvas->Scale(content_scale.x, content_scale.y);
93 canvas->Scale(2, 2);
94 TextRenderOptions options;
95 options.mask_filter =
96 DlBlurMaskFilter::Make(DlBlurStyle::kNormal, /*sigma=*/10,
97 /*respect_ctm=*/false);
98 ASSERT_TRUE(RenderTextInCanvasSkia(canvas, "hello world",
99 "Roboto-Regular.ttf",
100 SkPoint::Make(101, 101), options));
101 options.mask_filter = nullptr;
102 options.color = DlColor::kRed();
103 ASSERT_TRUE(RenderTextInCanvasSkia(canvas, "hello world",
104 "Roboto-Regular.ttf",
105 SkPoint::Make(100, 100), options));
106 };
107
108 DisplayListBuilder builder;
109 draw(&builder, /*images=*/{});
110
111 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
112 }

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

## ◆ TEST_P() [11/11]

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

Definition at line 60 of file dl_golden_blur_unittests.cc.

60 {
61 impeller::Point content_scale = GetContentScale();
62 auto draw = [&](DlCanvas* canvas,
63 const std::vector<std::unique_ptr<DlImage>>& images) {
64 canvas->DrawColor(DlColor(0xff111111));
65 canvas->Scale(content_scale.x, content_scale.y);
66 canvas->Scale(2, 2);
67 TextRenderOptions options;
68 options.mask_filter =
69 DlBlurMaskFilter::Make(DlBlurStyle::kNormal, /*sigma=*/10,
70 /*respect_ctm=*/true);
71 ASSERT_TRUE(RenderTextInCanvasSkia(canvas, "hello world",
72 "Roboto-Regular.ttf",
73 SkPoint::Make(101, 101), options));
74 options.mask_filter = nullptr;
75 options.color = DlColor::kRed();
76 ASSERT_TRUE(RenderTextInCanvasSkia(canvas, "hello world",
77 "Roboto-Regular.ttf",
78 SkPoint::Make(100, 100), options));
79 };
80
81 DisplayListBuilder builder;
82 draw(&builder, /*images=*/{});
83
84 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
85 }

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:41
impeller::TPoint::y
Type y
Definition: point.h:31
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::PathBuilder::kArcApproximationMagic
constexpr static const Scalar kArcApproximationMagic
Definition: path_builder.h:23
impeller::Point
TPoint< Scalar > Point
Definition: point.h:327
impeller::TPoint::x
Type x
Definition: point.h:30
impeller::TPoint< Scalar >
impeller::TPoint::Rotate
constexpr TPoint Rotate(const Radians &angle) const
Definition: point.h:226
impeller::DlScalar
flutter::DlScalar DlScalar
Definition: dl_dispatcher.h:21