@@ -97,14 +97,13 @@ std::shared_ptr<Texture> MakeDownsampleSubpass(
9797 frame_info.texture_sampler_y_coord_scale = 1.0 ;
9898 frame_info.alpha = 1.0 ;
9999
100- BindVertices<TextureFillVertexShader>(
101- cmd, host_buffer,
102- {
103- {Point (0 , 0 ), uvs[0 ]},
104- {Point (1 , 0 ), uvs[1 ]},
105- {Point (0 , 1 ), uvs[2 ]},
106- {Point (1 , 1 ), uvs[3 ]},
107- });
100+ BindVertices<TextureFillVertexShader>(cmd, host_buffer,
101+ {
102+ {Point (0 , 0 ), uvs[0 ]},
103+ {Point (1 , 0 ), uvs[1 ]},
104+ {Point (0 , 1 ), uvs[2 ]},
105+ {Point (1 , 1 ), uvs[3 ]},
106+ });
108107
109108 SamplerDescriptor linear_sampler_descriptor = sampler_descriptor;
110109 SetTileMode (&linear_sampler_descriptor, renderer, tile_mode);
@@ -259,8 +258,8 @@ std::optional<Entity> GaussianBlurFilterContents::RenderFilter(
259258 // Apply as much of the desired padding as possible from the source. This may
260259 // be ignored so must be accounted for in the downsample pass by adding a
261260 // transparent gutter.
262- std::optional<Rect> expanded_coverage_hint = ExpandCoverageHint (
263- coverage_hint, source_to_local, padding);
261+ std::optional<Rect> expanded_coverage_hint =
262+ ExpandCoverageHint ( coverage_hint, source_to_local, padding);
264263 // TODO(gaaclarke): How much of the gutter is thrown away can be used to
265264 // adjust the padding that is added in the downsample pass.
266265 // For example, if we get all the padding we requested from
@@ -281,20 +280,29 @@ std::optional<Entity> GaussianBlurFilterContents::RenderFilter(
281280
282281 Scalar desired_scalar =
283282 std::min (CalculateScale (scaled_sigma.x ), CalculateScale (scaled_sigma.y ));
283+ desired_scalar = 1.0 ;
284284 // TODO(jonahwilliams): If desired_scalar is 1.0 and we fully acquired the
285285 // gutter from the expanded_coverage_hint, we can skip the downsample pass.
286286 // pass.
287287 Vector2 downsample_scalar (desired_scalar, desired_scalar);
288288 Rect source_rect = Rect::MakeSize (input_snapshot->texture ->GetSize ());
289- Vector2 downsampled_size = source_rect.size * downsample_scalar;
289+ Rect source_rect_padded = source_rect;
290+ Matrix padding_adjustment;
291+ if (coverage_hint.has_value () && input_snapshot->GetCoverage ().has_value () &&
292+ coverage_hint->Contains (input_snapshot->GetCoverage ().value ())) {
293+ // This means the expanded snapshot was not valued.
294+ source_rect_padded = source_rect_padded.Expand (padding);
295+ padding_adjustment = Matrix::MakeTranslation (-padding)
296+ }
297+ Vector2 downsampled_size = source_rect_padded.size * downsample_scalar;
290298 // TODO(gaaclarke): I don't think we are correctly handling this fractional
291299 // amount we are throwing away.
292300 ISize subpass_size =
293301 ISize (round (downsampled_size.x ), round (downsampled_size.y ));
294- Vector2 effective_scalar = Vector2 (subpass_size) / source_rect .size ;
302+ Vector2 effective_scalar = Vector2 (subpass_size) / source_rect_padded .size ;
295303
296- Quad uvs =
297- CalculateUVs (inputs[ 0 ], entity, source_rect );
304+ Quad uvs = CalculateUVs (inputs[ 0 ], entity, source_rect_padded,
305+ input_snapshot-> texture -> GetSize () );
298306
299307 std::shared_ptr<Texture> pass1_out_texture = MakeDownsampleSubpass (
300308 renderer, input_snapshot->texture , input_snapshot->sampler_descriptor ,
@@ -327,12 +335,11 @@ std::optional<Entity> GaussianBlurFilterContents::RenderFilter(
327335 MinMagFilter::kLinear , SamplerAddressMode::kClampToEdge );
328336
329337 return Entity::FromSnapshot (
330- Snapshot{
331- .texture = pass3_out_texture,
332- .transform = input_snapshot->transform *
333- Matrix::MakeScale (1 / effective_scalar),
334- .sampler_descriptor = sampler_desc,
335- .opacity = input_snapshot->opacity },
338+ Snapshot{.texture = pass3_out_texture,
339+ .transform = input_snapshot->transform * padding_adjustment *
340+ Matrix::MakeScale (1 / effective_scalar),
341+ .sampler_descriptor = sampler_desc,
342+ .opacity = input_snapshot->opacity },
336343 entity.GetBlendMode (), entity.GetClipDepth ());
337344}
338345
@@ -343,12 +350,13 @@ Scalar GaussianBlurFilterContents::CalculateBlurRadius(Scalar sigma) {
343350Quad GaussianBlurFilterContents::CalculateUVs (
344351 const std::shared_ptr<FilterInput>& filter_input,
345352 const Entity& entity,
346- const Rect& source_rect) {
353+ const Rect& source_rect,
354+ const ISize& texture_size) {
347355 Matrix input_transform = filter_input->GetLocalTransform (entity);
348356 Quad coverage_quad = source_rect.GetTransformedPoints (input_transform);
349357
350358 Matrix uv_transform = Matrix::MakeScale (
351- {1 .0f / source_rect. size . width , 1 .0f / source_rect. size .height , 1 .0f });
359+ {1 .0f / texture_size. width , 1 .0f / texture_size .height , 1 .0f });
352360 return uv_transform.Transform (coverage_quad);
353361}
354362
0 commit comments