-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] simplify invert colors flag by supporting composed color filters. #46391
Changes from 2 commits
ca24ee6
bc1dcab
baa08b7
ccf0ec5
4c15cf3
1b33b1f
dad6ac8
5ff8158
2ca5a11
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 = std::make_shared<MergedColorFilter>( | ||
| std::move(paint_.color_filter), color_filter); | ||
| } 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 = std::make_shared<MergedColorFilter>( | ||
| invert_filter, std::move(paint_.color_filter)); | ||
| } else { | ||
| paint_.color_filter = ColorFilter::MakeMatrix(kColorInversion); | ||
| } | ||
|
Comment on lines
+491
to
+508
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. This sucks but there is no good answer to:
Contributor
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. To solve the composing problem, one possibility would be to add a "GetInverted()" to
Contributor
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. (This is one of those cases where I would clone things liberally to prevent bugs -- the only reason these things are smart pointers is for dynamic dispatch, but like so many things in Impeller, these should really just be discriminated unions, but we currently have an aversion for those in C++)
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. Right, this is 2.5 which is "callers need to be aware of both fields" which I guess is just us, but not idea. |
||
| } | ||
|
|
||
| // |flutter::DlOpReceiver| | ||
|
|
||
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.