From 408f54995316f53a63aafa3c6ab5f8badc2d3196 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Fri, 23 Aug 2024 15:25:16 -0700 Subject: [PATCH 1/7] Framework wide gamut - implemented linear gradients --- lib/ui/painting.dart | 21 +++++++++++++++++++-- lib/ui/painting/gradient.cc | 17 +++++++++++------ lib/ui/painting/gradient.h | 2 +- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/lib/ui/painting.dart b/lib/ui/painting.dart index 006235c0e5054..b2d31f178a445 100644 --- a/lib/ui/painting.dart +++ b/lib/ui/painting.dart @@ -4452,6 +4452,21 @@ enum TileMode { decal, } +Float32List _encodeWideColorList(List colors) { + final int colorCount = colors.length; + final Float32List result = Float32List(colorCount * 4); + for (int i = 0; i < colorCount; ++i) { + final Color colorXr = + colors[i].withValues(colorSpace: ColorSpace.extendedSRGB); + result[i*4+0] = colorXr.a; + result[i*4+1] = colorXr.r; + result[i*4+2] = colorXr.g; + result[i*4+3] = colorXr.b; + } + return result; +} + + Int32List _encodeColorList(List colors) { final int colorCount = colors.length; final Int32List result = Int32List(colorCount); @@ -4533,11 +4548,13 @@ base class Gradient extends Shader { assert(_offsetIsValid(to)), assert(matrix4 == null || _matrix4IsValid(matrix4)), super._() { + print("gradient.linear1"); _validateColorStops(colors, colorStops); final Float32List endPointsBuffer = _encodeTwoPoints(from, to); - final Int32List colorsBuffer = _encodeColorList(colors); + final Float32List colorsBuffer = _encodeWideColorList(colors); final Float32List? colorStopsBuffer = colorStops == null ? null : Float32List.fromList(colorStops); _constructor(); + print("gradient.linear2"); _initLinear(endPointsBuffer, colorsBuffer, colorStopsBuffer, tileMode.index, matrix4); } @@ -4657,7 +4674,7 @@ base class Gradient extends Shader { external void _constructor(); @Native, Handle, Handle, Handle, Int32, Handle)>(symbol: 'Gradient::initLinear') - external void _initLinear(Float32List endPoints, Int32List colors, Float32List? colorStops, int tileMode, Float64List? matrix4); + external void _initLinear(Float32List endPoints, Float32List colors, Float32List? colorStops, int tileMode, Float64List? matrix4); @Native, Double, Double, Double, Handle, Handle, Int32, Handle)>(symbol: 'Gradient::initRadial') external void _initRadial( diff --git a/lib/ui/painting/gradient.cc b/lib/ui/painting/gradient.cc index 4be8d056e9a82..17b7579674df6 100644 --- a/lib/ui/painting/gradient.cc +++ b/lib/ui/painting/gradient.cc @@ -24,12 +24,12 @@ void CanvasGradient::Create(Dart_Handle wrapper) { } void CanvasGradient::initLinear(const tonic::Float32List& end_points, - const tonic::Int32List& colors, + const tonic::Float32List& colors, const tonic::Float32List& color_stops, DlTileMode tile_mode, const tonic::Float64List& matrix4) { FML_DCHECK(end_points.num_elements() == 4); - FML_DCHECK(colors.num_elements() == color_stops.num_elements() || + FML_DCHECK(colors.num_elements() == (color_stops.num_elements() * 4) || color_stops.data() == nullptr); static_assert(sizeof(SkPoint) == sizeof(float) * 2, @@ -46,14 +46,19 @@ void CanvasGradient::initLinear(const tonic::Float32List& end_points, SkPoint p0 = SkPoint::Make(end_points[0], end_points[1]); SkPoint p1 = SkPoint::Make(end_points[2], end_points[3]); std::vector dl_colors; - dl_colors.reserve(colors.num_elements()); - for (int i = 0; i < colors.num_elements(); ++i) { + dl_colors.reserve(color_stops.num_elements()); + for (int i = 0; i < colors.num_elements(); i += 4) { /// TODO(gaaclarke): Make this preserve wide gamut colors. - dl_colors.emplace_back(DlColor(colors[i])); + DlScalar a = colors[i + 0]; + DlScalar r = colors[i + 1]; + DlScalar g = colors[i + 2]; + DlScalar b = colors[i + 3]; + FML_LOG(ERROR) << a << " " << r << " " << g << " " << b; + dl_colors.emplace_back(DlColor(a, r, g, b, DlColorSpace::kExtendedSRGB)); } dl_shader_ = DlColorSource::MakeLinear( - p0, p1, colors.num_elements(), dl_colors.data(), color_stops.data(), + p0, p1, color_stops.num_elements(), dl_colors.data(), color_stops.data(), tile_mode, has_matrix ? &sk_matrix : nullptr); // Just a sanity check, all gradient shaders should be thread-safe FML_DCHECK(dl_shader_->isUIThreadSafe()); diff --git a/lib/ui/painting/gradient.h b/lib/ui/painting/gradient.h index a0338d05fa5e7..ef5d4cf3fc02f 100644 --- a/lib/ui/painting/gradient.h +++ b/lib/ui/painting/gradient.h @@ -21,7 +21,7 @@ class CanvasGradient : public Shader { static void Create(Dart_Handle wrapper); void initLinear(const tonic::Float32List& end_points, - const tonic::Int32List& colors, + const tonic::Float32List& colors, const tonic::Float32List& color_stops, DlTileMode tile_mode, const tonic::Float64List& matrix4); From fc754cfd7adabf783926e78a6919fe3a75bfe30e Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Fri, 23 Aug 2024 15:40:00 -0700 Subject: [PATCH 2/7] removed todo --- lib/ui/painting/gradient.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/ui/painting/gradient.cc b/lib/ui/painting/gradient.cc index 17b7579674df6..95c90fdec71b9 100644 --- a/lib/ui/painting/gradient.cc +++ b/lib/ui/painting/gradient.cc @@ -48,7 +48,6 @@ void CanvasGradient::initLinear(const tonic::Float32List& end_points, std::vector dl_colors; dl_colors.reserve(color_stops.num_elements()); for (int i = 0; i < colors.num_elements(); i += 4) { - /// TODO(gaaclarke): Make this preserve wide gamut colors. DlScalar a = colors[i + 0]; DlScalar r = colors[i + 1]; DlScalar g = colors[i + 2]; From d9c6a963ea0b12e5a5784056b951537f977b1fba Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Fri, 23 Aug 2024 16:11:08 -0700 Subject: [PATCH 3/7] implemented radial gradient --- lib/ui/painting.dart | 4 +++- lib/ui/painting/gradient.cc | 15 +++++++++------ lib/ui/painting/gradient.h | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/ui/painting.dart b/lib/ui/painting.dart index b2d31f178a445..c68b519ddd9a2 100644 --- a/lib/ui/painting.dart +++ b/lib/ui/painting.dart @@ -4611,9 +4611,11 @@ base class Gradient extends Shader { // If focal is null or focal radius is null, this should be treated as a regular radial gradient // If focal == center and the focal radius is 0.0, it's still a regular radial gradient if (focal == null || (focal == center && focalRadius == 0.0)) { + final Float32List colorsBuffer = _encodeWideColorList(colors); _constructor(); _initRadial(center.dx, center.dy, radius, colorsBuffer, colorStopsBuffer, tileMode.index, matrix4); } else { + final Int32List colorsBuffer = _encodeColorList(colors); assert(center != Offset.zero || focal != Offset.zero); // will result in exception(s) in Skia side _constructor(); _initConical(focal.dx, focal.dy, focalRadius, center.dx, center.dy, radius, colorsBuffer, colorStopsBuffer, tileMode.index, matrix4); @@ -4681,7 +4683,7 @@ base class Gradient extends Shader { double centerX, double centerY, double radius, - Int32List colors, + Float32List colors, Float32List? colorStops, int tileMode, Float64List? matrix4); diff --git a/lib/ui/painting/gradient.cc b/lib/ui/painting/gradient.cc index 95c90fdec71b9..e722029c78c7c 100644 --- a/lib/ui/painting/gradient.cc +++ b/lib/ui/painting/gradient.cc @@ -52,7 +52,6 @@ void CanvasGradient::initLinear(const tonic::Float32List& end_points, DlScalar r = colors[i + 1]; DlScalar g = colors[i + 2]; DlScalar b = colors[i + 3]; - FML_LOG(ERROR) << a << " " << r << " " << g << " " << b; dl_colors.emplace_back(DlColor(a, r, g, b, DlColorSpace::kExtendedSRGB)); } @@ -66,11 +65,11 @@ void CanvasGradient::initLinear(const tonic::Float32List& end_points, void CanvasGradient::initRadial(double center_x, double center_y, double radius, - const tonic::Int32List& colors, + const tonic::Float32List& colors, const tonic::Float32List& color_stops, DlTileMode tile_mode, const tonic::Float64List& matrix4) { - FML_DCHECK(colors.num_elements() == color_stops.num_elements() || + FML_DCHECK(colors.num_elements() == (color_stops.num_elements() * 4) || color_stops.data() == nullptr); static_assert(sizeof(SkColor) == sizeof(int32_t), @@ -84,13 +83,17 @@ void CanvasGradient::initRadial(double center_x, std::vector dl_colors; dl_colors.reserve(colors.num_elements()); - for (int i = 0; i < colors.num_elements(); ++i) { - dl_colors.emplace_back(DlColor(colors[i])); + for (int i = 0; i < colors.num_elements(); i += 4) { + DlScalar a = colors[i + 0]; + DlScalar r = colors[i + 1]; + DlScalar g = colors[i + 2]; + DlScalar b = colors[i + 3]; + dl_colors.emplace_back(DlColor(a, r, g, b, DlColorSpace::kExtendedSRGB)); } dl_shader_ = DlColorSource::MakeRadial( SkPoint::Make(SafeNarrow(center_x), SafeNarrow(center_y)), - SafeNarrow(radius), colors.num_elements(), dl_colors.data(), + SafeNarrow(radius), color_stops.num_elements(), dl_colors.data(), color_stops.data(), tile_mode, has_matrix ? &sk_matrix : nullptr); // Just a sanity check, all gradient shaders should be thread-safe FML_DCHECK(dl_shader_->isUIThreadSafe()); diff --git a/lib/ui/painting/gradient.h b/lib/ui/painting/gradient.h index ef5d4cf3fc02f..4ce96b8aee82f 100644 --- a/lib/ui/painting/gradient.h +++ b/lib/ui/painting/gradient.h @@ -29,7 +29,7 @@ class CanvasGradient : public Shader { void initRadial(double center_x, double center_y, double radius, - const tonic::Int32List& colors, + const tonic::Float32List& colors, const tonic::Float32List& color_stops, DlTileMode tile_mode, const tonic::Float64List& matrix4); From 976963c5d6fcf2eb9789ee0c29ab5c91a2e915b7 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Fri, 23 Aug 2024 16:28:47 -0700 Subject: [PATCH 4/7] added conical gradient --- lib/ui/painting.dart | 6 ++---- lib/ui/painting/gradient.cc | 14 +++++++++----- lib/ui/painting/gradient.h | 2 +- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/ui/painting.dart b/lib/ui/painting.dart index c68b519ddd9a2..01eb569ec5f3b 100644 --- a/lib/ui/painting.dart +++ b/lib/ui/painting.dart @@ -4605,17 +4605,15 @@ base class Gradient extends Shader { assert(matrix4 == null || _matrix4IsValid(matrix4)), super._() { _validateColorStops(colors, colorStops); - final Int32List colorsBuffer = _encodeColorList(colors); final Float32List? colorStopsBuffer = colorStops == null ? null : Float32List.fromList(colorStops); + final Float32List colorsBuffer = _encodeWideColorList(colors); // If focal is null or focal radius is null, this should be treated as a regular radial gradient // If focal == center and the focal radius is 0.0, it's still a regular radial gradient if (focal == null || (focal == center && focalRadius == 0.0)) { - final Float32List colorsBuffer = _encodeWideColorList(colors); _constructor(); _initRadial(center.dx, center.dy, radius, colorsBuffer, colorStopsBuffer, tileMode.index, matrix4); } else { - final Int32List colorsBuffer = _encodeColorList(colors); assert(center != Offset.zero || focal != Offset.zero); // will result in exception(s) in Skia side _constructor(); _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 { double endX, double endY, double endRadius, - Int32List colors, + Float32List colors, Float32List? colorStops, int tileMode, Float64List? matrix4); diff --git a/lib/ui/painting/gradient.cc b/lib/ui/painting/gradient.cc index e722029c78c7c..9665580d56517 100644 --- a/lib/ui/painting/gradient.cc +++ b/lib/ui/painting/gradient.cc @@ -141,11 +141,11 @@ void CanvasGradient::initTwoPointConical(double start_x, double end_x, double end_y, double end_radius, - const tonic::Int32List& colors, + const tonic::Float32List& colors, const tonic::Float32List& color_stops, DlTileMode tile_mode, const tonic::Float64List& matrix4) { - FML_DCHECK(colors.num_elements() == color_stops.num_elements() || + FML_DCHECK(colors.num_elements() == (color_stops.num_elements() * 4) || color_stops.data() == nullptr); static_assert(sizeof(SkColor) == sizeof(int32_t), @@ -159,15 +159,19 @@ void CanvasGradient::initTwoPointConical(double start_x, std::vector dl_colors; dl_colors.reserve(colors.num_elements()); - for (int i = 0; i < colors.num_elements(); ++i) { - dl_colors.emplace_back(DlColor(colors[i])); + for (int i = 0; i < colors.num_elements(); i += 4) { + DlScalar a = colors[i + 0]; + DlScalar r = colors[i + 1]; + DlScalar g = colors[i + 2]; + DlScalar b = colors[i + 3]; + dl_colors.emplace_back(DlColor(a, r, g, b, DlColorSpace::kExtendedSRGB)); } dl_shader_ = DlColorSource::MakeConical( SkPoint::Make(SafeNarrow(start_x), SafeNarrow(start_y)), SafeNarrow(start_radius), SkPoint::Make(SafeNarrow(end_x), SafeNarrow(end_y)), - SafeNarrow(end_radius), colors.num_elements(), dl_colors.data(), + SafeNarrow(end_radius), color_stops.num_elements(), dl_colors.data(), color_stops.data(), tile_mode, has_matrix ? &sk_matrix : nullptr); // Just a sanity check, all gradient shaders should be thread-safe FML_DCHECK(dl_shader_->isUIThreadSafe()); diff --git a/lib/ui/painting/gradient.h b/lib/ui/painting/gradient.h index 4ce96b8aee82f..0198642d03d91 100644 --- a/lib/ui/painting/gradient.h +++ b/lib/ui/painting/gradient.h @@ -49,7 +49,7 @@ class CanvasGradient : public Shader { double end_x, double end_y, double end_radius, - const tonic::Int32List& colors, + const tonic::Float32List& colors, const tonic::Float32List& color_stops, DlTileMode tile_mode, const tonic::Float64List& matrix4); From 5c0887fe3b08df1e2af7d7641bebc664f171d5b2 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Fri, 23 Aug 2024 16:48:37 -0700 Subject: [PATCH 5/7] added sweep gradient --- lib/ui/painting.dart | 4 ++-- lib/ui/painting/gradient.cc | 16 ++++++++++------ lib/ui/painting/gradient.h | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/ui/painting.dart b/lib/ui/painting.dart index 01eb569ec5f3b..5ef7a5ba69af1 100644 --- a/lib/ui/painting.dart +++ b/lib/ui/painting.dart @@ -4664,7 +4664,7 @@ base class Gradient extends Shader { assert(matrix4 == null || _matrix4IsValid(matrix4)), super._() { _validateColorStops(colors, colorStops); - final Int32List colorsBuffer = _encodeColorList(colors); + final Float32List colorsBuffer = _encodeWideColorList(colors); final Float32List? colorStopsBuffer = colorStops == null ? null : Float32List.fromList(colorStops); _constructor(); _initSweep(center.dx, center.dy, colorsBuffer, colorStopsBuffer, tileMode.index, startAngle, endAngle, matrix4); @@ -4703,7 +4703,7 @@ base class Gradient extends Shader { external void _initSweep( double centerX, double centerY, - Int32List colors, + Float32List colors, Float32List? colorStops, int tileMode, double startAngle, diff --git a/lib/ui/painting/gradient.cc b/lib/ui/painting/gradient.cc index 9665580d56517..63e2336fbef7f 100644 --- a/lib/ui/painting/gradient.cc +++ b/lib/ui/painting/gradient.cc @@ -101,13 +101,13 @@ void CanvasGradient::initRadial(double center_x, void CanvasGradient::initSweep(double center_x, double center_y, - const tonic::Int32List& colors, + const tonic::Float32List& colors, const tonic::Float32List& color_stops, DlTileMode tile_mode, double start_angle, double end_angle, const tonic::Float64List& matrix4) { - FML_DCHECK(colors.num_elements() == color_stops.num_elements() || + FML_DCHECK(colors.num_elements() == (color_stops.num_elements() * 4) || color_stops.data() == nullptr); static_assert(sizeof(SkColor) == sizeof(int32_t), @@ -121,16 +121,20 @@ void CanvasGradient::initSweep(double center_x, std::vector dl_colors; dl_colors.reserve(colors.num_elements()); - for (int i = 0; i < colors.num_elements(); ++i) { - dl_colors.emplace_back(DlColor(colors[i])); + for (int i = 0; i < colors.num_elements(); i += 4) { + DlScalar a = colors[i + 0]; + DlScalar r = colors[i + 1]; + DlScalar g = colors[i + 2]; + DlScalar b = colors[i + 3]; + dl_colors.emplace_back(DlColor(a, r, g, b, DlColorSpace::kExtendedSRGB)); } dl_shader_ = DlColorSource::MakeSweep( SkPoint::Make(SafeNarrow(center_x), SafeNarrow(center_y)), SafeNarrow(start_angle) * 180.0f / static_cast(M_PI), SafeNarrow(end_angle) * 180.0f / static_cast(M_PI), - colors.num_elements(), dl_colors.data(), color_stops.data(), tile_mode, - has_matrix ? &sk_matrix : nullptr); + color_stops.num_elements(), dl_colors.data(), color_stops.data(), + tile_mode, has_matrix ? &sk_matrix : nullptr); // Just a sanity check, all gradient shaders should be thread-safe FML_DCHECK(dl_shader_->isUIThreadSafe()); } diff --git a/lib/ui/painting/gradient.h b/lib/ui/painting/gradient.h index 0198642d03d91..c33843cc8fb2d 100644 --- a/lib/ui/painting/gradient.h +++ b/lib/ui/painting/gradient.h @@ -36,7 +36,7 @@ class CanvasGradient : public Shader { void initSweep(double center_x, double center_y, - const tonic::Int32List& colors, + const tonic::Float32List& colors, const tonic::Float32List& color_stops, DlTileMode tile_mode, double start_angle, From 0419148fd72351920b1dde0765c231a9a18a6ced Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Tue, 3 Sep 2024 11:11:39 -0700 Subject: [PATCH 6/7] fixed color size --- impeller/display_list/skia_conversions.cc | 3 ++- lib/ui/painting.dart | 2 -- lib/ui/painting/gradient.cc | 8 ++++---- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/impeller/display_list/skia_conversions.cc b/impeller/display_list/skia_conversions.cc index 4e3180a6e2074..57dc07cbc2157 100644 --- a/impeller/display_list/skia_conversions.cc +++ b/impeller/display_list/skia_conversions.cc @@ -218,7 +218,8 @@ std::optional ToPixelFormat(SkColorType type) { void ConvertStops(const flutter::DlGradientColorSourceBase* gradient, std::vector& colors, std::vector& stops) { - FML_DCHECK(gradient->stop_count() >= 2); + FML_DCHECK(gradient->stop_count() >= 2) + << "stop_count:" << gradient->stop_count(); auto* dl_colors = gradient->colors(); auto* dl_stops = gradient->stops(); diff --git a/lib/ui/painting.dart b/lib/ui/painting.dart index 5ef7a5ba69af1..53225153eb983 100644 --- a/lib/ui/painting.dart +++ b/lib/ui/painting.dart @@ -4548,13 +4548,11 @@ base class Gradient extends Shader { assert(_offsetIsValid(to)), assert(matrix4 == null || _matrix4IsValid(matrix4)), super._() { - print("gradient.linear1"); _validateColorStops(colors, colorStops); final Float32List endPointsBuffer = _encodeTwoPoints(from, to); final Float32List colorsBuffer = _encodeWideColorList(colors); final Float32List? colorStopsBuffer = colorStops == null ? null : Float32List.fromList(colorStops); _constructor(); - print("gradient.linear2"); _initLinear(endPointsBuffer, colorsBuffer, colorStopsBuffer, tileMode.index, matrix4); } diff --git a/lib/ui/painting/gradient.cc b/lib/ui/painting/gradient.cc index 63e2336fbef7f..6415a2c4c8d94 100644 --- a/lib/ui/painting/gradient.cc +++ b/lib/ui/painting/gradient.cc @@ -56,7 +56,7 @@ void CanvasGradient::initLinear(const tonic::Float32List& end_points, } dl_shader_ = DlColorSource::MakeLinear( - p0, p1, color_stops.num_elements(), dl_colors.data(), color_stops.data(), + p0, p1, colors.num_elements() / 4, dl_colors.data(), color_stops.data(), tile_mode, has_matrix ? &sk_matrix : nullptr); // Just a sanity check, all gradient shaders should be thread-safe FML_DCHECK(dl_shader_->isUIThreadSafe()); @@ -93,7 +93,7 @@ void CanvasGradient::initRadial(double center_x, dl_shader_ = DlColorSource::MakeRadial( SkPoint::Make(SafeNarrow(center_x), SafeNarrow(center_y)), - SafeNarrow(radius), color_stops.num_elements(), dl_colors.data(), + SafeNarrow(radius), colors.num_elements() / 4, dl_colors.data(), color_stops.data(), tile_mode, has_matrix ? &sk_matrix : nullptr); // Just a sanity check, all gradient shaders should be thread-safe FML_DCHECK(dl_shader_->isUIThreadSafe()); @@ -133,7 +133,7 @@ void CanvasGradient::initSweep(double center_x, SkPoint::Make(SafeNarrow(center_x), SafeNarrow(center_y)), SafeNarrow(start_angle) * 180.0f / static_cast(M_PI), SafeNarrow(end_angle) * 180.0f / static_cast(M_PI), - color_stops.num_elements(), dl_colors.data(), color_stops.data(), + colors.num_elements() / 4, dl_colors.data(), color_stops.data(), tile_mode, has_matrix ? &sk_matrix : nullptr); // Just a sanity check, all gradient shaders should be thread-safe FML_DCHECK(dl_shader_->isUIThreadSafe()); @@ -175,7 +175,7 @@ void CanvasGradient::initTwoPointConical(double start_x, SkPoint::Make(SafeNarrow(start_x), SafeNarrow(start_y)), SafeNarrow(start_radius), SkPoint::Make(SafeNarrow(end_x), SafeNarrow(end_y)), - SafeNarrow(end_radius), color_stops.num_elements(), dl_colors.data(), + SafeNarrow(end_radius), colors.num_elements() / 4, dl_colors.data(), color_stops.data(), tile_mode, has_matrix ? &sk_matrix : nullptr); // Just a sanity check, all gradient shaders should be thread-safe FML_DCHECK(dl_shader_->isUIThreadSafe()); From 66b244e172afc637526e27564909872e25678623 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Tue, 3 Sep 2024 13:43:37 -0700 Subject: [PATCH 7/7] jonah feedback 1, fixed overactive allocation --- lib/ui/painting.dart | 8 ++++---- lib/ui/painting/gradient.cc | 32 ++++++++++++++++++-------------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/lib/ui/painting.dart b/lib/ui/painting.dart index 53225153eb983..1a67e9a64102f 100644 --- a/lib/ui/painting.dart +++ b/lib/ui/painting.dart @@ -4455,7 +4455,7 @@ enum TileMode { Float32List _encodeWideColorList(List colors) { final int colorCount = colors.length; final Float32List result = Float32List(colorCount * 4); - for (int i = 0; i < colorCount; ++i) { + for (int i = 0; i < colorCount; i++) { final Color colorXr = colors[i].withValues(colorSpace: ColorSpace.extendedSRGB); result[i*4+0] = colorXr.a; @@ -4470,7 +4470,7 @@ Float32List _encodeWideColorList(List colors) { Int32List _encodeColorList(List colors) { final int colorCount = colors.length; final Int32List result = Int32List(colorCount); - for (int i = 0; i < colorCount; ++i) { + for (int i = 0; i < colorCount; i++) { result[i] = colors[i].value; } return result; @@ -4479,7 +4479,7 @@ Int32List _encodeColorList(List colors) { Float32List _encodePointList(List points) { final int pointCount = points.length; final Float32List result = Float32List(pointCount * 2); - for (int i = 0; i < pointCount; ++i) { + for (int i = 0; i < pointCount; i++) { final int xIndex = i * 2; final int yIndex = xIndex + 1; final Offset point = points[i]; @@ -6518,7 +6518,7 @@ base class _NativeCanvas extends NativeFieldWrapperClass1 implements Canvas { final Float32List rstTransformBuffer = Float32List(rectCount * 4); final Float32List rectBuffer = Float32List(rectCount * 4); - for (int i = 0; i < rectCount; ++i) { + for (int i = 0; i < rectCount; i++) { final int index0 = i * 4; final int index1 = index0 + 1; final int index2 = index0 + 2; diff --git a/lib/ui/painting/gradient.cc b/lib/ui/painting/gradient.cc index 6415a2c4c8d94..6f3f8b5d60f3d 100644 --- a/lib/ui/painting/gradient.cc +++ b/lib/ui/painting/gradient.cc @@ -31,6 +31,7 @@ void CanvasGradient::initLinear(const tonic::Float32List& end_points, FML_DCHECK(end_points.num_elements() == 4); FML_DCHECK(colors.num_elements() == (color_stops.num_elements() * 4) || color_stops.data() == nullptr); + int num_colors = colors.num_elements() / 4; static_assert(sizeof(SkPoint) == sizeof(float) * 2, "SkPoint doesn't use floats."); @@ -46,7 +47,7 @@ void CanvasGradient::initLinear(const tonic::Float32List& end_points, SkPoint p0 = SkPoint::Make(end_points[0], end_points[1]); SkPoint p1 = SkPoint::Make(end_points[2], end_points[3]); std::vector dl_colors; - dl_colors.reserve(color_stops.num_elements()); + dl_colors.reserve(num_colors); for (int i = 0; i < colors.num_elements(); i += 4) { DlScalar a = colors[i + 0]; DlScalar r = colors[i + 1]; @@ -55,9 +56,9 @@ void CanvasGradient::initLinear(const tonic::Float32List& end_points, dl_colors.emplace_back(DlColor(a, r, g, b, DlColorSpace::kExtendedSRGB)); } - dl_shader_ = DlColorSource::MakeLinear( - p0, p1, colors.num_elements() / 4, dl_colors.data(), color_stops.data(), - tile_mode, has_matrix ? &sk_matrix : nullptr); + dl_shader_ = DlColorSource::MakeLinear(p0, p1, num_colors, dl_colors.data(), + color_stops.data(), tile_mode, + has_matrix ? &sk_matrix : nullptr); // Just a sanity check, all gradient shaders should be thread-safe FML_DCHECK(dl_shader_->isUIThreadSafe()); } @@ -71,6 +72,7 @@ void CanvasGradient::initRadial(double center_x, const tonic::Float64List& matrix4) { FML_DCHECK(colors.num_elements() == (color_stops.num_elements() * 4) || color_stops.data() == nullptr); + int num_colors = colors.num_elements() / 4; static_assert(sizeof(SkColor) == sizeof(int32_t), "SkColor doesn't use int32_t."); @@ -82,7 +84,7 @@ void CanvasGradient::initRadial(double center_x, } std::vector dl_colors; - dl_colors.reserve(colors.num_elements()); + dl_colors.reserve(num_colors); for (int i = 0; i < colors.num_elements(); i += 4) { DlScalar a = colors[i + 0]; DlScalar r = colors[i + 1]; @@ -93,8 +95,8 @@ void CanvasGradient::initRadial(double center_x, dl_shader_ = DlColorSource::MakeRadial( SkPoint::Make(SafeNarrow(center_x), SafeNarrow(center_y)), - SafeNarrow(radius), colors.num_elements() / 4, dl_colors.data(), - color_stops.data(), tile_mode, has_matrix ? &sk_matrix : nullptr); + SafeNarrow(radius), num_colors, dl_colors.data(), color_stops.data(), + tile_mode, has_matrix ? &sk_matrix : nullptr); // Just a sanity check, all gradient shaders should be thread-safe FML_DCHECK(dl_shader_->isUIThreadSafe()); } @@ -109,6 +111,7 @@ void CanvasGradient::initSweep(double center_x, const tonic::Float64List& matrix4) { FML_DCHECK(colors.num_elements() == (color_stops.num_elements() * 4) || color_stops.data() == nullptr); + int num_colors = colors.num_elements() / 4; static_assert(sizeof(SkColor) == sizeof(int32_t), "SkColor doesn't use int32_t."); @@ -120,7 +123,7 @@ void CanvasGradient::initSweep(double center_x, } std::vector dl_colors; - dl_colors.reserve(colors.num_elements()); + dl_colors.reserve(num_colors); for (int i = 0; i < colors.num_elements(); i += 4) { DlScalar a = colors[i + 0]; DlScalar r = colors[i + 1]; @@ -132,9 +135,9 @@ void CanvasGradient::initSweep(double center_x, dl_shader_ = DlColorSource::MakeSweep( SkPoint::Make(SafeNarrow(center_x), SafeNarrow(center_y)), SafeNarrow(start_angle) * 180.0f / static_cast(M_PI), - SafeNarrow(end_angle) * 180.0f / static_cast(M_PI), - colors.num_elements() / 4, dl_colors.data(), color_stops.data(), - tile_mode, has_matrix ? &sk_matrix : nullptr); + SafeNarrow(end_angle) * 180.0f / static_cast(M_PI), num_colors, + dl_colors.data(), color_stops.data(), tile_mode, + has_matrix ? &sk_matrix : nullptr); // Just a sanity check, all gradient shaders should be thread-safe FML_DCHECK(dl_shader_->isUIThreadSafe()); } @@ -151,6 +154,7 @@ void CanvasGradient::initTwoPointConical(double start_x, const tonic::Float64List& matrix4) { FML_DCHECK(colors.num_elements() == (color_stops.num_elements() * 4) || color_stops.data() == nullptr); + int num_colors = colors.num_elements() / 4; static_assert(sizeof(SkColor) == sizeof(int32_t), "SkColor doesn't use int32_t."); @@ -162,7 +166,7 @@ void CanvasGradient::initTwoPointConical(double start_x, } std::vector dl_colors; - dl_colors.reserve(colors.num_elements()); + dl_colors.reserve(num_colors); for (int i = 0; i < colors.num_elements(); i += 4) { DlScalar a = colors[i + 0]; DlScalar r = colors[i + 1]; @@ -175,8 +179,8 @@ void CanvasGradient::initTwoPointConical(double start_x, SkPoint::Make(SafeNarrow(start_x), SafeNarrow(start_y)), SafeNarrow(start_radius), SkPoint::Make(SafeNarrow(end_x), SafeNarrow(end_y)), - SafeNarrow(end_radius), colors.num_elements() / 4, dl_colors.data(), - color_stops.data(), tile_mode, has_matrix ? &sk_matrix : nullptr); + SafeNarrow(end_radius), num_colors, dl_colors.data(), color_stops.data(), + tile_mode, has_matrix ? &sk_matrix : nullptr); // Just a sanity check, all gradient shaders should be thread-safe FML_DCHECK(dl_shader_->isUIThreadSafe()); }