[Windows] Fix driver version detection of AMD RDNA+ GPU on Windows 10
[xbmc.git] / xbmc / pvr / guilib / PVRGUIProgressHandler.cpp
blobf8765227ddb31b776af210cdafd18ffd4b3d4ab2
1 /*
2 * Copyright (C) 2017-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 "PVRGUIProgressHandler.h"
11 #include "ServiceBroker.h"
12 #include "dialogs/GUIDialogExtendedProgressBar.h"
13 #include "guilib/GUIComponent.h"
14 #include "guilib/GUIWindowManager.h"
15 #include "guilib/WindowIDs.h"
17 #include <algorithm>
18 #include <cmath>
19 #include <mutex>
20 #include <string>
22 using namespace std::chrono_literals;
24 namespace PVR
27 CPVRGUIProgressHandler::CPVRGUIProgressHandler(const std::string& strTitle)
28 : CThread("PVRGUIProgressHandler"), m_strTitle(strTitle)
32 void CPVRGUIProgressHandler::UpdateProgress(const std::string& strText, float fProgress)
34 std::unique_lock<CCriticalSection> lock(m_critSection);
35 m_bChanged = true;
36 m_strText = strText;
37 m_fProgress = fProgress;
39 if (!m_bCreated)
41 m_bCreated = true;
42 Create();
46 void CPVRGUIProgressHandler::UpdateProgress(const std::string& strText, int iCurrent, int iMax)
48 float fPercentage = (iCurrent * 100.0f) / iMax;
49 if (!std::isnan(fPercentage))
50 fPercentage = std::min(100.0f, fPercentage);
52 UpdateProgress(strText, fPercentage);
55 void CPVRGUIProgressHandler::Process()
57 CGUIDialogExtendedProgressBar* progressBar =
58 CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogExtendedProgressBar>(
59 WINDOW_DIALOG_EXT_PROGRESS);
60 if (m_bStop || !progressBar)
61 return;
63 CGUIDialogProgressBarHandle* progressHandle = progressBar->GetHandle(m_strTitle);
64 if (!progressHandle)
65 return;
67 while (!m_bStop)
69 float fProgress = 0.0;
70 std::string strText;
71 bool bUpdate = false;
74 std::unique_lock<CCriticalSection> lock(m_critSection);
75 if (m_bChanged)
77 m_bChanged = false;
78 fProgress = m_fProgress;
79 strText = m_strText;
80 bUpdate = true;
84 if (bUpdate)
86 progressHandle->SetPercentage(fProgress);
87 progressHandle->SetText(strText);
90 // Intentionally ignore some changes that come in too fast. Humans cannot read as fast as Mr. Data ;-)
91 CThread::Sleep(100ms);
94 progressHandle->MarkFinished();
97 } // namespace PVR