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
Add function restoreToCount to Canvas. #35798
Merged
Merged
Changes from 4 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7c55c6b
Add function restoreToCount to Canvas.
guoguo338 86cc918
Change type from size_t to int
guoguo338 bdf23aa
Add restoreToCount to web
guoguo338 71ac13b
Merge branch 'flutter:main' into restoreToCount
guoguo338 21cad6c
Add more corner case test.
guoguo338 be229c2
Merge branch 'flutter:main' into restoreToCount
guoguo338 01199f3
add more comments.
guoguo338 bcd26dd
Merge branch 'restoreToCount' of github.com:guoguo338/engine into res…
guoguo338 371593c
Do some code refine.
guoguo338 762ef01
fix comment
guoguo338 c9962c7
code refine.
guoguo338 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4691,6 +4691,16 @@ class Canvas extends NativeFieldWrapperClass1 { | |
| @FfiNative<Void Function(Pointer<Void>)>('Canvas::restore', isLeaf: true) | ||
| external void restore(); | ||
|
|
||
| /// Pops the save stack until the count layer, if there is anything to pop. | ||
| /// Otherwise, does nothing. | ||
| /// | ||
| /// Use [save] and [saveLayer] to push state onto the stack. | ||
| /// | ||
| /// If the state was pushed with [saveLayer], then this call will also | ||
|
||
| /// cause the new layer to be composited into the previous layer. | ||
| @FfiNative<Void Function(Pointer<Void>, Int32)>('Canvas::restoreToCount', isLeaf: true) | ||
| external void restoreToCount(int count); | ||
|
|
||
| /// Returns the number of items on the save stack, including the | ||
| /// initial state. This means it returns 1 for a clean canvas, and | ||
| /// that each call to [save] and [saveLayer] increments it, and that | ||
|
|
||
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
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
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.
Add a comment about how this relates to getSaveCount(). Something along the lines of "the count layer that was previously retrieved with [getSaveCount]" or "After this method completes, the [count] should match the return value of [getSaveCount]".
Also, describe what happens if count > getSaveCount(). I believe it just gets ignored, but we should document that.
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.
How about:
I hinted at what happens with a negative count and also implied that the initial save count is 1 (is that true?) - perhaps we should add a test that verifies these behaviors. I believe that one of the web implementations may not be protected against restoring too far which means that behavior will end up blowing up compared to the other implementations (check that restore protects against an empty stack and also that restoreToCount of values less than 1 all behave the same on all platforms).
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.
Get that, I have added test to cover those corner cases.