Flutter Impeller
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 
5 #include "solid_color_contents.h"
6 
11 
12 namespace impeller {
13 
15  : geometry_(geometry) {}
16 
18 
20  color_ = color;
21 }
22 
24  return color_.WithAlpha(color_.alpha * GetOpacityFactor());
25 }
26 
28  return geometry_;
29 }
30 
32  return true;
33 }
34 
37 }
38 
39 std::optional<Rect> SolidColorContents::GetCoverage(
40  const Entity& entity) const {
41  if (GetColor().IsTransparent()) {
42  return std::nullopt;
43  }
44 
45  const Geometry* geometry = GetGeometry();
46  if (geometry == nullptr) {
47  return std::nullopt;
48  }
49  return geometry->GetCoverage(entity.GetTransform());
50 };
51 
53  const Entity& entity,
54  RenderPass& pass) const {
57  auto& data_host_buffer = renderer.GetTransientsDataBuffer();
58 
59  VS::FrameInfo frame_info;
60  FS::FragInfo frag_info;
61  frag_info.color = GetColor().Premultiply() *
63 
64  PipelineBuilderCallback pipeline_callback =
65  [&renderer](ContentContextOptions options) {
66  return renderer.GetSolidFillPipeline(options);
67  };
68  return ColorSourceContents::DrawGeometry<VS>(
69  renderer, entity, pass, pipeline_callback, frame_info,
70  [&frag_info, &data_host_buffer](RenderPass& pass) {
71  FS::BindFragInfo(pass, data_host_buffer.EmplaceUniform(frag_info));
72  pass.SetCommandLabel("Solid Fill");
73  return true;
74  });
75 }
76 
78  const Entity& entity,
79  ISize target_size) const {
80  const Geometry* geometry = GetGeometry();
81  if (geometry == nullptr) {
82  return std::nullopt;
83  }
84  Rect target_rect = Rect::MakeSize(target_size);
85  return geometry->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
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
PipelineRef GetSolidFillPipeline(ContentContextOptions opts) const
HostBuffer & GetTransientsDataBuffer() const
Retrieve the current host buffer for transient storage of other non-index data.
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
virtual Scalar ComputeAlphaCoverage(const Matrix &transform) const
Definition: geometry.h:125
virtual std::optional< Rect > GetCoverage(const Matrix &transform) const =0
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.
Definition: render_pass.cc:97
FragmentShader_ FragmentShader
Definition: pipeline.h:169
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 IsSolidColor() const override
bool ApplyColorFilter(const ColorFilterProc &color_filter_proc) override
If possible, applies a color filter to this contents inputs on the CPU.
SolidColorContents(const Geometry *geometry)
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.
const Geometry * GetGeometry() const override
Get the geometry that this contents will use to render.
LinePipeline::FragmentShader FS
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
constexpr static TRect MakeSize(const TSize< U > &size)
Definition: rect.h:150