@@ -27,10 +27,87 @@ Scalar CalculateSigmaForBlurRadius(Scalar blur_radius) {
2727
2828class DirectionalGaussianBlurFilterContentsTest : public ::testing::Test {
2929 public:
30- void SetUp () override { capabilities_ = mock_capabilities_; }
30+ void SetUp () override {
31+ mock_render_target_allocator_ =
32+ std::make_shared<MockRenderTargetAllocator>(mock_allocator_);
33+ capabilities_ = mock_capabilities_;
34+ }
3135
36+ // Stubs in the minimal support to make rendering pass.
37+ void SetupMinimalContext () {
38+ EXPECT_CALL (*mock_context_, GetCapabilities ())
39+ .WillRepeatedly (ReturnRef (capabilities_));
40+ EXPECT_CALL (*mock_context_, IsValid ()).WillRepeatedly (Return (true ));
41+ EXPECT_CALL (*mock_pipeline_library_, GetPipeline (An<PipelineDescriptor>()))
42+ .WillRepeatedly (Invoke ([mock_pipeline_library =
43+ std::weak_ptr<MockPipelineLibrary>(
44+ mock_pipeline_library_)](
45+ PipelineDescriptor descriptor) {
46+ PipelineFuture<PipelineDescriptor> result;
47+ std::promise<std::shared_ptr<Pipeline<PipelineDescriptor>>> promise;
48+ auto mock_pipeline =
49+ std::make_shared<MockPipeline<PipelineDescriptor>>(
50+ mock_pipeline_library, descriptor);
51+ EXPECT_CALL (*mock_pipeline, IsValid ()).WillRepeatedly (Return (true ));
52+ promise.set_value (mock_pipeline);
53+ result.descriptor = descriptor;
54+ result.future = promise.get_future ();
55+ return result;
56+ }));
57+ EXPECT_CALL (*mock_shader_library_, GetFunction (_, _))
58+ .WillRepeatedly (Invoke ([](std::string_view name, ShaderStage stage) {
59+ return std::make_shared<MockShaderFunction>(UniqueID (),
60+ std::string (name), stage);
61+ }));
62+ EXPECT_CALL (*mock_context_, GetSamplerLibrary ())
63+ .WillRepeatedly (Return (mock_sampler_library_));
64+ EXPECT_CALL (*mock_context_, GetShaderLibrary ())
65+ .WillRepeatedly (Return (mock_shader_library_));
66+ EXPECT_CALL (*mock_context_, GetPipelineLibrary ())
67+ .WillRepeatedly (Return (mock_pipeline_library_));
68+ EXPECT_CALL (*mock_context_, CreateCommandBuffer ())
69+ .WillRepeatedly (Invoke (([mock_context =
70+ std::weak_ptr<MockImpellerContext>(
71+ mock_context_)]() {
72+ auto result = std::make_shared<MockCommandBuffer>(mock_context);
73+ EXPECT_CALL (*result, IsValid ()).WillRepeatedly (Return (true ));
74+ EXPECT_CALL (*result, OnSubmitCommands (_))
75+ .WillRepeatedly (Return (true ));
76+ EXPECT_CALL (*result, OnCreateRenderPass (_))
77+ .WillRepeatedly (
78+ Invoke (([mock_context](const RenderTarget& render_target) {
79+ auto result = std::make_shared<MockRenderPass>(
80+ mock_context, render_target);
81+ EXPECT_CALL (*result, IsValid).WillRepeatedly (Return (true ));
82+ EXPECT_CALL (*result, OnEncodeCommands (_))
83+ .WillRepeatedly (Return (true ));
84+ return result;
85+ })));
86+ return result;
87+ })));
88+ EXPECT_CALL (*mock_render_target_allocator_, CreateTexture (_))
89+ .WillRepeatedly (Invoke (([](const TextureDescriptor& desc) {
90+ auto result = std::make_shared<MockTexture>(desc);
91+ EXPECT_CALL (*result, IsValid ()).WillRepeatedly (Return (true ));
92+ return result;
93+ })));
94+ }
95+
96+ std::shared_ptr<MockImpellerContext> mock_context_ =
97+ std::make_shared<MockImpellerContext>();
3298 std::shared_ptr<MockCapabilities> mock_capabilities_ =
3399 std::make_shared<MockCapabilities>();
100+ std::shared_ptr<MockSamplerLibrary> mock_sampler_library_ =
101+ std::make_shared<MockSamplerLibrary>();
102+ std::shared_ptr<MockShaderLibrary> mock_shader_library_ =
103+ std::make_shared<MockShaderLibrary>();
104+ std::shared_ptr<MockPipelineLibrary> mock_pipeline_library_ =
105+ std::make_shared<MockPipelineLibrary>();
106+ std::shared_ptr<MockTypographerContext> mock_typographer_context_ =
107+ std::make_shared<MockTypographerContext>();
108+ std::shared_ptr<MockAllocator> mock_allocator_ =
109+ std::make_shared<MockAllocator>();
110+ std::shared_ptr<MockRenderTargetAllocator> mock_render_target_allocator_;
34111 std::shared_ptr<const Capabilities> capabilities_;
35112};
36113
@@ -83,6 +160,7 @@ TEST_F(DirectionalGaussianBlurFilterContentsTest, RenderNoCoverage) {
83160}
84161
85162TEST_F (DirectionalGaussianBlurFilterContentsTest, RenderSomething) {
163+ SetupMinimalContext ();
86164 TextureDescriptor desc = {
87165 .size = ISize (100 , 100 ),
88166 };
@@ -93,67 +171,8 @@ TEST_F(DirectionalGaussianBlurFilterContentsTest, RenderSomething) {
93171 contents->SetSigma (Sigma{sigma_radius_1});
94172 contents->SetDirection ({1.0 , 0.0 });
95173 contents->SetInputs ({FilterInput::Make (texture)});
96- auto mock_context = std::make_shared<MockImpellerContext>();
97- EXPECT_CALL (*mock_context, GetCapabilities ())
98- .WillRepeatedly (ReturnRef (capabilities_));
99- EXPECT_CALL (*mock_context, IsValid ()).WillRepeatedly (Return (true ));
100- auto mock_sampler_library = std::make_shared<MockSamplerLibrary>();
101- auto mock_shader_library = std::make_shared<MockShaderLibrary>();
102- auto mock_pipeline_library = std::make_shared<MockPipelineLibrary>();
103- EXPECT_CALL (*mock_pipeline_library, GetPipeline (An<PipelineDescriptor>()))
104- .WillRepeatedly (
105- Invoke ([&mock_pipeline_library](PipelineDescriptor descriptor) {
106- PipelineFuture<PipelineDescriptor> result;
107- std::promise<std::shared_ptr<Pipeline<PipelineDescriptor>>> promise;
108- auto mock_pipeline =
109- std::make_shared<MockPipeline<PipelineDescriptor>>(
110- mock_pipeline_library, descriptor);
111- EXPECT_CALL (*mock_pipeline, IsValid ()).WillRepeatedly (Return (true ));
112- promise.set_value (mock_pipeline);
113- result.descriptor = descriptor;
114- result.future = promise.get_future ();
115- return result;
116- }));
117- EXPECT_CALL (*mock_shader_library, GetFunction (_, _))
118- .WillRepeatedly (Invoke ([](std::string_view name, ShaderStage stage) {
119- return std::make_shared<MockShaderFunction>(UniqueID (),
120- std::string (name), stage);
121- }));
122- EXPECT_CALL (*mock_context, GetSamplerLibrary ())
123- .WillRepeatedly (Return (mock_sampler_library));
124- EXPECT_CALL (*mock_context, GetShaderLibrary ())
125- .WillRepeatedly (Return (mock_shader_library));
126- EXPECT_CALL (*mock_context, GetPipelineLibrary ())
127- .WillRepeatedly (Return (mock_pipeline_library));
128- EXPECT_CALL (*mock_context, CreateCommandBuffer ())
129- .WillRepeatedly (Invoke (([&mock_context]() {
130- auto result = std::make_shared<MockCommandBuffer>(mock_context);
131- EXPECT_CALL (*result, IsValid ()).WillRepeatedly (Return (true ));
132- EXPECT_CALL (*result, OnSubmitCommands (_)).WillRepeatedly (Return (true ));
133- EXPECT_CALL (*result, OnCreateRenderPass (_))
134- .WillRepeatedly (
135- Invoke (([&mock_context](const RenderTarget& render_target) {
136- auto result = std::make_shared<MockRenderPass>(mock_context,
137- render_target);
138- EXPECT_CALL (*result, IsValid).WillRepeatedly (Return (true ));
139- EXPECT_CALL (*result, OnEncodeCommands (_))
140- .WillRepeatedly (Return (true ));
141- return result;
142- })));
143- return result;
144- })));
145- auto mock_typographer_context = std::make_shared<MockTypographerContext>();
146- auto mock_allocator = std::make_shared<MockAllocator>();
147- auto mock_render_target_allocator =
148- std::make_shared<MockRenderTargetAllocator>(mock_allocator);
149- EXPECT_CALL (*mock_render_target_allocator, CreateTexture (_))
150- .WillRepeatedly (Invoke (([](const TextureDescriptor& desc) {
151- auto result = std::make_shared<MockTexture>(desc);
152- EXPECT_CALL (*result, IsValid ()).WillRepeatedly (Return (true ));
153- return result;
154- })));
155- ContentContext renderer (mock_context, mock_typographer_context,
156- mock_render_target_allocator);
174+ ContentContext renderer (mock_context_, mock_typographer_context_,
175+ mock_render_target_allocator_);
157176 Entity entity;
158177 Rect coverage_hint = Rect::MakeLTRB (0 , 0 , 0 , 0 );
159178 std::optional<Entity> result =
0 commit comments