Added in API level 31

AttachedSurfaceControl


interface AttachedSurfaceControl
android.view.AttachedSurfaceControl

Provides an interface to the root-Surface of a View Hierarchy or Window. This is used in combination with the android.view.SurfaceControl API to enable attaching app created SurfaceControl to the SurfaceControl hierarchy used by the app, and enable SurfaceTransactions to be performed in sync with the View hierarchy drawing. This object is obtained from android.view.View#getRootSurfaceControl and android.view.Window#getRootSurfaceControl. It must be used from the UI thread of the object it was obtained from.

Summary

Nested classes
abstract

Buffer transform hint change listener.

Public methods
open Unit

Registers a OnBufferTransformHintChangedListener to receive notifications about when the transform hint changes.

abstract Boolean

Consume the passed in transaction, and request the View hierarchy to apply it atomically with the next draw.

abstract SurfaceControl.Transaction?

Create a transaction which will reparent {@param child} to the View hierarchy root SurfaceControl.

open Int

The transform hint can be used by a buffer producer to pre-rotate the rendering such that the final transformation in the system composer is identity.

open InputTransferToken

Gets the token used for associating this AttachedSurfaceControl with an embedded SurfaceControlViewHost or SurfaceControl

open Unit

Unregisters a OnBufferTransformHintChangedListener.

open Unit

Set a crop region on all children parented to the layer represented by this AttachedSurfaceControl.

open Unit

Sets the touchable region for this SurfaceControl, expressed in surface local coordinates.

Public methods

addOnBufferTransformHintChangedListener

Added in API level 32
open fun addOnBufferTransformHintChangedListener(listener: AttachedSurfaceControl.OnBufferTransformHintChangedListener): Unit

Registers a OnBufferTransformHintChangedListener to receive notifications about when the transform hint changes.

Parameters
listener AttachedSurfaceControl.OnBufferTransformHintChangedListener: This value cannot be null.

applyTransactionOnDraw

Added in API level 31
abstract fun applyTransactionOnDraw(t: SurfaceControl.Transaction): Boolean

Consume the passed in transaction, and request the View hierarchy to apply it atomically with the next draw. This transaction will be merged with the buffer transaction from the ViewRoot and they will show up on-screen atomically synced. This will not cause a draw to be scheduled, and if there are no other changes to the View hierarchy you may need to call android.view.View#invalidate

Parameters
t SurfaceControl.Transaction: This value cannot be null.

buildReparentTransaction

Added in API level 31
abstract fun buildReparentTransaction(child: SurfaceControl): SurfaceControl.Transaction?

Create a transaction which will reparent {@param child} to the View hierarchy root SurfaceControl. See SurfaceControl.Transaction.reparent. This transacton must be applied or merged in to another transaction by the caller, otherwise it will have no effect.

Parameters
child SurfaceControl: The SurfaceControl to reparent. This value cannot be null.
Return
SurfaceControl.Transaction? A new transaction which performs the reparent operation when applied. This value may be null.

getBufferTransformHint

Added in API level 32
open fun getBufferTransformHint(): Int

The transform hint can be used by a buffer producer to pre-rotate the rendering such that the final transformation in the system composer is identity. This can be very useful when used in conjunction with the h/w composer HAL in situations where it cannot handle rotations or handle them with an additional power cost. The transform hint should be used with ASurfaceControl APIs when submitting buffers. Example usage: 1. After a configuration change, before dequeuing a buffer, the buffer producer queries the function for the transform hint. 2. The desired buffer width and height is rotated by the transform hint. 3. The producer dequeues a buffer of the new pre-rotated size. 4. The producer renders to the buffer such that the image is already transformed, that is applying the transform hint to the rendering. 5. The producer applies the inverse transform hint to the buffer it just rendered. 6. The producer queues the pre-transformed buffer with the buffer transform. 7. The composer combines the buffer transform with the display transform. If the buffer transform happens to cancel out the display transform then no rotation is needed and there will be no performance penalties. Note, when using ANativeWindow APIs in conjunction with a NativeActivity Surface or SurfaceView Surface, the buffer producer will already have access to the transform hint and no additional work is needed. If the root surface is not available, the API will return BUFFER_TRANSFORM_IDENTITY. The caller should register a listener to listen for any changes. @see addOnBufferTransformHintChangedListener(android.view.AttachedSurfaceControl.OnBufferTransformHintChangedListener). Warning: Calling this API in Android 14 (API Level 34) or earlier will crash if the root surface is not available.

