[cosmetics] update date in GPL header
[vuplus_xbmc] / xbmc / guilib / DirtyRegionTracker.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://www.xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 #include "DirtyRegionTracker.h"
22 #include "settings/AdvancedSettings.h"
23 #include "utils/log.h"
24 #include <stdio.h>
25
26 CDirtyRegionTracker::CDirtyRegionTracker(int buffering)
27 {
28   m_buffering = buffering;
29   m_solver = NULL;
30 }
31
32 CDirtyRegionTracker::~CDirtyRegionTracker()
33 {
34   delete m_solver;
35 }
36
37 void CDirtyRegionTracker::SelectAlgorithm()
38 {
39   delete m_solver;
40
41   switch (g_advancedSettings.m_guiAlgorithmDirtyRegions)
42   {
43     case DIRTYREGION_SOLVER_FILL_VIEWPORT_ON_CHANGE:
44       CLog::Log(LOGDEBUG, "guilib: Fill viewport on change for solving rendering passes");
45       m_solver = new CFillViewportOnChangeRegionSolver();
46       break;
47     case DIRTYREGION_SOLVER_COST_REDUCTION:
48       CLog::Log(LOGDEBUG, "guilib: Cost reduction as algorithm for solving rendering passes");
49       m_solver = new CGreedyDirtyRegionSolver();
50       break;
51     case DIRTYREGION_SOLVER_UNION:
52       m_solver = new CUnionDirtyRegionSolver();
53       CLog::Log(LOGDEBUG, "guilib: Union as algorithm for solving rendering passes");
54       break;
55     case DIRTYREGION_SOLVER_FILL_VIEWPORT_ALWAYS:
56     default:
57       CLog::Log(LOGDEBUG, "guilib: Fill viewport always for solving rendering passes");
58       m_solver = new CFillViewportAlwaysRegionSolver();
59       break;
60   }
61 }
62
63 void CDirtyRegionTracker::MarkDirtyRegion(const CDirtyRegion &region)
64 {
65   if (!region.IsEmpty())
66     m_markedRegions.push_back(region);
67 }
68
69 const CDirtyRegionList &CDirtyRegionTracker::GetMarkedRegions() const
70 {
71   return m_markedRegions;
72 }
73
74 CDirtyRegionList CDirtyRegionTracker::GetDirtyRegions()
75 {
76   CDirtyRegionList output;
77
78   if (m_solver)
79     m_solver->Solve(m_markedRegions, output);
80
81   return output;
82 }
83
84 void CDirtyRegionTracker::CleanMarkedRegions()
85 {
86   int buffering = g_advancedSettings.m_guiVisualizeDirtyRegions ? 20 : m_buffering;
87   int i = m_markedRegions.size() - 1;
88   while (i >= 0)
89         {
90     if (m_markedRegions[i].UpdateAge() >= buffering)
91       m_markedRegions.erase(m_markedRegions.begin() + i);
92
93     i--;
94   }
95 }