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

Fixes https://github.com/flutter/flutter/issues/11007
This commit is contained in:
Jason Simmons
2017-06-29 14:14:33 -07:00
committed by GitHub
parent 2d8875c2bc
commit e556332932
6 changed files with 29 additions and 0 deletions
+8
View File
@@ -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
+2
View File
@@ -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:
+8
View File
@@ -48,4 +48,12 @@ void Picture::dispose() {
ClearDartWrapper();
}
size_t Picture::GetAllocationSize() {
if (picture_) {
return picture_->approximateBytesUsed();
} else {
return sizeof(Picture);
}
}
} // namespace blink
+2
View File
@@ -31,6 +31,8 @@ class Picture : public ftl::RefCountedThreadSafe<Picture>,
void dispose();
virtual size_t GetAllocationSize() override;
static void RegisterNatives(tonic::DartLibraryNatives* natives);
private:
+7
View File
@@ -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();
}
+2
View File
@@ -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: