Trace calls to Canvas::saveLayer (flutter/engine#29444)

This commit is contained in:
Dan Field
2021-11-05 14:29:04 -07:00
committed by GitHub
parent facf9e1c5b
commit 19885035d0
8 changed files with 72 additions and 4 deletions

View File

@@ -135,7 +135,7 @@ RasterStatus CompositorContext::ScopedFrame::Raster(
}
if (needs_save_layer) {
FML_LOG(INFO) << "Using SaveLayer to protect non-readback surface";
TRACE_EVENT0("flutter", "Canvas::saveLayer");
SkRect bounds = SkRect::Make(layer_tree.frame_size());
SkPaint paint;
paint.setBlendMode(SkBlendMode::kSrc);

View File

@@ -59,6 +59,7 @@ void ClipPathLayer::Paint(PaintContext& context) const {
clip_behavior_ != Clip::hardEdge);
if (UsesSaveLayer()) {
TRACE_EVENT0("flutter", "Canvas::saveLayer");
context.internal_nodes_canvas->saveLayer(paint_bounds(), nullptr);
}
PaintChildren(context);

View File

@@ -58,6 +58,7 @@ void ClipRectLayer::Paint(PaintContext& context) const {
clip_behavior_ != Clip::hardEdge);
if (UsesSaveLayer()) {
TRACE_EVENT0("flutter", "Canvas::saveLayer");
context.internal_nodes_canvas->saveLayer(clip_rect_, nullptr);
}
PaintChildren(context);

View File

@@ -59,6 +59,7 @@ void ClipRRectLayer::Paint(PaintContext& context) const {
clip_behavior_ != Clip::hardEdge);
if (UsesSaveLayer()) {
TRACE_EVENT0("flutter", "Canvas::saveLayer");
context.internal_nodes_canvas->saveLayer(paint_bounds(), nullptr);
}
PaintChildren(context);

View File

@@ -97,10 +97,11 @@ void PhysicalShapeLayer::Paint(PaintContext& context) const {
case Clip::antiAlias:
context.internal_nodes_canvas->clipPath(path_, true);
break;
case Clip::antiAliasWithSaveLayer:
case Clip::antiAliasWithSaveLayer: {
TRACE_EVENT0("flutter", "Canvas::saveLayer");
context.internal_nodes_canvas->clipPath(path_, true);
context.internal_nodes_canvas->saveLayer(paint_bounds(), nullptr);
break;
} break;
case Clip::none:
break;
}

View File

@@ -105,6 +105,7 @@ void Canvas::saveLayerWithoutBounds(const Paint& paint,
if (!canvas_) {
return;
}
TRACE_EVENT0("flutter", "Canvas::saveLayer");
canvas_->saveLayer(nullptr, paint.paint());
}
@@ -117,6 +118,7 @@ void Canvas::saveLayer(double left,
if (!canvas_) {
return;
}
TRACE_EVENT0("flutter", "Canvas::saveLayer");
SkRect bounds = SkRect::MakeLTRB(left, top, right, bottom);
canvas_->saveLayer(&bounds, paint.paint());
}

View File

@@ -4,7 +4,10 @@
import("//flutter/testing/dart/compile_test.gni")
tests = [ "skp_test.dart" ]
tests = [
"skp_test.dart",
"tracing_test.dart",
]
foreach(test, tests) {
compile_flutter_dart_test("compile_$test") {

View File

@@ -0,0 +1,59 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'dart:developer' as developer;
import 'dart:ui';
import 'package:litetest/litetest.dart';
import 'package:vm_service/vm_service.dart' as vms;
import 'package:vm_service/vm_service_io.dart';
void main() {
test('Canvas.saveLayer emits tracing', () async {
final developer.ServiceProtocolInfo info = await developer.Service.getInfo();
if (info.serverUri == null) {
fail('This test must not be run with --disable-observatory.');
}
final vms.VmService vmService = await vmServiceConnectUri(
'ws://localhost:${info.serverUri!.port}${info.serverUri!.path}ws',
);
final Completer<void> completer = Completer<void>();
window.onBeginFrame = (Duration timeStamp) {
final PictureRecorder recorder = PictureRecorder();
final Canvas canvas = Canvas(recorder);
canvas.saveLayer(null, Paint());
canvas.saveLayer(const Rect.fromLTWH(0, 0, 100, 100), Paint());
canvas.drawRect(const Rect.fromLTRB(10, 10, 20, 20), Paint());
canvas.restore();
canvas.restore();
final Picture picture = recorder.endRecording();
final SceneBuilder builder = SceneBuilder();
builder.addPicture(Offset.zero, picture);
final Scene scene = builder.build();
window.render(scene);
scene.dispose();
completer.complete();
};
window.scheduleFrame();
await completer.future;
final vms.Timeline timeline = await vmService.getVMTimeline();
await vmService.dispose();
int saveLayerCount = 0;
for (final vms.TimelineEvent event in timeline.traceEvents!) {
final Map<String, dynamic> json = event.json!;
if (json['name'] == 'Canvas::saveLayer' && json['ph'] == 'B') {
saveLayerCount += 1;
}
}
expect(saveLayerCount, 2);
});
}