55#include " impeller/entity/contents/filters/blend_filter_contents.h"
66
77#include " impeller/entity/contents/content_context.h"
8+ #include " impeller/entity/contents/filters/filter_input.h"
89#include " impeller/renderer/render_pass.h"
910#include " impeller/renderer/sampler_library.h"
1011
@@ -20,11 +21,13 @@ using PipelineProc =
2021 std::shared_ptr<Pipeline> (ContentContext::*)(ContentContextOptions) const ;
2122
2223template <typename VS, typename FS>
23- static bool AdvancedBlend (const std::vector<Contents::Snapshot>& input_textures ,
24+ static bool AdvancedBlend (const FilterInput::Vector& inputs ,
2425 const ContentContext& renderer,
26+ const Entity& entity,
2527 RenderPass& pass,
28+ const Rect& bounds,
2629 PipelineProc pipeline_proc) {
27- if (input_textures .size () < 2 ) {
30+ if (inputs .size () < 2 ) {
2831 return false ;
2932 }
3033
@@ -56,19 +59,21 @@ static bool AdvancedBlend(const std::vector<Contents::Snapshot>& input_textures,
5659 typename VS::FrameInfo frame_info;
5760 frame_info.mvp = Matrix::MakeOrthographic (size);
5861
59- auto dst_snapshot = input_textures [1 ];
60- FS::BindTextureSamplerSrc (cmd, dst_snapshot. texture , sampler);
62+ auto dst_snapshot = inputs [1 ]-> GetSnapshot (renderer, entity) ;
63+ FS::BindTextureSamplerSrc (cmd, dst_snapshot-> texture , sampler);
6164 frame_info.dst_uv_transform =
62- Matrix::MakeTranslation (-dst_snapshot.position / size) *
65+ Matrix::MakeTranslation (-(dst_snapshot->position - bounds.origin ) /
66+ size) *
6367 Matrix::MakeScale (
64- Vector3 (Size (size) / Size (dst_snapshot. texture ->GetSize ())));
68+ Vector3 (Size (size) / Size (dst_snapshot-> texture ->GetSize ())));
6569
66- auto src_snapshot = input_textures [0 ];
67- FS::BindTextureSamplerDst (cmd, src_snapshot. texture , sampler);
70+ auto src_snapshot = inputs [0 ]-> GetSnapshot (renderer, entity) ;
71+ FS::BindTextureSamplerDst (cmd, src_snapshot-> texture , sampler);
6872 frame_info.src_uv_transform =
69- Matrix::MakeTranslation (-src_snapshot.position / size) *
73+ Matrix::MakeTranslation (-(src_snapshot->position - bounds.origin ) /
74+ size) *
7075 Matrix::MakeScale (
71- Vector3 (Size (size) / Size (src_snapshot. texture ->GetSize ())));
76+ Vector3 (Size (size) / Size (src_snapshot-> texture ->GetSize ())));
7277
7378 auto uniform_view = host_buffer.EmplaceUniform (frame_info);
7479 VS::BindFrameInfo (cmd, uniform_view);
@@ -91,13 +96,14 @@ void BlendFilterContents::SetBlendMode(Entity::BlendMode blend_mode) {
9196
9297 switch (blend_mode) {
9398 case Entity::BlendMode::kScreen :
94- advanced_blend_proc_ = [](const std::vector<Snapshot>& input_textures ,
99+ advanced_blend_proc_ = [](const FilterInput::Vector& inputs ,
95100 const ContentContext& renderer,
96- RenderPass& pass) {
101+ const Entity& entity, RenderPass& pass,
102+ const Rect& bounds) {
97103 PipelineProc p = &ContentContext::GetTextureBlendScreenPipeline;
98104 return AdvancedBlend<TextureBlendScreenPipeline::VertexShader,
99105 TextureBlendScreenPipeline::FragmentShader>(
100- input_textures , renderer, pass, p);
106+ inputs , renderer, entity, pass, bounds , p);
101107 };
102108 break ;
103109 default :
@@ -106,9 +112,11 @@ void BlendFilterContents::SetBlendMode(Entity::BlendMode blend_mode) {
106112 }
107113}
108114
109- static bool BasicBlend (const std::vector<Contents::Snapshot>& input_textures ,
115+ static bool BasicBlend (const FilterInput::Vector& inputs ,
110116 const ContentContext& renderer,
117+ const Entity& entity,
111118 RenderPass& pass,
119+ const Rect& bounds,
112120 Entity::BlendMode basic_blend) {
113121 using VS = TextureBlendPipeline::VertexShader;
114122 using FS = TextureBlendPipeline::FragmentShader;
@@ -138,21 +146,21 @@ static bool BasicBlend(const std::vector<Contents::Snapshot>& input_textures,
138146 options.blend_mode = Entity::BlendMode::kSource ;
139147 cmd.pipeline = renderer.GetTextureBlendPipeline (options);
140148 {
141- auto input = input_textures [0 ];
142- FS::BindTextureSamplerSrc (cmd, input. texture , sampler);
149+ auto input = inputs [0 ]-> GetSnapshot (renderer, entity) ;
150+ FS::BindTextureSamplerSrc (cmd, input-> texture , sampler);
143151
144152 VS::FrameInfo frame_info;
145153 frame_info.mvp =
146154 Matrix::MakeOrthographic (size) *
147- Matrix::MakeTranslation (input. position ) *
148- Matrix::MakeScale (Size (input. texture ->GetSize ()) / Size (size));
155+ Matrix::MakeTranslation (input-> position - bounds. origin ) *
156+ Matrix::MakeScale (Size (input-> texture ->GetSize ()) / Size (size));
149157
150158 auto uniform_view = host_buffer.EmplaceUniform (frame_info);
151159 VS::BindFrameInfo (cmd, uniform_view);
152160 }
153161 pass.AddCommand (cmd);
154162
155- if (input_textures .size () < 2 ) {
163+ if (inputs .size () < 2 ) {
156164 return true ;
157165 }
158166
@@ -161,16 +169,16 @@ static bool BasicBlend(const std::vector<Contents::Snapshot>& input_textures,
161169 options.blend_mode = basic_blend;
162170 cmd.pipeline = renderer.GetTextureBlendPipeline (options);
163171
164- for (auto texture_i = input_textures .begin () + 1 ;
165- texture_i < input_textures. end (); texture_i ++) {
166- auto input = * texture_i;
167- FS::BindTextureSamplerSrc (cmd, input. texture , sampler);
172+ for (auto texture_i = inputs .begin () + 1 ; texture_i < inputs. end () ;
173+ texture_i++) {
174+ auto input = texture_i-> get ()-> GetSnapshot (renderer, entity) ;
175+ FS::BindTextureSamplerSrc (cmd, input-> texture , sampler);
168176
169177 VS::FrameInfo frame_info;
170178 frame_info.mvp = frame_info.mvp =
171179 Matrix::MakeOrthographic (size) *
172- Matrix::MakeTranslation (input. position ) *
173- Matrix::MakeScale (Size (input. texture ->GetSize ()) / Size (size));
180+ Matrix::MakeTranslation (input-> position - bounds. origin ) *
181+ Matrix::MakeScale (Size (input-> texture ->GetSize ()) / Size (size));
174182
175183 auto uniform_view = host_buffer.EmplaceUniform (frame_info);
176184 VS::BindFrameInfo (cmd, uniform_view);
@@ -180,27 +188,27 @@ static bool BasicBlend(const std::vector<Contents::Snapshot>& input_textures,
180188 return true ;
181189}
182190
183- bool BlendFilterContents::RenderFilter (
184- const std::vector<Snapshot>& input_textures ,
185- const ContentContext& renderer ,
186- RenderPass& pass,
187- const Matrix& transform ) const {
188- if (input_textures .empty ()) {
191+ bool BlendFilterContents::RenderFilter (const FilterInput::Vector& inputs,
192+ const ContentContext& renderer ,
193+ const Entity& entity ,
194+ RenderPass& pass,
195+ const Rect& bounds ) const {
196+ if (inputs .empty ()) {
189197 return true ;
190198 }
191199
192- if (input_textures .size () == 1 ) {
200+ if (inputs .size () == 1 ) {
193201 // Nothing to blend.
194- return BasicBlend (input_textures , renderer, pass,
202+ return BasicBlend (inputs , renderer, entity, pass, bounds ,
195203 Entity::BlendMode::kSource );
196204 }
197205
198206 if (blend_mode_ <= Entity::BlendMode::kLastPipelineBlendMode ) {
199- return BasicBlend (input_textures , renderer, pass, blend_mode_);
207+ return BasicBlend (inputs , renderer, entity, pass, bounds , blend_mode_);
200208 }
201209
202210 if (blend_mode_ <= Entity::BlendMode::kLastAdvancedBlendMode ) {
203- return advanced_blend_proc_ (input_textures , renderer, pass);
211+ return advanced_blend_proc_ (inputs , renderer, entity, pass, bounds );
204212 }
205213
206214 FML_UNREACHABLE ();
0 commit comments