androidx.webgpu.helper


Classes

WebGpu

A helper class representing a WebGPU environment, encapsulating the instance, adapter, device, and surface.

Objects

Top-level functions summary

suspend WebGpu
createWebGpu(
    surface: Surface?,
    instanceDescriptor: GPUInstanceDescriptor,
    requestAdapterOptions: GPURequestAdapterOptions,
    deviceDescriptor: GPUDeviceDescriptor
)

Creates a WebGpu environment using a newly created default single-threaded dispatcher.

suspend WebGpu
createWebGpu(
    dispatcher: CoroutineDispatcher,
    surface: Surface?,
    instanceDescriptor: GPUInstanceDescriptor,
    requestAdapterOptions: GPURequestAdapterOptions,
    deviceDescriptor: GPUDeviceDescriptor
)

Creates a WebGpu environment using the provided dispatcher.

Unit

Initializes the native library.

Extension functions summary

String
suspend Bitmap
GPUTexture
Long

Helpers for image dimension management.

Int
Long
Int
GPUColor

Converts an Android color integer to a GPUColor.

GPUColor

Converts an Android color long to a GPUColor.

SyncFence?

Converts to an Android platform SyncFence.

Top-level functions

createWebGpu

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

Creates a WebGpu environment using a newly created default single-threaded dispatcher.

Parameters
surface: Surface? = null

An optional Android Surface to bind to WebGPU.

instanceDescriptor: GPUInstanceDescriptor = GPUInstanceDescriptor()

Options for configuring the native WebGPU instance.

requestAdapterOptions: GPURequestAdapterOptions = GPURequestAdapterOptions()

Options for selecting the GPU adapter (e.g., backend type).

deviceDescriptor: GPUDeviceDescriptor = defaultDeviceDescriptor

Options for requesting the GPU device.

Returns
WebGpu

A configured WebGpu instance.

createWebGpu

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

Creates a WebGpu environment using the provided dispatcher.

Parameters
dispatcher: CoroutineDispatcher

A custom CoroutineDispatcher to use for executing WebGPU JNI operations. Must be single-threaded.

surface: Surface? = null

An optional Android Surface to bind to WebGPU.

instanceDescriptor: GPUInstanceDescriptor = GPUInstanceDescriptor()

Options for configuring the native WebGPU instance.

requestAdapterOptions: GPURequestAdapterOptions = GPURequestAdapterOptions()

Options for selecting the GPU adapter (e.g., backend type).

deviceDescriptor: GPUDeviceDescriptor = defaultDeviceDescriptor

Options for requesting the GPU device.

Returns
WebGpu

A configured WebGpu instance.

initLibrary

fun initLibrary(): Unit

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

Extension functions

InputStream.asString

fun InputStream.asString(): String

GPUTexture.createBitmap

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

Bitmap.createGpuTexture

fun Bitmap.createGpuTexture(device: GPUDevice): GPUTexture

Long.roundDownToNearestMultipleOf

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

fun Int.roundDownToNearestMultipleOf(boundary: Int): Int

Long.roundUpToNearestMultipleOf

fun Long.roundUpToNearestMultipleOf(boundary: Int): Long

Int.roundUpToNearestMultipleOf

fun Int.roundUpToNearestMultipleOf(boundary: Int): Int

Int.toGPUColor

fun Int.toGPUColor(): GPUColor

Converts an Android color integer to a GPUColor.

Returns
GPUColor

The GPUColor representation of the integer color.

Long.toGPUColor

fun Long.toGPUColor(): GPUColor

Converts an Android color long to a GPUColor.

Returns
GPUColor

The GPUColor representation of the long color.

GPUSyncFence.toSyncFence

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

Converts to an Android platform SyncFence.

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.