W3cubDocs

/Web APIs

GPUCanvasContext

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

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

js

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

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/GPUCanvasContext