mirror of
https://github.com/encounter/engine.git
synced 2026-03-30 11:09:55 -07:00
Report size estimates to Dart for Image/Picture/Paragraph objects (#3840)
Fixes https://github.com/flutter/flutter/issues/11007
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user