| Flutter Impeller |

Typedefs | Functions
flutter::testing Namespace Reference

## Typedefs
using | DlGoldenTest = impeller::DlPlayground

## Functions
| TEST_P (DlGoldenTest, TextBlurMaskFilterRespectCTM)
| TEST_P (DlGoldenTest, TextBlurMaskFilterDisrespectCTM)
| 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, 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/9]

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

Definition at line 57 of file dl_golden_unittests.cc.

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

References paint.

## ◆ TEST_P() [2/9]

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

Definition at line 23 of file dl_golden_unittests.cc.

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

References paint.

## ◆ TEST_P() [3/9]

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

Definition at line 38 of file dl_golden_unittests.cc.

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

References paint.

## ◆ TEST_P() [4/9]

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

Definition at line 185 of file dl_golden_unittests.cc.

185 {
186 Point content_scale = GetContentScale();
187 auto draw = [content_scale](DlCanvas* canvas,
188 const std::vector<sk_sp<DlImage>>& images) {
189 canvas->Scale(content_scale.x, content_scale.y);
190 canvas->DrawPaint(DlPaint().setColor(DlColor::kWhite()));
191
192 auto draw_one = [canvas](DlStrokeCap cap, Scalar x, Scalar y,
193 Scalar dash_on, Scalar dash_off) {
194 Point center = Point(x, y);
195 Scalar inner = 20.0f;
196 Scalar outer = 100.0f;
197 DlPaint thick_paint = DlPaint()
198 .setColor(DlColor::kBlue())
199 .setStrokeCap(cap)
200 .setStrokeWidth(8.0f);
201 DlPaint middle_paint = DlPaint()
202 .setColor(DlColor::kGreen())
203 .setStrokeCap(cap)
204 .setStrokeWidth(5.0f);
205 DlPaint thin_paint = DlPaint()
206 .setColor(DlColor::kMagenta())
207 .setStrokeCap(cap)
208 .setStrokeWidth(2.0f);
209 for (int degrees = 0; degrees < 360; degrees += 30) {
210 Point delta = Point(1.0f, 0.0f).Rotate(Degrees(degrees));
211 canvas->DrawDashedLine(center + inner * delta, center + outer * delta,
212 dash_on, dash_off, thick_paint);
213 canvas->DrawDashedLine(center + inner * delta, center + outer * delta,
214 dash_on, dash_off, middle_paint);
215 canvas->DrawDashedLine(center + inner * delta, center + outer * delta,
216 dash_on, dash_off, thin_paint);
217 }
218 };
219
220 draw_one(DlStrokeCap::kButt, 150.0f, 150.0f, 15.0f, 10.0f);
221 draw_one(DlStrokeCap::kSquare, 400.0f, 150.0f, 15.0f, 10.0f);
222 draw_one(DlStrokeCap::kRound, 150.0f, 400.0f, 15.0f, 10.0f);
223 draw_one(DlStrokeCap::kRound, 400.0f, 400.0f, 0.0f, 11.0f);
224
225 // Make sure the rendering op responds appropriately to clipping
226 canvas->Save();
227 SkPath clip_path = SkPath();
228 clip_path.moveTo(275.0f, 225.0f);
229 clip_path.lineTo(325.0f, 275.0f);
230 clip_path.lineTo(275.0f, 325.0f);
231 clip_path.lineTo(225.0f, 275.0f);
232 canvas->ClipPath(clip_path);
233 canvas->DrawColor(DlColor::kYellow());
234 draw_one(DlStrokeCap::kRound, 275.0f, 275.0f, 15.0f, 10.0f);
235 canvas->Restore();
236 };
237
238 DisplayListBuilder builder;
239 std::vector<sk_sp<DlImage>> images;
240 draw(&builder, images);
241
242 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
243 }

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

## ◆ TEST_P() [5/9]

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

Definition at line 131 of file dl_golden_unittests.cc.

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

## ◆ TEST_P() [6/9]

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

Definition at line 147 of file dl_golden_unittests.cc.

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

## ◆ TEST_P() [7/9]

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

Definition at line 164 of file dl_golden_unittests.cc.

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

## ◆ TEST_P() [8/9]

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

Definition at line 86 of file dl_golden_blur_unittests.cc.

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

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

## ◆ TEST_P() [9/9]

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

Definition at line 59 of file dl_golden_blur_unittests.cc.

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

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

impeller::TPoint::y
Type y
Definition: point.h:31
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::Point
TPoint< Scalar > Point
Definition: point.h:322
impeller::TPoint::x
Type x
Definition: point.h:30
impeller::testing::RenderTextInCanvasSkia
bool RenderTextInCanvasSkia(const std::shared_ptr< Context > &context, Canvas &canvas, const std::string &text, const std::string_view &font_fixture, TextRenderOptions options={})
Definition: aiks_unittests.cc:550
impeller::TPoint< Scalar >
paint
const Paint & paint
Definition: color_source.cc:38
impeller::TPoint::Rotate
constexpr TPoint Rotate(const Radians &angle) const
Definition: point.h:226