camera/camera-testing/src/main/java/androidx/camera/testing/SurfaceTextureProvider.java
/**
     * Creates a {@link Preview.SurfaceProvider} that is backed by a {@link SurfaceTexture}.
     *
     * <p>This is a convenience method for creating a {@link Preview.SurfaceProvider}
     * whose {@link Surface} is backed by a {@link SurfaceTexture}. The returned
     * {@link Preview.SurfaceProvider} is responsible for creating the
     * {@link SurfaceTexture}. The {@link SurfaceTexture} may not be safe to use with
     * {@link TextureView}
     * Example:
     *
     * <pre><code>
     * preview.setSurfaceProvider(createSurfaceTextureProvider(
     *         new SurfaceTextureProvider.SurfaceTextureCallback() {
     *             &#64;Override
     *             public void onSurfaceTextureReady(@NonNull SurfaceTexture surfaceTexture) {
     *                 // Use the SurfaceTexture
     *             }
     *
     *             &#64;Override
     *             public void onSafeToRelease(@NonNull SurfaceTexture surfaceTexture) {
     *                 surfaceTexture.release();
     *             }
     *         }));
     * </code></pre>
     *
     * @param surfaceTextureCallback callback called when the SurfaceTexture is ready to be
     *                               set/released.
     * @return a {@link Preview.SurfaceProvider} to be used with
     * {@link Preview#setSurfaceProvider(Preview.SurfaceProvider)}.
     */
Creates a  Preview.SurfaceProvider that is backed by a  SurfaceTexture.
This is a convenience method for creating a  Preview.SurfaceProvider
whose  Surface is backed by a  SurfaceTexture. The returned
Preview.SurfaceProvider is responsible for creating the
SurfaceTexture. The  SurfaceTexture may not be safe to use with
TextureView
Example.



@Override
public void onSafeToRelease(@NonNull SurfaceTexture surfaceTexture) {
surfaceTexture.release();
}
}));


@param surfaceTextureCallback callback called when the SurfaceTexture is ready to be
set/released.
Creates a Preview . SurfaceProvider that is backed by a SurfaceTexture . This is a convenience method for creating a Preview . SurfaceProvider whose Surface is backed by a SurfaceTexture . The returned Preview . SurfaceProvider is responsible for creating the SurfaceTexture . The SurfaceTexture may not be safe to use with TextureView Example . @Override public void onSafeToRelease ( @NonNull SurfaceTexture surfaceTexture ) { surfaceTexture . release () ; } } )) ; @param surfaceTextureCallback callback called when the SurfaceTexture is ready to be set / released .
@NonNull
    public static Preview.SurfaceProvider createSurfaceTextureProvider(
            @NonNull SurfaceTextureCallback surfaceTextureCallback) {
        return (surfaceRequest) -> {
            SurfaceTexture surfaceTexture = new SurfaceTexture(0);
            surfaceTexture.setDefaultBufferSize(surfaceRequest.getResolution().getWidth(),
                    surfaceRequest.getResolution().getHeight());
            surfaceTexture.detachFromGLContext();
            surfaceTextureCallback.onSurfaceTextureReady(surfaceTexture,
                    surfaceRequest.getResolution());
            Surface surface = new Surface(surfaceTexture);
            surfaceRequest.provideSurface(surface,
                    CameraXExecutors.directExecutor(),
                    (surfaceResponse) -> {
                        surface.release();
                        surfaceTextureCallback.onSafeToRelease(surfaceTexture);
                    });
        };
    }
@ NonNull public static Preview . SurfaceProvider createSurfaceTextureProvider ( @ NonNull SurfaceTextureCallback surfaceTextureCallback ) { return ( surfaceRequest ) -> { SurfaceTexture surfaceTexture = new SurfaceTexture ( 0 ) ; surfaceTexture . setDefaultBufferSize ( surfaceRequest . getResolution ( ) . getWidth ( ) , surfaceRequest . getResolution ( ) . getHeight ( ) ) ; surfaceTexture . detachFromGLContext ( ) ; surfaceTextureCallback . onSurfaceTextureReady ( surfaceTexture , surfaceRequest . getResolution ( ) ) ; Surface surface = new Surface ( surfaceTexture ) ; surfaceRequest . provideSurface ( surface , CameraXExecutors . directExecutor ( ) , ( surfaceResponse ) -> { surface . release ( ) ; surfaceTextureCallback . onSafeToRelease ( surfaceTexture ) ; } ) ; } ; }
Creates a {@link Preview.SurfaceProvider} that is backed by a {@link SurfaceTexture}.
Creates a { @link Preview . SurfaceProvider } that is backed by a { @link SurfaceTexture } .