Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some important comments to some of the FilteContents methods #47567

Merged
merged 3 commits into from
Nov 2, 2023

Conversation

flar
Copy link
Contributor

@flar flar commented Nov 1, 2023

Fixes flutter/flutter#137703

Also clarified and fixed indentation on docstring comment for the public method FilterContents::GetSourceCoverage

@flar flar requested a review from gaaclarke November 1, 2023 19:49
/// @brief Determines the coverage of source pixels that will be needed
/// to produce results for the indicated output limit. This is a
/// reverse bounds calculation computing a source coverage from
/// an intended output coverage.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, it's the inverse of GetCoverage?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. Is that confusing from what I wrote? Or are you suggesting a simplification?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I lost the mention of the transform. Minor update coming...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about:

  /// @brief  Determines the coverage of source pixels that will be needed
  ///         to produce results for the indicated output coverage under the
  ///         indicated effect transform. This is essentially a reverse of
  ///         the |GetCoverage| method computing a source coverage from
  ///         an intended output coverage.

(I'm also renaming the output_limit parameter to output_coverage to match that text)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, renaming the parameter and propagating it to all of the downstream methods would touch a bunch of files unnecessarily, so I'll change the comment to match instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was just a genuine question. That doesn't match my understanding after having looked at DirectionalGaussianBlurFilterContents.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps you are confused by the non-intuitive fact that blur filters expand in both directions. Just as a given edge pixel can be the input for a fringe around the source and so it expands when you apply the filter, each pixel takes input from a range of pixels around it so you need more source pixels than output pixels in order to compute the values correctly.

So, the gaussian filter is computing a reverse bounds by expanding it...

Copy link
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per our discussion in the chat. If you want to format these differently. I'm fine with that. Here is an example of implicit brief/details that doesn't use extra whitespace.

/// This is brief.
/// This is a details, lots and lots of details.
/// Here's even more details.
void Foobar();

/// to apply this filter under the given transform and produce
/// results anywhere within the indicated coverage limit.
/// @brief Determines the coverage of source pixels that will be needed
/// to produce results for the indicated output limit. This is a
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// to produce results for the indicated output limit. This is a
/// to produce results for the indicated `output_limit`. This is a

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used the |output_limit| notation in my latest push, which is what I've used elsewhere for parameters. Is that correct?

/// to collect all pixels that might affect the supplied output
/// coverage limit. While we might clip the rendering of the subpass,
/// we want to avoid clipping out any pixels that contribute to
/// the output limit via the filtering operation.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This never defines what effect_transform is. Looking at the implementation of some GetFilterSourceCoverage i know that only the basis is used. That should be mentioned.

For DirectionalGaussianBlurFilterContents::GetFilterSourceCoverage shouldn't the result of GetFilterSourceCoverage be smaller than output_limit since the source will not have the blur radius? It is actually returning a larger result.

The problem I ran into was this:

TEST(DirectionalGaussianBlurFilterContents, FilterSourceCoverage) {
  Scalar sigma_radius_1 = CalculateSigmaForBlurRadius(1.0);
  auto contents = std::make_unique<DirectionalGaussianBlurFilterContents>();
  contents->SetSigma(Sigma{sigma_radius_1});
  contents->SetDirection({1.0, 0.0});
  std::optional<Rect> coverage = contents->GetFilterSourceCoverage(
      /*effect_transform=*/Matrix::MakeScale({2.0, 2.0, 1.0}),
      /*output_limit=*/Rect::MakeLTRB(100, 100, 200, 200));
  ASSERT_EQ(coverage, ???);
}

Should the output_limit be Rect::MakeLTRB(100 - 2, 100, 200 + 2, 200) or Rect::MakeLTRB(50 - 2, 50, 100 + 2, 100) or Rect::MakeLTRB(200 - 2, 200, 400 + 2, 400)? It's not clear how the effect_transform is related to the operation by reading the documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This never defines what effect_transform is. Looking at the implementation of some GetFilterSourceCoverage i know that only the basis is used. That should be mentioned.

Use of Basis is specific to a filter computing its best guess, not to the general operation. All this method specifies is that the filters should do a reverse computation, not how they should do it.

For the record, I don't think the use of basis on those filters is correct and I should file an issue about it (done). I used basis because the existing methods in the class already used basis and I wanted to be consistent with the current state of their implementations.

For DirectionalGaussianBlurFilterContents::GetFilterSourceCoverage shouldn't the result of GetFilterSourceCoverage be smaller than output_limit since the source will not have the blur radius? It is actually returning a larger result.

No, it has to be larger. Input pixels are taken from a radius and so we need more pixels from the source than the size of the dest.

The problem I ran into was this:

TEST(DirectionalGaussianBlurFilterContents, FilterSourceCoverage) {
  Scalar sigma_radius_1 = CalculateSigmaForBlurRadius(1.0);
  auto contents = std::make_unique<DirectionalGaussianBlurFilterContents>();
  contents->SetSigma(Sigma{sigma_radius_1});
  contents->SetDirection({1.0, 0.0});
  std::optional<Rect> coverage = contents->GetFilterSourceCoverage(
      /*effect_transform=*/Matrix::MakeScale({2.0, 2.0, 1.0}),
      /*output_limit=*/Rect::MakeLTRB(100, 100, 200, 200));
  ASSERT_EQ(coverage, ???);
}

Should the output_limit be Rect::MakeLTRB(100 - 2, 100, 200 + 2, 200) or Rect::MakeLTRB(50 - 2, 50, 100 + 2, 100) or Rect::MakeLTRB(200 - 2, 200, 400 + 2, 400)? It's not clear how the effect_transform is related to the operation by reading the documentation.

I mentioned that it was relative to the transform in the most recent cut, but I'll be more specific. The supplied "output_limit" and the result should both be in the transformed space. The sigma is in the untransformed space, but the input and output coverages are both in the transformed space. So, you need to adjust the sigma to its correct value in the transformed space and then all 3 are in the same space.

So, here you would need to scale the radius by 2, but then apply it directly to the 100,100 values and return them relative to 100,100 - so expand by 2 in both left and right. Your first answer looks right to me, other than assuming that sigma is the value you should expand to. There is a calculation in the code that maps sigma to the "fringe" of the gaussian blur. That "fringe" calculation will be in the untransformed space, so compute sigma -> fringe, and then map fringe through the transform.

But since both the input and the output rectangles are in the transformed space of the effect_transform, neither of those gets run through, or inversed through, the transform.

impeller/entity/contents/filters/filter_contents.h Outdated Show resolved Hide resolved
impeller/entity/contents/filters/filter_contents.h Outdated Show resolved Hide resolved
virtual std::optional<Rect> GetFilterCoverage(
const FilterInput::Vector& inputs,
const Entity& entity,
const Matrix& effect_transform) const;

/// @brief Internal utility method for |GetSourceCoverage|.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is mostly good, but make the brief define what the function does briefly. Also define effect_transform. You'll probably just want to link to a definition somewhere else in this file.

What is the coordinate space of the output_limit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

|GetSourceCoverage| is a link to the full definition...

impeller/entity/contents/filters/filter_contents.h Outdated Show resolved Hide resolved
@flar
Copy link
Contributor Author

flar commented Nov 1, 2023

As per our discussion in the chat. If you want to format these differently. I'm fine with that. Here is an example of implicit brief/details that doesn't use extra whitespace.

Consistency within files and modules is always a win, though. I was more questioning if we are sure we want to finalize on this style before we start going back and really filling out a lot of comments as we are likely to do in the near future. The chat showed widespread support for doing the style already being used in this file.

Copy link
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is much more helpful. I still suspect they can be improved but I'm definitely not well informed enough to suggest anything. Thanks!

@flar flar added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 1, 2023
Copy link
Contributor

auto-submit bot commented Nov 1, 2023

auto label is removed for flutter/engine/47567, due to - The status or check suite Linux linux_android_aot_engine has failed. Please fix the issues identified (or deflake) before re-applying this label.

@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 1, 2023
@flar flar force-pushed the filter-contents-method-comments branch from 765b1c6 to 7906807 Compare November 2, 2023 00:57
@flar flar force-pushed the filter-contents-method-comments branch from 7906807 to 7b136ff Compare November 2, 2023 01:15
@flar flar added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 2, 2023
@auto-submit auto-submit bot merged commit bc39653 into flutter:main Nov 2, 2023
25 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 2, 2023
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Nov 2, 2023
…137751)

flutter/engine@ff8d3a3...bc39653

2023-11-02 flar@google.com Add some important comments to some of the FilteContents methods (flutter/engine#47567)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC rmistry@google.com,zra@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App e: impeller
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Add docstrings for FilterContents coverage functions
2 participants