Flutter Impeller
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_IMPELLER_AIKS_COLOR_SOURCE_H_
6 #define FLUTTER_IMPELLER_AIKS_COLOR_SOURCE_H_
7 
8 #include <functional>
9 #include <memory>
10 #include <vector>
11 
12 #include "flutter/fml/macros.h"
14 #include "impeller/entity/entity.h"
19 
20 #if IMPELLER_ENABLE_3D
21 #include "impeller/scene/node.h" // nogncheck
22 #endif // IMPELLER_ENABLE_3D
23 
24 namespace impeller {
25 
26 struct Paint;
27 
28 class ColorSource {
29  public:
30  enum class Type {
31  kColor,
32  kImage,
38  kScene,
39  };
40 
41  using ColorSourceProc =
42  std::function<std::shared_ptr<ColorSourceContents>(const Paint& paint)>;
43 
44  ColorSource() noexcept;
45 
46  ~ColorSource();
47 
48  static ColorSource MakeColor();
49 
50  static ColorSource MakeLinearGradient(Point start_point,
51  Point end_point,
52  std::vector<Color> colors,
53  std::vector<Scalar> stops,
54  Entity::TileMode tile_mode,
55  Matrix effect_transform);
56 
58  Scalar radius,
59  std::vector<Color> colors,
60  std::vector<Scalar> stops,
61  Point focus_center,
62  Scalar focus_radius,
63  Entity::TileMode tile_mode,
64  Matrix effect_transform);
65 
66  static ColorSource MakeRadialGradient(Point center,
67  Scalar radius,
68  std::vector<Color> colors,
69  std::vector<Scalar> stops,
70  Entity::TileMode tile_mode,
71  Matrix effect_transform);
72 
73  static ColorSource MakeSweepGradient(Point center,
74  Degrees start_angle,
75  Degrees end_angle,
76  std::vector<Color> colors,
77  std::vector<Scalar> stops,
78  Entity::TileMode tile_mode,
79  Matrix effect_transform);
80 
81  static ColorSource MakeImage(std::shared_ptr<Texture> texture,
82  Entity::TileMode x_tile_mode,
83  Entity::TileMode y_tile_mode,
84  SamplerDescriptor sampler_descriptor,
85  Matrix effect_transform);
86 
88  std::shared_ptr<RuntimeStage> runtime_stage,
89  std::shared_ptr<std::vector<uint8_t>> uniform_data,
90  std::vector<RuntimeEffectContents::TextureInput> texture_inputs);
91 
92 #if IMPELLER_ENABLE_3D
93  static ColorSource MakeScene(std::shared_ptr<scene::Node> scene_node,
94  Matrix camera_transform);
95 #endif // IMPELLER_ENABLE_3D
96 
97  Type GetType() const;
98 
99  std::shared_ptr<ColorSourceContents> GetContents(const Paint& paint) const;
100 
101  private:
102  Type type_ = Type::kColor;
103  ColorSourceProc proc_;
104 };
105 
106 } // namespace impeller
107 
108 #endif // FLUTTER_IMPELLER_AIKS_COLOR_SOURCE_H_
impeller::ColorSource::Type::kScene
@ kScene
impeller::ColorSource::Type::kLinearGradient
@ kLinearGradient
impeller::ColorSource::GetContents
std::shared_ptr< ColorSourceContents > GetContents(const Paint &paint) const
Definition: color_source.cc:234
point.h
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::ColorSource::Type::kRadialGradient
@ kRadialGradient
entity.h
impeller::ColorSource::MakeLinearGradient
static ColorSource MakeLinearGradient(Point start_point, Point end_point, std::vector< Color > colors, std::vector< Scalar > stops, Entity::TileMode tile_mode, Matrix effect_transform)
Definition: color_source.cc:45
impeller::Paint
Definition: paint.h:23
impeller::Color
Definition: color.h:124
impeller::ColorSource::MakeSweepGradient
static ColorSource MakeSweepGradient(Point center, Degrees start_angle, Degrees end_angle, std::vector< Color > colors, std::vector< Scalar > stops, Entity::TileMode tile_mode, Matrix effect_transform)
Definition: color_source.cc:138
impeller::ColorSource::MakeColor
static ColorSource MakeColor()
Definition: color_source.cc:41
impeller::ColorSource::MakeImage
static ColorSource MakeImage(std::shared_ptr< Texture > texture, Entity::TileMode x_tile_mode, Entity::TileMode y_tile_mode, SamplerDescriptor sampler_descriptor, Matrix effect_transform)
Definition: color_source.cc:163
impeller::ColorSource::ColorSourceProc
std::function< std::shared_ptr< ColorSourceContents >(const Paint &paint)> ColorSourceProc
Definition: color_source.h:42
impeller::RuntimeStage
Definition: runtime_stage.h:19
runtime_effect_contents.h
impeller::RuntimeEffectContents
Definition: runtime_effect_contents.h:17
impeller::SamplerDescriptor
Definition: sampler_descriptor.h:15
matrix.h
impeller::Entity
Definition: entity.h:21
impeller::Texture
Definition: texture.h:17
impeller::ColorSource
Definition: color_source.h:28
runtime_stage.h
node.h
impeller::ColorSource::MakeConicalGradient
static ColorSource MakeConicalGradient(Point center, Scalar radius, std::vector< Color > colors, std::vector< Scalar > stops, Point focus_center, Scalar focus_radius, Entity::TileMode tile_mode, Matrix effect_transform)
Definition: color_source.cc:74
impeller::ColorSource::Type::kRuntimeEffect
@ kRuntimeEffect
impeller::ColorSource::ColorSource
ColorSource() noexcept
Definition: color_source.cc:32
impeller::ColorSource::MakeRadialGradient
static ColorSource MakeRadialGradient(Point center, Scalar radius, std::vector< Color > colors, std::vector< Scalar > stops, Entity::TileMode tile_mode, Matrix effect_transform)
Definition: color_source.cc:108
impeller::ColorSource::Type::kImage
@ kImage
impeller::ColorSource::MakeRuntimeEffect
static ColorSource MakeRuntimeEffect(std::shared_ptr< RuntimeStage > runtime_stage, std::shared_ptr< std::vector< uint8_t >> uniform_data, std::vector< RuntimeEffectContents::TextureInput > texture_inputs)
Definition: color_source.cc:193
impeller::ColorSource::Type::kConicalGradient
@ kConicalGradient
std
Definition: comparable.h:95
impeller::ColorSource::Type
Type
Definition: color_source.h:30
impeller::TPoint< Scalar >
impeller::Degrees
Definition: scalar.h:46
color.h
impeller::ColorSource::Type::kSweepGradient
@ kSweepGradient
impeller
Definition: aiks_blur_unittests.cc:20
impeller::ColorSource::Type::kColor
@ kColor
impeller::ColorSource::GetType
Type GetType() const
Definition: color_source.cc:230
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37