Skip to content

Commit

Permalink
[osx/videosync] - move calls to displaylink init/deinit into the vsyn…
Browse files Browse the repository at this point in the history
…c thread and make sure that init is only called once the display reset is done - same as GLX does
  • Loading branch information
Memphiz committed May 18, 2015
1 parent 0f32a2f commit b1e3ebe
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
42 changes: 30 additions & 12 deletions xbmc/video/videosync/VideoSyncOsx.cpp
Expand Up @@ -34,35 +34,44 @@
bool CVideoSyncOsx::Setup(PUPDATECLOCK func)
{
CLog::Log(LOGDEBUG, "CVideoSyncOsx::%s setting up OSX", __FUNCTION__);
bool setupOk = false;

//init the vblank timestamp
m_LastVBlankTime = CurrentHostCounter();
UpdateClock = func;
m_abort = false;

setupOk = InitDisplayLink();
if (setupOk)
{
g_Windowing.Register(this);
}
m_displayLost = false;
m_displayReset = false;
m_lostEvent.Reset();

g_Windowing.Register(this);

return setupOk;
return true;
}

void CVideoSyncOsx::Run(volatile bool& stop)
{
InitDisplayLink();

//because cocoa has a vblank callback, we just keep sleeping until we're asked to stop the thread
while(!stop && !m_abort)
while(!stop && !m_displayLost && !m_displayReset)
{
Sleep(100);
}

m_lostEvent.Set();

while(!stop && m_displayLost && !m_displayReset)
{
Sleep(10);
}

DeinitDisplayLink();
}

void CVideoSyncOsx::Cleanup()
{
CLog::Log(LOGDEBUG, "CVideoSyncOsx::%s cleaning up OSX", __FUNCTION__);
DeinitDisplayLink();
m_lostEvent.Set();
m_LastVBlankTime = 0;
g_Windowing.Unregister(this);
}

Expand All @@ -73,9 +82,18 @@ float CVideoSyncOsx::GetFps()
return m_fps;
}

void CVideoSyncOsx::OnLostDevice()
{
if (!m_displayLost)
{
m_displayLost = true;
m_lostEvent.WaitMSec(1000);
}
}

void CVideoSyncOsx::OnResetDevice()
{
m_abort = true;
m_displayReset = true;
}

void CVideoSyncOsx::VblankHandler(int64_t nowtime)
Expand Down
8 changes: 6 additions & 2 deletions xbmc/video/videosync/VideoSyncOsx.h
Expand Up @@ -22,12 +22,13 @@
#if defined(TARGET_DARWIN_OSX)
#include "VideoSync.h"
#include "guilib/DispResource.h"
#include "threads/Event.h"

class CVideoSyncOsx : public CVideoSync, IDispResource
{
public:

CVideoSyncOsx() : m_LastVBlankTime(0), m_abort(false){}
CVideoSyncOsx() : m_LastVBlankTime(0), m_displayLost(false), m_displayReset(false){}

// CVideoSync interface
virtual bool Setup(PUPDATECLOCK func);
Expand All @@ -36,6 +37,7 @@ class CVideoSyncOsx : public CVideoSync, IDispResource
virtual float GetFps();

// IDispResource interface
virtual void OnLostDevice();
virtual void OnResetDevice();

// used in the displaylink callback
Expand All @@ -46,7 +48,9 @@ class CVideoSyncOsx : public CVideoSync, IDispResource
virtual void DeinitDisplayLink();

int64_t m_LastVBlankTime; //timestamp of the last vblank, used for calculating how many vblanks happened
volatile bool m_abort;
volatile bool m_displayLost;
volatile bool m_displayReset;
CEvent m_lostEvent;
};

#endif// TARGET_DARWIN_OSX

0 comments on commit b1e3ebe

Please sign in to comment.