provide Destructor for sized-new DlGradient shared_ptr objects (flutter/engine#32088)

This commit is contained in:
Jim Graham 2022-03-17 13:55:40 -07:00 committed by GitHub
parent 8cae15f027
commit 7e3a6b1d3d

View File

@ -84,6 +84,15 @@ std::shared_ptr<DlColorSource> DlColorSource::From(SkShader* sk_shader) {
return source;
}
static void DlGradientDeleter(void* p) {
// Some of our target environments would prefer a sized delete,
// but other target environments do not have that operator.
// Use an unsized delete until we get better agreement in the
// environments.
// See https://github.com/flutter/flutter/issues/100327
::operator delete(p);
}
std::shared_ptr<DlColorSource> DlColorSource::MakeLinear(
const SkPoint start_point,
const SkPoint end_point,
@ -98,8 +107,10 @@ std::shared_ptr<DlColorSource> DlColorSource::MakeLinear(
void* storage = ::operator new(needed);
std::shared_ptr<DlLinearGradientColorSource> ret;
ret.reset(new (storage) DlLinearGradientColorSource(
start_point, end_point, stop_count, colors, stops, tile_mode, matrix));
ret.reset(new (storage)
DlLinearGradientColorSource(start_point, end_point, stop_count,
colors, stops, tile_mode, matrix),
DlGradientDeleter);
return std::move(ret);
}
@ -118,7 +129,8 @@ std::shared_ptr<DlColorSource> DlColorSource::MakeRadial(
std::shared_ptr<DlRadialGradientColorSource> ret;
ret.reset(new (storage) DlRadialGradientColorSource(
center, radius, stop_count, colors, stops, tile_mode, matrix));
center, radius, stop_count, colors, stops, tile_mode, matrix),
DlGradientDeleter);
return std::move(ret);
}
@ -139,8 +151,9 @@ std::shared_ptr<DlColorSource> DlColorSource::MakeConical(
std::shared_ptr<DlConicalGradientColorSource> ret;
ret.reset(new (storage) DlConicalGradientColorSource(
start_center, start_radius, end_center, end_radius, stop_count, colors,
stops, tile_mode, matrix));
start_center, start_radius, end_center, end_radius, stop_count,
colors, stops, tile_mode, matrix),
DlGradientDeleter);
return std::move(ret);
}
@ -159,8 +172,10 @@ std::shared_ptr<DlColorSource> DlColorSource::MakeSweep(
void* storage = ::operator new(needed);
std::shared_ptr<DlSweepGradientColorSource> ret;
ret.reset(new (storage) DlSweepGradientColorSource(
center, start, end, stop_count, colors, stops, tile_mode, matrix));
ret.reset(new (storage)
DlSweepGradientColorSource(center, start, end, stop_count,
colors, stops, tile_mode, matrix),
DlGradientDeleter);
return std::move(ret);
}