# SurfaceControl.Builder

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# Builder

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/android/view/SurfaceControl.Builder "View this page in Java")  

```
class Builder
```

|---|----------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                                             ||
| ↳ | [android.view.SurfaceControl.Builder](https://developer.android.com/reference/kotlin/android/view/SurfaceControl.Builder#) |

Builder class for[SurfaceControl](https://developer.android.com/reference/kotlin/android/view/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](https://developer.android.com/reference/kotlin/android/view/SurfaceControl.Builder#setName(kotlin.String))

## Summary

|                                                               Public constructors                                                               ||
|----------------------------------------------------------------------------------------------------------------------------------------------|---|
| [Builder](https://developer.android.com/reference/kotlin/android/view/SurfaceControl.Builder#Builder())`()` Begin building a SurfaceControl. |

|                                                                                                                                                                                                                                                           Public methods                                                                                                                                                                                                                                                            ||
|-------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| open[SurfaceControl](https://developer.android.com/reference/kotlin/android/view/SurfaceControl)                  | [build](https://developer.android.com/reference/kotlin/android/view/SurfaceControl.Builder#build())`()` Construct a new[SurfaceControl](https://developer.android.com/reference/kotlin/android/view/SurfaceControl)with the set parameters.                                                                                                                                                                      |
| open[SurfaceControl.Builder](https://developer.android.com/reference/kotlin/android/view/SurfaceControl.Builder#) | [setBufferSize](https://developer.android.com/reference/kotlin/android/view/SurfaceControl.Builder#setBufferSize(kotlin.Int,%20kotlin.Int))`(`width:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `height:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Set the initial size of the controlled surface's buffers in pixels.                 |
| open[SurfaceControl.Builder](https://developer.android.com/reference/kotlin/android/view/SurfaceControl.Builder#) | [setFormat](https://developer.android.com/reference/kotlin/android/view/SurfaceControl.Builder#setFormat(kotlin.Int))`(`format:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Set the pixel format of the controlled surface's buffers, using constants from[android.graphics.PixelFormat](https://developer.android.com/reference/kotlin/android/graphics/PixelFormat.html#). |
| open[SurfaceControl.Builder](https://developer.android.com/reference/kotlin/android/view/SurfaceControl.Builder#) | [setHidden](https://developer.android.com/reference/kotlin/android/view/SurfaceControl.Builder#setHidden(kotlin.Boolean))`(`hidden:` `[Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`)` Set the initial visibility for the SurfaceControl.                                                                                                                                   |
| open[SurfaceControl.Builder](https://developer.android.com/reference/kotlin/android/view/SurfaceControl.Builder#) | [setName](https://developer.android.com/reference/kotlin/android/view/SurfaceControl.Builder#setName(kotlin.String))`(`name:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`)` Set a debugging-name for the SurfaceControl.                                                                                                                                                  |
| open[SurfaceControl.Builder](https://developer.android.com/reference/kotlin/android/view/SurfaceControl.Builder#) | [setOpaque](https://developer.android.com/reference/kotlin/android/view/SurfaceControl.Builder#setOpaque(kotlin.Boolean))`(`opaque:` `[Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`)` Indicates whether the surface must be considered opaque, even if its pixel format is set to translucent.                                                                             |
| open[SurfaceControl.Builder](https://developer.android.com/reference/kotlin/android/view/SurfaceControl.Builder#) | [setParent](https://developer.android.com/reference/kotlin/android/view/SurfaceControl.Builder#setParent(android.view.SurfaceControl))`(`parent:` `[SurfaceControl](https://developer.android.com/reference/kotlin/android/view/SurfaceControl)?`)` Set a parent surface for our new SurfaceControl.                                                                                                             |

## Public constructors

### Builder

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
Builder()
```

Begin building a SurfaceControl.

## Public methods

### build

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun build(): SurfaceControl
```

Construct a new[SurfaceControl](https://developer.android.com/reference/kotlin/android/view/SurfaceControl)with the set parameters. The builder remains valid.

|                                                          Return                                                           ||
|----------------------------------------------------------------------------------------------|-----------------------------|
| [SurfaceControl](https://developer.android.com/reference/kotlin/android/view/SurfaceControl) | This value cannot be`null`. |

### setBufferSize

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

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

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

|                                                               Parameters                                                                ||
|----------|-------------------------------------------------------------------------------------------------------------------------------|
| `width`  | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):The buffer width in pixels. Value is 0 or greater  |
| `height` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):The buffer height in pixels. Value is 0 or greater |

|                                                                   Return                                                                   ||
|---------------------------------------------------------------------------------------------------------------|-----------------------------|
| [SurfaceControl.Builder](https://developer.android.com/reference/kotlin/android/view/SurfaceControl.Builder#) | This value cannot be`null`. |

### setFormat

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun setFormat(format: Int): SurfaceControl.Builder
```

Set the pixel format of the controlled surface's buffers, using constants from[android.graphics.PixelFormat](https://developer.android.com/reference/kotlin/android/graphics/PixelFormat.html#).

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          Parameters                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           ||
|----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `format` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):Value is[android.graphics.PixelFormat#RGBA_8888](https://developer.android.com/reference/kotlin/android/graphics/PixelFormat.html#RGBA_8888:kotlin.Int),[android.graphics.PixelFormat#RGBX_8888](https://developer.android.com/reference/kotlin/android/graphics/PixelFormat.html#RGBX_8888:kotlin.Int),[android.graphics.PixelFormat#RGBA_F16](https://developer.android.com/reference/kotlin/android/graphics/PixelFormat.html#RGBA_F16:kotlin.Int),[android.graphics.PixelFormat#RGBA_1010102](https://developer.android.com/reference/kotlin/android/graphics/PixelFormat.html#RGBA_1010102:kotlin.Int),[android.graphics.PixelFormat#RGB_888](https://developer.android.com/reference/kotlin/android/graphics/PixelFormat.html#RGB_888:kotlin.Int),[android.graphics.PixelFormat#RGB_565](https://developer.android.com/reference/kotlin/android/graphics/PixelFormat.html#RGB_565:kotlin.Int), or android.graphics.PixelFormat.R_8 |

|                                                                   Return                                                                   ||
|---------------------------------------------------------------------------------------------------------------|-----------------------------|
| [SurfaceControl.Builder](https://developer.android.com/reference/kotlin/android/view/SurfaceControl.Builder#) | This value cannot be`null`. |

### setHidden

Added in[API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun setHidden(hidden: Boolean): SurfaceControl.Builder
```

Set the initial visibility for the SurfaceControl.

|                                                              Parameters                                                               ||
|----------|-----------------------------------------------------------------------------------------------------------------------------|
| `hidden` | [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html):Whether the Surface is initially HIDDEN. |

|                                                                   Return                                                                   ||
|---------------------------------------------------------------------------------------------------------------|-----------------------------|
| [SurfaceControl.Builder](https://developer.android.com/reference/kotlin/android/view/SurfaceControl.Builder#) | This value cannot be`null`. |

### setName

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun setName(name: String): SurfaceControl.Builder
```

Set a debugging-name for the SurfaceControl.

|                                                                            Parameters                                                                             ||
|--------|-----------------------------------------------------------------------------------------------------------------------------------------------------------|
| `name` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html):A name to identify the Surface in debugging. This value cannot be`null`. |

|                                                                   Return                                                                   ||
|---------------------------------------------------------------------------------------------------------------|-----------------------------|
| [SurfaceControl.Builder](https://developer.android.com/reference/kotlin/android/view/SurfaceControl.Builder#) | This value cannot be`null`. |

### setOpaque

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
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](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html):Whether the Surface is OPAQUE. |

|                                                                   Return                                                                   ||
|---------------------------------------------------------------------------------------------------------------|-----------------------------|
| [SurfaceControl.Builder](https://developer.android.com/reference/kotlin/android/view/SurfaceControl.Builder#) | This value cannot be`null`. |

### setParent

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
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](https://developer.android.com/reference/kotlin/android/view/SurfaceControl)?:The parent control. This value may be`null`. |

|                                                                   Return                                                                   ||
|---------------------------------------------------------------------------------------------------------------|-----------------------------|
| [SurfaceControl.Builder](https://developer.android.com/reference/kotlin/android/view/SurfaceControl.Builder#) | This value cannot be`null`. |