提交 e5563329 编写于 作者: J Jason Simmons 提交者: GitHub

Report size estimates to Dart for Image/Picture/Paragraph objects (#3840)

Fixes https://github.com/flutter/flutter/issues/11007
上级 2d8875c2
......@@ -40,4 +40,12 @@ void CanvasImage::dispose() {
ClearDartWrapper();
}
size_t CanvasImage::GetAllocationSize() {
if (image_) {
return image_->width() * image_->height() * 4;
} else {
return sizeof(CanvasImage);
}
}
} // namespace blink
......@@ -32,6 +32,8 @@ class CanvasImage final : public ftl::RefCountedThreadSafe<CanvasImage>,
const sk_sp<SkImage>& image() const { return image_; }
void set_image(sk_sp<SkImage> image) { image_ = std::move(image); }
virtual size_t GetAllocationSize() override;
static void RegisterNatives(tonic::DartLibraryNatives* natives);
private:
......
......@@ -48,4 +48,12 @@ void Picture::dispose() {
ClearDartWrapper();
}
size_t Picture::GetAllocationSize() {
if (picture_) {
return picture_->approximateBytesUsed();
} else {
return sizeof(Picture);
}
}
} // namespace blink
......@@ -31,6 +31,8 @@ class Picture : public ftl::RefCountedThreadSafe<Picture>,
void dispose();
virtual size_t GetAllocationSize() override;
static void RegisterNatives(tonic::DartLibraryNatives* natives);
private:
......
......@@ -51,6 +51,13 @@ Paragraph::~Paragraph() {
}
}
size_t Paragraph::GetAllocationSize() {
// 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 firstChildBox()->width();
}
......
......@@ -45,6 +45,8 @@ class Paragraph : public ftl::RefCountedThreadSafe<Paragraph>,
RenderView* renderView() const { return m_renderView.get(); }
virtual size_t GetAllocationSize() override;
static void RegisterNatives(tonic::DartLibraryNatives* natives);
private:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册