Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | List of all members
flutter::CanvasGradient Class Reference

#include <gradient.h>

Inheritance diagram for flutter::CanvasGradient:
flutter::Shader flutter::RefCountedDartWrappable< Shader > fml::RefCountedThreadSafe< Shader > tonic::DartWrappable fml::internal::RefCountedThreadSafeBase

Public Member Functions

 ~CanvasGradient () override
 
void initLinear (const tonic::Float32List &end_points, const tonic::Int32List &colors, const tonic::Float32List &color_stops, DlTileMode tile_mode, const tonic::Float64List &matrix4)
 
void initRadial (double center_x, double center_y, double radius, const tonic::Int32List &colors, const tonic::Float32List &color_stops, DlTileMode tile_mode, const tonic::Float64List &matrix4)
 
void initSweep (double center_x, double center_y, const tonic::Int32List &colors, const tonic::Float32List &color_stops, DlTileMode tile_mode, double start_angle, double end_angle, const tonic::Float64List &matrix4)
 
void initTwoPointConical (double start_x, double start_y, double start_radius, double end_x, double end_y, double end_radius, const tonic::Int32List &colors, const tonic::Float32List &color_stops, DlTileMode tile_mode, const tonic::Float64List &matrix4)
 
std::shared_ptr< DlColorSourceshader (DlImageSampling sampling) override
 
- Public Member Functions inherited from flutter::Shader
 ~Shader () override
 
virtual std::shared_ptr< DlColorSourceshader (DlImageSampling)=0
 
- Public Member Functions inherited from flutter::RefCountedDartWrappable< Shader >
virtual void RetainDartWrappableReference () const override
 
virtual void ReleaseDartWrappableReference () const override
 
- Public Member Functions inherited from fml::RefCountedThreadSafe< Shader >
void Release () const
 
- Public Member Functions inherited from fml::internal::RefCountedThreadSafeBase
void AddRef () const
 
bool HasOneRef () const
 
void AssertHasOneRef () const
 
- Public Member Functions inherited from tonic::DartWrappable
 DartWrappable ()
 
virtual const DartWrapperInfoGetDartWrapperInfo () const =0
 
virtual void RetainDartWrappableReference () const =0
 
virtual void ReleaseDartWrappableReference () const =0
 
Dart_Handle CreateDartWrapper (DartState *dart_state)
 
void AssociateWithDartWrapper (Dart_Handle wrappable)
 
void ClearDartWrapper ()
 
Dart_WeakPersistentHandle dart_wrapper () const
 

Static Public Member Functions

static void Create (Dart_Handle wrapper)
 

Additional Inherited Members

- Public Types inherited from tonic::DartWrappable
enum  DartNativeFields { kPeerIndex , kNumberOfNativeFields }
 
- Protected Member Functions inherited from flutter::Shader
 Shader ()
 
- Protected Member Functions inherited from fml::RefCountedThreadSafe< Shader >
 RefCountedThreadSafe ()
 
 ~RefCountedThreadSafe ()
 
- Protected Member Functions inherited from fml::internal::RefCountedThreadSafeBase
 RefCountedThreadSafeBase ()
 
 ~RefCountedThreadSafeBase ()
 
bool Release () const
 
void Adopt ()
 
- Protected Member Functions inherited from tonic::DartWrappable
virtual ~DartWrappable ()
 
- Static Protected Member Functions inherited from tonic::DartWrappable
static Dart_PersistentHandle GetTypeForWrapper (tonic::DartState *dart_state, const tonic::DartWrapperInfo &wrapper_info)
 

Detailed Description

Definition at line 15 of file gradient.h.

Constructor & Destructor Documentation

◆ ~CanvasGradient()

flutter::CanvasGradient::~CanvasGradient ( )
overridedefault

Member Function Documentation

◆ Create()

void flutter::CanvasGradient::Create ( Dart_Handle  wrapper)
static

Definition at line 20 of file gradient.cc.

