Flutter Engine
 
Loading...
Searching...
No Matches
flutter::CanvasGradient Class Reference

#include <gradient.h>

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

Public Member Functions

 ~CanvasGradient () override
 
void initLinear (const tonic::Float32List &end_points, const tonic::Float32List &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::Float32List &colors, const tonic::Float32List &color_stops, DlTileMode tile_mode, const tonic::Float64List &matrix4)
 
void initSweep (double center_x, double center_y, const tonic::Float32List &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::Float32List &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
 
- 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< T >
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
 
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< T >
 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()

References flutter::UIDartState::ThrowIfUIOperationsProhibited().

◆ initLinear()

void flutter::CanvasGradient::initLinear ( const tonic::Float32List &  end_points,
const tonic::Float32List &  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() * 4) ||
33 color_stops.data() == nullptr);
34 int num_colors = colors.num_elements() / 4;
35
36 static_assert(sizeof(DlPoint) == sizeof(float) * 2,
37 "DlPoint doesn't use floats.");
38
39 DlMatrix dl_matrix;
40 bool has_matrix = matrix4.data() != nullptr;
41 if (has_matrix) {
42 dl_matrix = ToDlMatrix(matrix4);
43 }
44
45 DlPoint p0 = DlPoint(end_points[0], end_points[1]);
46 DlPoint p1 = DlPoint(end_points[2], end_points[3]);
47 dl_shader_ = DlColorSource::MakeLinear(p0, p1, num_colors, colors.data(),
48 color_stops.data(), tile_mode,
49 has_matrix ? &dl_matrix : nullptr);
50 // Just a sanity check, all gradient shaders should be thread-safe
51 FML_DCHECK(dl_shader_->isUIThreadSafe());
52}
static std::shared_ptr< DlColorSource > MakeLinear(const DlPoint start_point, const DlPoint end_point, uint32_t stop_count, const DlColor *colors, const float *stops, DlTileMode tile_mode, const DlMatrix *matrix=nullptr)
#define FML_DCHECK(condition)
Definition logging.h:122
impeller::Matrix DlMatrix
DlMatrix ToDlMatrix(const SkMatrix &matrix)
impeller::Point DlPoint

References FML_DCHECK, flutter::DlColorSource::MakeLinear(), and flutter::ToDlMatrix().

◆ initRadial()

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

Definition at line 54 of file gradient.cc.

60 {
61 FML_DCHECK(colors.num_elements() == (color_stops.num_elements() * 4) ||
62 color_stops.data() == nullptr);
63 int num_colors = colors.num_elements() / 4;
64
65 DlMatrix dl_matrix;
66 bool has_matrix = matrix4.data() != nullptr;
67 if (has_matrix) {
68 dl_matrix = ToDlMatrix(matrix4);
69 }
70
71 dl_shader_ = DlColorSource::MakeRadial(
72 DlPoint(SafeNarrow(center_x), SafeNarrow(center_y)), SafeNarrow(radius),
73 num_colors, colors.data(), color_stops.data(), tile_mode,
74 has_matrix ? &dl_matrix : nullptr);
75 // Just a sanity check, all gradient shaders should be thread-safe
76 FML_DCHECK(dl_shader_->isUIThreadSafe());
77}
static std::shared_ptr< DlColorSource > MakeRadial(DlPoint center, DlScalar radius, uint32_t stop_count, const DlColor *colors, const float *stops, DlTileMode tile_mode, const DlMatrix *matrix=nullptr)
static float SafeNarrow(double value)

References FML_DCHECK, flutter::DlColorSource::MakeRadial(), flutter::SafeNarrow(), and flutter::ToDlMatrix().

◆ initSweep()

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

Definition at line 79 of file gradient.cc.

86 {
87 FML_DCHECK(colors.num_elements() == (color_stops.num_elements() * 4) ||
88 color_stops.data() == nullptr);
89 int num_colors = colors.num_elements() / 4;
90
91 DlMatrix dl_matrix;
92 bool has_matrix = matrix4.data() != nullptr;
93 if (has_matrix) {
94 dl_matrix = ToDlMatrix(matrix4);
95 }
96
97 dl_shader_ = DlColorSource::MakeSweep(
98 DlPoint(SafeNarrow(center_x), SafeNarrow(center_y)),
99 SafeNarrow(start_angle) * 180.0f / static_cast<float>(M_PI),
100 SafeNarrow(end_angle) * 180.0f / static_cast<float>(M_PI), num_colors,
101 colors.data(), color_stops.data(), tile_mode,
102 has_matrix ? &dl_matrix : nullptr);
103 // Just a sanity check, all gradient shaders should be thread-safe
104 FML_DCHECK(dl_shader_->isUIThreadSafe());
105}
static std::shared_ptr< DlColorSource > MakeSweep(DlPoint center, DlScalar start, DlScalar end, uint32_t stop_count, const DlColor *colors, const float *stops, DlTileMode tile_mode, const DlMatrix *matrix=nullptr)

References FML_DCHECK, flutter::DlColorSource::MakeSweep(), flutter::SafeNarrow(), and flutter::ToDlMatrix().

◆ 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::Float32List &  colors,
const tonic::Float32List &  color_stops,
DlTileMode  tile_mode,
const tonic::Float64List &  matrix4 
)

Definition at line 107 of file gradient.cc.

116 {
117 FML_DCHECK(colors.num_elements() == (color_stops.num_elements() * 4) ||
118 color_stops.data() == nullptr);
119 int num_colors = colors.num_elements() / 4;
120
121 DlMatrix dl_matrix;
122 bool has_matrix = matrix4.data() != nullptr;
123 if (has_matrix) {
124 dl_matrix = ToDlMatrix(matrix4);
125 }
126
127 dl_shader_ = DlColorSource::MakeConical(
128 DlPoint(SafeNarrow(start_x), SafeNarrow(start_y)),
129 SafeNarrow(start_radius), DlPoint(SafeNarrow(end_x), SafeNarrow(end_y)),
130 SafeNarrow(end_radius), num_colors, colors.data(), color_stops.data(),
131 tile_mode, has_matrix ? &dl_matrix : nullptr);
132 // Just a sanity check, all gradient shaders should be thread-safe
133 FML_DCHECK(dl_shader_->isUIThreadSafe());
134}
static std::shared_ptr< DlColorSource > MakeConical(DlPoint start_center, DlScalar start_radius, DlPoint end_center, DlScalar end_radius, uint32_t stop_count, const DlColor *colors, const float *stops, DlTileMode tile_mode, const DlMatrix *matrix=nullptr)

References FML_DCHECK, flutter::DlColorSource::MakeConical(), flutter::SafeNarrow(), and flutter::ToDlMatrix().

◆ 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: