@@ -3134,7 +3134,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
31343134 & self ,
31353135 surface_id : id:: SurfaceId ,
31363136 adapter_id : id:: AdapterId ,
3137- ) -> Result < Vec < TextureFormat > , instance:: GetSurfacePreferredFormatError > {
3137+ ) -> Result < Vec < TextureFormat > , instance:: GetSurfaceSupportError > {
31383138 profiling:: scope!( "Surface::get_supported_formats" ) ;
31393139 let hub = A :: hub ( self ) ;
31403140 let mut token = Token :: root ( ) ;
@@ -3143,13 +3143,33 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
31433143 let ( adapter_guard, mut _token) = hub. adapters . read ( & mut token) ;
31443144 let adapter = adapter_guard
31453145 . get ( adapter_id)
3146- . map_err ( |_| instance:: GetSurfacePreferredFormatError :: InvalidAdapter ) ?;
3146+ . map_err ( |_| instance:: GetSurfaceSupportError :: InvalidAdapter ) ?;
31473147 let surface = surface_guard
31483148 . get ( surface_id)
3149- . map_err ( |_| instance:: GetSurfacePreferredFormatError :: InvalidSurface ) ?;
3149+ . map_err ( |_| instance:: GetSurfaceSupportError :: InvalidSurface ) ?;
31503150
31513151 surface. get_supported_formats ( adapter)
31523152 }
3153+ pub fn surface_get_supported_modes < A : HalApi > (
3154+ & self ,
3155+ surface_id : id:: SurfaceId ,
3156+ adapter_id : id:: AdapterId ,
3157+ ) -> Result < Vec < wgt:: PresentMode > , instance:: GetSurfaceSupportError > {
3158+ profiling:: scope!( "Surface::get_supported_modes" ) ;
3159+ let hub = A :: hub ( self ) ;
3160+ let mut token = Token :: root ( ) ;
3161+
3162+ let ( surface_guard, mut token) = self . surfaces . read ( & mut token) ;
3163+ let ( adapter_guard, mut _token) = hub. adapters . read ( & mut token) ;
3164+ let adapter = adapter_guard
3165+ . get ( adapter_id)
3166+ . map_err ( |_| instance:: GetSurfaceSupportError :: InvalidAdapter ) ?;
3167+ let surface = surface_guard
3168+ . get ( surface_id)
3169+ . map_err ( |_| instance:: GetSurfaceSupportError :: InvalidSurface ) ?;
3170+
3171+ surface. get_supported_modes ( adapter)
3172+ }
31533173
31543174 pub fn device_features < A : HalApi > (
31553175 & self ,
@@ -4955,11 +4975,40 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
49554975 ) ;
49564976 }
49574977 if !caps. present_modes . contains ( & config. present_mode ) {
4958- log:: warn!(
4959- "Surface does not support present mode: {:?}, falling back to FIFO" ,
4960- config. present_mode,
4978+ let new_mode = loop {
4979+ // Automatic present mode checks.
4980+ //
4981+ // The "Automatic" modes are never supported by the backends.
4982+ match config. present_mode {
4983+ wgt:: PresentMode :: AutoVsync => {
4984+ if caps. present_modes . contains ( & wgt:: PresentMode :: FifoRelaxed ) {
4985+ break wgt:: PresentMode :: FifoRelaxed ;
4986+ }
4987+ if caps. present_modes . contains ( & wgt:: PresentMode :: Fifo ) {
4988+ break wgt:: PresentMode :: Fifo ;
4989+ }
4990+ }
4991+ wgt:: PresentMode :: AutoNoVsync => {
4992+ if caps. present_modes . contains ( & wgt:: PresentMode :: Immediate ) {
4993+ break wgt:: PresentMode :: Immediate ;
4994+ }
4995+ if caps. present_modes . contains ( & wgt:: PresentMode :: Mailbox ) {
4996+ break wgt:: PresentMode :: Mailbox ;
4997+ }
4998+ }
4999+ _ => { }
5000+ }
5001+ return Err ( E :: UnsupportedPresentMode {
5002+ requested : config. present_mode ,
5003+ available : caps. present_modes . clone ( ) ,
5004+ } ) ;
5005+ } ;
5006+
5007+ log:: info!(
5008+ "Automatically choosing presentation mode by rule {:?}. Chose {new_mode:?}" ,
5009+ config. present_mode
49615010 ) ;
4962- config. present_mode = wgt :: PresentMode :: Fifo ;
5011+ config. present_mode = new_mode ;
49635012 }
49645013 if !caps. formats . contains ( & config. format ) {
49655014 return Err ( E :: UnsupportedFormat {
0 commit comments