The GPUCanvasContext
interface of the WebGPU API represents the WebGPU rendering context of a <canvas>
element, returned via an HTMLCanvasElement.getContext()
call with a contextType
of "webgpu"
.
Instance properties
canvas
Experimental Read only
-
Returns a reference to the canvas that the context was created from.
Instance methods
configure()
Experimental
-
Configures the context to use for rendering with a given GPUDevice
and clears the canvas to transparent black.
getCurrentTexture()
Experimental
-
Returns the next GPUTexture
to be composited to the document by the canvas context.
unconfigure()
Experimental
-
Removes any previously-set context configuration, and destroys any textures produced while the canvas context was configured.
Examples
const canvas = document.querySelector("#gpuCanvas");
const context = canvas.getContext("webgpu");
context.configure({
device: device,
format: navigator.gpu.getPreferredCanvasFormat(),
alphaMode: "premultiplied",
});
Specifications
Browser compatibility
|
Desktop |
Mobile |
|
Chrome |
Edge |
Firefox |
Internet Explorer |
Opera |
Safari |
WebView Android |
Chrome Android |
Firefox for Android |
Opera Android |
Safari on IOS |
Samsung Internet |
GPUCanvasContext |
113Currently supported on ChromeOS, macOS, and Windows only.
|
113Currently supported on ChromeOS, macOS, and Windows only.
|
previewCurrently supported on Linux and Windows only.
|
No |
99Currently supported on ChromeOS, macOS, and Windows only.
|
No |
No |
No |
No |
No |
No |
No |
canvas |
113Currently supported on ChromeOS, macOS, and Windows only.
|
113Currently supported on ChromeOS, macOS, and Windows only.
|
previewCurrently supported on Linux and Windows only.
|
No |
99Currently supported on ChromeOS, macOS, and Windows only.
|
No |
No |
No |
No |
No |
No |
No |
configure |
113["Currently supported on ChromeOS, macOS, and Windows only.", "The rgba8unorm format is currently not supported on macOS. See bug 1298618."]
|
113["Currently supported on ChromeOS, macOS, and Windows only.", "The rgba8unorm format is currently not supported on macOS. See bug 1298618."]
|
previewCurrently supported on Linux and Windows only.
|
No |
99["Currently supported on ChromeOS, macOS, and Windows only.", "The rgba8unorm format is currently not supported on macOS. See bug 1298618."]
|
No |
No |
No |
No |
No |
No |
No |
getCurrentTexture |
113Currently supported on ChromeOS, macOS, and Windows only.
|
113Currently supported on ChromeOS, macOS, and Windows only.
|
previewCurrently supported on Linux and Windows only.
|
No |
99Currently supported on ChromeOS, macOS, and Windows only.
|
No |
No |
No |
No |
No |
No |
No |
unconfigure |
113Currently supported on ChromeOS, macOS, and Windows only.
|
113Currently supported on ChromeOS, macOS, and Windows only.
|
previewCurrently supported on Linux and Windows only.
|
No |
99Currently supported on ChromeOS, macOS, and Windows only.
|
No |
No |
No |
No |
No |
No |
No |
See also