SurfaceControl.Transaction


public static class SurfaceControl.Transaction
extends Object implements Closeable, Parcelable

java.lang.Object
   ↳ android.view.SurfaceControl.Transaction


An atomic set of changes to a set of SurfaceControl.

Summary

Inherited constants

Fields

public static final Creator<SurfaceControl.Transaction> CREATOR

Public constructors

Transaction()

Open a new transaction object.

Public methods

SurfaceControl.Transaction addTransactionCommittedListener(Executor executor, SurfaceControl.TransactionCommittedListener listener)

Request to add a TransactionCommittedListener.

SurfaceControl.Transaction addTransactionCompletedListener(Executor executor, Consumer<SurfaceControl.TransactionStats> listener)

Request to add a TransactionCompletedListener.

void apply()

Apply the transaction, clearing it's state, and making it usable as a new transaction.

SurfaceControl.Transaction clearFrameRate(SurfaceControl sc)

Clears the frame rate which was set for the surface SurfaceControl.

SurfaceControl.Transaction clearTrustedPresentationCallback(SurfaceControl sc)

This method was deprecated in API level 35. Use WindowManager.unregisterTrustedPresentationListener(Consumer) instead.

void close()

Release the native transaction object, without applying it.

int describeContents()

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.

SurfaceControl.Transaction merge(SurfaceControl.Transaction other)

Merge the other transaction into this transaction, clearing the other transaction as if it had been applied.

SurfaceControl.Transaction reparent(SurfaceControl sc, SurfaceControl newParent)

Re-parents a given layer to a new parent.

SurfaceControl.Transaction setAlpha(SurfaceControl sc, float alpha)

Set the alpha for a given surface.

SurfaceControl.Transaction setBuffer(SurfaceControl sc, HardwareBuffer buffer, SyncFence fence)

Updates the HardwareBuffer displayed for the SurfaceControl.

SurfaceControl.Transaction setBuffer(SurfaceControl sc, HardwareBuffer buffer)

Updates the HardwareBuffer displayed for the SurfaceControl.

SurfaceControl.Transaction setBuffer(SurfaceControl sc, HardwareBuffer buffer, SyncFence fence, Consumer<SyncFence> releaseCallback)

Updates the HardwareBuffer displayed for the SurfaceControl.

SurfaceControl.Transaction setBufferSize(SurfaceControl sc, int w, int h)

Set the default buffer size for the SurfaceControl, if there is a Surface associated with the control, then this will be the default size for buffers dequeued from it.

SurfaceControl.Transaction setBufferTransform(SurfaceControl sc, int transform)

Sets the buffer transform that should be applied to the current buffer.

SurfaceControl.Transaction setCrop(SurfaceControl sc, Rect crop)

Bounds the surface and its children to the bounds specified.

SurfaceControl.Transaction setDamageRegion(SurfaceControl sc, Region region)

Updates the region for the content on this surface updated in this transaction.

SurfaceControl.Transaction setDataSpace(SurfaceControl sc, int dataspace)

Set the dataspace for the SurfaceControl.

SurfaceControl.Transaction setDesiredHdrHeadroom(SurfaceControl sc, float desiredRatio)

Sets the desired HDR headroom for the layer.

SurfaceControl.Transaction setDesiredPresentTimeNanos(long desiredPresentTimeNanos)

Specifies a desiredPresentTimeNanos for the transaction.

SurfaceControl.Transaction setExtendedRangeBrightness(SurfaceControl sc, float currentBufferRatio, float desiredRatio)

Sets the desired extended range brightness for the layer.

SurfaceControl.Transaction setFrameRate(SurfaceControl sc, Surface.FrameRateParams frameRateParams)

Sets the intended frame rate for the surface SurfaceControl.

SurfaceControl.Transaction setFrameRate(SurfaceControl sc, float frameRate, int compatibility)

Sets the intended frame rate for this surface.

SurfaceControl.Transaction setFrameRate(SurfaceControl sc, float frameRate, int compatibility, int changeFrameRateStrategy)

Sets the intended frame rate for the surface SurfaceControl.

SurfaceControl.Transaction setFrameTimeline(long vsyncId)

