Skip to content

Conversation

@matanlurey
Copy link
Contributor

Follow-up to #160937 (#160933).

This more or less mirrors what we did already for onSurfaceCreated to match onSurfaceAvailable.

With this approach, the master branch should immediately start seeing better behavior in terms of being able to use the onSurfaceDestroyed callback effectively (before the surface has been released). For example, for a plugin that already uses onSurfaceDestroyed, i.e camerax:

@Override
public void onSurfaceDestroyed() {
  // Invalidate the SurfaceRequest so that CameraX knows to to make a new request
  // for a surface.
  request.invalidate();
}

... the request is now invalidated before the surface has been destroyed, which is what (I believe) we wanted?


Folks that want to publish package updates that definitely use the correct timing will have to wait for the next stable.

/cc @hasali19 would be great to get your input here.

@github-actions github-actions bot added platform-android Android applications specifically engine flutter/engine related. See also e: labels. labels Jan 7, 2025
* </pre>
*/
default void onSurfaceCleanup() {}
default void onSurfaceCleanup() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be in control of the call to onSurfaceDestroyed?

Seems confusing that if I override onSurfaceCleanup that this other life cycle method stops firing.

On the other hand, it's nice that if you use onSurfaceCleanup you don't have to worry about what to do with onSurfaceDestroyed because it won't ever be called.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should at least document this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, and applied to created/available as well for consistency,

@hasali19
Copy link

hasali19 commented Jan 7, 2025

This looks good to me. I believe it should solve the video player issue, though I'm not familiar with camerax.

@matanlurey matanlurey added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 7, 2025
@auto-submit auto-submit bot added this pull request to the merge queue Jan 7, 2025
Merged via the queue into flutter:master with commit 9467677 Jan 7, 2025
180 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jan 7, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 7, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 8, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 8, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 8, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 8, 2025
srujzs pushed a commit to srujzs/flutter that referenced this pull request Jan 12, 2025
…utter#161252)

Follow-up to flutter#160937
(flutter#160933).

This more or less mirrors what we did already for `onSurfaceCreated` to
match `onSurfaceAvailable`.

With this approach, the master branch should immediately start seeing
better behavior in terms of being able to use the `onSurfaceDestroyed`
callback effectively (before the surface has been released). For
example, for a plugin that already uses `onSurfaceDestroyed`, [i.e
`camerax`](https://github.com/flutter/packages/blob/97ce56a68eea650dc784617b4eed7814cccedeb8/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/PreviewHostApiImpl.java):

```java
@OverRide
public void onSurfaceDestroyed() {
  // Invalidate the SurfaceRequest so that CameraX knows to to make a new request
  // for a surface.
  request.invalidate();
}
```

... the request is now invalidated _before_ the surface has been
destroyed, which is what (I believe) we wanted?

---

Folks that want to publish package updates that _definitely_ use the
correct timing will have to wait for the next stable.

/cc @hasali19 would be great to get your input here.
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 12, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 13, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 13, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

engine flutter/engine related. See also e: labels. platform-android Android applications specifically

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants