-
Notifications
You must be signed in to change notification settings - Fork 7
/
TimedDeviceContext.h
65 lines (54 loc) · 1.05 KB
/
TimedDeviceContext.h
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
54
55
56
57
58
59
60
61
62
63
64
65
#pragma once
namespace happy
{
class TimedDeviceContext
{
friend class RenderingContext;
TimedDeviceContext(ID3D11DeviceContext *context, const char *perfZone, function<void()> cb)
: m_pContext(context)
, m_pRef(new int)
, m_Callback(cb)
{
(*m_pRef) = 1;
}
ID3D11DeviceContext *m_pContext;
int *m_pRef;
function<void()> m_Callback;
public:
TimedDeviceContext(const TimedDeviceContext& other)
: m_pContext(other.m_pContext)
, m_pRef(other.m_pRef)
, m_Callback(other.m_Callback)
{
(*m_pRef)++;
}
TimedDeviceContext& operator=(const TimedDeviceContext& other)
{
m_pContext = other.m_pContext;
m_pRef = other.m_pRef;
m_Callback = other.m_Callback;
(*m_pRef)++;
}
~TimedDeviceContext()
{
(*m_pRef)--;
if ((*m_pRef) == 0)
{
m_Callback();
delete m_pRef;
}
}
operator ID3D11DeviceContext*() const
{
return m_pContext;
}
ID3D11DeviceContext& operator*() const
{
return *m_pContext;
}
ID3D11DeviceContext* operator->() const
{
return m_pContext;
}
};
}