| 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
11 #include "flutter/impeller/core/texture.h"
12 #include "impeller/core/shader_types.h"
13 #include "impeller/geometry/color.h"
14 #include "impeller/geometry/gradient.h"
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 {
29 Color color;
30 Scalar stop;
31 Scalar inverse_delta;
32 Padding<8> _padding_;
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 */
63 int PopulateUniformGradientColors(
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_
color.h
texture.h
gradient.h
impeller
Definition: allocation.cc:12
impeller::Scalar
float Scalar
Definition: scalar.h:19
impeller::PopulateUniformGradientColors
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.
Definition: gradient_generator.cc:51
impeller::CreateGradientColors
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.
Definition: gradient_generator.cc:34
impeller::CreateGradientTexture
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.
Definition: gradient_generator.cc:17
impeller::kMaxUniformGradientStops
static constexpr uint32_t kMaxUniformGradientStops
Definition: gradient_generator.h:47
shader_types.h
impeller::Color
Definition: color.h:124
impeller::Padding< 8 >
impeller::StopData
Definition: gradient_generator.h:28
impeller::StopData::inverse_delta
Scalar inverse_delta
Definition: gradient_generator.h:31
impeller::StopData::_padding_
Padding< 8 > _padding_
Definition: gradient_generator.h:32
impeller::StopData::color
Color color
Definition: gradient_generator.h:29
impeller::StopData::stop
Scalar stop
Definition: gradient_generator.h:30
impeller::Vector4
Definition: vector.h:232