SurfaceControlCompat.Transaction
@RequiresApi(value = 29)
public final class SurfaceControlCompat.Transaction implements AutoCloseable
An atomic set of changes to a set of SurfaceControlCompat.
Summary
Public constructors |
|---|
Public methods |
|
|---|---|
final @NonNull SurfaceControlCompat.Transaction |
@RequiresApi(value = 31)Request to add a |
final @NonNull SurfaceControlCompat.Transaction |
clearFrameRate(@NonNull SurfaceControlCompat surfaceControl)Clears the frame rate which was set for the surface SurfaceControl. |
void |
close()Release the native transaction object, without committing it. |
final void |
commit()Commit the transaction, clearing it's state, and making it usable as a new transaction. |
final void |
@RequiresApi(value = 33)Consume the passed in transaction, and request the View hierarchy to apply it atomically with the next draw. |
final @NonNull SurfaceControlCompat.Transaction |
@RequiresApi(value = 33)Re-parents a given |
final @NonNull SurfaceControlCompat.Transaction |
reparent(Re-parents a given |
final @NonNull SurfaceControlCompat.Transaction |
setAlpha(@NonNull SurfaceControlCompat surfaceControl, float alpha)Set the alpha for a given surface. |
final @NonNull SurfaceControlCompat.Transaction |
setBuffer(Updates the |
final @NonNull SurfaceControlCompat.Transaction |
setBufferTransform(Sets the buffer transform that should be applied to the current buffer |
final @NonNull SurfaceControlCompat.Transaction |
setCrop(@NonNull SurfaceControlCompat surfaceControl, Rect crop)Bounds the surface and its children to the bounds specified. |
final @NonNull SurfaceControlCompat.Transaction |
setDamageRegion(Updates the region for the content on this surface updated in this transaction. |
final @NonNull SurfaceControlCompat.Transaction |
setDataSpace(@NonNull SurfaceControlCompat surfaceControl, int dataSpace)Set the |
final @NonNull SurfaceControlCompat.Transaction |
@RequiresApi(value = 34)Sets the desired extended range brightness for the layer. |
final @NonNull SurfaceControlCompat.Transaction |
setFrameRate(Sets the intended frame rate for |
final @NonNull SurfaceControlCompat.Transaction |
setLayer(@NonNull SurfaceControlCompat surfaceControl, int z)Set the Z-order for a given |
final @NonNull SurfaceControlCompat.Transaction |
setOpaque(@NonNull SurfaceControlCompat surfaceControl, boolean isOpaque)Indicates whether the surface must be considered opaque, even if its pixel format is set to translucent. |
final @NonNull SurfaceControlCompat.Transaction |
setPosition(Sets the SurfaceControl to the specified position relative to the parent SurfaceControl |
final @NonNull SurfaceControlCompat.Transaction |
setScale(Sets the SurfaceControl to the specified scale with (0, 0) as the center point of the scale. |
final @NonNull SurfaceControlCompat.Transaction |
setVisibility(Sets the visibility of a given Layer and it's sub-tree. |
Public constructors
Public methods
addTransactionCommittedListener
@RequiresApi(value = 31)
public final @NonNull SurfaceControlCompat.Transaction addTransactionCommittedListener(
@NonNull Executor executor,
@NonNull SurfaceControlCompat.TransactionCommittedListener listener
)
Request to add a SurfaceControlCompat.TransactionCommittedListener. The callback is invoked when transaction is applied and the updates are ready to be presented. Once applied, any callbacks added before the commit will be cleared from the Transaction. This callback does not mean buffers have been released! It simply means that any new transactions applied will not overwrite the transaction for which we are receiving a callback and instead will be included in the next frame. If you are trying to avoid dropping frames (overwriting transactions), and unable to use timestamps (Which provide a more efficient solution), then this method provides a method to pace your transaction application.
| Parameters | |
|---|---|
@NonNull Executor executor |
|
@NonNull SurfaceControlCompat.TransactionCommittedListener listener |
|
clearFrameRate
public final @NonNull SurfaceControlCompat.Transaction clearFrameRate(@NonNull SurfaceControlCompat surfaceControl)
Clears the frame rate which was set for the surface SurfaceControl.
This is equivalent to calling setFrameRate with 0 for the framerate and FRAME_RATE_COMPATIBILITY_DEFAULT
Note that this only has an effect for surfaces presented on the display. If this surface is consumed by something other than the system compositor, e.g. a media codec, this call has no effect.
This is only supported on Android R and above. This is ignored on older Android versions.
| Parameters | |
|---|---|
@NonNull SurfaceControlCompat surfaceControl |
|
close
public void close()
Release the native transaction object, without committing it.
commit
public final void commit()
Commit the transaction, clearing it's state, and making it usable as a new transaction. This will not release any resources and SurfaceControlCompat.Transaction.close must be called to release the transaction.
commitTransactionOnDraw
@RequiresApi(value = 33)
public final void commitTransactionOnDraw(
@NonNull AttachedSurfaceControl attachedSurfaceControl
)
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 | |
|---|---|
@NonNull AttachedSurfaceControl attachedSurfaceControl |
|
reparent
@RequiresApi(value = 33)
public final @NonNull SurfaceControlCompat.Transaction reparent(
@NonNull SurfaceControlCompat surfaceControl,
@NonNull AttachedSurfaceControl attachedSurfaceControl
)
Re-parents a given SurfaceControlCompat to be a child of the AttachedSurfaceControl. Children inherit transform (position, scaling) crop, visibility, and Z-ordering from their parents, as if the children were pixels within the parent Surface.
| Parameters | |
|---|---|
@NonNull SurfaceControlCompat surfaceControl |
Target |
@NonNull AttachedSurfaceControl attachedSurfaceControl |
|
reparent
public final @NonNull SurfaceControlCompat.Transaction reparent(
@NonNull SurfaceControlCompat surfaceControl,
SurfaceControlCompat newParent
)
Re-parents a given SurfaceControlCompat to a new parent. Children inherit transform (position, scaling) crop, visibility, and Z-ordering from their parents, as if the children were pixels within the parent Surface.
| Parameters | |
|---|---|
@NonNull SurfaceControlCompat surfaceControl |
Target |
SurfaceControlCompat newParent |
Parent |
setAlpha
public final @NonNull SurfaceControlCompat.Transaction setAlpha(@NonNull SurfaceControlCompat surfaceControl, float alpha)
Set the alpha for a given surface. If the alpha is non-zero the SurfaceControl will be blended with the Surfaces under it according to the specified ratio.
| Parameters | |
|---|---|
@NonNull SurfaceControlCompat surfaceControl |
Target |
float alpha |
The alpha to set. Value is between 0.0 and 1.0 inclusive. |
setBuffer
public final @NonNull SurfaceControlCompat.Transaction setBuffer(
@NonNull SurfaceControlCompat surfaceControl,
HardwareBuffer buffer,
SyncFenceCompat fence,
Function1<@NonNull SyncFenceCompat, Unit> releaseCallback
)
Updates the HardwareBuffer displayed for the SurfaceControlCompat. Note that the buffer must be allocated with HardwareBuffer.USAGE_COMPOSER_OVERLAY as well as HardwareBuffer.USAGE_GPU_SAMPLED_IMAGE as the surface control might be composited using either an overlay or using the GPU. A presentation fence may be passed to improve performance by allowing the buffer to complete rendering while it is waiting for the transaction to be applied. For example, if the buffer is being produced by rendering with OpenGL ES then a fence created with the eglDupNativeFenceFDANDROID EGL extension API can be used to allow the GPU rendering to be concurrent with the transaction. The compositor will wait for the fence to be signaled before the buffer is displayed. If multiple buffers are set as part of the same transaction, the presentation fences of all of them must signal before any buffer is displayed. That is, the entire transaction is delayed until all presentation fences have signaled, ensuring the transaction remains consistent.
| Parameters | |
|---|---|
@NonNull SurfaceControlCompat surfaceControl |
Target |
HardwareBuffer buffer |
|
SyncFenceCompat fence |
Optional |
Function1<@NonNull SyncFenceCompat, Unit> releaseCallback |
Optional callback invoked when the buffer is ready for re-use after being presented to the display. This also includes a |
setBufferTransform
public final @NonNull SurfaceControlCompat.Transaction setBufferTransform(
@NonNull SurfaceControlCompat surfaceControl,
int transformation
)
Sets the buffer transform that should be applied to the current buffer
| Parameters | |
|---|---|
@NonNull SurfaceControlCompat surfaceControl |
the |
int transformation |
The transform to apply to the buffer. Value is |
setCrop
public final @NonNull SurfaceControlCompat.Transaction setCrop(@NonNull SurfaceControlCompat surfaceControl, Rect crop)
Bounds the surface and its children to the bounds specified. Size of the surface will be ignored and only the crop and buffer size will be used to determine the bounds of the surface. If no crop is specified and the surface has no buffer, the surface bounds is only constrained by the size of its parent bounds.
| Parameters | |
|---|---|
@NonNull SurfaceControlCompat surfaceControl |
The |
Rect crop |
Bounds of the crop to apply. This value can be null. |
| Throws | |
|---|---|
IllegalArgumentException |
if crop is not a valid rectangle. |
setDamageRegion
public final @NonNull SurfaceControlCompat.Transaction setDamageRegion(
@NonNull SurfaceControlCompat surfaceControl,
Region region
)
Updates the region for the content on this surface updated in this transaction. The damage region is the area of the buffer that has changed since the previously sent buffer. This can be used to reduce the amount of recomposition that needs to happen when only a small region of the buffer is being updated, such as for a small blinking cursor or a loading indicator.
| Parameters | |
|---|---|
@NonNull SurfaceControlCompat surfaceControl |
Target |
Region region |
The region to be set. If null, the entire buffer is assumed dirty. This is equivalent to not setting a damage region at all. |
setDataSpace
public final @NonNull SurfaceControlCompat.Transaction setDataSpace(@NonNull SurfaceControlCompat surfaceControl, int dataSpace)
Set the DataSpace for the SurfaceControl. This will control how the buffer set with setBuffer is displayed.
NOTE it is strongly recommended to verify that the display supports the corresponding DataSpace in advance before configuring the data space. For example, if DataSpace.DATASPACE_DISPLAY_P3 is desired, consumers should verify that Window.isWideGamut returns true before proceeding.
| Parameters | |
|---|---|
@NonNull SurfaceControlCompat surfaceControl |
The SurfaceControl to update |
int dataSpace |
The |
| Returns | |
|---|---|
@NonNull SurfaceControlCompat.Transaction |
this |
| See also | |
|---|---|
setDataSpace |
setExtendedRangeBrightness
@RequiresApi(value = 34)
public final @NonNull SurfaceControlCompat.Transaction setExtendedRangeBrightness(
@NonNull SurfaceControlCompat surfaceControl,
@FloatRange(from = 1.0, fromInclusive = true) float currentBufferRatio,
@FloatRange(from = 1.0, fromInclusive = true) float desiredRatio
)
Sets the desired extended range brightness for the layer. This only applies for layers that are displaying HardwareBuffer instances with a DataSpace of DataSpace.RANGE_EXTENDED.
| Parameters | |
|---|---|
@NonNull SurfaceControlCompat surfaceControl |
The layer whose extended range brightness is being specified |
@FloatRange(from = 1.0, fromInclusive = true) float currentBufferRatio |
The current hdr/sdr ratio of the current buffer. For example if the buffer was rendered with a target SDR whitepoint of 100 nits and a max display brightness of 200 nits, this should be set to 2.0f. Default value is 1.0f. Transfer functions that encode their own brightness ranges, such as HLG or PQ, should also set this to 1.0f and instead communicate extended content brightness information via metadata such as CTA861_3 or SMPTE2086. Must be finite &&>= 1.0f |
@FloatRange(from = 1.0, fromInclusive = true) float desiredRatio |
The desired hdr/sdr ratio. This can be used to communicate the max desired brightness range. This is similar to the "max luminance" value in other HDR metadata formats, but represented as a ratio of the target SDR whitepoint to the max display brightness. The system may not be able to, or may choose not to, deliver the requested range. While requesting a large desired ratio will result in the most dynamic range, voluntarily reducing the requested range can help improve battery life as well as can improve quality by ensuring greater bit depth is allocated to the luminance range in use. Default value is 1.0f and indicates that extended range brightness is not being used, so the resulting SDR or HDR behavior will be determined entirely by the dataspace being used (ie, typically SDR however PQ or HLG transfer functions will still result in HDR) Must be finite &&>= 1.0f |
| Returns | |
|---|---|
@NonNull SurfaceControlCompat.Transaction |
this |
setFrameRate
public final @NonNull SurfaceControlCompat.Transaction setFrameRate(
@NonNull SurfaceControlCompat surfaceControl,
float frameRate,
int compatibility,
int changeFrameRateStrategy
)
Sets the intended frame rate for SurfaceControlCompat.
On devices that are capable of running the display at different refresh rates, the system may choose a display refresh rate to better match this surface's frame rate. Usage of this API won't directly affect the application's frame production pipeline. However, because the system may change the display refresh rate, calls to this function may result in changes to Choreographer callback timings, and changes to the time interval at which the system releases buffers back to the application.
This method is only supported on Android R+ and is ignored on older platform versions.
| Parameters | |
|---|---|
@NonNull SurfaceControlCompat surfaceControl |
The target |
float frameRate |
The intended frame rate of this surface, in frames per second. 0 is a special value that indicates the app will accept the system's choice for the display frame rate, which is the default behavior if this function isn't called. Must be greater than or equal to 0. The frameRate param does not need to be a valid refresh rate for this device's display
|
int compatibility |
The frame rate compatibility of this surface. The compatibility value may influence the system's choice of display frame rate. This must be either |
int changeFrameRateStrategy |
Whether display refresh rate transitions should be seamless. A seamless transition does not have any visual interruptions, such as a black screen for a second or two. Must be either |
setLayer
public final @NonNull SurfaceControlCompat.Transaction setLayer(@NonNull SurfaceControlCompat surfaceControl, int z)
Set the Z-order for a given SurfaceControlCompat, relative to it's siblings. If two siblings share the same Z order the ordering is undefined. Surfaces with a negative Z will be placed below the parent Surface.
setOpaque
public final @NonNull SurfaceControlCompat.Transaction setOpaque(@NonNull SurfaceControlCompat surfaceControl, boolean isOpaque)
Indicates whether the surface must be considered opaque, even if its pixel format is set to translucent. This can be useful if an application needs full RGBA 8888 support for instance but will still draw every pixel opaque. This flag only determines whether opacity will be sampled from the alpha channel. Plane-alpha from calls to setAlpha() can still result in blended composition regardless of the opaque setting. Combined effects are (assuming a buffer format with an alpha channel):
OPAQUE + alpha(1.0) == opaque composition OPAQUE + alpha(0.x) == blended composition OPAQUE + alpha(0.0) == no composition !OPAQUE + alpha(1.0) == blended composition !OPAQUE + alpha(0.x) == blended composition !OPAQUE + alpha(0.0) == no composition If the underlying buffer lacks an alpha channel, it is as if setOpaque(true) were set automatically.
| Parameters | |
|---|---|
@NonNull SurfaceControlCompat surfaceControl |
Target |
boolean isOpaque |
Flag indicating if the |
setPosition
public final @NonNull SurfaceControlCompat.Transaction setPosition(
@NonNull SurfaceControlCompat surfaceControl,
float x,
float y
)
Sets the SurfaceControl to the specified position relative to the parent SurfaceControl
| Parameters | |
|---|---|
@NonNull SurfaceControlCompat surfaceControl |
The |
float x |
the X position |
float y |
the Y position |
setScale
public final @NonNull SurfaceControlCompat.Transaction setScale(
@NonNull SurfaceControlCompat surfaceControl,
float scaleX,
float scaleY
)
Sets the SurfaceControl to the specified scale with (0, 0) as the center point of the scale.
| Parameters | |
|---|---|
@NonNull SurfaceControlCompat surfaceControl |
The |
float scaleX |
the X scale |
float scaleY |
the Y scale |
setVisibility
public final @NonNull SurfaceControlCompat.Transaction setVisibility(
@NonNull SurfaceControlCompat surfaceControl,
boolean visible
)
Sets the visibility of a given Layer and it's sub-tree.
| Parameters | |
|---|---|
@NonNull SurfaceControlCompat surfaceControl |
Target |
boolean visible |
|