# androidx.webgpu.helper

*** ** * ** ***

## Classes

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/webgpu/helper/WebGpu` | A helper class representing a WebGPU environment, encapsulating the instance, adapter, device, and surface. |

## Objects

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/webgpu/helper/GPUAndroidHardwareBufferUtil` |   |
| `https://developer.android.com/reference/kotlin/androidx/webgpu/helper/Util` |   |

## Top-level functions summary

|---|---|
| `suspend https://developer.android.com/reference/kotlin/androidx/webgpu/helper/WebGpu` | `https://developer.android.com/reference/kotlin/androidx/webgpu/helper/package-summary#createWebGpu(android.view.Surface,androidx.webgpu.GPUInstanceDescriptor,androidx.webgpu.GPURequestAdapterOptions,androidx.webgpu.GPUDeviceDescriptor)( surface: https://developer.android.com/reference/android/view/Surface.html?, instanceDescriptor: https://developer.android.com/reference/kotlin/androidx/webgpu/GPUInstanceDescriptor, requestAdapterOptions: https://developer.android.com/reference/kotlin/androidx/webgpu/GPURequestAdapterOptions, deviceDescriptor: https://developer.android.com/reference/kotlin/androidx/webgpu/GPUDeviceDescriptor )` Creates a `https://developer.android.com/reference/kotlin/androidx/webgpu/helper/WebGpu` environment using a newly created default single-threaded dispatcher. |
| `suspend https://developer.android.com/reference/kotlin/androidx/webgpu/helper/WebGpu` | `https://developer.android.com/reference/kotlin/androidx/webgpu/helper/package-summary#createWebGpu(kotlinx.coroutines.CoroutineDispatcher,android.view.Surface,androidx.webgpu.GPUInstanceDescriptor,androidx.webgpu.GPURequestAdapterOptions,androidx.webgpu.GPUDeviceDescriptor)( dispatcher: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/index.html, surface: https://developer.android.com/reference/android/view/Surface.html?, instanceDescriptor: https://developer.android.com/reference/kotlin/androidx/webgpu/GPUInstanceDescriptor, requestAdapterOptions: https://developer.android.com/reference/kotlin/androidx/webgpu/GPURequestAdapterOptions, deviceDescriptor: https://developer.android.com/reference/kotlin/androidx/webgpu/GPUDeviceDescriptor )` Creates a `https://developer.android.com/reference/kotlin/androidx/webgpu/helper/WebGpu` environment using the provided `https://developer.android.com/reference/kotlin/androidx/webgpu/helper/package-summary#createWebGpu(kotlinx.coroutines.CoroutineDispatcher,android.view.Surface,androidx.webgpu.GPUInstanceDescriptor,androidx.webgpu.GPURequestAdapterOptions,androidx.webgpu.GPUDeviceDescriptor)`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/webgpu/helper/package-summary#initLibrary()()` Initializes the native library. |

## Extension functions summary

