@@ -895,6 +895,23 @@ impl WindowSurface {
895
895
surface
896
896
} ;
897
897
898
+ // VSync defaults to enabled; disable it if it was not requested.
899
+ if !ctx. pixel_format . vsync {
900
+ let _guard = MakeCurrentGuard :: new (
901
+ * * ctx. display ,
902
+ surface,
903
+ surface,
904
+ ctx. context ,
905
+ )
906
+ . map_err ( |err| CreationError :: OsError ( err) ) ?;
907
+
908
+ unsafe {
909
+ if egl. SwapInterval ( * * ctx. display , 0 ) == ffi:: egl:: FALSE {
910
+ panic ! ( "finish_impl: eglSwapInterval failed: 0x{:x}" , egl. GetError ( ) ) ;
911
+ }
912
+ }
913
+ }
914
+
898
915
Ok ( WindowSurface {
899
916
display : Arc :: clone ( & ctx. display ) ,
900
917
pixel_format : ctx. pixel_format . clone ( ) ,
@@ -1211,7 +1228,42 @@ where
1211
1228
) ) ;
1212
1229
}
1213
1230
1214
- if num_configs == 0 {
1231
+ // We're interested in those configs which allow our desired VSync.
1232
+ let desired_swap_interval = if cb. pf_reqs . vsync {
1233
+ 1
1234
+ } else {
1235
+ 0
1236
+ } ;
1237
+
1238
+ let config_ids = config_ids. into_iter ( ) . filter ( |& config| {
1239
+ let mut min_swap_interval = 0 ;
1240
+ let res = egl. GetConfigAttrib (
1241
+ display,
1242
+ config,
1243
+ ffi:: egl:: MIN_SWAP_INTERVAL as ffi:: egl:: types:: EGLint ,
1244
+ & mut min_swap_interval,
1245
+ ) ;
1246
+
1247
+ if desired_swap_interval < min_swap_interval {
1248
+ return false ;
1249
+ }
1250
+
1251
+ let mut max_swap_interval = 0 ;
1252
+ let res = egl. GetConfigAttrib (
1253
+ display,
1254
+ config,
1255
+ ffi:: egl:: MAX_SWAP_INTERVAL as ffi:: egl:: types:: EGLint ,
1256
+ & mut max_swap_interval,
1257
+ ) ;
1258
+
1259
+ if desired_swap_interval > max_swap_interval {
1260
+ return false ;
1261
+ }
1262
+
1263
+ true
1264
+ } ) . collect :: < Vec < _ > > ( ) ;
1265
+
1266
+ if config_ids. is_empty ( ) {
1215
1267
return Err ( CreationError :: NoAvailablePixelFormat ) ;
1216
1268
}
1217
1269
0 commit comments