blob: f3cb2fe3666e094d983c78431c9b0a495969145d (
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
|
#pragma once
#include "drape/oglcontext.hpp"
#include "base/condition.hpp"
#include "base/assert.hpp"
#include "std/function.hpp"
namespace dp
{
class OGLContextFactory
{
public:
virtual ~OGLContextFactory() {}
virtual OGLContext * getDrawContext() = 0;
virtual OGLContext * getResourcesUploadContext() = 0;
virtual bool isDrawContextCreated() const { return false; }
virtual bool isUploadContextCreated() const { return false; }
virtual void waitForInitialization() {}
};
class ThreadSafeFactory : public OGLContextFactory
{
public:
ThreadSafeFactory(OGLContextFactory * factory, bool enableSharing = true);
~ThreadSafeFactory();
OGLContext * getDrawContext() override;
OGLContext * getResourcesUploadContext() override;
template<typename T>
T * CastFactory()
{
ASSERT(dynamic_cast<T *>(m_factory) != nullptr, ());
return static_cast<T *>(m_factory);
}
void waitForInitialization() override;
protected:
typedef function<OGLContext * ()> TCreateCtxFn;
typedef function<bool()> TIsSeparateCreatedFn;
OGLContext * CreateContext(TCreateCtxFn const & createFn, TIsSeparateCreatedFn const checkFn);
private:
OGLContextFactory * m_factory;
threads::Condition m_contidion;
bool m_enableSharing;
};
} // namespace dp
|