@@ -320,9 +320,9 @@ impl Timings {
320320 }
321321 }
322322
323- pub fn past_min_presentation_time ( & self , clock : & Clock < Monotonic > ) -> bool {
323+ pub fn past_min_render_time ( & self , clock : & Clock < Monotonic > ) -> bool {
324324 let now: Duration = clock. now ( ) . into ( ) ;
325- let Some ( refresh_interval_ns ) = self . min_refresh_interval_ns else {
325+ let Some ( min_refresh_interval_ns ) = self . min_refresh_interval_ns else {
326326 return true ;
327327 } ;
328328 let Some ( last_presentation_time) : Option < Duration > = self
@@ -333,13 +333,29 @@ impl Timings {
333333 return true ;
334334 } ;
335335
336- let refresh_interval_ns = refresh_interval_ns . get ( ) ;
336+ let min_refresh_interval_ns = min_refresh_interval_ns . get ( ) ;
337337 if now <= last_presentation_time {
338338 return false ;
339339 }
340340
341- let next = last_presentation_time + Duration :: from_nanos ( refresh_interval_ns) ;
342- now >= next
341+ const MIN_MARGIN : Duration = Duration :: from_millis ( 3 ) ;
342+ let baseline = if let Some ( refresh_interval_ns) = self . refresh_interval_ns {
343+ MIN_MARGIN . max ( Duration :: from_nanos ( refresh_interval_ns. get ( ) / 2 ) )
344+ } else {
345+ MIN_MARGIN
346+ } ;
347+
348+ let next_presentation_time =
349+ last_presentation_time + Duration :: from_nanos ( min_refresh_interval_ns) ;
350+ let deadline = next_presentation_time. saturating_sub (
351+ if let Some ( avg_submittime) = self . avg_submittime ( SAMPLE_TIME_WINDOW ) {
352+ avg_submittime
353+ } else {
354+ baseline
355+ } + BASE_SAFETY_MARGIN ,
356+ ) ;
357+
358+ now >= deadline
343359 }
344360
345361 pub fn next_render_time ( & self , clock : & Clock < Monotonic > ) -> Duration {
0 commit comments