|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/java/io/InputStream.html.https://developer.android.com/reference/kotlin/androidx/webgpu/helper/package-summary#(java.io.InputStream).asString()()` |
| `suspend https://developer.android.com/reference/android/graphics/Bitmap.html` | `https://developer.android.com/reference/kotlin/androidx/webgpu/GPUTexture.https://developer.android.com/reference/kotlin/androidx/webgpu/helper/package-summary#(androidx.webgpu.GPUTexture).createBitmap(androidx.webgpu.GPUDevice)(device: https://developer.android.com/reference/kotlin/androidx/webgpu/GPUDevice)` |
| `https://developer.android.com/reference/kotlin/androidx/webgpu/GPUTexture` | `https://developer.android.com/reference/android/graphics/Bitmap.html.https://developer.android.com/reference/kotlin/androidx/webgpu/helper/package-summary#(android.graphics.Bitmap).createGpuTexture(androidx.webgpu.GPUDevice)(device: https://developer.android.com/reference/kotlin/androidx/webgpu/GPUDevice)` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html.https://developer.android.com/reference/kotlin/androidx/webgpu/helper/package-summary#(kotlin.Long).roundDownToNearestMultipleOf(kotlin.Int)(boundary: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Helpers for image dimension management. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html.https://developer.android.com/reference/kotlin/androidx/webgpu/helper/package-summary#(kotlin.Int).roundDownToNearestMultipleOf(kotlin.Int)(boundary: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html.https://developer.android.com/reference/kotlin/androidx/webgpu/helper/package-summary#(kotlin.Long).roundUpToNearestMultipleOf(kotlin.Int)(boundary: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html.https://developer.android.com/reference/kotlin/androidx/webgpu/helper/package-summary#(kotlin.Int).roundUpToNearestMultipleOf(kotlin.Int)(boundary: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` |
| `https://developer.android.com/reference/kotlin/androidx/webgpu/GPUColor` | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html.https://developer.android.com/reference/kotlin/androidx/webgpu/helper/package-summary#(kotlin.Int).toGPUColor()()` Converts an Android color integer to a `https://developer.android.com/reference/kotlin/androidx/webgpu/GPUColor`. |
| `https://developer.android.com/reference/kotlin/androidx/webgpu/GPUColor` | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html.https://developer.android.com/reference/kotlin/androidx/webgpu/helper/package-summary#(kotlin.Long).toGPUColor()()` Converts an Android color long to a `https://developer.android.com/reference/kotlin/androidx/webgpu/GPUColor`. |
| `https://developer.android.com/reference/android/hardware/SyncFence.html?` | `@https://developer.android.com/reference/kotlin/androidx/webgpu/ExperimentalWebGpuApi https://developer.android.com/reference/kotlin/androidx/webgpu/GPUSyncFence?.https://developer.android.com/reference/kotlin/androidx/webgpu/helper/package-summary#(androidx.webgpu.GPUSyncFence).toSyncFence()()` Converts to an Android platform `https://developer.android.com/reference/android/hardware/SyncFence.html`. |

## Top-level functions

### createWebGpu

