Flutter Engine
 
Loading...
Searching...
No Matches
dl_color_source.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_DISPLAY_LIST_EFFECTS_DL_COLOR_SOURCE_H_
6#define FLUTTER_DISPLAY_LIST_EFFECTS_DL_COLOR_SOURCE_H_
7
14#include "flutter/fml/logging.h"
15
16namespace flutter {
17
18class DlImageColorSource;
19class DlLinearGradientColorSource;
20class DlRadialGradientColorSource;
21class DlConicalGradientColorSource;
22class DlSweepGradientColorSource;
23class DlRuntimeEffectColorSource;
24
25// The DisplayList ColorSource class. This class implements all of the
26// facilities and adheres to the design goals of the |DlAttribute| base
27// class.
28//
29// The role of the DlColorSource is to provide color information for
30// the pixels of a rendering operation. The object is essentially the
31// origin of all color being rendered, though its output may be
32// modified or transformed by geometric coverage data, the filter
33// attributes, and the final blend with the pixels in the destination.
34
43
44class DlColorSource : public DlAttribute<DlColorSource, DlColorSourceType> {
45 public:
46 static std::shared_ptr<DlColorSource> MakeImage(
47 const sk_sp<const DlImage>& image,
48 DlTileMode horizontal_tile_mode,
49 DlTileMode vertical_tile_mode,
51 const DlMatrix* matrix = nullptr);
52
53 static std::shared_ptr<DlColorSource> MakeLinear(
54 const DlPoint start_point,
55 const DlPoint end_point,
56 uint32_t stop_count,
57 const DlColor* colors,
58 const float* stops,
59 DlTileMode tile_mode,
60 const DlMatrix* matrix = nullptr);
61
62 /// @brief Make a linear gradient.
63 /// @param colors_argb Array of DlScalars that represents colors in the ARGB
64 /// format, in the extended srgb colorspace.
65 static std::shared_ptr<DlColorSource> MakeLinear(
66 const DlPoint start_point,
67 const DlPoint end_point,
68 uint32_t stop_count,
69 const DlScalar* colors_argb,
70 const float* stops,
71 DlTileMode tile_mode,
72 const DlMatrix* matrix = nullptr);
73
74 static std::shared_ptr<DlColorSource> MakeRadial(
75 DlPoint center,
76 DlScalar radius,
77 uint32_t stop_count,
78 const DlColor* colors,
79 const float* stops,
80 DlTileMode tile_mode,
81 const DlMatrix* matrix = nullptr);
82
83 /// @brief Make a radial gradient.
84 /// @param colors_argb Array of DlScalars that represents colors in the ARGB
85 /// format, in the extended srgb colorspace.
86 static std::shared_ptr<DlColorSource> MakeRadial(
87 DlPoint center,
88 DlScalar radius,
89 uint32_t stop_count,
90 const DlScalar* colors_argb,
91 const float* stops,
92 DlTileMode tile_mode,
93 const DlMatrix* matrix = nullptr);
94
95 static std::shared_ptr<DlColorSource> MakeConical(
96 DlPoint start_center,
97 DlScalar start_radius,
98 DlPoint end_center,
99 DlScalar end_radius,
100 uint32_t stop_count,
101 const DlColor* colors,
102 const float* stops,
103 DlTileMode tile_mode,
104 const DlMatrix* matrix = nullptr);
105
106 /// @brief Make a conical gradient.
107 /// @param colors_argb colors_argb Array of DlScalars that represents colors
108 /// in the ARGB format, in the extended srgb colorspace.
109 static std::shared_ptr<DlColorSource> MakeConical(
110 DlPoint start_center,
111 DlScalar start_radius,
112 DlPoint end_center,
113 DlScalar end_radius,
114 uint32_t stop_count,
115 const DlScalar* colors_argb,
116 const float* stops,
117 DlTileMode tile_mode,
118 const DlMatrix* matrix = nullptr);
119
120 static std::shared_ptr<DlColorSource> MakeSweep(
121 DlPoint center,
124 uint32_t stop_count,
125 const DlColor* colors,
126 const float* stops,
127 DlTileMode tile_mode,
128 const DlMatrix* matrix = nullptr);
129
130 /// @brief Make a sweep gradient.
131 /// @param colors_argb Array of DlScalars that represents colors in the ARGB
132 /// format, in the extended srgb colorspace.
133 static std::shared_ptr<DlColorSource> MakeSweep(
134 DlPoint center,
137 uint32_t stop_count,
138 const DlScalar* colors_argb,
139 const float* stops,
140 DlTileMode tile_mode,
141 const DlMatrix* matrix = nullptr);
142
143 static std::shared_ptr<DlColorSource> MakeRuntimeEffect(
144 sk_sp<DlRuntimeEffect> runtime_effect,
145 std::vector<std::shared_ptr<DlColorSource>> samplers,
146 std::shared_ptr<std::vector<uint8_t>> uniform_data);
147
148 virtual bool is_opaque() const = 0;
149
150 //----------------------------------------------------------------------------
151 /// @brief If the underlying platform data held by this object is
152 /// held in a way that it can be stored and potentially
153 /// released from the UI thread, this method returns true.
154 ///
155 /// @return True if the class has no GPU related resources or if any
156 /// that it holds are held in a thread-safe manner.
157 ///
158 virtual bool isUIThreadSafe() const = 0;
159
160 //----------------------------------------------------------------------------
161 /// @brief If the underlying platform data represents a gradient.
162 ///
163 /// TODO(matanl): Remove this flag when the Skia backend is
164 /// removed, https://github.com/flutter/flutter/issues/112498.
165 ///
166 /// @return True if the class represents the output of a gradient.
167 ///
168 virtual bool isGradient() const { return false; }
169
170 // Return a DlImageColorSource pointer to this object iff it is an Image
171 // type of ColorSource, otherwise return nullptr.
172 virtual const DlImageColorSource* asImage() const { return nullptr; }
173
174 // Return a DlLinearGradientColorSource pointer to this object iff it is a
175 // Linear Gradient type of ColorSource, otherwise return nullptr.
177 return nullptr;
178 }
179
180 // Return a DlRadialGradientColorSource pointer to this object iff it is a
181 // Radial Gradient type of ColorSource, otherwise return nullptr.
183 return nullptr;
184 }
185
186 // Return a DlConicalGradientColorSource pointer to this object iff it is a
187 // Conical Gradient type of ColorSource, otherwise return nullptr.
189 return nullptr;
190 }
191
192 // Return a DlSweepGradientColorSource pointer to this object iff it is a
193 // Sweep Gradient type of ColorSource, otherwise return nullptr.
195 return nullptr;
196 }
197
199 return nullptr;
200 }
201
202 protected:
203 DlColorSource() = default;
204
205 private:
207};
208
209} // namespace flutter
210
211#endif // FLUTTER_DISPLAY_LIST_EFFECTS_DL_COLOR_SOURCE_H_
virtual const DlRuntimeEffectColorSource * asRuntimeEffect() const
virtual bool isUIThreadSafe() const =0
If the underlying platform data held by this object is held in a way that it can be stored and potent...
static std::shared_ptr< DlColorSource > MakeSweep(DlPoint center, DlScalar start, DlScalar end, uint32_t stop_count, const DlColor *colors, const float *stops, DlTileMode tile_mode, const DlMatrix *matrix=nullptr)
static std::shared_ptr< DlColorSource > MakeImage(const sk_sp< const DlImage > &image, DlTileMode horizontal_tile_mode, DlTileMode vertical_tile_mode, DlImageSampling sampling=DlImageSampling::kLinear, const DlMatrix *matrix=nullptr)
static std::shared_ptr< DlColorSource > MakeLinear(const DlPoint start_point, const DlPoint end_point, uint32_t stop_count, const DlColor *colors, const float *stops, DlTileMode tile_mode, const DlMatrix *matrix=nullptr)
virtual const DlRadialGradientColorSource * asRadialGradient() const
virtual const DlLinearGradientColorSource * asLinearGradient() const
virtual const DlImageColorSource * asImage() const
virtual bool is_opaque() const =0
virtual const DlSweepGradientColorSource * asSweepGradient() const
static std::shared_ptr< DlColorSource > MakeRuntimeEffect(sk_sp< DlRuntimeEffect > runtime_effect, std::vector< std::shared_ptr< DlColorSource > > samplers, std::shared_ptr< std::vector< uint8_t > > uniform_data)
virtual bool isGradient() const
If the underlying platform data represents a gradient.
virtual const DlConicalGradientColorSource * asConicalGradient() const
static std::shared_ptr< DlColorSource > MakeConical(DlPoint start_center, DlScalar start_radius, DlPoint end_center, DlScalar end_radius, uint32_t stop_count, const DlColor *colors, const float *stops, DlTileMode tile_mode, const DlMatrix *matrix=nullptr)
static std::shared_ptr< DlColorSource > MakeRadial(DlPoint center, DlScalar radius, uint32_t stop_count, const DlColor *colors, const float *stops, DlTileMode tile_mode, const DlMatrix *matrix=nullptr)
FlutterVulkanImage * image
#define FML_DISALLOW_COPY_ASSIGN_AND_MOVE(TypeName)
Definition macros.h:31
impeller::Scalar DlScalar
A 4x4 matrix using column-major storage.
Definition matrix.h:37
const size_t start
const size_t end