Skip to content

Commit

Permalink
removed constructor redundancy
Browse files Browse the repository at this point in the history
  • Loading branch information
gaaclarke committed Dec 11, 2024
1 parent ea32f33 commit 9a7613f
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 165 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,23 @@ class DlConicalGradientColorSource final : public DlGradientColorSourceBase {
bool equals_(DlColorSource const& other) const override;

private:
template <typename Colors>
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,19 @@ class DlLinearGradientColorSource final : public DlGradientColorSourceBase {
bool equals_(DlColorSource const& other) const override;

private:
template <typename Colors>
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,19 @@ class DlRadialGradientColorSource final : public DlGradientColorSourceBase {
bool equals_(DlColorSource const& other) const override;

private:
template <typename Colors>
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,21 @@ class DlSweepGradientColorSource final : public DlGradientColorSourceBase {
bool equals_(DlColorSource const& other) const override;

private:
template <typename Colors>
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);

Expand Down
13 changes: 13 additions & 0 deletions display_list/effects/dl_color_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ size_t CalculateGradientSize(uint32_t stop_count) {
return sizeof(GradientColorSource) +
(stop_count * (sizeof(DlColor) + sizeof(float)));
}

template <typename GradientType, typename... Args>
std::shared_ptr<DlColorSource> MakeGradient(uint32_t stop_count,
Args&&... args) {
size_t needed = CalculateGradientSize<GradientType>(stop_count);
void* storage = ::operator new(needed);

std::shared_ptr<GradientType> ret;
ret.reset(new (storage) GradientType(std::forward<Args>(args)...),
DlGradientDeleter);

return ret;
}
} // namespace

std::shared_ptr<DlColorSource> DlColorSource::MakeLinear(
Expand Down

0 comments on commit 9a7613f

Please sign in to comment.