winemac: Check the display link running state as well as the window count to decide whether to start/stop it.

The display link may be stopped even if there are associated windows, due to
idleness.  So, it may need to be started when a window is added even if it's
not the first window.

Signed-off-by: Ken Thomases <ken@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Ken Thomases 2017-12-08 02:54:06 -06:00 committed by Alexandre Julliard
parent 20aaf167dd
commit fd6f2a1781
1 changed files with 8 additions and 8 deletions

View File

@ -218,25 +218,25 @@ - (void) dealloc
- (void) addWindow:(WineWindow*)window - (void) addWindow:(WineWindow*)window
{ {
BOOL needsStart; BOOL firstWindow;
@synchronized(self) { @synchronized(self) {
needsStart = !_windows.count; firstWindow = !_windows.count;
[_windows addObject:window]; [_windows addObject:window];
} }
if (needsStart) if (firstWindow || !CVDisplayLinkIsRunning(_link))
CVDisplayLinkStart(_link); CVDisplayLinkStart(_link);
} }
- (void) removeWindow:(WineWindow*)window - (void) removeWindow:(WineWindow*)window
{ {
BOOL shouldStop = FALSE; BOOL lastWindow = FALSE;
@synchronized(self) { @synchronized(self) {
BOOL wasRunning = _windows.count > 0; BOOL hadWindows = _windows.count > 0;
[_windows removeObject:window]; [_windows removeObject:window];
if (wasRunning && !_windows.count) if (hadWindows && !_windows.count)
shouldStop = TRUE; lastWindow = TRUE;
} }
if (shouldStop) if (lastWindow && CVDisplayLinkIsRunning(_link))
CVDisplayLinkStop(_link); CVDisplayLinkStop(_link);
} }