GPU:getPreferredCanvasFormat() 方法
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
GPU
接口的 getPreferredCanvasFormat()
方法返回用于当前系统上显示 8 位色深、标准动态范围(SDR)内容的最佳 canvas 纹理格式。
这通常用于为当前系统提供 GPUCanvasContext.configure()
调用的最佳 format
值。这是推荐的——如果你没有在配置 canvas 上下文时使用最佳的格式,可能会产生开销,例如根据平台而异的额外纹理的复制。
语法
js
getPreferredCanvasFormat()
参数
无。
返回值
一个字符串,表示 canvas 的纹理格式。该值可以是 rgba8unorm
或 bgra8unorm
。
异常
无。
示例
js
const canvas = document.querySelector("#gpuCanvas");
const context = canvas.getContext("webgpu");
context.configure({
device: device,
format: navigator.gpu.getPreferredCanvasFormat(),
alphaMode: "premultiplied",
});
规范
Specification |
---|
WebGPU # dom-gpu-getpreferredcanvasformat |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | server | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
getPreferredCanvasFormat |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- Partial support
- Partial support
- In development. Supported in a pre-release version.
- In development. Supported in a pre-release version.
- No support
- No support
- Experimental. Expect behavior to change in the future.
- See implementation notes.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.