Flutter Impeller
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 
11 namespace impeller {
12 
13 namespace {
14 using PipelineBuilderCallback =
15  std::function<PipelineRef(ContentContextOptions)>;
16 
19 
20 Scalar kAntialiasPixels = 1.0;
21 } // namespace
22 
23 std::unique_ptr<CircleContents> CircleContents::Make(
24  std::unique_ptr<CircleGeometry> geometry,
25  Color color,
26  bool stroked) {
27  geometry->SetAntialiasPadding(kAntialiasPixels);
28  return std::unique_ptr<CircleContents>(
29  new CircleContents(std::move(geometry), color, stroked));
30 }
31 
32 CircleContents::CircleContents(std::unique_ptr<CircleGeometry> geometry,
33  Color color,
34  bool stroked)
35  : geometry_(std::move(geometry)), color_(color), stroked_(stroked) {}
36 
38  const Entity& entity,
39  RenderPass& pass) const {
40  auto& data_host_buffer = renderer.GetTransientsDataBuffer();
41 
42  VS::FrameInfo frame_info;
43  FS::FragInfo frag_info;
44  frag_info.color = color_.WithAlpha(color_.alpha * GetOpacityFactor());
45  frag_info.center = geometry_->GetCenter();
46  frag_info.radius = geometry_->GetRadius();
47  frag_info.stroke_width = geometry_->GetStrokeWidth();
48  frag_info.aa_pixels = kAntialiasPixels;
49  frag_info.stroked = stroked_ ? 1.0f : 0.0f;
50 
51  auto geometry_result = geometry_->GetPositionBuffer(renderer, entity, pass);
52 
53  PipelineBuilderCallback pipeline_callback =
54  [&renderer](ContentContextOptions options) {
55  return renderer.GetCirclePipeline(options);
56  };
57 
58  return ColorSourceContents::DrawGeometry<VS>(
59  this, geometry_.get(), renderer, entity, pass, pipeline_callback,
60  frame_info,
61  /*bind_fragment_callback=*/
62  [&frag_info, &data_host_buffer](RenderPass& pass) {
63  FS::BindFragInfo(pass, data_host_buffer.EmplaceUniform(frag_info));
64  pass.SetCommandLabel("Circle");
65  return true;
66  },
67  /*force_stencil=*/false,
68  /*create_geom_callback=*/
69  [geometry_result = std::move(geometry_result)](
70  const ContentContext& renderer, const Entity& entity,
71  RenderPass& pass,
72  const Geometry* geometry) { return geometry_result; });
73 }
74 
75 std::optional<Rect> CircleContents::GetCoverage(const Entity& entity) const {
76  return geometry_->GetCoverage(entity.GetTransform());
77 }
78 
79 } // 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
PipelineRef GetCirclePipeline(ContentContextOptions opts) const
HostBuffer & GetTransientsDataBuffer() const
Retrieve the current host buffer for transient storage of other non-index data.
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
FragmentShader_ FragmentShader
Definition: pipeline.h:164
float Scalar
Definition: scalar.h:19
raw_ptr< Pipeline< PipelineDescriptor > > PipelineRef
A raw ptr to a pipeline object.
Definition: pipeline.h:88
LinePipeline::FragmentShader FS
LinePipeline::VertexShader VS
Definition: comparable.h:95
Scalar alpha
Definition: color.h:143
constexpr Color WithAlpha(Scalar new_alpha) const
Definition: color.h:278