Skip to content

Commit c700479

Browse files
authored
Revert external size changes to Picture (flutter#20950)
1 parent 634e499 commit c700479

File tree

6 files changed

+12
-92
lines changed

6 files changed

+12
-92
lines changed

lib/ui/painting/canvas.cc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ void Canvas::clipPath(const CanvasPath* path, bool doAntiAlias) {
198198
ToDart("Canvas.clipPath called with non-genuine Path."));
199199
return;
200200
}
201-
external_allocation_size_ += path->path().approximateBytesUsed();
202201
canvas_->clipPath(path->path(), doAntiAlias);
203202
}
204203

@@ -310,7 +309,6 @@ void Canvas::drawPath(const CanvasPath* path,
310309
ToDart("Canvas.drawPath called with non-genuine Path."));
311310
return;
312311
}
313-
external_allocation_size_ += path->path().approximateBytesUsed();
314312
canvas_->drawPath(path->path(), *paint.paint());
315313
}
316314

@@ -391,7 +389,6 @@ void Canvas::drawPicture(Picture* picture) {
391389
ToDart("Canvas.drawPicture called with non-genuine Picture."));
392390
return;
393391
}
394-
external_allocation_size_ += picture->GetAllocationSize();
395392
canvas_->drawPicture(picture->picture().get());
396393
}
397394

@@ -424,7 +421,6 @@ void Canvas::drawVertices(const Vertices* vertices,
424421
ToDart("Canvas.drawVertices called with non-genuine Vertices."));
425422
return;
426423
}
427-
external_allocation_size_ += vertices->GetAllocationSize();
428424
canvas_->drawVertices(vertices->vertices(), blend_mode, *paint.paint());
429425
}
430426

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

