From c2a098c593829977a7bdb66c011841f1a43b9dc9 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Tue, 6 Sep 2022 13:50:04 -0700 Subject: [PATCH] External sizes (flutter/engine#35813) --- .../ci/licenses_golden/licenses_flutter | 1 - engine/src/flutter/lib/ui/BUILD.gn | 1 - .../lib/ui/painting/fragment_shader.cc | 1 - engine/src/flutter/lib/ui/painting/image.cc | 7 -- engine/src/flutter/lib/ui/painting/image.h | 2 - .../lib/ui/painting/image_descriptor.h | 4 -- .../ui/painting/image_encoding_unittests.cc | 1 - .../lib/ui/painting/immutable_buffer.cc | 4 -- .../lib/ui/painting/immutable_buffer.h | 2 - engine/src/flutter/lib/ui/painting/path.cc | 7 -- engine/src/flutter/lib/ui/painting/path.h | 2 - engine/src/flutter/lib/ui/painting/picture.h | 2 +- .../lib/ui/painting/single_frame_codec.cc | 4 -- .../lib/ui/painting/single_frame_codec.h | 3 - .../painting/single_frame_codec_unittests.cc | 2 - .../src/flutter/lib/ui/painting/vertices.cc | 7 -- engine/src/flutter/lib/ui/painting/vertices.h | 2 - .../lib/ui/painting/vertices_unittests.cc | 64 ------------------- engine/src/flutter/lib/ui/text/paragraph.cc | 7 -- engine/src/flutter/lib/ui/text/paragraph.h | 2 - .../third_party/tonic/dart_wrappable.cc | 8 +-- .../third_party/tonic/dart_wrappable.h | 6 -- .../third_party/tonic/dart_wrapper_info.h | 1 - 23 files changed, 3 insertions(+), 137 deletions(-) delete mode 100644 engine/src/flutter/lib/ui/painting/vertices_unittests.cc diff --git a/engine/src/flutter/ci/licenses_golden/licenses_flutter b/engine/src/flutter/ci/licenses_golden/licenses_flutter index 21c4d8f1d4..2dfc3857d0 100644 --- a/engine/src/flutter/ci/licenses_golden/licenses_flutter +++ b/engine/src/flutter/ci/licenses_golden/licenses_flutter @@ -1074,7 +1074,6 @@ FILE: ../../../flutter/lib/ui/painting/single_frame_codec.h FILE: ../../../flutter/lib/ui/painting/single_frame_codec_unittests.cc FILE: ../../../flutter/lib/ui/painting/vertices.cc FILE: ../../../flutter/lib/ui/painting/vertices.h -FILE: ../../../flutter/lib/ui/painting/vertices_unittests.cc FILE: ../../../flutter/lib/ui/platform_dispatcher.dart FILE: ../../../flutter/lib/ui/plugins.dart FILE: ../../../flutter/lib/ui/plugins/callback_cache.cc diff --git a/engine/src/flutter/lib/ui/BUILD.gn b/engine/src/flutter/lib/ui/BUILD.gn index d9f1a893cf..6e5c8296d3 100644 --- a/engine/src/flutter/lib/ui/BUILD.gn +++ b/engine/src/flutter/lib/ui/BUILD.gn @@ -228,7 +228,6 @@ if (enable_unittests) { "painting/image_generator_registry_unittests.cc", "painting/path_unittests.cc", "painting/single_frame_codec_unittests.cc", - "painting/vertices_unittests.cc", "semantics/semantics_update_builder_unittests.cc", "window/platform_configuration_unittests.cc", "window/platform_message_response_dart_unittests.cc", diff --git a/engine/src/flutter/lib/ui/painting/fragment_shader.cc b/engine/src/flutter/lib/ui/painting/fragment_shader.cc index 7d57b3ac14..1a4a3306e4 100644 --- a/engine/src/flutter/lib/ui/painting/fragment_shader.cc +++ b/engine/src/flutter/lib/ui/painting/fragment_shader.cc @@ -23,7 +23,6 @@ namespace flutter { static const tonic::DartWrapperInfo kDartWrapperInfo_ui_FragmentShader = { "ui", "_FragmentShader", - sizeof(FragmentShader), }; const tonic::DartWrapperInfo& FragmentShader::dart_wrapper_info_ = kDartWrapperInfo_ui_FragmentShader; diff --git a/engine/src/flutter/lib/ui/painting/image.cc b/engine/src/flutter/lib/ui/painting/image.cc index c0c8f47bea..e349121c94 100644 --- a/engine/src/flutter/lib/ui/painting/image.cc +++ b/engine/src/flutter/lib/ui/painting/image.cc @@ -21,7 +21,6 @@ typedef CanvasImage Image; static const tonic::DartWrapperInfo kDartWrapperInfo_ui_Image = { "ui", "_Image", - sizeof(Image), }; const tonic::DartWrapperInfo& Image::dart_wrapper_info_ = kDartWrapperInfo_ui_Image; @@ -39,10 +38,4 @@ void CanvasImage::dispose() { ClearDartWrapper(); } -size_t CanvasImage::GetAllocationSize() const { - // 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.h b/engine/src/flutter/lib/ui/painting/image.h index d7a9bb3d9c..35b710160e 100644 --- a/engine/src/flutter/lib/ui/painting/image.h +++ b/engine/src/flutter/lib/ui/painting/image.h @@ -37,8 +37,6 @@ class CanvasImage final : public RefCountedDartWrappable { void set_image(sk_sp image) { image_ = image; } - size_t GetAllocationSize() const override; - private: CanvasImage(); diff --git a/engine/src/flutter/lib/ui/painting/image_descriptor.h b/engine/src/flutter/lib/ui/painting/image_descriptor.h index 271a60a4dd..191e2f49fb 100644 --- a/engine/src/flutter/lib/ui/painting/image_descriptor.h +++ b/engine/src/flutter/lib/ui/painting/image_descriptor.h @@ -114,10 +114,6 @@ class ImageDescriptor : public RefCountedDartWrappable { ClearDartWrapper(); } - size_t GetAllocationSize() const override { - return sizeof(ImageDescriptor) + sizeof(SkImageInfo) + buffer_->size(); - } - private: ImageDescriptor(sk_sp buffer, const SkImageInfo& image_info, 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 22dd425ffc..7b6d0eb8c1 100644 --- a/engine/src/flutter/lib/ui/painting/image_encoding_unittests.cc +++ b/engine/src/flutter/lib/ui/painting/image_encoding_unittests.cc @@ -125,7 +125,6 @@ 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); diff --git a/engine/src/flutter/lib/ui/painting/immutable_buffer.cc b/engine/src/flutter/lib/ui/painting/immutable_buffer.cc index adb328805f..7540135fd8 100644 --- a/engine/src/flutter/lib/ui/painting/immutable_buffer.cc +++ b/engine/src/flutter/lib/ui/painting/immutable_buffer.cc @@ -77,10 +77,6 @@ Dart_Handle ImmutableBuffer::initFromAsset(Dart_Handle buffer_handle, return Dart_Null(); } -size_t ImmutableBuffer::GetAllocationSize() const { - return sizeof(ImmutableBuffer) + data_->size(); -} - #if FML_OS_ANDROID // Compressed image buffers are allocated on the UI thread but are deleted on a diff --git a/engine/src/flutter/lib/ui/painting/immutable_buffer.h b/engine/src/flutter/lib/ui/painting/immutable_buffer.h index d03006b11c..5c51f65c51 100644 --- a/engine/src/flutter/lib/ui/painting/immutable_buffer.h +++ b/engine/src/flutter/lib/ui/painting/immutable_buffer.h @@ -75,8 +75,6 @@ class ImmutableBuffer : public RefCountedDartWrappable { ClearDartWrapper(); } - size_t GetAllocationSize() const override; - private: explicit ImmutableBuffer(sk_sp data) : data_(std::move(data)) {} diff --git a/engine/src/flutter/lib/ui/painting/path.cc b/engine/src/flutter/lib/ui/painting/path.cc index 938ecaa141..647250e451 100644 --- a/engine/src/flutter/lib/ui/painting/path.cc +++ b/engine/src/flutter/lib/ui/painting/path.cc @@ -308,11 +308,4 @@ void CanvasPath::clone(Dart_Handle path_handle) { path->mutable_path() = this->path(); } -// This is doomed to be called too early, since Paths are mutable. -// However, it can help for some of the clone/shift/transform type methods -// where the resultant path will initially have a meaningful size. -size_t CanvasPath::GetAllocationSize() const { - return sizeof(CanvasPath) + path().approximateBytesUsed(); -} - } // namespace flutter diff --git a/engine/src/flutter/lib/ui/painting/path.h b/engine/src/flutter/lib/ui/painting/path.h index 1361497e18..60f07e5d52 100644 --- a/engine/src/flutter/lib/ui/painting/path.h +++ b/engine/src/flutter/lib/ui/painting/path.h @@ -111,8 +111,6 @@ class CanvasPath : public RefCountedDartWrappable { const SkPath& path() const { return tracked_path_->path; } - size_t GetAllocationSize() const override; - private: CanvasPath(); diff --git a/engine/src/flutter/lib/ui/painting/picture.h b/engine/src/flutter/lib/ui/painting/picture.h index 15d1c8623a..68e1ced710 100644 --- a/engine/src/flutter/lib/ui/painting/picture.h +++ b/engine/src/flutter/lib/ui/painting/picture.h @@ -40,7 +40,7 @@ class Picture : public RefCountedDartWrappable { void dispose(); - size_t GetAllocationSize() const override; + size_t GetAllocationSize() const; static void RasterizeToImageSync(sk_sp display_list, uint32_t width, diff --git a/engine/src/flutter/lib/ui/painting/single_frame_codec.cc b/engine/src/flutter/lib/ui/painting/single_frame_codec.cc index ce1f6fc91c..e962b405cd 100644 --- a/engine/src/flutter/lib/ui/painting/single_frame_codec.cc +++ b/engine/src/flutter/lib/ui/painting/single_frame_codec.cc @@ -113,8 +113,4 @@ Dart_Handle SingleFrameCodec::getNextFrame(Dart_Handle callback_handle) { return Dart_Null(); } -size_t SingleFrameCodec::GetAllocationSize() const { - return sizeof(*this); -} - } // namespace flutter diff --git a/engine/src/flutter/lib/ui/painting/single_frame_codec.h b/engine/src/flutter/lib/ui/painting/single_frame_codec.h index 7e4ac13402..ef5fca8e58 100644 --- a/engine/src/flutter/lib/ui/painting/single_frame_codec.h +++ b/engine/src/flutter/lib/ui/painting/single_frame_codec.h @@ -32,9 +32,6 @@ class SingleFrameCodec : public Codec { // |Codec| Dart_Handle getNextFrame(Dart_Handle args) override; - // |DartWrappable| - size_t GetAllocationSize() const override; - private: enum class Status { kNew, kInProgress, kComplete }; Status status_; diff --git a/engine/src/flutter/lib/ui/painting/single_frame_codec_unittests.cc b/engine/src/flutter/lib/ui/painting/single_frame_codec_unittests.cc index 7e07033d2e..a3dae8c610 100644 --- a/engine/src/flutter/lib/ui/painting/single_frame_codec_unittests.cc +++ b/engine/src/flutter/lib/ui/painting/single_frame_codec_unittests.cc @@ -25,8 +25,6 @@ TEST_F(ShellTest, SingleFrameCodecAccuratelyReportsSize) { Dart_Handle result = Dart_GetNativeInstanceField( handle, tonic::DartWrappable::kPeerIndex, &peer); ASSERT_FALSE(Dart_IsError(result)); - SingleFrameCodec* codec = reinterpret_cast(peer); - ASSERT_EQ(codec->GetAllocationSize(), sizeof(SingleFrameCodec)); }; auto finish = [message_latch](Dart_NativeArguments args) { message_latch->Signal(); diff --git a/engine/src/flutter/lib/ui/painting/vertices.cc b/engine/src/flutter/lib/ui/painting/vertices.cc index 78d8c825a0..1eb69acef0 100644 --- a/engine/src/flutter/lib/ui/painting/vertices.cc +++ b/engine/src/flutter/lib/ui/painting/vertices.cc @@ -80,13 +80,6 @@ bool Vertices::init(Dart_Handle vertices_handle, return true; } -size_t Vertices::GetAllocationSize() const { - if (!vertices_) { - return sizeof(*this); - } - return vertices_->size(); -} - void Vertices::dispose() { vertices_.reset(); ClearDartWrapper(); diff --git a/engine/src/flutter/lib/ui/painting/vertices.h b/engine/src/flutter/lib/ui/painting/vertices.h index f5a210fe74..9c94f81359 100644 --- a/engine/src/flutter/lib/ui/painting/vertices.h +++ b/engine/src/flutter/lib/ui/painting/vertices.h @@ -28,8 +28,6 @@ class Vertices : public RefCountedDartWrappable { const DlVertices* vertices() const { return vertices_.get(); } - size_t GetAllocationSize() const override; - void dispose(); private: diff --git a/engine/src/flutter/lib/ui/painting/vertices_unittests.cc b/engine/src/flutter/lib/ui/painting/vertices_unittests.cc deleted file mode 100644 index c0d52dae19..0000000000 --- a/engine/src/flutter/lib/ui/painting/vertices_unittests.cc +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "flutter/lib/ui/painting/vertices.h" - -#include - -#include "flutter/common/task_runners.h" -#include "flutter/fml/synchronization/waitable_event.h" -#include "flutter/runtime/dart_vm.h" -#include "flutter/shell/common/shell_test.h" -#include "flutter/shell/common/thread_host.h" -#include "flutter/testing/testing.h" - -namespace flutter { -namespace testing { - -TEST_F(ShellTest, VerticesAccuratelyReportsSize) { - auto message_latch = std::make_shared(); - - auto nativeValidateVertices = [message_latch](Dart_NativeArguments args) { - auto handle = Dart_GetNativeArgument(args, 0); - intptr_t peer = 0; - Dart_Handle result = Dart_GetNativeInstanceField( - handle, tonic::DartWrappable::kPeerIndex, &peer); - ASSERT_FALSE(Dart_IsError(result)); - Vertices* vertices = reinterpret_cast(peer); - // GT because we don't want to be too dependent on platform specific - // differences, or minor changes to Skia. The actual value of this on - // macOS as of the test writing is 1441890ul. Just need to assert it's - // big enough to get the Dart GC's attention. - ASSERT_GT(vertices->GetAllocationSize(), 1300000ul); - message_latch->Signal(); - }; - - Settings settings = CreateSettingsForFixture(); - TaskRunners task_runners("test", // label - GetCurrentTaskRunner(), // platform - CreateNewThread(), // raster - CreateNewThread(), // ui - CreateNewThread() // io - ); - - AddNativeCallback("ValidateVertices", - CREATE_NATIVE_ENTRY(nativeValidateVertices)); - - std::unique_ptr shell = - CreateShell(std::move(settings), std::move(task_runners)); - - ASSERT_TRUE(shell->IsSetup()); - auto configuration = RunConfiguration::InferFromSettings(settings); - configuration.SetEntrypoint("createVertices"); - - shell->RunEngine(std::move(configuration), [](auto result) { - ASSERT_EQ(result, Engine::RunStatus::Success); - }); - - message_latch->Wait(); - DestroyShell(std::move(shell), std::move(task_runners)); -} - -} // namespace testing -} // namespace flutter diff --git a/engine/src/flutter/lib/ui/text/paragraph.cc b/engine/src/flutter/lib/ui/text/paragraph.cc index 58b5230f59..6b4bb3610b 100644 --- a/engine/src/flutter/lib/ui/text/paragraph.cc +++ b/engine/src/flutter/lib/ui/text/paragraph.cc @@ -22,13 +22,6 @@ Paragraph::Paragraph(std::unique_ptr paragraph) Paragraph::~Paragraph() = default; -size_t Paragraph::GetAllocationSize() const { - // We don't have an accurate accounting of the paragraph's memory consumption, - // so return a fixed size to indicate that its impact is more than the size - // of the Paragraph class. - return 2000; -} - double Paragraph::width() { return m_paragraph->GetMaxWidth(); } diff --git a/engine/src/flutter/lib/ui/text/paragraph.h b/engine/src/flutter/lib/ui/text/paragraph.h index 3f24d1f03e..1a5d8217aa 100644 --- a/engine/src/flutter/lib/ui/text/paragraph.h +++ b/engine/src/flutter/lib/ui/text/paragraph.h @@ -49,8 +49,6 @@ class Paragraph : public RefCountedDartWrappable { Dart_Handle getLineBoundary(unsigned offset); tonic::Float64List computeLineMetrics(); - size_t GetAllocationSize() const override; - void dispose(); private: diff --git a/engine/src/flutter/third_party/tonic/dart_wrappable.cc b/engine/src/flutter/third_party/tonic/dart_wrappable.cc index 630d6121d0..baa1fa5a20 100644 --- a/engine/src/flutter/third_party/tonic/dart_wrappable.cc +++ b/engine/src/flutter/third_party/tonic/dart_wrappable.cc @@ -38,7 +38,7 @@ Dart_Handle DartWrappable::CreateDartWrapper(DartState* dart_state) { TONIC_DCHECK(!CheckAndHandleError(res)); this->RetainDartWrappableReference(); // Balanced in FinalizeDartWrapper. - dart_wrapper_.Set(dart_state, wrapper, this, GetAllocationSize(), + dart_wrapper_.Set(dart_state, wrapper, this, sizeof(*this), &FinalizeDartWrapper); return wrapper; @@ -59,7 +59,7 @@ void DartWrappable::AssociateWithDartWrapper(Dart_Handle wrapper) { this->RetainDartWrappableReference(); // Balanced in FinalizeDartWrapper. DartState* dart_state = DartState::Current(); - dart_wrapper_.Set(dart_state, wrapper, this, GetAllocationSize(), + dart_wrapper_.Set(dart_state, wrapper, this, sizeof(*this), &FinalizeDartWrapper); } @@ -78,10 +78,6 @@ void DartWrappable::FinalizeDartWrapper(void* isolate_callback_data, wrappable->ReleaseDartWrappableReference(); // Balanced in CreateDartWrapper. } -size_t DartWrappable::GetAllocationSize() const { - return GetDartWrapperInfo().size_in_bytes; -} - Dart_PersistentHandle DartWrappable::GetTypeForWrapper( tonic::DartState* dart_state, const tonic::DartWrapperInfo& wrapper_info) { diff --git a/engine/src/flutter/third_party/tonic/dart_wrappable.h b/engine/src/flutter/third_party/tonic/dart_wrappable.h index 40532bf0cb..9c155da27e 100644 --- a/engine/src/flutter/third_party/tonic/dart_wrappable.h +++ b/engine/src/flutter/third_party/tonic/dart_wrappable.h @@ -34,11 +34,6 @@ class DartWrappable { // Implement using IMPLEMENT_WRAPPERTYPEINFO macro virtual const DartWrapperInfo& GetDartWrapperInfo() const = 0; - // Override this to customize the object size reported to the Dart garbage - // collector. - // Implement using IMPLEMENT_WRAPPERTYPEINFO macro - virtual size_t GetAllocationSize() const; - virtual void RetainDartWrappableReference() const = 0; virtual void ReleaseDartWrappableReference() const = 0; @@ -85,7 +80,6 @@ class DartWrappable { kDartWrapperInfo_##LibraryName_##ClassName = { \ #LibraryName, \ #ClassName, \ - sizeof(ClassName), \ }; \ const tonic::DartWrapperInfo& ClassName::dart_wrapper_info_ = \ kDartWrapperInfo_##LibraryName_##ClassName; diff --git a/engine/src/flutter/third_party/tonic/dart_wrapper_info.h b/engine/src/flutter/third_party/tonic/dart_wrapper_info.h index 06174f3a24..8333c81d06 100644 --- a/engine/src/flutter/third_party/tonic/dart_wrapper_info.h +++ b/engine/src/flutter/third_party/tonic/dart_wrapper_info.h @@ -15,7 +15,6 @@ typedef void (*DartWrappableAccepter)(DartWrappable*); struct DartWrapperInfo { const char* library_name; const char* interface_name; - const size_t size_in_bytes; private: DartWrapperInfo(const DartWrapperInfo&) = delete;