| Flutter Impeller |

color_source_contents.h
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 #ifndef FLUTTER_IMPELLER_ENTITY_CONTENTS_COLOR_SOURCE_CONTENTS_H_
6 #define FLUTTER_IMPELLER_ENTITY_CONTENTS_COLOR_SOURCE_CONTENTS_H_
7
8 #include "flutter/fml/macros.h"
9 #include "impeller/entity/contents/contents.h"
10 #include "impeller/entity/geometry/geometry.h"
11 #include "impeller/geometry/matrix.h"
12 #include "impeller/geometry/path.h"
13
14 namespace impeller {
15
16 //------------------------------------------------------------------------------
17 /// Color sources are geometry-ignostic `Contents` capable of shading any area
18 /// defined by an `impeller::Geometry`. Conceptually,
19 /// `impeller::ColorSourceContents` implement a particular color shading
20 /// behavior.
21 ///
22 /// This separation of concerns between geometry and color source output allows
23 /// Impeller to handle most possible draw combinations in a consistent way.
24 /// For example: There are color sources for handling solid colors, gradients,
25 /// textures, custom runtime effects, and even 3D scenes.
26 ///
27 /// There are some special rendering exceptions that deviate from this pattern
28 /// and cross geometry and color source concerns, such as text atlas and image
29 /// atlas rendering. Special `Contents` exist for rendering these behaviors
30 /// which don't implement `ColorSourceContents`.
31 ///
32 /// @see `impeller::Geometry`
33 ///
34 class ColorSourceContents : public Contents {
35 public:
36 ColorSourceContents();
37
38 ~ColorSourceContents() override;
39
40 //----------------------------------------------------------------------------
41 /// @brief Set the geometry that this contents will use to render.
42 ///
43 void SetGeometry(std::shared_ptr<Geometry> geometry);
44
45 //----------------------------------------------------------------------------
46 /// @brief Get the geometry that this contents will use to render.
47 ///
48 const std::shared_ptr<Geometry>& GetGeometry() const;
49
50 //----------------------------------------------------------------------------
51 /// @brief Set the effect transform for this color source.
52 ///
53 /// The effect transform is a transform matrix that is applied to
54 /// the shaded color output and does not impact geometry in any way.
55 ///
56 /// For example: With repeat tiling, any gradient or
57 /// `TiledTextureContents` could be used with an effect transform to
58 /// inexpensively draw an infinite scrolling background pattern.
59 ///
60 void SetEffectTransform(Matrix matrix);
61
62 //----------------------------------------------------------------------------
63 /// @brief Set the inverted effect transform for this color source.
64 ///
65 /// When the effect transform is set via `SetEffectTransform`, the
66 /// value is inverted upon storage. The reason for this is that most
67 /// color sources internally use the inverted transform.
68 ///
69 /// @return The inverse of the transform set by `SetEffectTransform`.
70 ///
71 /// @see `SetEffectTransform`
72 ///
73 const Matrix& GetInverseEffectTransform() const;
74
75 //----------------------------------------------------------------------------
76 /// @brief Set the opacity factor for this color source.
77 ///
78 void SetOpacityFactor(Scalar opacity);
79
80 //----------------------------------------------------------------------------
81 /// @brief Get the opacity factor for this color source.
82 ///
83 /// This value is is factored into the output of the color source in
84 /// addition to opacity information that may be supplied any other
85 /// inputs.
86 ///
87 /// @note If set, the output of this method factors factors in the inherited
88 /// opacity of this `Contents`.
89 ///
90 /// @see `Contents::CanInheritOpacity`
91 ///
92 Scalar GetOpacityFactor() const;
93
94 virtual bool IsSolidColor() const;
95
96 // |Contents|
97 std::optional<Rect> GetCoverage(const Entity& entity) const override;
98
99 // |Contents|
100 bool CanInheritOpacity(const Entity& entity) const override;
101
102 // |Contents|
103 void SetInheritedOpacity(Scalar opacity) override;
104
105 private:
106 std::shared_ptr<Geometry> geometry_;
107 Matrix inverse_matrix_;
108 Scalar opacity_ = 1.0;
109 Scalar inherited_opacity_ = 1.0;
110
111 ColorSourceContents(const ColorSourceContents&) = delete;
112
113 ColorSourceContents& operator=(const ColorSourceContents&) = delete;
114 };
115
116 } // namespace impeller
117
118 #endif // FLUTTER_IMPELLER_ENTITY_CONTENTS_COLOR_SOURCE_CONTENTS_H_
path.h
impeller::ColorSourceContents::GetOpacityFactor
Scalar GetOpacityFactor() const
Get the opacity factor for this color source.
Definition: color_source_contents.cc:29
contents.h
impeller::ColorSourceContents::IsSolidColor
virtual bool IsSolidColor() const
Definition: color_source_contents.cc:41
impeller::ColorSourceContents::SetInheritedOpacity
void SetInheritedOpacity(Scalar opacity) override
Inherit the provided opacity.
Definition: color_source_contents.cc:54
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::ColorSourceContents::SetGeometry
void SetGeometry(std::shared_ptr< Geometry > geometry)
Set the geometry that this contents will use to render.
Definition: color_source_contents.cc:17
impeller::ColorSourceContents::SetEffectTransform
void SetEffectTransform(Matrix matrix)
Set the effect transform for this color source.
Definition: color_source_contents.cc:33
impeller::ColorSourceContents::GetGeometry
const std::shared_ptr< Geometry > & GetGeometry() const
Get the geometry that this contents will use to render.
Definition: color_source_contents.cc:21
impeller::ColorSourceContents::CanInheritOpacity
bool CanInheritOpacity(const Entity &entity) const override
Whether or not this contents can accept the opacity peephole optimization.
Definition: color_source_contents.cc:50
impeller::ColorSourceContents::ColorSourceContents
ColorSourceContents()
matrix.h
impeller::Entity
Definition: entity.h:21
impeller::ColorSourceContents::~ColorSourceContents
~ColorSourceContents() override
geometry.h
impeller::ColorSourceContents::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: color_source_contents.cc:45
impeller::ColorSourceContents::SetOpacityFactor
void SetOpacityFactor(Scalar opacity)
Set the opacity factor for this color source.
Definition: color_source_contents.cc:25
impeller::Contents
Definition: contents.h:34
impeller::ColorSourceContents
Definition: color_source_contents.h:34
impeller
Definition: aiks_context.cc:10
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
impeller::ColorSourceContents::GetInverseEffectTransform
const Matrix & GetInverseEffectTransform() const
Set the inverted effect transform for this color source.
Definition: color_source_contents.cc:37