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

Commit 7814e5d

Browse files
authored
[Impeller] replaced playground macros with functions (#50602)
testing: Refactor only ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides]. - [ ] I listed at least one issue that this PR fixes in the description above. - [x] I added new tests to check the change I am making or feature I am adding, or the PR is [test-exempt]. See [testing the engine] for instructions on writing and running engine tests. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I signed the [CLA]. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [test-exempt]: https://github.com/flutter/flutter/wiki/Tree-hygiene#tests [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style [testing the engine]: https://github.com/flutter/flutter/wiki/Testing-the-engine [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat
1 parent f330905 commit 7814e5d

File tree

8 files changed

+175
-122
lines changed

8 files changed

+175
-122
lines changed

impeller/aiks/aiks_blur_unittests.cc

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ TEST_P(AiksTest, CanRenderForegroundAdvancedBlendWithMaskBlur) {
7676

7777
TEST_P(AiksTest, CanRenderBackdropBlurInteractive) {
7878
auto callback = [&](AiksContext& renderer) -> std::optional<Picture> {
79-
auto [a, b] = IMPELLER_PLAYGROUND_LINE(Point(50, 50), Point(300, 200), 30,
80-
Color::White(), Color::White());
79+
static PlaygroundPoint point_a(Point(50, 50), 30, Color::White());
80+
static PlaygroundPoint point_b(Point(300, 200), 30, Color::White());
81+
auto [a, b] = DrawPlaygroundLine(point_a, point_b);
8182

8283
Canvas canvas;
8384
canvas.DrawCircle({100, 100}, 50, {.color = Color::CornflowerBlue()});
@@ -143,7 +144,9 @@ TEST_P(AiksTest, CanRenderClippedBlur) {
143144

144145
TEST_P(AiksTest, ClippedBlurFilterRendersCorrectlyInteractive) {
145146
auto callback = [&](AiksContext& renderer) -> std::optional<Picture> {
146-
auto point = IMPELLER_PLAYGROUND_POINT(Point(400, 400), 20, Color::Green());
147+
static PlaygroundPoint playground_point(Point(400, 400), 20,
148+
Color::Green());
149+
auto point = DrawPlaygroundPoint(playground_point);
147150

148151
Canvas canvas;
149152
canvas.Translate(point - Point(400, 400));
@@ -465,8 +468,9 @@ TEST_P(AiksTest, GaussianBlurRotatedAndClippedInteractive) {
465468
ImageFilter::MakeBlur(Sigma(20.0), Sigma(20.0),
466469
FilterContents::BlurStyle::kNormal,
467470
tile_modes[selected_tile_mode])};
468-
auto [handle_a, handle_b] = IMPELLER_PLAYGROUND_LINE(
469-
Point(362, 309), Point(662, 459), 20, Color::Red(), Color::Red());
471+
static PlaygroundPoint point_a(Point(362, 309), 20, Color::Red());
472+
static PlaygroundPoint point_b(Point(662, 459), 20, Color::Red());
473+
auto [handle_a, handle_b] = DrawPlaygroundLine(point_a, point_b);
470474
Vector2 center = Vector2(1024, 768) / 2;
471475
canvas.Scale(GetContentScale());
472476
canvas.ClipRect(
@@ -567,8 +571,9 @@ TEST_P(AiksTest, GaussianBlurAnimatedBackdrop) {
567571
Point(1024 / 2 - boston->GetSize().width / 2,
568572
(768 / 2 - boston->GetSize().height / 2) + y),
569573
{});
570-
auto [handle_a, handle_b] = IMPELLER_PLAYGROUND_LINE(
571-
Point(100, 100), Point(900, 700), 20, Color::Red(), Color::Red());
574+
static PlaygroundPoint point_a(Point(100, 100), 20, Color::Red());
575+
static PlaygroundPoint point_b(Point(900, 700), 20, Color::Red());
576+
auto [handle_a, handle_b] = DrawPlaygroundLine(point_a, point_b);
572577
canvas.ClipRect(
573578
Rect::MakeLTRB(handle_a.x, handle_a.y, handle_b.x, handle_b.y));
574579
canvas.ClipRect(Rect::MakeLTRB(100, 100, 900, 700));

impeller/aiks/aiks_gradient_unittests.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,8 +702,12 @@ TEST_P(AiksTest, GradientStrokesRenderCorrectly) {
702702
canvas.Scale(Vector2(scale, scale));
703703

704704
if (add_circle_clip) {
705-
auto [handle_a, handle_b] = IMPELLER_PLAYGROUND_LINE(
706-
Point(60, 300), Point(600, 300), 20, Color::Red(), Color::Red());
705+
static PlaygroundPoint circle_clip_point_a(Point(60, 300), 20,
706+
Color::Red());
707+
static PlaygroundPoint circle_clip_point_b(Point(600, 300), 20,
708+
Color::Red());
709+
auto [handle_a, handle_b] =
710+
DrawPlaygroundLine(circle_clip_point_a, circle_clip_point_b);
707711

708712
auto screen_to_canvas = canvas.GetCurrentTransform().Invert();
709713
Point point_a = screen_to_canvas * handle_a * GetContentScale();

impeller/aiks/aiks_path_unittests.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,12 @@ TEST_P(AiksTest, SolidStrokesRenderCorrectly) {
215215
canvas.Scale(Vector2(scale, scale));
216216

217217
if (add_circle_clip) {
218-
auto [handle_a, handle_b] = IMPELLER_PLAYGROUND_LINE(
219-
Point(60, 300), Point(600, 300), 20, Color::Red(), Color::Red());
218+
static PlaygroundPoint circle_clip_point_a(Point(60, 300), 20,
219+
Color::Red());
220+
static PlaygroundPoint circle_clip_point_b(Point(600, 300), 20,
221+
Color::Red());
222+
auto [handle_a, handle_b] =
223+
DrawPlaygroundLine(circle_clip_point_a, circle_clip_point_b);
220224

221225
auto screen_to_canvas = canvas.GetCurrentTransform().Invert();
222226
Point point_a = screen_to_canvas * handle_a * GetContentScale();

impeller/aiks/aiks_unittests.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,8 +1715,9 @@ TEST_P(AiksTest, CoverageOriginShouldBeAccountedForInSubpasses) {
17151715
const auto offset = Point{25, 25};
17161716
const auto size = Size(100, 100);
17171717

1718-
auto [b0, b1] = IMPELLER_PLAYGROUND_LINE(Point(40, 40), Point(160, 160), 10,
1719-
Color::White(), Color::White());
1718+
static PlaygroundPoint point_a(Point(40, 40), 10, Color::White());
1719+
static PlaygroundPoint point_b(Point(160, 160), 10, Color::White());
1720+
auto [b0, b1] = DrawPlaygroundLine(point_a, point_b);
17201721
auto bounds = Rect::MakeLTRB(b0.x, b0.y, b1.x, b1.y);
17211722

17221723
canvas.DrawRect(bounds, Paint{.color = Color::Yellow(),

impeller/display_list/dl_unittests.cc

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,9 @@ TEST_P(DisplayListTest, CanDrawArc) {
184184
break;
185185
}
186186

187-
auto [p1, p2] = IMPELLER_PLAYGROUND_LINE(
188-
Point(200, 200), Point(400, 400), 20, Color::White(), Color::White());
187+
static PlaygroundPoint point_a(Point(200, 200), 20, Color::White());
188+
static PlaygroundPoint point_b(Point(400, 400), 20, Color::White());
189+
auto [p1, p2] = DrawPlaygroundLine(point_a, point_b);
189190

190191
flutter::DisplayListBuilder builder;
191192
flutter::DlPaint paint;
@@ -676,8 +677,9 @@ TEST_P(DisplayListTest, CanDrawBackdropFilter) {
676677

677678
std::optional<SkRect> bounds;
678679
if (use_bounds) {
679-
auto [p1, p2] = IMPELLER_PLAYGROUND_LINE(
680-
Point(350, 150), Point(800, 600), 20, Color::White(), Color::White());
680+
static PlaygroundPoint point_a(Point(350, 150), 20, Color::White());
681+
static PlaygroundPoint point_b(Point(800, 600), 20, Color::White());
682+
auto [p1, p2] = DrawPlaygroundLine(point_a, point_b);
681683
bounds = SkRect::MakeLTRB(p1.x, p1.y, p2.x, p2.y);
682684
}
683685

@@ -694,8 +696,8 @@ TEST_P(DisplayListTest, CanDrawBackdropFilter) {
694696
&filter);
695697

696698
if (draw_circle) {
697-
auto circle_center =
698-
IMPELLER_PLAYGROUND_POINT(Point(500, 400), 20, Color::Red());
699+
static PlaygroundPoint center_point(Point(500, 400), 20, Color::Red());
700+
auto circle_center = DrawPlaygroundPoint(center_point);
699701

700702
flutter::DlPaint paint;
701703
paint.setDrawStyle(flutter::DlDrawStyle::kStroke);

impeller/entity/entity_unittests.cc

Lines changed: 65 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -300,20 +300,21 @@ TEST_P(EntityTest, TriangleInsideASquare) {
300300
auto callback = [&](ContentContext& context, RenderPass& pass) {
301301
Point offset(100, 100);
302302

303-
Point a =
304-
IMPELLER_PLAYGROUND_POINT(Point(10, 10) + offset, 20, Color::White());
305-
Point b =
306-
IMPELLER_PLAYGROUND_POINT(Point(210, 10) + offset, 20, Color::White());
307-
Point c =
308-
IMPELLER_PLAYGROUND_POINT(Point(210, 210) + offset, 20, Color::White());
309-
Point d =
310-
IMPELLER_PLAYGROUND_POINT(Point(10, 210) + offset, 20, Color::White());
311-
Point e =
312-
IMPELLER_PLAYGROUND_POINT(Point(50, 50) + offset, 20, Color::White());
313-
Point f =
314-
IMPELLER_PLAYGROUND_POINT(Point(100, 50) + offset, 20, Color::White());
315-
Point g =
316-
IMPELLER_PLAYGROUND_POINT(Point(50, 150) + offset, 20, Color::White());
303+
static PlaygroundPoint point_a(Point(10, 10) + offset, 20, Color::White());
304+
Point a = DrawPlaygroundPoint(point_a);
305+
static PlaygroundPoint point_b(Point(210, 10) + offset, 20, Color::White());
306+
Point b = DrawPlaygroundPoint(point_b);
307+
static PlaygroundPoint point_c(Point(210, 210) + offset, 20,
308+
Color::White());
309+
Point c = DrawPlaygroundPoint(point_c);
310+
static PlaygroundPoint point_d(Point(10, 210) + offset, 20, Color::White());
311+
Point d = DrawPlaygroundPoint(point_d);
312+
static PlaygroundPoint point_e(Point(50, 50) + offset, 20, Color::White());
313+
Point e = DrawPlaygroundPoint(point_e);
314+
static PlaygroundPoint point_f(Point(100, 50) + offset, 20, Color::White());
315+
Point f = DrawPlaygroundPoint(point_f);
316+
static PlaygroundPoint point_g(Point(50, 150) + offset, 20, Color::White());
317+
Point g = DrawPlaygroundPoint(point_g);
317318
Path path = PathBuilder{}
318319
.MoveTo(a)
319320
.LineTo(b)
@@ -392,42 +393,54 @@ TEST_P(EntityTest, StrokeCapAndJoinTest) {
392393
// Cap::kButt demo.
393394
{
394395
Point off = Point(0, 0) * padding + margin;
395-
auto [a, b] = IMPELLER_PLAYGROUND_LINE(off + a_def, off + b_def, r,
396-
Color::Black(), Color::White());
397-
auto [c, d] = IMPELLER_PLAYGROUND_LINE(off + c_def, off + d_def, r,
398-
Color::Black(), Color::White());
396+
static PlaygroundPoint point_a(off + a_def, r, Color::Black());
397+
static PlaygroundPoint point_b(off + b_def, r, Color::White());
398+
auto [a, b] = DrawPlaygroundLine(point_a, point_b);
399+
static PlaygroundPoint point_c(off + c_def, r, Color::Black());
400+
static PlaygroundPoint point_d(off + d_def, r, Color::White());
401+
auto [c, d] = DrawPlaygroundLine(point_c, point_d);
399402
render_path(PathBuilder{}.AddCubicCurve(a, b, d, c).TakePath(),
400403
Cap::kButt, Join::kBevel);
401404
}
402405

403406
// Cap::kSquare demo.
404407
{
405408
Point off = Point(1, 0) * padding + margin;
406-
auto [a, b] = IMPELLER_PLAYGROUND_LINE(off + a_def, off + b_def, r,
407-
Color::Black(), Color::White());
408-
auto [c, d] = IMPELLER_PLAYGROUND_LINE(off + c_def, off + d_def, r,
409-
Color::Black(), Color::White());
409+
static PlaygroundPoint point_a(off + a_def, r, Color::Black());
410+
static PlaygroundPoint point_b(off + b_def, r, Color::White());
411+
auto [a, b] = DrawPlaygroundLine(point_a, point_b);
412+
static PlaygroundPoint point_c(off + c_def, r, Color::Black());
413+
static PlaygroundPoint point_d(off + d_def, r, Color::White());
414+
auto [c, d] = DrawPlaygroundLine(point_c, point_d);
410415
render_path(PathBuilder{}.AddCubicCurve(a, b, d, c).TakePath(),
411416
Cap::kSquare, Join::kBevel);
412417
}
413418

414419
// Cap::kRound demo.
415420
{
416421
Point off = Point(2, 0) * padding + margin;
417-
auto [a, b] = IMPELLER_PLAYGROUND_LINE(off + a_def, off + b_def, r,
418-
Color::Black(), Color::White());
419-
auto [c, d] = IMPELLER_PLAYGROUND_LINE(off + c_def, off + d_def, r,
420-
Color::Black(), Color::White());
422+
static PlaygroundPoint point_a(off + a_def, r, Color::Black());
423+
static PlaygroundPoint point_b(off + b_def, r, Color::White());
424+
auto [a, b] = DrawPlaygroundLine(point_a, point_b);
425+
static PlaygroundPoint point_c(off + c_def, r, Color::Black());
426+
static PlaygroundPoint point_d(off + d_def, r, Color::White());
427+
auto [c, d] = DrawPlaygroundLine(point_c, point_d);
421428
render_path(PathBuilder{}.AddCubicCurve(a, b, d, c).TakePath(),
422429
Cap::kRound, Join::kBevel);
423430
}
424431

425432
// Join::kBevel demo.
426433
{
427434
Point off = Point(0, 1) * padding + margin;
428-
Point a = IMPELLER_PLAYGROUND_POINT(off + a_def, r, Color::White());
429-
Point b = IMPELLER_PLAYGROUND_POINT(off + e_def, r, Color::White());
430-
Point c = IMPELLER_PLAYGROUND_POINT(off + c_def, r, Color::White());
435+
static PlaygroundPoint point_a =
436+
PlaygroundPoint(off + a_def, r, Color::White());
437+
static PlaygroundPoint point_b =
438+
PlaygroundPoint(off + e_def, r, Color::White());
439+
static PlaygroundPoint point_c =
440+
PlaygroundPoint(off + c_def, r, Color::White());
441+
Point a = DrawPlaygroundPoint(point_a);
442+
Point b = DrawPlaygroundPoint(point_b);
443+
Point c = DrawPlaygroundPoint(point_c);
431444
render_path(
432445
PathBuilder{}.MoveTo(a).LineTo(b).LineTo(c).Close().TakePath(),
433446
Cap::kButt, Join::kBevel);
@@ -436,9 +449,12 @@ TEST_P(EntityTest, StrokeCapAndJoinTest) {
436449
// Join::kMiter demo.
437450
{
438451
Point off = Point(1, 1) * padding + margin;
439-
Point a = IMPELLER_PLAYGROUND_POINT(off + a_def, r, Color::White());
440-
Point b = IMPELLER_PLAYGROUND_POINT(off + e_def, r, Color::White());
441-
Point c = IMPELLER_PLAYGROUND_POINT(off + c_def, r, Color::White());
452+
static PlaygroundPoint point_a(off + a_def, r, Color::White());
453+
static PlaygroundPoint point_b(off + e_def, r, Color::White());
454+
static PlaygroundPoint point_c(off + c_def, r, Color::White());
455+
Point a = DrawPlaygroundPoint(point_a);
456+
Point b = DrawPlaygroundPoint(point_b);
457+
Point c = DrawPlaygroundPoint(point_c);
442458
render_path(
443459
PathBuilder{}.MoveTo(a).LineTo(b).LineTo(c).Close().TakePath(),
444460
Cap::kButt, Join::kMiter);
@@ -447,9 +463,12 @@ TEST_P(EntityTest, StrokeCapAndJoinTest) {
447463
// Join::kRound demo.
448464
{
449465
Point off = Point(2, 1) * padding + margin;
450-
Point a = IMPELLER_PLAYGROUND_POINT(off + a_def, r, Color::White());
451-
Point b = IMPELLER_PLAYGROUND_POINT(off + e_def, r, Color::White());
452-
Point c = IMPELLER_PLAYGROUND_POINT(off + c_def, r, Color::White());
466+
static PlaygroundPoint point_a(off + a_def, r, Color::White());
467+
static PlaygroundPoint point_b(off + e_def, r, Color::White());
468+
static PlaygroundPoint point_c(off + c_def, r, Color::White());
469+
Point a = DrawPlaygroundPoint(point_a);
470+
Point b = DrawPlaygroundPoint(point_b);
471+
Point c = DrawPlaygroundPoint(point_c);
453472
render_path(
454473
PathBuilder{}.MoveTo(a).LineTo(b).LineTo(c).Close().TakePath(),
455474
Cap::kButt, Join::kRound);
@@ -905,10 +924,12 @@ TEST_P(EntityTest, BlendingModeOptions) {
905924
BlendMode selected_mode = blend_mode_values[current_blend_index];
906925

907926
Point a, b, c, d;
908-
std::tie(a, b) = IMPELLER_PLAYGROUND_LINE(
909-
Point(400, 100), Point(200, 300), 20, Color::White(), Color::White());
910-
std::tie(c, d) = IMPELLER_PLAYGROUND_LINE(
911-
Point(470, 190), Point(270, 390), 20, Color::White(), Color::White());
927+
static PlaygroundPoint point_a(Point(400, 100), 20, Color::White());
928+
static PlaygroundPoint point_b(Point(200, 300), 20, Color::White());
929+
std::tie(a, b) = DrawPlaygroundLine(point_a, point_b);
930+
static PlaygroundPoint point_c(Point(470, 190), 20, Color::White());
931+
static PlaygroundPoint point_d(Point(270, 390), 20, Color::White());
932+
std::tie(c, d) = DrawPlaygroundLine(point_c, point_d);
912933

913934
bool result = true;
914935
result = result &&
@@ -1739,8 +1760,11 @@ TEST_P(EntityTest, RRectShadowTest) {
17391760
}
17401761
ImGui::End();
17411762

1742-
auto [top_left, bottom_right] = IMPELLER_PLAYGROUND_LINE(
1743-
Point(200, 200), Point(600, 400), 30, Color::White(), Color::White());
1763+
static PlaygroundPoint top_left_point(Point(200, 200), 30, Color::White());
1764+
static PlaygroundPoint bottom_right_point(Point(600, 400), 30,
1765+
Color::White());
1766+
auto [top_left, bottom_right] =
1767+
DrawPlaygroundLine(top_left_point, bottom_right_point);
17441768
auto rect =
17451769
Rect::MakeLTRB(top_left.x, top_left.y, bottom_right.x, bottom_right.y);
17461770

impeller/playground/widgets.cc

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,62 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
#include "widgets.h"
5+
#include "impeller/playground/widgets.h"
66

77
namespace impeller {
88

9+
Point DrawPlaygroundPoint(PlaygroundPoint& point) {
10+
impeller::Point mouse_pos(ImGui::GetMousePos().x, ImGui::GetMousePos().y);
11+
if (!point.prev_mouse_pos.has_value()) {
12+
point.prev_mouse_pos = mouse_pos;
13+
}
14+
15+
if (ImGui::IsKeyPressed(ImGuiKey_R)) {
16+
point.position = point.reset_position;
17+
point.dragging = false;
18+
}
19+
20+
bool hovering =
21+
point.position.GetDistance(mouse_pos) < point.radius &&
22+
point.position.GetDistance(point.prev_mouse_pos.value()) < point.radius;
23+
if (!ImGui::IsMouseDown(0)) {
24+
point.dragging = false;
25+
} else if (hovering && ImGui::IsMouseClicked(0)) {
26+
point.dragging = true;
27+
}
28+
if (point.dragging) {
29+
point.position += mouse_pos - point.prev_mouse_pos.value();
30+
}
31+
ImGui::GetBackgroundDrawList()->AddCircleFilled(
32+
{point.position.x, point.position.y}, point.radius,
33+
ImColor(point.color.red, point.color.green, point.color.blue,
34+
(hovering || point.dragging) ? 0.6f : 0.3f));
35+
if (hovering || point.dragging) {
36+
ImGui::GetBackgroundDrawList()->AddText(
37+
{point.position.x - point.radius, point.position.y + point.radius + 10},
38+
ImColor(point.color.red, point.color.green, point.color.blue, 1.0f),
39+
impeller::SPrintF("x:%0.3f y:%0.3f", point.position.x, point.position.y)
40+
.c_str());
41+
}
42+
point.prev_mouse_pos = mouse_pos;
43+
return point.position;
44+
}
45+
46+
std::tuple<Point, Point> DrawPlaygroundLine(PlaygroundPoint& point_a,
47+
PlaygroundPoint& point_b) {
48+
Point position_a = DrawPlaygroundPoint(point_a);
49+
Point position_b = DrawPlaygroundPoint(point_b);
50+
51+
auto dir = (position_b - position_a).Normalize() * point_a.radius;
52+
auto line_a = position_a + dir;
53+
auto line_b = position_b - dir;
54+
ImGui::GetBackgroundDrawList()->AddLine(
55+
{line_a.x, line_a.y}, {line_b.x, line_b.y},
56+
ImColor(point_b.color.red, point_b.color.green, point_b.color.blue,
57+
0.3f));
58+
59+
return std::make_tuple(position_a, position_b);
60+
}
961
//
1062

1163
} // namespace impeller

0 commit comments

Comments
 (0)