-
Notifications
You must be signed in to change notification settings - Fork 18
Make the filter DAG render all textures at the correct resolution #99
Conversation
7133ce2
to
61f017b
Compare
97b8df0
to
e853a2c
Compare
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.
Overall looks good but I think there is an opportunity to handle this without static pointer casts. I've provided suggestions inline but happy to discuss alternatives. Rest are API UX and styling nits.
@@ -442,6 +442,7 @@ TEST_F(AiksTest, TransformMultipliesCorrectly) { | |||
-3, 0, 0, 0, | |||
0, 0, 0, 0, | |||
-500, 400, 0, 1)); | |||
// clang-format on |
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.
Good catch.
void DirectionalGaussianBlurFilterContents::SetClipBorder(bool clip) { | ||
clip_ = clip; | ||
void DirectionalGaussianBlurFilterContents::SetBlurVector(Vector2 blur_vector) { | ||
if (blur_vector.GetLengthSquared() < 1e-3f) { |
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.
Maybe we should put Scalar kEhCloseEnough = 1e-3f;
in scalar.h
as I've seen this used in a couple of spots now.
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.
Done. Good name. 😄
@@ -3,8 +3,11 @@ | |||
// found in the LICENSE file. | |||
|
|||
#include "impeller/entity/contents/filters/gaussian_blur_filter_contents.h" | |||
#include <valarray> |
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.
Uber small nit: Newline between different include types.
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.
Done.
@@ -11,7 +11,8 @@ namespace impeller { | |||
class BlendFilterContents : public FilterContents { | |||
public: | |||
using AdvancedBlendProc = std::function<bool( | |||
const std::vector<std::shared_ptr<Texture>>& input_textures, | |||
const std::vector<std::tuple<std::shared_ptr<Texture>, Rect>>& |
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.
Not a huge fan of tuples from an API UX perspective. It is hard to tell what the Rect
is meant to be and even harder to document it (later perhaps) using headerdoc and have editors and IDEs provide inline hints for it. Prefer a struct that does the same.
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.
sgtm, I had a thonk about this and ended up standardizing around "snapshot" for this. Let me know what you think.
@@ -48,32 +51,29 @@ std::shared_ptr<FilterContents> FilterContents::MakeBlend( | |||
new_blend->SetBlendMode(blend_mode); | |||
blend = new_blend; | |||
} | |||
return std::get<std::shared_ptr<FilterContents>>(blend); | |||
auto contents = std::get<std::shared_ptr<Contents>>(blend); | |||
// This downcast is safe because we know blend is a BlendFilterContents. |
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.
FML_DCHECK(contents->IsFilter) << "This downcast is safe because we know blend is a BlendFilterContents"
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.
IsFilter
no longer exists, but maybe we can do some type trickery to compare the vtable ptr? Stuff like &contents->RenderToTexture == &FilterContents::RenderToTexture
doesn't work in clang.
entity/contents/contents.h
Outdated
@@ -33,6 +34,14 @@ class Contents { | |||
const Entity& entity, | |||
RenderPass& pass) const = 0; | |||
|
|||
/// @brief Returns true if this Contents is a FilterContents. This is useful | |||
/// for downcasting to FilterContents without RTTI. | |||
virtual bool IsFilter() const; |
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.
I wonder if we are going down the path of reinventing RTTI (poorly)? I works great for simpler use cases but quickly gets out of hand.
Presumably, you are using this so you can perform the filter resolve later. Can this not be handled by a virtual that returns a resolved texture that only filters can provide an implementation for?
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.
Done. I added RenderToTexture
to Contents instead of having the filter do this dispatch inline.
Note that all contents can actually be rendered to a texture, which makes your approach doubly good.
We'll likely need this in a number of non-filter situations down the line too, so we would have eventually ended up with this design by necessity. Now that I think about it, RenderToTexture
is probably the real star of the show in this PR. :)
…s through the filter graph, make gaussian blur interface match Skia better
22a0abc
to
98b7fbd
Compare
This changes a lot about how the filters work and lines us up to make the paint image filter/advanced blends work. A lot of the changes here were made on the fly in order to avoid landing intermediary changes that reduce functionality.
Changes:
FilterContents
has enough information at render any contents to a texture at the correct end resolution, and so I extended filter inputs to allow for any Contents type in addition to filters and textures. This will make supporting the paint filter very easy.Optimization ideas for later:
Screen.Recording.2022-03-22.at.7.51.00.PM.mov
Usage: