Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
circle_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
10
11namespace impeller {
12
13namespace {
14using PipelineBuilderCallback =
15 std::function<PipelineRef(ContentContextOptions)>;
16
17using VS = CirclePipeline::VertexShader;
18using FS = CirclePipeline::FragmentShader;
19
20} // namespace
21
22std::unique_ptr<CircleContents> CircleContents::Make(
23 std::unique_ptr<CircleGeometry> geometry,
24 Color color,
25 bool stroked) {
26 Scalar aa_padding = geometry->GetAntialiasPadding();
27 return std::unique_ptr<CircleContents>(
28 new CircleContents(std::move(geometry), color, stroked, aa_padding));
29}
30
31CircleContents::CircleContents(std::unique_ptr<CircleGeometry> geometry,
32 Color color,
33 bool stroked,
34 Scalar aa_padding)
35 : geometry_(std::move(geometry)),
36 color_(color),
37 stroked_(stroked),
38 aa_padding_(aa_padding) {}
39
41 const Entity& entity,
42 RenderPass& pass) const {
43 auto& data_host_buffer = renderer.GetTransientsDataBuffer();
44
45 VS::FrameInfo frame_info;
46 FS::FragInfo frag_info;
47 frag_info.color = color_.WithAlpha(color_.alpha * GetOpacityFactor());
48 frag_info.center = geometry_->GetCenter();
49 frag_info.radius = geometry_->GetRadius();
50 frag_info.stroke_width = geometry_->GetStrokeWidth();
51 frag_info.aa_pixels = aa_padding_;
52 frag_info.stroked = stroked_ ? 1.0f : 0.0f;
53
54 auto geometry_result = geometry_->GetPositionBuffer(renderer, entity, pass);
55
56 PipelineBuilderCallback pipeline_callback =
57 [&renderer](ContentContextOptions options) {
58 return renderer.GetCirclePipeline(options);
59 };
60
61 return ColorSourceContents::DrawGeometry<VS>(
62 this, geometry_.get(), renderer, entity, pass, pipeline_callback,
63 frame_info,
64 /*bind_fragment_callback=*/
65 [&frag_info, &data_host_buffer](RenderPass& pass) {
66 FS::BindFragInfo(pass, data_host_buffer.EmplaceUniform(frag_info));
67 pass.SetCommandLabel("Circle");
68 return true;
69 },
70 /*force_stencil=*/false,
71 /*create_geom_callback=*/
72 [geometry_result = std::move(geometry_result)](
73 const ContentContext& renderer, const Entity& entity,
74 RenderPass& pass,
75 const Geometry* geometry) { return geometry_result; });
76}
77
78std::optional<Rect> CircleContents::GetCoverage(const Entity& entity) const {
79 return geometry_->GetCoverage(entity.GetTransform());
80}
81
83 return geometry_.get();
84}
85
86} // namespace impeller
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.
static std::unique_ptr< CircleContents > Make(std::unique_ptr< CircleGeometry > geometry, Color color, bool stroked)
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
Scalar GetOpacityFactor() const
Get the opacity factor for this color source.
std::function< PipelineRef(ContentContextOptions)> PipelineBuilderCallback
HostBuffer & GetTransientsDataBuffer() const
Retrieve the current host buffer for transient storage of other non-index data.
PipelineRef GetCirclePipeline(ContentContextOptions opts) const
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
Definition entity.cc:46
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition render_pass.h:30
float Scalar
Definition scalar.h:19
raw_ptr< Pipeline< PipelineDescriptor > > PipelineRef
A raw ptr to a pipeline object.
Definition pipeline.h:89
LinePipeline::FragmentShader FS
LinePipeline::VertexShader VS
Definition ref_ptr.h:261
Scalar alpha
Definition color.h:143
constexpr Color WithAlpha(Scalar new_alpha) const
Definition color.h:283