Flutter Impeller
gradient_generator.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_GRADIENT_GENERATOR_H_
6 #define FLUTTER_IMPELLER_ENTITY_CONTENTS_GRADIENT_GENERATOR_H_
7 
8 #include <memory>
9 #include <vector>
10 
15 
16 namespace impeller {
17 
18 class Context;
19 
20 /**
21  * @brief Create a host visible texture that contains the gradient defined
22  * by the provided gradient data.
23  */
24 std::shared_ptr<Texture> CreateGradientTexture(
25  const GradientData& gradient_data,
26  const std::shared_ptr<impeller::Context>& context);
27 
28 struct StopData {
33 };
34 
35 static_assert(sizeof(StopData) == 32);
36 
37 /**
38  * @brief Populate a vector with the color and stop data for a gradient
39  *
40  * @param colors
41  * @param stops
42  * @return StopData
43  */
44 std::vector<StopData> CreateGradientColors(const std::vector<Color>& colors,
45  const std::vector<Scalar>& stops);
46 
47 static constexpr uint32_t kMaxUniformGradientStops = 256u;
48 
49 /**
50  * @brief Populate 2 arrays with the colors and stop data for a gradient
51  *
52  * The color data is simply converted to a vec4 format, but the stop data
53  * is both turned into pairs of {t, inverse_delta} information and also
54  * stops are themselves paired up into a vec4 format for efficient packing
55  * in the uniform data.
56  *
57  * @param colors colors from gradient
58  * @param stops stops from gradient
59  * @param frag_info_colors colors for fragment shader in vec4 format
60  * @param frag_info_stop_pairs pairs of stop data for shader in vec4 format
61  * @return count of colors stored
62  */
64  const std::vector<Color>& colors,
65  const std::vector<Scalar>& stops,
66  Vector4 frag_info_colors[kMaxUniformGradientStops],
67  Vector4 frag_info_stop_pairs[kMaxUniformGradientStops / 2]);
68 
69 } // namespace impeller
70 
71 #endif // FLUTTER_IMPELLER_ENTITY_CONTENTS_GRADIENT_GENERATOR_H_
float Scalar
Definition: scalar.h:19
int PopulateUniformGradientColors(const std::vector< Color > &colors, const std::vector< Scalar > &stops, Vector4 frag_info_colors[kMaxUniformGradientStops], Vector4 frag_info_stop_pairs[kMaxUniformGradientStops/2])
Populate 2 arrays with the colors and stop data for a gradient.
std::vector< StopData > CreateGradientColors(const std::vector< Color > &colors, const std::vector< Scalar > &stops)
Populate a vector with the color and stop data for a gradient.
std::shared_ptr< Texture > CreateGradientTexture(const GradientData &gradient_data, const std::shared_ptr< impeller::Context > &context)
Create a host visible texture that contains the gradient defined by the provided gradient data.
static constexpr uint32_t kMaxUniformGradientStops