5#include "flutter/impeller/aiks/aiks_unittests.h"
13#include "third_party/imgui/imgui.h"
29 .sigma =
Sigma(99999),
46 .mask_blur_descriptor =
67 .mask_blur_descriptor =
99 ASSERT_TRUE(OpenPlaygroundHere(
callback));
165 ASSERT_TRUE(OpenPlaygroundHere(
callback));
203 canvas.
Scale(GetContentScale());
207 .mask_blur_descriptor =
210 .sigma =
Sigma(47.6),
219 canvas.
Scale(GetContentScale());
225 paint.stroke_width = 5;
235 for (
int x = 0;
x < 5; ++
x) {
236 for (
int y = 0;
y < 5; ++
y) {
244 std::shared_ptr<Texture>
texture =
245 picture.ToImage(renderer,
ISize{100, 100})->GetTexture();
262 paint_lines(300, 300,
272 .mask_blur_descriptor =
307 paint.mask_blur_descriptor->style = config.
style;
314 const Scalar radius = 20.0f;
315 const Scalar y_spacing = 100.0f;
320 radius, 60.0f - radius),
330 radius, 60.0f - radius),
342 {radius, 5.0f},
paint);
370 {
"NormalTranslucentZeroSigma",
375 {
"NormalTranslucent",
388 {
"SolidTranslucentWithFilters",
396 .invert_colors =
true}},
398 {
"SolidTranslucentExclusionBlend",
409 {
"InnerTranslucentWithBlurImageFilter",
423 {
"OuterOpaqueWithBlurImageFilter",
432#define MASK_BLUR_VARIANT_TEST(config) \
433 TEST_P(AiksTest, MaskBlurVariantTest##config) { \
434 ASSERT_TRUE(OpenPlaygroundHere( \
435 MaskBlurVariantTest(*this, kPaintVariations.at(#config)))); \
449#undef MASK_BLUR_VARIANT_TEST
454 canvas.
Scale(GetContentScale());
472 canvas.
Scale(GetContentScale());
473 std::shared_ptr<Texture> boston = CreateTextureForFixture(
"boston.jpg");
475 std::make_shared<Image>(boston),
476 Rect::MakeXYWH(0, 0, boston->GetSize().width, boston->GetSize().height),
489#define FLT_FORWARD(mock, real, method) \
490 EXPECT_CALL(*mock, method()) \
491 .WillRepeatedly(::testing::Return(real->method()));
496 "This backend doesn't yet support setting device capabilities.");
498 if (!WillRenderSomething()) {
502 GTEST_SKIP_(
"This test requires playgrounds.");
505 std::shared_ptr<const Capabilities> old_capabilities =
506 GetContext()->GetCapabilities();
507 auto mock_capabilities = std::make_shared<MockCapabilities>();
508 EXPECT_CALL(*mock_capabilities, SupportsDecalSamplerAddressMode())
509 .Times(::testing::AtLeast(1))
510 .WillRepeatedly(::testing::Return(
false));
511 FLT_FORWARD(mock_capabilities, old_capabilities, GetDefaultColorFormat);
512 FLT_FORWARD(mock_capabilities, old_capabilities, GetDefaultStencilFormat);
514 GetDefaultDepthStencilFormat);
515 FLT_FORWARD(mock_capabilities, old_capabilities, SupportsOffscreenMSAA);
517 SupportsImplicitResolvingMSAA);
518 FLT_FORWARD(mock_capabilities, old_capabilities, SupportsReadFromResolve);
519 FLT_FORWARD(mock_capabilities, old_capabilities, SupportsFramebufferFetch);
520 FLT_FORWARD(mock_capabilities, old_capabilities, SupportsSSBO);
521 FLT_FORWARD(mock_capabilities, old_capabilities, SupportsCompute);
523 SupportsTextureToTextureBlits);
524 FLT_FORWARD(mock_capabilities, old_capabilities, GetDefaultGlyphAtlasFormat);
525 ASSERT_TRUE(SetCapabilities(mock_capabilities).
ok());
527 auto texture = std::make_shared<Image>(CreateTextureForFixture(
"boston.jpg"));
529 canvas.
Scale(GetContentScale() * 0.5);
544 canvas.
Scale(GetContentScale());
545 canvas.
Scale({0.5, 0.5, 1.0});
546 std::shared_ptr<Texture> boston = CreateTextureForFixture(
"boston.jpg");
562 std::shared_ptr<Texture> boston = CreateTextureForFixture(
"boston.jpg");
564 Rect::MakeXYWH(0, 0, boston->GetSize().width, boston->GetSize().height);
572 canvas.
Scale(GetContentScale());
576 canvas.
Scale({0.6, 0.6, 1});
579 canvas.
DrawImageRect(std::make_shared<Image>(boston), bounds,
580 bounds.Shift(-image_center),
paint);
587 std::shared_ptr<Texture> boston = CreateTextureForFixture(
"boston.jpg");
589 Rect::MakeXYWH(0, 0, boston->GetSize().width, boston->GetSize().height);
597 canvas.
Scale(GetContentScale());
601 canvas.
Scale({0.6, 0.6, 1});
603 canvas.
DrawImageRect(std::make_shared<Image>(boston), bounds,
604 bounds.Shift(-image_center),
paint);
610 std::shared_ptr<Texture> boston = CreateTextureForFixture(
"boston.jpg");
613 const char* tile_mode_names[] = {
"Clamp",
"Repeat",
"Mirror",
"Decal"};
618 static float rotation = 0;
619 static float scale = 0.6;
620 static int selected_tile_mode = 3;
623 ImGuiWindowFlags_AlwaysAutoResize)) {
624 ImGui::SliderFloat(
"Rotation (degrees)", &rotation, -180, 180);
625 ImGui::SliderFloat(
"Scale", &
scale, 0, 2.0);
626 ImGui::Combo(
"Tile mode", &selected_tile_mode, tile_mode_names,
627 sizeof(tile_mode_names) /
sizeof(
char*));
633 Rect::MakeXYWH(0, 0, boston->GetSize().width, boston->GetSize().height);
638 tile_modes[selected_tile_mode])};
643 canvas.
Scale(GetContentScale());
650 canvas.
DrawImageRect(std::make_shared<Image>(boston), bounds,
651 bounds.Shift(-image_center),
paint);
655 ASSERT_TRUE(OpenPlaygroundHere(
callback));
662 for (int32_t i = 1; i < 5; ++i) {
668 .
LineTo({100.f + fi, 100.f + fi})
676 std::shared_ptr<RenderTargetCache> cache =
677 std::make_shared<RenderTargetCache>(
678 GetContext()->GetResourceAllocator());
679 AiksContext aiks_context(GetContext(),
nullptr, cache);
680 std::shared_ptr<Image>
image = picture.ToImage(aiks_context, {1024, 768});
689 for (int32_t i = 0; i < 5; ++i) {
705 std::shared_ptr<RenderTargetCache> cache =
706 std::make_shared<RenderTargetCache>(
707 GetContext()->GetResourceAllocator());
708 AiksContext aiks_context(GetContext(),
nullptr, cache);
709 std::shared_ptr<Image>
image = picture.ToImage(aiks_context, {1024, 768});
719 auto boston = std::make_shared<Image>(
720 CreateTextureForFixture(
"boston.jpg",
true));
728 ImGuiWindowFlags_AlwaysAutoResize)) {
729 ImGui::SliderFloat(
"Sigma", &sigma, 0, 200);
730 ImGui::SliderFloat(
"Frequency", &freq, 0.01, 2.0);
731 ImGui::SliderFloat(
"Amplitude", &, 1, 100);
736 canvas.
Scale(GetContentScale());
739 Point(1024 / 2 - boston->GetSize().width / 2,
740 (768 / 2 - boston->GetSize().height / 2) +
y),
755 ASSERT_TRUE(OpenPlaygroundHere(
callback));
760 canvas.
Scale(GetContentScale());
764 std::vector<Color> colors = {
Color{0.9568, 0.2627, 0.2118, 1.0},
765 Color{0.7568, 0.2627, 0.2118, 1.0}};
766 std::vector<Scalar> stops = {0.0, 1.0};
770 {0, 0}, {200, 200}, std::move(colors), std::move(stops),
793 canvas.
Scale(GetContentScale());
797 std::vector<Color> colors = {
Color{0.9568, 0.2627, 0.2118, 1.0},
798 Color{0.7568, 0.2627, 0.2118, 1.0}};
799 std::vector<Scalar> stops = {0.0, 1.0};
803 {0, 0}, {200, 200}, std::move(colors), std::move(stops),
826 canvas.
Scale(GetContentScale());
830 std::vector<Color> colors = {
Color{0.9568, 0.2627, 0.2118, 1.0},
831 Color{0.7568, 0.2627, 0.2118, 1.0}};
832 std::vector<Scalar> stops = {0.0, 1.0};
836 {0, 0}, {200, 200}, std::move(colors), std::move(stops),
859 canvas.
Scale(GetContentScale());
887 canvas.
Scale(GetContentScale());
915 canvas.
Scale(GetContentScale());
945 ImGuiWindowFlags_AlwaysAutoResize)) {
946 ImGui::SliderFloat(
"Sigma", &sigma, 0, 500);
950 canvas.
Scale(GetContentScale());
955 .sigma =
Sigma(sigma),
957 std::shared_ptr<Texture> boston = CreateTextureForFixture(
"boston.jpg");
958 canvas.
DrawImage(std::make_shared<Image>(boston), {200, 200},
paint);
964 ASSERT_TRUE(OpenPlaygroundHere(
callback));
992 ASSERT_TRUE(OpenPlaygroundHere(
callback));
1005 EXPECT_EQ(4, picture.pass->GetRequiredMipCount());
1009 size_t blur_required_mip_count =
1021 std::shared_ptr<RenderTargetCache> cache =
1022 std::make_shared<RenderTargetCache>(GetContext()->GetResourceAllocator());
1023 AiksContext aiks_context(GetContext(),
nullptr, cache);
1024 picture.ToImage(aiks_context, {100, 100});
1026 size_t max_mip_count = 0;
1027 for (
auto it = cache->GetRenderTargetDataBegin();
1028 it != cache->GetRenderTargetDataEnd(); ++it) {
1029 max_mip_count = std::max(it->config.mip_count, max_mip_count);
1031 EXPECT_EQ(max_mip_count, blur_required_mip_count);
1036 size_t blur_required_mip_count =
1050 std::shared_ptr<RenderTargetCache> cache =
1051 std::make_shared<RenderTargetCache>(GetContext()->GetResourceAllocator());
1052 AiksContext aiks_context(GetContext(),
nullptr, cache);
1053 picture.ToImage(aiks_context, {100, 100});
1055 size_t max_mip_count = 0;
1056 for (
auto it = cache->GetRenderTargetDataBegin();
1057 it != cache->GetRenderTargetDataEnd(); ++it) {
1058 max_mip_count = std::max(it->config.mip_count, max_mip_count);
1060 EXPECT_EQ(max_mip_count, blur_required_mip_count);
1074 size_t blur_required_mip_count =
1085 std::shared_ptr<RenderTargetCache> cache =
1086 std::make_shared<RenderTargetCache>(GetContext()->GetResourceAllocator());
1087 AiksContext aiks_context(GetContext(),
nullptr, cache);
1088 picture.ToImage(aiks_context, {1024, 768});
1090 size_t max_mip_count = 0;
1091 for (
auto it = cache->GetRenderTargetDataBegin();
1092 it != cache->GetRenderTargetDataEnd(); ++it) {
1093 max_mip_count = std::max(it->config.mip_count, max_mip_count);
1095 EXPECT_EQ(max_mip_count, blur_required_mip_count);
1109 size_t blur_required_mip_count =
1126 std::shared_ptr<RenderTargetCache> cache =
1127 std::make_shared<RenderTargetCache>(GetContext()->GetResourceAllocator());
1128 AiksContext aiks_context(GetContext(),
nullptr, cache);
1129 picture.ToImage(aiks_context, {1024, 768});
1131 size_t max_mip_count = 0;
1132 for (
auto it = cache->GetRenderTargetDataBegin();
1133 it != cache->GetRenderTargetDataEnd(); ++it) {
1134 max_mip_count = std::max(it->config.mip_count, max_mip_count);
1136 EXPECT_EQ(max_mip_count, blur_required_mip_count);
1153 ImGuiWindowFlags_AlwaysAutoResize)) {
1154 ImGui::SliderFloat(
"Sigma", &sigma, 0, 500);
1158 canvas.
Scale(GetContentScale());
1161 std::shared_ptr<Texture> boston = CreateTextureForFixture(
"boston.jpg");
1168 .color_source = image_source,
1169 .mask_blur_descriptor =
1172 .sigma =
Sigma(sigma),
1176 Rect::MakeXYWH(0, 0, boston->GetSize().width, boston->GetSize().height),
1181 ASSERT_TRUE(OpenPlaygroundHere(
callback));
static bool ok(int result)
static SkScalar center(float pos0, float pos1)
#define FLT_FORWARD(mock, real, method)
#define MASK_BLUR_VARIANT_TEST(config)
static bool ImGuiBegin(const char *name, bool *p_open, ImGuiWindowFlags flags)
void DrawImageRect(const std::shared_ptr< Image > &image, Rect source, Rect dest, const Paint &paint, SamplerDescriptor sampler={}, SourceRectConstraint src_rect_constraint=SourceRectConstraint::kFast)
virtual void SaveLayer(const Paint &paint, std::optional< Rect > bounds=std::nullopt, const std::shared_ptr< ImageFilter > &backdrop_filter=nullptr, ContentBoundsPromise bounds_promise=ContentBoundsPromise::kUnknown, uint32_t total_content_depth=kMaxDepth)
void DrawOval(const Rect &rect, const Paint &paint)
void ClipRRect(const Rect &rect, const Size &corner_radii, Entity::ClipOperation clip_op=Entity::ClipOperation::kIntersect)
void Transform(const Matrix &transform)
void DrawImage(const std::shared_ptr< Image > &image, Point offset, const Paint &paint, SamplerDescriptor sampler={})
void Rotate(Radians radians)
void DrawPaint(const Paint &paint)
void ClipRect(const Rect &rect, Entity::ClipOperation clip_op=Entity::ClipOperation::kIntersect)
void Scale(const Vector2 &scale)
Picture EndRecordingAsPicture()
void DrawPath(const Path &path, const Paint &paint)
void DrawRect(const Rect &rect, const Paint &paint)
void DrawRRect(const Rect &rect, const Size &corner_radii, 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 MakeImage(std::shared_ptr< Texture > texture, Entity::TileMode x_tile_mode, Entity::TileMode y_tile_mode, SamplerDescriptor sampler_descriptor, Matrix effect_transform)
@ kNormal
Blurred inside and outside.
@ kOuter
Nothing inside, blurred outside.
@ kInner
Blurred inside, nothing outside.
@ kSolid
Solid inside, blurred outside.
static std::string_view kNoMipsError
static std::shared_ptr< ImageFilter > MakeBlur(Sigma sigma_x, Sigma sigma_y, FilterContents::BlurStyle blur_style, Entity::TileMode tile_mode)
Path TakePath(FillType fill=FillType::kNonZero)
PathBuilder & AddArc(const Rect &oval_bounds, Radians start, Radians sweep, bool use_center=false)
PathBuilder & MoveTo(Point point, bool relative=false)
PathBuilder & AddLine(const Point &p1, const Point &p2)
Move to point p1, then insert a line from p1 to p2.
Point GetContentScale() const
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
static void draw_line(SkCanvas *canvas, SkImage *, const SkRect &r, sk_sp< SkImageFilter > imf)
static const std::map< std::string, MaskBlurTestConfig > kPaintVariations
static Picture MaskBlurVariantTest(const AiksTest &test_context, const MaskBlurTestConfig &config)
TEST_P(AiksTest, CanRenderAdvancedBlendColorFilterWithSaveLayer)
Point DrawPlaygroundPoint(PlaygroundPoint &point)
std::tuple< Point, Point > DrawPlaygroundLine(PlaygroundPoint &point_a, PlaygroundPoint &point_b)
void MoveTo(PathBuilder *builder, Scalar x, Scalar y)
void LineTo(PathBuilder *builder, Scalar x, Scalar y)
void Close(PathBuilder *builder)
static constexpr Color Crimson()
static constexpr Color Grey()
static constexpr Color LimeGreen()
static constexpr Color GreenYellow()
static constexpr Color Chartreuse()
static constexpr Color Black()
static constexpr Color CornflowerBlue()
static constexpr Color White()
static constexpr Color Magenta()
constexpr Color WithAlpha(Scalar new_alpha) const
static constexpr Color Maroon()
static constexpr Color OrangeRed()
static constexpr Color DarkGreen()
static constexpr Color Orange()
static constexpr Color Purple()
static constexpr Color Wheat()
static constexpr Color Red()
static constexpr Color AntiqueWhite()
static constexpr Color DarkMagenta()
static constexpr Color Yellow()
static constexpr Color Blue()
static constexpr Color Green()
static constexpr Matrix MakeTranslation(const Vector3 &t)
static constexpr Matrix MakeScale(const Vector3 &s)
FilterContents::BlurStyle style
std::optional< MaskBlurDescriptor > mask_blur_descriptor
For convolution filters, the "radius" is the size of the convolution kernel to use on the local space...
In filters that use Gaussian distributions, "sigma" is a size of one standard deviation in terms of t...
static constexpr TPoint< Type > MakeXY(Type x, Type y)
static constexpr TRect MakeXYWH(Type x, Type y, Type width, Type height)
constexpr TRect< T > Expand(T left, T top, T right, T bottom) const
Returns a rectangle with expanded edges. Negative expansion results in shrinking.
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
std::shared_ptr< ImageFilter > image_filter
FilterContents::BlurStyle style
#define EXPECT_TRUE(handle)