Flutter Engine
 
Loading...
Searching...
No Matches
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
11
12namespace impeller {
13
15
17
19 color_ = color;
20}
21
23 return color_.WithAlpha(color_.alpha * GetOpacityFactor());
24}
25
27 return true;
28}
29
33
35 const Entity& entity) const {
36 if (GetColor().IsTransparent()) {
37 return std::nullopt;
38 }
39
40 const Geometry* geometry = GetGeometry();
41 if (geometry == nullptr) {
42 return std::nullopt;
43 }
44 return geometry->GetCoverage(entity.GetTransform());
45};
46
48 const Entity& entity,
49 RenderPass& pass) const {
50 using VS = SolidFillPipeline::VertexShader;
51 using FS = SolidFillPipeline::FragmentShader;
52 auto& data_host_buffer = renderer.GetTransientsDataBuffer();
53
54 VS::FrameInfo frame_info;
55 FS::FragInfo frag_info;
56 frag_info.color = GetColor().Premultiply() *
58
59 PipelineBuilderCallback pipeline_callback =
60 [&renderer](ContentContextOptions options) {
61 return renderer.GetSolidFillPipeline(options);
62 };
63 return ColorSourceContents::DrawGeometry<VS>(
64 renderer, entity, pass, pipeline_callback, frame_info,
65 [&frag_info, &data_host_buffer](RenderPass& pass) {
66 FS::BindFragInfo(pass, data_host_buffer.EmplaceUniform(frag_info));
67 pass.SetCommandLabel("Solid Fill");
68 return true;
69 });
70}
71
73 const Entity& entity,
74 ISize target_size) const {
75 Rect target_rect = Rect::MakeSize(target_size);
76 return GetGeometry()->CoversArea(entity.GetTransform(), target_rect)
77 ? GetColor()
78 : std::optional<Color>();
79}
80
82 const ColorFilterProc& color_filter_proc) {
83 color_ = color_filter_proc(color_);
84 return true;
85}
86
87} // namespace impeller
const Geometry * GetGeometry() const
Get the geometry that this contents will use to render.
Scalar GetOpacityFactor() const
Get the opacity factor for this color source.
bool AppliesAlphaForStrokeCoverage(const Matrix &transform) const
Whether the entity should be treated as non-opaque due to stroke geometry requiring alpha for coverag...
std::function< PipelineRef(ContentContextOptions)> PipelineBuilderCallback
HostBuffer & GetTransientsDataBuffer() const
Retrieve the current host buffer for transient storage of other non-index data.
PipelineRef GetSolidFillPipeline(ContentContextOptions opts) const
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
Definition entity.cc:44
virtual std::optional< Rect > GetCoverage(const Matrix &transform) const =0
virtual Scalar ComputeAlphaCoverage(const Matrix &transform) const
Definition geometry.h:125
virtual bool CoversArea(const Matrix &transform, const Rect &rect) const
Determines if this geometry, transformed by the given transform, will completely cover all surface ar...
Definition geometry.cc:136
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition render_pass.h:30
virtual void SetCommandLabel(std::string_view label)
The debugging label to use for the command.
bool IsOpaque(const Matrix &transform) const override
Whether this Contents only emits opaque source colors from the fragment stage. This value does not ac...
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
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.
LinePipeline::FragmentShader FS
std::function< Color(Color)> ColorFilterProc
LinePipeline::VertexShader VS
constexpr bool IsOpaque() const
Definition color.h:894
Scalar alpha
Definition color.h:143
constexpr Color WithAlpha(Scalar new_alpha) const
Definition color.h:278
constexpr Color Premultiply() const
Definition color.h:212
A 4x4 matrix using column-major storage.
Definition matrix.h:37
static constexpr TRect MakeSize(const TSize< U > &size)
Definition rect.h:150