PageRenderTime 38ms CodeModel.GetById 31ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/xbmc/guilib/DirtyRegionSolvers.cpp

http://github.com/xbmc/xbmc
C++ | 73 lines | 53 code | 12 blank | 8 comment | 8 complexity | aa9f740a41ac91d7a91a90cf9c350b7f MD5 | raw file
 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 "DirtyRegionSolvers.h"
10
11#include "windowing/GraphicContext.h"
12
13#include <stdio.h>
14
15void CUnionDirtyRegionSolver::Solve(const CDirtyRegionList &input, CDirtyRegionList &output)
16{
17  CDirtyRegion unifiedRegion;
18  for (unsigned int i = 0; i < input.size(); i++)
19    unifiedRegion.Union(input[i]);
20
21  if (!unifiedRegion.IsEmpty())
22    output.push_back(unifiedRegion);
23}
24
25void CFillViewportAlwaysRegionSolver::Solve(const CDirtyRegionList &input, CDirtyRegionList &output)
26{
27  CDirtyRegion unifiedRegion(CServiceBroker::GetWinSystem()->GetGfxContext().GetViewWindow());
28  output.push_back(unifiedRegion);
29}
30
31void CFillViewportOnChangeRegionSolver::Solve(const CDirtyRegionList &input, CDirtyRegionList &output)
32{
33  if (!input.empty())
34    output.assign(1,CDirtyRegion(CServiceBroker::GetWinSystem()->GetGfxContext().GetViewWindow()));
35}
36
37CGreedyDirtyRegionSolver::CGreedyDirtyRegionSolver()
38{
39  m_costNewRegion = 10.0f;
40  m_costPerArea   = 0.01f;
41}
42
43void CGreedyDirtyRegionSolver::Solve(const CDirtyRegionList &input, CDirtyRegionList &output)
44{
45  for (unsigned int i = 0; i < input.size(); i++)
46  {
47    CDirtyRegion possibleUnionRegion;
48    int   possibleUnionNbr = -1;
49    float possibleUnionCost = 100000.0f;
50
51    CDirtyRegion currentRegion = input[i];
52    for (unsigned int j = 0; j < output.size(); j++)
53    {
54      CDirtyRegion temporaryUnion = output[j];
55      temporaryUnion.Union(currentRegion);
56      float temporaryCost = m_costPerArea * (temporaryUnion.Area() - output[j].Area());
57      if (temporaryCost < possibleUnionCost)
58      {
59        //! @todo if the temporaryCost is 0 then we could skip checking the other regions since there exist no better solution
60        possibleUnionRegion = temporaryUnion;
61        possibleUnionNbr    = j;
62        possibleUnionCost   = temporaryCost;
63      }
64    }
65
66    float newRegionTotalCost = m_costPerArea * currentRegion.Area() + m_costNewRegion;
67
68    if (possibleUnionNbr >= 0 && possibleUnionCost < newRegionTotalCost)
69      output[possibleUnionNbr] = possibleUnionRegion;
70    else
71      output.push_back(currentRegion);
72  }
73}