Sets the frame timeline to use in SurfaceFlinger.

SurfaceControl.Transaction setGeometry(SurfaceControl sc, Rect sourceCrop, Rect destFrame, int orientation)

This method was deprecated in API level 33. Use setCrop(android.view.SurfaceControl, android.graphics.Rect), setBufferTransform(android.view.SurfaceControl, int), setPosition(android.view.SurfaceControl, float, float) and setScale(android.view.SurfaceControl, float, float) instead.

SurfaceControl.Transaction setLayer(SurfaceControl sc, int z)

Set the Z-order for a given SurfaceControl, relative to it's siblings.

SurfaceControl.Transaction setOpaque(SurfaceControl sc, boolean isOpaque)

Indicates whether the surface must be considered opaque, even if its pixel format is set to translucent.

SurfaceControl.Transaction setPosition(SurfaceControl sc, float x, float y)

Sets the SurfaceControl to the specified position relative to the parent SurfaceControl

SurfaceControl.Transaction setScale(SurfaceControl sc, float scaleX, float scaleY)

Sets the SurfaceControl to the specified scale with (0, 0) as the center point of the scale.

SurfaceControl.Transaction setTrustedPresentationCallback(SurfaceControl sc, SurfaceControl.TrustedPresentationThresholds thresholds, Executor executor, Consumer<Boolean> listener)

This method was deprecated in API level 35. Use WindowManager.registerTrustedPresentationListener(IBinder, android.window.TrustedPresentationThresholds, Executor, Consumer) instead.

SurfaceControl.Transaction setVisibility(SurfaceControl sc, boolean visible)

Toggle the visibility of a given Layer and it's sub-tree.

void writeToParcel(Parcel dest, int flags)

Writes the transaction to parcel, clearing the transaction as if it had been applied so it can be used to store future transactions.

Inherited methods

Fields

CREATOR

Added in API level 30
public static final Creator<SurfaceControl.Transaction> CREATOR

Public constructors

Transaction

Added in API level 29
public Transaction ()

Open a new transaction object. The transaction may be filed with commands to manipulate SurfaceControl instances, and then applied atomically with apply(). Eventually the user should invoke close(), when the object is no longer required. Note however that re-using a transaction after a call to apply is allowed as a convenience.

Public methods

addTransactionCommittedListener

Added in API level 33
public SurfaceControl.Transaction addTransactionCommittedListener (Executor executor, 
                SurfaceControl.TransactionCommittedListener listener)

Request to add a TransactionCommittedListener. The callback is invoked when transaction is applied and the updates are ready to be presented. 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. The listener is invoked once the transaction is applied, and never again. Multiple listeners can be added to the same transaction, however the order the listeners will be called is not guaranteed.

Parameters
executor Executor: The executor that the callback should be invoked on. This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread.

listener SurfaceControl.TransactionCommittedListener: The callback that will be invoked when the transaction has been committed. This value cannot be null.

Returns
SurfaceControl.Transaction This value cannot be null.

addTransactionCompletedListener

Added in API level 35
public SurfaceControl.Transaction addTransactionCompletedListener (Executor executor, 
                Consumer<SurfaceControl.TransactionStats> listener)

Request to add a TransactionCompletedListener. The listener is invoked when transaction is presented, and never again. Multiple listeners can be added to the same transaction, however the order the listeners will be called is not guaranteed.

Parameters
executor Executor: The executor that the callback should be invoked on. This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread.

listener Consumer: The callback that will be invoked when the transaction has been completed. This value cannot be null.

Returns
SurfaceControl.Transaction This value cannot be null.

apply

Added in API level 29
public void apply ()

Apply the transaction, clearing it's state, and making it usable as a new transaction.

clearFrameRate

Added in API level 34
public SurfaceControl.Transaction clearFrameRate (SurfaceControl sc)

Clears the frame rate which was set for the surface SurfaceControl.

This is equivalent to calling setFrameRate(android.view.SurfaceControl, float, int, int) using 0 for frameRate.

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.

Parameters
sc SurfaceControl: The SurfaceControl to clear the frame rate of. This value cannot be null.

