15 #include "flutter/fml/logging.h"
44 auto blur = std::make_shared<GaussianBlurFilterContents>(
45 sigma_x.
sigma, sigma_y.
sigma, tile_mode, mask_blur_style, mask_geometry);
46 blur->SetInputs({input});
55 auto filter = std::make_shared<BorderMaskBlurFilterContents>();
56 filter->SetInputs({std::move(input)});
57 filter->SetSigma(sigma_x, sigma_y);
58 filter->SetBlurStyle(blur_style);
67 auto filter = std::make_shared<DirectionalMorphologyFilterContents>();
68 filter->SetInputs({std::move(input)});
69 filter->SetRadius(radius);
70 filter->SetDirection(direction);
71 filter->SetMorphType(morph_type);
81 Point(1, 0), morph_type);
91 auto filter = std::make_shared<MatrixFilterContents>();
92 filter->SetInputs({std::move(input)});
93 filter->SetMatrix(matrix);
94 filter->SetSamplerDescriptor(desc);
101 auto filter = std::make_shared<LocalMatrixFilterContents>();
102 filter->SetInputs({std::move(input)});
103 filter->SetMatrix(matrix);
108 std::shared_ptr<Texture> y_texture,
109 std::shared_ptr<Texture> uv_texture,
111 auto filter = std::make_shared<impeller::YUVToRGBFilterContents>();
114 filter->SetYUVColorSpace(yuv_color_space);
120 std::shared_ptr<RuntimeStage> runtime_stage,
121 std::shared_ptr<std::vector<uint8_t>> uniforms,
122 std::vector<RuntimeEffectContents::TextureInput> texture_inputs) {
123 auto filter = std::make_shared<impeller::RuntimeEffectFilterContents>();
124 filter->SetInputs({std::move(input)});
125 filter->SetRuntimeStage(std::move(runtime_stage));
126 filter->SetUniforms(std::move(uniforms));
127 filter->SetTextureInputs(std::move(texture_inputs));
136 inputs_ = std::move(inputs);
140 effect_transform_ = effect_transform;
142 for (
auto& input : inputs_) {
143 input->SetEffectTransform(effect_transform);
151 if (!filter_coverage.has_value()) {
158 if (!maybe_entity.has_value()) {
162 return maybe_entity->Render(renderer, pass);
165 std::optional<Rect> FilterContents::GetLocalCoverage(
166 const Entity& local_entity)
const {
167 auto coverage = GetFilterCoverage(inputs_, local_entity, effect_transform_);
169 if (coverage_hint.has_value() && coverage.has_value()) {
170 coverage = coverage->Intersection(coverage_hint.value());
177 Entity entity_with_local_transform = entity.
Clone();
180 return GetLocalCoverage(entity_with_local_transform);
183 std::optional<Rect> FilterContents::GetFilterCoverage(
186 const Matrix& effect_transform)
const {
191 if (inputs_.empty()) {
195 std::optional<Rect> result;
196 for (
const auto& input : inputs) {
197 auto coverage = input->GetCoverage(entity);
198 if (!coverage.has_value()) {
201 if (!result.has_value()) {
205 result = result->Union(coverage.value());
211 const Matrix& effect_transform,
212 const Rect& output_limit)
const {
213 auto filter_input_coverage =
214 GetFilterSourceCoverage(effect_transform_, output_limit);
216 if (!filter_input_coverage.has_value()) {
220 std::optional<Rect> inputs_coverage;
221 for (
const auto& input : inputs_) {
222 auto input_coverage = input->GetSourceCoverage(
223 effect_transform, filter_input_coverage.value());
224 if (!input_coverage.has_value()) {
227 inputs_coverage =
Rect::Union(inputs_coverage, input_coverage.value());
229 return inputs_coverage;
235 const std::optional<Rect>& coverage_hint)
const {
236 Entity entity_with_local_transform = entity.
Clone();
239 std::optional<Rect> coverage = GetLocalCoverage(entity_with_local_transform);
240 if (!coverage.has_value() || coverage->IsEmpty()) {
244 return RenderFilter(inputs_,
246 entity_with_local_transform,
256 std::optional<Rect> coverage_limit,
257 const std::optional<SamplerDescriptor>& sampler_descriptor,
260 std::string_view label)
const {
263 if (std::optional<Entity> result =
264 GetEntity(renderer, entity, coverage_limit);
265 result.has_value()) {
266 return result->GetContents()->RenderToSnapshot(
289 for (
auto& input : inputs_) {
290 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 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 > 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)
static std::shared_ptr< FilterContents > MakeGaussianBlur(const FilterInput::Ref &input, Sigma sigma_x, Sigma sigma_y, Entity::TileMode tile_mode=Entity::TileMode::kDecal, BlurStyle mask_blur_style=BlurStyle::kNormal, const Geometry *mask_geometry=nullptr)
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)
std::optional< Snapshot > RenderToSnapshot(const ContentContext &renderer, const Entity &entity, std::optional< Rect > coverage_limit=std::nullopt, const std::optional< SamplerDescriptor > &sampler_descriptor=std::nullopt, bool msaa_enabled=true, int32_t mip_count=1, std::string_view label="Filter Snapshot") const override
Render this contents to a snapshot, respecting the entity's transform, path, clip depth,...
static std::shared_ptr< FilterContents > MakeYUVToRGBFilter(std::shared_ptr< Texture > y_texture, std::shared_ptr< Texture > uv_texture, YUVColorSpace yuv_color_space)
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)
virtual Matrix GetLocalTransform(const Matrix &parent_transform) const
Render passes encode render commands directed as one specific render target into an underlying comman...
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