GPU: phương thức getPreferredCanvasFormat()

Limited availability

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 getPreferredCanvasFormat() của giao diện GPU trả về định dạng texture canvas tối ưu để hiển thị nội dung có độ sâu 8 bit, dải động tiêu chuẩn trên hệ thống hiện tại.

Phương thức này thường được dùng để cung cấp cho lệnh gọi GPUCanvasContext.configure() giá trị format tối ưu cho hệ thống hiện tại. Điều này được khuyến nghị - nếu bạn không dùng định dạng được ưu tiên khi cấu hình canvas context, bạn có thể phát sinh thêm chi phí, chẳng hạn như các bản sao texture bổ sung, tùy theo nền tảng.

Cú pháp

js
getPreferredCanvasFormat()

Tham số

Không có.

Giá trị trả về

Một chuỗi cho biết định dạng texture canvas. Giá trị có thể là rgba8unorm hoặc bgra8unorm.

Ngoại lệ

Không có.

Ví dụ

js
const canvas = document.querySelector("#gpuCanvas");
const context = canvas.getContext("webgpu");

context.configure({
  device,
  format: navigator.gpu.getPreferredCanvasFormat(),
  alphaMode: "premultiplied",
});

Đặc tả

Specification
WebGPU
# dom-gpu-getpreferredcanvasformat

Tương thích trình duyệt

Xem thêm