@@ -348,11 +348,13 @@ impl NodeRuntime {
348348 // Configure the surface at physical resolution (for HiDPI displays)
349349 let surface_inner = & surface. surface . inner ;
350350 let surface_caps = surface_inner. get_capabilities ( & executor. context . adapter ) ;
351+ // Use the surface's preferred format (Firefox WebGL prefers Bgra8Unorm, Chrome prefers Rgba8Unorm)
352+ let surface_format = surface_caps. formats . iter ( ) . copied ( ) . find ( |f| f. is_srgb ( ) ) . unwrap_or ( surface_caps. formats [ 0 ] ) ;
351353 surface_inner. configure (
352354 & executor. context . device ,
353355 & vello:: wgpu:: SurfaceConfiguration {
354356 usage : vello:: wgpu:: TextureUsages :: RENDER_ATTACHMENT | vello:: wgpu:: TextureUsages :: COPY_DST ,
355- format : vello :: wgpu :: TextureFormat :: Rgba8Unorm ,
357+ format : surface_format ,
356358 width : physical_resolution. x ,
357359 height : physical_resolution. y ,
358360 present_mode : surface_caps. present_modes [ 0 ] ,
@@ -365,21 +367,11 @@ impl NodeRuntime {
365367 let surface_texture = surface_inner. get_current_texture ( ) . expect ( "Failed to get surface texture" ) ;
366368 self . current_viewport_texture = Some ( image_texture. clone ( ) ) ;
367369
368- encoder. copy_texture_to_texture (
369- vello:: wgpu:: TexelCopyTextureInfoBase {
370- texture : image_texture. texture . as_ref ( ) ,
371- mip_level : 0 ,
372- origin : Default :: default ( ) ,
373- aspect : Default :: default ( ) ,
374- } ,
375- vello:: wgpu:: TexelCopyTextureInfoBase {
376- texture : & surface_texture. texture ,
377- mip_level : 0 ,
378- origin : Default :: default ( ) ,
379- aspect : Default :: default ( ) ,
380- } ,
381- image_texture. texture . size ( ) ,
382- ) ;
370+ // Use the blitter to copy the texture to the surface, handling format conversion
371+ // (e.g., Rgba8Unorm source to Bgra8Unorm surface on Firefox)
372+ let source_view = image_texture. texture . create_view ( & vello:: wgpu:: TextureViewDescriptor :: default ( ) ) ;
373+ let target_view = surface_texture. texture . create_view ( & vello:: wgpu:: TextureViewDescriptor :: default ( ) ) ;
374+ surface. surface . blitter . copy ( & executor. context . device , & mut encoder, & source_view, & target_view) ;
383375
384376 executor. context . queue . submit ( [ encoder. finish ( ) ] ) ;
385377 surface_texture. present ( ) ;
0 commit comments