@@ -104,28 +104,27 @@ - (void)waitForVSync:(uintptr_t)baton {
104104 TRACE_VSYNC (" VSyncRequest" , _pending_baton.value_or (0 ));
105105
106106 CFTimeInterval tick_interval = _displayLink.nominalOutputRefreshPeriod ;
107- NSLog (@" >> TICK INTERVAL %f " , tick_interval);
108107 if (_displayLink.paused || tick_interval == 0 ) {
109108 // When starting display link the first notification will come in the middle
110109 // of next frame, which would incur a whole frame period of latency.
111110 // To avoid that, first vsync notification will be fired using a timer
112111 // scheduled to fire where the next frame is expected to start.
113112 // Also use a timer if display link does not belong to any display
114113 // (nominalOutputRefreshPeriod being 0)
115- CFTimeInterval phase = fmod (_lastTargetTimestamp, tick_interval);
116- CFTimeInterval now = CACurrentMediaTime ();
117- CFTimeInterval start = now - (fmod (now, tick_interval)) + phase;
118- if (start < now) {
119- start += tick_interval;
114+ CFTimeInterval delay = 0 ;
115+ if (tick_interval != 0 && _lastTargetTimestamp != 0 ) {
116+ CFTimeInterval phase = fmod (_lastTargetTimestamp, tick_interval);
117+ CFTimeInterval now = CACurrentMediaTime ();
118+ CFTimeInterval start = now - (fmod (now, tick_interval)) + phase;
119+ if (start < now) {
120+ start += tick_interval;
121+ }
122+ delay = start - now;
120123 }
121- CFTimeInterval delay = start - now;
122-
123- NSLog (@" Scheduling timer in %f " , delay);
124124
125125 NSTimer * timer = [NSTimer timerWithTimeInterval: delay
126126 repeats: NO
127127 block: ^(NSTimer * timer) {
128- NSLog (@" Firing synthesized vsync" );
129128 CFTimeInterval timestamp = CACurrentMediaTime ();
130129 CFTimeInterval targetTimestamp =
131130 timestamp + tick_interval;
0 commit comments