Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions lib/ui/painting/canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ void Canvas::clipPath(const CanvasPath* path, bool doAntiAlias) {
ToDart("Canvas.clipPath called with non-genuine Path."));
return;
}
external_allocation_size_ += path->path().approximateBytesUsed();
canvas_->clipPath(path->path(), doAntiAlias);
}

Expand Down Expand Up @@ -310,7 +309,6 @@ void Canvas::drawPath(const CanvasPath* path,
ToDart("Canvas.drawPath called with non-genuine Path."));
return;
}
external_allocation_size_ += path->path().approximateBytesUsed();
canvas_->drawPath(path->path(), *paint.paint());
}

Expand Down Expand Up @@ -391,7 +389,6 @@ void Canvas::drawPicture(Picture* picture) {
ToDart("Canvas.drawPicture called with non-genuine Picture."));
return;
}
external_allocation_size_ += picture->GetAllocationSize();
canvas_->drawPicture(picture->picture().get());
}

Expand Down Expand Up @@ -424,7 +421,6 @@ void Canvas::drawVertices(const Vertices* vertices,
ToDart("Canvas.drawVertices called with non-genuine Vertices."));
return;
}
external_allocation_size_ += vertices->GetAllocationSize();
canvas_->drawVertices(vertices->vertices(), blend_mode, *paint.paint());
}

