5#include "flutter/impeller/aiks/aiks_unittests.h"
15#include "third_party/imgui/imgui.h"
28 canvas.Scale(aiks_test->GetContentScale());
30 canvas.Translate({100.0f, 0, 0});
32 std::vector<Color>
colors = {Color{0.9568, 0.2627, 0.2118, 1.0},
33 Color{0.1294, 0.5882, 0.9529, 0.0}};
34 std::vector<Scalar> stops = {0.0, 1.0};
37 {0, 0}, {200, 200}, std::move(colors), std::move(stops), tile_mode, {});
39 paint.color = Color(1.0, 1.0, 1.0, 1.0);
41 ASSERT_TRUE(aiks_test->OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
60 canvas.
Scale(GetContentScale());
64 std::vector<Color> colors = {
Color{0.9568, 0.2627, 0.2118, 1.0},
65 Color{0.1294, 0.5882, 0.9529, 0.0}};
66 std::vector<Scalar> stops = {0.0, 1.0};
69 {0, 0}, {200, 200}, std::move(colors), std::move(stops),
90 std::vector<Color> colors = {
Color{0.8, 0.8, 0.8, 1.0},
91 Color{0.2, 0.2, 0.2, 1.0}};
92 std::vector<Scalar> stops = {0.0, 1.0};
95 {0, 0}, {800, 500}, std::move(colors), std::move(stops),
97 paint.dither = use_dithering;
111 bool use_dithering) {
117 std::vector<Color> colors = {
Color{1.0, 1.0, 1.0, 1.0},
118 Color{0.0, 0.0, 0.0, 1.0}};
119 std::vector<Scalar> stops = {0.0, 1.0};
122 {600, 600}, 600, std::move(colors), std::move(stops),
124 paint.dither = use_dithering;
138 bool use_dithering) {
145 std::vector<Color> colors = {
Color{1.0, 1.0, 1.0, 1.0},
146 Color{0.0, 0.0, 0.0, 1.0}};
147 std::vector<Scalar> stops = {0.0, 1.0};
152 paint.dither = use_dithering;
167 bool use_dithering) {
174 std::vector<Color> colors = {
Color{1.0, 1.0, 1.0, 1.0},
175 Color{0.0, 0.0, 0.0, 1.0}};
176 std::vector<Scalar> stops = {0.0, 1.0};
179 {100, 100}, 100, std::move(colors), std::move(stops), {0, 1}, 0,
181 paint.dither = use_dithering;
196void CanRenderLinearGradientWithOverlappingStops(
AiksTest* aiks_test,
202 std::vector<Color> colors = {
203 Color{0.9568, 0.2627, 0.2118, 1.0}, Color{0.9568, 0.2627, 0.2118, 1.0},
204 Color{0.1294, 0.5882, 0.9529, 1.0}, Color{0.1294, 0.5882, 0.9529, 1.0}};
205 std::vector<Scalar> stops = {0.0, 0.5, 0.5, 1.0};
208 {0, 0}, {500, 500}, std::move(colors), std::move(stops), tile_mode, {});
210 paint.color = Color(1.0, 1.0, 1.0, 1.0);
222void CanRenderLinearGradientManyColors(
AiksTest* aiks_test,
225 canvas.
Scale(aiks_test->GetContentScale());
229 std::vector<Color> colors = {
230 Color{0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0},
231 Color{0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0},
232 Color{0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0},
233 Color{0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0},
234 Color{0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0},
235 Color{0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0},
236 Color{0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0}};
237 std::vector<Scalar> stops = {
248 {0, 0}, {200, 200}, std::move(colors), std::move(stops), tile_mode, {});
250 paint.color = Color(1.0, 1.0, 1.0, 1.0);
271void CanRenderLinearGradientWayManyColors(
AiksTest* aiks_test,
276 auto color = Color{0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0};
277 std::vector<Color>
colors;
278 std::vector<Scalar> stops;
279 auto current_stop = 0.0;
280 for (
int i = 0; i < 2000; i++) {
282 stops.push_back(current_stop);
283 current_stop += 1 / 2000.0;
285 stops[2000 - 1] = 1.0;
288 {0, 0}, {200, 200}, std::move(colors), std::move(stops), tile_mode, {});
302 const char* tile_mode_names[] = {
"Clamp",
"Repeat",
"Mirror",
"Decal"};
307 static int selected_tile_mode = 0;
315 ImGuiWindowFlags_AlwaysAutoResize)) {
316 ImGui::Combo(
"Tile mode", &selected_tile_mode, tile_mode_names,
317 sizeof(tile_mode_names) /
sizeof(
char*));
318 std::string label =
"##1";
319 for (
int i = 0; i < 4; i++) {
320 ImGui::InputScalarN(label.c_str(), ImGuiDataType_Float,
321 &(matrix.vec[i]), 4, NULL, NULL,
"%.2f", 0);
330 auto tile_mode = tile_modes[selected_tile_mode];
332 std::vector<Color> colors = {
333 Color{0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0},
334 Color{0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0},
335 Color{0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0},
336 Color{0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0},
337 Color{0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0},
338 Color{0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0},
339 Color{0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0}};
340 std::vector<Scalar> stops = {
341 0.0, 2.0 / 62.0, 4.0 / 62.0, 8.0 / 62.0, 16.0 / 62.0, 32.0 / 62.0, 1.0,
345 {0, 0}, {200, 200}, std::move(colors), std::move(stops), tile_mode, {});
350 ASSERT_TRUE(OpenPlaygroundHere(
callback));
359 {200, 200}, {400, 400},
363 {0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0},
365 .mask_blur_descriptor =
380 const char* tile_mode_names[] = {
"Clamp",
"Repeat",
"Mirror",
"Decal"};
385 static int selected_tile_mode = 0;
393 ImGuiWindowFlags_AlwaysAutoResize)) {
394 ImGui::Combo(
"Tile mode", &selected_tile_mode, tile_mode_names,
395 sizeof(tile_mode_names) /
sizeof(
char*));
396 std::string label =
"##1";
397 for (
int i = 0; i < 4; i++) {
398 ImGui::InputScalarN(label.c_str(), ImGuiDataType_Float,
399 &(matrix.vec[i]), 4, NULL, NULL,
"%.2f", 0);
408 auto tile_mode = tile_modes[selected_tile_mode];
410 std::vector<Color> colors = {
Color{0.9568, 0.2627, 0.2118, 1.0},
411 Color{0.1294, 0.5882, 0.9529, 1.0}};
412 std::vector<Scalar> stops = {0.0, 1.0};
415 {100, 100}, 100, std::move(colors), std::move(stops), tile_mode, {});
420 ASSERT_TRUE(OpenPlaygroundHere(
callback));
425 const char* tile_mode_names[] = {
"Clamp",
"Repeat",
"Mirror",
"Decal"};
430 static int selected_tile_mode = 0;
438 ImGuiWindowFlags_AlwaysAutoResize)) {
439 ImGui::Combo(
"Tile mode", &selected_tile_mode, tile_mode_names,
440 sizeof(tile_mode_names) /
sizeof(
char*));
441 std::string label =
"##1";
442 for (
int i = 0; i < 4; i++) {
443 ImGui::InputScalarN(label.c_str(), ImGuiDataType_Float,
444 &(matrix.vec[i]), 4, NULL, NULL,
"%.2f", 0);
453 auto tile_mode = tile_modes[selected_tile_mode];
455 std::vector<Color> colors = {
456 Color{0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0},
457 Color{0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0},
458 Color{0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0},
459 Color{0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0},
460 Color{0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0},
461 Color{0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0},
462 Color{0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0}};
463 std::vector<Scalar> stops = {
474 {100, 100}, 100, std::move(colors), std::move(stops), tile_mode, {});
479 ASSERT_TRUE(OpenPlaygroundHere(
callback));
485 canvas.
Scale(aiks_test->GetContentScale());
489 std::vector<Color> colors = {Color{0.9568, 0.2627, 0.2118, 1.0},
490 Color{0.1294, 0.5882, 0.9529, 1.0}};
491 std::vector<Scalar> stops = {0.0, 1.0};
495 std::move(stops), tile_mode, {});
516void CanRenderSweepGradientManyColors(
AiksTest* aiks_test,
522 std::vector<Color> colors = {
523 Color{0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0},
524 Color{0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0},
525 Color{0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0},
526 Color{0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0},
527 Color{0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0},
528 Color{0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0},
529 Color{0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0}};
530 std::vector<Scalar> stops = {
542 std::move(stops), tile_mode, {});
572 std::vector<Scalar> stops = {0.0, 1.f / 3.f, 2.f / 3.f, 1.0};
573 std::array<std::tuple<Point, float, Point, float>, 8> array{
574 std::make_tuple(
Point{size / 2.f, size / 2.f}, 0.f,
575 Point{size / 2.f, size / 2.f}, size / 2.f),
576 std::make_tuple(
Point{size / 2.f, size / 2.f}, size / 4.f,
577 Point{size / 2.f, size / 2.f}, size / 2.f),
578 std::make_tuple(
Point{size / 4.f, size / 4.f}, 0.f,
579 Point{size / 2.f, size / 2.f}, size / 2.f),
580 std::make_tuple(
Point{size / 4.f, size / 4.f}, size / 2.f,
581 Point{size / 2.f, size / 2.f}, 0),
582 std::make_tuple(
Point{size / 4.f, size / 4.f}, size / 4.f,
583 Point{size / 2.f, size / 2.f}, size / 2.f),
584 std::make_tuple(
Point{size / 4.f, size / 4.f}, size / 16.f,
585 Point{size / 2.f, size / 2.f}, size / 8.f),
586 std::make_tuple(
Point{size / 4.f, size / 4.f}, size / 8.f,
587 Point{size / 2.f, size / 2.f}, size / 16.f),
588 std::make_tuple(
Point{size / 8.f, size / 8.f}, size / 8.f,
589 Point{size / 2.f, size / 2.f}, size / 8.f),
591 for (
int i = 0; i < 8; i++) {
593 canvas.
Translate({(i % 3) * size, i / 3 * size, 0});
595 std::get<0>(array[i]), std::get<1>(array[i]), colors, stops,
609 std::vector<Scalar> stops = {0.0, 1.f / 3.f, 2.f / 3.f, 1.0};
611 std::array<ColorSource, 3> color_sources = {
625 for (
int i = 0; i < 3; i++) {
628 paint.color_source = color_sources[i];
635#define APPLY_COLOR_FILTER_GRADIENT_TEST(name) \
636 TEST_P(AiksTest, name##GradientApplyColorFilter) { \
637 auto contents = name##GradientContents(); \
638 contents.SetColors({Color::CornflowerBlue().WithAlpha(0.75)}); \
639 auto result = contents.ApplyColorFilter([](const Color& color) { \
640 return color.Blend(Color::LimeGreen().WithAlpha(0.75), \
641 BlendMode::kScreen); \
643 ASSERT_TRUE(result); \
645 std::vector<Color> expected = {Color(0.433247, 0.879523, 0.825324, 0.75)}; \
646 ASSERT_COLORS_NEAR(contents.GetColors(), expected); \
657 static float scale = 3;
658 static bool add_circle_clip =
true;
659 const char* tile_mode_names[] = {
"Clamp",
"Repeat",
"Mirror",
"Decal"};
663 static int selected_tile_mode = 0;
664 static float alpha = 1;
667 ImGuiWindowFlags_AlwaysAutoResize)) {
668 ImGui::SliderFloat(
"Scale", &
scale, 0, 6);
669 ImGui::Checkbox(
"Circle clip", &add_circle_clip);
670 ImGui::SliderFloat(
"Alpha", &alpha, 0, 1);
671 ImGui::Combo(
"Tile mode", &selected_tile_mode, tile_mode_names,
672 sizeof(tile_mode_names) /
sizeof(
char*));
677 canvas.
Scale(GetContentScale());
684 paint.stroke_width = 10;
685 auto tile_mode = tile_modes[selected_tile_mode];
687 std::vector<Color> colors = {
Color{0.9568, 0.2627, 0.2118, 1.0},
688 Color{0.1294, 0.5882, 0.9529, 1.0}};
689 std::vector<Scalar> stops = {0.0, 1.0};
692 {0, 0}, {50, 50}, std::move(colors), std::move(stops), tile_mode, {});
696 .QuadraticCurveTo({60, 20}, {60, 60})
699 .QuadraticCurveTo({60, 60}, {20, 60})
704 if (add_circle_clip) {
709 auto [handle_a, handle_b] =
713 Point point_a = screen_to_canvas * handle_a * GetContentScale();
714 Point point_b = screen_to_canvas * handle_b * GetContentScale();
716 Point middle = (point_a + point_b) / 2;
722 paint.stroke_join = join;
724 paint.stroke_cap = cap;
734 ASSERT_TRUE(OpenPlaygroundHere(
callback));
#define APPLY_COLOR_FILTER_GRADIENT_TEST(name)
bool OpenPlaygroundHere(Picture picture)
static bool ImGuiBegin(const char *name, bool *p_open, ImGuiWindowFlags flags)
const Matrix & GetCurrentTransform() const
void ClipPath(const Path &path, Entity::ClipOperation clip_op=Entity::ClipOperation::kIntersect)
void DrawPaint(const Paint &paint)
void Scale(const Vector2 &scale)
Picture EndRecordingAsPicture()
void DrawPath(const Path &path, const Paint &paint)
virtual void Save(uint32_t total_content_depth=kMaxDepth)
void DrawRect(const Rect &rect, const Paint &paint)
void Translate(const Vector3 &offset)
void DrawCircle(const Point ¢er, Scalar radius, const Paint &paint)
static std::shared_ptr< ColorFilter > MakeBlend(BlendMode blend_mode, Color color)
static ColorSource MakeLinearGradient(Point start_point, Point end_point, std::vector< Color > colors, std::vector< Scalar > stops, Entity::TileMode tile_mode, Matrix effect_transform)
static ColorSource MakeRadialGradient(Point center, Scalar radius, std::vector< Color > colors, std::vector< Scalar > stops, Entity::TileMode tile_mode, Matrix effect_transform)
static ColorSource MakeSweepGradient(Point center, Degrees start_angle, Degrees end_angle, std::vector< Color > colors, std::vector< Scalar > stops, Entity::TileMode tile_mode, Matrix effect_transform)
static ColorSource MakeConicalGradient(Point center, Scalar radius, std::vector< Color > colors, std::vector< Scalar > stops, Point focus_center, Scalar focus_radius, Entity::TileMode tile_mode, Matrix effect_transform)
@ kNormal
Blurred inside and outside.
Path TakePath(FillType fill=FillType::kNonZero)
PathBuilder & MoveTo(Point point, bool relative=false)
PathBuilder & AddCircle(const Point ¢er, Scalar radius)
Paths are lightweight objects that describe a collection of linear, quadratic, or cubic segments....
Point GetContentScale() const
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
PODArray< SkColor > colors
impeller::Degrees Degrees
static void CanRenderLinearGradientWithDithering(AiksTest *aiks_test, bool use_dithering)
static void CanRenderRadialGradientWithDithering(AiksTest *aiks_test, bool use_dithering)
static void CanRenderSweepGradientWithDithering(AiksTest *aiks_test, bool use_dithering)
static void CanRenderConicalGradientWithDithering(AiksTest *aiks_test, bool use_dithering)
TEST_P(AiksTest, CanRenderAdvancedBlendColorFilterWithSaveLayer)
std::tuple< Point, Point > DrawPlaygroundLine(PlaygroundPoint &point_a, PlaygroundPoint &point_b)
void Close(PathBuilder *builder)
static constexpr Color White()
static constexpr Color Red()
static constexpr Color MakeRGBA8(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
static constexpr Color Green()
A 4x4 matrix using column-major storage.
FilterContents::BlurStyle style
In filters that use Gaussian distributions, "sigma" is a size of one standard deviation in terms of t...
constexpr Type GetDistance(const TPoint &p) const
static constexpr TRect MakeXYWH(Type x, Type y, Type width, Type height)
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)