From 9faf3b6746b880e7323618023e5dc4f94d81762f Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Wed, 17 Aug 2022 14:55:06 -0700 Subject: [PATCH] don't report GPU image size (flutter/engine#35473) --- engine/src/flutter/lib/ui/painting/image.cc | 14 ++++---------- .../lib/ui/painting/image_encoding_unittests.cc | 1 + 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/engine/src/flutter/lib/ui/painting/image.cc b/engine/src/flutter/lib/ui/painting/image.cc index 91a6c6eea7..c0c8f47bea 100644 --- a/engine/src/flutter/lib/ui/painting/image.cc +++ b/engine/src/flutter/lib/ui/painting/image.cc @@ -40,15 +40,9 @@ void CanvasImage::dispose() { } size_t CanvasImage::GetAllocationSize() const { - auto size = sizeof(this); - if (image_) { - size += image_->GetApproximateByteSize(); - } - // The VM will assert if we set a value larger than or close to - // std::numeric_limits::max(). - // https://github.com/dart-lang/sdk/issues/49332 - return std::clamp( - size, static_cast(0), - static_cast(std::numeric_limits::max() / 10)); + // We don't actually want Dart's GC to use the size of this object to make GC + // decisions, as it is generally both created and disposed in the framework. + // This is similar to why we do not report the sizes of engine layers. + return sizeof(*this); } } // namespace flutter diff --git a/engine/src/flutter/lib/ui/painting/image_encoding_unittests.cc b/engine/src/flutter/lib/ui/painting/image_encoding_unittests.cc index 7b6d0eb8c1..22dd425ffc 100644 --- a/engine/src/flutter/lib/ui/painting/image_encoding_unittests.cc +++ b/engine/src/flutter/lib/ui/painting/image_encoding_unittests.cc @@ -125,6 +125,7 @@ TEST_F(ShellTest, EncodeImageAccessesSyncSwitch) { image_handle, tonic::DartWrappable::kPeerIndex, &peer); ASSERT_FALSE(Dart_IsError(result)); CanvasImage* canvas_image = reinterpret_cast(peer); + ASSERT_EQ(canvas_image->GetAllocationSize(), sizeof(*canvas_image)); int64_t format = -1; result = Dart_IntegerToInt64(format_handle, &format);