2 * Copyright (C) 2005-2013 Team XBMC
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)
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.
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/>.
21 #include "DirtyRegionSolvers.h"
22 #include "GraphicContext.h"
25 void CUnionDirtyRegionSolver::Solve(const CDirtyRegionList &input, CDirtyRegionList &output)
27 CDirtyRegion unifiedRegion;
28 for (unsigned int i = 0; i < input.size(); i++)
29 unifiedRegion.Union(input[i]);
31 if (!unifiedRegion.IsEmpty())
32 output.push_back(unifiedRegion);
35 void CFillViewportAlwaysRegionSolver::Solve(const CDirtyRegionList &input, CDirtyRegionList &output)
37 CDirtyRegion unifiedRegion(g_graphicsContext.GetViewWindow());
38 output.push_back(unifiedRegion);
41 void CFillViewportOnChangeRegionSolver::Solve(const CDirtyRegionList &input, CDirtyRegionList &output)
44 output.assign(1,g_graphicsContext.GetViewWindow());
47 CGreedyDirtyRegionSolver::CGreedyDirtyRegionSolver()
49 m_costNewRegion = 10.0f;
50 m_costPerArea = 0.01f;
53 void CGreedyDirtyRegionSolver::Solve(const CDirtyRegionList &input, CDirtyRegionList &output)
55 for (unsigned int i = 0; i < input.size(); i++)
57 CDirtyRegion possibleUnionRegion;
58 int possibleUnionNbr = -1;
59 float possibleUnionCost = 100000.0f;
61 CDirtyRegion currentRegion = input[i];
62 for (unsigned int j = 0; j < output.size(); j++)
64 CDirtyRegion temporaryUnion = output[j];
65 temporaryUnion.Union(currentRegion);
66 float temporaryCost = m_costPerArea * (temporaryUnion.Area() - output[j].Area());
67 if (temporaryCost < possibleUnionCost)
69 // TODO if the temporaryCost is 0 then we could skip checking the other regions since there exist no better solution
70 possibleUnionRegion = temporaryUnion;
72 possibleUnionCost = temporaryCost;
76 float newRegionTotalCost = m_costPerArea * currentRegion.Area() + m_costNewRegion;
78 if (possibleUnionNbr >= 0 && possibleUnionCost < newRegionTotalCost)
79 output[possibleUnionNbr] = possibleUnionRegion;
81 output.push_back(currentRegion);