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. |
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.
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
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
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 2024-12-18 UTC.