Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit cad3ee7

Browse files
committed
added sweep gradient
1 parent c404781 commit cad3ee7

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

lib/ui/painting.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4664,7 +4664,7 @@ base class Gradient extends Shader {
46644664
assert(matrix4 == null || _matrix4IsValid(matrix4)),
46654665
super._() {
46664666
_validateColorStops(colors, colorStops);
4667-
final Int32List colorsBuffer = _encodeColorList(colors);
4667+
final Float32List colorsBuffer = _encodeWideColorList(colors);
46684668
final Float32List? colorStopsBuffer = colorStops == null ? null : Float32List.fromList(colorStops);
46694669
_constructor();
46704670
_initSweep(center.dx, center.dy, colorsBuffer, colorStopsBuffer, tileMode.index, startAngle, endAngle, matrix4);
@@ -4703,7 +4703,7 @@ base class Gradient extends Shader {
47034703
external void _initSweep(
47044704
double centerX,
47054705
double centerY,
4706-
Int32List colors,
4706+
Float32List colors,
47074707
Float32List? colorStops,
47084708
int tileMode,
47094709
double startAngle,

lib/ui/painting/gradient.cc

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,13 @@ void CanvasGradient::initRadial(double center_x,
101101

102102
void CanvasGradient::initSweep(double center_x,
103103
double center_y,
104-
const tonic::Int32List& colors,
104+
const tonic::Float32List& colors,
105105
const tonic::Float32List& color_stops,
106106
DlTileMode tile_mode,
107107
double start_angle,
108108
double end_angle,
109109
const tonic::Float64List& matrix4) {
110-
FML_DCHECK(colors.num_elements() == color_stops.num_elements() ||
110+
FML_DCHECK(colors.num_elements() == (color_stops.num_elements() * 4) ||
111111
color_stops.data() == nullptr);
112112

113113
static_assert(sizeof(SkColor) == sizeof(int32_t),
@@ -121,16 +121,20 @@ void CanvasGradient::initSweep(double center_x,
121121

122122
std::vector<DlColor> dl_colors;
123123
dl_colors.reserve(colors.num_elements());
124-
for (int i = 0; i < colors.num_elements(); ++i) {
125-
dl_colors.emplace_back(DlColor(colors[i]));
124+
for (int i = 0; i < colors.num_elements(); i += 4) {
125+
DlScalar a = colors[i + 0];
126+
DlScalar r = colors[i + 1];
127+
DlScalar g = colors[i + 2];
128+
DlScalar b = colors[i + 3];
129+
dl_colors.emplace_back(DlColor(a, r, g, b, DlColorSpace::kExtendedSRGB));
126130
}
127131

128132
dl_shader_ = DlColorSource::MakeSweep(
129133
SkPoint::Make(SafeNarrow(center_x), SafeNarrow(center_y)),
130134
SafeNarrow(start_angle) * 180.0f / static_cast<float>(M_PI),
131135
SafeNarrow(end_angle) * 180.0f / static_cast<float>(M_PI),
132-
colors.num_elements(), dl_colors.data(), color_stops.data(), tile_mode,
133-
has_matrix ? &sk_matrix : nullptr);
136+
color_stops.num_elements(), dl_colors.data(), color_stops.data(),
137+
tile_mode, has_matrix ? &sk_matrix : nullptr);
134138
// Just a sanity check, all gradient shaders should be thread-safe
135139
FML_DCHECK(dl_shader_->isUIThreadSafe());
136140
}

lib/ui/painting/gradient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class CanvasGradient : public Shader {
3636

3737
void initSweep(double center_x,
3838
double center_y,
39-
const tonic::Int32List& colors,
39+
const tonic::Float32List& colors,
4040
const tonic::Float32List& color_stops,
4141
DlTileMode tile_mode,
4242
double start_angle,

0 commit comments

Comments
 (0)