Added in API level 29

Builder


class Builder
kotlin.Any
   ↳ android.view.SurfaceControl.Builder

Builder class for SurfaceControl objects. By default the surface will be hidden, and have "unset" bounds, meaning it can be as large as the bounds of its parent if a buffer or child so requires. It is necessary to set at least a name via Builder.setName

Summary

Public constructors

Begin building a SurfaceControl.

Public methods
open SurfaceControl

Construct a new SurfaceControl with the set parameters.

open SurfaceControl.Builder
setBufferSize(width: Int, height: Int)

Set the initial size of the controlled surface's buffers in pixels.

open SurfaceControl.Builder
setFormat(format: Int)

Set the pixel format of the controlled surface's buffers, using constants from android.graphics.PixelFormat.

open SurfaceControl.Builder
setHidden(hidden: Boolean)

Set the initial visibility for the SurfaceControl.

open SurfaceControl.Builder
setName(name: String)

Set a debugging-name for the SurfaceControl.

open SurfaceControl.Builder
setOpaque(opaque: Boolean)

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

open SurfaceControl.Builder

Set a parent surface for our new SurfaceControl.

Public constructors

Builder

Added in API level 29
Builder()

Begin building a SurfaceControl.

Public methods

build

Added in API level 29
open fun build(): SurfaceControl

Construct a new SurfaceControl with the set parameters. The builder remains valid.

Return
SurfaceControl This value cannot be null.

setBufferSize

Added in API level 29
open fun setBufferSize(
    width: Int,
    height: Int
): SurfaceControl.Builder

Set the initial size of the controlled surface's buffers in pixels.

Parameters
width Int: The buffer width in pixels. Value is 0 or greater
height Int: The buffer height in pixels. Value is 0 or greater
Return
SurfaceControl.Builder This value cannot be null.

setFormat

Added in API level 29
open fun setFormat(format: Int): SurfaceControl.Builder

Set the pixel format of the controlled surface's buffers, using constants from android.graphics.PixelFormat.

Parameters
format Int: Value is android.graphics.PixelFormat#RGBA_8888, android.graphics.PixelFormat#RGBX_8888, android.graphics.PixelFormat#RGBA_F16, android.graphics.PixelFormat#RGBA_1010102, android.graphics.PixelFormat#RGB_888, android.graphics.PixelFormat#RGB_565, or android.graphics.PixelFormat.R_8
Return
SurfaceControl.Builder This value cannot be null.

setHidden

Added in API level 33
open fun setHidden(hidden: Boolean): SurfaceControl.Builder

Set the initial visibility for the SurfaceControl.

Parameters
hidden Boolean: Whether the Surface is initially HIDDEN.
Return
SurfaceControl.Builder This value cannot be null.

setName

Added in API level 29
open fun setName(name: String): SurfaceControl.Builder

Set a debugging-name for the SurfaceControl.

Parameters
name String: A name to identify the Surface in debugging. This value cannot be null.
Return
SurfaceControl.Builder This value cannot be null.

setOpaque

Added in API level 29
open fun setOpaque(opaque: Boolean): SurfaceControl.Builder

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
opaque Boolean: Whether the Surface is OPAQUE.
Return
SurfaceControl.Builder This value cannot be null.

setParent

Added in API level 29
open fun setParent(parent: SurfaceControl?): SurfaceControl.Builder

Set a parent surface for our new SurfaceControl. Child surfaces are constrained to the onscreen region of their parent. Furthermore they stack relatively in Z order, and inherit the transformation of the parent.

Parameters
parent SurfaceControl?: The parent control. This value may be null.
Return
SurfaceControl.Builder This value cannot be null.