public final class WebGPU


Provides access to the Dawn implementation of WebGPU packaged in Android System WebView.

Most apps should use the androidx.webgpu library instead of calling this class directly.

Summary

Constants

static final long

Returned by getWGPUProcGetProcAddress when WebView no longer supports the requested Dawn major version.

static final long

Returned by getWGPUProcGetProcAddress when WebView does not expose WebGPU or its Dawn version is older than requested.

Public methods

static long
@AnyThread
getWGPUProcGetProcAddress(
    @IntRange(from = 0, to = 16777215) int majorVersion,
    @IntRange(from = 0, to = 1099511627775) long minorVersion
)

Returns the native WGPUProcGetProcAddress function pointer (see webgpu.h) from WebView when it supports the requested Dawn version.

Constants

ERROR_APP_TOO_OLD

public static final long ERROR_APP_TOO_OLD = -1

Returned by getWGPUProcGetProcAddress when WebView no longer supports the requested Dawn major version.

ERROR_WEBVIEW_TOO_OLD

public static final long ERROR_WEBVIEW_TOO_OLD = 0

Returned by getWGPUProcGetProcAddress when WebView does not expose WebGPU or its Dawn version is older than requested.

Public methods

getWGPUProcGetProcAddress

@AnyThread
public static long getWGPUProcGetProcAddress(
    @IntRange(from = 0, to = 16777215) int majorVersion,
    @IntRange(from = 0, to = 1099511627775) long minorVersion
)

Returns the native WGPUProcGetProcAddress function pointer (see webgpu.h) from WebView when it supports the requested Dawn version.

Native C/C++ code casts a positive return value to WGPUProcGetProcAddress to look up WebGPU functions. The returned pointer is valid for the lifetime of the process. Values <= 0 are error codes and must not be cast to a pointer.

Dawn uses a 24-bit unsigned major version (fits in int) and a 40-bit unsigned minor version (needs long).

Parameters
@IntRange(from = 0, to = 16777215) int majorVersion

exact Dawn major version required (0 to 2^24 - 1).

@IntRange(from = 0, to = 1099511627775) long minorVersion

minimum Dawn minor version required (0 to 2^40 - 1).

Returns
long

a positive function pointer address if compatible, ERROR_WEBVIEW_TOO_OLD, or ERROR_APP_TOO_OLD.

Throws
java.lang.IllegalArgumentException

if majorVersion or minorVersion is out of range.