Skip to content

Commit

Permalink
External sizes (#35813)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnfield committed Sep 6, 2022
1 parent 28999a1 commit b6b5291
Show file tree
Hide file tree
Showing 23 changed files with 3 additions and 137 deletions.
1 change: 0 additions & 1 deletion ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion lib/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion lib/ui/painting/fragment_shader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 0 additions & 7 deletions lib/ui/painting/image.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
2 changes: 0 additions & 2 deletions lib/ui/painting/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ class CanvasImage final : public RefCountedDartWrappable<CanvasImage> {

void set_image(sk_sp<DlImage> image) { image_ = image; }

size_t GetAllocationSize() const override;

private:
CanvasImage();

Expand Down
4 changes: 0 additions & 4 deletions lib/ui/painting/image_descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,6 @@ class ImageDescriptor : public RefCountedDartWrappable<ImageDescriptor> {
ClearDartWrapper();
}

size_t GetAllocationSize() const override {
return sizeof(ImageDescriptor) + sizeof(SkImageInfo) + buffer_->size();
}

private:
ImageDescriptor(sk_sp<SkData> buffer,
const SkImageInfo& image_info,
Expand Down
1 change: 0 additions & 1 deletion lib/ui/painting/image_encoding_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ TEST_F(ShellTest, EncodeImageAccessesSyncSwitch) {
image_handle, tonic::DartWrappable::kPeerIndex, &peer);
ASSERT_FALSE(Dart_IsError(result));
CanvasImage* canvas_image = reinterpret_cast<CanvasImage*>(peer);
ASSERT_EQ(canvas_image->GetAllocationSize(), sizeof(*canvas_image));

int64_t format = -1;
result = Dart_IntegerToInt64(format_handle, &format);
Expand Down
4 changes: 0 additions & 4 deletions lib/ui/painting/immutable_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions lib/ui/painting/immutable_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ class ImmutableBuffer : public RefCountedDartWrappable<ImmutableBuffer> {
ClearDartWrapper();
}

size_t GetAllocationSize() const override;

private:
explicit ImmutableBuffer(sk_sp<SkData> data) : data_(std::move(data)) {}

Expand Down
7 changes: 0 additions & 7 deletions lib/ui/painting/path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 0 additions & 2 deletions lib/ui/painting/path.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ class CanvasPath : public RefCountedDartWrappable<CanvasPath> {

const SkPath& path() const { return tracked_path_->path; }

size_t GetAllocationSize() const override;

private:
CanvasPath();

Expand Down
2 changes: 1 addition & 1 deletion lib/ui/painting/picture.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Picture : public RefCountedDartWrappable<Picture> {

void dispose();

size_t GetAllocationSize() const override;
size_t GetAllocationSize() const;

static void RasterizeToImageSync(sk_sp<DisplayList> display_list,
uint32_t width,
Expand Down
4 changes: 0 additions & 4 deletions lib/ui/painting/single_frame_codec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 0 additions & 3 deletions lib/ui/painting/single_frame_codec.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
2 changes: 0 additions & 2 deletions lib/ui/painting/single_frame_codec_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<SingleFrameCodec*>(peer);
ASSERT_EQ(codec->GetAllocationSize(), sizeof(SingleFrameCodec));
};
auto finish = [message_latch](Dart_NativeArguments args) {
message_latch->Signal();
Expand Down
7 changes: 0 additions & 7 deletions lib/ui/painting/vertices.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 0 additions & 2 deletions lib/ui/painting/vertices.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ class Vertices : public RefCountedDartWrappable<Vertices> {

const DlVertices* vertices() const { return vertices_.get(); }

size_t GetAllocationSize() const override;

void dispose();

private:
Expand Down
64 changes: 0 additions & 64 deletions lib/ui/painting/vertices_unittests.cc

This file was deleted.

7 changes: 0 additions & 7 deletions lib/ui/text/paragraph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ Paragraph::Paragraph(std::unique_ptr<txt::Paragraph> 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();
}
Expand Down
2 changes: 0 additions & 2 deletions lib/ui/text/paragraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ class Paragraph : public RefCountedDartWrappable<Paragraph> {
Dart_Handle getLineBoundary(unsigned offset);
tonic::Float64List computeLineMetrics();

size_t GetAllocationSize() const override;

void dispose();

private:
Expand Down
8 changes: 2 additions & 6 deletions third_party/tonic/dart_wrappable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

Expand All @@ -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) {
Expand Down
6 changes: 0 additions & 6 deletions third_party/tonic/dart_wrappable.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -85,7 +80,6 @@ class DartWrappable {
kDartWrapperInfo_##LibraryName_##ClassName = { \
#LibraryName, \
#ClassName, \
sizeof(ClassName), \
}; \
const tonic::DartWrapperInfo& ClassName::dart_wrapper_info_ = \
kDartWrapperInfo_##LibraryName_##ClassName;
Expand Down
1 change: 0 additions & 1 deletion third_party/tonic/dart_wrapper_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit b6b5291

Please sign in to comment.