forked from mapsme/omim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoglcontextfactory.cpp
49 lines (40 loc) · 1.09 KB
/
oglcontextfactory.cpp
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