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

Commit 7af5b38

Browse files
Reverts "Add SurfaceProducer#onSurfaceAvailable, deprecate onSurfaceCreated. (#55418)" (#55450)
Reverts: #55418 Initiated by: bdero Reason for reverting: [Engine->Framework roll breakage](flutter/flutter#155727 (comment)) Original PR Author: matanlurey Reviewed By: {jonahwilliams} This change reverts the following previous change: Closes flutter/flutter#155131. Not only did I rename the method, but I also changed the contract slightly - now `onSurfaceAvailable` is _only_ invoked _after_ `onSurfaceDestroyed` has been called. The cost is a single `boolean`, and it honestly makes the API make a lot more sense than someone having to track this themselves. /cc @johnmccutchan (OOO), and @flutter/android-reviewers.
1 parent 7461499 commit 7af5b38

File tree

3 files changed

+12
-71
lines changed

3 files changed

+12
-71
lines changed

shell/platform/android/io/flutter/embedding/engine/renderer/FlutterRenderer.java

+2-11
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,8 @@ public FlutterRenderer(@NonNull FlutterJNI flutterJNI) {
108108
public void onResume(@NonNull LifecycleOwner owner) {
109109
Log.v(TAG, "onResume called; notifying SurfaceProducers");
110110
for (ImageReaderSurfaceProducer producer : imageReaderProducers) {
111-
if (producer.callback != null && producer.notifiedDestroy) {
112-
producer.notifiedDestroy = false;
113-
producer.callback.onSurfaceAvailable();
111+
if (producer.callback != null) {
112+
producer.callback.onSurfaceCreated();
114113
}
115114
}
116115
}
@@ -463,13 +462,6 @@ final class ImageReaderSurfaceProducer
463462
// will be produced at that size.
464463
private boolean createNewReader = true;
465464

466-
/**
467-
* Stores whether {@link Callback#onSurfaceDestroyed()} was previously invoked.
468-
*
469-
* <p>Used to avoid signaling {@link Callback#onSurfaceAvailable()} unnecessarily.
470-
*/
471-
private boolean notifiedDestroy = false;
472-
473465
// State held to track latency of various stages.
474466
private long lastDequeueTime = 0;
475467
private long lastQueueTime = 0;
@@ -697,7 +689,6 @@ public void onTrimMemory(int level) {
697689
cleanup();
698690
createNewReader = true;
699691
if (this.callback != null) {
700-
notifiedDestroy = true;
701692
this.callback.onSurfaceDestroyed();
702693
}
703694
}

shell/platform/android/io/flutter/view/TextureRegistry.java

+9-56
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ interface SurfaceProducer extends TextureEntry {
9696

9797
/**
9898
* Sets a callback that is notified when a previously created {@link Surface} returned by {@link
99-
* SurfaceProducer#getSurface()} is no longer valid due to being destroyed, or a new surface is
100-
* now available (after the previous one was destroyed) for rendering.
99+
* SurfaceProducer#getSurface()} is no longer valid, either due to being destroyed or being
100+
* changed.
101101
*
102102
* @param callback The callback to notify, or null to remove the callback.
103103
*/
@@ -106,65 +106,18 @@ interface SurfaceProducer extends TextureEntry {
106106
/** Callback invoked by {@link #setCallback(Callback)}. */
107107
interface Callback {
108108
/**
109-
* An alias for {@link Callback#onSurfaceAvailable()} with a less accurate name.
110-
*
111-
* @deprecated Override and use {@link Callback#onSurfaceAvailable()} instead.
112-
*/
113-
@Deprecated(since = "Flutter 3.27", forRemoval = true)
114-
default void onSurfaceCreated() {}
115-
116-
/**
117-
* Invoked when an Android application is resumed after {@link Callback#onSurfaceDestroyed()}.
109+
* Invoked when a previous surface is now invalid and a new surface is now available.
118110
*
119-
* <p>Applications should now call {@link SurfaceProducer#getSurface()} to get a new
120-
* {@link Surface}, as the previous one was destroyed and released as a result of a low memory
121-
* event from the Android OS.
122-
*
123-
* <pre>
124-
* {@code
125-
* void example(SurfaceProducer producer) {
126-
* producer.setCallback(new SurfaceProducer.Callback() {
127-
* @override
128-
* public void onSurfaceAvailable() {
129-
* Surface surface = producer.getSurface();
130-
* redrawOrUse(surface);
131-
* }
132-
*
133-
* // ...
134-
* });
135-
* }
136-
* }
137-
* </pre>
111+
* <p>Typically plugins will use this callback as a signal to redraw, such as due to the
112+
* texture being resized, the format being changed, or the application being resumed after
113+
* being suspended in the background.
138114
*/
139-
default void onSurfaceAvailable() {
140-
this.onSurfaceCreated();
141-
}
115+
void onSurfaceCreated();
142116

143117
/**
144-
* Invoked when a {@link Surface} returned by {@link SurfaceProducer#getSurface()} is invalid.
145-
*
146-
* <p>In a low memory environment, the Android OS will signal to Flutter to release resources,
147-
* such as surfaces, that are not currently in use, such as when the application is in the
148-
* background, and this method is subsequently called to notify a plugin author to stop
149-
* using or rendering to the last surface.
150-
*
151-
* <p>Use {@link Callback#onSurfaceAvailable()} to be notified to resume rendering.
152-
*
153-
* <pre>
154-
* {@code
155-
* void example(SurfaceProducer producer) {
156-
* producer.setCallback(new SurfaceProducer.Callback() {
157-
* @override
158-
* public void onSurfaceDestroyed() {
159-
* // Store information about the last frame, if necessary.
160-
* // Potentially release other dependent resources.
161-
* }
118+
* Invoked when a previous surface is now invalid.
162119
*
163-
* // ...
164-
* });
165-
* }
166-
* }
167-
* </pre>
120+
* <p>Typically plugins will use this callback as a signal to release resources.
168121
*/
169122
void onSurfaceDestroyed();
170123
}

shell/platform/android/test/io/flutter/embedding/engine/renderer/FlutterRendererTest.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ public void ImageReaderSurfaceProducerIsCreatedOnLifecycleResume() throws Except
785785
TextureRegistry.SurfaceProducer.Callback callback =
786786
new TextureRegistry.SurfaceProducer.Callback() {
787787
@Override
788-
public void onSurfaceAvailable() {
788+
public void onSurfaceCreated() {
789789
latch.countDown();
790790
}
791791

@@ -794,9 +794,6 @@ public void onSurfaceDestroyed() {}
794794
};
795795
producer.setCallback(callback);
796796

797-
// Trim memory.
798-
((FlutterRenderer.ImageReaderSurfaceProducer) producer).onTrimMemory(40);
799-
800797
// Trigger a resume.
801798
((LifecycleRegistry) ProcessLifecycleOwner.get().getLifecycle())
802799
.setCurrentState(Lifecycle.State.RESUMED);

0 commit comments

Comments
 (0)