Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
border_mask_blur_filter_contents.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
7
12
13namespace impeller {
14
16
18
20 sigma_x_ = sigma_x;
21 sigma_y_ = sigma_y;
22}
23
25 blur_style_ = blur_style;
26
27 switch (blur_style) {
29 src_color_factor_ = false;
30 inner_blur_factor_ = true;
31 outer_blur_factor_ = true;
32 break;
34 src_color_factor_ = true;
35 inner_blur_factor_ = false;
36 outer_blur_factor_ = true;
37 break;
39 src_color_factor_ = false;
40 inner_blur_factor_ = false;
41 outer_blur_factor_ = true;
42 break;
44 src_color_factor_ = false;
45 inner_blur_factor_ = true;
46 outer_blur_factor_ = false;
47 break;
48 }
49}
50
51std::optional<Entity> BorderMaskBlurFilterContents::RenderFilter(
52 const FilterInput::Vector& inputs,
53 const ContentContext& renderer,
54 const Entity& entity,
55 const Matrix& effect_transform,
56 const Rect& coverage,
57 const std::optional<Rect>& coverage_hint) const {
58 using VS = BorderMaskBlurPipeline::VertexShader;
59 using FS = BorderMaskBlurPipeline::FragmentShader;
60
61 //----------------------------------------------------------------------------
62 /// Handle inputs.
63 ///
64
65 if (inputs.empty()) {
66 return std::nullopt;
67 }
68
69 auto input_snapshot =
70 inputs[0]->GetSnapshot("BorderMaskBlur", renderer, entity);
71 if (!input_snapshot.has_value()) {
72 return std::nullopt;
73 }
74
75 auto maybe_input_uvs = input_snapshot->GetCoverageUVs(coverage);
76 if (!maybe_input_uvs.has_value()) {
77 return std::nullopt;
78 }
79 auto input_uvs = maybe_input_uvs.value();
80
81 //----------------------------------------------------------------------------
82 /// Create AnonymousContents for rendering.
83 ///
84
85 auto sigma = effect_transform * Vector2(sigma_x_.sigma, sigma_y_.sigma);
86 RenderProc render_proc = [coverage, input_snapshot, input_uvs = input_uvs,
87 src_color_factor = src_color_factor_,
88 inner_blur_factor = inner_blur_factor_,
89 outer_blur_factor = outer_blur_factor_, sigma](
90 const ContentContext& renderer,
91 const Entity& entity, RenderPass& pass) -> bool {
92 auto& data_host_buffer = renderer.GetTransientsDataBuffer();
93
94 auto origin = coverage.GetOrigin();
95 auto size = coverage.GetSize();
96 std::array<VS::PerVertexData, 4> vertices = {
97 VS::PerVertexData{origin, input_uvs[0]},
98 VS::PerVertexData{{origin.x + size.width, origin.y}, input_uvs[1]},
99 VS::PerVertexData{{origin.x, origin.y + size.height}, input_uvs[2]},
100 VS::PerVertexData{{origin.x + size.width, origin.y + size.height},
101 input_uvs[3]},
102 };
103
104 auto options = OptionsFromPassAndEntity(pass, entity);
105 options.primitive_type = PrimitiveType::kTriangleStrip;
106
107 VS::FrameInfo frame_info;
108 frame_info.mvp = entity.GetShaderTransform(pass);
109
110 FS::FragInfo frag_info;
111 frag_info.sigma_uv = sigma.Abs() / input_snapshot->texture->GetSize();
112 frag_info.src_factor = src_color_factor;
113 frag_info.inner_blur_factor = inner_blur_factor;
114 frag_info.outer_blur_factor = outer_blur_factor;
115
116 pass.SetCommandLabel("Border Mask Blur Filter");
117 pass.SetPipeline(renderer.GetBorderMaskBlurPipeline(options));
118 pass.SetVertexBuffer(CreateVertexBuffer(vertices, data_host_buffer));
119
120 FS::BindFragInfo(pass, data_host_buffer.EmplaceUniform(frag_info));
121 VS::BindFrameInfo(pass, data_host_buffer.EmplaceUniform(frame_info));
122
123 raw_ptr<const Sampler> sampler =
124 renderer.GetContext()->GetSamplerLibrary()->GetSampler({});
125 FS::BindTextureSampler(pass, input_snapshot->texture, sampler);
126
127 return pass.Draw().ok();
128 };
129
130 CoverageProc coverage_proc =
131 [coverage](const Entity& entity) -> std::optional<Rect> {
132 return coverage.TransformBounds(entity.GetTransform());
133 };
134
135 auto contents = AnonymousContents::Make(render_proc, coverage_proc);
136
137 Entity sub_entity;
138 sub_entity.SetContents(std::move(contents));
139 sub_entity.SetBlendMode(entity.GetBlendMode());
140 return sub_entity;
141}
142
144 const FilterInput::Vector& inputs,
145 const Entity& entity,
146 const Matrix& effect_transform) const {
147 if (inputs.empty()) {
148 return std::nullopt;
149 }
150
151 auto coverage = inputs[0]->GetCoverage(entity);
152 if (!coverage.has_value()) {
153 return std::nullopt;
154 }
155 auto transform = inputs[0]->GetTransform(entity) * effect_transform;
156 auto transformed_blur_vector =
157 transform.TransformDirection(Vector2(Radius{sigma_x_}.radius, 0)).Abs() +
158 transform.TransformDirection(Vector2(0, Radius{sigma_y_}.radius)).Abs();
159 return coverage->Expand(transformed_blur_vector);
160}
161
163 const Matrix& effect_transform,
164 const Rect& output_limit) const {
165 auto transformed_blur_vector =
166 effect_transform.TransformDirection(Vector2(Radius{sigma_x_}.radius, 0))
167 .Abs() +
168 effect_transform.TransformDirection(Vector2(0, Radius{sigma_y_}.radius))
169 .Abs();
170 return output_limit.Expand(transformed_blur_vector);
171}
172
173} // namespace impeller
static std::shared_ptr< Contents > Make(RenderProc render_proc, CoverageProc coverage_proc)
std::optional< Rect > GetFilterCoverage(const FilterInput::Vector &inputs, const Entity &entity, const Matrix &effect_transform) const override
Internal utility method for |GetLocalCoverage| that computes the output coverage of this filter acros...
std::optional< Rect > GetFilterSourceCoverage(const Matrix &effect_transform, const Rect &output_limit) const override
Internal utility method for |GetSourceCoverage| that computes the inverse effect of this transform on...
std::function< std::optional< Rect >(const Entity &entity)> CoverageProc
Definition contents.h:40
std::function< bool(const ContentContext &renderer, const Entity &entity, RenderPass &pass)> RenderProc
Definition contents.h:39
@ kNormal
Blurred inside and outside.
@ kOuter
Nothing inside, blurred outside.
@ kInner
Blurred inside, nothing outside.
@ kSolid
Solid inside, blurred outside.
std::vector< FilterInput::Ref > Vector
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Point Vector2
Definition point.h:430
LinePipeline::FragmentShader FS
VertexBuffer CreateVertexBuffer(std::array< VertexType, size > input, HostBuffer &data_host_buffer)
Create an index-less vertex buffer from a fixed size array.
LinePipeline::VertexShader VS
ContentContextOptions OptionsFromPassAndEntity(const RenderPass &pass, const Entity &entity)
Definition contents.cc:34
A 4x4 matrix using column-major storage.
Definition matrix.h:37
constexpr Vector4 TransformDirection(const Vector4 &v) const
Definition matrix.h:615
For convolution filters, the "radius" is the size of the convolution kernel to use on the local space...
Definition sigma.h:48
In filters that use Gaussian distributions, "sigma" is a size of one standard deviation in terms of t...
Definition sigma.h:32
Scalar sigma
Definition sigma.h:33
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
Definition rect.h:506
constexpr TSize< Type > GetSize() const
Returns the size of the rectangle which may be negative in either width or height and may have been c...
Definition rect.h:361
constexpr TRect< T > Expand(T left, T top, T right, T bottom) const
Returns a rectangle with expanded edges. Negative expansion results in shrinking.
Definition rect.h:652
constexpr TPoint< Type > GetOrigin() const
Returns the upper left corner of the rectangle as specified by the left/top or x/y values when it was...
Definition rect.h:354