diff --git a/impeller/entity/contents/content_context.cc b/impeller/entity/contents/content_context.cc index f0910f52ecdbd..8a1a29c70160b 100644 --- a/impeller/entity/contents/content_context.cc +++ b/impeller/entity/contents/content_context.cc @@ -41,7 +41,7 @@ void ContentContextOptions::ApplyToPipelineDescriptor( case Entity::BlendMode::kSource: color0.dst_alpha_blend_factor = BlendFactor::kZero; color0.dst_color_blend_factor = BlendFactor::kZero; - color0.src_alpha_blend_factor = BlendFactor::kSourceAlpha; + color0.src_alpha_blend_factor = BlendFactor::kOne; color0.src_color_blend_factor = BlendFactor::kOne; break; case Entity::BlendMode::kDestination: diff --git a/impeller/entity/entity_unittests.cc b/impeller/entity/entity_unittests.cc index 1517bbd486fa2..2559ff8b77908 100644 --- a/impeller/entity/entity_unittests.cc +++ b/impeller/entity/entity_unittests.cc @@ -10,6 +10,7 @@ #include "impeller/entity/contents/filters/inputs/filter_input.h" #include "impeller/entity/contents/solid_color_contents.h" #include "impeller/entity/contents/solid_stroke_contents.h" +#include "impeller/entity/contents/texture_contents.h" #include "impeller/entity/contents/vertices_contents.h" #include "impeller/entity/entity.h" #include "impeller/entity/entity_pass.h" @@ -772,19 +773,18 @@ TEST_P(EntityTest, Filters) { } TEST_P(EntityTest, GaussianBlurFilter) { - auto bridge = CreateTextureForFixture("bay_bridge.jpg"); auto boston = CreateTextureForFixture("boston.jpg"); - auto kalimba = CreateTextureForFixture("kalimba.jpg"); - ASSERT_TRUE(bridge && boston && kalimba); + ASSERT_TRUE(boston); bool first_frame = true; auto callback = [&](ContentContext& context, RenderPass& pass) -> bool { if (first_frame) { first_frame = false; - ImGui::SetNextWindowSize({500, 250}); - ImGui::SetNextWindowPos({300, 500}); + ImGui::SetNextWindowSize({500, 290}); + ImGui::SetNextWindowPos({300, 480}); } + const char* input_type_names[] = {"Texture", "Solid Color"}; const char* blur_type_names[] = {"Image blur", "Mask blur"}; const char* blur_style_names[] = {"Normal", "Solid", "Outer", "Inner"}; const FilterContents::BlurStyle blur_styles[] = { @@ -792,6 +792,8 @@ TEST_P(EntityTest, GaussianBlurFilter) { FilterContents::BlurStyle::kOuter, FilterContents::BlurStyle::kInner}; // UI state. + static int selected_input_type = 0; + static Color input_color = Color::Black(); static int selected_blur_type = 0; static float blur_amount[2] = {20, 20}; static int selected_blur_style = 0; @@ -799,11 +801,19 @@ TEST_P(EntityTest, GaussianBlurFilter) { static Color bounds_color(0, 1, 0, 0.1); static float offset[2] = {500, 400}; static float rotation = 0; - static float scale[2] = {0.5, 0.5}; + static float scale[2] = {0.75, 0.75}; static float skew[2] = {0, 0}; ImGui::Begin("Controls"); { + ImGui::Combo("Input type", &selected_input_type, input_type_names, + sizeof(input_type_names) / sizeof(char*)); + if (selected_input_type == 0) { + ImGui::SliderFloat("Input opacity", &input_color.alpha, 0, 1); + } else { + ImGui::ColorEdit4("Input color", + reinterpret_cast(&input_color)); + } ImGui::Combo("Blur type", &selected_blur_type, blur_type_names, sizeof(blur_type_names) / sizeof(char*)); ImGui::SliderFloat2("Blur", &blur_amount[0], 0, 200); @@ -820,21 +830,39 @@ TEST_P(EntityTest, GaussianBlurFilter) { } ImGui::End(); - auto blend = - FilterContents::MakeBlend(Entity::BlendMode::kScreen, - FilterInput::Make({boston, bridge, kalimba})); + std::shared_ptr input; + Size input_size; + + if (selected_input_type == 0) { + auto texture = std::make_shared(); + auto input_rect = Rect::MakeSize(Size(boston->GetSize())); + texture->SetSourceRect(input_rect); + texture->SetPath(PathBuilder{}.AddRect(input_rect).TakePath()); + texture->SetTexture(boston); + texture->SetOpacity(input_color.alpha); + + input = texture; + input_size = input_rect.size; + } else { + auto fill = std::make_shared(); + auto input_rect = Rect::MakeSize(Size(boston->GetSize())); + fill->SetColor(input_color); + fill->SetPath(PathBuilder{}.AddRect(input_rect).TakePath()); + + input = fill; + input_size = input_rect.size; + } auto blur = FilterContents::MakeGaussianBlur( - FilterInput::Make(blend), FilterContents::Sigma{blur_amount[0]}, + FilterInput::Make(input), FilterContents::Sigma{blur_amount[0]}, FilterContents::Sigma{blur_amount[1]}, blur_styles[selected_blur_style]); auto mask_blur = FilterContents::MakeBorderMaskBlur( - FilterInput::Make(bridge), FilterContents::Sigma{blur_amount[0]}, + FilterInput::Make(input), FilterContents::Sigma{blur_amount[0]}, FilterContents::Sigma{blur_amount[1]}, blur_styles[selected_blur_style]); - auto input_size = bridge->GetSize(); auto ctm = Matrix::MakeScale(GetContentScale()) * Matrix::MakeTranslation(Vector3(offset[0], offset[1])) * Matrix::MakeRotationZ(Radians(rotation)) *