mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Revert external size changes to Picture (#20950)
This commit is contained in:
parent
634e499bcc
commit
c700479db5
@ -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<const SkRSXform*>(transforms.data()),
|
||||
reinterpret_cast<const SkRect*>(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);
|
||||
}
|
||||
|
||||
@ -169,8 +169,6 @@ 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);
|
||||
|
||||
@ -178,7 +176,6 @@ class Canvas : public RefCountedDartWrappable<Canvas> {
|
||||
// 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
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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(); }
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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));
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user