@@ -78,38 +78,55 @@ bool DirectionalGaussianBlurFilterContents::RenderFilter(
7878 auto & host_buffer = pass.GetTransientsBuffer ();
7979
8080 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+ }
8395
8496 auto transformed_blur =
8597 entity.GetTransformation ().TransformDirection (blur_vector_);
8698
8799 // LTRB
88100 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 ,
97109 };
98110
99111 auto source = source_override_ ? source_override_ : inputs[0 ];
100112 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+ }
102119
103120 // LTRB
104121 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 ,
113130 };
114131
115132 VertexBufferBuilder<VS::PerVertexData> vtx_builder;
@@ -124,7 +141,7 @@ bool DirectionalGaussianBlurFilterContents::RenderFilter(
124141 auto vtx_buffer = vtx_builder.CreateVertexBuffer (host_buffer);
125142
126143 VS::FrameInfo frame_info;
127- frame_info.texture_size = Point (input_bounds. size );
144+ frame_info.texture_size = Point (input_bounds-> size );
128145 frame_info.blur_radius = transformed_blur.GetLength ();
129146 frame_info.blur_direction = transformed_blur.Normalize ();
130147 frame_info.src_factor = src_color_factor_;
@@ -150,13 +167,17 @@ bool DirectionalGaussianBlurFilterContents::RenderFilter(
150167 return pass.AddCommand (cmd);
151168}
152169
153- Rect DirectionalGaussianBlurFilterContents::GetBounds (
170+ std::optional< Rect> DirectionalGaussianBlurFilterContents::GetCoverage (
154171 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+
156177 auto transformed_blur =
157178 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 ));
160181}
161182
162183} // namespace impeller
0 commit comments