@@ -24,13 +24,14 @@ void CanvasGradient::Create(Dart_Handle wrapper) {
2424}
2525
2626void CanvasGradient::initLinear (const tonic::Float32List& end_points,
27- const tonic::Int32List & colors,
27+ const tonic::Float32List & colors,
2828 const tonic::Float32List& color_stops,
2929 DlTileMode tile_mode,
3030 const tonic::Float64List& matrix4) {
3131 FML_DCHECK (end_points.num_elements () == 4 );
32- FML_DCHECK (colors.num_elements () == color_stops.num_elements () ||
32+ FML_DCHECK (colors.num_elements () == ( color_stops.num_elements () * 4 ) ||
3333 color_stops.data () == nullptr );
34+ int num_colors = colors.num_elements () / 4 ;
3435
3536 static_assert (sizeof (SkPoint) == sizeof (float ) * 2 ,
3637 " SkPoint doesn't use floats." );
@@ -46,28 +47,32 @@ void CanvasGradient::initLinear(const tonic::Float32List& end_points,
4647 SkPoint p0 = SkPoint::Make (end_points[0 ], end_points[1 ]);
4748 SkPoint p1 = SkPoint::Make (end_points[2 ], end_points[3 ]);
4849 std::vector<DlColor> dl_colors;
49- dl_colors.reserve (colors.num_elements ());
50- for (int i = 0 ; i < colors.num_elements (); ++i) {
51- // / TODO(gaaclarke): Make this preserve wide gamut colors.
52- dl_colors.emplace_back (DlColor (colors[i]));
50+ dl_colors.reserve (num_colors);
51+ for (int i = 0 ; i < colors.num_elements (); i += 4 ) {
52+ DlScalar a = colors[i + 0 ];
53+ DlScalar r = colors[i + 1 ];
54+ DlScalar g = colors[i + 2 ];
55+ DlScalar b = colors[i + 3 ];
56+ dl_colors.emplace_back (DlColor (a, r, g, b, DlColorSpace::kExtendedSRGB ));
5357 }
5458
55- dl_shader_ = DlColorSource::MakeLinear (
56- p0, p1, colors. num_elements (), dl_colors. data (), color_stops.data (),
57- tile_mode, has_matrix ? &sk_matrix : nullptr );
59+ dl_shader_ = DlColorSource::MakeLinear (p0, p1, num_colors, dl_colors. data (),
60+ color_stops.data (), tile_mode ,
61+ has_matrix ? &sk_matrix : nullptr );
5862 // Just a sanity check, all gradient shaders should be thread-safe
5963 FML_DCHECK (dl_shader_->isUIThreadSafe ());
6064}
6165
6266void CanvasGradient::initRadial (double center_x,
6367 double center_y,
6468 double radius,
65- const tonic::Int32List & colors,
69+ const tonic::Float32List & colors,
6670 const tonic::Float32List& color_stops,
6771 DlTileMode tile_mode,
6872 const tonic::Float64List& matrix4) {
69- FML_DCHECK (colors.num_elements () == color_stops.num_elements () ||
73+ FML_DCHECK (colors.num_elements () == ( color_stops.num_elements () * 4 ) ||
7074 color_stops.data () == nullptr );
75+ int num_colors = colors.num_elements () / 4 ;
7176
7277 static_assert (sizeof (SkColor) == sizeof (int32_t ),
7378 " SkColor doesn't use int32_t." );
@@ -79,29 +84,34 @@ void CanvasGradient::initRadial(double center_x,
7984 }
8085
8186 std::vector<DlColor> dl_colors;
82- dl_colors.reserve (colors.num_elements ());
83- for (int i = 0 ; i < colors.num_elements (); ++i) {
84- dl_colors.emplace_back (DlColor (colors[i]));
87+ dl_colors.reserve (num_colors);
88+ for (int i = 0 ; i < colors.num_elements (); i += 4 ) {
89+ DlScalar a = colors[i + 0 ];
90+ DlScalar r = colors[i + 1 ];
91+ DlScalar g = colors[i + 2 ];
92+ DlScalar b = colors[i + 3 ];
93+ dl_colors.emplace_back (DlColor (a, r, g, b, DlColorSpace::kExtendedSRGB ));
8594 }
8695
8796 dl_shader_ = DlColorSource::MakeRadial (
8897 SkPoint::Make (SafeNarrow (center_x), SafeNarrow (center_y)),
89- SafeNarrow (radius), colors. num_elements (), dl_colors .data (),
90- color_stops. data (), tile_mode, has_matrix ? &sk_matrix : nullptr );
98+ SafeNarrow (radius), num_colors, dl_colors. data (), color_stops .data (),
99+ tile_mode, has_matrix ? &sk_matrix : nullptr );
91100 // Just a sanity check, all gradient shaders should be thread-safe
92101 FML_DCHECK (dl_shader_->isUIThreadSafe ());
93102}
94103
95104void CanvasGradient::initSweep (double center_x,
96105 double center_y,
97- const tonic::Int32List & colors,
106+ const tonic::Float32List & colors,
98107 const tonic::Float32List& color_stops,
99108 DlTileMode tile_mode,
100109 double start_angle,
101110 double end_angle,
102111 const tonic::Float64List& matrix4) {
103- FML_DCHECK (colors.num_elements () == color_stops.num_elements () ||
112+ FML_DCHECK (colors.num_elements () == ( color_stops.num_elements () * 4 ) ||
104113 color_stops.data () == nullptr );
114+ int num_colors = colors.num_elements () / 4 ;
105115
106116 static_assert (sizeof (SkColor) == sizeof (int32_t ),
107117 " SkColor doesn't use int32_t." );
@@ -113,16 +123,20 @@ void CanvasGradient::initSweep(double center_x,
113123 }
114124
115125 std::vector<DlColor> dl_colors;
116- dl_colors.reserve (colors.num_elements ());
117- for (int i = 0 ; i < colors.num_elements (); ++i) {
118- dl_colors.emplace_back (DlColor (colors[i]));
126+ dl_colors.reserve (num_colors);
127+ for (int i = 0 ; i < colors.num_elements (); i += 4 ) {
128+ DlScalar a = colors[i + 0 ];
129+ DlScalar r = colors[i + 1 ];
130+ DlScalar g = colors[i + 2 ];
131+ DlScalar b = colors[i + 3 ];
132+ dl_colors.emplace_back (DlColor (a, r, g, b, DlColorSpace::kExtendedSRGB ));
119133 }
120134
121135 dl_shader_ = DlColorSource::MakeSweep (
122136 SkPoint::Make (SafeNarrow (center_x), SafeNarrow (center_y)),
123137 SafeNarrow (start_angle) * 180 .0f / static_cast <float >(M_PI),
124- SafeNarrow (end_angle) * 180 .0f / static_cast <float >(M_PI),
125- colors. num_elements (), dl_colors.data (), color_stops.data (), tile_mode,
138+ SafeNarrow (end_angle) * 180 .0f / static_cast <float >(M_PI), num_colors,
139+ dl_colors.data (), color_stops.data (), tile_mode,
126140 has_matrix ? &sk_matrix : nullptr );
127141 // Just a sanity check, all gradient shaders should be thread-safe
128142 FML_DCHECK (dl_shader_->isUIThreadSafe ());
@@ -134,12 +148,13 @@ void CanvasGradient::initTwoPointConical(double start_x,
134148 double end_x,
135149 double end_y,
136150 double end_radius,
137- const tonic::Int32List & colors,
151+ const tonic::Float32List & colors,
138152 const tonic::Float32List& color_stops,
139153 DlTileMode tile_mode,
140154 const tonic::Float64List& matrix4) {
141- FML_DCHECK (colors.num_elements () == color_stops.num_elements () ||
155+ FML_DCHECK (colors.num_elements () == ( color_stops.num_elements () * 4 ) ||
142156 color_stops.data () == nullptr );
157+ int num_colors = colors.num_elements () / 4 ;
143158
144159 static_assert (sizeof (SkColor) == sizeof (int32_t ),
145160 " SkColor doesn't use int32_t." );
@@ -151,17 +166,21 @@ void CanvasGradient::initTwoPointConical(double start_x,
151166 }
152167
153168 std::vector<DlColor> dl_colors;
154- dl_colors.reserve (colors.num_elements ());
155- for (int i = 0 ; i < colors.num_elements (); ++i) {
156- dl_colors.emplace_back (DlColor (colors[i]));
169+ dl_colors.reserve (num_colors);
170+ for (int i = 0 ; i < colors.num_elements (); i += 4 ) {
171+ DlScalar a = colors[i + 0 ];
172+ DlScalar r = colors[i + 1 ];
173+ DlScalar g = colors[i + 2 ];
174+ DlScalar b = colors[i + 3 ];
175+ dl_colors.emplace_back (DlColor (a, r, g, b, DlColorSpace::kExtendedSRGB ));
157176 }
158177
159178 dl_shader_ = DlColorSource::MakeConical (
160179 SkPoint::Make (SafeNarrow (start_x), SafeNarrow (start_y)),
161180 SafeNarrow (start_radius),
162181 SkPoint::Make (SafeNarrow (end_x), SafeNarrow (end_y)),
163- SafeNarrow (end_radius), colors. num_elements (), dl_colors .data (),
164- color_stops. data (), tile_mode, has_matrix ? &sk_matrix : nullptr );
182+ SafeNarrow (end_radius), num_colors, dl_colors. data (), color_stops .data (),
183+ tile_mode, has_matrix ? &sk_matrix : nullptr );
165184 // Just a sanity check, all gradient shaders should be thread-safe
166185 FML_DCHECK (dl_shader_->isUIThreadSafe ());
167186}
0 commit comments