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 BindFragmentCallback = std::function<bool(RenderPass& pass)>;
15using PipelineBuilderCallback =
16 std::function<PipelineRef(ContentContextOptions)>;
17using CreateGeometryCallback =
18 std::function<GeometryResult(const ContentContext& renderer,
19 const Entity& entity,
20 RenderPass& pass,
21 const Geometry* geometry)>;
22
23using VS = CirclePipeline::VertexShader;
24using FS = CirclePipeline::FragmentShader;
25
26GeometryResult CreateGeometry(const ContentContext& renderer,
27 const Entity& entity,
28 RenderPass& pass,
29 const CircleGeometry* circle_geometry) {
30 auto geometry_result =
31 circle_geometry->GetPositionBuffer(renderer, entity, pass);
32 return geometry_result;
33}
34} // namespace
35
36std::unique_ptr<CircleContents> CircleContents::Make(
37 std::unique_ptr<CircleGeometry> geometry,
38 Color color,
39 bool stroked) {
40 return std::unique_ptr<CircleContents>(
41 new CircleContents(std::move(geometry), color, stroked));
42}
43
44CircleContents::CircleContents(std::unique_ptr<CircleGeometry> geometry,
45 Color color,
46 bool stroked)
47 : geometry_(std::move(geometry)), color_(color), stroked_(stroked) {}
48
50 const Entity& entity,
51 RenderPass& pass) const {
52 auto& data_host_buffer = renderer.GetTransientsDataBuffer();
53
54 VS::FrameInfo frame_info;
55 FS::FragInfo frag_info;
56 frag_info.color = color_.WithAlpha(color_.alpha * GetOpacityFactor());
57 frag_info.center = geometry_->GetCenter();
58 frag_info.radius = geometry_->GetRadius();
59 frag_info.stroke_width = geometry_->GetStrokeWidth();
60 frag_info.aa_pixels = 1.0;
61 frag_info.stroked = stroked_ ? 1.0f : 0.0f;
62
63 auto geometry_result =
64 CreateGeometry(renderer, entity, pass, geometry_.get());
65
66 PipelineBuilderCallback pipeline_callback =
67 [&renderer](ContentContextOptions options) {
68 return renderer.GetCirclePipeline(options);
69 };
70
71 return ColorSourceContents::DrawGeometry<VS>(
72 this, geometry_.get(), renderer, entity, pass, pipeline_callback,
73 frame_info,
74 /*bind_fragment_callback=*/
75 [&frag_info, &data_host_buffer](RenderPass& pass) {
76 FS::BindFragInfo(pass, data_host_buffer.EmplaceUniform(frag_info));
77 pass.SetCommandLabel("Circle");
78 return true;
79 },
80 /*force_stencil=*/false,
81 /*create_geom_callback=*/
82 [geometry_result = std::move(geometry_result)](
83 const ContentContext& renderer, const Entity& entity,
84 RenderPass& pass,
85 const Geometry* geometry) { return geometry_result; });
86}
87
88std::optional<Rect> CircleContents::GetCoverage(const Entity& entity) const {
89 return geometry_->GetCoverage(entity.GetTransform());
90}
91
92} // namespace impeller
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
raw_ptr< Pipeline< PipelineDescriptor > > PipelineRef
A raw ptr to a pipeline object.
Definition pipeline.h:88
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:278