This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] simplify invert colors flag by supporting composed color filters. #46391
Merged
auto-submit
merged 9 commits into
flutter:main
from
jonahwilliams:simplify_invert_colors
Sep 29, 2023
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ca24ee6
[Impeller] Simplify invert colors.
bc1dcab
++
baa08b7
rename to composed
ccf0ec5
++
4c15cf3
++
1b33b1f
++
dad6ac8
Update dl_dispatcher.cc
5ff8158
Update dl_dispatcher.cc
2ca5a11
Update dl_dispatcher.cc
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,6 @@ | |
|
|
||
| #include "impeller/aiks/canvas.h" | ||
|
|
||
| #include <algorithm> | ||
| #include <optional> | ||
| #include <utility> | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,28 +8,20 @@ | |
| #include <cstring> | ||
| #include <memory> | ||
| #include <optional> | ||
| #include <unordered_map> | ||
| #include <utility> | ||
| #include <vector> | ||
|
|
||
| #include "flutter/fml/logging.h" | ||
| #include "flutter/fml/trace_event.h" | ||
| #include "impeller/aiks/color_filter.h" | ||
| #include "impeller/core/formats.h" | ||
| #include "impeller/display_list/dl_image_impeller.h" | ||
| #include "impeller/display_list/dl_vertices_geometry.h" | ||
| #include "impeller/display_list/nine_patch_converter.h" | ||
| #include "impeller/display_list/skia_conversions.h" | ||
| #include "impeller/entity/contents/conical_gradient_contents.h" | ||
| #include "impeller/entity/contents/filters/filter_contents.h" | ||
| #include "impeller/entity/contents/filters/inputs/filter_input.h" | ||
| #include "impeller/entity/contents/linear_gradient_contents.h" | ||
| #include "impeller/entity/contents/radial_gradient_contents.h" | ||
| #include "impeller/entity/contents/runtime_effect_contents.h" | ||
| #include "impeller/entity/contents/sweep_gradient_contents.h" | ||
| #include "impeller/entity/contents/tiled_texture_contents.h" | ||
| #include "impeller/entity/entity.h" | ||
| #include "impeller/entity/geometry/geometry.h" | ||
| #include "impeller/geometry/path.h" | ||
| #include "impeller/geometry/path_builder.h" | ||
| #include "impeller/geometry/scalar.h" | ||
|
|
@@ -41,6 +33,18 @@ | |
|
|
||
| namespace impeller { | ||
|
|
||
| /// A color matrix which inverts colors. | ||
| // clang-format off | ||
| constexpr ColorMatrix kColorInversion = { | ||
| .array = { | ||
| -1.0, 0, 0, 1.0, 0, // | ||
| 0, -1.0, 0, 1.0, 0, // | ||
| 0, 0, -1.0, 1.0, 0, // | ||
| 1.0, 1.0, 1.0, 1.0, 0 // | ||
| } | ||
| }; | ||
| // clang-format on | ||
|
|
||
| #define UNIMPLEMENTED \ | ||
| FML_DLOG(ERROR) << "Unimplemented detail in " << __FUNCTION__; | ||
|
|
||
|
|
@@ -484,12 +488,24 @@ static std::shared_ptr<ColorFilter> ToColorFilter( | |
| // |flutter::DlOpReceiver| | ||
| void DlDispatcher::setColorFilter(const flutter::DlColorFilter* filter) { | ||
| // Needs https://github.com/flutter/flutter/issues/95434 | ||
| paint_.color_filter = ToColorFilter(filter); | ||
| if (paint_.color_filter) { | ||
| auto color_filter = ToColorFilter(filter); | ||
| paint_.color_filter = | ||
| ColorFilter::MakeComposed(paint_.color_filter, color_filter); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the paint state get cleared out between every draw call? I think this solution implicitly relies on
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ugh yeah
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I hate this
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reverted! |
||
| } else { | ||
| paint_.color_filter = ToColorFilter(filter); | ||
| } | ||
| } | ||
|
|
||
| // |flutter::DlOpReceiver| | ||
| void DlDispatcher::setInvertColors(bool invert) { | ||
| paint_.invert_colors = invert; | ||
| if (paint_.color_filter) { | ||
| auto invert_filter = ColorFilter::MakeMatrix(kColorInversion); | ||
| paint_.color_filter = | ||
| ColorFilter::MakeComposed(invert_filter, paint_.color_filter); | ||
| } else { | ||
| paint_.color_filter = ColorFilter::MakeMatrix(kColorInversion); | ||
| } | ||
| } | ||
|
|
||
| // |flutter::DlOpReceiver| | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now defined in at least three places - it'd be nice if it could live in some common header somewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could pull this logic all the way up too painting.dart but then we wont be able to test it with impeller yet. For the purposes of this test though it doesn't really matter what the filter is, just that it composes.