1 /*
2  *  Copyright (C) 2005-2018 Team Kodi
3  *  This file is part of Kodi - https://kodi.tv
4  *
5  *  SPDX-License-Identifier: GPL-2.0-or-later
6  *  See LICENSES/README.md for more information.
7  */
8 
9 #include "DirtyRegionTracker.h"
10 
11 #include "DirtyRegionSolvers.h"
12 #include "ServiceBroker.h"
13 #include "settings/AdvancedSettings.h"
14 #include "settings/SettingsComponent.h"
15 #include "utils/log.h"
16 
17 #include <stdio.h>
18 
CDirtyRegionTracker(int buffering)19 CDirtyRegionTracker::CDirtyRegionTracker(int buffering)
20 {
21   m_buffering = buffering;
22   m_solver = NULL;
23 }
24 
~CDirtyRegionTracker()25 CDirtyRegionTracker::~CDirtyRegionTracker()
26 {
27   delete m_solver;
28 }
29 
SelectAlgorithm()30 void CDirtyRegionTracker::SelectAlgorithm()
31 {
32   delete m_solver;
33 
34   switch (CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_guiAlgorithmDirtyRegions)
35   {
36     case DIRTYREGION_SOLVER_FILL_VIEWPORT_ON_CHANGE:
37       CLog::Log(LOGDEBUG, "guilib: Fill viewport on change for solving rendering passes");
38       m_solver = new CFillViewportOnChangeRegionSolver();
39       break;
40     case DIRTYREGION_SOLVER_COST_REDUCTION:
41       CLog::Log(LOGDEBUG, "guilib: Cost reduction as algorithm for solving rendering passes");
42       m_solver = new CGreedyDirtyRegionSolver();
43       break;
44     case DIRTYREGION_SOLVER_UNION:
45       m_solver = new CUnionDirtyRegionSolver();
46       CLog::Log(LOGDEBUG, "guilib: Union as algorithm for solving rendering passes");
47       break;
48     case DIRTYREGION_SOLVER_FILL_VIEWPORT_ALWAYS:
49     default:
50       CLog::Log(LOGDEBUG, "guilib: Fill viewport always for solving rendering passes");
51       m_solver = new CFillViewportAlwaysRegionSolver();
52       break;
53   }
54 }
55 
MarkDirtyRegion(const CDirtyRegion & region)56 void CDirtyRegionTracker::MarkDirtyRegion(const CDirtyRegion &region)
57 {
58   if (!region.IsEmpty())
59     m_markedRegions.push_back(region);
60 }
61 
GetMarkedRegions() const62 const CDirtyRegionList &CDirtyRegionTracker::GetMarkedRegions() const
63 {
64   return m_markedRegions;
65 }
66 
GetDirtyRegions()67 CDirtyRegionList CDirtyRegionTracker::GetDirtyRegions()
68 {
69   CDirtyRegionList output;
70 
71   if (m_solver)
72     m_solver->Solve(m_markedRegions, output);
73 
74   return output;
75 }
76 
CleanMarkedRegions()77 void CDirtyRegionTracker::CleanMarkedRegions()
78 {
79   int buffering = CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_guiVisualizeDirtyRegions ? 20 : m_buffering;
80   int i = m_markedRegions.size() - 1;
81   while (i >= 0)
82 	{
83     if (m_markedRegions[i].UpdateAge() >= buffering)
84       m_markedRegions.erase(m_markedRegions.begin() + i);
85 
86     i--;
87   }
88 }
89