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

Conversation

@flar
Copy link
Contributor

@flar flar commented Nov 19, 2024

The DlImageFilter code uses Skia geometry classes for its internal computations. This PR switches those implementations to use the Impeller geometry classes for consistency and 3rd party header file independence.

@flar flar force-pushed the dl-image-filter-on-impeller-geometry branch from 981ba0f to 199970f Compare November 20, 2024 00:05
@flar
Copy link
Contributor Author

flar commented Nov 20, 2024

There are just a few lines of code in dl_image_filter.cc that still use the Skia classes for bounds computation as they seem to pass the perspective transform tests better, but otherwise the ImageFilter code is 99.5% migrated to the Impeller classes including what should be 100% of the API (not including the use of SkShader by the runtime effect class). See flutter/flutter#159175 for more information.

@flar flar marked this pull request as ready for review November 20, 2024 01:02
@flutter-dashboard
Copy link

Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change).

If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review.

Changes reported for pull request #56720 at sha 199970f

@flar
Copy link
Contributor Author

flar commented Nov 20, 2024

I find the golden diffs interesting. They are very tiny, but they don't appear (by name) to involve image filters.

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.

Woo, that was a lot to look at. Mostly looking good, here's some notes and questions.

// A backdrop will affect up to the entire surface, bounded by the clip
bool will_be_unbounded = (backdrop != nullptr);
std::shared_ptr<const DlImageFilter> filter;
std::shared_ptr<DlImageFilter> filter;
Copy link
Member

Choose a reason for hiding this comment

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

Why change this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The classes are immutable and I was having trouble with the fact that you can't mix and match shared_ptr with different "const" modifiers.

Copy link
Member

Choose a reason for hiding this comment

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

https://google.github.io/styleguide/cppguide.html#Use_of_const

Immutable classes should have const methods so having a const reference should still be the appropriate usage in c++.

if (global_bounds.intersect(clip)) {
parent_layer().global_space_accumulator.accumulate(global_bounds);
global_bounds = DlRect::Make(global_ibounds);
auto clipped_bounds = global_bounds.Intersection(clip);
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


// |DlCanvas|
void SaveLayer(std::optional<const DlRect>& bounds,
void SaveLayer(const std::optional<DlRect>& bounds,
Copy link
Member

Choose a reason for hiding this comment

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

Why was this changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

const in an optional doesn't really prevent you from changing it, the optional itself has to be const. And at that point, why have the const inside the template type?

Copy link
Member

Choose a reason for hiding this comment

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

why have the const inside the template type?

To make sure no one modifies the DlRect. I would have expected const std::optional<const DlRect>& bounds

namespace flutter {

ImageFilterLayer::ImageFilterLayer(std::shared_ptr<const DlImageFilter> filter,
ImageFilterLayer::ImageFilterLayer(const std::shared_ptr<DlImageFilter>& filter,
Copy link
Member

Choose a reason for hiding this comment

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

I don't think switching these to const references is an improvement. With the std::move there ways to avoid a copy, the const reference forces a copy to happen.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are always called from a reference source that cannot be moved so a copy must happen at some point. It would be better if the copy happened into the layer's local field rather than to the value handed in to the constructor.

Copy link
Member

Choose a reason for hiding this comment

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

You are considering just the code that is written today. There is no way to enforce that this is only called with references.

Comment on lines +281 to +284
// The transform from the local coordinates to the device coordinates
// in 4x4 DlMatrix representation. This matrix provides all information
// needed to compute bounds for a 2D rendering primitive, and it will
// accurately concatenate with other 4x4 matrices without losing information.
Copy link
Member

Choose a reason for hiding this comment

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

Please write as a docstring (ie ///)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

None of the methods in this file are docstring. This is an issue with a scope outside of this change - flutter/flutter#159179

return TRect(0.0, 0.0, size.width, size.height);
}

template <class U, class FT = T>
Copy link
Member

Choose a reason for hiding this comment

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

docstring would help here, it's not immediately clear to me what this is for. it's copying a rect, but why the enable_if_t? If this potentially throwing away precision implicitly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. It's only defined for float destinations. If you want to convert to an integer rect you have to use a method like RoundOut to specify the rounding behavior.


Scalar GetDeterminant() const;

bool IsInvertible() const { return GetDeterminant() != 0; }
Copy link
Contributor

Choose a reason for hiding this comment

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

can you put these in the implementation?

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'm not sure what you are asking?

Copy link
Contributor

Choose a reason for hiding this comment

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

I forget the proper terminology :). Can you put the method bodies in the .cc file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These geometry files seem to prefer inline implementations unless the method is very complicated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

flutter/flutter#159220 - we should reconsider the decisions made in that module separately.

Copy link
Contributor

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

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

LGTM!

@flar flar added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 20, 2024
@auto-submit auto-submit bot merged commit 2d32cf3 into flutter:main Nov 20, 2024
36 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 20, 2024
github-merge-queue bot pushed a commit to flutter/flutter that referenced this pull request Nov 20, 2024
…159226)

flutter/engine@3828681...2d32cf3

2024-11-20 [email protected] [DisplayList] migrate DlImageFilter code to
Impeller geometry classes (flutter/engine#56720)
2024-11-20 [email protected] Split channel messaging out of
handlers (flutter/engine#56667)
2024-11-20 [email protected] Revert "Added assert
for opengles thread safety (#56585)" (flutter/engine#56730)

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 [email protected],[email protected] 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
nick9822 pushed a commit to nick9822/flutter that referenced this pull request Dec 18, 2024
…flutter/engine#56720)

The DlImageFilter code uses Skia geometry classes for its internal computations. This PR switches those implementations to use the Impeller geometry classes for consistency and 3rd party header file independence.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

autosubmit Merge PR when tree becomes green via auto submit App e: impeller platform-ios will affect goldens

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants