GPUCanvasContext: getConfiguration() method
Khả dụng hạn chế
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Note: This feature is available in Web Workers.
Phương thức getConfiguration() của giao diện GPUCanvasContext trả về cấu hình hiện tại được đặt cho ngữ cảnh.
Cú pháp
js
getConfiguration()
Tham số
Không có.
Giá trị trả về
Đối tượng chứa các tùy chọn cấu hình được đặt trên ngữ cảnh (tức là qua phương thức GPUCanvasContext.configure()), hoặc null nếu không có cấu hình nào được đặt (hoặc không có cấu hình nào đã được đặt trước đó, hoặc cấu hình đã được đặt rồi GPUCanvasContext.unconfigure() đã được gọi trên ngữ cảnh).
Ví dụ
js
const canvas = document.querySelector("canvas");
const context = canvas.getContext("webgpu");
if (!navigator.gpu) {
throw Error("WebGPU not supported.");
}
const adapter = await navigator.gpu.requestAdapter();
if (!adapter) {
throw Error("Couldn't request WebGPU adapter.");
}
const device = await adapter.requestDevice();
context.configure({
device,
format: navigator.gpu.getPreferredCanvasFormat(),
alphaMode: "premultiplied",
});
console.log(context.getConfiguration());
/* Logs something like:
{
"alphaMode": "premultiplied",
"colorSpace": "srgb",
"device": { ... },
"format": "bgra8unorm",
"toneMapping": {
"mode": "standard"
},
"usage": 16,
"viewFormats": []
}
*/
Thông số kỹ thuật
| Thông số kỹ thuật |
|---|
| WebGPU> # dom-gpucanvascontext-getconfiguration> |