From 8ae72c1191b06fdd2965832b669b5c63ba0bff43 Mon Sep 17 00:00:00 2001 From: Jim Graham Date: Thu, 17 Mar 2022 12:03:24 -0700 Subject: [PATCH 1/4] override delete operators in DlGradient classes --- display_list/display_list_color_source.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/display_list/display_list_color_source.h b/display_list/display_list_color_source.h index 6dd1912c04284..feddd6d655d87 100644 --- a/display_list/display_list_color_source.h +++ b/display_list/display_list_color_source.h @@ -282,6 +282,12 @@ class DlGradientColorSourceBase : public DlMatrixColorSourceBase { return reinterpret_cast(colors() + stop_count()); } + void operator delete(void* p) { ::operator delete(p); } + + void operator delete(void* p, size_t s) { + ::operator delete(p, static_cast(p)->size()); + } + protected: DlGradientColorSourceBase(uint32_t stop_count, DlTileMode tile_mode, From 5bb95023d523da3abd703b35b3cc64fd45af98df Mon Sep 17 00:00:00 2001 From: Jim Graham Date: Thu, 17 Mar 2022 12:23:46 -0700 Subject: [PATCH 2/4] switch to individual Deleters in shared_ptr allocations --- display_list/display_list_color_source.cc | 20 +++++++++++++------- display_list/display_list_color_source.h | 6 ------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/display_list/display_list_color_source.cc b/display_list/display_list_color_source.cc index 1a59463bb0561..a787fc65a49bc 100644 --- a/display_list/display_list_color_source.cc +++ b/display_list/display_list_color_source.cc @@ -98,8 +98,10 @@ std::shared_ptr DlColorSource::MakeLinear( void* storage = ::operator new(needed); std::shared_ptr 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), + [needed](auto p) { ::operator delete(p, needed); }); return std::move(ret); } @@ -118,7 +120,8 @@ std::shared_ptr DlColorSource::MakeRadial( std::shared_ptr ret; ret.reset(new (storage) DlRadialGradientColorSource( - center, radius, stop_count, colors, stops, tile_mode, matrix)); + center, radius, stop_count, colors, stops, tile_mode, matrix), + [needed](auto p) { ::operator delete(p, needed); }); return std::move(ret); } @@ -139,8 +142,9 @@ std::shared_ptr DlColorSource::MakeConical( std::shared_ptr 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), + [needed](auto p) { ::operator delete(p, needed); }); return std::move(ret); } @@ -159,8 +163,10 @@ std::shared_ptr DlColorSource::MakeSweep( void* storage = ::operator new(needed); std::shared_ptr 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), + [needed](auto p) { ::operator delete(p, needed); }); return std::move(ret); } diff --git a/display_list/display_list_color_source.h b/display_list/display_list_color_source.h index feddd6d655d87..6dd1912c04284 100644 --- a/display_list/display_list_color_source.h +++ b/display_list/display_list_color_source.h @@ -282,12 +282,6 @@ class DlGradientColorSourceBase : public DlMatrixColorSourceBase { return reinterpret_cast(colors() + stop_count()); } - void operator delete(void* p) { ::operator delete(p); } - - void operator delete(void* p, size_t s) { - ::operator delete(p, static_cast(p)->size()); - } - protected: DlGradientColorSourceBase(uint32_t stop_count, DlTileMode tile_mode, From dd2acb990073fb7263e616c6006d0ae0b5e10aaf Mon Sep 17 00:00:00 2001 From: Jim Graham Date: Thu, 17 Mar 2022 12:45:40 -0700 Subject: [PATCH 3/4] switch to static (non-closure) Destructor --- display_list/display_list_color_source.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/display_list/display_list_color_source.cc b/display_list/display_list_color_source.cc index a787fc65a49bc..181191019dc4d 100644 --- a/display_list/display_list_color_source.cc +++ b/display_list/display_list_color_source.cc @@ -84,6 +84,10 @@ std::shared_ptr DlColorSource::From(SkShader* sk_shader) { return source; } +static void DlGradientDeleter(void* p) { + ::operator delete(p, static_cast(p)->size()); +} + std::shared_ptr DlColorSource::MakeLinear( const SkPoint start_point, const SkPoint end_point, @@ -101,7 +105,7 @@ std::shared_ptr DlColorSource::MakeLinear( ret.reset(new (storage) DlLinearGradientColorSource(start_point, end_point, stop_count, colors, stops, tile_mode, matrix), - [needed](auto p) { ::operator delete(p, needed); }); + DlGradientDeleter); return std::move(ret); } @@ -121,7 +125,7 @@ std::shared_ptr DlColorSource::MakeRadial( std::shared_ptr ret; ret.reset(new (storage) DlRadialGradientColorSource( center, radius, stop_count, colors, stops, tile_mode, matrix), - [needed](auto p) { ::operator delete(p, needed); }); + DlGradientDeleter); return std::move(ret); } @@ -144,7 +148,7 @@ std::shared_ptr DlColorSource::MakeConical( ret.reset(new (storage) DlConicalGradientColorSource( start_center, start_radius, end_center, end_radius, stop_count, colors, stops, tile_mode, matrix), - [needed](auto p) { ::operator delete(p, needed); }); + DlGradientDeleter); return std::move(ret); } @@ -166,7 +170,7 @@ std::shared_ptr DlColorSource::MakeSweep( ret.reset(new (storage) DlSweepGradientColorSource(center, start, end, stop_count, colors, stops, tile_mode, matrix), - [needed](auto p) { ::operator delete(p, needed); }); + DlGradientDeleter); return std::move(ret); } From d03e4b24737bbe81c1d41e0cb77b5d774bce99d9 Mon Sep 17 00:00:00 2001 From: Jim Graham Date: Thu, 17 Mar 2022 13:01:05 -0700 Subject: [PATCH 4/4] avoid sized deletes which are missing on iOS --- display_list/display_list_color_source.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/display_list/display_list_color_source.cc b/display_list/display_list_color_source.cc index 181191019dc4d..6c5a5ce746b81 100644 --- a/display_list/display_list_color_source.cc +++ b/display_list/display_list_color_source.cc @@ -85,7 +85,12 @@ std::shared_ptr DlColorSource::From(SkShader* sk_shader) { } static void DlGradientDeleter(void* p) { - ::operator delete(p, static_cast(p)->size()); + // 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::MakeLinear(