@@ -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, either due to being destroyed or being
100- * changed .
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 .
101101 *
102102 * @param callback The callback to notify, or null to remove the callback.
103103 */
@@ -106,18 +106,65 @@ interface SurfaceProducer extends TextureEntry {
106106 /** Callback invoked by {@link #setCallback(Callback)}. */
107107 interface Callback {
108108 /**
109- * Invoked when a previous surface is now invalid and a new surface is now available.
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()}.
110118 *
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.
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>
114138 */
115- void onSurfaceCreated ();
139+ default void onSurfaceAvailable () {
140+ this .onSurfaceCreated ();
141+ }
116142
117143 /**
118- * Invoked when a previous surface is now invalid.
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+ * }
119162 *
120- * <p>Typically plugins will use this callback as a signal to release resources.
163+ * // ...
164+ * });
165+ * }
166+ * }
167+ * </pre>
121168 */
122169 void onSurfaceDestroyed ();
123170 }
0 commit comments