5
5
#include " impeller/entity/contents/filters/blend_filter_contents.h"
6
6
7
7
#include " impeller/entity/contents/content_context.h"
8
+ #include " impeller/entity/contents/filters/filter_input.h"
8
9
#include " impeller/renderer/render_pass.h"
9
10
#include " impeller/renderer/sampler_library.h"
10
11
@@ -20,11 +21,13 @@ using PipelineProc =
20
21
std::shared_ptr<Pipeline> (ContentContext::*)(ContentContextOptions) const ;
21
22
22
23
template <typename VS, typename FS>
23
- static bool AdvancedBlend (const std::vector<Contents::Snapshot>& input_textures ,
24
+ static bool AdvancedBlend (const FilterInput::Vector& inputs ,
24
25
const ContentContext& renderer,
26
+ const Entity& entity,
25
27
RenderPass& pass,
28
+ const Rect & bounds,
26
29
PipelineProc pipeline_proc) {
27
- if (input_textures .size () < 2 ) {
30
+ if (inputs .size () < 2 ) {
28
31
return false ;
29
32
}
30
33
@@ -56,19 +59,21 @@ static bool AdvancedBlend(const std::vector<Contents::Snapshot>& input_textures,
56
59
typename VS::FrameInfo frame_info;
57
60
frame_info.mvp = Matrix::MakeOrthographic (size);
58
61
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);
61
64
frame_info.dst_uv_transform =
62
- Matrix::MakeTranslation (-dst_snapshot.position / size) *
65
+ Matrix::MakeTranslation (-(dst_snapshot->position - bounds.origin ) /
66
+ size) *
63
67
Matrix::MakeScale (
64
- Vector3 (Size (size) / Size (dst_snapshot. texture ->GetSize ())));
68
+ Vector3 (Size (size) / Size (dst_snapshot-> texture ->GetSize ())));
65
69
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);
68
72
frame_info.src_uv_transform =
69
- Matrix::MakeTranslation (-src_snapshot.position / size) *
73
+ Matrix::MakeTranslation (-(src_snapshot->position - bounds.origin ) /
74
+ size) *
70
75
Matrix::MakeScale (
71
- Vector3 (Size (size) / Size (src_snapshot. texture ->GetSize ())));
76
+ Vector3 (Size (size) / Size (src_snapshot-> texture ->GetSize ())));
72
77
73
78
auto uniform_view = host_buffer.EmplaceUniform (frame_info);
74
79
VS::BindFrameInfo (cmd, uniform_view);
@@ -91,13 +96,14 @@ void BlendFilterContents::SetBlendMode(Entity::BlendMode blend_mode) {
91
96
92
97
switch (blend_mode) {
93
98
case Entity::BlendMode::kScreen :
94
- advanced_blend_proc_ = [](const std::vector<Snapshot>& input_textures ,
99
+ advanced_blend_proc_ = [](const FilterInput::Vector& inputs ,
95
100
const ContentContext& renderer,
96
- RenderPass& pass) {
101
+ const Entity& entity, RenderPass& pass,
102
+ const Rect & bounds) {
97
103
PipelineProc p = &ContentContext::GetTextureBlendScreenPipeline;
98
104
return AdvancedBlend<TextureBlendScreenPipeline::VertexShader,
99
105
TextureBlendScreenPipeline::FragmentShader>(
100
- input_textures , renderer, pass, p);
106
+ inputs , renderer, entity, pass, bounds , p);
101
107
};
102
108
break ;
103
109
default :
@@ -106,9 +112,11 @@ void BlendFilterContents::SetBlendMode(Entity::BlendMode blend_mode) {
106
112
}
107
113
}
108
114
109
- static bool BasicBlend (const std::vector<Contents::Snapshot>& input_textures ,
115
+ static bool BasicBlend (const FilterInput::Vector& inputs ,
110
116
const ContentContext& renderer,
117
+ const Entity& entity,
111
118
RenderPass& pass,
119
+ const Rect & bounds,
112
120
Entity::BlendMode basic_blend) {
113
121
using VS = TextureBlendPipeline::VertexShader;
114
122
using FS = TextureBlendPipeline::FragmentShader;
@@ -138,21 +146,21 @@ static bool BasicBlend(const std::vector<Contents::Snapshot>& input_textures,
138
146
options.blend_mode = Entity::BlendMode::kSource ;
139
147
cmd.pipeline = renderer.GetTextureBlendPipeline (options);
140
148
{
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);
143
151
144
152
VS::FrameInfo frame_info;
145
153
frame_info.mvp =
146
154
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));
149
157
150
158
auto uniform_view = host_buffer.EmplaceUniform (frame_info);
151
159
VS::BindFrameInfo (cmd, uniform_view);
152
160
}
153
161
pass.AddCommand (cmd);
154
162
155
- if (input_textures .size () < 2 ) {
163
+ if (inputs .size () < 2 ) {
156
164
return true ;
157
165
}
158
166
@@ -161,16 +169,16 @@ static bool BasicBlend(const std::vector<Contents::Snapshot>& input_textures,
161
169
options.blend_mode = basic_blend;
162
170
cmd.pipeline = renderer.GetTextureBlendPipeline (options);
163
171
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);
168
176
169
177
VS::FrameInfo frame_info;
170
178
frame_info.mvp = frame_info.mvp =
171
179
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));
174
182
175
183
auto uniform_view = host_buffer.EmplaceUniform (frame_info);
176
184
VS::BindFrameInfo (cmd, uniform_view);
@@ -180,27 +188,27 @@ static bool BasicBlend(const std::vector<Contents::Snapshot>& input_textures,
180
188
return true ;
181
189
}
182
190
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 ()) {
189
197
return true ;
190
198
}
191
199
192
- if (input_textures .size () == 1 ) {
200
+ if (inputs .size () == 1 ) {
193
201
// Nothing to blend.
194
- return BasicBlend (input_textures , renderer, pass,
202
+ return BasicBlend (inputs , renderer, entity, pass, bounds ,
195
203
Entity::BlendMode::kSource );
196
204
}
197
205
198
206
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_);
200
208
}
201
209
202
210
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 );
204
212
}
205
213
206
214
FML_UNREACHABLE ();
0 commit comments