@@ -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);
@@ -255,12 +254,11 @@ std::optional<Entity> GaussianBlurFilterContents::RenderFilter(
255254 CalculateBlurRadius (scaled_sigma.y )};
256255 Vector2 padding (ceil (blur_radius.x ), ceil (blur_radius.y ));
257256
258- Matrix source_to_local = entity.GetTransform () * effect_transform;
259257 // Apply as much of the desired padding as possible from the source. This may
260258 // be ignored so must be accounted for in the downsample pass by adding a
261259 // transparent gutter.
262260 std::optional<Rect> expanded_coverage_hint = ExpandCoverageHint (
263- coverage_hint, source_to_local , padding);
261+ coverage_hint, entity. GetTransform () * effect_transform , padding);
264262 // TODO(gaaclarke): How much of the gutter is thrown away can be used to
265263 // adjust the padding that is added in the downsample pass.
266264 // For example, if we get all the padding we requested from
@@ -281,20 +279,31 @@ std::optional<Entity> GaussianBlurFilterContents::RenderFilter(
281279
282280 Scalar desired_scalar =
283281 std::min (CalculateScale (scaled_sigma.x ), CalculateScale (scaled_sigma.y ));
282+ desired_scalar = 1.0 ;
284283 // TODO(jonahwilliams): If desired_scalar is 1.0 and we fully acquired the
285284 // gutter from the expanded_coverage_hint, we can skip the downsample pass.
286285 // pass.
287286 Vector2 downsample_scalar (desired_scalar, desired_scalar);
288287 Rect source_rect = Rect::MakeSize (input_snapshot->texture ->GetSize ());
289- Vector2 downsampled_size = source_rect.size * downsample_scalar;
288+ Rect source_rect_padded = source_rect;
289+ Matrix padding_adjustment;
290+ if (coverage_hint.has_value () && input_snapshot->GetCoverage ().has_value () &&
291+ coverage_hint->Contains (input_snapshot->GetCoverage ().value ())) {
292+ // This means the expanded_coverage_hint was requested in order to get more
293+ // content to sample from, but none was available. So, we'll add our own
294+ // padding.
295+ source_rect_padded = source_rect_padded.Expand (padding);
296+ padding_adjustment = Matrix::MakeTranslation (-padding);
297+ }
298+ Vector2 downsampled_size = source_rect_padded.size * downsample_scalar;
290299 // TODO(gaaclarke): I don't think we are correctly handling this fractional
291300 // amount we are throwing away.
292301 ISize subpass_size =
293302 ISize (round (downsampled_size.x ), round (downsampled_size.y ));
294- Vector2 effective_scalar = Vector2 (subpass_size) / source_rect .size ;
303+ Vector2 effective_scalar = Vector2 (subpass_size) / source_rect_padded .size ;
295304
296- Quad uvs =
297- CalculateUVs (inputs[ 0 ], entity, source_rect );
305+ Quad uvs = CalculateUVs (inputs[ 0 ], entity, source_rect_padded,
306+ input_snapshot-> texture -> GetSize () );
298307
299308 std::shared_ptr<Texture> pass1_out_texture = MakeDownsampleSubpass (
300309 renderer, input_snapshot->texture , input_snapshot->sampler_descriptor ,
@@ -327,12 +336,11 @@ std::optional<Entity> GaussianBlurFilterContents::RenderFilter(
327336 MinMagFilter::kLinear , SamplerAddressMode::kClampToEdge );
328337
329338 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 },
339+ Snapshot{.texture = pass3_out_texture,
340+ .transform = input_snapshot->transform * padding_adjustment *
341+ Matrix::MakeScale (1 / effective_scalar),
342+ .sampler_descriptor = sampler_desc,
343+ .opacity = input_snapshot->opacity },
336344 entity.GetBlendMode (), entity.GetClipDepth ());
337345}
338346
@@ -343,12 +351,13 @@ Scalar GaussianBlurFilterContents::CalculateBlurRadius(Scalar sigma) {
343351Quad GaussianBlurFilterContents::CalculateUVs (
344352 const std::shared_ptr<FilterInput>& filter_input,
345353 const Entity& entity,
346- const Rect& source_rect) {
354+ const Rect& source_rect,
355+ const ISize& texture_size) {
347356 Matrix input_transform = filter_input->GetLocalTransform (entity);
348357 Quad coverage_quad = source_rect.GetTransformedPoints (input_transform);
349358
350359 Matrix uv_transform = Matrix::MakeScale (
351- {1 .0f / source_rect. size . width , 1 .0f / source_rect. size .height , 1 .0f });
360+ {1 .0f / texture_size. width , 1 .0f / texture_size .height , 1 .0f });
352361 return uv_transform.Transform (coverage_quad);
353362}
354363
0 commit comments