From fa6bb53142e2c79e90d26eb3a64c759e271a09f0 Mon Sep 17 00:00:00 2001 From: Till Wegmueller Date: Tue, 7 Apr 2026 18:11:47 +0200 Subject: [PATCH] Fix pixel format: pass ARGB8888 directly as BGRA8 On little-endian x86, ARGB8888 bytes in memory are [B,G,R,A] which matches wgpu's Bgra8Unorm layout. No byte swapping needed. --- crates/wrclient/src/display.rs | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/crates/wrclient/src/display.rs b/crates/wrclient/src/display.rs index a21736a..3077d47 100644 --- a/crates/wrclient/src/display.rs +++ b/crates/wrclient/src/display.rs @@ -246,8 +246,10 @@ impl Display { /// Upload framebuffer pixel data to the GPU texture. /// - /// `pixel_data` is ARGB8888 format from the server (PixmanRenderer). - /// This method converts to BGRA8 for the GPU texture. + /// `pixel_data` is ARGB8888 from the server (PixmanRenderer on + /// little-endian x86). In memory this is `[B, G, R, A]` per pixel, + /// which matches wgpu's `Bgra8Unorm` layout directly — no conversion + /// needed. pub fn update_frame(&self, pixel_data: &[u8]) { let expected = (self.width * self.height * 4) as usize; if pixel_data.len() != expected { @@ -258,18 +260,9 @@ impl Display { return; } - // Convert ARGB8888 → BGRA8: [A,R,G,B] → [B,G,R,A] - let mut bgra = Vec::with_capacity(pixel_data.len()); - for pixel in pixel_data.chunks_exact(4) { - bgra.push(pixel[3]); // B - bgra.push(pixel[2]); // G - bgra.push(pixel[1]); // R - bgra.push(pixel[0]); // A - } - self.queue.write_texture( self.frame_texture.as_image_copy(), - &bgra, + pixel_data, wgpu::TexelCopyBufferLayout { offset: 0, bytes_per_row: Some(self.width * 4),