-
Notifications
You must be signed in to change notification settings - Fork 6k
Make images contribute to Picture allocation size, more aggressively release references when dispose is called #18706
Changes from all commits
1150bc2
2e82317
5398e9b
fd87388
3d7a601
e445fd7
b2d1765
b9b06ba
15bf5da
017c9d5
4416c3d
7ccaede
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -293,6 +293,7 @@ void Canvas::drawImage(const CanvasImage* image, | |
| if (!image) | ||
| Dart_ThrowException( | ||
| ToDart("Canvas.drawImage called with non-genuine Image.")); | ||
| image_allocation_size_ += image->GetAllocationSize(); | ||
| canvas_->drawImage(image->image(), x, y, paint.paint()); | ||
| } | ||
|
|
||
|
|
@@ -314,6 +315,7 @@ void Canvas::drawImageRect(const CanvasImage* image, | |
| ToDart("Canvas.drawImageRect called with non-genuine Image.")); | ||
| SkRect src = SkRect::MakeLTRB(src_left, src_top, src_right, src_bottom); | ||
| SkRect dst = SkRect::MakeLTRB(dst_left, dst_top, dst_right, dst_bottom); | ||
| image_allocation_size_ += image->GetAllocationSize(); | ||
| canvas_->drawImageRect(image->image(), src, dst, paint.paint(), | ||
| SkCanvas::kFast_SrcRectConstraint); | ||
| } | ||
|
|
@@ -339,6 +341,7 @@ void Canvas::drawImageNine(const CanvasImage* image, | |
| SkIRect icenter; | ||
| center.round(&icenter); | ||
| SkRect dst = SkRect::MakeLTRB(dst_left, dst_top, dst_right, dst_bottom); | ||
| image_allocation_size_ += image->GetAllocationSize(); | ||
| canvas_->drawImageNine(image->image(), icenter, dst, paint.paint()); | ||
| } | ||
|
|
||
|
|
@@ -348,6 +351,7 @@ void Canvas::drawPicture(Picture* picture) { | |
| if (!picture) | ||
| Dart_ThrowException( | ||
| ToDart("Canvas.drawPicture called with non-genuine Picture.")); | ||
| image_allocation_size_ += picture->GetAllocationSize(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You missed a few:
I understand if you don't want to audit the existing codebase and track everything in this one patch. Let's file a bug to follow up on to perform correct book-keeping on the resources referenced by dart:ui call.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm including
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Filed flutter/flutter#58440 specifically for
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good. Thanks. |
||
| canvas_->drawPicture(picture->picture().get()); | ||
| } | ||
|
|
||
|
|
@@ -402,6 +406,7 @@ void Canvas::drawAtlas(const Paint& paint, | |
| static_assert(sizeof(SkRect) == sizeof(float) * 4, | ||
| "SkRect doesn't use floats."); | ||
|
|
||
| image_allocation_size_ += atlas->GetAllocationSize(); | ||
| canvas_->drawAtlas( | ||
| skImage.get(), reinterpret_cast<const SkRSXform*>(transforms.data()), | ||
| reinterpret_cast<const SkRect*>(rects.data()), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this accurate? I would have expected the canvas to rasterize the drawn image at some point so it doesn't actually hold on to the full image.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's going to hold a reference to the SkImage as long as its alive. The memory is not necessarily duplicated (e.g. we don't necessarily have 2x the pixel allocation for the extra reference), but we need to do a better job of letting the GC know how expensive the object is, otherwise it will think it can skip a GC pass when it really needs one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might help to clarify the semantics of "allocation size". The allocation size is not the size of the allocation that will be collected when the owning object is collected. Instead, it is the size of the allocation that is guaranteed to stay alive pending the collection of the owning object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As in a doc comment in dart_wrappable.h?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. I don't know of a better place.