Added in API level 31

AttachedSurfaceControl


public 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 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 View.getRootSurfaceControl() and Window.getRootSurfaceControl(). It must be used from the UI thread of the object it was obtained from.

Summary

Nested classes

interface AttachedSurfaceControl.OnBufferTransformHintChangedListener

Buffer transform hint change listener. 

Public methods

default void addOnBufferTransformHintChangedListener(AttachedSurfaceControl.OnBufferTransformHintChangedListener listener)

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

abstract boolean applyTransactionOnDraw(SurfaceControl.Transaction t)

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

abstract SurfaceControl.Transaction buildReparentTransaction(SurfaceControl child)

Create a transaction which will reparent to the View hierarchy root SurfaceControl.

default int getBufferTransformHint()

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.

default InputTransferToken getInputTransferToken()

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 ERROR(WindowManager.registerBatchedSurfaceControlInputReceiver(int, InputTransferToken, SurfaceControl, Choreographer, SurfaceControlInputReceiver)/android.view.WindowManager#registerBatchedSurfaceControlInputReceiver(int,android.window.InputTransferToken,android.view.SurfaceControl,android.view.Choreographer,android.view.SurfaceControlInputReceiver) WindowManager.registerBatchedSurfaceControlInputReceiver(int, InputTransferToken, SurfaceControl, Choreographer, SurfaceControlInputReceiver)) or ERROR(WindowManager.registerUnbatchedSurfaceControlInputReceiver(int, InputTransferToken, SurfaceControl, Looper, SurfaceControlInputReceiver)/android.view.WindowManager#registerUnbatchedSurfaceControlInputReceiver(int,android.window.InputTransferToken,android.view.SurfaceControl,android.os.Looper,android.view.SurfaceControlInputReceiver) WindowManager.registerUnbatchedSurfaceControlInputReceiver(int, InputTransferToken, SurfaceControl, Looper, SurfaceControlInputReceiver))

default void removeOnBufferTransformHintChangedListener(AttachedSurfaceControl.OnBufferTransformHintChangedListener listener)

Unregisters a OnBufferTransformHintChangedListener.

default void setChildBoundingInsets(Rect insets)

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

default void setTouchableRegion(Region r)

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

Public methods

addOnBufferTransformHintChangedListener

Added in API level 32
public void addOnBufferTransformHintChangedListener (AttachedSurfaceControl.OnBufferTransformHintChangedListener listener)

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
public abstract boolean applyTransactionOnDraw (SurfaceControl.Transaction t)

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 View.invalidate()

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

Returns
boolean

buildReparentTransaction

Added in API level 31
public abstract SurfaceControl.Transaction buildReparentTransaction (SurfaceControl child)

Create a transaction which will reparent 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.

Returns
SurfaceControl.Transaction A new transaction which performs the reparent operation when applied. This value may be null.

getBufferTransformHint

Added in API level 32
public int getBufferTransformHint ()

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.

Returns
int Value is SurfaceControl.BUFFER_TRANSFORM_IDENTITY, SurfaceControl.BUFFER_TRANSFORM_MIRROR_HORIZONTAL, SurfaceControl.BUFFER_TRANSFORM_MIRROR_VERTICAL, SurfaceControl.BUFFER_TRANSFORM_ROTATE_90, SurfaceControl.BUFFER_TRANSFORM_ROTATE_180, SurfaceControl.BUFFER_TRANSFORM_ROTATE_270, BUFFER_TRANSFORM_MIRROR_HORIZONTAL | BUFFER_TRANSFORM_ROTATE_90, or BUFFER_TRANSFORM_MIRROR_VERTICAL | BUFFER_TRANSFORM_ROTATE_90

See also:

getInputTransferToken

Added in API level 35
public InputTransferToken getInputTransferToken ()

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 ERROR(WindowManager.registerBatchedSurfaceControlInputReceiver(int, InputTransferToken, SurfaceControl, Choreographer, SurfaceControlInputReceiver)/android.view.WindowManager#registerBatchedSurfaceControlInputReceiver(int,android.window.InputTransferToken,android.view.SurfaceControl,android.view.Choreographer,android.view.SurfaceControlInputReceiver) WindowManager.registerBatchedSurfaceControlInputReceiver(int, InputTransferToken, SurfaceControl, Choreographer, SurfaceControlInputReceiver)) or ERROR(WindowManager.registerUnbatchedSurfaceControlInputReceiver(int, InputTransferToken, SurfaceControl, Looper, SurfaceControlInputReceiver)/android.view.WindowManager#registerUnbatchedSurfaceControlInputReceiver(int,android.window.InputTransferToken,android.view.SurfaceControl,android.os.Looper,android.view.SurfaceControlInputReceiver) WindowManager.registerUnbatchedSurfaceControlInputReceiver(int, InputTransferToken, SurfaceControl, Looper, SurfaceControlInputReceiver))

Returns
InputTransferToken The InputTransferToken for the AttachedSurfaceControl This value cannot be null.

Throws
IllegalStateException if the AttachedSurfaceControl was created with no registered input

removeOnBufferTransformHintChangedListener

Added in API level 32
public void removeOnBufferTransformHintChangedListener (AttachedSurfaceControl.OnBufferTransformHintChangedListener listener)

Unregisters a OnBufferTransformHintChangedListener.

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

setChildBoundingInsets

Added in API level 34
public void setChildBoundingInsets (Rect insets)

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 SurfaceView.setZOrderOnTop(boolean) 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.

Throws
IllegalArgumentException If negative insets are provided.

setTouchableRegion

Added in API level 33
public void setTouchableRegion (Region r)

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