SurfaceControl.Builder


public static class SurfaceControl.Builder
extends Object

java.lang.Object
   ↳ 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

Builder()

Begin building a SurfaceControl.

Public methods

SurfaceControl build()

Construct a new SurfaceControl with the set parameters.

SurfaceControl.Builder setBufferSize(int width, int height)

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

SurfaceControl.Builder setFormat(int format)

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

SurfaceControl.Builder setHidden(boolean hidden)

Set the initial visibility for the SurfaceControl.

SurfaceControl.Builder setName(String name)

Set a debugging-name for the SurfaceControl.

SurfaceControl.Builder setOpaque(boolean opaque)

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

SurfaceControl.Builder setParent(SurfaceControl parent)

Set a parent surface for our new SurfaceControl.

Inherited methods

Public constructors

Builder

Added in API level 29
public Builder ()

Begin building a SurfaceControl.

Public methods

build

Added in API level 29
public SurfaceControl build ()

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

Returns
SurfaceControl This value cannot be null.

setBufferSize

Added in API level 29
public SurfaceControl.Builder setBufferSize (int width, 
                int height)

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

Returns
SurfaceControl.Builder This value cannot be null.

setFormat

Added in API level 29
public SurfaceControl.Builder setFormat (int format)

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

Parameters
format int: Value is PixelFormat.RGBA_8888, PixelFormat.RGBX_8888, PixelFormat.RGBA_F16, PixelFormat.RGBA_1010102, PixelFormat.RGB_888, PixelFormat.RGB_565, or android.graphics.PixelFormat.R_8

Returns
SurfaceControl.Builder This value cannot be null.

setHidden

Added in API level 33
public SurfaceControl.Builder setHidden (boolean hidden)

Set the initial visibility for the SurfaceControl.

Parameters
hidden boolean: Whether the Surface is initially HIDDEN.

Returns
SurfaceControl.Builder This value cannot be null.

setName

Added in API level 29
public SurfaceControl.Builder setName (String name)

Set a debugging-name for the SurfaceControl.

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

Returns
SurfaceControl.Builder This value cannot be null.

setOpaque

Added in API level 29
public SurfaceControl.Builder setOpaque (boolean opaque)

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.

Returns
SurfaceControl.Builder This value cannot be null.

setParent

Added in API level 29
public SurfaceControl.Builder setParent (SurfaceControl parent)

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.

Returns
SurfaceControl.Builder This value cannot be null.