Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 44 additions & 12 deletions impeller/aiks/aiks_blend_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,14 @@ TEST_P(AiksTest, ClearBlend) {
static Picture BlendModeTest(Vector2 content_scale,
BlendMode blend_mode,
const std::shared_ptr<Image>& src_image,
const std::shared_ptr<Image>& dst_image) {
const std::shared_ptr<Image>& dst_image,
Scalar src_alpha) {
if (AiksTest::ImGuiBegin("Controls", nullptr,
ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::SliderFloat("Source alpha", &src_alpha, 0, 1);
ImGui::End();
}

Color destination_color = Color::CornflowerBlue().WithAlpha(0.75);
auto source_colors = std::vector<Color>({Color::White().WithAlpha(0.75),
Color::LimeGreen().WithAlpha(0.75),
Expand Down Expand Up @@ -456,8 +463,15 @@ static Picture BlendModeTest(Vector2 content_scale,
canvas.Save();
canvas.SaveLayer({.blend_mode = BlendMode::kSourceOver});
{
canvas.DrawImage(dst_image, {0, 0}, {.blend_mode = BlendMode::kSourceOver});
canvas.DrawImage(src_image, {0, 0}, {.blend_mode = blend_mode});
canvas.DrawImage(dst_image, {0, 0},
{
.blend_mode = BlendMode::kSourceOver,
});
canvas.DrawImage(src_image, {0, 0},
{
.color = Color::White().WithAlpha(src_alpha),
.blend_mode = blend_mode,
});
}
canvas.Restore();
canvas.Restore();
Expand All @@ -468,7 +482,8 @@ static Picture BlendModeTest(Vector2 content_scale,
{
canvas.DrawImage(dst_image, {400, 0},
{.blend_mode = BlendMode::kSourceOver});
canvas.SaveLayer({.blend_mode = blend_mode});
canvas.SaveLayer({.color = Color::White().WithAlpha(src_alpha),
.blend_mode = blend_mode});
{
canvas.DrawImage(src_image, {400, 0},
{.blend_mode = BlendMode::kSourceOver});
Expand All @@ -481,17 +496,34 @@ static Picture BlendModeTest(Vector2 content_scale,
return canvas.EndRecordingAsPicture();
}

#define BLEND_MODE_TEST(blend_mode) \
TEST_P(AiksTest, BlendMode##blend_mode) { \
auto src_image = std::make_shared<Image>( \
CreateTextureForFixture("blend_mode_src.png")); \
auto dst_image = std::make_shared<Image>( \
CreateTextureForFixture("blend_mode_dst.png")); \
OpenPlaygroundHere(BlendModeTest( \
GetContentScale(), BlendMode::k##blend_mode, src_image, dst_image)); \
#define BLEND_MODE_TEST(blend_mode) \
TEST_P(AiksTest, BlendMode##blend_mode) { \
auto src_image = std::make_shared<Image>( \
CreateTextureForFixture("blend_mode_src.png")); \
auto dst_image = std::make_shared<Image>( \
CreateTextureForFixture("blend_mode_dst.png")); \
auto callback = [&](AiksContext& renderer) -> std::optional<Picture> { \
return BlendModeTest(GetContentScale(), BlendMode::k##blend_mode, \
src_image, dst_image, /*src_alpha=*/1.0); \
}; \
OpenPlaygroundHere(callback); \
}
IMPELLER_FOR_EACH_BLEND_MODE(BLEND_MODE_TEST)

#define BLEND_MODE_SRC_ALPHA_TEST(blend_mode) \
TEST_P(AiksTest, BlendModeSrcAlpha##blend_mode) { \
auto src_image = std::make_shared<Image>( \
CreateTextureForFixture("blend_mode_src.png")); \
auto dst_image = std::make_shared<Image>( \
CreateTextureForFixture("blend_mode_dst.png")); \
auto callback = [&](AiksContext& renderer) -> std::optional<Picture> { \
return BlendModeTest(GetContentScale(), BlendMode::k##blend_mode, \
src_image, dst_image, /*src_alpha=*/0.5); \
}; \
OpenPlaygroundHere(callback); \
}
IMPELLER_FOR_EACH_BLEND_MODE(BLEND_MODE_SRC_ALPHA_TEST)

TEST_P(AiksTest, CanDrawPaintMultipleTimesInteractive) {
auto modes = GetBlendModeSelection();

Expand Down
1 change: 1 addition & 0 deletions impeller/entity/shaders/blending/framebuffer_blend.frag
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ void main() {
int nblend_type = int(blend_type);

if (nblend_type == /*BlendSelectValues::kPlusAdvanced*/ 14) {
premultiplied_src *= frag_info.src_input_alpha;
frag_color = IPHalfPlusBlend(premultiplied_src, premultiplied_dst);
} else {
f16vec4 dst = IPHalfUnpremultiply(premultiplied_dst);
Expand Down