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 |
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
void
|
removeOnBufferTransformHintChangedListener(AttachedSurfaceControl.OnBufferTransformHintChangedListener listener)
Unregisters a |
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
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
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
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
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.
| 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:
removeOnBufferTransformHintChangedListener
public void removeOnBufferTransformHintChangedListener (AttachedSurfaceControl.OnBufferTransformHintChangedListener listener)
Unregisters a OnBufferTransformHintChangedListener.
| Parameters | |
|---|---|
listener |
AttachedSurfaceControl.OnBufferTransformHintChangedListener: This value cannot be null. |
setChildBoundingInsets
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
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 |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2023-03-08 UTC.

