blob: 3b9b6d3c18f08926c2d2e17326abb9cd7bf56719 (
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
#include "window_handle.hpp"
#include "render_policy.hpp"
WindowHandle::WindowHandle() :
m_hasPendingUpdates(false),
m_isUpdatesEnabled(true),
m_needRedraw(true),
m_videoTimer(nullptr),
m_stallsCount(0)
{
}
void WindowHandle::setRenderPolicy(RenderPolicy * renderPolicy)
{
m_renderPolicy = renderPolicy;
}
void WindowHandle::setVideoTimer(VideoTimer * videoTimer)
{
m_videoTimer = videoTimer;
if (m_videoTimer != nullptr)
{
m_frameFn = videoTimer->frameFn();
m_videoTimer->setFrameFn(bind(&WindowHandle::checkedFrameFn, this));
}
m_stallsCount = 0;
}
void WindowHandle::checkedFrameFn()
{
if (m_renderPolicy->NeedRedraw())
m_stallsCount = 0;
else
++m_stallsCount;
if (m_stallsCount >= 60)
{
//LOG(LINFO, ("PausedDOWN"));
if (m_videoTimer != nullptr)
m_videoTimer->pause();
}
else
{
if (m_frameFn != nullptr)
m_frameFn();
}
}
WindowHandle::~WindowHandle()
{
if (m_videoTimer != nullptr)
{
m_videoTimer->stop();
m_videoTimer->setFrameFn(m_frameFn);
}
}
bool WindowHandle::needRedraw() const
{
return m_isUpdatesEnabled && m_needRedraw;
}
void WindowHandle::checkTimer()
{
if (m_videoTimer == nullptr)
return;
switch (m_videoTimer->state())
{
case VideoTimer::EStopped:
m_videoTimer->start();
break;
case VideoTimer::EPaused:
//LOG(LINFO, ("WokenUP"));
m_videoTimer->resume();
break;
default:
break;
}
}
void WindowHandle::setNeedRedraw(bool flag)
{
m_needRedraw = flag;
if (m_needRedraw && m_isUpdatesEnabled)
checkTimer();
}
shared_ptr<graphics::RenderContext> const & WindowHandle::renderContext()
{
return m_renderContext;
}
void WindowHandle::setRenderContext(shared_ptr<graphics::RenderContext> const & renderContext)
{
m_renderContext = renderContext;
}
bool WindowHandle::setUpdatesEnabled(bool doEnable)
{
bool res = false;
bool wasUpdatesEnabled = m_isUpdatesEnabled;
m_isUpdatesEnabled = doEnable;
if ((!wasUpdatesEnabled) && (doEnable) && (m_hasPendingUpdates))
{
setNeedRedraw(true);
m_hasPendingUpdates = false;
res = true;
}
return res;
}
void WindowHandle::invalidate()
{
if (m_isUpdatesEnabled)
setNeedRedraw(true);
else
m_hasPendingUpdates = true;
}
|