Skip to content

Commit

Permalink
feat(unstable): implement navigator.gpu.getPreferredCanvasFormat() (d…
Browse files Browse the repository at this point in the history
  • Loading branch information
littledivy authored Jan 27, 2024
1 parent bde2028 commit cc0a372
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cli/tests/unit/webgpu_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
1 change: 1 addition & 0 deletions cli/tsc/dts/lib.deno_webgpu.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ declare class GPU {
requestAdapter(
options?: GPURequestAdapterOptions,
): Promise<GPUAdapter | null>;
getPreferredCanvasFormat(): GPUTextureFormat;
}

/** @category WebGPU */
Expand Down
10 changes: 10 additions & 0 deletions ext/webgpu/01_webgpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`;
}
Expand Down

0 comments on commit cc0a372

Please sign in to comment.