未验证 提交 7e38261e 编写于 作者: D Dan Field 提交者: GitHub

Record path memory usage in SkPictures (#18827)

上级 5efd2e82
......@@ -181,6 +181,7 @@ void Canvas::clipPath(const CanvasPath* path, bool doAntiAlias) {
if (!path)
Dart_ThrowException(
ToDart("Canvas.clipPath called with non-genuine Path."));
external_allocation_size_ += path->path().approximateBytesUsed();
canvas_->clipPath(path->path(), doAntiAlias);
}
......@@ -280,6 +281,7 @@ void Canvas::drawPath(const CanvasPath* path,
if (!path)
Dart_ThrowException(
ToDart("Canvas.drawPath called with non-genuine Path."));
external_allocation_size_ += path->path().approximateBytesUsed();
canvas_->drawPath(path->path(), *paint.paint());
}
......@@ -425,6 +427,7 @@ void Canvas::drawShadow(const CanvasPath* path,
ToDart("Canvas.drawShader called with non-genuine Path."));
SkScalar dpr =
UIDartState::Current()->window()->viewport_metrics().device_pixel_ratio;
external_allocation_size_ += path->path().approximateBytesUsed();
flutter::PhysicalShapeLayer::DrawShadow(canvas_, path->path(), color,
elevation, transparentOccluder, dpr);
}
......
......@@ -297,4 +297,11 @@ void CanvasPath::clone(Dart_Handle path_handle) {
path->path_ = 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
......@@ -110,6 +110,8 @@ class CanvasPath : public RefCountedDartWrappable<CanvasPath> {
const SkPath& path() const { return path_; }
size_t GetAllocationSize() const override;
static void RegisterNatives(tonic::DartLibraryNatives* natives);
private:
......
......@@ -286,4 +286,23 @@ void main() {
expect(picture2.approximateBytesUsed, greaterThan(minimumExpected));
});
test('Path reflected in picture size for drawPath, clipPath, and drawShadow', () async {
final PictureRecorder recorder = PictureRecorder();
final Canvas canvas = Canvas(recorder);
final Path path = Path();
for (int i = 0; i < 10000; i++) {
path.lineTo(5, 9);
path.lineTo(i.toDouble(), i.toDouble());
}
path.close();
canvas.drawPath(path, Paint());
canvas.drawShadow(path, const Color(0xFF000000), 5.0, false);
canvas.clipPath(path);
final Picture picture = recorder.endRecording();
// Slightly fuzzy here to allow for platform specific differences
// Measurement on macOS: 541078
expect(picture.approximateBytesUsed, greaterThan(530000));
});
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册