Returns
SurfaceControl.Transaction This transaction object. This value cannot be null.

clearTrustedPresentationCallback

Added in API level 34
Deprecated in API level 35
public SurfaceControl.Transaction clearTrustedPresentationCallback (SurfaceControl sc)

This method was deprecated in API level 35.
Use WindowManager.unregisterTrustedPresentationListener(Consumer) instead.

Clears the callback for a specific SurfaceControl

Parameters
sc SurfaceControl: The SurfaceControl that the callback should be cleared from This value cannot be null.

Returns
SurfaceControl.Transaction This transaction This value cannot be null.

close

Added in API level 29
public void close ()

Release the native transaction object, without applying it.

describeContents

Added in API level 30
public int describeContents ()

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. For example, if the object will include a file descriptor in the output of writeToParcel(android.os.Parcel, int), the return value of this method must include the CONTENTS_FILE_DESCRIPTOR bit.

Returns
int a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either 0 or CONTENTS_FILE_DESCRIPTOR

merge

Added in API level 29
public SurfaceControl.Transaction merge (SurfaceControl.Transaction other)

Merge the other transaction into this transaction, clearing the other transaction as if it had been applied.

Parameters
other SurfaceControl.Transaction: The transaction to merge in to this one. This value cannot be null.

Returns
SurfaceControl.Transaction This transaction. This value cannot be null.

reparent

Added in API level 29
public SurfaceControl.Transaction reparent (SurfaceControl sc, 
                SurfaceControl newParent)

Re-parents a given layer 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
sc SurfaceControl: The SurfaceControl to reparent This value cannot be null.

newParent SurfaceControl: The new parent for the given control. This value may be null.

Returns
SurfaceControl.Transaction This Transaction This value cannot be null.

setAlpha

