diff --git a/display_list/effects/color_sources/dl_conical_gradient_color_source.cc b/display_list/effects/color_sources/dl_conical_gradient_color_source.cc index 0e94d0c6078d3..2b930398c9565 100644 --- a/display_list/effects/color_sources/dl_conical_gradient_color_source.cc +++ b/display_list/effects/color_sources/dl_conical_gradient_color_source.cc @@ -6,24 +6,6 @@ namespace flutter { -DlConicalGradientColorSource::DlConicalGradientColorSource( - 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) - : DlGradientColorSourceBase(stop_count, tile_mode, matrix), - start_center_(start_center), - start_radius_(start_radius), - end_center_(end_center), - end_radius_(end_radius) { - store_color_stops(this + 1, colors, stops); -} - DlConicalGradientColorSource::DlConicalGradientColorSource( const DlConicalGradientColorSource* source) : DlGradientColorSourceBase(source->stop_count(), diff --git a/display_list/effects/color_sources/dl_conical_gradient_color_source.h b/display_list/effects/color_sources/dl_conical_gradient_color_source.h index db523bc94c1c5..3efb60e698fef 100644 --- a/display_list/effects/color_sources/dl_conical_gradient_color_source.h +++ b/display_list/effects/color_sources/dl_conical_gradient_color_source.h @@ -35,15 +35,23 @@ class DlConicalGradientColorSource final : public DlGradientColorSourceBase { bool equals_(DlColorSource const& other) const override; private: + template DlConicalGradientColorSource(DlPoint start_center, DlScalar start_radius, DlPoint end_center, DlScalar end_radius, uint32_t stop_count, - const DlColor* colors, + Colors colors, const float* stops, DlTileMode tile_mode, - const DlMatrix* matrix = nullptr); + const DlMatrix* matrix = nullptr) + : DlGradientColorSourceBase(stop_count, tile_mode, matrix), + start_center_(start_center), + start_radius_(start_radius), + end_center_(end_center), + end_radius_(end_radius) { + store_color_stops(this + 1, colors, stops); + } explicit DlConicalGradientColorSource( const DlConicalGradientColorSource* source); diff --git a/display_list/effects/color_sources/dl_linear_gradient_color_source.cc b/display_list/effects/color_sources/dl_linear_gradient_color_source.cc index 6c9fa3b19a1ea..953cc82d84f04 100644 --- a/display_list/effects/color_sources/dl_linear_gradient_color_source.cc +++ b/display_list/effects/color_sources/dl_linear_gradient_color_source.cc @@ -6,34 +6,6 @@ namespace flutter { -DlLinearGradientColorSource::DlLinearGradientColorSource( - const DlPoint start_point, - const DlPoint end_point, - uint32_t stop_count, - const DlColor* colors, - const float* stops, - DlTileMode tile_mode, - const DlMatrix* matrix) - : DlGradientColorSourceBase(stop_count, tile_mode, matrix), - start_point_(start_point), - end_point_(end_point) { - store_color_stops(this + 1, colors, stops); -} - -DlLinearGradientColorSource::DlLinearGradientColorSource( - const DlPoint start_point, - const DlPoint end_point, - uint32_t stop_count, - const DlScalar* colors, - const float* stops, - DlTileMode tile_mode, - const DlMatrix* matrix) - : DlGradientColorSourceBase(stop_count, tile_mode, matrix), - start_point_(start_point), - end_point_(end_point) { - store_color_stops(this + 1, colors, stops); -} - DlLinearGradientColorSource::DlLinearGradientColorSource( const DlLinearGradientColorSource* source) : DlGradientColorSourceBase(source->stop_count(), diff --git a/display_list/effects/color_sources/dl_linear_gradient_color_source.h b/display_list/effects/color_sources/dl_linear_gradient_color_source.h index a229fbbd233c6..18ca74afe61f7 100644 --- a/display_list/effects/color_sources/dl_linear_gradient_color_source.h +++ b/display_list/effects/color_sources/dl_linear_gradient_color_source.h @@ -33,21 +33,19 @@ class DlLinearGradientColorSource final : public DlGradientColorSourceBase { bool equals_(DlColorSource const& other) const override; private: + template DlLinearGradientColorSource(const DlPoint start_point, const DlPoint end_point, uint32_t stop_count, - const DlColor* colors, + Colors colors, const float* stops, DlTileMode tile_mode, - const DlMatrix* matrix = nullptr); - - DlLinearGradientColorSource(const DlPoint start_point, - const DlPoint end_point, - uint32_t stop_count, - const DlScalar* colors, - const float* stops, - DlTileMode tile_mode, - const DlMatrix* matrix = nullptr); + const DlMatrix* matrix = nullptr) + : DlGradientColorSourceBase(stop_count, tile_mode, matrix), + start_point_(start_point), + end_point_(end_point) { + store_color_stops(this + 1, colors, stops); + } explicit DlLinearGradientColorSource( const DlLinearGradientColorSource* source); diff --git a/display_list/effects/color_sources/dl_radial_gradient_color_source.cc b/display_list/effects/color_sources/dl_radial_gradient_color_source.cc index 7c217f649fbd7..94b526a3cf60d 100644 --- a/display_list/effects/color_sources/dl_radial_gradient_color_source.cc +++ b/display_list/effects/color_sources/dl_radial_gradient_color_source.cc @@ -6,19 +6,6 @@ namespace flutter { -DlRadialGradientColorSource::DlRadialGradientColorSource(DlPoint center, - DlScalar radius, - uint32_t stop_count, - const DlColor* colors, - const float* stops, - DlTileMode tile_mode, - const DlMatrix* matrix) - : DlGradientColorSourceBase(stop_count, tile_mode, matrix), - center_(center), - radius_(radius) { - store_color_stops(this + 1, colors, stops); -} - DlRadialGradientColorSource::DlRadialGradientColorSource( const DlRadialGradientColorSource* source) : DlGradientColorSourceBase(source->stop_count(), diff --git a/display_list/effects/color_sources/dl_radial_gradient_color_source.h b/display_list/effects/color_sources/dl_radial_gradient_color_source.h index 70b48d504578f..fe05c334c9e73 100644 --- a/display_list/effects/color_sources/dl_radial_gradient_color_source.h +++ b/display_list/effects/color_sources/dl_radial_gradient_color_source.h @@ -33,13 +33,19 @@ class DlRadialGradientColorSource final : public DlGradientColorSourceBase { bool equals_(DlColorSource const& other) const override; private: + template DlRadialGradientColorSource(DlPoint center, DlScalar radius, uint32_t stop_count, - const DlColor* colors, + Colors colors, const float* stops, DlTileMode tile_mode, - const DlMatrix* matrix = nullptr); + const DlMatrix* matrix = nullptr) + : DlGradientColorSourceBase(stop_count, tile_mode, matrix), + center_(center), + radius_(radius) { + store_color_stops(this + 1, colors, stops); + } explicit DlRadialGradientColorSource( const DlRadialGradientColorSource* source); diff --git a/display_list/effects/color_sources/dl_sweep_gradient_color_source.cc b/display_list/effects/color_sources/dl_sweep_gradient_color_source.cc index c575e72947a31..4af8e04ba4e3f 100644 --- a/display_list/effects/color_sources/dl_sweep_gradient_color_source.cc +++ b/display_list/effects/color_sources/dl_sweep_gradient_color_source.cc @@ -6,21 +6,6 @@ namespace flutter { -DlSweepGradientColorSource::DlSweepGradientColorSource(DlPoint center, - DlScalar start, - DlScalar end, - uint32_t stop_count, - const DlColor* colors, - const float* stops, - DlTileMode tile_mode, - const DlMatrix* matrix) - : DlGradientColorSourceBase(stop_count, tile_mode, matrix), - center_(center), - start_(start), - end_(end) { - store_color_stops(this + 1, colors, stops); -} - DlSweepGradientColorSource::DlSweepGradientColorSource( const DlSweepGradientColorSource* source) : DlGradientColorSourceBase(source->stop_count(), diff --git a/display_list/effects/color_sources/dl_sweep_gradient_color_source.h b/display_list/effects/color_sources/dl_sweep_gradient_color_source.h index b33753898ce31..4a01048deae15 100644 --- a/display_list/effects/color_sources/dl_sweep_gradient_color_source.h +++ b/display_list/effects/color_sources/dl_sweep_gradient_color_source.h @@ -34,14 +34,21 @@ class DlSweepGradientColorSource final : public DlGradientColorSourceBase { bool equals_(DlColorSource const& other) const override; private: + template DlSweepGradientColorSource(DlPoint center, DlScalar start, DlScalar end, uint32_t stop_count, - const DlColor* colors, + Colors colors, const float* stops, DlTileMode tile_mode, - const DlMatrix* matrix = nullptr); + const DlMatrix* matrix = nullptr) + : DlGradientColorSourceBase(stop_count, tile_mode, matrix), + center_(center), + start_(start), + end_(end) { + store_color_stops(this + 1, colors, stops); + } explicit DlSweepGradientColorSource(const DlSweepGradientColorSource* source); diff --git a/display_list/effects/dl_color_source.cc b/display_list/effects/dl_color_source.cc index 6d027ef822d59..3a0fd78c15bcb 100644 --- a/display_list/effects/dl_color_source.cc +++ b/display_list/effects/dl_color_source.cc @@ -31,8 +31,9 @@ std::shared_ptr DlColorSource::MakeImage( } namespace { -size_t CalculateLinearGradientSize(uint32_t stop_count) { - return sizeof(DlLinearGradientColorSource) + +template +size_t CalculateGradientSize(uint32_t stop_count) { + return sizeof(GradientColorSource) + (stop_count * (sizeof(DlColor) + sizeof(float))); } } // namespace @@ -45,7 +46,8 @@ std::shared_ptr DlColorSource::MakeLinear( const float* stops, DlTileMode tile_mode, const DlMatrix* matrix) { - size_t needed = CalculateLinearGradientSize(stop_count); + size_t needed = + CalculateGradientSize(stop_count); void* storage = ::operator new(needed); std::shared_ptr ret; @@ -64,7 +66,8 @@ std::shared_ptr DlColorSource::MakeLinear( const float* stops, DlTileMode tile_mode, const DlMatrix* matrix) { - size_t needed = CalculateLinearGradientSize(stop_count); + size_t needed = + CalculateGradientSize(stop_count); void* storage = ::operator new(needed); std::shared_ptr ret; @@ -83,9 +86,8 @@ std::shared_ptr DlColorSource::MakeRadial( const float* stops, DlTileMode tile_mode, const DlMatrix* matrix) { - size_t needed = sizeof(DlRadialGradientColorSource) + - (stop_count * (sizeof(DlColor) + sizeof(float))); - + size_t needed = + CalculateGradientSize(stop_count); void* storage = ::operator new(needed); std::shared_ptr ret; @@ -95,6 +97,26 @@ std::shared_ptr DlColorSource::MakeRadial( return ret; } +std::shared_ptr DlColorSource::MakeRadial( + DlPoint center, + DlScalar radius, + uint32_t stop_count, + const DlScalar* colors_argb, + const float* stops, + DlTileMode tile_mode, + const DlMatrix* matrix) { + size_t needed = + CalculateGradientSize(stop_count); + void* storage = ::operator new(needed); + + std::shared_ptr ret; + ret.reset( + new (storage) DlRadialGradientColorSource( + center, radius, stop_count, colors_argb, stops, tile_mode, matrix), + DlGradientDeleter); + return ret; +} + std::shared_ptr DlColorSource::MakeConical( DlPoint start_center, DlScalar start_radius, @@ -105,9 +127,8 @@ std::shared_ptr DlColorSource::MakeConical( const float* stops, DlTileMode tile_mode, const DlMatrix* matrix) { - size_t needed = sizeof(DlConicalGradientColorSource) + - (stop_count * (sizeof(DlColor) + sizeof(float))); - + size_t needed = + CalculateGradientSize(stop_count); void* storage = ::operator new(needed); std::shared_ptr ret; @@ -118,6 +139,29 @@ std::shared_ptr DlColorSource::MakeConical( return ret; } +std::shared_ptr DlColorSource::MakeConical( + DlPoint start_center, + DlScalar start_radius, + DlPoint end_center, + DlScalar end_radius, + uint32_t stop_count, + const DlScalar* colors_argb, + const float* stops, + DlTileMode tile_mode, + const DlMatrix* matrix) { + size_t needed = + CalculateGradientSize(stop_count); + + void* storage = ::operator new(needed); + + std::shared_ptr ret; + ret.reset(new (storage) DlConicalGradientColorSource( + start_center, start_radius, end_center, end_radius, stop_count, + colors_argb, stops, tile_mode, matrix), + DlGradientDeleter); + return ret; +} + std::shared_ptr DlColorSource::MakeSweep( DlPoint center, DlScalar start, @@ -127,9 +171,7 @@ std::shared_ptr DlColorSource::MakeSweep( const float* stops, DlTileMode tile_mode, const DlMatrix* matrix) { - size_t needed = sizeof(DlSweepGradientColorSource) + - (stop_count * (sizeof(DlColor) + sizeof(float))); - + size_t needed = CalculateGradientSize(stop_count); void* storage = ::operator new(needed); std::shared_ptr ret; @@ -140,6 +182,26 @@ std::shared_ptr DlColorSource::MakeSweep( return ret; } +std::shared_ptr DlColorSource::MakeSweep( + DlPoint center, + DlScalar start, + DlScalar end, + uint32_t stop_count, + const DlScalar* colors_argb, + const float* stops, + DlTileMode tile_mode, + const DlMatrix* matrix) { + size_t needed = CalculateGradientSize(stop_count); + void* storage = ::operator new(needed); + + std::shared_ptr ret; + ret.reset(new (storage) DlSweepGradientColorSource(center, start, end, + stop_count, colors_argb, + stops, tile_mode, matrix), + DlGradientDeleter); + return ret; +} + std::shared_ptr DlColorSource::MakeRuntimeEffect( sk_sp runtime_effect, std::vector> samplers, diff --git a/display_list/effects/dl_color_source.h b/display_list/effects/dl_color_source.h index 44aa88ef38924..4f3284c848ab2 100644 --- a/display_list/effects/dl_color_source.h +++ b/display_list/effects/dl_color_source.h @@ -60,7 +60,8 @@ class DlColorSource : public DlAttribute { const DlMatrix* matrix = nullptr); /// @brief Make a linear gradient. - /// @param colors_argb Array of DlScalars that represents colors in the ARGB. + /// @param colors_argb Array of DlScalars that represents colors in the ARGB + /// format, in the extended srgb colorspace. static std::shared_ptr MakeLinear( const DlPoint start_point, const DlPoint end_point, @@ -79,6 +80,18 @@ class DlColorSource : public DlAttribute { DlTileMode tile_mode, const DlMatrix* matrix = nullptr); + /// @brief Make a radial gradient. + /// @param colors_argb Array of DlScalars that represents colors in the ARGB + /// format, in the extended srgb colorspace. + static std::shared_ptr MakeRadial( + DlPoint center, + DlScalar radius, + uint32_t stop_count, + const DlScalar* colors_argb, + const float* stops, + DlTileMode tile_mode, + const DlMatrix* matrix = nullptr); + static std::shared_ptr MakeConical( DlPoint start_center, DlScalar start_radius, @@ -90,6 +103,20 @@ class DlColorSource : public DlAttribute { DlTileMode tile_mode, const DlMatrix* matrix = nullptr); + /// @brief Make a conical gradient. + /// @param colors_argb colors_argb Array of DlScalars that represents colors + /// in the ARGB format, in the extended srgb colorspace. + static std::shared_ptr MakeConical( + DlPoint start_center, + DlScalar start_radius, + DlPoint end_center, + DlScalar end_radius, + uint32_t stop_count, + const DlScalar* colors_argb, + const float* stops, + DlTileMode tile_mode, + const DlMatrix* matrix = nullptr); + static std::shared_ptr MakeSweep( DlPoint center, DlScalar start, @@ -100,6 +127,19 @@ class DlColorSource : public DlAttribute { DlTileMode tile_mode, const DlMatrix* matrix = nullptr); + /// @brief Make a sweep gradient. + /// @param colors_argb Array of DlScalars that represents colors in the ARGB + /// format, in the extended srgb colorspace. + static std::shared_ptr MakeSweep( + DlPoint center, + DlScalar start, + DlScalar end, + uint32_t stop_count, + const DlScalar* colors_argb, + const float* stops, + DlTileMode tile_mode, + const DlMatrix* matrix = nullptr); + static std::shared_ptr MakeRuntimeEffect( sk_sp runtime_effect, std::vector> samplers, diff --git a/display_list/effects/dl_color_source_unittests.cc b/display_list/effects/dl_color_source_unittests.cc index de2a9b97011b2..4fd44469b1eaf 100644 --- a/display_list/effects/dl_color_source_unittests.cc +++ b/display_list/effects/dl_color_source_unittests.cc @@ -333,6 +333,32 @@ TEST(DisplayListColorSource, RadialGradientConstructor) { DlTileMode::kClamp, &kTestMatrix1); } +TEST(DisplayListColorSource, RadialGradientARGBConstructor) { + std::array colors; + for (int i = 0; i < kTestStopCount; ++i) { + colors[i * 4 + 0] = kTestColors[i].getAlphaF(); // + colors[i * 4 + 1] = kTestColors[i].getRedF(); // + colors[i * 4 + 2] = kTestColors[i].getGreenF(); // + colors[i * 4 + 3] = kTestColors[i].getBlueF(); + } + std::shared_ptr source = DlColorSource::MakeRadial( + kTestPoints[0], 10.f, kTestStopCount, colors.data(), kTestStops, + DlTileMode::kClamp, &kTestMatrix1); + ASSERT_TRUE(source); + ASSERT_TRUE(source->asRadialGradient()); + EXPECT_EQ(source->asRadialGradient()->center(), kTestPoints[0]); + EXPECT_EQ(source->asRadialGradient()->radius(), 10.f); + EXPECT_EQ(source->asRadialGradient()->stop_count(), kTestStopCount); + for (int i = 0; i < kTestStopCount; i++) { + EXPECT_EQ(source->asRadialGradient()->colors()[i], + kTestColors[i].withColorSpace(DlColorSpace::kExtendedSRGB)); + EXPECT_EQ(source->asRadialGradient()->stops()[i], kTestStops[i]); + } + EXPECT_EQ(source->asRadialGradient()->tile_mode(), DlTileMode::kClamp); + EXPECT_EQ(source->asRadialGradient()->matrix(), kTestMatrix1); + EXPECT_EQ(source->is_opaque(), true); +} + TEST(DisplayListColorSource, RadialGradientShared) { std::shared_ptr source = DlColorSource::MakeRadial( kTestPoints[0], 10.0, kTestStopCount, kTestColors, kTestStops, @@ -451,6 +477,34 @@ TEST(DisplayListColorSource, ConicalGradientConstructor) { kTestStops, DlTileMode::kClamp, &kTestMatrix1); } +TEST(DisplayListColorSource, ConicalGradientARGBConstructor) { + std::array colors; + for (int i = 0; i < kTestStopCount; ++i) { + colors[i * 4 + 0] = kTestColors[i].getAlphaF(); // + colors[i * 4 + 1] = kTestColors[i].getRedF(); // + colors[i * 4 + 2] = kTestColors[i].getGreenF(); // + colors[i * 4 + 3] = kTestColors[i].getBlueF(); + } + std::shared_ptr source = DlColorSource::MakeConical( + kTestPoints[0], 10.f, kTestPoints[1], 20.f, kTestStopCount, colors.data(), + kTestStops, DlTileMode::kClamp, &kTestMatrix1); + ASSERT_TRUE(source); + ASSERT_TRUE(source->asConicalGradient()); + EXPECT_EQ(source->asConicalGradient()->start_center(), kTestPoints[0]); + EXPECT_EQ(source->asConicalGradient()->start_radius(), 10.f); + EXPECT_EQ(source->asConicalGradient()->end_center(), kTestPoints[1]); + EXPECT_EQ(source->asConicalGradient()->end_radius(), 20.f); + EXPECT_EQ(source->asConicalGradient()->stop_count(), kTestStopCount); + for (int i = 0; i < kTestStopCount; i++) { + EXPECT_EQ(source->asConicalGradient()->colors()[i], + kTestColors[i].withColorSpace(DlColorSpace::kExtendedSRGB)); + EXPECT_EQ(source->asConicalGradient()->stops()[i], kTestStops[i]); + } + EXPECT_EQ(source->asConicalGradient()->tile_mode(), DlTileMode::kClamp); + EXPECT_EQ(source->asConicalGradient()->matrix(), kTestMatrix1); + EXPECT_EQ(source->is_opaque(), true); +} + TEST(DisplayListColorSource, ConicalGradientShared) { std::shared_ptr source = DlColorSource::MakeConical( kTestPoints[0], 10.0, kTestPoints[1], 20.0, kTestStopCount, kTestColors, @@ -585,6 +639,33 @@ TEST(DisplayListColorSource, SweepGradientConstructor) { DlTileMode::kClamp, &kTestMatrix1); } +TEST(DisplayListColorSource, SweepGradientARGBConstructor) { + std::array colors; + for (int i = 0; i < kTestStopCount; ++i) { + colors[i * 4 + 0] = kTestColors[i].getAlphaF(); // + colors[i * 4 + 1] = kTestColors[i].getRedF(); // + colors[i * 4 + 2] = kTestColors[i].getGreenF(); // + colors[i * 4 + 3] = kTestColors[i].getBlueF(); + } + std::shared_ptr source = DlColorSource::MakeSweep( + kTestPoints[0], 10.f, 20.f, kTestStopCount, colors.data(), kTestStops, + DlTileMode::kClamp, &kTestMatrix1); + ASSERT_TRUE(source); + ASSERT_TRUE(source->asSweepGradient()); + EXPECT_EQ(source->asSweepGradient()->center(), kTestPoints[0]); + EXPECT_EQ(source->asSweepGradient()->start(), 10.f); + EXPECT_EQ(source->asSweepGradient()->end(), 20.f); + EXPECT_EQ(source->asSweepGradient()->stop_count(), kTestStopCount); + for (int i = 0; i < kTestStopCount; i++) { + EXPECT_EQ(source->asSweepGradient()->colors()[i], + kTestColors[i].withColorSpace(DlColorSpace::kExtendedSRGB)); + EXPECT_EQ(source->asSweepGradient()->stops()[i], kTestStops[i]); + } + EXPECT_EQ(source->asSweepGradient()->tile_mode(), DlTileMode::kClamp); + EXPECT_EQ(source->asSweepGradient()->matrix(), kTestMatrix1); + EXPECT_EQ(source->is_opaque(), true); +} + TEST(DisplayListColorSource, SweepGradientShared) { std::shared_ptr source = DlColorSource::MakeSweep( kTestPoints[0], 10.0, 20.0, kTestStopCount, kTestColors, kTestStops, diff --git a/lib/ui/painting/gradient.cc b/lib/ui/painting/gradient.cc index a7ecf3be6cfdb..a4d783910afad 100644 --- a/lib/ui/painting/gradient.cc +++ b/lib/ui/painting/gradient.cc @@ -68,19 +68,9 @@ void CanvasGradient::initRadial(double center_x, dl_matrix = ToDlMatrix(matrix4); } - std::vector dl_colors; - 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]; - 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( DlPoint(SafeNarrow(center_x), SafeNarrow(center_y)), SafeNarrow(radius), - num_colors, dl_colors.data(), color_stops.data(), tile_mode, + num_colors, colors.data(), color_stops.data(), tile_mode, has_matrix ? &dl_matrix : nullptr); // Just a sanity check, all gradient shaders should be thread-safe FML_DCHECK(dl_shader_->isUIThreadSafe()); @@ -104,21 +94,11 @@ void CanvasGradient::initSweep(double center_x, dl_matrix = ToDlMatrix(matrix4); } - std::vector dl_colors; - 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]; - 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( DlPoint(SafeNarrow(center_x), SafeNarrow(center_y)), SafeNarrow(start_angle) * 180.0f / static_cast(M_PI), SafeNarrow(end_angle) * 180.0f / static_cast(M_PI), num_colors, - dl_colors.data(), color_stops.data(), tile_mode, + colors.data(), color_stops.data(), tile_mode, has_matrix ? &dl_matrix : nullptr); // Just a sanity check, all gradient shaders should be thread-safe FML_DCHECK(dl_shader_->isUIThreadSafe()); @@ -144,20 +124,10 @@ void CanvasGradient::initTwoPointConical(double start_x, dl_matrix = ToDlMatrix(matrix4); } - std::vector dl_colors; - 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]; - 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( DlPoint(SafeNarrow(start_x), SafeNarrow(start_y)), SafeNarrow(start_radius), DlPoint(SafeNarrow(end_x), SafeNarrow(end_y)), - SafeNarrow(end_radius), num_colors, dl_colors.data(), color_stops.data(), + SafeNarrow(end_radius), num_colors, colors.data(), color_stops.data(), tile_mode, has_matrix ? &dl_matrix : nullptr); // Just a sanity check, all gradient shaders should be thread-safe FML_DCHECK(dl_shader_->isUIThreadSafe());