Skip to content

Commit 1c22a58

Browse files
authored
Fix source blend (flutter#34066)
1 parent ae357ca commit 1c22a58

File tree

2 files changed

+41
-13
lines changed

2 files changed

+41
-13
lines changed

impeller/entity/contents/content_context.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void ContentContextOptions::ApplyToPipelineDescriptor(
4141
case Entity::BlendMode::kSource:
4242
color0.dst_alpha_blend_factor = BlendFactor::kZero;
4343
color0.dst_color_blend_factor = BlendFactor::kZero;
44-
color0.src_alpha_blend_factor = BlendFactor::kSourceAlpha;
44+
color0.src_alpha_blend_factor = BlendFactor::kOne;
4545
color0.src_color_blend_factor = BlendFactor::kOne;
4646
break;
4747
case Entity::BlendMode::kDestination:

impeller/entity/entity_unittests.cc

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "impeller/entity/contents/filters/inputs/filter_input.h"
1111
#include "impeller/entity/contents/solid_color_contents.h"
1212
#include "impeller/entity/contents/solid_stroke_contents.h"
13+
#include "impeller/entity/contents/texture_contents.h"
1314
#include "impeller/entity/contents/vertices_contents.h"
1415
#include "impeller/entity/entity.h"
1516
#include "impeller/entity/entity_pass.h"
@@ -772,38 +773,47 @@ TEST_P(EntityTest, Filters) {
772773
}
773774

774775
TEST_P(EntityTest, GaussianBlurFilter) {
775-
auto bridge = CreateTextureForFixture("bay_bridge.jpg");
776776
auto boston = CreateTextureForFixture("boston.jpg");
777-
auto kalimba = CreateTextureForFixture("kalimba.jpg");
778-
ASSERT_TRUE(bridge && boston && kalimba);
777+
ASSERT_TRUE(boston);
779778

780779
bool first_frame = true;
781780
auto callback = [&](ContentContext& context, RenderPass& pass) -> bool {
782781
if (first_frame) {
783782
first_frame = false;
784-
ImGui::SetNextWindowSize({500, 250});
785-
ImGui::SetNextWindowPos({300, 500});
783+
ImGui::SetNextWindowSize({500, 290});
784+
ImGui::SetNextWindowPos({300, 480});
786785
}
787786

787+
const char* input_type_names[] = {"Texture", "Solid Color"};
788788
const char* blur_type_names[] = {"Image blur", "Mask blur"};
789789
const char* blur_style_names[] = {"Normal", "Solid", "Outer", "Inner"};
790790
const FilterContents::BlurStyle blur_styles[] = {
791791
FilterContents::BlurStyle::kNormal, FilterContents::BlurStyle::kSolid,
792792
FilterContents::BlurStyle::kOuter, FilterContents::BlurStyle::kInner};
793793

794794
// UI state.
795+
static int selected_input_type = 0;
796+
static Color input_color = Color::Black();
795797
static int selected_blur_type = 0;
796798
static float blur_amount[2] = {20, 20};
797799
static int selected_blur_style = 0;
798800
static Color cover_color(1, 0, 0, 0.2);
799801
static Color bounds_color(0, 1, 0, 0.1);
800802
static float offset[2] = {500, 400};
801803
static float rotation = 0;
802-
static float scale[2] = {0.5, 0.5};
804+
static float scale[2] = {0.75, 0.75};
803805
static float skew[2] = {0, 0};
804806

805807
ImGui::Begin("Controls");
806808
{
809+
ImGui::Combo("Input type", &selected_input_type, input_type_names,
810+
sizeof(input_type_names) / sizeof(char*));
811+
if (selected_input_type == 0) {
812+
ImGui::SliderFloat("Input opacity", &input_color.alpha, 0, 1);
813+
} else {
814+
ImGui::ColorEdit4("Input color",
815+
reinterpret_cast<float*>(&input_color));
816+
}
807817
ImGui::Combo("Blur type", &selected_blur_type, blur_type_names,
808818
sizeof(blur_type_names) / sizeof(char*));
809819
ImGui::SliderFloat2("Blur", &blur_amount[0], 0, 200);
@@ -820,21 +830,39 @@ TEST_P(EntityTest, GaussianBlurFilter) {
820830
}
821831
ImGui::End();
822832

823-
auto blend =
824-
FilterContents::MakeBlend(Entity::BlendMode::kScreen,
825-
FilterInput::Make({boston, bridge, kalimba}));
833+
std::shared_ptr<Contents> input;
834+
Size input_size;
835+
836+
if (selected_input_type == 0) {
837+
auto texture = std::make_shared<TextureContents>();
838+
auto input_rect = Rect::MakeSize(Size(boston->GetSize()));
839+
texture->SetSourceRect(input_rect);
840+
texture->SetPath(PathBuilder{}.AddRect(input_rect).TakePath());
841+
texture->SetTexture(boston);
842+
texture->SetOpacity(input_color.alpha);
843+
844+
input = texture;
845+
input_size = input_rect.size;
846+
} else {
847+
auto fill = std::make_shared<SolidColorContents>();
848+
auto input_rect = Rect::MakeSize(Size(boston->GetSize()));
849+
fill->SetColor(input_color);
850+
fill->SetPath(PathBuilder{}.AddRect(input_rect).TakePath());
851+
852+
input = fill;
853+
input_size = input_rect.size;
854+
}
826855

827856
auto blur = FilterContents::MakeGaussianBlur(
828-
FilterInput::Make(blend), FilterContents::Sigma{blur_amount[0]},
857+
FilterInput::Make(input), FilterContents::Sigma{blur_amount[0]},
829858
FilterContents::Sigma{blur_amount[1]},
830859
blur_styles[selected_blur_style]);
831860

832861
auto mask_blur = FilterContents::MakeBorderMaskBlur(
833-
FilterInput::Make(bridge), FilterContents::Sigma{blur_amount[0]},
862+
FilterInput::Make(input), FilterContents::Sigma{blur_amount[0]},
834863
FilterContents::Sigma{blur_amount[1]},
835864
blur_styles[selected_blur_style]);
836865

837-
auto input_size = bridge->GetSize();
838866
auto ctm = Matrix::MakeScale(GetContentScale()) *
839867
Matrix::MakeTranslation(Vector3(offset[0], offset[1])) *
840868
Matrix::MakeRotationZ(Radians(rotation)) *

0 commit comments

Comments
 (0)