20 {
22 auto res = fml::MakeRefCounted<CanvasGradient>();
23 res->AssociateWithDartWrapper(wrapper);
24}
static void ThrowIfUIOperationsProhibited()

◆ initLinear()

void flutter::CanvasGradient::initLinear ( const tonic::Float32List &  end_points,
const tonic::Int32List &  colors,
const tonic::Float32List &  color_stops,
DlTileMode  tile_mode,
const tonic::Float64List &  matrix4 
)

Definition at line 26 of file gradient.cc.

30 {
31 FML_DCHECK(end_points.num_elements() == 4);
32 FML_DCHECK(colors.num_elements() == color_stops.num_elements() ||
33 color_stops.data() == nullptr);
34
35 static_assert(sizeof(SkPoint) == sizeof(float) * 2,
36 "SkPoint doesn't use floats.");
37 static_assert(sizeof(SkColor) == sizeof(int32_t),
38 "SkColor doesn't use int32_t.");
39
41 bool has_matrix = matrix4.data() != nullptr;
42 if (has_matrix) {
43 sk_matrix = ToSkMatrix(matrix4);
44 }
45
46 SkPoint p0 = SkPoint::Make(end_points[0], end_points[1]);
47 SkPoint p1 = SkPoint::Make(end_points[2], end_points[3]);
48 const DlColor* colors_array = reinterpret_cast<const DlColor*>(colors.data());
49
50 dl_shader_ = DlColorSource::MakeLinear(
51 p0, p1, colors.num_elements(), colors_array, color_stops.data(),
52 tile_mode, has_matrix ? &sk_matrix : nullptr);
53 // Just a sanity check, all gradient shaders should be thread-safe
54 FML_DCHECK(dl_shader_->isUIThreadSafe());
55}
uint32_t SkColor
Definition: SkColor.h:37
static std::shared_ptr< DlLinearGradientColorSource > MakeLinear(const SkPoint start_point, const SkPoint end_point, uint32_t stop_count, const DlColor *colors, const float *stops, DlTileMode tile_mode, const SkMatrix *matrix=nullptr)
SkMatrix sk_matrix
#define FML_DCHECK(condition)
Definition: logging.h:103
PODArray< SkColor > colors
Definition: SkRecords.h:276
constexpr SkMatrix ToSkMatrix(const DlMatrix &matrix)
flutter::DlColor DlColor
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173

◆ initRadial()

void flutter::CanvasGradient::initRadial ( double  center_x,
double  center_y,
double  radius,
const tonic::Int32List &  colors,
const tonic::Float32List &  color_stops,
DlTileMode  tile_mode,
const tonic::Float64List &  matrix4 
)

Definition at line 57 of file gradient.cc.

63 {
64 FML_DCHECK(colors.num_elements() == color_stops.num_elements() ||
65 color_stops.data() == nullptr);
66
67 static_assert(sizeof(SkColor) == sizeof(int32_t),
68 "SkColor doesn't use int32_t.");
69
71 bool has_matrix = matrix4.data() != nullptr;
72 if (has_matrix) {
73 sk_matrix = ToSkMatrix(matrix4);
74 }
75
76 const DlColor* colors_array = reinterpret_cast<const DlColor*>(colors.data());
77
78 dl_shader_ = DlColorSource::MakeRadial(
79 SkPoint::Make(SafeNarrow(center_x), SafeNarrow(center_y)),
80 SafeNarrow(radius), colors.num_elements(), colors_array,
81 color_stops.data(), tile_mode, has_matrix ? &sk_matrix : nullptr);
82 // Just a sanity check, all gradient shaders should be thread-safe
83 FML_DCHECK(dl_shader_->isUIThreadSafe());
84}
static std::shared_ptr< DlRadialGradientColorSource > MakeRadial(SkPoint center, SkScalar radius, uint32_t stop_count, const DlColor *colors, const float *stops, DlTileMode tile_mode, const SkMatrix *matrix=nullptr)
static float SafeNarrow(double value)

◆ initSweep()

