This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
separate saveLayer events into record and execute variants and trace more of the execution calls #29598
Merged
fluttergithubbot
merged 2 commits into
flutter:master
from
flar:more-save-layer-tracing
Nov 10, 2021
Merged
separate saveLayer events into record and execute variants and trace more of the execution calls #29598
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,9 +23,11 @@ void main() { | |
| ); | ||
|
|
||
| final Completer<void> completer = Completer<void>(); | ||
| window.onBeginFrame = (Duration timeStamp) { | ||
| window.onBeginFrame = (Duration timeStamp) async { | ||
| final PictureRecorder recorder = PictureRecorder(); | ||
| final Canvas canvas = Canvas(recorder); | ||
| canvas.drawColor(const Color(0xff0000ff), BlendMode.srcOut); | ||
| canvas.drawPaint(Paint()..imageFilter = ImageFilter.blur(sigmaX: 2, sigmaY: 3)); | ||
| canvas.saveLayer(null, Paint()); | ||
| canvas.saveLayer(const Rect.fromLTWH(0, 0, 100, 100), Paint()); | ||
| canvas.drawRect(const Rect.fromLTRB(10, 10, 20, 20), Paint()); | ||
|
|
@@ -37,7 +39,7 @@ void main() { | |
| builder.addPicture(Offset.zero, picture); | ||
| final Scene scene = builder.build(); | ||
|
|
||
| window.render(scene); | ||
| await scene.toImage(100, 100); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: add a comment about why we're doing this |
||
| scene.dispose(); | ||
| completer.complete(); | ||
| }; | ||
|
|
@@ -47,13 +49,20 @@ void main() { | |
| final vms.Timeline timeline = await vmService.getVMTimeline(); | ||
| await vmService.dispose(); | ||
|
|
||
| int saveLayerRecordCount = 0; | ||
| 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; | ||
| if (json['ph'] == 'B') { | ||
| if (json['name'] == 'ui.Canvas::saveLayer (Recorded)') { | ||
| saveLayerRecordCount += 1; | ||
| } | ||
| if (json['name'] == 'Canvas::saveLayer') { | ||
| saveLayerCount += 1; | ||
| } | ||
| } | ||
| } | ||
| expect(saveLayerCount, 2); | ||
| expect(saveLayerRecordCount, 3); | ||
| expect(saveLayerCount, 3); | ||
| }); | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may also want to capture when drawPaint and draw color will insert a save layer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like there is a public way to determine if the drawPaint will use a saveLayer so I'm adding that. (It's only when there is an ImageFilter, though, so it probably won't happen much in practice.)
drawColor doesn't show any signs of using a saveLayer, though. The operation becomes a drawPaint with no ImageFilter which never generates a saveLayer in the Skia code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should probably also mark it as recorded when I record the drawPaint. Should that be the same event name as when we record saveLayer? Or modified slightly - like "(drawPaint Recorded)" to distinguish it so that developers can know to look for a drawPaint call instead of a saveLayer. Or "ui.Canvas::drawPaint (Recorded needing saveLayer)" or something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. I know the method name has something about ImageFilters in its return type, but when I was tracing through the code it looked like the surface could decide to trigger a savelayer with or without an image filter... Specifically I'm looking at these sites:
https://github.com/google/skia/blob/6a5f772ea6f0f689b32e9dbdb78f6a24963f524a/src/core/SkCanvas.cpp#L1750 eventually ends up in https://github.com/google/skia/blob/6a5f772ea6f0f689b32e9dbdb78f6a24963f524a/src/core/SkCanvas.cpp#L170 and then https://github.com/google/skia/blob/6a5f772ea6f0f689b32e9dbdb78f6a24963f524a/src/core/SkCanvas.cpp#L170
What's the part that I'm missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those last 2 lines are the same. The one that determines whether to add a saveLayer is:
https://github.com/google/skia/blob/6a5f772ea6f0f689b32e9dbdb78f6a24963f524a/src/core/SkCanvas.cpp#L311
And that's the one I model in the (new) code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, tha tlast link was supposed to be https://github.com/google/skia/blob/main/src/image/SkSurface.cpp#L120
But now I see the part you linked and it all makes sense. Ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think that call can reject the operation entirely, but the actual saveLayer happens in their ...Auto... object.