Flutter Engine
The Flutter Engine
solid_color_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
12
13namespace impeller {
14
16
18
20 color_ = color;
21}
22
24 return color_.WithAlpha(color_.alpha * GetOpacityFactor());
25}
26
28 return true;
29}
30
32 return GetColor().IsOpaque();
33}
34
36 const Entity& entity) const {
37 if (GetColor().IsTransparent()) {
38 return std::nullopt;
39 }
40
41 const std::shared_ptr<Geometry>& geometry = GetGeometry();
42 if (geometry == nullptr) {
43 return std::nullopt;
44 }
45 return geometry->GetCoverage(entity.GetTransform());
46};
47
49 const Entity& entity,
50 RenderPass& pass) const {
53 auto& host_buffer = renderer.GetTransientsBuffer();
54
55 VS::FrameInfo frame_info;
56 FS::FragInfo frag_info;
57 frag_info.color =
58 GetColor().Premultiply() * GetGeometry()->ComputeAlphaCoverage(entity);
59
60 PipelineBuilderCallback pipeline_callback =
62 return renderer.GetSolidFillPipeline(options);
63 };
64 return ColorSourceContents::DrawGeometry<VS>(
65 renderer, entity, pass, pipeline_callback, frame_info,
66 [&frag_info, &host_buffer](RenderPass& pass) {
67 FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
68 pass.SetCommandLabel("Solid Fill");
69 return true;
70 });
71}
72
73std::unique_ptr<SolidColorContents> SolidColorContents::Make(const Path& path,
74 Color color) {
75 auto contents = std::make_unique<SolidColorContents>();
76 contents->SetGeometry(Geometry::MakeFillPath(path));
77 contents->SetColor(color);
78 return contents;
79}
80
82 const Entity& entity,
83 ISize target_size) const {
84 Rect target_rect = Rect::MakeSize(target_size);
85 return GetGeometry()->CoversArea(entity.GetTransform(), target_rect)
86 ? GetColor()
87 : std::optional<Color>();
88}
89
91 const ColorFilterProc& color_filter_proc) {
92 color_ = color_filter_proc(color_);
93 return true;
94}
95
96} // namespace impeller
const char * options
Scalar GetOpacityFactor() const
Get the opacity factor for this color source.
std::function< std::shared_ptr< Pipeline< PipelineDescriptor > >(ContentContextOptions)> PipelineBuilderCallback
const std::shared_ptr< Geometry > & GetGeometry() const
Get the geometry that this contents will use to render.
std::function< Color(Color)> ColorFilterProc
Definition: contents.h:35
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
Definition: entity.cc:46
static std::shared_ptr< Geometry > MakeFillPath(const Path &path, std::optional< Rect > inner_rect=std::nullopt)
Definition: geometry.cc:60
Paths are lightweight objects that describe a collection of linear, quadratic, or cubic segments....
Definition: path.h:52
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:33
virtual void SetCommandLabel(std::string_view label)
The debugging label to use for the command.
Definition: render_pass.cc:97
FragmentShader_ FragmentShader
Definition: pipeline.h:107
bool IsOpaque() const override
Whether this Contents only emits opaque source colors from the fragment stage. This value does not ac...
bool IsSolidColor() const override
bool ApplyColorFilter(const ColorFilterProc &color_filter_proc) override
If possible, applies a color filter to this contents inputs on the CPU.
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
static std::unique_ptr< SolidColorContents > Make(const Path &path, Color color)
std::optional< Color > AsBackgroundColor(const Entity &entity, ISize target_size) const override
Returns a color if this Contents will flood the given target_size with a color. This output color is ...
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.
DlColor color
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
SolidFillVertexShader VS
constexpr bool IsOpaque() const
Definition: color.h:896
Scalar alpha
Definition: color.h:143
constexpr Color WithAlpha(Scalar new_alpha) const
Definition: color.h:280
constexpr Color Premultiply() const
Definition: color.h:214
static constexpr TRect MakeSize(const TSize< U > &size)
Definition: rect.h:146