void flutter::CanvasGradient::initSweep ( double  center_x,
double  center_y,
const tonic::Int32List &  colors,
const tonic::Float32List &  color_stops,
DlTileMode  tile_mode,
double  start_angle,
double  end_angle,
const tonic::Float64List &  matrix4 
)

Definition at line 86 of file gradient.cc.

93 {
94 FML_DCHECK(colors.num_elements() == color_stops.num_elements() ||
95 color_stops.data() == nullptr);
96
97 static_assert(sizeof(SkColor) == sizeof(int32_t),
98 "SkColor doesn't use int32_t.");
99
101 bool has_matrix = matrix4.data() != nullptr;
102 if (has_matrix) {
103 sk_matrix = ToSkMatrix(matrix4);
104 }
105
106 const DlColor* colors_array = reinterpret_cast<const DlColor*>(colors.data());
107
108 dl_shader_ = DlColorSource::MakeSweep(
109 SkPoint::Make(SafeNarrow(center_x), SafeNarrow(center_y)),
110 SafeNarrow(start_angle) * 180.0f / static_cast<float>(M_PI),
111 SafeNarrow(end_angle) * 180.0f / static_cast<float>(M_PI),
112 colors.num_elements(), colors_array, color_stops.data(), tile_mode,
113 has_matrix ? &sk_matrix : nullptr);
114 // Just a sanity check, all gradient shaders should be thread-safe
115 FML_DCHECK(dl_shader_->isUIThreadSafe());
116}
#define M_PI
static std::shared_ptr< DlSweepGradientColorSource > MakeSweep(SkPoint center, SkScalar start, SkScalar end, uint32_t stop_count, const DlColor *colors, const float *stops, DlTileMode tile_mode, const SkMatrix *matrix=nullptr)

◆ initTwoPointConical()

void flutter::CanvasGradient::initTwoPointConical ( double  start_x,
double  start_y,
double  start_radius,
double  end_x,
double  end_y,
double  end_radius,
const tonic::Int32List &  colors,
const tonic::Float32List &  color_stops,
DlTileMode  tile_mode,
const tonic::Float64List &  matrix4 
)

Definition at line 118 of file gradient.cc.

127 {
128 FML_DCHECK(colors.num_elements() == color_stops.num_elements() ||
129 color_stops.data() == nullptr);
130
131 static_assert(sizeof(SkColor) == sizeof(int32_t),
132 "SkColor doesn't use int32_t.");
133
135 bool has_matrix = matrix4.data() != nullptr;
136 if (has_matrix) {
137 sk_matrix = ToSkMatrix(matrix4);
138 }
139
140 const DlColor* colors_array = reinterpret_cast<const DlColor*>(colors.data());
141
142 dl_shader_ = DlColorSource::MakeConical(
143 SkPoint::Make(SafeNarrow(start_x), SafeNarrow(start_y)),
144 SafeNarrow(start_radius),
145 SkPoint::Make(SafeNarrow(end_x), SafeNarrow(end_y)),
146 SafeNarrow(end_radius), colors.num_elements(), colors_array,
147 color_stops.data(), tile_mode, has_matrix ? &sk_matrix : nullptr);
148 // Just a sanity check, all gradient shaders should be thread-safe
149 FML_DCHECK(dl_shader_->isUIThreadSafe());
150}
static std::shared_ptr< DlConicalGradientColorSource > MakeConical(SkPoint start_center, SkScalar start_radius, SkPoint end_center, SkScalar end_radius, uint32_t stop_count, const DlColor *colors, const float *stops, DlTileMode tile_mode, const SkMatrix *matrix=nullptr)

◆ shader()

std::shared_ptr< DlColorSource > flutter::CanvasGradient::shader ( DlImageSampling  sampling)
inlineoverridevirtual

Implements flutter::Shader.

Definition at line 57 of file gradient.h.

57 {
58 // Gradient color sources do not have image sampling variants...
59 return dl_shader_;
60 }

The documentation for this class was generated from the following files: