| 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
5 #include "impeller/entity/contents/circle_contents.h"
6 #include "impeller/entity/contents/color_source_contents.h"
7 #include "impeller/entity/contents/content_context.h"
8 #include "impeller/entity/geometry/circle_geometry.h"
9 #include "impeller/geometry/point.h"
10
11 namespace impeller {
12
13 namespace {
14 using BindFragmentCallback = std::function<bool(RenderPass& pass)>;
15 using PipelineBuilderCallback =
16 std::function<PipelineRef(ContentContextOptions)>;
17 using CreateGeometryCallback =
18 std::function<GeometryResult(const ContentContext& renderer,
19 const Entity& entity,
20 RenderPass& pass,
21 const Geometry* geometry)>;
22
23 using VS = CirclePipeline::VertexShader;
24 using FS = CirclePipeline::FragmentShader;
25
26 GeometryResult 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
36 std::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
44 CircleContents::CircleContents(std::unique_ptr<CircleGeometry> geometry,
45 Color color,
46 bool stroked)
47 : geometry_(std::move(geometry)), color_(color), stroked_(stroked) {}
48
49 bool CircleContents::Render(const ContentContext& renderer,
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
88 std::optional<Rect> CircleContents::GetCoverage(const Entity& entity) const {
89 return geometry_->GetCoverage(entity.GetTransform());
90 }
91
92 } // namespace impeller
circle_contents.h
circle_geometry.h
impeller::CircleContents
Definition: circle_contents.h:15
impeller::CircleContents::GetCoverage
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.
Definition: circle_contents.cc:88
impeller::CircleContents::Make
static std::unique_ptr< CircleContents > Make(std::unique_ptr< CircleGeometry > geometry, Color color, bool stroked)
Definition: circle_contents.cc:36
impeller::CircleContents::Render
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
Definition: circle_contents.cc:49
impeller::ColorSourceContents::GetOpacityFactor
Scalar GetOpacityFactor() const
Get the opacity factor for this color source.
Definition: color_source_contents.cc:28
impeller::ColorSourceContents::PipelineBuilderCallback
std::function< PipelineRef(ContentContextOptions)> PipelineBuilderCallback
Definition: color_source_contents.h:42
impeller::ContentContext
Definition: content_context.h:138
impeller::ContentContext::GetCirclePipeline
PipelineRef GetCirclePipeline(ContentContextOptions opts) const
Definition: content_context.cc:1502
impeller::ContentContext::GetTransientsDataBuffer
HostBuffer & GetTransientsDataBuffer() const
Retrieve the current host buffer for transient storage of other non-index data.
Definition: content_context.h:311
impeller::Entity
Definition: entity.h:26
impeller::Entity::GetTransform
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
Definition: entity.cc:44
impeller::Geometry
Definition: geometry.h:50
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:30
impeller::RenderPipelineHandle::VertexShader
VertexShader_ VertexShader
Definition: pipeline.h:163
impeller::RenderPipelineHandle::FragmentShader
FragmentShader_ FragmentShader
Definition: pipeline.h:164
color_source_contents.h
content_context.h
impeller
Definition: allocation.cc:12
impeller::PipelineRef
raw_ptr< Pipeline< PipelineDescriptor > > PipelineRef
A raw ptr to a pipeline object.
Definition: pipeline.h:88
impeller::FS
LinePipeline::FragmentShader FS
Definition: line_contents.cc:14
impeller::VS
LinePipeline::VertexShader VS
Definition: line_contents.cc:13
std
Definition: comparable.h:95
point.h
impeller::Color
Definition: color.h:124
impeller::Color::alpha
Scalar alpha
Definition: color.h:143
impeller::Color::WithAlpha
constexpr Color WithAlpha(Scalar new_alpha) const
Definition: color.h:278
impeller::ContentContextOptions
Definition: content_context.h:40