[Windows] Fix driver version detection of AMD RDNA+ GPU on Windows 10
[xbmc.git] / xbmc / windowing / tvos / VideoSyncTVos.cpp
blob1e4170756fac7e027f02bfd4dfd3e6cfb69bbf44
1 /*
2 * Copyright (C) 2015-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "VideoSyncTVos.h"
11 #include "cores/VideoPlayer/VideoReferenceClock.h"
12 #include "utils/MathUtils.h"
13 #include "utils/TimeUtils.h"
14 #include "utils/log.h"
15 #include "windowing/GraphicContext.h"
16 #import "windowing/tvos/WinSystemTVOS.h"
18 bool CVideoSyncTVos::Setup()
20 CLog::Log(LOGDEBUG, "CVideoSyncTVos::{} setting up TVOS", __FUNCTION__);
22 //init the vblank timestamp
23 m_LastVBlankTime = CurrentHostCounter();
24 m_abortEvent.Reset();
26 bool setupOk = InitDisplayLink();
27 if (setupOk)
29 m_winSystem.Register(this);
32 return setupOk;
35 void CVideoSyncTVos::Run(CEvent& stopEvent)
37 //because cocoa has a vblank callback, we just keep sleeping until we're asked to stop the thread
38 XbmcThreads::CEventGroup waitGroup{&stopEvent, &m_abortEvent};
39 waitGroup.wait();
42 void CVideoSyncTVos::Cleanup()
44 CLog::Log(LOGDEBUG, "CVideoSyncTVos::{} cleaning up TVOS", __FUNCTION__);
45 DeinitDisplayLink();
46 m_winSystem.Unregister(this);
49 float CVideoSyncTVos::GetFps()
51 m_fps = CServiceBroker::GetWinSystem()->GetGfxContext().GetFPS();
52 CLog::Log(LOGDEBUG, "CVideoSyncTVos::{} Detected refreshrate: {} hertz", __FUNCTION__, m_fps);
53 return m_fps;
56 void CVideoSyncTVos::OnResetDisplay()
58 m_abortEvent.Set();
61 void CVideoSyncTVos::TVosVblankHandler()
63 int64_t nowtime = CurrentHostCounter();
65 //calculate how many vblanks happened
66 double VBlankTime =
67 static_cast<double>(nowtime - m_LastVBlankTime) / static_cast<double>(CurrentHostFrequency());
68 int NrVBlanks = MathUtils::round_int(VBlankTime * static_cast<double>(m_fps));
70 //save the timestamp of this vblank so we can calculate how many happened next time
71 m_LastVBlankTime = nowtime;
73 //update the vblank timestamp, update the clock and send a signal that we got a vblank
74 m_refClock->UpdateClock(NrVBlanks, nowtime);
77 bool CVideoSyncTVos::InitDisplayLink()
79 bool ret = true;
80 CLog::Log(LOGDEBUG, "CVideoSyncTVos: setting up displaylink");
81 if (!m_winSystem.InitDisplayLink(this))
83 CLog::Log(LOGDEBUG, "CVideoSyncTVos: InitDisplayLink failed");
84 ret = false;
86 return ret;
89 void CVideoSyncTVos::DeinitDisplayLink()
91 m_winSystem.DeinitDisplayLink();