Return
Int Value is android.view.SurfaceControl#BUFFER_TRANSFORM_IDENTITY, android.view.SurfaceControl#BUFFER_TRANSFORM_MIRROR_HORIZONTAL, android.view.SurfaceControl#BUFFER_TRANSFORM_MIRROR_VERTICAL, android.view.SurfaceControl#BUFFER_TRANSFORM_ROTATE_90, android.view.SurfaceControl#BUFFER_TRANSFORM_ROTATE_180, android.view.SurfaceControl#BUFFER_TRANSFORM_ROTATE_270, BUFFER_TRANSFORM_MIRROR_HORIZONTAL | BUFFER_TRANSFORM_ROTATE_90, or BUFFER_TRANSFORM_MIRROR_VERTICAL | BUFFER_TRANSFORM_ROTATE_90

getInputTransferToken

Added in API level 35
open fun getInputTransferToken(): InputTransferToken

Gets the token used for associating this AttachedSurfaceControl with an embedded SurfaceControlViewHost or SurfaceControl

This token should be passed to SurfaceControlViewHost.SurfaceControlViewHost(Context, Display, InputTransferToken) or android.view.WindowManager#registerBatchedSurfaceControlInputReceiver(int,android.window.InputTransferToken,android.view.SurfaceControl,android.view.Choreographer,android.view.SurfaceControlInputReceiver) or android.view.WindowManager#registerUnbatchedSurfaceControlInputReceiver(int,android.window.InputTransferToken,android.view.SurfaceControl,android.os.Looper,android.view.SurfaceControlInputReceiver)

Return
InputTransferToken The InputTransferToken for the AttachedSurfaceControl This value cannot be null.
Exceptions
java.lang.IllegalStateException if the AttachedSurfaceControl was created with no registered input

removeOnBufferTransformHintChangedListener

Added in API level 32
open fun removeOnBufferTransformHintChangedListener(listener: AttachedSurfaceControl.OnBufferTransformHintChangedListener): Unit

Unregisters a OnBufferTransformHintChangedListener.

Parameters
listener AttachedSurfaceControl.OnBufferTransformHintChangedListener: This value cannot be null.

setChildBoundingInsets

Added in API level 34
open fun setChildBoundingInsets(insets: Rect): Unit

Set a crop region on all children parented to the layer represented by this AttachedSurfaceControl. This includes SurfaceView, and an example usage may be to ensure that SurfaceView with android.view.SurfaceView#setZOrderOnTop are cropped to a region not including the app bar.

This cropped is expressed in terms of insets in window-space. Negative insets are considered invalid and will produce an exception. Insets of zero will produce the same result as if this function had never been called.

Parameters
insets Rect: The insets in each direction by which to bound the children expressed in window-space. This value cannot be null.
Exceptions
java.lang.IllegalArgumentException If negative insets are provided.

setTouchableRegion

Added in API level 33
open fun setTouchableRegion(r: Region?): Unit

Sets the touchable region for this SurfaceControl, expressed in surface local coordinates. By default the touchable region is the entire Layer, indicating that if the layer is otherwise eligible to receive touch it receives touch on the entire surface. Setting the touchable region allows the SurfaceControl to receive touch in some regions, while allowing for pass-through in others.

Parameters
r Region?: The region to use or null to use the entire Layer bounds