37#define BLEND_MODE_TUPLE(blend_mode) {#blend_mode, BlendMode::k##blend_mode},
45 std::vector<const char*> blend_mode_names;
46 std::vector<BlendMode> blend_mode_values;
48 const std::vector<std::tuple<const char*, BlendMode>> blends = {
50 assert(blends.size() ==
52 for (
const auto& [
name,
mode] : blends) {
53 blend_mode_names.push_back(
name);
54 blend_mode_values.push_back(
mode);
58 return {blend_mode_names, blend_mode_values};
70 builder.
SaveLayer(layer_rect, &save_paint);
79 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
104 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
110 builder.
Scale(0.2, 0.2);
122 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
139 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
151 std::vector<DlColor> colors = {
DlColor::RGBA(0.9568, 0.2627, 0.2118, 1.0),
153 std::vector<Scalar> stops = {0.0, 1.0};
169 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
194 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
199 bool has_color_filter =
true;
200 auto callback = [&]() -> sk_sp<DisplayList> {
201 if (IsPlaygroundEnabled()) {
202 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
203 ImGui::Checkbox(
"has color filter", &has_color_filter);
208 builder.
Scale(GetContentScale().
x, GetContentScale().
y);
215 std::vector<DlBlendMode> blend_modes = {
216 DlBlendMode::kSrc, DlBlendMode::kSrcATop, DlBlendMode::kSrcOver,
217 DlBlendMode::kSrcIn, DlBlendMode::kSrcOut, DlBlendMode::kDst,
218 DlBlendMode::kDstATop, DlBlendMode::kDstOver, DlBlendMode::kDstIn,
219 DlBlendMode::kDstOut, DlBlendMode::kClear, DlBlendMode::kXor};
221 for (uint32_t
i = 0;
i < blend_modes.size(); ++
i) {
224 builder.
Scale(0.4, 0.4);
228 DlImageSampling::kMipmapLinear, &dstPaint);
233 if (has_color_filter) {
234 std::shared_ptr<const DlColorFilter> color_filter =
236 DlBlendMode::kSrcIn);
240 DlImageSampling::kMipmapLinear, &srcPaint);
244 return builder.
Build();
246 ASSERT_TRUE(OpenPlaygroundHere(
callback));
251 bool has_color_filter =
true;
252 auto callback = [&]() -> sk_sp<DisplayList> {
253 if (IsPlaygroundEnabled()) {
254 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
255 ImGui::Checkbox(
"has color filter", &has_color_filter);
260 builder.
Scale(GetContentScale().
x, GetContentScale().
y);
267 std::vector<DlBlendMode> blend_modes = {
268 DlBlendMode::kScreen, DlBlendMode::kOverlay,
269 DlBlendMode::kDarken, DlBlendMode::kLighten,
270 DlBlendMode::kColorDodge, DlBlendMode::kColorBurn,
271 DlBlendMode::kHardLight, DlBlendMode::kSoftLight,
272 DlBlendMode::kDifference, DlBlendMode::kExclusion,
273 DlBlendMode::kMultiply, DlBlendMode::kHue,
274 DlBlendMode::kSaturation, DlBlendMode::kColor,
275 DlBlendMode::kLuminosity,
278 for (uint32_t
i = 0;
i < blend_modes.size(); ++
i) {
281 builder.
Scale(0.4, 0.4);
285 DlImageSampling::kMipmapLinear, &dstPaint);
290 if (has_color_filter) {
291 std::shared_ptr<const DlColorFilter> color_filter =
293 DlBlendMode::kSrcIn);
297 DlImageSampling::kMipmapLinear, &srcPaint);
301 return builder.
Build();
303 ASSERT_TRUE(OpenPlaygroundHere(
callback));
312 <<
"This backend doesn't yet support setting device capabilities.";
315 std::shared_ptr<const Capabilities> old_capabilities =
316 GetContext()->GetCapabilities();
317 auto mock_capabilities = std::make_shared<MockCapabilities>();
318 EXPECT_CALL(*mock_capabilities, SupportsFramebufferFetch())
319 .Times(::testing::AtLeast(1))
320 .WillRepeatedly(::testing::Return(
false));
321 FLT_FORWARD(mock_capabilities, old_capabilities, GetDefaultColorFormat);
322 FLT_FORWARD(mock_capabilities, old_capabilities, GetDefaultStencilFormat);
324 GetDefaultDepthStencilFormat);
325 FLT_FORWARD(mock_capabilities, old_capabilities, SupportsOffscreenMSAA);
327 SupportsImplicitResolvingMSAA);
328 FLT_FORWARD(mock_capabilities, old_capabilities, SupportsReadFromResolve);
329 FLT_FORWARD(mock_capabilities, old_capabilities, SupportsSSBO);
330 FLT_FORWARD(mock_capabilities, old_capabilities, SupportsCompute);
332 SupportsTextureToTextureBlits);
333 FLT_FORWARD(mock_capabilities, old_capabilities, GetDefaultGlyphAtlasFormat);
334 FLT_FORWARD(mock_capabilities, old_capabilities, SupportsTriangleFan);
336 SupportsDecalSamplerAddressMode);
337 FLT_FORWARD(mock_capabilities, old_capabilities, SupportsPrimitiveRestart);
338 FLT_FORWARD(mock_capabilities, old_capabilities, GetMinimumUniformAlignment);
339 ASSERT_TRUE(SetCapabilities(mock_capabilities).ok());
341 bool has_color_filter =
true;
342 auto callback = [&]() -> sk_sp<DisplayList> {
343 if (IsPlaygroundEnabled()) {
344 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
345 ImGui::Checkbox(
"has color filter", &has_color_filter);
350 builder.
Scale(GetContentScale().
x, GetContentScale().
y);
357 std::vector<DlBlendMode> blend_modes = {
358 DlBlendMode::kScreen, DlBlendMode::kOverlay,
359 DlBlendMode::kDarken, DlBlendMode::kLighten,
360 DlBlendMode::kColorDodge, DlBlendMode::kColorBurn,
361 DlBlendMode::kHardLight, DlBlendMode::kSoftLight,
362 DlBlendMode::kDifference, DlBlendMode::kExclusion,
363 DlBlendMode::kMultiply, DlBlendMode::kHue,
364 DlBlendMode::kSaturation, DlBlendMode::kColor,
365 DlBlendMode::kLuminosity,
368 for (uint32_t
i = 0;
i < blend_modes.size(); ++
i) {
371 builder.
Scale(0.4, 0.4);
375 DlImageSampling::kMipmapLinear, &dstPaint);
380 if (has_color_filter) {
381 std::shared_ptr<const DlColorFilter> color_filter =
383 DlBlendMode::kMultiply);
387 DlImageSampling::kMipmapLinear, &srcPaint);
391 return builder.
Build();
393 ASSERT_TRUE(OpenPlaygroundHere(
callback));
400 if (!EnsureContextSupportsWideGamut()) {
401 GTEST_SKIP() <<
"This backend doesn't yet support wide gamut.";
404 EXPECT_EQ(GetContext()->GetCapabilities()->GetDefaultColorFormat(),
406 auto texture = CreateTextureForFixture(
"airplane.jpg",
411 builder.
Scale(GetContentScale().
x, GetContentScale().
y);
428 rect.GetRight(), rect.GetBottom()),
429 DlImageSampling::kMipmapLinear, &paint);
431 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
438 if (!EnsureContextSupportsWideGamut()) {
439 GTEST_SKIP() <<
"This backend doesn't yet support wide gamut.";
442 EXPECT_EQ(GetContext()->GetCapabilities()->GetDefaultColorFormat(),
444 auto texture = CreateTextureForFixture(
"airplane.jpg",
448 builder.
Scale(GetContentScale().
x, GetContentScale().
y);
457 builder.
SaveLayer(std::nullopt, &save_paint);
469 rect.GetRight(), rect.GetBottom()),
470 DlImageSampling::kMipmapLinear, &paint);
473 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
482 builder.
SaveLayer(std::nullopt, &save_paint);
491 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
506 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
512 const sk_sp<DlImageImpeller>& src_image,
513 const sk_sp<DlImageImpeller>& dst_image,
516 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
517 ImGui::SliderFloat(
"Source alpha", &src_alpha, 0, 1);
530 builder.DrawPaint(paint);
541 for (
const auto& color : source_colors) {
548 builder.SaveLayer(std::nullopt);
553 destination_color.
blue, destination_color.
alpha));
554 builder.DrawPaint(draw_paint);
560 builder.SaveLayer(std::nullopt, &save_paint);
564 DlColor::RGBA(color.red, color.green, color.blue, color.alpha));
572 builder.Translate(100, 0);
574 builder.RestoreToCount(0);
581 builder.Translate(0, 100);
584 builder.SaveLayer(std::nullopt);
585 for (
const auto& color : source_colors) {
588 auto dest = destination_color.
Blend(color, blend_mode);
592 builder.Translate(100, 0);
604 builder.Translate(0, 250);
615 for (
int y = 0;
y < 400 / 8;
y++) {
616 for (
int x = 0;
x < 800 / 16;
x++) {
626 builder.SaveLayer(std::nullopt, &paint);
628 builder.DrawImage(dst_image,
DlPoint(0, 0), DlImageSampling::kMipmapLinear,
633 builder.DrawImage(src_image,
DlPoint(0, 0), DlImageSampling::kMipmapLinear,
643 builder.SaveLayer(std::nullopt, &save_paint);
645 builder.DrawImage(dst_image,
DlPoint(400, 0),
646 DlImageSampling::kMipmapLinear,
nullptr);
651 builder.SaveLayer(std::nullopt, &save_paint);
653 builder.DrawImage(src_image,
DlPoint(400, 0),
654 DlImageSampling::kMipmapLinear,
nullptr);
661 return builder.Build();
664#define BLEND_MODE_TEST(blend_mode) \
665 TEST_P(AiksTest, BlendMode##blend_mode) { \
667 DlImageImpeller::Make(CreateTextureForFixture("blend_mode_src.png")); \
669 DlImageImpeller::Make(CreateTextureForFixture("blend_mode_dst.png")); \
670 auto callback = [&]() -> sk_sp<DisplayList> { \
671 return BlendModeTest(this, GetContentScale(), BlendMode::k##blend_mode, \
672 src_image, dst_image, 1.0); \
674 OpenPlaygroundHere(callback); \
678#define BLEND_MODE_SRC_ALPHA_TEST(blend_mode) \
679 TEST_P(AiksTest, BlendModeSrcAlpha##blend_mode) { \
681 DlImageImpeller::Make(CreateTextureForFixture("blend_mode_src.png")); \
683 DlImageImpeller::Make(CreateTextureForFixture("blend_mode_dst.png")); \
684 auto callback = [&]() -> sk_sp<DisplayList> { \
685 return BlendModeTest(this, GetContentScale(), BlendMode::k##blend_mode, \
686 src_image, dst_image, 0.5); \
688 OpenPlaygroundHere(callback); \
695 auto callback = [&]() -> sk_sp<DisplayList> {
697 static Color foreground = Color::Color::OrangeRed().
WithAlpha(0.5);
698 static int current_blend_index = 3;
700 if (IsPlaygroundEnabled()) {
701 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
702 ImGui::ColorEdit4(
"Background",
reinterpret_cast<float*
>(&background));
703 ImGui::ColorEdit4(
"Foreground",
reinterpret_cast<float*
>(&foreground));
704 ImGui::ListBox(
"Blend mode", ¤t_blend_index,
705 modes.blend_mode_names.data(),
706 modes.blend_mode_names.size());
711 builder.
Scale(0.2, 0.2);
719 return builder.
Build();
721 ASSERT_TRUE(OpenPlaygroundHere(
callback));
725 auto texture = CreateTextureForFixture(
"airplane.jpg",
733 DlColor::RGBA(255.0f / 255.0f, 165.0f / 255.0f, 0.0f / 255.0f, 1.0f),
734 DlBlendMode::kSrcIn));
737 DlImageSampling::kMipmapLinear, &image_paint);
739 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
743 auto texture = CreateTextureForFixture(
"airplane.jpg",
751 DlColor::RGBA(255.0f / 255.0f, 165.0f / 255.0f, 0.0f / 255.0f, 1.0f),
752 DlBlendMode::kColorDodge));
755 DlImageSampling::kMipmapLinear, &image_paint);
757 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
761 auto texture = CreateTextureForFixture(
"airplane.jpg",
770 DlColor::RGBA(169.0f / 255.0f, 169.0f / 255.0f, 169.0f / 255.0f, 1.0f));
772 builder.
Scale(0.4, 0.4);
778 DlImageSampling::kMipmapLinear, &image_paint);
780 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
791 auto color_wheel_sampler = [](
Radians r) {
795 auto color_cycle = [](
Scalar x) {
796 Scalar cycle = std::fmod(
x, 6.0f);
797 return std::max(0.0f, std::min(1.0f, 2 - std::abs(2 - cycle)));
799 return Color(color_cycle(6 *
x + 1),
800 color_cycle(6 *
x - 1),
801 color_cycle(6 *
x - 3),
810 const int max_dist = 900;
811 for (
int i = 0;
i <= 900;
i++) {
814 Scalar normalized_distance =
static_cast<Scalar>(
i) / max_dist;
816 auto color = color_wheel_sampler(r).WithAlpha(1.0f - normalized_distance);
818 DlColor::RGBA(color.red, color.green, color.blue, color.alpha));
820 -distance * std::cos(r.
radians));
822 builder.DrawCircle(position, 9 + normalized_distance * 3, paint);
826 auto callback = [&]() -> sk_sp<DisplayList> {
828 static bool cache_the_wheel =
true;
829 static int current_blend_index = 3;
830 static float dst_alpha = 1;
831 static float src_alpha = 1;
836 if (IsPlaygroundEnabled()) {
837 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
838 ImGui::Checkbox(
"Cache the wheel", &cache_the_wheel);
839 ImGui::ListBox(
"Blending mode", ¤t_blend_index,
842 ImGui::SliderFloat(
"Source alpha", &src_alpha, 0, 1);
843 ImGui::ColorEdit4(
"Color A",
reinterpret_cast<float*
>(&color0));
844 ImGui::ColorEdit4(
"Color B",
reinterpret_cast<float*
>(&color1));
845 ImGui::ColorEdit4(
"Color C",
reinterpret_cast<float*
>(&color2));
846 ImGui::SliderFloat(
"Destination alpha", &dst_alpha, 0, 1);
861 builder.
SaveLayer(std::nullopt,
nullptr);
862 builder.
Scale(GetContentScale().
x, GetContentScale().
y);
865 draw_color_wheel(builder);
870 builder.
Scale(GetContentScale().
x, GetContentScale().
y);
879 builder.
SaveLayer(std::nullopt, &save_paint);
894 return builder.
Build();
897 ASSERT_TRUE(OpenPlaygroundHere(
callback));
910 builder.
SaveLayer(std::nullopt, &save_paint);
914 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
925 DlBlendMode::kSaturation));
926 builder.
SaveLayer(std::nullopt, &save_paint);
934 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
948 .setBlendMode(DlBlendMode::kDifference));
954 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
#define BLEND_MODE_TUPLE(blend_mode)
#define BLEND_MODE_SRC_ALPHA_TEST(blend_mode)
#define BLEND_MODE_TEST(blend_mode)
void ClipRect(const DlRect &rect, DlClipOp clip_op=DlClipOp::kIntersect, bool is_aa=false) override
void DrawImageRect(const sk_sp< DlImage > &image, const DlRect &src, const DlRect &dst, DlImageSampling sampling, const DlPaint *paint=nullptr, DlSrcRectConstraint constraint=DlSrcRectConstraint::kFast) override
void DrawImage(const sk_sp< DlImage > &image, const DlPoint &point, DlImageSampling sampling, const DlPaint *paint=nullptr) override
void DrawCircle(const DlPoint ¢er, DlScalar radius, const DlPaint &paint) override
void SaveLayer(const std::optional< DlRect > &bounds, const DlPaint *paint=nullptr, const DlImageFilter *backdrop=nullptr, std::optional< int64_t > backdrop_id=std::nullopt) override
void Rotate(DlScalar degrees) override
void Scale(DlScalar sx, DlScalar sy) override
void Translate(DlScalar tx, DlScalar ty) override
void DrawPaint(const DlPaint &paint) override
sk_sp< DisplayList > Build()
void DrawRect(const DlRect &rect, const DlPaint &paint) override
static std::shared_ptr< DlMaskFilter > Make(DlBlurStyle style, SkScalar sigma, bool respect_ctm=true)
static std::shared_ptr< const DlColorFilter > MakeBlend(DlColor color, DlBlendMode mode)
static std::shared_ptr< DlColorSource > MakeLinear(const DlPoint start_point, const DlPoint end_point, uint32_t stop_count, const DlColor *colors, const float *stops, DlTileMode tile_mode, const DlMatrix *matrix=nullptr)
DlPaint & setColor(DlColor color)
DlPaint & setBlendMode(DlBlendMode mode)
DlPaint & setMaskFilter(std::nullptr_t filter)
DlPaint & setOpacity(DlScalar opacity)
DlPaint & setColorFilter(std::nullptr_t filter)
DlPaint & setColorSource(std::nullptr_t source)
static sk_sp< DlImageImpeller > Make(std::shared_ptr< Texture > texture, OwningContext owning_context=OwningContext::kIO)
static constexpr BlendMode kLastAdvancedBlendMode
bool IsPlaygroundEnabled() const
#define IMPELLER_FOR_EACH_BLEND_MODE(V)
FlutterDesktopBinaryReply callback
#define FLT_FORWARD(mock, real, method)
DEF_SWITCHES_START aot vmservice shared library name
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
static sk_sp< DisplayList > BlendModeTest(AiksTest *test, Vector2 content_scale, BlendMode blend_mode, const sk_sp< DlImageImpeller > &src_image, const sk_sp< DlImageImpeller > &dst_image, Scalar src_alpha)
TEST_P(AiksTest, DrawAtlasNoColor)
static BlendModeSelection GetBlendModeSelection()
static constexpr DlColor kWhite()
static constexpr DlColor kBlue()
static constexpr DlColor RGBA(DlScalar r, DlScalar g, DlScalar b, DlScalar a)
Construct a 32 bit color from floating point R, G, B, and A color channels.
static constexpr DlColor kBlack()
static constexpr DlColor kMaroon()
static constexpr DlColor kTransparent()
static constexpr DlColor kRed()
static constexpr DlColor kGreen()
DlColor withAlpha(uint8_t alpha) const
uint32_t ToARGB() const
Convert to ARGB 32 bit color.
static constexpr Color LimeGreen()
static constexpr Color Black()
static constexpr Color CornflowerBlue()
static constexpr Color MediumTurquoise()
static constexpr Color White()
constexpr Color WithAlpha(Scalar new_alpha) const
static constexpr Color OrangeRed()
Color Blend(Color source, BlendMode blend_mode) const
Blends an unpremultiplied destination color into a given unpremultiplied source color to form a new u...
A 4x4 matrix using column-major storage.
static constexpr Matrix MakeScale(const Vector3 &s)
static constexpr TRect MakeWH(Type width, Type height)
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::vector< BlendMode > blend_mode_values
std::vector< const char * > blend_mode_names