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