@@ -78,38 +78,55 @@ bool DirectionalGaussianBlurFilterContents::RenderFilter(
78
78
auto & host_buffer = pass.GetTransientsBuffer ();
79
79
80
80
auto input = inputs[0 ]->GetSnapshot (renderer, entity);
81
- auto input_bounds = inputs[0 ]->GetBounds (entity);
82
- auto filter_bounds = GetBounds (entity);
81
+ if (!input.has_value ()) {
82
+ return true ;
83
+ }
84
+
85
+ auto input_bounds = inputs[0 ]->GetCoverage (entity);
86
+ if (!input_bounds.has_value () || input_bounds->IsEmpty ()) {
87
+ return true ;
88
+ }
89
+ auto filter_bounds = GetCoverage (entity);
90
+ if (!filter_bounds.has_value () || filter_bounds->IsEmpty ()) {
91
+ FML_LOG (ERROR) << " The gaussian blur filter coverage is missing or empty "
92
+ " even though the filter's input has coverage." ;
93
+ return false ;
94
+ }
83
95
84
96
auto transformed_blur =
85
97
entity.GetTransformation ().TransformDirection (blur_vector_);
86
98
87
99
// LTRB
88
100
Scalar uv[4 ] = {
89
- (filter_bounds. GetLeft () - input_bounds. GetLeft ()) /
90
- input_bounds. size .width ,
91
- (filter_bounds. GetTop () - input_bounds. GetTop ()) /
92
- input_bounds. size .height ,
93
- 1 + (filter_bounds. GetRight () - input_bounds. GetRight ()) /
94
- input_bounds. size .width ,
95
- 1 + (filter_bounds. GetBottom () - input_bounds. GetBottom ()) /
96
- input_bounds. size .height ,
101
+ (filter_bounds-> GetLeft () - input_bounds-> GetLeft ()) /
102
+ input_bounds-> size .width ,
103
+ (filter_bounds-> GetTop () - input_bounds-> GetTop ()) /
104
+ input_bounds-> size .height ,
105
+ 1 + (filter_bounds-> GetRight () - input_bounds-> GetRight ()) /
106
+ input_bounds-> size .width ,
107
+ 1 + (filter_bounds-> GetBottom () - input_bounds-> GetBottom ()) /
108
+ input_bounds-> size .height ,
97
109
};
98
110
99
111
auto source = source_override_ ? source_override_ : inputs[0 ];
100
112
auto source_texture = source->GetSnapshot (renderer, entity);
101
- auto source_bounds = source->GetBounds (entity);
113
+ auto source_bounds = source->GetCoverage (entity);
114
+ if (!source_texture.has_value () || !source_bounds.has_value () ||
115
+ source_bounds->IsEmpty ()) {
116
+ VALIDATION_LOG << " The gaussian blur source override has no coverage." ;
117
+ return false ;
118
+ }
102
119
103
120
// LTRB
104
121
Scalar uv_src[4 ] = {
105
- (filter_bounds. GetLeft () - source_bounds. GetLeft ()) /
106
- source_bounds. size .width ,
107
- (filter_bounds. GetTop () - source_bounds. GetTop ()) /
108
- source_bounds. size .height ,
109
- 1 + (filter_bounds. GetRight () - source_bounds. GetRight ()) /
110
- source_bounds. size .width ,
111
- 1 + (filter_bounds. GetBottom () - source_bounds. GetBottom ()) /
112
- source_bounds. size .height ,
122
+ (filter_bounds-> GetLeft () - source_bounds-> GetLeft ()) /
123
+ source_bounds-> size .width ,
124
+ (filter_bounds-> GetTop () - source_bounds-> GetTop ()) /
125
+ source_bounds-> size .height ,
126
+ 1 + (filter_bounds-> GetRight () - source_bounds-> GetRight ()) /
127
+ source_bounds-> size .width ,
128
+ 1 + (filter_bounds-> GetBottom () - source_bounds-> GetBottom ()) /
129
+ source_bounds-> size .height ,
113
130
};
114
131
115
132
VertexBufferBuilder<VS::PerVertexData> vtx_builder;
@@ -124,7 +141,7 @@ bool DirectionalGaussianBlurFilterContents::RenderFilter(
124
141
auto vtx_buffer = vtx_builder.CreateVertexBuffer (host_buffer);
125
142
126
143
VS::FrameInfo frame_info;
127
- frame_info.texture_size = Point (input_bounds. size );
144
+ frame_info.texture_size = Point (input_bounds-> size );
128
145
frame_info.blur_radius = transformed_blur.GetLength ();
129
146
frame_info.blur_direction = transformed_blur.Normalize ();
130
147
frame_info.src_factor = src_color_factor_;
@@ -150,13 +167,17 @@ bool DirectionalGaussianBlurFilterContents::RenderFilter(
150
167
return pass.AddCommand (cmd);
151
168
}
152
169
153
- Rect DirectionalGaussianBlurFilterContents::GetBounds (
170
+ std::optional< Rect > DirectionalGaussianBlurFilterContents::GetCoverage (
154
171
const Entity& entity) const {
155
- auto bounds = FilterContents::GetBounds (entity);
172
+ auto bounds = FilterContents::GetCoverage (entity);
173
+ if (!bounds.has_value ()) {
174
+ return std::nullopt;
175
+ }
176
+
156
177
auto transformed_blur =
157
178
entity.GetTransformation ().TransformDirection (blur_vector_).Abs ();
158
- auto extent = bounds. size + transformed_blur * 2 ;
159
- return Rect (bounds. origin - transformed_blur, Size (extent.x , extent.y ));
179
+ auto extent = bounds-> size + transformed_blur * 2 ;
180
+ return Rect (bounds-> origin - transformed_blur, Size (extent.x , extent.y ));
160
181
}
161
182
162
183
} // namespace impeller
0 commit comments