Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
complex_rse_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
6
11
12namespace impeller {
13
14namespace {
15
16using PipelineBuilderCallback =
17 std::function<PipelineRef(ContentContextOptions)>;
18
19using VS = ComplexRSEPipeline::VertexShader;
20using FS = ComplexRSEPipeline::FragmentShader;
21
22} // namespace
23
24std::unique_ptr<ComplexRoundedSuperellipseContents>
26 Color color,
27 const Rect& bounds,
28 const RoundSuperellipseParam& round_superellipse_params,
29 std::optional<StrokeParameters> stroke) {
30 return std::unique_ptr<ComplexRoundedSuperellipseContents>(
32 color, bounds, round_superellipse_params, stroke));
33}
34
35ComplexRoundedSuperellipseContents::ComplexRoundedSuperellipseContents(
36 Color color,
37 const Rect& bounds,
38 const RoundSuperellipseParam& round_superellipse_params,
39 std::optional<StrokeParameters> stroke)
40 : color_(color),
41 bounds_(bounds),
42 round_superellipse_params_(round_superellipse_params),
43 stroke_(stroke) {
44 if (stroke) {
45 geometry_ = Geometry::MakeRect(bounds_.Expand(stroke->width / 2.0f));
46 } else {
47 geometry_ = Geometry::MakeRect(bounds_);
48 }
49}
50
52 const Entity& entity,
53 RenderPass& pass) const {
54 auto& data_host_buffer = renderer.GetTransientsDataBuffer();
55
56 Point center = bounds_.GetCenter();
57
59 round_superellipse_params_.top_right;
61 round_superellipse_params_.bottom_right;
63 round_superellipse_params_.bottom_left;
65 round_superellipse_params_.top_left;
66
67 Point top_right_center_relative = top_right.offset - center;
68 Point bottom_right_center_relative = bottom_right.offset - center;
69 Point bottom_left_center_relative = bottom_left.offset - center;
70 Point top_left_center_relative = top_left.offset - center;
71
72 Point size = Point(bounds_.GetSize() * 0.5f);
73
74 VS::FrameInfo frame_info;
75 FS::FragInfo frag_info;
76
77 frag_info.color = color_.WithAlpha(color_.alpha * GetOpacityFactor());
78 frag_info.center = center;
79 frag_info.size = size;
80 frag_info.stroked = stroke_ ? 1.0f : 0.0f;
81 frag_info.stroke_width = stroke_ ? stroke_->width : 0.0f;
82
83 frag_info.superellipse_degrees_top =
84 Vector4(bottom_right.top.se_n, top_right.top.se_n, bottom_left.top.se_n,
85 top_left.top.se_n);
86 frag_info.superellipse_degrees_right =
87 Vector4(bottom_right.right.se_n, top_right.right.se_n,
88 bottom_left.right.se_n, top_left.right.se_n);
89 frag_info.superellipse_semi_axes_top =
90 Vector4(bottom_right.top.se_a, top_right.top.se_a, bottom_left.top.se_a,
91 top_left.top.se_a);
92 frag_info.superellipse_semi_axes_right =
93 Vector4(bottom_right.right.se_a, top_right.right.se_a,
94 bottom_left.right.se_a, top_left.right.se_a);
95 frag_info.angle_spans_top = Vector4(bottom_right.top.circle_max_angle.radians,
97 bottom_left.top.circle_max_angle.radians,
99 frag_info.angle_spans_right =
102 bottom_left.right.circle_max_angle.radians,
104 frag_info.octant_offsets_c =
105 Vector4(bottom_right.top.se_a - bottom_right.right.se_a,
106 top_right.top.se_a - top_right.right.se_a,
107 bottom_left.top.se_a - bottom_left.right.se_a,
108 top_left.top.se_a - top_left.right.se_a);
109 frag_info.radii_width =
110 Vector4(bottom_right.top.circle_radius, top_right.top.circle_radius,
111 bottom_left.top.circle_radius, top_left.top.circle_radius);
112 frag_info.radii_height =
113 Vector4(bottom_right.right.circle_radius, top_right.right.circle_radius,
114 bottom_left.right.circle_radius, top_left.right.circle_radius);
115 frag_info.circle_centers_top_x =
116 Vector4(bottom_right.top.circle_center.x, top_right.top.circle_center.x,
117 bottom_left.top.circle_center.x, top_left.top.circle_center.x);
118 frag_info.circle_centers_top_y =
119 Vector4(bottom_right.top.circle_center.y, top_right.top.circle_center.y,
120 bottom_left.top.circle_center.y, top_left.top.circle_center.y);
121 frag_info.circle_centers_right_x = Vector4(
122 bottom_right.right.circle_center.x, top_right.right.circle_center.x,
123 bottom_left.right.circle_center.x, top_left.right.circle_center.x);
124 frag_info.circle_centers_right_y = Vector4(
125 bottom_right.right.circle_center.y, top_right.right.circle_center.y,
126 bottom_left.right.circle_center.y, top_left.right.circle_center.y);
127 frag_info.superellipse_scales_x =
128 Vector4(bottom_right.signed_scale.Abs().x, top_right.signed_scale.Abs().x,
129 bottom_left.signed_scale.Abs().x, top_left.signed_scale.Abs().x);
130 frag_info.superellipse_scales_y =
131 Vector4(bottom_right.signed_scale.Abs().y, top_right.signed_scale.Abs().y,
132 bottom_left.signed_scale.Abs().y, top_left.signed_scale.Abs().y);
133 frag_info.quadrant_centers_x =
134 Vector4(bottom_right_center_relative.x, top_right_center_relative.x,
135 bottom_left_center_relative.x, top_left_center_relative.x);
136 frag_info.quadrant_centers_y =
137 Vector4(bottom_right_center_relative.y, top_right_center_relative.y,
138 bottom_left_center_relative.y, top_left_center_relative.y);
139 frag_info.quadrant_splits =
140 Vector4(round_superellipse_params_.top_split - center.x,
141 round_superellipse_params_.bottom_split - center.x,
142 round_superellipse_params_.left_split - center.y,
143 round_superellipse_params_.right_split - center.y);
144
145 auto geometry_result =
146 GetGeometry()->GetPositionBuffer(renderer, entity, pass);
147
148 PipelineBuilderCallback pipeline_callback =
149 [&renderer](ContentContextOptions options) {
150 return renderer.GetComplexRSEPipeline(options);
151 };
152
153 return ColorSourceContents::DrawGeometry<VS>(
154 this, GetGeometry(), renderer, entity, pass, pipeline_callback,
155 frame_info,
156 /*bind_fragment_callback=*/
157 [&frag_info, &data_host_buffer](RenderPass& pass) {
158 FS::BindFragInfo(pass, data_host_buffer.EmplaceUniform(frag_info));
159 return true;
160 });
161}
162
164 const Entity& entity) const {
165 return GetGeometry()->GetCoverage(entity.GetTransform());
166}
167
169 return geometry_.get();
170}
171
172} // namespace impeller
Scalar GetOpacityFactor() const
Get the opacity factor for this color source.
std::function< PipelineRef(ContentContextOptions)> PipelineBuilderCallback
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
static std::unique_ptr< ComplexRoundedSuperellipseContents > Make(Color color, const Rect &bounds, const RoundSuperellipseParam &round_superellipse_params, std::optional< StrokeParameters > stroke)
const Geometry * GetGeometry() const override
Get the geometry that this contents will use to render.
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.
HostBuffer & GetTransientsDataBuffer() const
Retrieve the current host buffer for transient storage of other non-index data.
PipelineRef GetComplexRSEPipeline(ContentContextOptions opts) const
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
Definition entity.cc:46
virtual std::optional< Rect > GetCoverage(const Matrix &transform) const =0
The coverage rectangle of this geometry, transformed by the transform argument.
static std::unique_ptr< Geometry > MakeRect(const Rect &rect)
Definition geometry.cc:83
virtual GeometryResult GetPositionBuffer(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const =0
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition render_pass.h:30
TPoint< Scalar > Point
Definition point.h:426
raw_ptr< Pipeline< PipelineDescriptor > > PipelineRef
A raw ptr to a pipeline object.
Definition pipeline.h:89
LinePipeline::FragmentShader FS
LinePipeline::VertexShader VS
Scalar alpha
Definition color.h:143
constexpr Color WithAlpha(Scalar new_alpha) const
Definition color.h:283
Scalar radians
Definition scalar.h:45
constexpr TPoint Abs() const
Definition point.h:294
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 Point GetCenter() const
Get the center point as a |Point|.
Definition rect.h:416