ViewfinderSurfaceRequest


class ViewfinderSurfaceRequest


The request to get a Surface to display viewfinder input.

This request contains requirements for the surface resolution and viewfinder input and output information.

Calling ViewfinderSurfaceRequest.markSurfaceSafeToRelease will notify the surface provider that the surface is not needed and related resources can be released.

Creates a new surface request with surface resolution, viewfinder input and output information.

Summary

Nested types

Builder for ViewfinderSurfaceRequest.

Result of providing a surface to a ViewfinderSurfaceRequest via .provideSurface.

Constants

const Int

Horizontal mirror transform needs to be applied to the viewfinder output.

const Int

No mirror transform needs to be applied to the viewfinder output.

Public functions

suspend Surface

Retrieves the Surface provided to the ViewfinderSurfaceRequest.

ListenableFuture<Surface>

Retrieves the Surface provided to the ViewfinderSurfaceRequest.

Unit

Closes the viewfinder surface to mark it as safe to release.

Unit
provideSurface(
    surface: Surface,
    executor: Executor,
    resultListener: Consumer<ViewfinderSurfaceRequest.Result?>
)

Completes the request for a Surface if it has not already been completed or cancelled.

Boolean

Signals that the request will never be fulfilled.

Public properties

ImplementationMode?

The {@link ImplementationMode} to apply to the viewfinder.

Int

The viewfinder output mirror mode.

Size

The requested surface resolution.

Int

The viewfinder source orientation.

Constants

MIRROR_MODE_HORIZONTAL

const val MIRROR_MODE_HORIZONTAL = 1: Int

Horizontal mirror transform needs to be applied to the viewfinder output.

The mirror transform should be applied in display coordinate.

MIRROR_MODE_NONE

const val MIRROR_MODE_NONE = 0: Int

No mirror transform needs to be applied to the viewfinder output.

Public functions

getSurface

suspend fun getSurface(): Surface

Retrieves the Surface provided to the ViewfinderSurfaceRequest.

This can be used to get access to the Surface that's provided to the ViewfinderSurfaceRequest.

If the application is shutting down and a Surface will never be provided, this will throw a kotlinx.coroutines.CancellationException.

The returned Surface must not be used after markSurfaceSafeToRelease has been called.

getSurfaceAsync

Added in 1.4.0-alpha05
fun getSurfaceAsync(): ListenableFuture<Surface>

Retrieves the Surface provided to the ViewfinderSurfaceRequest.

This can be used to get access to the Surface that's provided to the ViewfinderSurfaceRequest.

If the application is shutting down and a Surface will never be provided, the ListenableFuture will fail with a CancellationException.

The returned Surface must not be used after markSurfaceSafeToRelease has been called.

markSurfaceSafeToRelease

Added in 1.4.0-alpha05
fun markSurfaceSafeToRelease(): Unit

Closes the viewfinder surface to mark it as safe to release.

This method should be called by the user when the requested surface is not needed and related resources can be released.

provideSurface

Added in 1.4.0-alpha05
fun provideSurface(
    surface: Surface,
    executor: Executor,
    resultListener: Consumer<ViewfinderSurfaceRequest.Result?>
): Unit

Completes the request for a Surface if it has not already been completed or cancelled.

Once the producer no longer needs the provided surface, the resultListener will be invoked with a Result containing Result.RESULT_SURFACE_USED_SUCCESSFULLY. At this point it is safe to release the surface and any underlying resources. Releasing the surface before receiving this signal may cause undesired behavior on lower API levels.

If the request is cancelled by the producer before successfully attaching the provided surface to the producer, then the resultListener will be invoked with a Result containing Result.RESULT_REQUEST_CANCELLED.

If the request was previously completed via .willNotProvideSurface, then resultListener will be invoked with a Result containing Result.RESULT_WILL_NOT_PROVIDE_SURFACE.

Upon returning from this method, the surface request is guaranteed to be complete. However, only the resultListener provided to the first invocation of this method should be used to track when the provided Surface is no longer in use by the producer, as subsequent invocations will always invoke the resultListener with a Result containing Result.RESULT_SURFACE_ALREADY_PROVIDED.

Parameters
surface: Surface

The surface which will complete the request.

executor: Executor

Executor used to execute the resultListener.

resultListener: Consumer<ViewfinderSurfaceRequest.Result?>

Listener used to track how the surface is used by the producer in response to being provided by this method.

willNotProvideSurface

Added in 1.4.0-alpha05
fun willNotProvideSurface(): Boolean

Signals that the request will never be fulfilled.

This may be called in the case where the application may be shutting down and a surface will never be produced to fulfill the request.

This will be called by the producer as soon as it is known that the request will not be fulfilled. Failure to complete the SurfaceRequest via willNotProvideSurface() or .provideSurface may cause long delays in shutting down the producer.

Upon returning from this method, the request is guaranteed to be complete, regardless of the return value. If the request was previously successfully completed by .provideSurface, invoking this method will return false, and will have no effect on how the surface is used by the producer.

Returns
Boolean

true if this call to willNotProvideSurface() successfully completes the request, i.e., the request has not already been completed via .provideSurface or by a previous call to willNotProvideSurface() and has not already been cancelled by the producer.

Public properties

implementationMode

Added in 1.4.0-alpha05
val implementationModeImplementationMode?

The {@link ImplementationMode} to apply to the viewfinder.

outputMirrorMode

Added in 1.4.0-alpha05
val outputMirrorModeInt

The viewfinder output mirror mode.

resolution

Added in 1.4.0-alpha05
val resolutionSize

The requested surface resolution.

sourceOrientation

Added in 1.4.0-alpha05
val sourceOrientationInt

The viewfinder source orientation.