10
10
#include " impeller/entity/contents/filters/inputs/filter_input.h"
11
11
#include " impeller/entity/contents/solid_color_contents.h"
12
12
#include " impeller/entity/contents/solid_stroke_contents.h"
13
+ #include " impeller/entity/contents/texture_contents.h"
13
14
#include " impeller/entity/contents/vertices_contents.h"
14
15
#include " impeller/entity/entity.h"
15
16
#include " impeller/entity/entity_pass.h"
@@ -772,38 +773,47 @@ TEST_P(EntityTest, Filters) {
772
773
}
773
774
774
775
TEST_P (EntityTest, GaussianBlurFilter) {
775
- auto bridge = CreateTextureForFixture (" bay_bridge.jpg" );
776
776
auto boston = CreateTextureForFixture (" boston.jpg" );
777
- auto kalimba = CreateTextureForFixture (" kalimba.jpg" );
778
- ASSERT_TRUE (bridge && boston && kalimba);
777
+ ASSERT_TRUE (boston);
779
778
780
779
bool first_frame = true ;
781
780
auto callback = [&](ContentContext& context, RenderPass& pass) -> bool {
782
781
if (first_frame) {
783
782
first_frame = false ;
784
- ImGui::SetNextWindowSize ({500 , 250 });
785
- ImGui::SetNextWindowPos ({300 , 500 });
783
+ ImGui::SetNextWindowSize ({500 , 290 });
784
+ ImGui::SetNextWindowPos ({300 , 480 });
786
785
}
787
786
787
+ const char * input_type_names[] = {" Texture" , " Solid Color" };
788
788
const char * blur_type_names[] = {" Image blur" , " Mask blur" };
789
789
const char * blur_style_names[] = {" Normal" , " Solid" , " Outer" , " Inner" };
790
790
const FilterContents::BlurStyle blur_styles[] = {
791
791
FilterContents::BlurStyle::kNormal , FilterContents::BlurStyle::kSolid ,
792
792
FilterContents::BlurStyle::kOuter , FilterContents::BlurStyle::kInner };
793
793
794
794
// UI state.
795
+ static int selected_input_type = 0 ;
796
+ static Color input_color = Color::Black ();
795
797
static int selected_blur_type = 0 ;
796
798
static float blur_amount[2 ] = {20 , 20 };
797
799
static int selected_blur_style = 0 ;
798
800
static Color cover_color (1 , 0 , 0 , 0.2 );
799
801
static Color bounds_color (0 , 1 , 0 , 0.1 );
800
802
static float offset[2 ] = {500 , 400 };
801
803
static float rotation = 0 ;
802
- static float scale[2 ] = {0.5 , 0.5 };
804
+ static float scale[2 ] = {0.75 , 0.75 };
803
805
static float skew[2 ] = {0 , 0 };
804
806
805
807
ImGui::Begin (" Controls" );
806
808
{
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
+ }
807
817
ImGui::Combo (" Blur type" , &selected_blur_type, blur_type_names,
808
818
sizeof (blur_type_names) / sizeof (char *));
809
819
ImGui::SliderFloat2 (" Blur" , &blur_amount[0 ], 0 , 200 );
@@ -820,21 +830,39 @@ TEST_P(EntityTest, GaussianBlurFilter) {
820
830
}
821
831
ImGui::End ();
822
832
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
+ }
826
855
827
856
auto blur = FilterContents::MakeGaussianBlur (
828
- FilterInput::Make (blend ), FilterContents::Sigma{blur_amount[0 ]},
857
+ FilterInput::Make (input ), FilterContents::Sigma{blur_amount[0 ]},
829
858
FilterContents::Sigma{blur_amount[1 ]},
830
859
blur_styles[selected_blur_style]);
831
860
832
861
auto mask_blur = FilterContents::MakeBorderMaskBlur (
833
- FilterInput::Make (bridge ), FilterContents::Sigma{blur_amount[0 ]},
862
+ FilterInput::Make (input ), FilterContents::Sigma{blur_amount[0 ]},
834
863
FilterContents::Sigma{blur_amount[1 ]},
835
864
blur_styles[selected_blur_style]);
836
865
837
- auto input_size = bridge->GetSize ();
838
866
auto ctm = Matrix::MakeScale (GetContentScale ()) *
839
867
Matrix::MakeTranslation (Vector3 (offset[0 ], offset[1 ])) *
840
868
Matrix::MakeRotationZ (Radians (rotation)) *
0 commit comments