Artifact: [androidx.webgpu:webgpu](https://developer.android.com/jetpack/androidx/releases/webgpu) [View Source](https://cs.android.com/search?q=file:androidx/webgpu/helper/WebGpu.kt+function:createWebGpu)

```
suspend fun createWebGpu(
    surface: Surface? = null,
    instanceDescriptor: GPUInstanceDescriptor = GPUInstanceDescriptor(),
    requestAdapterOptions: GPURequestAdapterOptions = GPURequestAdapterOptions(),
    deviceDescriptor: GPUDeviceDescriptor = defaultDeviceDescriptor
): WebGpu
```

Creates a `https://developer.android.com/reference/kotlin/androidx/webgpu/helper/WebGpu` environment using a newly created default single-threaded dispatcher.

| Parameters |
|---|---|
| `surface: https://developer.android.com/reference/android/view/Surface.html? = null` | An optional Android `https://developer.android.com/reference/android/view/Surface.html` to bind to WebGPU. |
| `instanceDescriptor: https://developer.android.com/reference/kotlin/androidx/webgpu/GPUInstanceDescriptor = GPUInstanceDescriptor()` | Options for configuring the native WebGPU instance. |
| `requestAdapterOptions: https://developer.android.com/reference/kotlin/androidx/webgpu/GPURequestAdapterOptions = GPURequestAdapterOptions()` | Options for selecting the GPU adapter (e.g., backend type). |
| `deviceDescriptor: https://developer.android.com/reference/kotlin/androidx/webgpu/GPUDeviceDescriptor = defaultDeviceDescriptor` | Options for requesting the GPU device. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/webgpu/helper/WebGpu` | A configured `https://developer.android.com/reference/kotlin/androidx/webgpu/helper/WebGpu` instance. |

### createWebGpu

Artifact: [androidx.webgpu:webgpu](https://developer.android.com/jetpack/androidx/releases/webgpu) [View Source](https://cs.android.com/search?q=file:androidx/webgpu/helper/WebGpu.kt+function:createWebGpu)

```
suspend fun createWebGpu(
    dispatcher: CoroutineDispatcher,
    surface: Surface? = null,
    instanceDescriptor: GPUInstanceDescriptor = GPUInstanceDescriptor(),
    requestAdapterOptions: GPURequestAdapterOptions = GPURequestAdapterOptions(),
    deviceDescriptor: GPUDeviceDescriptor = defaultDeviceDescriptor
): WebGpu
```

Creates a `https://developer.android.com/reference/kotlin/androidx/webgpu/helper/WebGpu` environment using the provided `https://developer.android.com/reference/kotlin/androidx/webgpu/helper/package-summary#createWebGpu(kotlinx.coroutines.CoroutineDispatcher,android.view.Surface,androidx.webgpu.GPUInstanceDescriptor,androidx.webgpu.GPURequestAdapterOptions,androidx.webgpu.GPUDeviceDescriptor)`.

| Parameters |
|---|---|
| `dispatcher: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/index.html` | A custom `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/index.html` to use for executing WebGPU JNI operations. Must be single-threaded. |
| `surface: https://developer.android.com/reference/android/view/Surface.html? = null` | An optional Android `https://developer.android.com/reference/android/view/Surface.html` to bind to WebGPU. |
| `instanceDescriptor: https://developer.android.com/reference/kotlin/androidx/webgpu/GPUInstanceDescriptor = GPUInstanceDescriptor()` | Options for configuring the native WebGPU instance. |
| `requestAdapterOptions: https://developer.android.com/reference/kotlin/androidx/webgpu/GPURequestAdapterOptions = GPURequestAdapterOptions()` | Options for selecting the GPU adapter (e.g., backend type). |
| `deviceDescriptor: https://developer.android.com/reference/kotlin/androidx/webgpu/GPUDeviceDescriptor = defaultDeviceDescriptor` | Options for requesting the GPU device. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/webgpu/helper/WebGpu` | A configured `https://developer.android.com/reference/kotlin/androidx/webgpu/helper/WebGpu` instance. |

### initLibrary

Artifact: [androidx.webgpu:webgpu](https://developer.android.com/jetpack/androidx/releases/webgpu) [View Source](https://cs.android.com/search?q=file:androidx/webgpu/helper/WebGpu.kt+function:initLibrary) Added in [1.0.0-alpha06](https://developer.android.com/jetpack/androidx/releases/webgpu#1.0.0-alpha06)

```
fun initLibrary(): Unit
```

Initializes the native library. This method should be called before making and WebGPU calls.

## Extension functions

### InputStream.asString

Artifact: [androidx.webgpu:webgpu](https://developer.android.com/jetpack/androidx/releases/webgpu) [View Source](https://cs.android.com/search?q=file:androidx/webgpu/helper/Streams.kt+function:asString) Added in [1.0.0-alpha06](https://developer.android.com/jetpack/androidx/releases/webgpu#1.0.0-alpha06)

```
fun InputStream.asString(): String
```

### GPUTexture.createBitmap

Artifact: [androidx.webgpu:webgpu](https://developer.android.com/jetpack/androidx/releases/webgpu) [View Source](https://cs.android.com/search?q=file:androidx/webgpu/helper/Textures.kt+function:createBitmap)

```
suspend fun GPUTexture.createBitmap(device: GPUDevice): Bitmap
```

### Bitmap.createGpuTexture

Artifact: [androidx.webgpu:webgpu](https://developer.android.com/jetpack/androidx/releases/webgpu) [View Source](https://cs.android.com/search?q=file:androidx/webgpu/helper/Textures.kt+function:createGpuTexture) Added in [1.0.0-alpha06](https://developer.android.com/jetpack/androidx/releases/webgpu#1.0.0-alpha06)

```
fun Bitmap.createGpuTexture(device: GPUDevice): GPUTexture
```

### Long.roundDownToNearestMultipleOf

Artifact: [androidx.webgpu:webgpu](https://developer.android.com/jetpack/androidx/releases/webgpu) [View Source](https://cs.android.com/search?q=file:androidx/webgpu/helper/Rounding.kt+function:roundDownToNearestMultipleOf) Added in [1.0.0-alpha06](https://developer.android.com/jetpack/androidx/releases/webgpu#1.0.0-alpha06)

```
fun Long.roundDownToNearestMultipleOf(boundary: Int): Long
```

Helpers for image dimension management. Each adds a method to round to the next higher or lower multiple of a value, e.g., "round -1,234 down to the nearest multiple of 1,000" returns -2000.

### Int.roundDownToNearestMultipleOf

Artifact: [androidx.webgpu:webgpu](https://developer.android.com/jetpack/androidx/releases/webgpu) [View Source](https://cs.android.com/search?q=file:androidx/webgpu/helper/Rounding.kt+function:roundDownToNearestMultipleOf) Added in [1.0.0-alpha06](https://developer.android.com/jetpack/androidx/releases/webgpu#1.0.0-alpha06)

```
fun Int.roundDownToNearestMultipleOf(boundary: Int): Int
```

### Long.roundUpToNearestMultipleOf

Artifact: [androidx.webgpu:webgpu](https://developer.android.com/jetpack/androidx/releases/webgpu) [View Source](https://cs.android.com/search?q=file:androidx/webgpu/helper/Rounding.kt+function:roundUpToNearestMultipleOf) Added in [1.0.0-alpha06](https://developer.android.com/jetpack/androidx/releases/webgpu#1.0.0-alpha06)

```
fun Long.roundUpToNearestMultipleOf(boundary: Int): Long
```

### Int.roundUpToNearestMultipleOf

Artifact: [androidx.webgpu:webgpu](https://developer.android.com/jetpack/androidx/releases/webgpu) [View Source](https://cs.android.com/search?q=file:androidx/webgpu/helper/Rounding.kt+function:roundUpToNearestMultipleOf) Added in [1.0.0-alpha06](https://developer.android.com/jetpack/androidx/releases/webgpu#1.0.0-alpha06)

```
fun Int.roundUpToNearestMultipleOf(boundary: Int): Int
```

### Int.toGPUColor

Artifact: [androidx.webgpu:webgpu](https://developer.android.com/jetpack/androidx/releases/webgpu) [View Source](https://cs.android.com/search?q=file:androidx/webgpu/helper/Extensions.kt+function:toGPUColor) Added in [1.0.0-alpha06](https://developer.android.com/jetpack/androidx/releases/webgpu#1.0.0-alpha06)

```
fun Int.toGPUColor(): GPUColor
```

Converts an Android color integer to a `https://developer.android.com/reference/kotlin/androidx/webgpu/GPUColor`.

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/webgpu/GPUColor` | The `https://developer.android.com/reference/kotlin/androidx/webgpu/GPUColor` representation of the integer color. |

### Long.toGPUColor

Artifact: [androidx.webgpu:webgpu](https://developer.android.com/jetpack/androidx/releases/webgpu) [View Source](https://cs.android.com/search?q=file:androidx/webgpu/helper/Extensions.kt+function:toGPUColor) Added in [1.0.0-alpha06](https://developer.android.com/jetpack/androidx/releases/webgpu#1.0.0-alpha06)

```
fun Long.toGPUColor(): GPUColor
```

Converts an Android color long to a `https://developer.android.com/reference/kotlin/androidx/webgpu/GPUColor`.

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/webgpu/GPUColor` | The `https://developer.android.com/reference/kotlin/androidx/webgpu/GPUColor` representation of the long color. |

### GPUSyncFence.toSyncFence

Artifact: [androidx.webgpu:webgpu](https://developer.android.com/jetpack/androidx/releases/webgpu) [View Source](https://cs.android.com/search?q=file:androidx/webgpu/helper/Extensions.kt+function:toSyncFence) Added in [1.0.0-alpha06](https://developer.android.com/jetpack/androidx/releases/webgpu#1.0.0-alpha06)

```
@ExperimentalWebGpuApi
fun GPUSyncFence?.toSyncFence(): SyncFence?
```

Converts to an Android platform `https://developer.android.com/reference/android/hardware/SyncFence.html`.

Safely handles API level compatibility internally. On devices below Android T (API 33), this function will safely return `null` without requiring API version checks at the call site.