2 * Copyright (C) 2005-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.
9 #include "DirtyRegionSolvers.h"
11 #include "windowing/GraphicContext.h"
15 void CUnionDirtyRegionSolver::Solve(const CDirtyRegionList
&input
, CDirtyRegionList
&output
)
17 CDirtyRegion unifiedRegion
;
18 for (unsigned int i
= 0; i
< input
.size(); i
++)
19 unifiedRegion
.Union(input
[i
]);
21 if (!unifiedRegion
.IsEmpty())
22 output
.push_back(unifiedRegion
);
25 void CFillViewportAlwaysRegionSolver::Solve(const CDirtyRegionList
&input
, CDirtyRegionList
&output
)
27 CDirtyRegion
unifiedRegion(CServiceBroker::GetWinSystem()->GetGfxContext().GetViewWindow());
28 output
.push_back(unifiedRegion
);
31 void CFillViewportOnChangeRegionSolver::Solve(const CDirtyRegionList
&input
, CDirtyRegionList
&output
)
34 output
.assign(1,CDirtyRegion(CServiceBroker::GetWinSystem()->GetGfxContext().GetViewWindow()));
37 CGreedyDirtyRegionSolver::CGreedyDirtyRegionSolver()
39 m_costNewRegion
= 10.0f
;
40 m_costPerArea
= 0.01f
;
43 void CGreedyDirtyRegionSolver::Solve(const CDirtyRegionList
&input
, CDirtyRegionList
&output
)
45 for (unsigned int i
= 0; i
< input
.size(); i
++)
47 CDirtyRegion possibleUnionRegion
;
48 int possibleUnionNbr
= -1;
49 float possibleUnionCost
= 100000.0f
;
51 CDirtyRegion currentRegion
= input
[i
];
52 for (unsigned int j
= 0; j
< output
.size(); j
++)
54 CDirtyRegion temporaryUnion
= output
[j
];
55 temporaryUnion
.Union(currentRegion
);
56 float temporaryCost
= m_costPerArea
* (temporaryUnion
.Area() - output
[j
].Area());
57 if (temporaryCost
< possibleUnionCost
)
59 //! @todo if the temporaryCost is 0 then we could skip checking the other regions since there exist no better solution
60 possibleUnionRegion
= temporaryUnion
;
62 possibleUnionCost
= temporaryCost
;
66 float newRegionTotalCost
= m_costPerArea
* currentRegion
.Area() + m_costNewRegion
;
68 if (possibleUnionNbr
>= 0 && possibleUnionCost
< newRegionTotalCost
)
69 output
[possibleUnionNbr
] = possibleUnionRegion
;
71 output
.push_back(currentRegion
);