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: b2c7762a83edc55436e766022929b4ebabf0adbd (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
#include "batchers_pool.hpp"
#include "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,
                   dp::TransferPointer<dp::RenderBucket> buffer)
{
  sendMessage(dp::MovePointer<Message>(new FlushRenderBucketMessage(key, state, buffer)));
}

} // namespace

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

BatchersPool::~BatchersPool()
{
  ASSERT(m_batchs.empty(), ());
}

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));
}

dp::RefPointer<dp::Batcher> BatchersPool::GetTileBatcher(TileKey const & key)
{
  TIterator it = m_batchs.find(key);
  ASSERT(it != m_batchs.end(), ());
  return dp::MakeStackRefPointer(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