Transaction
class Transaction : Closeable, Parcelable
kotlin.Any | |
↳ | android.view.SurfaceControl.Transaction |
An atomic set of changes to a set of SurfaceControl.
Summary
Inherited constants | |
---|---|
Public constructors | |
---|---|
Open a new transaction object. |
Public methods | |
---|---|
open SurfaceControl.Transaction |
addTransactionCommittedListener(executor: Executor, listener: SurfaceControl.TransactionCommittedListener) Request to add a |
open SurfaceControl.Transaction |
addTransactionCompletedListener(executor: Executor, listener: Consumer<SurfaceControl.TransactionStats!>) Request to add a TransactionCompletedListener. |
open Unit |
apply() Apply the transaction, clearing it's state, and making it usable as a new transaction. |
open SurfaceControl.Transaction |
Clears the frame rate which was set for the surface |
open SurfaceControl.Transaction |
Clears the callback for a specific |
open Unit |
close() Release the native transaction object, without applying it. |
open Int | |
open SurfaceControl.Transaction |
merge(other: SurfaceControl.Transaction) Merge the other transaction into this transaction, clearing the other transaction as if it had been applied. |
open SurfaceControl.Transaction |
reparent(sc: SurfaceControl, newParent: SurfaceControl?) Re-parents a given layer to a new parent. |
open SurfaceControl.Transaction |
setAlpha(sc: SurfaceControl, alpha: Float) Set the alpha for a given surface. |
open SurfaceControl.Transaction |
setBuffer(sc: SurfaceControl, buffer: HardwareBuffer?) Updates the HardwareBuffer displayed for the SurfaceControl. |
open SurfaceControl.Transaction |
setBuffer(sc: SurfaceControl, buffer: HardwareBuffer?, fence: SyncFence?) Updates the HardwareBuffer displayed for the SurfaceControl. |
open SurfaceControl.Transaction |
setBuffer(sc: SurfaceControl, buffer: HardwareBuffer?, fence: SyncFence?, releaseCallback: Consumer<SyncFence!>?) Updates the HardwareBuffer displayed for the SurfaceControl. |
open SurfaceControl.Transaction |
setBufferSize(sc: SurfaceControl, w: Int, h: Int) Set the default buffer size for the SurfaceControl, if there is a |
open SurfaceControl.Transaction |
setBufferTransform(sc: SurfaceControl, transform: Int) Sets the buffer transform that should be applied to the current buffer. |
open SurfaceControl.Transaction |
setCrop(sc: SurfaceControl, crop: Rect?) Bounds the surface and its children to the bounds specified. |
open SurfaceControl.Transaction |
setDamageRegion(sc: SurfaceControl, region: Region?) Updates the region for the content on this surface updated in this transaction. |
open SurfaceControl.Transaction |
setDataSpace(sc: SurfaceControl, dataspace: Int) Set the dataspace for the SurfaceControl. |
open SurfaceControl.Transaction |
setDesiredHdrHeadroom(sc: SurfaceControl, desiredRatio: Float) Sets the desired HDR headroom for the layer. |
open SurfaceControl.Transaction |
setDesiredPresentTimeNanos(desiredPresentTimeNanos: Long) Specifies a desiredPresentTimeNanos for the transaction. |
open SurfaceControl.Transaction |
setExtendedRangeBrightness(sc: SurfaceControl, currentBufferRatio: Float, desiredRatio: Float) Sets the desired extended range brightness for the layer. |
open SurfaceControl.Transaction |
setFrameRate(sc: SurfaceControl, frameRateParams: Surface.FrameRateParams) Sets the intended frame rate for the surface |
open SurfaceControl.Transaction |
setFrameRate(sc: SurfaceControl, frameRate: Float, compatibility: Int) Sets the intended frame rate for this surface. |
open SurfaceControl.Transaction |
setFrameRate(sc: SurfaceControl, frameRate: Float, compatibility: Int, changeFrameRateStrategy: Int) Sets the intended frame rate for the surface |
open SurfaceControl.Transaction |
setFrameTimeline(vsyncId: Long) Sets the frame timeline to use in SurfaceFlinger. |
open SurfaceControl.Transaction |
setGeometry(sc: SurfaceControl, sourceCrop: Rect?, destFrame: Rect?, orientation: Int) Specify how the buffer associated with this Surface is mapped in to the parent coordinate space. |
open SurfaceControl.Transaction |
setLayer(sc: SurfaceControl, z: Int) Set the Z-order for a given SurfaceControl, relative to it's siblings. |
open SurfaceControl.Transaction |
setOpaque(sc: SurfaceControl, isOpaque: Boolean) Indicates whether the surface must be considered opaque, even if its pixel format is set to translucent. |
open SurfaceControl.Transaction |
setPosition(sc: SurfaceControl, x: Float, y: Float) Sets the SurfaceControl to the specified position relative to the parent SurfaceControl |
open SurfaceControl.Transaction |
setScale(sc: SurfaceControl, scaleX: Float, scaleY: Float) Sets the SurfaceControl to the specified scale with (0, 0) as the center point of the scale. |
open SurfaceControl.Transaction |
setTrustedPresentationCallback(sc: SurfaceControl, thresholds: SurfaceControl.TrustedPresentationThresholds, executor: Executor, listener: Consumer<Boolean!>) Sets a callback to receive feedback about the presentation of a |
open SurfaceControl.Transaction |
setVisibility(sc: SurfaceControl, visible: Boolean) Toggle the visibility of a given Layer and it's sub-tree. |
open Unit |
writeToParcel(dest: Parcel, flags: Int) Writes the transaction to parcel, clearing the transaction as if it had been applied so it can be used to store future transactions. |
Properties | |
---|---|
static Parcelable.Creator<SurfaceControl.Transaction!> |
Public constructors
Transaction
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
open fun addTransactionCommittedListener(
executor: Executor,
listener: SurfaceControl.TransactionCommittedListener
): SurfaceControl.Transaction
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 . |
Return | |
---|---|
SurfaceControl.Transaction |
This value cannot be null . |
addTransactionCompletedListener
open fun addTransactionCompletedListener(
executor: Executor,
listener: Consumer<SurfaceControl.TransactionStats!>
): SurfaceControl.Transaction
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<SurfaceControl.TransactionStats!>: The callback that will be invoked when the transaction has been completed. This value cannot be null . |
Return | |
---|---|
SurfaceControl.Transaction |
This value cannot be null . |
apply
open fun apply(): Unit
Apply the transaction, clearing it's state, and making it usable as a new transaction.
clearFrameRate
open fun clearFrameRate(sc: SurfaceControl): SurfaceControl.Transaction
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 . |
Return | |
---|---|
SurfaceControl.Transaction |
This transaction object. This value cannot be null . |
clearTrustedPresentationCallback
open funclearTrustedPresentationCallback(sc: SurfaceControl): SurfaceControl.Transaction
Deprecated: 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 . |
Return | |
---|---|
SurfaceControl.Transaction |
This transaction This value cannot be null . |
close
open fun close(): Unit
Release the native transaction object, without applying it.
Exceptions | |
---|---|
java.lang.Exception |
if this resource cannot be closed |
java.io.IOException |
if an I/O error occurs |
describeContents
open fun describeContents(): Int
Return | |
---|---|
Int |
a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either 0 or android.os.Parcelable#CONTENTS_FILE_DESCRIPTOR |
merge
open fun merge(other: SurfaceControl.Transaction): SurfaceControl.Transaction
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 . |
Return | |
---|---|
SurfaceControl.Transaction |
This transaction. This value cannot be null . |
reparent
open fun reparent(
sc: SurfaceControl,
newParent: SurfaceControl?
): SurfaceControl.Transaction
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 . |
Return | |
---|---|
SurfaceControl.Transaction |
This Transaction This value cannot be null . |
setAlpha
open fun setAlpha(
sc: SurfaceControl,
alpha: Float
): SurfaceControl.Transaction
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 |
Return | |
---|---|
SurfaceControl.Transaction |
This value cannot be null . |
setBuffer
open fun setBuffer(
sc: SurfaceControl,
buffer: HardwareBuffer?
): SurfaceControl.Transaction
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 . |
Return | |
---|---|
SurfaceControl.Transaction |
this This value cannot be null . |
setBuffer
open fun setBuffer(
sc: SurfaceControl,
buffer: HardwareBuffer?,
fence: SyncFence?
): SurfaceControl.Transaction
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 android.opengl.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) |
Return | |
---|---|
SurfaceControl.Transaction |
this This value cannot be null . |
setBuffer
open fun setBuffer(
sc: SurfaceControl,
buffer: HardwareBuffer?,
fence: SyncFence?,
releaseCallback: Consumer<SyncFence!>?
): SurfaceControl.Transaction
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 android.opengl.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 android.media.Image#setFence(SyncFence)
when using android.media.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<SyncFence!>?: 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 . |
Return | |
---|---|
SurfaceControl.Transaction |
this This value cannot be null . |
setBufferSize
open fun setBufferSize(
sc: SurfaceControl,
w: Int,
h: Int
): SurfaceControl.Transaction
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 |
Return | |
---|---|
SurfaceControl.Transaction |
This Transaction This value cannot be null . |
setBufferTransform
open fun setBufferTransform(
sc: SurfaceControl,
transform: Int
): SurfaceControl.Transaction
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 android.view.SurfaceControl#BUFFER_TRANSFORM_IDENTITY , android.view.SurfaceControl#BUFFER_TRANSFORM_MIRROR_HORIZONTAL , android.view.SurfaceControl#BUFFER_TRANSFORM_MIRROR_VERTICAL , android.view.SurfaceControl#BUFFER_TRANSFORM_ROTATE_90 , android.view.SurfaceControl#BUFFER_TRANSFORM_ROTATE_180 , android.view.SurfaceControl#BUFFER_TRANSFORM_ROTATE_270 , BUFFER_TRANSFORM_MIRROR_HORIZONTAL | BUFFER_TRANSFORM_ROTATE_90, or BUFFER_TRANSFORM_MIRROR_VERTICAL | BUFFER_TRANSFORM_ROTATE_90 |
Return | |
---|---|
SurfaceControl.Transaction |
this This value cannot be null . |
setCrop
open fun setCrop(
sc: SurfaceControl,
crop: Rect?
): SurfaceControl.Transaction
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 . |
Return | |
---|---|
SurfaceControl.Transaction |
this This transaction for chaining This value cannot be null . |
setDamageRegion
open fun setDamageRegion(
sc: SurfaceControl,
region: Region?
): SurfaceControl.Transaction
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. |
Return | |
---|---|
SurfaceControl.Transaction |
This value cannot be null . |
setDataSpace
open fun setDataSpace(
sc: SurfaceControl,
dataspace: Int
): SurfaceControl.Transaction
Set the dataspace for the SurfaceControl. This will control how the buffer set with setBuffer(android.view.SurfaceControl,android.hardware.HardwareBuffer)
is displayed.
Return | |
---|---|
SurfaceControl.Transaction |
this This value cannot be null . |
setDesiredHdrHeadroom
open fun setDesiredHdrHeadroom(
sc: SurfaceControl,
desiredRatio: Float
): SurfaceControl.Transaction
Sets the desired HDR headroom for the layer.
Prefer using this API over setExtendedRangeBrightness
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 Must be finite && >= 1.0f or 0.0f. Value is 0.0f or greater |
Return | |
---|---|
SurfaceControl.Transaction |
this This value cannot be null . |
See Also
setDesiredPresentTimeNanos
open fun setDesiredPresentTimeNanos(desiredPresentTimeNanos: Long): SurfaceControl.Transaction
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. |
Return | |
---|---|
SurfaceControl.Transaction |
This transaction This value cannot be null . |
setExtendedRangeBrightness
open fun setExtendedRangeBrightness(
sc: SurfaceControl,
currentBufferRatio: Float,
desiredRatio: Float
): SurfaceControl.Transaction
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 |
Return | |
---|---|
SurfaceControl.Transaction |
this This value cannot be null . |
setFrameRate
open fun setFrameRate(
sc: SurfaceControl,
frameRateParams: Surface.FrameRateParams
): SurfaceControl.Transaction
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 . |
Return | |
---|---|
SurfaceControl.Transaction |
This transaction object. This value cannot be null . |
See Also
setFrameRate
open fun setFrameRate(
sc: SurfaceControl,
frameRate: Float,
compatibility: Int
): SurfaceControl.Transaction
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 android.view.Surface#FRAME_RATE_COMPATIBILITY_DEFAULT , or android.view.Surface#FRAME_RATE_COMPATIBILITY_FIXED_SOURCE |
Return | |
---|---|
SurfaceControl.Transaction |
This value cannot be null . |
setFrameRate
open fun setFrameRate(
sc: SurfaceControl,
frameRate: Float,
compatibility: Int,
changeFrameRateStrategy: Int
): SurfaceControl.Transaction
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 android.view.Surface#FRAME_RATE_COMPATIBILITY_DEFAULT , or android.view.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 android.view.Surface#CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS , or android.view.Surface#CHANGE_FRAME_RATE_ALWAYS |
Return | |
---|---|
SurfaceControl.Transaction |
This transaction object. This value cannot be null . |
See Also
setFrameTimeline
open fun setFrameTimeline(vsyncId: Long): SurfaceControl.Transaction
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. |
Return | |
---|---|
SurfaceControl.Transaction |
This value cannot be null . |
setGeometry
open funsetGeometry(
sc: SurfaceControl,
sourceCrop: Rect?,
destFrame: Rect?,
orientation: Int
): SurfaceControl.Transaction
Deprecated: 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 android.view.Surface#ROTATION_0 , android.view.Surface#ROTATION_90 , android.view.Surface#ROTATION_180 , or android.view.Surface#ROTATION_270 |
Return | |
---|---|
SurfaceControl.Transaction |
This transaction object. This value cannot be null . |
setLayer
open fun setLayer(
sc: SurfaceControl,
z: Int
): SurfaceControl.Transaction
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 |
Return | |
---|---|
SurfaceControl.Transaction |
This Transaction. This value cannot be null . |
setOpaque
open fun setOpaque(
sc: SurfaceControl,
isOpaque: Boolean
): SurfaceControl.Transaction
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
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 |
Return | |
---|---|
SurfaceControl.Transaction |
this This value cannot be null . |
setPosition
open fun setPosition(
sc: SurfaceControl,
x: Float,
y: Float
): SurfaceControl.Transaction
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 |
Return | |
---|---|
SurfaceControl.Transaction |
this transaction This value cannot be null . |
setScale
open fun setScale(
sc: SurfaceControl,
scaleX: Float,
scaleY: Float
): SurfaceControl.Transaction
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 |
Return | |
---|---|
SurfaceControl.Transaction |
this transaction This value cannot be null . |
setTrustedPresentationCallback
open funsetTrustedPresentationCallback(
sc: SurfaceControl,
thresholds: SurfaceControl.TrustedPresentationThresholds,
executor: Executor,
listener: Consumer<Boolean!>
): SurfaceControl.Transaction
Deprecated: Use WindowManager.registerTrustedPresentationListener(IBinder,
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)
b | c | c | c |
o | x | x | x |
o | x | x | x |
o | x | x | x |
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<Boolean!>: The Consumer that will receive the callbacks when entered or exited the threshold. This value cannot be null . |
Return | |
---|---|
SurfaceControl.Transaction |
This transaction This value cannot be null . |
setVisibility
open fun setVisibility(
sc: SurfaceControl,
visible: Boolean
): SurfaceControl.Transaction
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 |
Return | |
---|---|
SurfaceControl.Transaction |
This transaction object. This value cannot be null . |
writeToParcel
open fun writeToParcel(
dest: Parcel,
flags: Int
): Unit
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 android.os.Parcelable#PARCELABLE_WRITE_RETURN_VALUE , and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES |