Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 69c3255

Browse files
authored
Fix: Impeller playground's shapes should react to controllers (#56734)
Fixes flutter/flutter#159213 I've went through all `static` in the file and removed the ones that I think are incorrect. <img width="1136" alt="image" src="https://github.com/user-attachments/assets/29fe63ed-d077-4384-88ec-2f80dcc8c719"> I've experimented with all entity playgrounds to make sure their controllers work, except for `BlendingModeOptions`, which doesn't change whatsoever and I can't figure out. This PR should not need tests, as it fixes the tests. [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent 2d32cf3 commit 69c3255

File tree

1 file changed

+54
-58
lines changed

1 file changed

+54
-58
lines changed

impeller/entity/entity_unittests.cc

Lines changed: 54 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ TEST_P(EntityTest, ThreeStrokesInOnePath) {
119119
entity.SetTransform(Matrix::MakeScale(GetContentScale()));
120120
auto contents = std::make_unique<SolidColorContents>();
121121

122-
static std::unique_ptr<Geometry> geom = Geometry::MakeStrokePath(path, 5.0);
122+
std::unique_ptr<Geometry> geom = Geometry::MakeStrokePath(path, 5.0);
123123
contents->SetGeometry(geom.get());
124124
contents->SetColor(Color::Red());
125125
entity.SetContents(std::move(contents));
@@ -140,7 +140,7 @@ TEST_P(EntityTest, StrokeWithTextureContents) {
140140
Entity entity;
141141
entity.SetTransform(Matrix::MakeScale(GetContentScale()));
142142
auto contents = std::make_unique<TiledTextureContents>();
143-
static std::unique_ptr<Geometry> geom = Geometry::MakeStrokePath(path, 100.0);
143+
std::unique_ptr<Geometry> geom = Geometry::MakeStrokePath(path, 100.0);
144144
contents->SetGeometry(geom.get());
145145
contents->SetTexture(bridge);
146146
contents->SetTileModes(Entity::TileMode::kClamp, Entity::TileMode::kClamp);
@@ -152,20 +152,19 @@ TEST_P(EntityTest, TriangleInsideASquare) {
152152
auto callback = [&](ContentContext& context, RenderPass& pass) {
153153
Point offset(100, 100);
154154

155-
static PlaygroundPoint point_a(Point(10, 10) + offset, 20, Color::White());
155+
PlaygroundPoint point_a(Point(10, 10) + offset, 20, Color::White());
156156
Point a = DrawPlaygroundPoint(point_a);
157-
static PlaygroundPoint point_b(Point(210, 10) + offset, 20, Color::White());
157+
PlaygroundPoint point_b(Point(210, 10) + offset, 20, Color::White());
158158
Point b = DrawPlaygroundPoint(point_b);
159-
static PlaygroundPoint point_c(Point(210, 210) + offset, 20,
160-
Color::White());
159+
PlaygroundPoint point_c(Point(210, 210) + offset, 20, Color::White());
161160
Point c = DrawPlaygroundPoint(point_c);
162-
static PlaygroundPoint point_d(Point(10, 210) + offset, 20, Color::White());
161+
PlaygroundPoint point_d(Point(10, 210) + offset, 20, Color::White());
163162
Point d = DrawPlaygroundPoint(point_d);
164-
static PlaygroundPoint point_e(Point(50, 50) + offset, 20, Color::White());
163+
PlaygroundPoint point_e(Point(50, 50) + offset, 20, Color::White());
165164
Point e = DrawPlaygroundPoint(point_e);
166-
static PlaygroundPoint point_f(Point(100, 50) + offset, 20, Color::White());
165+
PlaygroundPoint point_f(Point(100, 50) + offset, 20, Color::White());
167166
Point f = DrawPlaygroundPoint(point_f);
168-
static PlaygroundPoint point_g(Point(50, 150) + offset, 20, Color::White());
167+
PlaygroundPoint point_g(Point(50, 150) + offset, 20, Color::White());
169168
Point g = DrawPlaygroundPoint(point_g);
170169
Path path = PathBuilder{}
171170
.MoveTo(a)
@@ -182,8 +181,7 @@ TEST_P(EntityTest, TriangleInsideASquare) {
182181
Entity entity;
183182
entity.SetTransform(Matrix::MakeScale(GetContentScale()));
184183
auto contents = std::make_unique<SolidColorContents>();
185-
static std::unique_ptr<Geometry> geom =
186-
Geometry::MakeStrokePath(path, 20.0);
184+
std::unique_ptr<Geometry> geom = Geometry::MakeStrokePath(path, 20.0);
187185
contents->SetGeometry(geom.get());
188186
contents->SetColor(Color::Red());
189187
entity.SetContents(std::move(contents));
@@ -219,7 +217,7 @@ TEST_P(EntityTest, StrokeCapAndJoinTest) {
219217
auto render_path = [width = width, &context, &pass, &world_matrix](
220218
const Path& path, Cap cap, Join join) {
221219
auto contents = std::make_unique<SolidColorContents>();
222-
static std::unique_ptr<Geometry> geom =
220+
std::unique_ptr<Geometry> geom =
223221
Geometry::MakeStrokePath(path, width, miter_limit, cap, join);
224222
contents->SetGeometry(geom.get());
225223
contents->SetColor(Color::Red());
@@ -232,7 +230,7 @@ TEST_P(EntityTest, StrokeCapAndJoinTest) {
232230
if (coverage.has_value()) {
233231
auto bounds_contents = std::make_unique<SolidColorContents>();
234232

235-
static std::unique_ptr<Geometry> geom = Geometry::MakeFillPath(
233+
std::unique_ptr<Geometry> geom = Geometry::MakeFillPath(
236234
PathBuilder{}.AddRect(entity.GetCoverage().value()).TakePath());
237235

238236
bounds_contents->SetGeometry(geom.get());
@@ -251,11 +249,11 @@ TEST_P(EntityTest, StrokeCapAndJoinTest) {
251249
// Cap::kButt demo.
252250
{
253251
Point off = Point(0, 0) * padding + margin;
254-
static PlaygroundPoint point_a(off + a_def, r, Color::Black());
255-
static PlaygroundPoint point_b(off + b_def, r, Color::White());
252+
PlaygroundPoint point_a(off + a_def, r, Color::Black());
253+
PlaygroundPoint point_b(off + b_def, r, Color::White());
256254
auto [a, b] = DrawPlaygroundLine(point_a, point_b);
257-
static PlaygroundPoint point_c(off + c_def, r, Color::Black());
258-
static PlaygroundPoint point_d(off + d_def, r, Color::White());
255+
PlaygroundPoint point_c(off + c_def, r, Color::Black());
256+
PlaygroundPoint point_d(off + d_def, r, Color::White());
259257
auto [c, d] = DrawPlaygroundLine(point_c, point_d);
260258
render_path(PathBuilder{}.AddCubicCurve(a, b, d, c).TakePath(),
261259
Cap::kButt, Join::kBevel);
@@ -264,11 +262,11 @@ TEST_P(EntityTest, StrokeCapAndJoinTest) {
264262
// Cap::kSquare demo.
265263
{
266264
Point off = Point(1, 0) * padding + margin;
267-
static PlaygroundPoint point_a(off + a_def, r, Color::Black());
268-
static PlaygroundPoint point_b(off + b_def, r, Color::White());
265+
PlaygroundPoint point_a(off + a_def, r, Color::Black());
266+
PlaygroundPoint point_b(off + b_def, r, Color::White());
269267
auto [a, b] = DrawPlaygroundLine(point_a, point_b);
270-
static PlaygroundPoint point_c(off + c_def, r, Color::Black());
271-
static PlaygroundPoint point_d(off + d_def, r, Color::White());
268+
PlaygroundPoint point_c(off + c_def, r, Color::Black());
269+
PlaygroundPoint point_d(off + d_def, r, Color::White());
272270
auto [c, d] = DrawPlaygroundLine(point_c, point_d);
273271
render_path(PathBuilder{}.AddCubicCurve(a, b, d, c).TakePath(),
274272
Cap::kSquare, Join::kBevel);
@@ -277,11 +275,11 @@ TEST_P(EntityTest, StrokeCapAndJoinTest) {
277275
// Cap::kRound demo.
278276
{
279277
Point off = Point(2, 0) * padding + margin;
280-
static PlaygroundPoint point_a(off + a_def, r, Color::Black());
281-
static PlaygroundPoint point_b(off + b_def, r, Color::White());
278+
PlaygroundPoint point_a(off + a_def, r, Color::Black());
279+
PlaygroundPoint point_b(off + b_def, r, Color::White());
282280
auto [a, b] = DrawPlaygroundLine(point_a, point_b);
283-
static PlaygroundPoint point_c(off + c_def, r, Color::Black());
284-
static PlaygroundPoint point_d(off + d_def, r, Color::White());
281+
PlaygroundPoint point_c(off + c_def, r, Color::Black());
282+
PlaygroundPoint point_d(off + d_def, r, Color::White());
285283
auto [c, d] = DrawPlaygroundLine(point_c, point_d);
286284
render_path(PathBuilder{}.AddCubicCurve(a, b, d, c).TakePath(),
287285
Cap::kRound, Join::kBevel);
@@ -290,12 +288,9 @@ TEST_P(EntityTest, StrokeCapAndJoinTest) {
290288
// Join::kBevel demo.
291289
{
292290
Point off = Point(0, 1) * padding + margin;
293-
static PlaygroundPoint point_a =
294-
PlaygroundPoint(off + a_def, r, Color::White());
295-
static PlaygroundPoint point_b =
296-
PlaygroundPoint(off + e_def, r, Color::White());
297-
static PlaygroundPoint point_c =
298-
PlaygroundPoint(off + c_def, r, Color::White());
291+
PlaygroundPoint point_a = PlaygroundPoint(off + a_def, r, Color::White());
292+
PlaygroundPoint point_b = PlaygroundPoint(off + e_def, r, Color::White());
293+
PlaygroundPoint point_c = PlaygroundPoint(off + c_def, r, Color::White());
299294
Point a = DrawPlaygroundPoint(point_a);
300295
Point b = DrawPlaygroundPoint(point_b);
301296
Point c = DrawPlaygroundPoint(point_c);
@@ -307,9 +302,9 @@ TEST_P(EntityTest, StrokeCapAndJoinTest) {
307302
// Join::kMiter demo.
308303
{
309304
Point off = Point(1, 1) * padding + margin;
310-
static PlaygroundPoint point_a(off + a_def, r, Color::White());
311-
static PlaygroundPoint point_b(off + e_def, r, Color::White());
312-
static PlaygroundPoint point_c(off + c_def, r, Color::White());
305+
PlaygroundPoint point_a(off + a_def, r, Color::White());
306+
PlaygroundPoint point_b(off + e_def, r, Color::White());
307+
PlaygroundPoint point_c(off + c_def, r, Color::White());
313308
Point a = DrawPlaygroundPoint(point_a);
314309
Point b = DrawPlaygroundPoint(point_b);
315310
Point c = DrawPlaygroundPoint(point_c);
@@ -321,9 +316,9 @@ TEST_P(EntityTest, StrokeCapAndJoinTest) {
321316
// Join::kRound demo.
322317
{
323318
Point off = Point(2, 1) * padding + margin;
324-
static PlaygroundPoint point_a(off + a_def, r, Color::White());
325-
static PlaygroundPoint point_b(off + e_def, r, Color::White());
326-
static PlaygroundPoint point_c(off + c_def, r, Color::White());
319+
PlaygroundPoint point_a(off + a_def, r, Color::White());
320+
PlaygroundPoint point_b(off + e_def, r, Color::White());
321+
PlaygroundPoint point_c(off + c_def, r, Color::White());
327322
Point a = DrawPlaygroundPoint(point_a);
328323
Point b = DrawPlaygroundPoint(point_b);
329324
Point c = DrawPlaygroundPoint(point_c);
@@ -356,7 +351,7 @@ TEST_P(EntityTest, CubicCurveTest) {
356351
Entity entity;
357352
entity.SetTransform(Matrix::MakeScale(GetContentScale()));
358353

359-
static std::unique_ptr<Geometry> geom = Geometry::MakeFillPath(path);
354+
std::unique_ptr<Geometry> geom = Geometry::MakeFillPath(path);
360355

361356
auto contents = std::make_shared<SolidColorContents>();
362357
contents->SetColor(Color::Red());
@@ -407,7 +402,7 @@ TEST_P(EntityTest, CanDrawCorrectlyWithRotatedTransform) {
407402
Entity entity;
408403
entity.SetTransform(result_transform);
409404

410-
static std::unique_ptr<Geometry> geom = Geometry::MakeFillPath(path);
405+
std::unique_ptr<Geometry> geom = Geometry::MakeFillPath(path);
411406

412407
auto contents = std::make_shared<SolidColorContents>();
413408
contents->SetColor(Color::Red());
@@ -644,7 +639,7 @@ TEST_P(EntityTest, CubicCurveAndOverlapTest) {
644639
Entity entity;
645640
entity.SetTransform(Matrix::MakeScale(GetContentScale()));
646641

647-
static std::unique_ptr<Geometry> geom = Geometry::MakeFillPath(path);
642+
std::unique_ptr<Geometry> geom = Geometry::MakeFillPath(path);
648643

649644
auto contents = std::make_shared<SolidColorContents>();
650645
contents->SetColor(Color::Red());
@@ -808,11 +803,11 @@ TEST_P(EntityTest, BlendingModeOptions) {
808803
BlendMode selected_mode = blend_mode_values[current_blend_index];
809804

810805
Point a, b, c, d;
811-
static PlaygroundPoint point_a(Point(400, 100), 20, Color::White());
812-
static PlaygroundPoint point_b(Point(200, 300), 20, Color::White());
806+
PlaygroundPoint point_a(Point(400, 100), 20, Color::White());
807+
PlaygroundPoint point_b(Point(200, 300), 20, Color::White());
813808
std::tie(a, b) = DrawPlaygroundLine(point_a, point_b);
814-
static PlaygroundPoint point_c(Point(470, 190), 20, Color::White());
815-
static PlaygroundPoint point_d(Point(270, 390), 20, Color::White());
809+
PlaygroundPoint point_c(Point(470, 190), 20, Color::White());
810+
PlaygroundPoint point_d(Point(270, 390), 20, Color::White());
816811
std::tie(c, d) = DrawPlaygroundLine(point_c, point_d);
817812

818813
bool result = true;
@@ -858,7 +853,7 @@ TEST_P(EntityTest, BezierCircleScaled) {
858853
entity.SetTransform(
859854
Matrix::MakeScale({scale, scale, 1.0}).Translate({-90, -20, 0}));
860855

861-
static std::unique_ptr<Geometry> geom = Geometry::MakeFillPath(path);
856+
std::unique_ptr<Geometry> geom = Geometry::MakeFillPath(path);
862857

863858
auto contents = std::make_shared<SolidColorContents>();
864859
contents->SetColor(Color::Red());
@@ -987,6 +982,8 @@ TEST_P(EntityTest, GaussianBlurFilter) {
987982

988983
auto input_rect =
989984
Rect::MakeXYWH(path_rect[0], path_rect[1], path_rect[2], path_rect[3]);
985+
986+
std::unique_ptr<Geometry> solid_color_input;
990987
if (selected_input_type == 0) {
991988
auto texture = std::make_shared<TextureContents>();
992989
texture->SetSourceRect(Rect::MakeSize(boston->GetSize()));
@@ -999,10 +996,10 @@ TEST_P(EntityTest, GaussianBlurFilter) {
999996
} else {
1000997
auto fill = std::make_shared<SolidColorContents>();
1001998
fill->SetColor(input_color);
1002-
static std::unique_ptr<Geometry> geom =
999+
solid_color_input =
10031000
Geometry::MakeFillPath(PathBuilder{}.AddRect(input_rect).TakePath());
10041001

1005-
fill->SetGeometry(geom.get());
1002+
fill->SetGeometry(solid_color_input.get());
10061003

10071004
input = fill;
10081005
input_size = input_rect.GetSize();
@@ -1047,7 +1044,7 @@ TEST_P(EntityTest, GaussianBlurFilter) {
10471044
// Renders a red "cover" rectangle that shows the original position of the
10481045
// unfiltered input.
10491046
Entity cover_entity;
1050-
static std::unique_ptr<Geometry> geom =
1047+
std::unique_ptr<Geometry> geom =
10511048
Geometry::MakeFillPath(PathBuilder{}.AddRect(input_rect).TakePath());
10521049
auto contents = std::make_shared<SolidColorContents>();
10531050
contents->SetColor(cover_color);
@@ -1061,7 +1058,7 @@ TEST_P(EntityTest, GaussianBlurFilter) {
10611058
std::optional<Rect> target_contents_coverage =
10621059
target_contents->GetCoverage(entity);
10631060
if (target_contents_coverage.has_value()) {
1064-
static std::unique_ptr<Geometry> geom = Geometry::MakeFillPath(
1061+
std::unique_ptr<Geometry> geom = Geometry::MakeFillPath(
10651062
PathBuilder{}
10661063
.AddRect(target_contents->GetCoverage(entity).value())
10671064
.TakePath());
@@ -1159,7 +1156,7 @@ TEST_P(EntityTest, MorphologyFilter) {
11591156
// Renders a red "cover" rectangle that shows the original position of the
11601157
// unfiltered input.
11611158
Entity cover_entity;
1162-
static std::unique_ptr<Geometry> geom =
1159+
std::unique_ptr<Geometry> geom =
11631160
Geometry::MakeFillPath(PathBuilder{}.AddRect(input_rect).TakePath());
11641161
auto cover_contents = std::make_shared<SolidColorContents>();
11651162
cover_contents->SetColor(cover_color);
@@ -1170,7 +1167,7 @@ TEST_P(EntityTest, MorphologyFilter) {
11701167

11711168
// Renders a green bounding rect of the target filter.
11721169
Entity bounds_entity;
1173-
static std::unique_ptr<Geometry> bounds_geom = Geometry::MakeFillPath(
1170+
std::unique_ptr<Geometry> bounds_geom = Geometry::MakeFillPath(
11741171
PathBuilder{}
11751172
.AddRect(contents->GetCoverage(entity).value())
11761173
.TakePath());
@@ -1349,9 +1346,8 @@ TEST_P(EntityTest, RRectShadowTest) {
13491346
}
13501347
ImGui::End();
13511348

1352-
static PlaygroundPoint top_left_point(Point(200, 200), 30, Color::White());
1353-
static PlaygroundPoint bottom_right_point(Point(600, 400), 30,
1354-
Color::White());
1349+
PlaygroundPoint top_left_point(Point(200, 200), 30, Color::White());
1350+
PlaygroundPoint bottom_right_point(Point(600, 400), 30, Color::White());
13551351
auto [top_left, bottom_right] =
13561352
DrawPlaygroundLine(top_left_point, bottom_right_point);
13571353
auto rect =
@@ -1700,7 +1696,7 @@ TEST_P(EntityTest, RuntimeEffect) {
17001696

17011697
bool expect_dirty = true;
17021698
Pipeline<PipelineDescriptor>* first_pipeline;
1703-
static std::unique_ptr<Geometry> geom = Geometry::MakeCover();
1699+
std::unique_ptr<Geometry> geom = Geometry::MakeCover();
17041700

17051701
auto callback = [&](ContentContext& context, RenderPass& pass) -> bool {
17061702
EXPECT_EQ(runtime_stage->IsDirty(), expect_dirty);
@@ -2292,7 +2288,7 @@ TEST_P(EntityTest, CanRenderEmptyPathsWithoutCrashing) {
22922288
EXPECT_TRUE(path.GetBoundingBox()->IsEmpty());
22932289

22942290
auto contents = std::make_shared<SolidColorContents>();
2295-
static std::unique_ptr<Geometry> geom = Geometry::MakeFillPath(path);
2291+
std::unique_ptr<Geometry> geom = Geometry::MakeFillPath(path);
22962292
contents->SetGeometry(geom.get());
22972293
contents->SetColor(Color::Red());
22982294

@@ -2321,7 +2317,7 @@ TEST_P(EntityTest, DrawSuperEllipse) {
23212317
ImGui::End();
23222318

23232319
auto contents = std::make_shared<SolidColorContents>();
2324-
static std::unique_ptr<SuperellipseGeometry> geom =
2320+
std::unique_ptr<SuperellipseGeometry> geom =
23252321
std::make_unique<SuperellipseGeometry>(Point{400, 400}, radius, degree,
23262322
alpha, beta);
23272323
contents->SetColor(color);

0 commit comments

Comments
 (0)