456-
external_allocation_size_ += atlas->GetAllocationSize();
457452
canvas_->drawAtlas(
458453
skImage.get(), reinterpret_cast<const SkRSXform*>(transforms.data()),
459454
reinterpret_cast<const SkRect*>(rects.data()),
@@ -477,7 +472,6 @@ void Canvas::drawShadow(const CanvasPath* path,
477472
->window()
478473
->viewport_metrics()
479474
.device_pixel_ratio;
480-
external_allocation_size_ += path->path().approximateBytesUsed();
481475
flutter::PhysicalShapeLayer::DrawShadow(canvas_, path->path(), color,
482476
elevation, transparentOccluder, dpr);
483477
}

lib/ui/painting/canvas.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,13 @@ class Canvas : public RefCountedDartWrappable<Canvas> {
169169

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

172-
size_t external_allocation_size() const { return external_allocation_size_; }
173-
174172
private:
175173
explicit Canvas(SkCanvas* canvas);
176174

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

184181
} // namespace flutter

lib/ui/painting/picture.cc

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,17 @@ IMPLEMENT_WRAPPERTYPEINFO(ui, Picture);
2828

2929
DART_BIND_ALL(Picture, FOR_EACH_BINDING)
3030

31-
fml::RefPtr<Picture> Picture::Create(Dart_Handle dart_handle,
32-
flutter::SkiaGPUObject<SkPicture> picture,
33-
size_t external_allocation_size) {
34-
auto canvas_picture = fml::MakeRefCounted<Picture>(std::move(picture),
35-
external_allocation_size);
31+
fml::RefPtr<Picture> Picture::Create(
32+
Dart_Handle dart_handle,
33+
flutter::SkiaGPUObject<SkPicture> picture) {
34+
auto canvas_picture = fml::MakeRefCounted<Picture>(std::move(picture));
3635

3736
canvas_picture->AssociateWithDartWrapper(dart_handle);
3837
return canvas_picture;
3938
}
4039

41-
Picture::Picture(flutter::SkiaGPUObject<SkPicture> picture,
42-
size_t external_allocation_size)
43-
: picture_(std::move(picture)),
44-
external_allocation_size_(external_allocation_size) {}
40+
Picture::Picture(flutter::SkiaGPUObject<SkPicture> picture)
41+
: picture_(std::move(picture)) {}
4542

4643
Picture::~Picture() = default;
4744

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

6360
size_t Picture::GetAllocationSize() const {
6461
if (auto picture = picture_.get()) {
65-
return picture->approximateBytesUsed() + sizeof(Picture) +
66-
external_allocation_size_;
62+
return picture->approximateBytesUsed() + sizeof(Picture);
6763
} else {
6864
return sizeof(Picture);
6965
}

lib/ui/painting/picture.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ class Picture : public RefCountedDartWrappable<Picture> {
2525
public:
2626
~Picture() override;
2727
static fml::RefPtr<Picture> Create(Dart_Handle dart_handle,
28-
flutter::SkiaGPUObject<SkPicture> picture,
29-
size_t external_allocation_size);
28+
flutter::SkiaGPUObject<SkPicture> picture);
3029

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

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

48-
size_t external_allocation_size() const { return external_allocation_size_; }
49-
5047
private:
51-
Picture(flutter::SkiaGPUObject<SkPicture> picture,
52-
size_t external_allocation_size_);
48+
Picture(flutter::SkiaGPUObject<SkPicture> picture);
5349

5450
flutter::SkiaGPUObject<SkPicture> picture_;
55-
size_t external_allocation_size_;
5651
};
5752

5853
} // namespace flutter

lib/ui/painting/picture_recorder.cc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,9 @@ fml::RefPtr<Picture> PictureRecorder::endRecording(Dart_Handle dart_picture) {
4747
return nullptr;
4848
}
4949

50-
fml::RefPtr<Picture> picture =
51-
Picture::Create(dart_picture,
52-
UIDartState::CreateGPUObject(
53-
picture_recorder_.finishRecordingAsPicture()),
54-
canvas_->external_allocation_size());
50+
fml::RefPtr<Picture> picture = Picture::Create(
51+
dart_picture, UIDartState::CreateGPUObject(
52+
picture_recorder_.finishRecordingAsPicture()));
5553

5654
canvas_->Invalidate();
5755
canvas_ = nullptr;

testing/dart/canvas_test.dart

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -269,64 +269,4 @@ void main() {
269269
expectArgumentError(() => canvas.drawRawAtlas(image, Float32List(0), Float32List(4), null, null, rect, paint));
270270
expectArgumentError(() => canvas.drawRawAtlas(image, Float32List(4), Float32List(4), Int32List(2), BlendMode.src, rect, paint));
271271
});
272-
273-
test('Vertex buffer size reflected in picture size for drawVertices', () async {
274-
final PictureRecorder recorder = PictureRecorder();
275-
final Canvas canvas = Canvas(recorder);
276-
277-
const int uint16max = 65535;
278-
279-
final Int32List colors = Int32List(uint16max);
280-
final Float32List coords = Float32List(uint16max * 2);
281-
final Uint16List indices = Uint16List(uint16max);
282-
final Float32List positions = Float32List(uint16max * 2);
283-
colors[0] = const Color(0xFFFF0000).value;
284-
colors[1] = const Color(0xFF00FF00).value;
285-
colors[2] = const Color(0xFF0000FF).value;
286-
colors[3] = const Color(0xFF00FFFF).value;
287-
indices[1] = indices[3] = 1;
288-
indices[2] = indices[5] = 3;
289-
indices[4] = 2;
290-
positions[2] = positions[4] = positions[5] = positions[7] = 250.0;
291-
292-
final Vertices vertices = Vertices.raw(
293-
VertexMode.triangles,
294-
positions,
295-
textureCoordinates: coords,
296-
colors: colors,
297-
indices: indices,
298-
);
299-
canvas.drawVertices(vertices, BlendMode.src, Paint());
300-
final Picture picture = recorder.endRecording();
301-
302-
303-
const int minimumExpected = uint16max * 4;
304-
expect(picture.approximateBytesUsed, greaterThan(minimumExpected));
305-
306-
final PictureRecorder recorder2 = PictureRecorder();
307-
final Canvas canvas2 = Canvas(recorder2);
308-
canvas2.drawPicture(picture);
309-
final Picture picture2 = recorder2.endRecording();
310-
311-
expect(picture2.approximateBytesUsed, greaterThan(minimumExpected));
312-
});
313-
314-
test('Path reflected in picture size for drawPath, clipPath, and drawShadow', () async {
315-
final PictureRecorder recorder = PictureRecorder();
316-
final Canvas canvas = Canvas(recorder);
317-
final Path path = Path();
318-
for (int i = 0; i < 10000; i++) {
319-
path.lineTo(5, 9);
320-
path.lineTo(i.toDouble(), i.toDouble());
321-
}
322-
path.close();
323-
canvas.drawPath(path, Paint());
324-
canvas.drawShadow(path, const Color(0xFF000000), 5.0, false);
325-
canvas.clipPath(path);
326-
final Picture picture = recorder.endRecording();
327-
328-
// Slightly fuzzy here to allow for platform specific differences
329-
// Measurement on macOS: 541078
330-
expect(picture.approximateBytesUsed, greaterThan(530000));
331-
});
332272
}

0 commit comments

Comments
 (0)