Welcome to mirror list, hosted at ThFree Co, Russian Federation.

batchers_pool.cpp « drape_frontend - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ce0423cdfe12f87db03559b19e591012cd126e7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "drape_frontend/batchers_pool.hpp"
#include "drape_frontend/message_subclasses.hpp"

#include "drape/batcher.hpp"

#include "base/assert.hpp"

#include "std/bind.hpp"

namespace df
{

using dp::Batcher;

namespace
{

void FlushGeometry(BatchersPool::TSendMessageFn const & sendMessage,
                   TileKey const & key,
                   dp::GLState const & state,
                   drape_ptr<dp::RenderBucket> && buffer)
{
  sendMessage(make_unique_dp<FlushRenderBucketMessage>(key, state, move(buffer)));
}

} // namespace

BatchersPool::BatchersPool(int initBatcherCount, TSendMessageFn const & sendMessageFn)
  : m_sendMessageFn(sendMessageFn)
  , m_pool(initBatcherCount, dp::BatcherFactory())
{}

BatchersPool::~BatchersPool()
{
  for_each(m_batchs.begin(), m_batchs.end(), [this](pair<TileKey, TBatcherPair> const & p)
  {
    m_pool.Return(p.second.first);
  });

  m_batchs.clear();
}

void BatchersPool::ReserveBatcher(TileKey const & key)
{
  TIterator it = m_batchs.find(key);
  if (it != m_batchs.end())
  {
    it->second.second++;
    return;
  }
  Batcher * batcher = m_pool.Get();
  m_batchs.insert(make_pair(key, make_pair(batcher, 1)));
  batcher->StartSession(bind(&FlushGeometry, m_sendMessageFn, key, _1, _2));
}

ref_ptr<dp::Batcher> BatchersPool::GetTileBatcher(TileKey const & key)
{
  TIterator it = m_batchs.find(key);
  ASSERT(it != m_batchs.end(), ());
  return make_ref(it->second.first);
}

void BatchersPool::ReleaseBatcher(TileKey const & key)
{
  TIterator it = m_batchs.find(key);
  ASSERT(it != m_batchs.end(), ());
  ASSERT_GREATER(it->second.second, 0, ());
  if ((--it->second.second)== 0)
  {
    Batcher * batcher = it->second.first;
    batcher->EndSession();
    m_pool.Return(batcher);
    m_batchs.erase(it);
  }
}

} // namespace df