blob: 395c06a56ca11f20c34122272e4c81a1885d7545 (
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
|
#pragma once
#include "drape/graphics_context.hpp"
#include "base/condition.hpp"
#include "base/assert.hpp"
#include <functional>
namespace dp
{
class GraphicsContextFactory
{
public:
virtual ~GraphicsContextFactory() = default;
virtual GraphicsContext * GetDrawContext() = 0;
virtual GraphicsContext * GetResourcesUploadContext() = 0;
virtual bool IsDrawContextCreated() const { return false; }
virtual bool IsUploadContextCreated() const { return false; }
virtual void WaitForInitialization(dp::GraphicsContext * context) {}
virtual void SetPresentAvailable(bool available) {}
};
class ThreadSafeFactory : public GraphicsContextFactory
{
public:
ThreadSafeFactory(GraphicsContextFactory * factory, bool enableSharing = true);
~ThreadSafeFactory();
GraphicsContext * GetDrawContext() override;
GraphicsContext * GetResourcesUploadContext() override;
template<typename T>
T * CastFactory()
{
ASSERT(dynamic_cast<T *>(m_factory) != nullptr, ());
return static_cast<T *>(m_factory);
}
void WaitForInitialization(dp::GraphicsContext * context) override;
void SetPresentAvailable(bool available) override;
protected:
using TCreateCtxFn = std::function<GraphicsContext * ()>;
using TIsSeparateCreatedFn = std::function<bool()>;
GraphicsContext * CreateContext(TCreateCtxFn const & createFn,
TIsSeparateCreatedFn const & checkFn);
private:
GraphicsContextFactory * m_factory;
threads::Condition m_condition;
bool m_enableSharing;
};
} // namespace dp
|