diff options
author | davilla <davilla@svn> | 2009-10-10 02:30:56 +0000 |
---|---|---|
committer | davilla <davilla@svn> | 2009-10-10 02:30:56 +0000 |
commit | 65d883781132b229d57637596fb84d71d38894b7 (patch) | |
tree | 3c75dfb198295e5c423c04ad4be1345e99ed22ec | |
parent | a8194e926f9d59fea108afd63c272fe678e6a085 (diff) |
[all] another winapi nuke, QueryPerformanceCounter/QueryPerformanceFrequency replaced with CurrentHostCounter/CurrentHostFrequency, uses int64_t instead of LARGE_INTEGER. Need Linux/Win build testing.
git-svn-id: https://xbmc.svn.sourceforge.net/svnroot/xbmc/trunk@23569 568bbfeb-2a22-0410-94d2-cc84cf5bfa90
-rw-r--r-- | guilib/GUIControlProfiler.cpp | 731 | ||||
-rw-r--r-- | guilib/GUIControlProfiler.h | 4 | ||||
-rw-r--r-- | guilib/GUIWindow.cpp | 28 | ||||
-rw-r--r-- | guilib/TextureManager.cpp | 24 | ||||
-rw-r--r-- | xbmc/Application.cpp | 12 | ||||
-rw-r--r-- | xbmc/Credits.cpp | 22 | ||||
-rw-r--r-- | xbmc/RenderSystemGL.cpp | 9 | ||||
-rw-r--r-- | xbmc/Util.cpp | 6 | ||||
-rw-r--r-- | xbmc/VideoReferenceClock.cpp | 102 | ||||
-rw-r--r-- | xbmc/VideoReferenceClock.h | 4 | ||||
-rw-r--r-- | xbmc/cores/VideoRenderers/RenderManager.cpp | 2 | ||||
-rw-r--r-- | xbmc/cores/dvdplayer/DVDClock.cpp | 76 | ||||
-rw-r--r-- | xbmc/cores/dvdplayer/DVDClock.h | 12 | ||||
-rw-r--r-- | xbmc/cores/dvdplayer/DVDPlayerAudio.cpp | 15 | ||||
-rw-r--r-- | xbmc/cores/dvdplayer/DVDPlayerAudio.h | 4 | ||||
-rw-r--r-- | xbmc/linux/XTimeUtils.cpp | 33 | ||||
-rw-r--r-- | xbmc/linux/XTimeUtils.h | 3 | ||||
-rw-r--r-- | xbmc/utils/BitstreamStats.cpp | 20 | ||||
-rw-r--r-- | xbmc/utils/BitstreamStats.h | 7 | ||||
-rw-r--r-- | xbmc/utils/PerformanceSample.cpp | 32 | ||||
-rw-r--r-- | xbmc/utils/PerformanceSample.h | 4 | ||||
-rw-r--r-- | xbmc/utils/Stopwatch.cpp | 9 | ||||
-rw-r--r-- | xbmc/utils/TimeUtils.cpp | 30 | ||||
-rw-r--r-- | xbmc/utils/TimeUtils.h | 4 |
24 files changed, 591 insertions, 602 deletions
diff --git a/guilib/GUIControlProfiler.cpp b/guilib/GUIControlProfiler.cpp index 4435189d4f..121e5be566 100644 --- a/guilib/GUIControlProfiler.cpp +++ b/guilib/GUIControlProfiler.cpp @@ -1,368 +1,363 @@ -/*
- * Copyright (C) 2005-2009 Team XBMC
- * http://www.xbmc.org
- *
- * This Program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This Program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with XBMC; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- */
-
-#include "GUIControlProfiler.h"
-#include "tinyXML/tinyxml.h"
-
-bool CGUIControlProfiler::m_bIsRunning = false;
-
-CGUIControlProfilerItem::CGUIControlProfilerItem(CGUIControlProfiler *pProfiler, CGUIControlProfilerItem *pParent, CGUIControl *pControl)
-: m_pProfiler(pProfiler), m_pParent(pParent), m_pControl(pControl), m_visTime(0), m_renderTime(0)
-{
- if (m_pControl)
- {
- m_controlID = m_pControl->GetID();
- m_ControlType = m_pControl->GetControlType();
- m_strDescription = m_pControl->GetDescription();
- }
- else
- {
- m_controlID = 0;
- m_ControlType = CGUIControl::GUICONTROL_UNKNOWN;
- }
-}
-
-CGUIControlProfilerItem::~CGUIControlProfilerItem(void)
-{
- Reset(NULL);
-}
-
-void CGUIControlProfilerItem::Reset(CGUIControlProfiler *pProfiler)
-{
- m_controlID = 0;
- m_ControlType = CGUIControl::GUICONTROL_UNKNOWN;
- m_pControl = NULL;
-
- m_visTime = 0;
- m_renderTime = 0;
- const unsigned int dwSize = m_vecChildren.size();
- for (unsigned int i=0; i<dwSize; ++i)
- delete m_vecChildren[i];
- m_vecChildren.clear();
-
- m_pProfiler = pProfiler;
-}
-
-void CGUIControlProfilerItem::BeginVisibility(void)
-{
- QueryPerformanceCounter(&m_i64VisStart);
-}
-
-void CGUIControlProfilerItem::EndVisibility(void)
-{
- LARGE_INTEGER t2;
- QueryPerformanceCounter(&t2);
- m_visTime += (unsigned int)(m_pProfiler->m_fPerfScale * (t2.QuadPart - m_i64VisStart.QuadPart));
-}
-
-void CGUIControlProfilerItem::BeginRender(void)
-{
- QueryPerformanceCounter(&m_i64RenderStart);
-}
-
-void CGUIControlProfilerItem::EndRender(void)
-{
- LARGE_INTEGER t2;
- QueryPerformanceCounter(&t2);
- m_renderTime += (unsigned int)(m_pProfiler->m_fPerfScale * (t2.QuadPart - m_i64RenderStart.QuadPart));
-}
-
-void CGUIControlProfilerItem::SaveToXML(TiXmlElement *parent)
-{
- TiXmlElement *xmlControl = new TiXmlElement("control");
- parent->LinkEndChild(xmlControl);
-
- const char *lpszType = NULL;
- switch (m_ControlType)
- {
- case CGUIControl::GUICONTROL_BUTTON:
- lpszType = "button"; break;
- case CGUIControl::GUICONTROL_CHECKMARK:
- lpszType = "checkmark"; break;
- case CGUIControl::GUICONTROL_FADELABEL:
- lpszType = "fadelabel"; break;
- case CGUIControl::GUICONTROL_IMAGE:
- case CGUIControl::GUICONTROL_BORDEREDIMAGE:
- lpszType = "image"; break;
- case CGUIControl::GUICONTROL_LARGE_IMAGE:
- lpszType = "largeimage"; break;
- case CGUIControl::GUICONTROL_LABEL:
- lpszType = "label"; break;
- case CGUIControl::GUICONTROL_LISTGROUP:
- lpszType = "group"; break;
- case CGUIControl::GUICONTROL_PROGRESS:
- lpszType = "progress"; break;
- case CGUIControl::GUICONTROL_RADIO:
- lpszType = "radiobutton"; break;
- case CGUIControl::GUICONTROL_RSS:
- lpszType = "rss"; break;
- case CGUIControl::GUICONTROL_SELECTBUTTON:
- lpszType = "selectbutton"; break;
- case CGUIControl::GUICONTROL_SLIDER:
- lpszType = "slider"; break;
- case CGUIControl::GUICONTROL_SETTINGS_SLIDER:
- lpszType = "sliderex"; break;
- case CGUIControl::GUICONTROL_SPIN:
- lpszType = "spincontrol"; break;
- case CGUIControl::GUICONTROL_SPINEX:
- lpszType = "spincontrolex"; break;
- case CGUIControl::GUICONTROL_TEXTBOX:
- lpszType = "textbox"; break;
- case CGUIControl::GUICONTROL_TOGGLEBUTTON:
- lpszType = "togglebutton"; break;
- case CGUIControl::GUICONTROL_VIDEO:
- lpszType = "videowindow"; break;
- case CGUIControl::GUICONTROL_MOVER:
- lpszType = "mover"; break;
- case CGUIControl::GUICONTROL_RESIZE:
- lpszType = "resize"; break;
- case CGUIControl::GUICONTROL_BUTTONBAR:
- lpszType = "buttonscroller"; break;
- case CGUIControl::GUICONTROL_EDIT:
- lpszType = "edit"; break;
- case CGUIControl::GUICONTROL_VISUALISATION:
- lpszType = "visualisation"; break;
- case CGUIControl::GUICONTROL_MULTI_IMAGE:
- lpszType = "multiimage"; break;
- case CGUIControl::GUICONTROL_GROUP:
- lpszType = "group"; break;
- case CGUIControl::GUICONTROL_GROUPLIST:
- lpszType = "grouplist"; break;
- case CGUIControl::GUICONTROL_SCROLLBAR:
- lpszType = "scrollbar"; break;
- case CGUIControl::GUICONTROL_LISTLABEL:
- lpszType = "label"; break;
- case CGUIControl::GUICONTROL_MULTISELECT:
- lpszType = "multiselect"; break;
- case CGUIControl::GUICONTAINER_LIST:
- lpszType = "list"; break;
- case CGUIControl::GUICONTAINER_WRAPLIST:
- lpszType = "wraplist"; break;
- case CGUIControl::GUICONTAINER_FIXEDLIST:
- lpszType = "fixedlist"; break;
- case CGUIControl::GUICONTAINER_PANEL:
- lpszType = "panel"; break;
- //case CGUIControl::GUICONTROL_LIST:
- //case CGUIControl::GUICONTROL_UNKNOWN:
- //case CGUIControl::GUICONTROL_LISTEX:
- //case CGUIControl::GUICONTROL_SPINBUTTON:
- //case CGUIControl::GUICONTROL_THUMBNAIL:
- //case CGUIControl::GUICONTROL_CONSOLE:
- default:
- break;
- }
-
- if (lpszType)
- xmlControl->SetAttribute("type", lpszType);
- if (m_controlID != 0)
- {
- CStdString str;
- str.Format("%u", m_controlID);
- xmlControl->SetAttribute("id", str.c_str());
- }
-
- float pct = (float)GetTotalTime() / (float)m_pProfiler->GetTotalTime();
- if (pct > 0.01f)
- {
- CStdString str;
- str.Format("%.0f", pct * 100.0f);
- xmlControl->SetAttribute("percent", str.c_str());
- }
-
- if (!m_strDescription.IsEmpty())
- {
- TiXmlElement *elem = new TiXmlElement("description");
- xmlControl->LinkEndChild(elem);
- TiXmlText *text = new TiXmlText(m_strDescription.c_str());
- elem->LinkEndChild(text);
- }
-
- // Note time is stored in 1/100 milliseconds but reported in ms
- unsigned int vis = m_visTime / 100;
- unsigned int rend = m_renderTime / 100;
- if (vis || rend)
- {
- CStdString val;
- TiXmlElement *elem = new TiXmlElement("rendertime");
- xmlControl->LinkEndChild(elem);
- val.Format("%u", rend);
- TiXmlText *text = new TiXmlText(val.c_str());
- elem->LinkEndChild(text);
-
- elem = new TiXmlElement("visibletime");
- xmlControl->LinkEndChild(elem);
- val.Format("%u", vis);
- text = new TiXmlText(val.c_str());
- elem->LinkEndChild(text);
- }
-
- if (m_vecChildren.size())
- {
- TiXmlElement *xmlChilds = new TiXmlElement("children");
- xmlControl->LinkEndChild(xmlChilds);
- const unsigned int dwSize = m_vecChildren.size();
- for (unsigned int i=0; i<dwSize; ++i)
- m_vecChildren[i]->SaveToXML(xmlChilds);
- }
-}
-
-CGUIControlProfilerItem *CGUIControlProfilerItem::AddControl(CGUIControl *pControl)
-{
- m_vecChildren.push_back(new CGUIControlProfilerItem(m_pProfiler, this, pControl));
- return m_vecChildren.back();
-}
-
-CGUIControlProfilerItem *CGUIControlProfilerItem::FindOrAddControl(CGUIControl *pControl, bool recurse)
-{
- const unsigned int dwSize = m_vecChildren.size();
- for (unsigned int i=0; i<dwSize; ++i)
- {
- CGUIControlProfilerItem *p = m_vecChildren[i];
- if (p->m_pControl == pControl)
- return p;
- if (recurse && (p = p->FindOrAddControl(pControl, true)))
- return p;
- }
-
- if (pControl->GetParentControl() == m_pControl)
- return AddControl(pControl);
-
- return NULL;
-}
-
-CGUIControlProfiler::CGUIControlProfiler(void)
-: m_ItemHead(NULL, NULL, NULL), m_pLastItem(NULL), m_iMaxFrameCount(200)
-// m_bIsRunning(false), no isRunning because it is static
-{
- LARGE_INTEGER i64PerfFreq;
- QueryPerformanceFrequency(&i64PerfFreq);
- m_fPerfScale = 100000.0f / i64PerfFreq.QuadPart;
-}
-
-CGUIControlProfiler &CGUIControlProfiler::Instance(void)
-{
- static CGUIControlProfiler _instance;
- return _instance;
-}
-
-bool CGUIControlProfiler::IsRunning(void)
-{
- return m_bIsRunning;
-}
-
-void CGUIControlProfiler::Start(void)
-{
- m_iFrameCount = 0;
- m_bIsRunning = true;
- m_pLastItem = NULL;
- m_ItemHead.Reset(this);
-}
-
-void CGUIControlProfiler::BeginVisibility(CGUIControl *pControl)
-{
- CGUIControlProfilerItem *item = FindOrAddControl(pControl);
- item->BeginVisibility();
-}
-
-void CGUIControlProfiler::EndVisibility(CGUIControl *pControl)
-{
- CGUIControlProfilerItem *item = FindOrAddControl(pControl);
- item->EndVisibility();
-}
-
-void CGUIControlProfiler::BeginRender(CGUIControl *pControl)
-{
- CGUIControlProfilerItem *item = FindOrAddControl(pControl);
- item->BeginRender();
-}
-
-void CGUIControlProfiler::EndRender(CGUIControl *pControl)
-{
- CGUIControlProfilerItem *item = FindOrAddControl(pControl);
- item->EndRender();
-}
-
-CGUIControlProfilerItem *CGUIControlProfiler::FindOrAddControl(CGUIControl *pControl)
-{
- if (m_pLastItem)
- {
- // Typically calls come in pairs so the last control we found is probably
- // the one we want again next time
- if (m_pLastItem->m_pControl == pControl)
- return m_pLastItem;
- // If that control is not a match, usually the one we want is the next
- // sibling of that control, or the parent of that control so check
- // the parent first as it is more convenient
- m_pLastItem = m_pLastItem->m_pParent;
- if (m_pLastItem && m_pLastItem->m_pControl == pControl)
- return m_pLastItem;
- // continued from above, this searches the original control's siblings
- if (m_pLastItem)
- m_pLastItem = m_pLastItem->FindOrAddControl(pControl, false);
- if (m_pLastItem)
- return m_pLastItem;
- }
-
- m_pLastItem = m_ItemHead.FindOrAddControl(pControl, true);
- if (!m_pLastItem)
- m_pLastItem = m_ItemHead.AddControl(pControl);
-
- return m_pLastItem;
-}
-
-void CGUIControlProfiler::EndFrame(void)
-{
- m_iFrameCount++;
- if (m_iFrameCount >= m_iMaxFrameCount)
- {
- const unsigned int dwSize = m_ItemHead.m_vecChildren.size();
- for (unsigned int i=0; i<dwSize; ++i)
- {
- CGUIControlProfilerItem *p = m_ItemHead.m_vecChildren[i];
- m_ItemHead.m_visTime += p->m_visTime;
- m_ItemHead.m_renderTime += p->m_renderTime;
- }
-
- m_bIsRunning = false;
- if (SaveResults())
- m_ItemHead.Reset(this);
- }
-}
-
-bool CGUIControlProfiler::SaveResults(void)
-{
- if (m_strOutputFile.IsEmpty())
- return false;
-
- TiXmlDocument doc;
- TiXmlDeclaration decl("1.0", "", "yes");
- doc.InsertEndChild(decl);
-
- TiXmlElement *root = new TiXmlElement("guicontrolprofiler");
- CStdString str;
- str.Format("%d", m_iFrameCount);
- root->SetAttribute("framecount", str.c_str());
- root->SetAttribute("timeunit", "ms");
- doc.LinkEndChild(root);
-
- m_ItemHead.SaveToXML(root);
- return doc.SaveFile(m_strOutputFile);
-}
+/* + * Copyright (C) 2005-2009 Team XBMC + * http://www.xbmc.org + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * http://www.gnu.org/copyleft/gpl.html + * + */ + +#include "GUIControlProfiler.h" +#include "tinyXML/tinyxml.h" +#include "utils/TimeUtils.h" + +bool CGUIControlProfiler::m_bIsRunning = false; + +CGUIControlProfilerItem::CGUIControlProfilerItem(CGUIControlProfiler *pProfiler, CGUIControlProfilerItem *pParent, CGUIControl *pControl) +: m_pProfiler(pProfiler), m_pParent(pParent), m_pControl(pControl), m_visTime(0), m_renderTime(0) +{ + if (m_pControl) + { + m_controlID = m_pControl->GetID(); + m_ControlType = m_pControl->GetControlType(); + m_strDescription = m_pControl->GetDescription(); + } + else + { + m_controlID = 0; + m_ControlType = CGUIControl::GUICONTROL_UNKNOWN; + } +} + +CGUIControlProfilerItem::~CGUIControlProfilerItem(void) +{ + Reset(NULL); +} + +void CGUIControlProfilerItem::Reset(CGUIControlProfiler *pProfiler) +{ + m_controlID = 0; + m_ControlType = CGUIControl::GUICONTROL_UNKNOWN; + m_pControl = NULL; + + m_visTime = 0; + m_renderTime = 0; + const unsigned int dwSize = m_vecChildren.size(); + for (unsigned int i=0; i<dwSize; ++i) + delete m_vecChildren[i]; + m_vecChildren.clear(); + + m_pProfiler = pProfiler; +} + +void CGUIControlProfilerItem::BeginVisibility(void) +{ + m_i64VisStart = CurrentHostCounter(); +} + +void CGUIControlProfilerItem::EndVisibility(void) +{ + m_visTime += (unsigned int)(m_pProfiler->m_fPerfScale * (CurrentHostCounter() - m_i64VisStart)); +} + +void CGUIControlProfilerItem::BeginRender(void) +{ + m_i64RenderStart = CurrentHostCounter(); +} + +void CGUIControlProfilerItem::EndRender(void) +{ + m_renderTime += (unsigned int)(m_pProfiler->m_fPerfScale * (CurrentHostCounter() - m_i64RenderStart)); +} + +void CGUIControlProfilerItem::SaveToXML(TiXmlElement *parent) +{ + TiXmlElement *xmlControl = new TiXmlElement("control"); + parent->LinkEndChild(xmlControl); + + const char *lpszType = NULL; + switch (m_ControlType) + { + case CGUIControl::GUICONTROL_BUTTON: + lpszType = "button"; break; + case CGUIControl::GUICONTROL_CHECKMARK: + lpszType = "checkmark"; break; + case CGUIControl::GUICONTROL_FADELABEL: + lpszType = "fadelabel"; break; + case CGUIControl::GUICONTROL_IMAGE: + case CGUIControl::GUICONTROL_BORDEREDIMAGE: + lpszType = "image"; break; + case CGUIControl::GUICONTROL_LARGE_IMAGE: + lpszType = "largeimage"; break; + case CGUIControl::GUICONTROL_LABEL: + lpszType = "label"; break; + case CGUIControl::GUICONTROL_LISTGROUP: + lpszType = "group"; break; + case CGUIControl::GUICONTROL_PROGRESS: + lpszType = "progress"; break; + case CGUIControl::GUICONTROL_RADIO: + lpszType = "radiobutton"; break; + case CGUIControl::GUICONTROL_RSS: + lpszType = "rss"; break; + case CGUIControl::GUICONTROL_SELECTBUTTON: + lpszType = "selectbutton"; break; + case CGUIControl::GUICONTROL_SLIDER: + lpszType = "slider"; break; + case CGUIControl::GUICONTROL_SETTINGS_SLIDER: + lpszType = "sliderex"; break; + case CGUIControl::GUICONTROL_SPIN: + lpszType = "spincontrol"; break; + case CGUIControl::GUICONTROL_SPINEX: + lpszType = "spincontrolex"; break; + case CGUIControl::GUICONTROL_TEXTBOX: + lpszType = "textbox"; break; + case CGUIControl::GUICONTROL_TOGGLEBUTTON: + lpszType = "togglebutton"; break; + case CGUIControl::GUICONTROL_VIDEO: + lpszType = "videowindow"; break; + case CGUIControl::GUICONTROL_MOVER: + lpszType = "mover"; break; + case CGUIControl::GUICONTROL_RESIZE: + lpszType = "resize"; break; + case CGUIControl::GUICONTROL_BUTTONBAR: + lpszType = "buttonscroller"; break; + case CGUIControl::GUICONTROL_EDIT: + lpszType = "edit"; break; + case CGUIControl::GUICONTROL_VISUALISATION: + lpszType = "visualisation"; break; + case CGUIControl::GUICONTROL_MULTI_IMAGE: + lpszType = "multiimage"; break; + case CGUIControl::GUICONTROL_GROUP: + lpszType = "group"; break; + case CGUIControl::GUICONTROL_GROUPLIST: + lpszType = "grouplist"; break; + case CGUIControl::GUICONTROL_SCROLLBAR: + lpszType = "scrollbar"; break; + case CGUIControl::GUICONTROL_LISTLABEL: + lpszType = "label"; break; + case CGUIControl::GUICONTROL_MULTISELECT: + lpszType = "multiselect"; break; + case CGUIControl::GUICONTAINER_LIST: + lpszType = "list"; break; + case CGUIControl::GUICONTAINER_WRAPLIST: + lpszType = "wraplist"; break; + case CGUIControl::GUICONTAINER_FIXEDLIST: + lpszType = "fixedlist"; break; + case CGUIControl::GUICONTAINER_PANEL: + lpszType = "panel"; break; + //case CGUIControl::GUICONTROL_LIST: + //case CGUIControl::GUICONTROL_UNKNOWN: + //case CGUIControl::GUICONTROL_LISTEX: + //case CGUIControl::GUICONTROL_SPINBUTTON: + //case CGUIControl::GUICONTROL_THUMBNAIL: + //case CGUIControl::GUICONTROL_CONSOLE: + default: + break; + } + + if (lpszType) + xmlControl->SetAttribute("type", lpszType); + if (m_controlID != 0) + { + CStdString str; + str.Format("%u", m_controlID); + xmlControl->SetAttribute("id", str.c_str()); + } + + float pct = (float)GetTotalTime() / (float)m_pProfiler->GetTotalTime(); + if (pct > 0.01f) + { + CStdString str; + str.Format("%.0f", pct * 100.0f); + xmlControl->SetAttribute("percent", str.c_str()); + } + + if (!m_strDescription.IsEmpty()) + { + TiXmlElement *elem = new TiXmlElement("description"); + xmlControl->LinkEndChild(elem); + TiXmlText *text = new TiXmlText(m_strDescription.c_str()); + elem->LinkEndChild(text); + } + + // Note time is stored in 1/100 milliseconds but reported in ms + unsigned int vis = m_visTime / 100; + unsigned int rend = m_renderTime / 100; + if (vis || rend) + { + CStdString val; + TiXmlElement *elem = new TiXmlElement("rendertime"); + xmlControl->LinkEndChild(elem); + val.Format("%u", rend); + TiXmlText *text = new TiXmlText(val.c_str()); + elem->LinkEndChild(text); + + elem = new TiXmlElement("visibletime"); + xmlControl->LinkEndChild(elem); + val.Format("%u", vis); + text = new TiXmlText(val.c_str()); + elem->LinkEndChild(text); + } + + if (m_vecChildren.size()) + { + TiXmlElement *xmlChilds = new TiXmlElement("children"); + xmlControl->LinkEndChild(xmlChilds); + const unsigned int dwSize = m_vecChildren.size(); + for (unsigned int i=0; i<dwSize; ++i) + m_vecChildren[i]->SaveToXML(xmlChilds); + } +} + +CGUIControlProfilerItem *CGUIControlProfilerItem::AddControl(CGUIControl *pControl) +{ + m_vecChildren.push_back(new CGUIControlProfilerItem(m_pProfiler, this, pControl)); + return m_vecChildren.back(); +} + +CGUIControlProfilerItem *CGUIControlProfilerItem::FindOrAddControl(CGUIControl *pControl, bool recurse) +{ + const unsigned int dwSize = m_vecChildren.size(); + for (unsigned int i=0; i<dwSize; ++i) + { + CGUIControlProfilerItem *p = m_vecChildren[i]; + if (p->m_pControl == pControl) + return p; + if (recurse && (p = p->FindOrAddControl(pControl, true))) + return p; + } + + if (pControl->GetParentControl() == m_pControl) + return AddControl(pControl); + + return NULL; +} + +CGUIControlProfiler::CGUIControlProfiler(void) +: m_ItemHead(NULL, NULL, NULL), m_pLastItem(NULL), m_iMaxFrameCount(200) +// m_bIsRunning(false), no isRunning because it is static +{ + m_fPerfScale = 100000.0f / CurrentHostFrequency(); +} + +CGUIControlProfiler &CGUIControlProfiler::Instance(void) +{ + static CGUIControlProfiler _instance; + return _instance; +} + +bool CGUIControlProfiler::IsRunning(void) +{ + return m_bIsRunning; +} + +void CGUIControlProfiler::Start(void) +{ + m_iFrameCount = 0; + m_bIsRunning = true; + m_pLastItem = NULL; + m_ItemHead.Reset(this); +} + +void CGUIControlProfiler::BeginVisibility(CGUIControl *pControl) +{ + CGUIControlProfilerItem *item = FindOrAddControl(pControl); + item->BeginVisibility(); +} + +void CGUIControlProfiler::EndVisibility(CGUIControl *pControl) +{ + CGUIControlProfilerItem *item = FindOrAddControl(pControl); + item->EndVisibility(); +} + +void CGUIControlProfiler::BeginRender(CGUIControl *pControl) +{ + CGUIControlProfilerItem *item = FindOrAddControl(pControl); + item->BeginRender(); +} + +void CGUIControlProfiler::EndRender(CGUIControl *pControl) +{ + CGUIControlProfilerItem *item = FindOrAddControl(pControl); + item->EndRender(); +} + +CGUIControlProfilerItem *CGUIControlProfiler::FindOrAddControl(CGUIControl *pControl) +{ + if (m_pLastItem) + { + // Typically calls come in pairs so the last control we found is probably + // the one we want again next time + if (m_pLastItem->m_pControl == pControl) + return m_pLastItem; + // If that control is not a match, usually the one we want is the next + // sibling of that control, or the parent of that control so check + // the parent first as it is more convenient + m_pLastItem = m_pLastItem->m_pParent; + if (m_pLastItem && m_pLastItem->m_pControl == pControl) + return m_pLastItem; + // continued from above, this searches the original control's siblings + if (m_pLastItem) + m_pLastItem = m_pLastItem->FindOrAddControl(pControl, false); + if (m_pLastItem) + return m_pLastItem; + } + + m_pLastItem = m_ItemHead.FindOrAddControl(pControl, true); + if (!m_pLastItem) + m_pLastItem = m_ItemHead.AddControl(pControl); + + return m_pLastItem; +} + +void CGUIControlProfiler::EndFrame(void) +{ + m_iFrameCount++; + if (m_iFrameCount >= m_iMaxFrameCount) + { + const unsigned int dwSize = m_ItemHead.m_vecChildren.size(); + for (unsigned int i=0; i<dwSize; ++i) + { + CGUIControlProfilerItem *p = m_ItemHead.m_vecChildren[i]; + m_ItemHead.m_visTime += p->m_visTime; + m_ItemHead.m_renderTime += p->m_renderTime; + } + + m_bIsRunning = false; + if (SaveResults()) + m_ItemHead.Reset(this); + } +} + +bool CGUIControlProfiler::SaveResults(void) +{ + if (m_strOutputFile.IsEmpty()) + return false; + + TiXmlDocument doc; + TiXmlDeclaration decl("1.0", "", "yes"); + doc.InsertEndChild(decl); + + TiXmlElement *root = new TiXmlElement("guicontrolprofiler"); + CStdString str; + str.Format("%d", m_iFrameCount); + root->SetAttribute("framecount", str.c_str()); + root->SetAttribute("timeunit", "ms"); + doc.LinkEndChild(root); + + m_ItemHead.SaveToXML(root); + return doc.SaveFile(m_strOutputFile); +} diff --git a/guilib/GUIControlProfiler.h b/guilib/GUIControlProfiler.h index 34953ba6ec..7443c795ec 100644 --- a/guilib/GUIControlProfiler.h +++ b/guilib/GUIControlProfiler.h @@ -40,8 +40,8 @@ public: CGUIControl::GUICONTROLTYPES m_ControlType; unsigned int m_visTime; unsigned int m_renderTime; - LARGE_INTEGER m_i64VisStart; - LARGE_INTEGER m_i64RenderStart; + int64_t m_i64VisStart; + int64_t m_i64RenderStart; CGUIControlProfilerItem(CGUIControlProfiler *pProfiler, CGUIControlProfilerItem *pParent, CGUIControl *pControl); ~CGUIControlProfilerItem(void); diff --git a/guilib/GUIWindow.cpp b/guilib/GUIWindow.cpp index 2d78e95dcb..e685fa2853 100644 --- a/guilib/GUIWindow.cpp +++ b/guilib/GUIWindow.cpp @@ -79,8 +79,8 @@ bool CGUIWindow::Load(const CStdString& strFileName, bool bContainsPath) if (m_windowLoaded) return true; // no point loading if it's already there - LARGE_INTEGER start; - QueryPerformanceCounter(&start); + int64_t start; + start = CurrentHostCounter(); RESOLUTION resToUse = RES_INVALID; CLog::Log(LOGINFO, "Loading skin file: %s", strFileName.c_str()); @@ -102,10 +102,10 @@ bool CGUIWindow::Load(const CStdString& strFileName, bool bContainsPath) bool ret = LoadXML(strPath.c_str(), strLowerPath.c_str()); - LARGE_INTEGER end, freq; - QueryPerformanceCounter(&end); - QueryPerformanceFrequency(&freq); - CLog::Log(LOGDEBUG,"Load %s: %.2fms", m_xmlFile.c_str(), 1000.f * (end.QuadPart - start.QuadPart) / freq.QuadPart); + int64_t end, freq; + end = CurrentHostCounter(); + freq = CurrentHostFrequency(); + CLog::Log(LOGDEBUG,"Load %s: %.2fms", m_xmlFile.c_str(), 1000.f * (end - start) / freq); return ret; } @@ -666,8 +666,8 @@ void CGUIWindow::AllocResources(bool forceLoad /*= FALSE */) { CSingleLock lock(g_graphicsContext); - LARGE_INTEGER start; - QueryPerformanceCounter(&start); + int64_t start; + start = CurrentHostCounter(); // load skin xml file bool bHasPath=false; @@ -676,16 +676,16 @@ void CGUIWindow::AllocResources(bool forceLoad /*= FALSE */) if (m_xmlFile.size() && (forceLoad || m_loadOnDemand || !m_windowLoaded)) Load(m_xmlFile,bHasPath); - LARGE_INTEGER slend; - QueryPerformanceCounter(&slend); + int64_t slend; + slend = CurrentHostCounter(); // and now allocate resources CGUIControlGroup::AllocResources(); - LARGE_INTEGER end, freq; - QueryPerformanceCounter(&end); - QueryPerformanceFrequency(&freq); - CLog::Log(LOGDEBUG,"Alloc resources: %.2fms (%.2f ms skin load)", 1000.f * (end.QuadPart - start.QuadPart) / freq.QuadPart, 1000.f * (slend.QuadPart - start.QuadPart) / freq.QuadPart); + int64_t end, freq; + end = CurrentHostCounter(); + freq = CurrentHostFrequency(); + CLog::Log(LOGDEBUG,"Alloc resources: %.2fms (%.2f ms skin load)", 1000.f * (end - start) / freq, 1000.f * (slend - start) / freq); m_bAllocated = true; } diff --git a/guilib/TextureManager.cpp b/guilib/TextureManager.cpp index 3f18601ad9..d41ec38d8c 100644 --- a/guilib/TextureManager.cpp +++ b/guilib/TextureManager.cpp @@ -26,6 +26,10 @@ #include "utils/SingleLock.h" #include "utils/CharsetConverter.h" #include "utils/log.h" +#include "utils/log.h" +#ifdef _DEBUG +#include "utils/TimeUtils.h" +#endif #include "../xbmc/Util.h" #include "../xbmc/FileSystem/File.h" #include "../xbmc/FileSystem/Directory.h" @@ -306,8 +310,8 @@ int CGUITextureManager::Load(const CStdString& strTextureName, bool checkBundleO CSingleLock lock(g_graphicsContext); #ifdef _DEBUG - LARGE_INTEGER start; - QueryPerformanceCounter(&start); + int64_t start; + start = CurrentHostCounter(); #endif if (strPath.Right(4).ToLower() == ".gif") @@ -372,11 +376,11 @@ int CGUITextureManager::Load(const CStdString& strTextureName, bool checkBundleO } #ifdef _DEBUG - LARGE_INTEGER end, freq; - QueryPerformanceCounter(&end); - QueryPerformanceFrequency(&freq); + int64_t end, freq; + end = CurrentHostCounter(); + freq = CurrentHostFrequency(); char temp[200]; - sprintf(temp, "Load %s: %.1fms%s\n", strPath.c_str(), 1000.f * (end.QuadPart - start.QuadPart) / freq.QuadPart, (bundle >= 0) ? " (bundled)" : ""); + sprintf(temp, "Load %s: %.1fms%s\n", strPath.c_str(), 1000.f * (end - start) / freq, (bundle >= 0) ? " (bundled)" : ""); OutputDebugString(temp); #endif @@ -415,11 +419,11 @@ int CGUITextureManager::Load(const CStdString& strTextureName, bool checkBundleO m_vecTextures.push_back(pMap); #ifdef _DEBUG_TEXTURES - LARGE_INTEGER end, freq; - QueryPerformanceCounter(&end); - QueryPerformanceFrequency(&freq); + int64_t end, freq; + end = CurrentHostCounter(); + freq = CurrentHostFrequency(); char temp[200]; - sprintf(temp, "Load %s: %.1fms%s\n", strPath.c_str(), 1000.f * (end.QuadPart - start.QuadPart) / freq.QuadPart, (bundle >= 0) ? " (bundled)" : ""); + sprintf(temp, "Load %s: %.1fms%s\n", strPath.c_str(), 1000.f * (end - start) / freq, (bundle >= 0) ? " (bundled)" : ""); OutputDebugString(temp); #endif diff --git a/xbmc/Application.cpp b/xbmc/Application.cpp index e7f5c9edec..fdf91129fd 100644 --- a/xbmc/Application.cpp +++ b/xbmc/Application.cpp @@ -1823,8 +1823,8 @@ void CApplication::LoadSkin(const CStdString& strSkin) g_localizeStrings.LoadSkinStrings(skinPath, skinEnglishPath); - LARGE_INTEGER start; - QueryPerformanceCounter(&start); + int64_t start; + start = CurrentHostCounter(); CLog::Log(LOGINFO, " load new skin..."); CGUIWindowHome *pHome = (CGUIWindowHome *)g_windowManager.GetWindow(WINDOW_HOME); @@ -1844,10 +1844,10 @@ void CApplication::LoadSkin(const CStdString& strSkin) // Load the user windows LoadUserWindows(strSkinPath); - LARGE_INTEGER end, freq; - QueryPerformanceCounter(&end); - QueryPerformanceFrequency(&freq); - CLog::Log(LOGDEBUG,"Load Skin XML: %.2fms", 1000.f * (end.QuadPart - start.QuadPart) / freq.QuadPart); + int64_t end, freq; + end = CurrentHostCounter(); + freq = CurrentHostFrequency(); + CLog::Log(LOGDEBUG,"Load Skin XML: %.2fms", 1000.f * (end - start) / freq); CLog::Log(LOGINFO, " initialize new skin..."); m_guiPointer.AllocResources(true); diff --git a/xbmc/Credits.cpp b/xbmc/Credits.cpp index 02e333890b..afb96586ec 100644 --- a/xbmc/Credits.cpp +++ b/xbmc/Credits.cpp @@ -1142,10 +1142,10 @@ void RunCredits() CloseHandle(s_hMusicStarted); #ifdef _DEBUG - LARGE_INTEGER freq, start, end, start2, end2; - __int64 rendertime = 0; - QueryPerformanceFrequency(&freq); - QueryPerformanceCounter(&start2); + int64_t freq, start, end, start2, end2; + int64_t rendertime = 0; + freq = CurrentHostFrequency(); + start2 = CurrentHostCounter(); #endif // _DEBUG // Start credits loop @@ -1169,7 +1169,7 @@ void RunCredits() while (NextCredit < NUM_CREDITS || !ActiveList.empty()) { #ifdef _DEBUG - QueryPerformanceCounter(&start); + start = CurrentHostCounter(); #endif // _DEBUG if (WaitForSingleObject(hMusicThread, 0) == WAIT_TIMEOUT) @@ -1356,21 +1356,21 @@ void RunCredits() #ifdef _DEBUG static char FPS[80]; - QueryPerformanceCounter(&end); - rendertime += end.QuadPart - start.QuadPart; + end = CurrentHostCounter(); + rendertime += end - start; if (++n == 50) { - QueryPerformanceCounter(&end2); + end2 = CurrentHostCounter(); MEMORYSTATUS stat; GlobalMemoryStatus(&stat); - float f = float(end2.QuadPart - start2.QuadPart); - sprintf(FPS, "Render: %.2f fps (%.2f%%)\nFreeMem: %.1f/%uMB", 50.0f * freq.QuadPart / f, 100.f * rendertime / f, + float f = float(end2 - start2); + sprintf(FPS, "Render: %.2f fps (%.2f%%)\nFreeMem: %.1f/%uMB", 50.0f * freq / f, 100.f * rendertime / f, float(stat.dwAvailPhys) / (1024.0f*1024.0f), stat.dwTotalPhys / (1024*1024)); rendertime = 0; n = 0; - QueryPerformanceCounter(&start2); + start2 = CurrentHostCounter(); } CGUITextLayout::DrawText(g_fontManager.GetFont("font13"), 50, 30, 0xffffffff, 0, FPS, 0); #endif diff --git a/xbmc/RenderSystemGL.cpp b/xbmc/RenderSystemGL.cpp index 0871264b2f..cb2d0a8b92 100644 --- a/xbmc/RenderSystemGL.cpp +++ b/xbmc/RenderSystemGL.cpp @@ -28,6 +28,7 @@ #include "AdvancedSettings.h" #include "RenderSystemGL.h" #include "utils/log.h" +#include "utils/TimeUtils.h" CRenderSystemGL::CRenderSystemGL() : CRenderSystemBase() @@ -192,8 +193,8 @@ bool CRenderSystemGL::PresentRender() if (m_iVSyncMode != 0 && m_iSwapRate != 0) { int64_t curr, diff, freq; - QueryPerformanceCounter((LARGE_INTEGER*)&curr); - QueryPerformanceFrequency((LARGE_INTEGER*)&freq); + curr = CurrentHostCounter(); + freq = CurrentHostFrequency(); if(m_iSwapStamp == 0) m_iSwapStamp = curr; @@ -216,7 +217,7 @@ bool CRenderSystemGL::PresentRender() if (m_iVSyncMode && m_iSwapRate != 0) { int64_t curr, diff; - QueryPerformanceCounter((LARGE_INTEGER*)&curr); + curr = CurrentHostCounter(); diff = curr - m_iSwapStamp; m_iSwapStamp = curr; @@ -264,7 +265,7 @@ void CRenderSystemGL::SetVSync(bool enable) else { int64_t freq; - QueryPerformanceFrequency((LARGE_INTEGER*)&freq); + freq = CurrentHostFrequency(); m_iSwapRate = (int64_t)((double)freq / rate); m_iSwapTime = (int64_t)(0.001 * g_advancedSettings.m_ForcedSwapTime * freq); m_iSwapStamp = 0; diff --git a/xbmc/Util.cpp b/xbmc/Util.cpp index 6d98b192f3..b5dbf8ec26 100644 --- a/xbmc/Util.cpp +++ b/xbmc/Util.cpp @@ -3330,9 +3330,9 @@ void CUtil::ClearFileItemCache() void CUtil::InitRandomSeed() { // Init random seed - LARGE_INTEGER now; - QueryPerformanceCounter(&now); - unsigned int seed = (now.u.LowPart); + int64_t now; + now = CurrentHostCounter(); + unsigned int seed = now; // CLog::Log(LOGDEBUG, "%s - Initializing random seed with %u", __FUNCTION__, seed); srand(seed); } diff --git a/xbmc/VideoReferenceClock.cpp b/xbmc/VideoReferenceClock.cpp index 99dc858c9f..fe27e535f2 100644 --- a/xbmc/VideoReferenceClock.cpp +++ b/xbmc/VideoReferenceClock.cpp @@ -26,6 +26,7 @@ #include "MathUtils.h" #include "utils/SingleLock.h" #include "utils/log.h" +#include "utils/TimeUtils.h" #if defined(HAS_GLX) && defined(HAS_XRANDR) #include <X11/extensions/Xrandr.h> @@ -46,10 +47,10 @@ using namespace std; CVideoReferenceClock::CVideoReferenceClock() { - LARGE_INTEGER Freq; - QueryPerformanceFrequency(&Freq); - m_SystemFrequency = Freq.QuadPart; - m_AdjustedFrequency = Freq.QuadPart; + int64_t Freq; + Freq = CurrentHostFrequency(); + m_SystemFrequency = Freq; + m_AdjustedFrequency = Freq; m_ClockOffset = 0; m_TotalMissedVblanks = 0; m_UseVblank = false; @@ -73,7 +74,7 @@ CVideoReferenceClock::CVideoReferenceClock() void CVideoReferenceClock::Process() { bool SetupSuccess = false; - LARGE_INTEGER Now; + int64_t Now; while(!m_bStop) { @@ -91,8 +92,8 @@ void CVideoReferenceClock::Process() #endif CSingleLock SingleLock(m_CritSection); - QueryPerformanceCounter(&Now); - m_CurrTime = Now.QuadPart + m_ClockOffset; //add the clock offset from the previous time we stopped + Now = CurrentHostCounter(); + m_CurrTime = Now + m_ClockOffset; //add the clock offset from the previous time we stopped m_AdjustedFrequency = m_SystemFrequency; m_TotalMissedVblanks = 0; m_Started.Set(); @@ -100,7 +101,7 @@ void CVideoReferenceClock::Process() if (SetupSuccess) { m_UseVblank = true; //tell other threads we're using vblank as clock - m_VblankTime = Now.QuadPart; //initialize the timestamp of the last vblank + m_VblankTime = Now; //initialize the timestamp of the last vblank SingleLock.Leave(); //run the clock @@ -116,13 +117,13 @@ void CVideoReferenceClock::Process() else { SingleLock.Leave(); - CLog::Log(LOGDEBUG, "CVideoReferenceClock: Setup failed, falling back to QueryPerformanceCounter"); + CLog::Log(LOGDEBUG, "CVideoReferenceClock: Setup failed, falling back to CurrentHostCounter()"); } SingleLock.Enter(); m_UseVblank = false; //we're back to using the systemclock - QueryPerformanceCounter(&Now); //set the clockoffset between the vblank clock and systemclock - m_ClockOffset = m_CurrTime - Now.QuadPart; + Now = CurrentHostCounter(); //set the clockoffset between the vblank clock and systemclock + m_ClockOffset = m_CurrTime - Now; m_Started.Reset(); SingleLock.Leave(); @@ -372,7 +373,7 @@ void CVideoReferenceClock::RunGLX() unsigned int VblankCount; int ReturnV; bool IsReset = false; - LARGE_INTEGER Now; + int64_t Now; CSingleLock SingleLock(m_CritSection); SingleLock.Leave(); @@ -386,7 +387,7 @@ void CVideoReferenceClock::RunGLX() //wait for the next vblank ReturnV = m_glXWaitVideoSyncSGI(2, (VblankCount + 1) % 2, &VblankCount); m_glXGetVideoSyncSGI(&VblankCount); //the vblank count returned by glXWaitVideoSyncSGI is not always correct - QueryPerformanceCounter(&Now); //get the timestamp of this vblank + Now = CurrentHostCounter(); //get the timestamp of this vblank if(ReturnV) { @@ -398,7 +399,7 @@ void CVideoReferenceClock::RunGLX() { //update the vblank timestamp, update the clock and send a signal that we got a vblank SingleLock.Enter(); - m_VblankTime = Now.QuadPart; + m_VblankTime = Now; UpdateClock((int)(VblankCount - PrevVblankCount), true); SingleLock.Leave(); SendVblankSignal(); @@ -445,7 +446,7 @@ void CVideoReferenceClock::RunGLX() void CVideoReferenceClock::RunD3D() { D3DRASTER_STATUS RasterStatus; - LARGE_INTEGER Now; + int64_t Now; int64_t LastVBlankTime; unsigned int LastLine; int NrVBlanks; @@ -461,8 +462,8 @@ void CVideoReferenceClock::RunD3D() else LastLine = RasterStatus.ScanLine; //init the vblanktime - QueryPerformanceCounter(&Now); - LastVBlankTime = Now.QuadPart; + Now = CurrentHostCounter(); + LastVBlankTime = Now; while(!m_bStop) { @@ -479,13 +480,13 @@ void CVideoReferenceClock::RunD3D() if ((RasterStatus.InVBlank && LastLine > 0) || (RasterStatus.ScanLine < LastLine)) { //calculate how many vblanks happened - QueryPerformanceCounter(&Now); - VBlankTime = (double)(Now.QuadPart - LastVBlankTime) / (double)m_SystemFrequency; + Now CurrentHostCounter(); + VBlankTime = (double)(Now - LastVBlankTime) / (double)m_SystemFrequency; NrVBlanks = MathUtils::round_int(VBlankTime * (double)m_RefreshRate); //update the vblank timestamp, update the clock and send a signal that we got a vblank SingleLock.Enter(); - m_VblankTime = Now.QuadPart; + m_VblankTime = Now; UpdateClock(NrVBlanks, true); SingleLock.Leave(); SendVblankSignal(); @@ -499,13 +500,13 @@ void CVideoReferenceClock::RunD3D() } //save the timestamp of this vblank so we can calulate how many vblanks happened next time - LastVBlankTime = Now.QuadPart; + LastVBlankTime = Now; HandleWindowMessages(); //because we had a vblank, sleep until half the refreshrate period - QueryPerformanceCounter(&Now); - int SleepTime = (int)((LastVBlankTime + (m_SystemFrequency / m_RefreshRate / 2) - Now.QuadPart) * 1000 / m_SystemFrequency); + Now = CurrentHostCounter(); + int SleepTime = (int)((LastVBlankTime + (m_SystemFrequency / m_RefreshRate / 2) - Now) * 1000 / m_SystemFrequency); if (SleepTime > 100) SleepTime = 100; //failsafe if (SleepTime > 0) ::Sleep(SleepTime); } @@ -695,7 +696,7 @@ bool CVideoReferenceClock::SetupD3D() double CVideoReferenceClock::MeasureRefreshrate(int MSecs) { D3DRASTER_STATUS RasterStatus; - LARGE_INTEGER Now; + int64_t Now; int64_t Target; int64_t Prev; int64_t AvgInterval; @@ -703,18 +704,18 @@ double CVideoReferenceClock::MeasureRefreshrate(int MSecs) unsigned int LastLine; int ReturnV; - QueryPerformanceCounter(&Now); - Target = Now.QuadPart + (m_SystemFrequency * MSecs / 1000); + Now = CurrentHostCounter(); + Target = Now + (m_SystemFrequency * MSecs / 1000); Prev = -1; AvgInterval = 0; MeasureCount = 0; //start measuring vblanks LastLine = 0; - while(Now.QuadPart <= Target) + while(Now <= Target) { ReturnV = m_D3dDev->GetRasterStatus(0, &RasterStatus); - QueryPerformanceCounter(&Now); + Now = CurrentHostCounter(); if (ReturnV != D3D_OK) { CLog::Log(LOGDEBUG, "CVideoReferenceClock: GetRasterStatus returned returned %s: %s", @@ -726,10 +727,10 @@ double CVideoReferenceClock::MeasureRefreshrate(int MSecs) { //we got a vblank if (Prev != -1) //need two for a measurement { - AvgInterval += Now.QuadPart - Prev; //save how long this vblank lasted + AvgInterval += Now - Prev; //save how long this vblank lasted MeasureCount++; } - Prev = Now.QuadPart; //save this time for the next measurement + Prev = Now; //save this time for the next measurement } //save the current scanline @@ -866,10 +867,9 @@ static CVReturn DisplayLinkCallBack(CVDisplayLinkRef displayLink, const CVTimeSt bool CVideoReferenceClock::SetupCocoa() { CLog::Log(LOGDEBUG, "CVideoReferenceClock: setting up up Cocoa"); - LARGE_INTEGER Now; - - QueryPerformanceCounter(&Now); - m_LastVBlankTime = Now.QuadPart; //init the vblank timestamp + + //init the vblank timestamp + m_LastVBlankTime = CurrentHostCounter(); m_MissedVblanks = 0; m_RefreshRate = 60; //init the refreshrate so we don't get any division by 0 errors @@ -955,40 +955,40 @@ void CVideoReferenceClock::UpdateClock(int NrVBlanks, bool CheckMissed) } //called from dvdclock to get the time -void CVideoReferenceClock::GetTime(LARGE_INTEGER *ptime) +void CVideoReferenceClock::GetTime(int64_t *ptime) { CSingleLock SingleLock(m_CritSection); //when using vblank, get the time from that, otherwise use the systemclock if (m_UseVblank) { - int64_t NextVblank; - LARGE_INTEGER Now; + int64_t NextVblank; + int64_t Now; - QueryPerformanceCounter(&Now); //get current system time + Now = CurrentHostCounter(); //get current system time NextVblank = TimeOfNextVblank(); //get time when the next vblank should happen - while(Now.QuadPart >= NextVblank) //keep looping until the next vblank is in the future + while(Now >= NextVblank) //keep looping until the next vblank is in the future { UpdateClock(1, false); //update clock when next vblank should have happened already NextVblank = TimeOfNextVblank(); //get time when the next vblank should happen } - ptime->QuadPart = m_CurrTime; + *ptime = m_CurrTime; } else { int64_t ClockOffset = m_ClockOffset; //get offset of clock SingleLock.Leave(); - QueryPerformanceCounter(ptime); //get time of systemclock - ptime->QuadPart += ClockOffset; //add offset + *ptime = CurrentHostCounter(); //get time of systemclock + *ptime += ClockOffset; //add offset } } //called from dvdclock to get the clock frequency -void CVideoReferenceClock::GetFrequency(LARGE_INTEGER *pfreq) +void CVideoReferenceClock::GetFrequency(int64_t *pfreq) { - QueryPerformanceFrequency(pfreq); + *pfreq = CurrentHostFrequency(); } void CVideoReferenceClock::SetSpeed(double Speed) @@ -1151,7 +1151,7 @@ int CVideoReferenceClock::GetRefreshRate() //it waits until a certain timestamp has passed, used for displaying videoframes at the correct moment int64_t CVideoReferenceClock::Wait(int64_t Target) { - LARGE_INTEGER Now; + int64_t Now; int SleepTime; int64_t NextVblank; bool Late; @@ -1163,9 +1163,9 @@ int64_t CVideoReferenceClock::Wait(int64_t Target) while (m_CurrTime < Target) { //calculate how long to sleep before we should have gotten a signal that a vblank happened - QueryPerformanceCounter(&Now); + Now = CurrentHostCounter(); NextVblank = TimeOfNextVblank(); - SleepTime = (int)((NextVblank - Now.QuadPart) * 1000 / m_SystemFrequency); + SleepTime = (int)((NextVblank - Now) * 1000 / m_SystemFrequency); int64_t CurrTime = m_CurrTime; //save current value of the clock @@ -1200,14 +1200,14 @@ int64_t CVideoReferenceClock::Wait(int64_t Target) { int64_t ClockOffset = m_ClockOffset; SingleLock.Leave(); - QueryPerformanceCounter(&Now); + Now = CurrentHostCounter(); //sleep until the timestamp has passed - SleepTime = (int)((Target - (Now.QuadPart + ClockOffset)) * 1000 / m_SystemFrequency); + SleepTime = (int)((Target - (Now + ClockOffset)) * 1000 / m_SystemFrequency); if (SleepTime > 0) ::Sleep(SleepTime); - QueryPerformanceCounter(&Now); - return Now.QuadPart + ClockOffset; + Now = CurrentHostCounter(); + return Now + ClockOffset; } } diff --git a/xbmc/VideoReferenceClock.h b/xbmc/VideoReferenceClock.h index 5917a1a9c1..67967f6261 100644 --- a/xbmc/VideoReferenceClock.h +++ b/xbmc/VideoReferenceClock.h @@ -47,8 +47,8 @@ class CVideoReferenceClock : public CThread public: CVideoReferenceClock(); - void GetTime(LARGE_INTEGER *ptime); - void GetFrequency(LARGE_INTEGER *pfreq); + void GetTime(int64_t *ptime); + void GetFrequency(int64_t *pfreq); void SetSpeed(double Speed); double GetSpeed(); int GetRefreshRate(); diff --git a/xbmc/cores/VideoRenderers/RenderManager.cpp b/xbmc/cores/VideoRenderers/RenderManager.cpp index 2d03aed348..35c03d56be 100644 --- a/xbmc/cores/VideoRenderers/RenderManager.cpp +++ b/xbmc/cores/VideoRenderers/RenderManager.cpp @@ -110,7 +110,7 @@ CXBMCRenderManager::~CXBMCRenderManager() m_pRenderer = NULL; } -/* These is based on QueryPerformanceCounter */ +/* These is based on CurrentHostCounter() */ double CXBMCRenderManager::GetPresentTime() { return CDVDClock::GetAbsoluteClock() / DVD_TIME_BASE; diff --git a/xbmc/cores/dvdplayer/DVDClock.cpp b/xbmc/cores/dvdplayer/DVDClock.cpp index 5fcaadba43..4d0c440d08 100644 --- a/xbmc/cores/dvdplayer/DVDClock.cpp +++ b/xbmc/cores/dvdplayer/DVDClock.cpp @@ -26,20 +26,20 @@ #include "utils/SingleLock.h" #include "utils/log.h" -LARGE_INTEGER CDVDClock::m_systemOffset; -LARGE_INTEGER CDVDClock::m_systemFrequency; +int64_t CDVDClock::m_systemOffset; +int64_t CDVDClock::m_systemFrequency; CCriticalSection CDVDClock::m_systemsection; CDVDClock::CDVDClock() { - if(!m_systemFrequency.QuadPart) + if(!m_systemFrequency) g_VideoReferenceClock.GetFrequency(&m_systemFrequency); - if(!m_systemOffset.QuadPart) + if(!m_systemOffset) g_VideoReferenceClock.GetTime(&m_systemOffset); m_systemUsed = m_systemFrequency; - m_pauseClock.QuadPart = 0; + m_pauseClock = 0; m_bReset = true; m_iDisc = 0; m_maxspeedadjust = 0.0; @@ -54,43 +54,43 @@ double CDVDClock::GetAbsoluteClock() { CSingleLock lock(m_systemsection); - if(!m_systemFrequency.QuadPart) + if(!m_systemFrequency) g_VideoReferenceClock.GetFrequency(&m_systemFrequency); - if(!m_systemOffset.QuadPart) + if(!m_systemOffset) g_VideoReferenceClock.GetTime(&m_systemOffset); - LARGE_INTEGER current; + int64_t current; g_VideoReferenceClock.GetTime(¤t); - current.QuadPart -= m_systemOffset.QuadPart; + current -= m_systemOffset; #if _DEBUG - static LARGE_INTEGER old; - if(old.QuadPart > current.QuadPart) - CLog::Log(LOGWARNING, "QueryPerformanceCounter moving backwords by %"PRId64" ticks with freq of %"PRId64, old.QuadPart - current.QuadPart, m_systemFrequency.QuadPart); + static int64_t old; + if(old > current) + CLog::Log(LOGWARNING, "CurrentHostCounter() moving backwords by %"PRId64" ticks with freq of %"PRId64, old - current, m_systemFrequency); old = current; #endif - return DVD_TIME_BASE * (double)current.QuadPart / m_systemFrequency.QuadPart; + return DVD_TIME_BASE * (double)current / m_systemFrequency; } double CDVDClock::WaitAbsoluteClock(double target) { CSingleLock lock(m_systemsection); - __int64 systemtarget, freq, offset; - if(!m_systemFrequency.QuadPart) + int64_t systemtarget, freq, offset; + if(!m_systemFrequency) g_VideoReferenceClock.GetFrequency(&m_systemFrequency); - if(!m_systemOffset.QuadPart) + if(!m_systemOffset) g_VideoReferenceClock.GetTime(&m_systemOffset); - freq = m_systemFrequency.QuadPart; - offset = m_systemOffset.QuadPart; + freq = m_systemFrequency; + offset = m_systemOffset; lock.Leave(); - systemtarget = (__int64)(target / DVD_TIME_BASE * (double)freq); + systemtarget = (int64_t)(target / DVD_TIME_BASE * (double)freq); systemtarget += offset; systemtarget = g_VideoReferenceClock.Wait(systemtarget); systemtarget -= offset; @@ -100,24 +100,24 @@ double CDVDClock::WaitAbsoluteClock(double target) double CDVDClock::GetClock() { CSharedLock lock(m_critSection); - LARGE_INTEGER current; + int64_t current; if (m_bReset) { g_VideoReferenceClock.GetTime(&m_startClock); m_systemUsed = m_systemFrequency; - m_pauseClock.QuadPart = 0; + m_pauseClock = 0; m_iDisc = 0; m_bReset = false; } - if (m_pauseClock.QuadPart) + if (m_pauseClock) current = m_pauseClock; else g_VideoReferenceClock.GetTime(¤t); - current.QuadPart -= m_startClock.QuadPart; - return DVD_TIME_BASE * (double)current.QuadPart / m_systemUsed.QuadPart + m_iDisc; + current -= m_startClock; + return DVD_TIME_BASE * (double)current / m_systemUsed + m_iDisc; } void CDVDClock::SetSpeed(int iSpeed) @@ -127,23 +127,23 @@ void CDVDClock::SetSpeed(int iSpeed) if(iSpeed == DVD_PLAYSPEED_PAUSE) { - if(!m_pauseClock.QuadPart) + if(!m_pauseClock) g_VideoReferenceClock.GetTime(&m_pauseClock); return; } - LARGE_INTEGER current; - __int64 newfreq = m_systemFrequency.QuadPart * DVD_PLAYSPEED_NORMAL / iSpeed; + int64_t current; + int64_t newfreq = m_systemFrequency * DVD_PLAYSPEED_NORMAL / iSpeed; g_VideoReferenceClock.GetTime(¤t); - if( m_pauseClock.QuadPart ) + if( m_pauseClock ) { - m_startClock.QuadPart += current.QuadPart - m_pauseClock.QuadPart; - m_pauseClock.QuadPart = 0; + m_startClock += current - m_pauseClock; + m_pauseClock = 0; } - m_startClock.QuadPart = current.QuadPart - ( newfreq * (current.QuadPart - m_startClock.QuadPart) ) / m_systemUsed.QuadPart; - m_systemUsed.QuadPart = newfreq; + m_startClock = current - ( newfreq * (current - m_startClock) ) / m_systemUsed; + m_systemUsed = newfreq; } void CDVDClock::Discontinuity(ClockDiscontinuityType type, double currentPts, double delay) @@ -159,7 +159,7 @@ void CDVDClock::Discontinuity(ClockDiscontinuityType type, double currentPts, do case CLOCK_DISC_NORMAL: { g_VideoReferenceClock.GetTime(&m_startClock); - m_startClock.QuadPart += (__int64)(delay * m_systemUsed.QuadPart / DVD_TIME_BASE); + m_startClock += (int64_t)(delay * m_systemUsed / DVD_TIME_BASE); m_iDisc = currentPts; m_bReset = false; break; @@ -170,20 +170,20 @@ void CDVDClock::Discontinuity(ClockDiscontinuityType type, double currentPts, do void CDVDClock::Pause() { CExclusiveLock lock(m_critSection); - if(!m_pauseClock.QuadPart) + if(!m_pauseClock) g_VideoReferenceClock.GetTime(&m_pauseClock); } void CDVDClock::Resume() { CExclusiveLock lock(m_critSection); - if( m_pauseClock.QuadPart ) + if( m_pauseClock ) { - LARGE_INTEGER current; + int64_t current; g_VideoReferenceClock.GetTime(¤t); - m_startClock.QuadPart += current.QuadPart - m_pauseClock.QuadPart; - m_pauseClock.QuadPart = 0; + m_startClock += current - m_pauseClock; + m_pauseClock = 0; } } diff --git a/xbmc/cores/dvdplayer/DVDClock.h b/xbmc/cores/dvdplayer/DVDClock.h index 94e2224bab..36f10ec379 100644 --- a/xbmc/cores/dvdplayer/DVDClock.h +++ b/xbmc/cores/dvdplayer/DVDClock.h @@ -70,18 +70,18 @@ public: bool SetMaxSpeedAdjust(double speed); static double GetAbsoluteClock(); - static double GetFrequency() { return (double)m_systemFrequency.QuadPart ; } + static double GetFrequency() { return (double)m_systemFrequency ; } static double WaitAbsoluteClock(double target); protected: CSharedSection m_critSection; - LARGE_INTEGER m_systemUsed; - LARGE_INTEGER m_startClock; - LARGE_INTEGER m_pauseClock; + int64_t m_systemUsed; + int64_t m_startClock; + int64_t m_pauseClock; double m_iDisc; bool m_bReset; - static LARGE_INTEGER m_systemFrequency; - static LARGE_INTEGER m_systemOffset; + static int64_t m_systemFrequency; + static int64_t m_systemOffset; static CCriticalSection m_systemsection; double m_maxspeedadjust; diff --git a/xbmc/cores/dvdplayer/DVDPlayerAudio.cpp b/xbmc/cores/dvdplayer/DVDPlayerAudio.cpp index c14ccb81a6..a85ce283f4 100644 --- a/xbmc/cores/dvdplayer/DVDPlayerAudio.cpp +++ b/xbmc/cores/dvdplayer/DVDPlayerAudio.cpp @@ -28,6 +28,7 @@ #include "GUISettings.h" #include "VideoReferenceClock.h" #include "utils/log.h" +#include "utils/TimeUtils.h" #include <sstream> #include <iomanip> @@ -137,7 +138,7 @@ CDVDPlayerAudio::CDVDPlayerAudio(CDVDClock* pClock) m_stalled = false; m_started = false; - QueryPerformanceFrequency(&m_freq); + m_freq = CurrentHostFrequency(); InitializeCriticalSection(&m_critCodecSection); m_messageQueue.SetMaxDataSize(30 * 16 * 1024); @@ -185,7 +186,7 @@ bool CDVDPlayerAudio::OpenStream( CDVDStreamInfo &hints ) m_skipdupcount = 0; m_prevskipped = false; m_syncclock = true; - QueryPerformanceCounter(&m_errortime); + m_errortime = CurrentHostCounter(); m_maxspeedadjust = g_guiSettings.GetFloat("videoplayer.maxspeedadjust"); @@ -591,7 +592,7 @@ void CDVDPlayerAudio::HandleSyncError(double duration) { double clock = m_pClock->GetClock(); double error = m_ptsOutput.Current() - clock; - LARGE_INTEGER now; + int64_t now; if( fabs(error) > DVD_MSEC_TO_TIME(100) || m_syncclock ) { @@ -604,7 +605,7 @@ void CDVDPlayerAudio::HandleSyncError(double duration) m_skipdupcount = 0; m_error = 0; m_syncclock = false; - QueryPerformanceCounter(&m_errortime); + m_errortime = CurrentHostCounter(); return; } @@ -617,7 +618,7 @@ void CDVDPlayerAudio::HandleSyncError(double duration) m_skipdupcount = 0; m_error = 0; m_resampler.Flush(); - QueryPerformanceCounter(&m_errortime); + m_errortime = CurrentHostCounter(); return; } @@ -625,8 +626,8 @@ void CDVDPlayerAudio::HandleSyncError(double duration) m_errorcount++; //check if measured error for 1 second - QueryPerformanceCounter(&now); - if ((now.QuadPart - m_errortime.QuadPart) >= m_freq.QuadPart) + now = CurrentHostCounter(); + if ((now - m_errortime) >= m_freq) { m_errortime = now; m_error = m_errorbuff / m_errorcount; diff --git a/xbmc/cores/dvdplayer/DVDPlayerAudio.h b/xbmc/cores/dvdplayer/DVDPlayerAudio.h index 990a67962a..c42e8f7362 100644 --- a/xbmc/cores/dvdplayer/DVDPlayerAudio.h +++ b/xbmc/cores/dvdplayer/DVDPlayerAudio.h @@ -186,8 +186,8 @@ protected: double m_error; //last average error - LARGE_INTEGER m_errortime; //timestamp of last time we measured - LARGE_INTEGER m_freq; + int64_t m_errortime; //timestamp of last time we measured + int64_t m_freq; void SetSyncType(bool passthrough); void HandleSyncError(double duration); diff --git a/xbmc/linux/XTimeUtils.cpp b/xbmc/linux/XTimeUtils.cpp index 5586d879bd..4b3066af06 100644 --- a/xbmc/linux/XTimeUtils.cpp +++ b/xbmc/linux/XTimeUtils.cpp @@ -72,39 +72,6 @@ VOID GetLocalTime(LPSYSTEMTIME sysTime) g_timezone.m_IsDST = now.tm_isdst; } -BOOL QueryPerformanceCounter(LARGE_INTEGER *lpPerformanceCount) { - if (lpPerformanceCount == NULL) - return false; - -#ifdef __APPLE__ - lpPerformanceCount->QuadPart = CVGetCurrentHostTime(); -#else - struct timespec now; - if (clock_gettime(CLOCK_MONOTONIC, &now) != 0) { - CLog::Log(LOGERROR,"%s - error %d getting timer", __FUNCTION__, errno); - return false; - } - - lpPerformanceCount->QuadPart = ((__int64)now.tv_sec * 1000000000L) + now.tv_nsec; -#endif - - return true; -} - -BOOL QueryPerformanceFrequency(LARGE_INTEGER *lpFrequency) { - - if (lpFrequency == NULL) - return false; - -#ifdef __APPLE__ - // needed for 10.5.8 on ppc - lpFrequency->QuadPart = CVGetHostClockFrequency(); -#else - lpFrequency->QuadPart = 1000000000L; -#endif - return true; -} - BOOL FileTimeToLocalFileTime(const FILETIME* lpFileTime, LPFILETIME lpLocalFileTime) { // TODO: FileTimeToLocalTime not implemented diff --git a/xbmc/linux/XTimeUtils.h b/xbmc/linux/XTimeUtils.h index cf3a8a63d5..d1eaa600dd 100644 --- a/xbmc/linux/XTimeUtils.h +++ b/xbmc/linux/XTimeUtils.h @@ -26,9 +26,6 @@ VOID GetLocalTime(LPSYSTEMTIME); -BOOL QueryPerformanceCounter(LARGE_INTEGER *lpPerformanceCount); -BOOL QueryPerformanceFrequency(LARGE_INTEGER *lpFrequency); - void WINAPI Sleep(DWORD dwMilliSeconds); BOOL FileTimeToLocalFileTime(const FILETIME* lpFileTime, LPFILETIME lpLocalFileTime); diff --git a/xbmc/utils/BitstreamStats.cpp b/xbmc/utils/BitstreamStats.cpp index 3deb8fd3ac..dcc131a5a7 100644 --- a/xbmc/utils/BitstreamStats.cpp +++ b/xbmc/utils/BitstreamStats.cpp @@ -20,11 +20,9 @@ */ #include "BitstreamStats.h" -#ifdef _LINUX -#include "linux/XTimeUtils.h" -#endif +#include "utils/TimeUtils.h" -LARGE_INTEGER BitstreamStats::m_tmFreq; +int64_t BitstreamStats::m_tmFreq; BitstreamStats::BitstreamStats(unsigned int nEstimatedBitrate) { @@ -34,10 +32,10 @@ BitstreamStats::BitstreamStats(unsigned int nEstimatedBitrate) m_nBitCount = 0; m_nEstimatedBitrate = nEstimatedBitrate; - m_tmStart.QuadPart = 0LL; + m_tmStart = 0LL; - if (m_tmFreq.QuadPart == 0LL) - QueryPerformanceFrequency(&m_tmFreq); + if (m_tmFreq == 0LL) + m_tmFreq = CurrentHostFrequency(); } BitstreamStats::~BitstreamStats() @@ -59,15 +57,15 @@ void BitstreamStats::AddSampleBits(unsigned int nBits) void BitstreamStats::Start() { m_nBitCount = 0; - QueryPerformanceCounter(&m_tmStart); + m_tmStart = CurrentHostCounter(); } void BitstreamStats::CalculateBitrate() { - LARGE_INTEGER tmNow; - QueryPerformanceCounter(&tmNow); + int64_t tmNow; + tmNow = CurrentHostCounter(); - double elapsed = (double)(tmNow.QuadPart - m_tmStart.QuadPart) / (double)m_tmFreq.QuadPart; + double elapsed = (double)(tmNow - m_tmStart) / (double)m_tmFreq; // only update once every 2 seconds if (elapsed >= 2) { diff --git a/xbmc/utils/BitstreamStats.h b/xbmc/utils/BitstreamStats.h index f696e3853f..3f1e8b2543 100644 --- a/xbmc/utils/BitstreamStats.h +++ b/xbmc/utils/BitstreamStats.h @@ -26,9 +26,6 @@ #ifdef _LINUX #include "linux/PlatformDefs.h" #endif -#ifdef _WIN32 -#include "system.h" // for LARGE_INTEGER -#endif class BitstreamStats { @@ -55,8 +52,8 @@ private: double m_dMinBitrate; unsigned int m_nBitCount; unsigned int m_nEstimatedBitrate; // when we reach this amount of bits we check current bitrate. - LARGE_INTEGER m_tmStart; - static LARGE_INTEGER m_tmFreq; + int64_t m_tmStart; + static int64_t m_tmFreq; }; #endif diff --git a/xbmc/utils/PerformanceSample.cpp b/xbmc/utils/PerformanceSample.cpp index 2d35bcb350..79bfdb356c 100644 --- a/xbmc/utils/PerformanceSample.cpp +++ b/xbmc/utils/PerformanceSample.cpp @@ -24,23 +24,23 @@ #ifdef _LINUX #include "linux/PlatformInclude.h" -#include "linux/XTimeUtils.h" #endif #include <SDL/SDL.h> #include "Application.h" #include "log.h" +#include "TimeUtils.h" using namespace std; -LARGE_INTEGER CPerformanceSample::m_tmFreq; +int64_t CPerformanceSample::m_tmFreq; CPerformanceSample::CPerformanceSample(const string &statName, bool bCheckWhenDone) { m_statName = statName; m_bCheckWhenDone = bCheckWhenDone; - if (m_tmFreq.QuadPart == 0LL) - QueryPerformanceFrequency(&m_tmFreq); + if (m_tmFreq == 0LL) + m_tmFreq = CurrentHostFrequency(); Reset(); } @@ -53,7 +53,7 @@ CPerformanceSample::~CPerformanceSample() void CPerformanceSample::Reset() { - QueryPerformanceCounter(&m_tmStart); + m_tmStart = CurrentHostCounter(); #ifdef _LINUX if (getrusage(RUSAGE_SELF, &m_usage) == -1) CLog::Log(LOGERROR,"error %d in getrusage", errno); @@ -62,10 +62,10 @@ void CPerformanceSample::Reset() void CPerformanceSample::CheckPoint() { - LARGE_INTEGER tmNow; - QueryPerformanceCounter(&tmNow); + int64_t tmNow; + tmNow = CurrentHostCounter(); #ifdef HAS_PERFORMANCE_SAMPLE - double elapsed = (double)(tmNow.QuadPart - m_tmStart.QuadPart) / (double)m_tmFreq.QuadPart; + double elapsed = (double)(tmNow - m_tmStart) / (double)m_tmFreq.QuadPart; #endif double dUser=0.0, dSys=0.0; @@ -91,20 +91,20 @@ void CPerformanceSample::CheckPoint() double CPerformanceSample::GetEstimatedError() { - if (m_tmFreq.QuadPart == 0LL) - QueryPerformanceFrequency(&m_tmFreq); + if (m_tmFreq == 0LL) + m_tmFreq = CurrentHostFrequency(); - LARGE_INTEGER tmStart, tmEnd; - QueryPerformanceCounter(&tmStart); + int64_t tmStart, tmEnd; + tmStart = CurrentHostCounter(); for (int i=0; i<100000;i++) { - LARGE_INTEGER tmDummy; - QueryPerformanceCounter(&tmDummy); + int64_t tmDummy; + tmDummy = CurrentHostCounter(); } - QueryPerformanceCounter(&tmEnd); - double elapsed = (double)(tmEnd.QuadPart - tmStart.QuadPart) / (double)m_tmFreq.QuadPart; + tmEnd = CurrentHostCounter(); + double elapsed = (double)(tmEnd - tmStart) / (double)m_tmFreq; return (elapsed / 100000.0) * 2.0; // one measure at start time and another when done. } diff --git a/xbmc/utils/PerformanceSample.h b/xbmc/utils/PerformanceSample.h index 60b09474c5..439394df1a 100644 --- a/xbmc/utils/PerformanceSample.h +++ b/xbmc/utils/PerformanceSample.h @@ -60,8 +60,8 @@ protected: struct rusage m_usage; #endif - LARGE_INTEGER m_tmStart; - static LARGE_INTEGER m_tmFreq; + int64_t m_tmStart; + static int64_t m_tmFreq; }; #endif diff --git a/xbmc/utils/Stopwatch.cpp b/xbmc/utils/Stopwatch.cpp index 5d2cb61ee4..fe153e0438 100644 --- a/xbmc/utils/Stopwatch.cpp +++ b/xbmc/utils/Stopwatch.cpp @@ -19,7 +19,6 @@ * */ -#include "system.h" // for LARGE_INTEGER, QueryPerformanceCounter etc. #include "Stopwatch.h" #if defined(_LINUX) && !defined(__APPLE__) #include <sys/sysinfo.h> @@ -34,9 +33,7 @@ CStopWatch::CStopWatch() // Get the timer frequency (ticks per second) #ifndef _LINUX - LARGE_INTEGER timerFreq; - QueryPerformanceFrequency( &timerFreq ); - m_timerPeriod = 1.0f / (float)timerFreq.QuadPart; + m_timerPeriod = 1.0f / (float)CurrentHostFrequency(); #else m_timerPeriod = 1.0f / 1000.0f; // we want seconds #endif @@ -94,9 +91,7 @@ float CStopWatch::GetElapsedMilliseconds() const int64_t CStopWatch::GetTicks() const { #ifndef _LINUX - LARGE_INTEGER currTicks; - QueryPerformanceCounter( &currTicks ); - return currTicks.QuadPart; + return CurrentHostCounter(); #else return CTimeUtils::GetTimeMS(); #endif diff --git a/xbmc/utils/TimeUtils.cpp b/xbmc/utils/TimeUtils.cpp index 48115fb0f8..72b4405a8b 100644 --- a/xbmc/utils/TimeUtils.cpp +++ b/xbmc/utils/TimeUtils.cpp @@ -24,11 +24,41 @@ #include <time.h> #ifdef __APPLE__ #include <mach/mach_time.h> +#include <CoreVideo/CVHostTime.h> #endif #elif defined(_WIN32) #include <windows.h> #endif +int64_t CurrentHostCounter(void) +{ +#if defined(__APPLE__) + return( (int64_t)CVGetCurrentHostTime() ); +#elif defined(_LINUX) + struct timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); + return( ((int64_t)now.tv_sec * 1000000000L) + now.tv_nsec ); +#else + LARGE_INTEGER PerformanceCount; + QueryPerformanceCounter(&PerformanceCount); + return( (int64_t)PerformanceCount->QuadPart ); +#endif +} + +int64_t CurrentHostFrequency(void) +{ +#if defined(__APPLE__) + // needed for 10.5.8 on ppc + return( (int64_t)CVGetHostClockFrequency() ); +#elif defined(_LINUX) + return( (int64_t)1000000000L ); +#else + LARGE_INTEGER Frequency; + QueryPerformanceFrequency(&Frequency); + return( (int64_t)Frequency->QuadPart ); +#endif +} + unsigned int CTimeUtils::frameTime = 0; void CTimeUtils::UpdateFrameTime() diff --git a/xbmc/utils/TimeUtils.h b/xbmc/utils/TimeUtils.h index 3800f1fb89..a6025b7553 100644 --- a/xbmc/utils/TimeUtils.h +++ b/xbmc/utils/TimeUtils.h @@ -23,6 +23,9 @@ #include <stdint.h> +int64_t CurrentHostCounter(void); +int64_t CurrentHostFrequency(void); + class CTimeUtils { public: @@ -32,3 +35,4 @@ public: private: static unsigned int frameTime; }; + |