[cosmetics] update date in GPL header
[vuplus_xbmc] / xbmc / guilib / DirtyRegionSolvers.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 "DirtyRegionSolvers.h"
22 #include "GraphicContext.h"
23 #include <stdio.h>
24
25 void CUnionDirtyRegionSolver::Solve(const CDirtyRegionList &input, CDirtyRegionList &output)
26 {
27   CDirtyRegion unifiedRegion;
28   for (unsigned int i = 0; i < input.size(); i++)
29     unifiedRegion.Union(input[i]);
30
31   if (!unifiedRegion.IsEmpty())
32     output.push_back(unifiedRegion);
33 }
34
35 void CFillViewportAlwaysRegionSolver::Solve(const CDirtyRegionList &input, CDirtyRegionList &output)
36 {
37   CDirtyRegion unifiedRegion(g_graphicsContext.GetViewWindow());
38   output.push_back(unifiedRegion);
39 }
40
41 void CFillViewportOnChangeRegionSolver::Solve(const CDirtyRegionList &input, CDirtyRegionList &output)
42 {
43   if (input.size() > 0)
44     output.assign(1,g_graphicsContext.GetViewWindow());
45 }
46
47 CGreedyDirtyRegionSolver::CGreedyDirtyRegionSolver()
48 {
49   m_costNewRegion = 10.0f;
50   m_costPerArea   = 0.01f;
51 }
52
53 void CGreedyDirtyRegionSolver::Solve(const CDirtyRegionList &input, CDirtyRegionList &output)
54 {
55   for (unsigned int i = 0; i < input.size(); i++)
56   {
57     CDirtyRegion possibleUnionRegion;
58     int   possibleUnionNbr = -1;
59     float possibleUnionCost = 100000.0f;
60
61     CDirtyRegion currentRegion = input[i];
62     for (unsigned int j = 0; j < output.size(); j++)
63     {
64       CDirtyRegion temporaryUnion = output[j];
65       temporaryUnion.Union(currentRegion);
66       float temporaryCost = m_costPerArea * (temporaryUnion.Area() - output[j].Area());
67       if (temporaryCost < possibleUnionCost)
68       {
69         // TODO if the temporaryCost is 0 then we could skip checking the other regions since there exist no better solution
70         possibleUnionRegion = temporaryUnion;
71         possibleUnionNbr    = j;
72         possibleUnionCost   = temporaryCost;
73       }
74     }
75
76     float newRegionTotalCost = m_costPerArea * currentRegion.Area() + m_costNewRegion;
77
78     if (possibleUnionNbr >= 0 && possibleUnionCost < newRegionTotalCost)
79       output[possibleUnionNbr] = possibleUnionRegion;
80     else
81       output.push_back(currentRegion);
82   }
83 }