Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@knopp
Copy link
Member

@knopp knopp commented Oct 13, 2020

Description

Adds DiffContext class to facilitate diffing of layer trees.

Related Issues

flutter/flutter#33939

Tests

I added the following tests:

DiffContextTest.*

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the contributor guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the C++, Objective-C, Java style guides for the engine.
  • I read the tree hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation.
  • All existing and new tests are passing.
  • I am willing to follow-up on review comments in a timely manner.

Reviewer Checklist

Breaking Change

Did any tests fail when you ran them? Please read handling breaking changes.

  • No, no existing tests failed, so this is not a breaking change.
  • Yes, this is a breaking change. If not, delete the remainder of this section.

@flar flar requested review from flar and liyuqian October 13, 2020 23:42
@knopp knopp force-pushed the diff_context branch 3 times, most recently from 3a96779 to 7a5e736 Compare October 14, 2020 01:25
}

// Backdrop filter paints everywhere in cull rect
auto paint_bounds = filter_->computeFastBounds(context->GetCullRect());
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this use SkImageFilter->filterBounds(..., ReverseDirection, ...)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Possibly. At least in ImageFilterLayer computeFastBounds seems wrong.

One thing I don't quite understand, the documentation for filterBounds says it maps device-space rect, but ImageFilterLayer seems to apply it on local coordinate rect?

Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like computeFastBounds would be a NOP in this case, just returning the cull_rect. It apparently just does a union of the input bounds without considering how the filter will modify them. The bounds you pass in is the bounds to assume for any null inputs (null inputs represent source data that will be supplied later when you perform the filter).

Copy link
Member Author

Choose a reason for hiding this comment

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

computerFastBounds works for blur (I tested it). But I can use filterBounds instead. However this is one thing I'm unclear about:

void ImageFilterLayer::Preroll(PrerollContext* context,  SkMatrix& matrix) 
...
 if (filter_) {
    const SkIRect filter_input_bounds = child_bounds.roundOut();
    SkIRect filter_output_bounds =
        filter_->filterBounds(filter_input_bounds, SkMatrix::I(), SkImageFilter::kForward_MapDirection);
    child_bounds = SkRect::Make(filter_output_bounds);
}

filterBounds is supposed to map device space rects, so why is it used here on layer space rect?

Copy link
Contributor

Choose a reason for hiding this comment

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

filterBounds maps device space rects wrt the transform you give it, which is Identity in this case.

Copy link
Contributor

Choose a reason for hiding this comment

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

We may be losing some accuracy here. There may be a subtle difference between tx(filterBounds(rect)) and filterBounds(tx(rect)).

Part of me is now wondering why paint bounds is in layer space. I suppose it could be so that retained layers don't change their paint bounds info if an ancestor changes its transform.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah. In most cases, (2x 3x pixel scaling) the paint bounds will be larger than they should be. In case where the layer is scaled down it may actually paint outside of paint_bounds. Not directly related to diffing but something that we might want to fix for partial redraw because it could cause subtle issue for layers that are scaled down.

Copy link
Member Author

Choose a reason for hiding this comment

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

Should be fixed here.

Copy link
Contributor

Choose a reason for hiding this comment

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

The link no longer seems to go anywhere, but in looking through the latest version of this code, I think the filter needs to be used with "makeWithLocalMatrix" as we do here in image_filter_layer when we are applying the filter to a cached version.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed here.

@chinmaygarde chinmaygarde added the Work in progress (WIP) Not ready (yet) for review! label Oct 22, 2020
@knopp knopp force-pushed the diff_context branch 4 times, most recently from 5ad01b7 to dd0bde6 Compare October 31, 2020 01:01
@flar
Copy link
Contributor

flar commented Nov 20, 2020

Looking at the test failures there seems to be a problem with resolving dependencies based on differing NNBD settings. A rebase to ToT might help with that.

Other than that, is there anything else holding this up? Can the WIP labels be removed so we can review this and get it in?

@knopp
Copy link
Member Author

knopp commented Nov 20, 2020

I plan to rebase this over the weekend and put the tests to respective layer test classes.

@knopp knopp changed the title WIP: Add DiffContext Add DiffContext Nov 23, 2020
@flar
Copy link
Contributor

flar commented Nov 30, 2020

Sorry for the delays, I'm going to start a final pass over this today.

if (!context->IsSubtreeDirty()) {
FML_DCHECK(old_layer);
auto prev = old_layer->as_texture_layer();
// TODO(knopp) It would be nice to be able to determine that a texture is
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe file a github issue for this.

@zanderso zanderso requested a review from chinmaygarde December 2, 2020 00:30
@blasten blasten self-requested a review December 7, 2020 18:39
@flar
Copy link
Contributor

flar commented Dec 10, 2020

@chinmaygarde @zanderso the specific files that I would like to see some review from your perspective would be:

main focus:

  • diff_context.[cc,h]

support:

  • scene_builder.[cc,h]
  • layer.[cc,h]
  • container_layer.[cc,h]

the rest of the files fall mainly into the category of just implementing some supporting methods on the various layers, but the new code is focused in the first 2 files above.

Use SkImageFilter::makeWithLocalMatrix to convert the filter to screen space
and then apply the filter in screen space.
@chinmaygarde
Copy link
Member

chinmaygarde commented Feb 18, 2021

@flar Is expecting to land this. @knopp This is good to go right?

@chinmaygarde chinmaygarde added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Feb 18, 2021
@fluttergithubbot fluttergithubbot merged commit cfa1b8e into flutter:master Feb 18, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 19, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 19, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 19, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 19, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 19, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 19, 2021
hjfreyer pushed a commit to hjfreyer/engine that referenced this pull request Mar 22, 2021
chriscraws pushed a commit to chriscraws/engine that referenced this pull request Mar 23, 2021
@knopp knopp deleted the diff_context branch July 17, 2021 09:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants