feat(unstable): implement navigator.gpu.getPreferredCanvasFormat() (#22149)

This commit is contained in:
Divy Srivastava 2024-01-27 23:10:09 +05:30 committed by GitHub
parent bde2028d83
commit cc0a372127
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 16 additions and 0 deletions

View file

@ -247,6 +247,11 @@ Deno.test({
Deno.close(Number(resources[resources.length - 1]));
});
Deno.test(function getPreferredCanvasFormat() {
const preferredFormat = navigator.gpu.getPreferredCanvasFormat();
assert(preferredFormat === "bgra8unorm" || preferredFormat === "rgba8unorm");
});
async function checkIsWsl() {
return Deno.build.os === "linux" && await hasMicrosoftProcVersion();

View file

@ -78,6 +78,7 @@ declare class GPU {
requestAdapter(
options?: GPURequestAdapterOptions,
): Promise<GPUAdapter | null>;
getPreferredCanvasFormat(): GPUTextureFormat;
}
/** @category WebGPU */

View file

@ -344,6 +344,16 @@ class GPU {
}
}
getPreferredCanvasFormat() {
// Same as Gecko.
//
// https://github.com/mozilla/gecko-dev/blob/b75080bb8b11844d18cb5f9ac6e68a866ef8e243/dom/webgpu/Instance.h#L42-L47
if (core.build.os == "android") {
return "rgba8unorm";
}
return "bgra8unorm";
}
[SymbolFor("Deno.privateCustomInspect")](inspect, inspectOptions) {
return `${this.constructor.name} ${inspect({}, inspectOptions)}`;
}