Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 707b922

Browse files
authored
separate saveLayer events into record and execute variants and trace more of the execution calls (#29598)
1 parent 6ed34e8 commit 707b922

File tree

4 files changed

+41
-10
lines changed

4 files changed

+41
-10
lines changed

flow/display_list_canvas.cc

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ void DisplayListCanvasDispatcher::restore() {
1919
}
2020
void DisplayListCanvasDispatcher::saveLayer(const SkRect* bounds,
2121
bool restore_with_paint) {
22+
TRACE_EVENT0("flutter", "Canvas::saveLayer");
2223
canvas_->saveLayer(bounds, restore_with_paint ? &paint() : nullptr);
2324
}
2425

@@ -76,7 +77,14 @@ void DisplayListCanvasDispatcher::clipPath(const SkPath& path,
7677
}
7778

7879
void DisplayListCanvasDispatcher::drawPaint() {
79-
canvas_->drawPaint(paint());
80+
const SkPaint& sk_paint = paint();
81+
SkImageFilter* filter = sk_paint.getImageFilter();
82+
if (filter && !filter->asColorFilter(nullptr)) {
83+
// drawPaint does an implicit saveLayer if an SkImageFilter is
84+
// present that cannot be replaced by an SkColorFilter.
85+
TRACE_EVENT0("flutter", "Canvas::saveLayer");
86+
}
87+
canvas_->drawPaint(sk_paint);
8088
}
8189
void DisplayListCanvasDispatcher::drawColor(SkColor color, SkBlendMode mode) {
8290
canvas_->drawColor(color, mode);
@@ -170,8 +178,13 @@ void DisplayListCanvasDispatcher::drawAtlas(const sk_sp<SkImage> atlas,
170178
void DisplayListCanvasDispatcher::drawPicture(const sk_sp<SkPicture> picture,
171179
const SkMatrix* matrix,
172180
bool render_with_attributes) {
173-
canvas_->drawPicture(picture, matrix,
174-
render_with_attributes ? &paint() : nullptr);
181+
if (render_with_attributes) {
182+
// drawPicture does an implicit saveLayer if an SkPaint is supplied.
183+
TRACE_EVENT0("flutter", "Canvas::saveLayer");
184+
canvas_->drawPicture(picture, matrix, &paint());
185+
} else {
186+
canvas_->drawPicture(picture, matrix, nullptr);
187+
}
175188
}
176189
void DisplayListCanvasDispatcher::drawDisplayList(
177190
const sk_sp<DisplayList> display_list) {

flow/layers/layer.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ Layer::AutoSaveLayer::AutoSaveLayer(const PaintContext& paint_context,
6565
canvas_(save_mode == SaveMode::kInternalNodesCanvas
6666
? *(paint_context.internal_nodes_canvas)
6767
: *(paint_context.leaf_nodes_canvas)) {
68+
TRACE_EVENT0("flutter", "Canvas::saveLayer");
6869
canvas_.saveLayer(bounds_, paint);
6970
}
7071

@@ -76,6 +77,7 @@ Layer::AutoSaveLayer::AutoSaveLayer(const PaintContext& paint_context,
7677
canvas_(save_mode == SaveMode::kInternalNodesCanvas
7778
? *(paint_context.internal_nodes_canvas)
7879
: *(paint_context.leaf_nodes_canvas)) {
80+
TRACE_EVENT0("flutter", "Canvas::saveLayer");
7981
canvas_.saveLayer(layer_rec);
8082
}
8183

lib/ui/painting/canvas.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ void Canvas::saveLayerWithoutBounds(const Paint& paint,
105105
if (!canvas_) {
106106
return;
107107
}
108-
TRACE_EVENT0("flutter", "Canvas::saveLayer");
108+
TRACE_EVENT0("flutter", "ui.Canvas::saveLayer (Recorded)");
109109
canvas_->saveLayer(nullptr, paint.paint());
110110
}
111111

@@ -118,7 +118,7 @@ void Canvas::saveLayer(double left,
118118
if (!canvas_) {
119119
return;
120120
}
121-
TRACE_EVENT0("flutter", "Canvas::saveLayer");
121+
TRACE_EVENT0("flutter", "ui.Canvas::saveLayer (Recorded)");
122122
SkRect bounds = SkRect::MakeLTRB(left, top, right, bottom);
123123
canvas_->saveLayer(&bounds, paint.paint());
124124
}
@@ -230,6 +230,13 @@ void Canvas::drawPaint(const Paint& paint, const PaintData& paint_data) {
230230
if (!canvas_) {
231231
return;
232232
}
233+
const SkPaint* sk_paint = paint.paint();
234+
SkImageFilter* filter = sk_paint->getImageFilter();
235+
if (filter && !filter->asColorFilter(nullptr)) {
236+
// drawPaint does an implicit saveLayer if an SkImageFilter is
237+
// present that cannot be replaced by an SkColorFilter.
238+
TRACE_EVENT0("flutter", "ui.Canvas::saveLayer (Recorded)");
239+
}
233240
canvas_->drawPaint(*paint.paint());
234241
}
235242

testing/dart/observatory/tracing_test.dart

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ void main() {
2323
);
2424

2525
final Completer<void> completer = Completer<void>();
26-
window.onBeginFrame = (Duration timeStamp) {
26+
window.onBeginFrame = (Duration timeStamp) async {
2727
final PictureRecorder recorder = PictureRecorder();
2828
final Canvas canvas = Canvas(recorder);
29+
canvas.drawColor(const Color(0xff0000ff), BlendMode.srcOut);
30+
canvas.drawPaint(Paint()..imageFilter = ImageFilter.blur(sigmaX: 2, sigmaY: 3));
2931
canvas.saveLayer(null, Paint());
3032
canvas.saveLayer(const Rect.fromLTWH(0, 0, 100, 100), Paint());
3133
canvas.drawRect(const Rect.fromLTRB(10, 10, 20, 20), Paint());
@@ -37,7 +39,7 @@ void main() {
3739
builder.addPicture(Offset.zero, picture);
3840
final Scene scene = builder.build();
3941

40-
window.render(scene);
42+
await scene.toImage(100, 100);
4143
scene.dispose();
4244
completer.complete();
4345
};
@@ -47,13 +49,20 @@ void main() {
4749
final vms.Timeline timeline = await vmService.getVMTimeline();
4850
await vmService.dispose();
4951

52+
int saveLayerRecordCount = 0;
5053
int saveLayerCount = 0;
5154
for (final vms.TimelineEvent event in timeline.traceEvents!) {
5255
final Map<String, dynamic> json = event.json!;
53-
if (json['name'] == 'Canvas::saveLayer' && json['ph'] == 'B') {
54-
saveLayerCount += 1;
56+
if (json['ph'] == 'B') {
57+
if (json['name'] == 'ui.Canvas::saveLayer (Recorded)') {
58+
saveLayerRecordCount += 1;
59+
}
60+
if (json['name'] == 'Canvas::saveLayer') {
61+
saveLayerCount += 1;
62+
}
5563
}
5664
}
57-
expect(saveLayerCount, 2);
65+
expect(saveLayerRecordCount, 3);
66+
expect(saveLayerCount, 3);
5867
});
5968
}

0 commit comments

Comments
 (0)