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

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

namespace dp
{
ThreadSafeFactory::ThreadSafeFactory(GraphicsContextFactory * factory, bool enableSharing)
  : m_factory(factory)
  , m_enableSharing(enableSharing)
{}

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

GraphicsContext * ThreadSafeFactory::GetDrawContext()
{
  return CreateContext([this](){ return m_factory->GetDrawContext(); },
                       [this](){ return m_factory->IsUploadContextCreated(); });
}

GraphicsContext * ThreadSafeFactory::GetResourcesUploadContext()
{
  return CreateContext([this](){ return m_factory->GetResourcesUploadContext(); },
                       [this](){ return m_factory->IsDrawContextCreated(); });
}

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

  return ctx;
}

void ThreadSafeFactory::WaitForInitialization(GraphicsContext * context)
{
  m_factory->WaitForInitialization(context);
}
  
void ThreadSafeFactory::SetPresentAvailable(bool available)
{
  m_factory->SetPresentAvailable(available);
}
}  // namespace dp