From 09d3c21bbf32d31788a23bc8975b00d296b71b52 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Wed, 2 Sep 2020 10:26:47 -0700 Subject: [PATCH] Revert external size changes to Picture --- lib/ui/painting/canvas.cc | 6 --- lib/ui/painting/canvas.h | 3 -- lib/ui/painting/picture.cc | 18 ++++----- lib/ui/painting/picture.h | 9 +---- lib/ui/painting/picture_recorder.cc | 8 ++-- testing/dart/canvas_test.dart | 60 ----------------------------- 6 files changed, 12 insertions(+), 92 deletions(-) diff --git a/lib/ui/painting/canvas.cc b/lib/ui/painting/canvas.cc index c68f0d6001ad6..913730da65d4d 100644 --- a/lib/ui/painting/canvas.cc +++ b/lib/ui/painting/canvas.cc @@ -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); } @@ -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()); } @@ -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()); } @@ -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()); } @@ -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(transforms.data()), reinterpret_cast(rects.data()), @@ -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); } diff --git a/lib/ui/painting/canvas.h b/lib/ui/painting/canvas.h index 53492b9667875..3c58bad4e7895 100644 --- a/lib/ui/painting/canvas.h +++ b/lib/ui/painting/canvas.h @@ -169,8 +169,6 @@ class Canvas : public RefCountedDartWrappable { static void RegisterNatives(tonic::DartLibraryNatives* natives); - size_t external_allocation_size() const { return external_allocation_size_; } - private: explicit Canvas(SkCanvas* canvas); @@ -178,7 +176,6 @@ class Canvas : public RefCountedDartWrappable { // 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 diff --git a/lib/ui/painting/picture.cc b/lib/ui/painting/picture.cc index 1285a6b0921cb..5225d993ba4fb 100644 --- a/lib/ui/painting/picture.cc +++ b/lib/ui/painting/picture.cc @@ -28,20 +28,17 @@ IMPLEMENT_WRAPPERTYPEINFO(ui, Picture); DART_BIND_ALL(Picture, FOR_EACH_BINDING) -fml::RefPtr Picture::Create(Dart_Handle dart_handle, - flutter::SkiaGPUObject picture, - size_t external_allocation_size) { - auto canvas_picture = fml::MakeRefCounted(std::move(picture), - external_allocation_size); +fml::RefPtr Picture::Create( + Dart_Handle dart_handle, + flutter::SkiaGPUObject picture) { + auto canvas_picture = fml::MakeRefCounted(std::move(picture)); canvas_picture->AssociateWithDartWrapper(dart_handle); return canvas_picture; } -Picture::Picture(flutter::SkiaGPUObject picture, - size_t external_allocation_size) - : picture_(std::move(picture)), - external_allocation_size_(external_allocation_size) {} +Picture::Picture(flutter::SkiaGPUObject picture) + : picture_(std::move(picture)) {} Picture::~Picture() = default; @@ -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); } diff --git a/lib/ui/painting/picture.h b/lib/ui/painting/picture.h index 8f1879e1af7fa..e0158d400ff5e 100644 --- a/lib/ui/painting/picture.h +++ b/lib/ui/painting/picture.h @@ -25,8 +25,7 @@ class Picture : public RefCountedDartWrappable { public: ~Picture() override; static fml::RefPtr Create(Dart_Handle dart_handle, - flutter::SkiaGPUObject picture, - size_t external_allocation_size); + flutter::SkiaGPUObject picture); sk_sp picture() const { return picture_.get(); } @@ -45,14 +44,10 @@ class Picture : public RefCountedDartWrappable { uint32_t height, Dart_Handle raw_image_callback); - size_t external_allocation_size() const { return external_allocation_size_; } - private: - Picture(flutter::SkiaGPUObject picture, - size_t external_allocation_size_); + Picture(flutter::SkiaGPUObject picture); flutter::SkiaGPUObject picture_; - size_t external_allocation_size_; }; } // namespace flutter diff --git a/lib/ui/painting/picture_recorder.cc b/lib/ui/painting/picture_recorder.cc index 5916faa9df3ae..5084f30d7812f 100644 --- a/lib/ui/painting/picture_recorder.cc +++ b/lib/ui/painting/picture_recorder.cc @@ -47,11 +47,9 @@ fml::RefPtr PictureRecorder::endRecording(Dart_Handle dart_picture) { return nullptr; } - fml::RefPtr picture = - Picture::Create(dart_picture, - UIDartState::CreateGPUObject( - picture_recorder_.finishRecordingAsPicture()), - canvas_->external_allocation_size()); + fml::RefPtr picture = Picture::Create( + dart_picture, UIDartState::CreateGPUObject( + picture_recorder_.finishRecordingAsPicture())); canvas_->Invalidate(); canvas_ = nullptr; diff --git a/testing/dart/canvas_test.dart b/testing/dart/canvas_test.dart index 39a21a540f678..dd8143a39cc4b 100644 --- a/testing/dart/canvas_test.dart +++ b/testing/dart/canvas_test.dart @@ -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)); - }); }