Added in API level 29
public SurfaceControl.Transaction setAlpha (SurfaceControl sc, 
                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
sc SurfaceControl: The given SurfaceControl. This value cannot be null.

alpha float: The alpha to set. Value is between 0.0 and 1.0 inclusive

Returns
SurfaceControl.Transaction This value cannot be null.

setBuffer

Added in API level 33
public SurfaceControl.Transaction setBuffer (SurfaceControl sc, 
                HardwareBuffer buffer, 
                SyncFence fence)

Updates the HardwareBuffer displayed for the SurfaceControl. 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 EGLExt.eglDupNativeFenceFDANDROID(EGLDisplay, EGLSync) 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
sc SurfaceControl: The SurfaceControl to update This value cannot be null.

buffer HardwareBuffer: The buffer to be displayed. Pass in a null buffer to release the last displayed buffer.

fence SyncFence: The presentation fence. If null or invalid, this is equivalent to setBuffer(android.view.SurfaceControl, android.hardware.HardwareBuffer)

Returns
SurfaceControl.Transaction this This value cannot be null.

setBuffer

Added in API level 33
public SurfaceControl.Transaction setBuffer (SurfaceControl sc, 
                HardwareBuffer buffer)

Updates the HardwareBuffer displayed for the SurfaceControl. 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.

Parameters
sc SurfaceControl: The SurfaceControl to update This value cannot be null.

buffer HardwareBuffer: The buffer to be displayed This value may be null.

Returns
SurfaceControl.Transaction this This value cannot be null.

setBuffer

Added in API level 33
public SurfaceControl.Transaction setBuffer (SurfaceControl sc, 
                HardwareBuffer buffer, 
                SyncFence fence, 
                Consumer<SyncFence> releaseCallback)

Updates the HardwareBuffer displayed for the SurfaceControl. 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 EGLExt.eglDupNativeFenceFDANDROID(EGLDisplay, EGLSync) 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. A releaseCallback may be passed to know when the buffer is safe to be reused. This is recommended when attempting to render continuously using SurfaceControl transactions instead of through Surface, as it provides a safe & reliable way to know when a buffer can be re-used. The callback will be invoked with a SyncFence which, if valid, must be waited on prior to using the buffer. This can either be done directly with SyncFence.awaitForever() or it may be done indirectly such as passing it as a release fence to Image.setFence(SyncFence) when using ImageReader.

Parameters
sc SurfaceControl: The SurfaceControl to update This value cannot be null.

buffer HardwareBuffer: The buffer to be displayed This value may be null.

fence SyncFence: The presentation fence. If null or invalid, this is equivalent to setBuffer(android.view.SurfaceControl, android.hardware.HardwareBuffer)

releaseCallback Consumer: The callback to invoke when the buffer being set has been released by a later transaction. That is, the point at which it is safe to re-use the buffer. This value may be null.

Returns
SurfaceControl.Transaction this This value cannot be null.

setBufferSize

Added in API level 29
public SurfaceControl.Transaction setBufferSize (SurfaceControl sc, 
                int w, 
                int h)

Set the default buffer size for the SurfaceControl, if there is a Surface associated with the control, then this will be the default size for buffers dequeued from it.

Parameters
sc SurfaceControl: The surface to set the buffer size for. This value cannot be null.

w int: The default width Value is 0 or greater

h int: The default height Value is 0 or greater

Returns
SurfaceControl.Transaction This Transaction This value cannot be null.

setBufferTransform

Added in API level 33
public SurfaceControl.Transaction setBufferTransform (SurfaceControl sc, 
                int transform)

Sets the buffer transform that should be applied to the current buffer. This can be used in combination with AttachedSurfaceControl.addOnBufferTransformHintChangedListener(AttachedSurfaceControl.OnBufferTransformHintChangedListener) to pre-rotate the buffer for the current display orientation. This can improve the performance of displaying the associated buffer.

Parameters
sc SurfaceControl: The SurfaceControl to update This value cannot be null.

transform int: The transform to apply to the buffer. 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

Returns
SurfaceControl.Transaction this This value cannot be null.

setCrop

Added in API level 33
public SurfaceControl.Transaction setCrop (SurfaceControl sc, 
                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
sc SurfaceControl: SurfaceControl to set crop of. This value cannot be null.

crop Rect: Bounds of the crop to apply. This value may be null.

Returns
SurfaceControl.Transaction this This transaction for chaining This value cannot be null.

setDamageRegion

Added in API level 33
public SurfaceControl.Transaction setDamageRegion (SurfaceControl sc, 
                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
sc SurfaceControl: The SurfaceControl on which to set the damage region This value cannot be null.

region Region: The region to set. If null, the entire buffer is assumed dirty. This is equivalent to not setting a damage region at all.

Returns
SurfaceControl.Transaction This value cannot be null.

setDataSpace

Added in API level 33
public SurfaceControl.Transaction setDataSpace (SurfaceControl sc, 
                int dataspace)

Set the dataspace for the SurfaceControl. This will control how the buffer set with setBuffer(android.view.SurfaceControl, android.hardware.HardwareBuffer) is displayed.

Parameters
sc SurfaceControl: The SurfaceControl to update This value cannot be null.

dataspace int: The dataspace to set it to Value is either 0 or a combination of DataSpace.DATASPACE_DEPTH, DataSpace.DATASPACE_DYNAMIC_DEPTH, DataSpace.DATASPACE_HEIF, android.hardware.DataSpace.DATASPACE_HEIF_ULTRAHDR, DataSpace.DATASPACE_JPEG_R, DataSpace.DATASPACE_UNKNOWN, DataSpace.DATASPACE_SCRGB_LINEAR, DataSpace.DATASPACE_SRGB, DataSpace.DATASPACE_SCRGB, DataSpace.DATASPACE_DISPLAY_P3, DataSpace.DATASPACE_BT2020_HLG, DataSpace.DATASPACE_BT2020_PQ, DataSpace.DATASPACE_ADOBE_RGB, DataSpace.DATASPACE_JFIF, DataSpace.DATASPACE_BT601_625, DataSpace.DATASPACE_BT601_525, DataSpace.DATASPACE_BT2020, DataSpace.DATASPACE_BT709, DataSpace.DATASPACE_DCI_P3, DataSpace.DATASPACE_SRGB_LINEAR, and android.hardware.DataSpace.DATASPACE_DISPLAY_BT2020

Returns
SurfaceControl.Transaction this This value cannot be null.

setDesiredHdrHeadroom

Added in API level 35
public SurfaceControl.Transaction setDesiredHdrHeadroom (SurfaceControl sc, 
                float desiredRatio)

Sets the desired HDR headroom for the layer.

Prefer using this API over setExtendedRangeBrightness(SurfaceControl, float, float) for formats that . conform to HDR video standards like HLG or HDR10 which do not communicate a HDR/SDR ratio as part of generating the buffer.

Parameters
sc SurfaceControl: The layer whose desired HDR headroom is being specified This value cannot be null.

desiredRatio float: 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.

Default value is 0.0f and indicates that the system will choose the best headroom for this surface control's content. Typically, this means that HLG/PQ encoded content will be displayed with some HDR headroom greater than 1.0.

When called after setExtendedRangeBrightness(SurfaceControl, float, float), the desiredHeadroom will override the desiredRatio provided by setExtendedRangeBrightness(SurfaceControl, float, float). Conversely, when called before setExtendedRangeBrightness(SurfaceControl, float, float), the desiredRatio provided by setExtendedRangeBrightness(SurfaceControl, float, float) will override the desiredHeadroom.

Must be finite && >= 1.0f or 0.0f. Value is 0.0f or greater

Returns
SurfaceControl.Transaction this This value cannot be null.

setDesiredPresentTimeNanos

Added in API level 35
public SurfaceControl.Transaction setDesiredPresentTimeNanos (long desiredPresentTimeNanos)

Specifies a desiredPresentTimeNanos for the transaction. The framework will try to present the transaction at or after the time specified. Transactions will not be presented until all of their acquire fences have signaled even if the app requests an earlier present time. If an earlier transaction has a desired present time of x, and a later transaction has a desired present time that is before x, the later transaction will not preempt the earlier transaction.

Parameters
desiredPresentTimeNanos long: The desired time (in CLOCK_MONOTONIC) for the transaction.

Returns
SurfaceControl.Transaction This transaction This value cannot be null.

setExtendedRangeBrightness

Added in API level 34
public SurfaceControl.Transaction setExtendedRangeBrightness (SurfaceControl sc, 
                float currentBufferRatio, 
                float desiredRatio)

Sets the desired extended range brightness for the layer. This only applies for layers whose dataspace has RANGE_EXTENDED.

Parameters
sc SurfaceControl: The layer whose extended range brightness is being specified This value cannot be null.

currentBufferRatio float: 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

desiredRatio float: 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
SurfaceControl.Transaction this This value cannot be null.

setFrameRate

public SurfaceControl.Transaction setFrameRate (SurfaceControl sc, 
                Surface.FrameRateParams frameRateParams)

Sets the intended frame rate for the surface SurfaceControl.

On devices that are capable of running the display at different frame rates, the system may choose a display refresh rate to better match this surface's frame rate. Usage of this API won't introduce frame rate throttling, or affect other aspects of 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.

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.

Parameters
sc SurfaceControl: The SurfaceControl to specify the frame rate of. This value cannot be null.

frameRateParams Surface.FrameRateParams: The parameters describing the intended frame rate of this surface. Refer to Surface.FrameRateParams for details. This value cannot be null.

Returns
SurfaceControl.Transaction This transaction object. This value cannot be null.

setFrameRate

Added in API level 30
public SurfaceControl.Transaction setFrameRate (SurfaceControl sc, 
                float frameRate, 
                int compatibility)

Sets the intended frame rate for this surface. Any switching of refresh rates is most probably going to be seamless.

Parameters
sc SurfaceControl: This value cannot be null.

frameRate float: Value is 0.0 or greater

compatibility int: Value is Surface.FRAME_RATE_COMPATIBILITY_DEFAULT, or Surface.FRAME_RATE_COMPATIBILITY_FIXED_SOURCE

Returns
SurfaceControl.Transaction This value cannot be null.

setFrameRate

Added in API level 31
public SurfaceControl.Transaction setFrameRate (SurfaceControl sc, 
                float frameRate, 
                int compatibility, 
                int changeFrameRateStrategy)

Sets the intended frame rate for the surface SurfaceControl.

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.

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.

Parameters
sc SurfaceControl: The SurfaceControl to specify the frame rate of. This value cannot be null.

frameRate float: The intended frame rate for 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. The frameRate param does not need to be a valid refresh rate for this device's display - e.g., it's fine to pass 30fps to a device that can only run the display at 60fps. Value is 0.0 or greater

compatibility int: The frame rate compatibility of this surface. The compatibility value may influence the system's choice of display frame rate. This parameter is ignored when frameRate is 0. Value is Surface.FRAME_RATE_COMPATIBILITY_DEFAULT, or Surface.FRAME_RATE_COMPATIBILITY_FIXED_SOURCE

changeFrameRateStrategy int: Whether display refresh rate transitions caused by this surface should be seamless. A seamless transition is one that doesn't have any visual interruptions, such as a black screen for a second or two. This parameter is ignored when frameRate is 0. Value is Surface.CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, or Surface.CHANGE_FRAME_RATE_ALWAYS

Returns
SurfaceControl.Transaction This transaction object. This value cannot be null.

setFrameTimeline

Added in API level 35
public SurfaceControl.Transaction setFrameTimeline (long vsyncId)

Sets the frame timeline to use in SurfaceFlinger. A frame timeline should be chosen based on the frame deadline the application can meet when rendering the frame and the application's desired presentation time. By setting a frame timeline, SurfaceFlinger tries to present the frame at the corresponding expected presentation time. To receive frame timelines, a callback must be posted to Choreographer using Choreographer.postVsyncCallback The vsyncId can then be extracted from the Choreographer.FrameTimeline.getVsyncId.

Parameters
vsyncId long: The vsync ID received from Choreographer, setting the frame's presentation target to the corresponding expected presentation time and deadline from the frame to be rendered. A stale or invalid value will be ignored.

Returns
SurfaceControl.Transaction This value cannot be null.

setGeometry

Added in API level 29
Deprecated in API level 33
public SurfaceControl.Transaction setGeometry (SurfaceControl sc, 
                Rect sourceCrop, 
                Rect destFrame, 
                int orientation)

This method was deprecated in API level 33.
Use setCrop(android.view.SurfaceControl, android.graphics.Rect), setBufferTransform(android.view.SurfaceControl, int), setPosition(android.view.SurfaceControl, float, float) and setScale(android.view.SurfaceControl, float, float) instead.

Specify how the buffer associated with this Surface is mapped in to the parent coordinate space. The source frame will be scaled to fit the destination frame, after being rotated according to the orientation parameter.

Parameters
sc SurfaceControl: The SurfaceControl to specify the geometry of This value cannot be null.

sourceCrop Rect: The source rectangle in buffer space. Or null for the entire buffer.

destFrame Rect: The destination rectangle in parent space. Or null for the source frame.

orientation int: The buffer rotation Value is Surface.ROTATION_0, Surface.ROTATION_90, Surface.ROTATION_180, or Surface.ROTATION_270

Returns
SurfaceControl.Transaction This transaction object. This value cannot be null.

setLayer

Added in API level 29
public SurfaceControl.Transaction setLayer (SurfaceControl sc, 
                int z)

Set the Z-order for a given SurfaceControl, 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.

Parameters
sc SurfaceControl: The SurfaceControl to set the Z order on This value cannot be null.

z int: The Z-order Value is between Integer.MIN_VALUE and Integer.MAX_VALUE inclusive

Returns
SurfaceControl.Transaction This Transaction. This value cannot be null.

setOpaque

Added in API level 33
public SurfaceControl.Transaction setOpaque (SurfaceControl sc, 
                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
sc SurfaceControl: The SurfaceControl to update This value cannot be null.

isOpaque boolean: true if the buffer's alpha should be ignored, false otherwise

Returns
SurfaceControl.Transaction this This value cannot be null.

setPosition

Added in API level 33
public SurfaceControl.Transaction setPosition (SurfaceControl sc, 
                float x, 
                float y)

Sets the SurfaceControl to the specified position relative to the parent SurfaceControl

Parameters
sc SurfaceControl: The SurfaceControl to change position This value cannot be null.

x float: the X position

y float: the Y position

Returns
SurfaceControl.Transaction this transaction This value cannot be null.

setScale

Added in API level 33
public SurfaceControl.Transaction setScale (SurfaceControl sc, 
                float scaleX, 
                float scaleY)

Sets the SurfaceControl to the specified scale with (0, 0) as the center point of the scale.

Parameters
sc SurfaceControl: The SurfaceControl to change scale This value cannot be null.

scaleX float: the X scale

scaleY float: the Y scale

Returns
SurfaceControl.Transaction this transaction This value cannot be null.

setTrustedPresentationCallback

Added in API level 34
Deprecated in API level 35
public SurfaceControl.Transaction setTrustedPresentationCallback (SurfaceControl sc, 
                SurfaceControl.TrustedPresentationThresholds thresholds, 
                Executor executor, 
                Consumer<Boolean> listener)

This method was deprecated in API level 35.
Use WindowManager.registerTrustedPresentationListener(IBinder, android.window.TrustedPresentationThresholds, Executor, Consumer) instead.

Sets a callback to receive feedback about the presentation of a SurfaceControl. When the SurfaceControl is presented according to the passed in TrustedPresentationThresholds, it is said to "enter the state", and receives the callback with true. When the conditions fall out of thresholds, it is then said to leave the state.

There are a few simple thresholds:

  • minAlpha: Lower bound on computed alpha
  • minFractionRendered: Lower bounds on fraction of pixels that were rendered
  • stabilityThresholdMs: A time that alpha and fraction rendered must remain within bounds before we can "enter the state"

The fraction of pixels rendered is a computation based on scale, crop and occlusion. The calculation may be somewhat counterintuitive, so we can work through an example. Imagine we have a SurfaceControl with a 100x100 buffer which is occluded by (10x100) pixels on the left, and cropped by (100x10) pixels on the top. Furthermore imagine this SurfaceControl is scaled by 0.9 in both dimensions. (c=crop,o=occluded,b=both,x=none)

bccc
oxxx
oxxx
oxxx

We first start by computing fr=xscale*yscale=0.9*0.9=0.81, indicating that "81%" of the pixels were rendered. This corresponds to what was 100 pixels being displayed in 81 pixels. This is somewhat of an abuse of language, as the information of merged pixels isn't totally lost, but we err on the conservative side.

We then repeat a similar process for the crop and covered regions and accumulate the results: fr = fr * (fractionNotCropped) * (fractionNotCovered) So for this example we would get 0.9*0.9*0.9*0.9=0.65...

Notice that this is not completely accurate, as we have double counted the region marked as b. However we only wanted a "lower bound" and so it is ok to err in this direction. Selection of the threshold will ultimately be somewhat arbitrary, and so there are some somewhat arbitrary decisions in this API as well.

Parameters
sc SurfaceControl: The SurfaceControl to set the callback on This value cannot be null.

thresholds SurfaceControl.TrustedPresentationThresholds: The TrustedPresentationThresholds that will specify when the to invoke the callback. This value cannot be null.

executor Executor: The Executor where the callback will be invoked on. This value cannot be null.

listener Consumer: The Consumer that will receive the callbacks when entered or exited the threshold. This value cannot be null.

Returns
SurfaceControl.Transaction This transaction This value cannot be null.

setVisibility

Added in API level 29
public SurfaceControl.Transaction setVisibility (SurfaceControl sc, 
                boolean visible)

Toggle the visibility of a given Layer and it's sub-tree.

Parameters
sc SurfaceControl: The SurfaceControl for which to set the visibility This value cannot be null.

visible boolean: The new visibility

Returns
SurfaceControl.Transaction This transaction object. This value cannot be null.

writeToParcel

Added in API level 30
public void writeToParcel (Parcel dest, 
                int flags)

Writes the transaction to parcel, clearing the transaction as if it had been applied so it can be used to store future transactions. It's the responsibility of the parcel reader to apply the original transaction.

Parameters
dest Parcel: parcel to write the transaction to This value cannot be null.

flags int: Value is either 0 or a combination of Parcelable.PARCELABLE_WRITE_RETURN_VALUE, and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES