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

const Long

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

const Long

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

Public functions

java-static Long
@AnyThread
getWGPUProcGetProcAddress(
    majorVersion: @IntRange(from = 0, to = 16777215) Int,
    minorVersion: @IntRange(from = 0, to = 1099511627775) Long
)

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

Constants

ERROR_APP_TOO_OLD

const val ERROR_APP_TOO_OLD = -1: Long

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

ERROR_WEBVIEW_TOO_OLD

const val ERROR_WEBVIEW_TOO_OLD = 0: Long

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

Public functions

getWGPUProcGetProcAddress

@AnyThread
java-static fun getWGPUProcGetProcAddress(
    majorVersion: @IntRange(from = 0, to = 16777215) Int,
    minorVersion: @IntRange(from = 0, to = 1099511627775) Long
): Long

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
majorVersion: @IntRange(from = 0, to = 16777215) Int

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

minorVersion: @IntRange(from = 0, to = 1099511627775) Long

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.