Expand Down Expand Up @@ -453,7 +449,6 @@ void Canvas::drawAtlas(const Paint& paint,
static_assert(sizeof(SkRect) == sizeof(float) * 4,
"SkRect doesn't use floats.");

external_allocation_size_ += atlas->GetAllocationSize();
canvas_->drawAtlas(
skImage.get(), reinterpret_cast<const SkRSXform*>(transforms.data()),
reinterpret_cast<const SkRect*>(rects.data()),
Expand All @@ -477,7 +472,6 @@ void Canvas::drawShadow(const CanvasPath* path,
->window()
->viewport_metrics()
.device_pixel_ratio;
external_allocation_size_ += path->path().approximateBytesUsed();
flutter::PhysicalShapeLayer::DrawShadow(canvas_, path->path(), color,
elevation, transparentOccluder, dpr);
}
Expand Down
3 changes: 0 additions & 3 deletions lib/ui/painting/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,13 @@ class Canvas : public RefCountedDartWrappable<Canvas> {

static void RegisterNatives(tonic::DartLibraryNatives* natives);

size_t external_allocation_size() const { return external_allocation_size_; }

private:
explicit Canvas(SkCanvas* canvas);

// The SkCanvas is supplied by a call to SkPictureRecorder::beginRecording,
// which does not transfer ownership. For this reason, we hold a raw
// pointer and manually set to null in Clear.
SkCanvas* canvas_;
size_t external_allocation_size_ = 0;
};

} // namespace flutter
Expand Down
18 changes: 7 additions & 11 deletions lib/ui/painting/picture.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,17 @@ IMPLEMENT_WRAPPERTYPEINFO(ui, Picture);

DART_BIND_ALL(Picture, FOR_EACH_BINDING)

fml::RefPtr<Picture> Picture::Create(Dart_Handle dart_handle,
flutter::SkiaGPUObject<SkPicture> picture,
size_t external_allocation_size) {
auto canvas_picture = fml::MakeRefCounted<Picture>(std::move(picture),
external_allocation_size);
fml::RefPtr<Picture> Picture::Create(
Dart_Handle dart_handle,
flutter::SkiaGPUObject<SkPicture> picture) {
auto canvas_picture = fml::MakeRefCounted<Picture>(std::move(picture));

canvas_picture->AssociateWithDartWrapper(dart_handle);
return canvas_picture;
}

Picture::Picture(flutter::SkiaGPUObject<SkPicture> picture,
size_t external_allocation_size)
: picture_(std::move(picture)),
external_allocation_size_(external_allocation_size) {}
Picture::Picture(flutter::SkiaGPUObject<SkPicture> picture)
: picture_(std::move(picture)) {}

Picture::~Picture() = default;

Expand All @@ -62,8 +59,7 @@ void Picture::dispose() {

size_t Picture::GetAllocationSize() const {
if (auto picture = picture_.get()) {
return picture->approximateBytesUsed() + sizeof(Picture) +
external_allocation_size_;
return picture->approximateBytesUsed() + sizeof(Picture);
} else {
return sizeof(Picture);
}
Expand Down
9 changes: 2 additions & 7 deletions lib/ui/painting/picture.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ class Picture : public RefCountedDartWrappable<Picture> {
public:
~Picture() override;
static fml::RefPtr<Picture> Create(Dart_Handle dart_handle,
flutter::SkiaGPUObject<SkPicture> picture,
size_t external_allocation_size);
flutter::SkiaGPUObject<SkPicture> picture);

sk_sp<SkPicture> picture() const { return picture_.get(); }

Expand All @@ -45,14 +44,10 @@ class Picture : public RefCountedDartWrappable<Picture> {
uint32_t height,
Dart_Handle raw_image_callback);

size_t external_allocation_size() const { return external_allocation_size_; }

private:
Picture(flutter::SkiaGPUObject<SkPicture> picture,
size_t external_allocation_size_);
Picture(flutter::SkiaGPUObject<SkPicture> picture);

flutter::SkiaGPUObject<SkPicture> picture_;
size_t external_allocation_size_;
};

} // namespace flutter
Expand Down
8 changes: 3 additions & 5 deletions lib/ui/painting/picture_recorder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@ fml::RefPtr<Picture> PictureRecorder::endRecording(Dart_Handle dart_picture) {
return nullptr;
}

fml::RefPtr<Picture> picture =
Picture::Create(dart_picture,
UIDartState::CreateGPUObject(
picture_recorder_.finishRecordingAsPicture()),
canvas_->external_allocation_size());
fml::RefPtr<Picture> picture = Picture::Create(
dart_picture, UIDartState::CreateGPUObject(
picture_recorder_.finishRecordingAsPicture()));

canvas_->Invalidate();
canvas_ = nullptr;
Expand Down
60 changes: 0 additions & 60 deletions testing/dart/canvas_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -269,64 +269,4 @@ void main() {
expectArgumentError(() => canvas.drawRawAtlas(image, Float32List(0), Float32List(4), null, null, rect, paint));
expectArgumentError(() => canvas.drawRawAtlas(image, Float32List(4), Float32List(4), Int32List(2), BlendMode.src, rect, paint));
});

test('Vertex buffer size reflected in picture size for drawVertices', () async {
final PictureRecorder recorder = PictureRecorder();
final Canvas canvas = Canvas(recorder);

const int uint16max = 65535;

final Int32List colors = Int32List(uint16max);
final Float32List coords = Float32List(uint16max * 2);
final Uint16List indices = Uint16List(uint16max);
final Float32List positions = Float32List(uint16max * 2);
colors[0] = const Color(0xFFFF0000).value;
colors[1] = const Color(0xFF00FF00).value;
colors[2] = const Color(0xFF0000FF).value;
colors[3] = const Color(0xFF00FFFF).value;
indices[1] = indices[3] = 1;
indices[2] = indices[5] = 3;
indices[4] = 2;
positions[2] = positions[4] = positions[5] = positions[7] = 250.0;

final Vertices vertices = Vertices.raw(
VertexMode.triangles,
positions,
textureCoordinates: coords,
colors: colors,
indices: indices,
);
canvas.drawVertices(vertices, BlendMode.src, Paint());
final Picture picture = recorder.endRecording();


const int minimumExpected = uint16max * 4;
expect(picture.approximateBytesUsed, greaterThan(minimumExpected));

final PictureRecorder recorder2 = PictureRecorder();
final Canvas canvas2 = Canvas(recorder2);
canvas2.drawPicture(picture);
final Picture picture2 = recorder2.endRecording();

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));
});
}