From 1d9204b4b1b94575fdfd19efdc8389e23ad3e3f1 Mon Sep 17 00:00:00 2001 From: Ashwin Naren Date: Wed, 21 May 2025 13:07:00 -0700 Subject: [PATCH] Return the proper texture format for GetPreferredCanvasFormat (#37073) This follows firefox's implementation: https://github.com/mozilla-firefox/firefox/blob/24d49101ce17b78c3ba1217d00297fe2891be6b3/dom/webgpu/Instance.h#L68 It changes the default on most systems to `Bgra8Unorm` but leaves it as `Rgba8Unorm` on android. Signed-off-by: Ashwin Naren --- components/script/dom/webgpu/gpu.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/components/script/dom/webgpu/gpu.rs b/components/script/dom/webgpu/gpu.rs index 20380e07bfb..b2534cda9a8 100644 --- a/components/script/dom/webgpu/gpu.rs +++ b/components/script/dom/webgpu/gpu.rs @@ -86,8 +86,12 @@ impl GPUMethods for GPU { /// fn GetPreferredCanvasFormat(&self) -> GPUTextureFormat { - // TODO: real implementation - GPUTextureFormat::Rgba8unorm + // From https://github.com/mozilla-firefox/firefox/blob/24d49101ce17b78c3ba1217d00297fe2891be6b3/dom/webgpu/Instance.h#L68 + if cfg!(target_os = "android") { + GPUTextureFormat::Rgba8unorm + } else { + GPUTextureFormat::Bgra8unorm + } } ///