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 SurfaceProducer#onSurfaceAvailable
, deprecate onSurfaceCreated
.
#55418
Merged
Merged
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,8 +96,8 @@ interface SurfaceProducer extends TextureEntry { | |
|
||
/** | ||
* Sets a callback that is notified when a previously created {@link Surface} returned by {@link | ||
* SurfaceProducer#getSurface()} is no longer valid, either due to being destroyed or being | ||
* changed. | ||
* SurfaceProducer#getSurface()} is no longer valid due to being destroyed, or a new surface is | ||
* now available (after the previous one was destroyed) for rendering. | ||
* | ||
* @param callback The callback to notify, or null to remove the callback. | ||
*/ | ||
|
@@ -106,18 +106,65 @@ interface SurfaceProducer extends TextureEntry { | |
/** Callback invoked by {@link #setCallback(Callback)}. */ | ||
interface Callback { | ||
/** | ||
* Invoked when a previous surface is now invalid and a new surface is now available. | ||
* An alias for {@link Callback#onSurfaceAvailable()} with a less accurate name. | ||
* | ||
* @deprecated Override and use {@link Callback#onSurfaceAvailable()} instead. | ||
*/ | ||
@Deprecated(since = "Flutter 3.27", forRemoval = true) | ||
default void onSurfaceCreated() {} | ||
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. default? 🤔 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. Basically let folks who haven't used SurfaceProducer.Callback not have to define both methods. |
||
|
||
/** | ||
* Invoked when an Android application is resumed after {@link Callback#onSurfaceDestroyed()}. | ||
* | ||
* <p>Typically plugins will use this callback as a signal to redraw, such as due to the | ||
* texture being resized, the format being changed, or the application being resumed after | ||
* being suspended in the background. | ||
* <p>Applications should now call {@link SurfaceProducer#getSurface()} to get a new | ||
* {@link Surface}, as the previous one was destroyed and released as a result of a low memory | ||
* event from the Android OS. | ||
* | ||
* <pre> | ||
* {@code | ||
* void example(SurfaceProducer producer) { | ||
* producer.setCallback(new SurfaceProducer.Callback() { | ||
* @override | ||
* public void onSurfaceAvailable() { | ||
* Surface surface = producer.getSurface(); | ||
* redrawOrUse(surface); | ||
* } | ||
* | ||
* // ... | ||
* }); | ||
* } | ||
* } | ||
* </pre> | ||
*/ | ||
void onSurfaceCreated(); | ||
default void onSurfaceAvailable() { | ||
this.onSurfaceCreated(); | ||
} | ||
|
||
/** | ||
* Invoked when a previous surface is now invalid. | ||
* Invoked when a {@link Surface} returned by {@link SurfaceProducer#getSurface()} is invalid. | ||
* | ||
* <p>In a low memory environment, the Android OS will signal to Flutter to release resources, | ||
* such as surfaces, that are not currently in use, such as when the application is in the | ||
* background, and this method is subsequently called to notify a plugin author to stop | ||
* using or rendering to the last surface. | ||
* | ||
* <p>Use {@link Callback#onSurfaceAvailable()} to be notified to resume rendering. | ||
* | ||
* <pre> | ||
* {@code | ||
* void example(SurfaceProducer producer) { | ||
* producer.setCallback(new SurfaceProducer.Callback() { | ||
* @override | ||
* public void onSurfaceDestroyed() { | ||
* // Store information about the last frame, if necessary. | ||
* // Potentially release other dependent resources. | ||
* } | ||
* | ||
* <p>Typically plugins will use this callback as a signal to release resources. | ||
* // ... | ||
* }); | ||
* } | ||
* } | ||
* </pre> | ||
*/ | ||
void onSurfaceDestroyed(); | ||
} | ||
|
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.
So this check ensures that we don't fire the callback multiple times if the surface wasn't prev destroyed. Makes sense!