42 std::optional<Rect> bounds,
45 auto blur = std::make_shared<GaussianBlurFilterContents>(
46 sigma_x.
sigma, sigma_y.
sigma, tile_mode, bounds, mask_blur_style,
48 blur->SetInputs({
input});
57 auto filter = std::make_shared<BorderMaskBlurFilterContents>();
58 filter->SetInputs({std::move(
input)});
59 filter->SetSigma(sigma_x, sigma_y);
60 filter->SetBlurStyle(blur_style);
69 auto filter = std::make_shared<DirectionalMorphologyFilterContents>();
70 filter->SetInputs({std::move(
input)});
71 filter->SetRadius(radius);
72 filter->SetDirection(direction);
73 filter->SetMorphType(morph_type);
83 Point(1, 0), morph_type);
93 auto filter = std::make_shared<MatrixFilterContents>();
94 filter->SetInputs({std::move(
input)});
95 filter->SetMatrix(matrix);
96 filter->SetSamplerDescriptor(desc);
103 auto filter = std::make_shared<LocalMatrixFilterContents>();
104 filter->SetInputs({std::move(
input)});
105 filter->SetMatrix(matrix);
110 std::shared_ptr<Texture> y_texture,
111 std::shared_ptr<Texture> uv_texture,
113 auto filter = std::make_shared<impeller::YUVToRGBFilterContents>();
116 filter->SetYUVColorSpace(yuv_color_space);
122 std::shared_ptr<RuntimeStage> runtime_stage,
123 std::shared_ptr<std::vector<uint8_t>> uniforms,
124 std::vector<RuntimeEffectContents::TextureInput> texture_inputs) {
125 auto filter = std::make_shared<impeller::RuntimeEffectFilterContents>();
126 filter->SetInputs({std::move(
input)});
127 filter->SetRuntimeStage(std::move(runtime_stage));
128 filter->SetUniforms(std::move(uniforms));
129 filter->SetTextureInputs(std::move(texture_inputs));
138 inputs_ = std::move(inputs);
142 effect_transform_ = effect_transform;
144 for (
auto&
input : inputs_) {
145 input->SetEffectTransform(effect_transform);
153 if (!filter_coverage.has_value()) {
160 if (!maybe_entity.has_value()) {
164 return maybe_entity->Render(renderer, pass);
167std::optional<Rect> FilterContents::GetLocalCoverage(
168 const Entity& local_entity)
const {
169 auto coverage = GetFilterCoverage(inputs_, local_entity, effect_transform_);
171 if (coverage_hint.has_value() && coverage.has_value()) {
172 coverage = coverage->Intersection(coverage_hint.value());
179 Entity entity_with_local_transform = entity.
Clone();
182 return GetLocalCoverage(entity_with_local_transform);
185std::optional<Rect> FilterContents::GetFilterCoverage(
188 const Matrix& effect_transform)
const {
193 if (inputs_.empty()) {
197 std::optional<Rect> result;
198 for (
const auto&
input : inputs) {
199 auto coverage =
input->GetCoverage(entity);
200 if (!coverage.has_value()) {
203 if (!result.has_value()) {
207 result = result->Union(coverage.value());
213 const Matrix& effect_transform,
214 const Rect& output_limit)
const {
215 auto filter_input_coverage =
216 GetFilterSourceCoverage(effect_transform_, output_limit);
218 if (!filter_input_coverage.has_value()) {
222 std::optional<Rect> inputs_coverage;
223 for (
const auto&
input : inputs_) {
224 auto input_coverage =
input->GetSourceCoverage(
225 effect_transform, filter_input_coverage.value());
226 if (!input_coverage.has_value()) {
229 inputs_coverage =
Rect::Union(inputs_coverage, input_coverage.value());
231 return inputs_coverage;
237 const std::optional<Rect>& coverage_hint)
const {
238 Entity entity_with_local_transform = entity.
Clone();
241 std::optional<Rect> coverage = GetLocalCoverage(entity_with_local_transform);
242 if (!coverage.has_value() || coverage->IsEmpty()) {
246 return RenderFilter(inputs_,
248 entity_with_local_transform,
261 if (std::optional<Entity> result =
263 result.has_value()) {
264 return result->GetContents()->RenderToSnapshot(
265 renderer, result.value(),
267 .sampler_descriptor = std::nullopt,
268 .msaa_enabled =
true,
270 .label = options.
label});
285 for (
auto&
input : inputs_) {
286 input->SetRenderingMode(rendering_mode);
const std::optional< Rect > & GetCoverageHint() const
void SetTransform(const Matrix &transform)
Set the global transform matrix for this Entity.
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
uint32_t GetClipDepth() const
static std::shared_ptr< FilterContents > MakeGaussianBlur(const FilterInput::Ref &input, Sigma sigma_x, Sigma sigma_y, Entity::TileMode tile_mode=Entity::TileMode::kDecal, std::optional< Rect > bounds=std::nullopt, BlurStyle mask_blur_style=BlurStyle::kNormal, const Geometry *mask_geometry=nullptr)
static const int32_t kBlurFilterRequiredMipCount
std::optional< Entity > GetEntity(const ContentContext &renderer, const Entity &entity, const std::optional< Rect > &coverage_hint) const
Create an Entity that renders this filter's output.
static std::shared_ptr< FilterContents > MakeDirectionalMorphology(FilterInput::Ref input, Radius radius, Vector2 direction, MorphType morph_type)
std::optional< Rect > GetCoverage(const Entity &entity) const override
Get the area of the render pass that will be affected when this contents is rendered.
~FilterContents() override
Matrix GetTransform(const Matrix &parent_transform) const
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
static std::shared_ptr< FilterContents > MakeMorphology(FilterInput::Ref input, Radius radius_x, Radius radius_y, MorphType morph_type)
static std::shared_ptr< FilterContents > MakeRuntimeEffect(FilterInput::Ref input, std::shared_ptr< RuntimeStage > runtime_stage, std::shared_ptr< std::vector< uint8_t > > uniforms, std::vector< RuntimeEffectContents::TextureInput > texture_inputs)
static std::shared_ptr< FilterContents > MakeBorderMaskBlur(FilterInput::Ref input, Sigma sigma_x, Sigma sigma_y, BlurStyle blur_style=BlurStyle::kNormal)
static std::shared_ptr< FilterContents > MakeLocalMatrixFilter(FilterInput::Ref input, const Matrix &matrix)
std::optional< Snapshot > RenderToSnapshot(const ContentContext &renderer, const Entity &entity, const SnapshotOptions &options) const override
Render this contents to a snapshot, respecting the entity's transform, path, clip depth,...
void SetInputs(FilterInput::Vector inputs)
The input texture sources for this filter. Each input's emitted texture is expected to have premultip...
virtual void SetRenderingMode(Entity::RenderingMode rendering_mode)
Marks this filter chain as applying in a subpass scenario.
std::optional< Rect > GetSourceCoverage(const Matrix &effect_transform, const Rect &output_limit) const
Determines the coverage of source pixels that will be needed to produce results for the specified |ou...
void SetEffectTransform(const Matrix &effect_transform)
Sets the transform which gets appended to the effect of this filter. Note that this is in addition to...
static std::shared_ptr< FilterContents > MakeMatrixFilter(FilterInput::Ref input, const Matrix &matrix, const SamplerDescriptor &desc)
static std::shared_ptr< FilterContents > MakeYUVToRGBFilter(std::shared_ptr< Texture > y_texture, std::shared_ptr< Texture > uv_texture, YUVColorSpace yuv_color_space)
virtual Matrix GetLocalTransform(const Matrix &parent_transform) const
Render passes encode render commands directed as one specific render target into an underlying comman...
std::optional< Rect > coverage_limit
A 4x4 matrix using column-major storage.
For convolution filters, the "radius" is the size of the convolution kernel to use on the local space...
In filters that use Gaussian distributions, "sigma" is a size of one standard deviation in terms of t...
constexpr TRect Union(const TRect &o) const