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

oglcontextfactory.cpp « drape - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4d2d17d0b94cafdd5827d8f51d69abb6caf9fb79 (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
#include "drape/oglcontextfactory.hpp"

namespace dp
{

ThreadSafeFactory::ThreadSafeFactory(OGLContextFactory * factory, bool enableSharing)
  : m_factory(factory)
  , m_enableSharing(enableSharing)
{
}

ThreadSafeFactory::~ThreadSafeFactory()
{
  delete m_factory;
}

OGLContext * ThreadSafeFactory::getDrawContext()
{
  return CreateContext([this](){ return m_factory->getDrawContext(); },
                       [this](){ return m_factory->isUploadContextCreated(); });
}

OGLContext *ThreadSafeFactory::getResourcesUploadContext()
{
  return CreateContext([this](){ return m_factory->getResourcesUploadContext(); },
                       [this](){ return m_factory->isDrawContextCreated(); });
}

OGLContext * ThreadSafeFactory::CreateContext(TCreateCtxFn const & createFn, TIsSeparateCreatedFn const checkFn)
{
  threads::ConditionGuard g(m_contidion);
  OGLContext * ctx = createFn();
  if (m_enableSharing)
  {
    if (!checkFn())
      g.Wait();
    else
      g.Signal();
  }

  return ctx;
}

void ThreadSafeFactory::waitForInitialization()
{
  m_factory->waitForInitialization();
}

} // namespace dp