From 9a7613f4cf62319ff7914ef6033a9c54dffff71d Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Wed, 11 Dec 2024 14:22:43 -0800 Subject: [PATCH] removed constructor redundancy --- .../dl_conical_gradient_color_source.cc | 36 ------------------- .../dl_conical_gradient_color_source.h | 22 ++++++------ .../dl_linear_gradient_color_source.cc | 28 --------------- .../dl_linear_gradient_color_source.h | 18 +++++----- .../dl_radial_gradient_color_source.cc | 27 -------------- .../dl_radial_gradient_color_source.h | 18 +++++----- .../dl_sweep_gradient_color_source.cc | 31 ---------------- .../dl_sweep_gradient_color_source.h | 20 +++++------ display_list/effects/dl_color_source.cc | 13 +++++++ 9 files changed, 48 insertions(+), 165 deletions(-) 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 dbd93d1cf7975..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,42 +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( - 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) - : 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_argb, 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 2fee5884892aa..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,25 +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); - - DlConicalGradientColorSource(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); + 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 19ba780bffb78..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,33 +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( - DlPoint center, - DlScalar radius, - uint32_t stop_count, - const DlScalar* colors_argb, - 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_argb, 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 d1b2baecd7552..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,21 +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); - - DlRadialGradientColorSource(DlPoint center, - DlScalar radius, - uint32_t stop_count, - const DlScalar* colors_argb, - 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 7a1a9c92c3f0d..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,37 +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( - DlPoint center, - DlScalar start, - DlScalar end, - uint32_t stop_count, - const DlScalar* colors_argb, - 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_argb, 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 0f123169fd73d..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,23 +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); - - DlSweepGradientColorSource(DlPoint center, - DlScalar start, - DlScalar end, - uint32_t stop_count, - const DlScalar* colors_argb, - 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 3a0fd78c15bcb..27be8f74dfa9b 100644 --- a/display_list/effects/dl_color_source.cc +++ b/display_list/effects/dl_color_source.cc @@ -36,6 +36,19 @@ size_t CalculateGradientSize(uint32_t stop_count) { return sizeof(GradientColorSource) + (stop_count * (sizeof(DlColor) + sizeof(float))); } + +template +std::shared_ptr MakeGradient(uint32_t stop_count, + Args&&... args) { + size_t needed = CalculateGradientSize(stop_count); + void* storage = ::operator new(needed); + + std::shared_ptr ret; + ret.reset(new (storage) GradientType(std::forward(args)...), + DlGradientDeleter); + + return ret; +} } // namespace std::shared_ptr DlColorSource::MakeLinear(