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

Commit 4d01c0e

Browse files
committed
added conical gradient
1 parent c469921 commit 4d01c0e

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

lib/ui/painting.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4605,17 +4605,15 @@ base class Gradient extends Shader {
46054605
assert(matrix4 == null || _matrix4IsValid(matrix4)),
46064606
super._() {
46074607
_validateColorStops(colors, colorStops);
4608-
final Int32List colorsBuffer = _encodeColorList(colors);
46094608
final Float32List? colorStopsBuffer = colorStops == null ? null : Float32List.fromList(colorStops);
4609+
final Float32List colorsBuffer = _encodeWideColorList(colors);
46104610

46114611
// If focal is null or focal radius is null, this should be treated as a regular radial gradient
46124612
// If focal == center and the focal radius is 0.0, it's still a regular radial gradient
46134613
if (focal == null || (focal == center && focalRadius == 0.0)) {
4614-
final Float32List colorsBuffer = _encodeWideColorList(colors);
46154614
_constructor();
46164615
_initRadial(center.dx, center.dy, radius, colorsBuffer, colorStopsBuffer, tileMode.index, matrix4);
46174616
} else {
4618-
final Int32List colorsBuffer = _encodeColorList(colors);
46194617
assert(center != Offset.zero || focal != Offset.zero); // will result in exception(s) in Skia side
46204618
_constructor();
46214619
_initConical(focal.dx, focal.dy, focalRadius, center.dx, center.dy, radius, colorsBuffer, colorStopsBuffer, tileMode.index, matrix4);
@@ -4696,7 +4694,7 @@ base class Gradient extends Shader {
46964694
double endX,
46974695
double endY,
46984696
double endRadius,
4699-
Int32List colors,
4697+
Float32List colors,
47004698
Float32List? colorStops,
47014699
int tileMode,
47024700
Float64List? matrix4);

lib/ui/painting/gradient.cc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,11 @@ void CanvasGradient::initTwoPointConical(double start_x,
141141
double end_x,
142142
double end_y,
143143
double end_radius,
144-
const tonic::Int32List& colors,
144+
const tonic::Float32List& colors,
145145
const tonic::Float32List& color_stops,
146146
DlTileMode tile_mode,
147147
const tonic::Float64List& matrix4) {
148-
FML_DCHECK(colors.num_elements() == color_stops.num_elements() ||
148+
FML_DCHECK(colors.num_elements() == (color_stops.num_elements() * 4) ||
149149
color_stops.data() == nullptr);
150150

151151
static_assert(sizeof(SkColor) == sizeof(int32_t),
@@ -159,15 +159,19 @@ void CanvasGradient::initTwoPointConical(double start_x,
159159

160160
std::vector<DlColor> dl_colors;
161161
dl_colors.reserve(colors.num_elements());
162-
for (int i = 0; i < colors.num_elements(); ++i) {
163-
dl_colors.emplace_back(DlColor(colors[i]));
162+
for (int i = 0; i < colors.num_elements(); i += 4) {
163+
DlScalar a = colors[i + 0];
164+
DlScalar r = colors[i + 1];
165+
DlScalar g = colors[i + 2];
166+
DlScalar b = colors[i + 3];
167+
dl_colors.emplace_back(DlColor(a, r, g, b, DlColorSpace::kExtendedSRGB));
164168
}
165169

166170
dl_shader_ = DlColorSource::MakeConical(
167171
SkPoint::Make(SafeNarrow(start_x), SafeNarrow(start_y)),
168172
SafeNarrow(start_radius),
169173
SkPoint::Make(SafeNarrow(end_x), SafeNarrow(end_y)),
170-
SafeNarrow(end_radius), colors.num_elements(), dl_colors.data(),
174+
SafeNarrow(end_radius), color_stops.num_elements(), dl_colors.data(),
171175
color_stops.data(), tile_mode, has_matrix ? &sk_matrix : nullptr);
172176
// Just a sanity check, all gradient shaders should be thread-safe
173177
FML_DCHECK(dl_shader_->isUIThreadSafe());

lib/ui/painting/gradient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class CanvasGradient : public Shader {
4949
double end_x,
5050
double end_y,
5151
double end_radius,
52-
const tonic::Int32List& colors,
52+
const tonic::Float32List& colors,
5353
const tonic::Float32List& color_stops,
5454
DlTileMode tile_mode,
5555
const tonic::Float64List& matrix4);

0 commit comments

Comments
 (0)