forked from organicmaps/organicmaps
Added stop rendering on FR while user is inactive
This commit is contained in:
parent
875192615a
commit
3b009921ae
6 changed files with 62 additions and 15 deletions
|
@ -458,23 +458,31 @@ void FrontendRenderer::Routine::Do()
|
|||
context->setDefaultFramebuffer();
|
||||
m_renderer.m_textureManager->UpdateDynamicTextures();
|
||||
m_renderer.RenderScene();
|
||||
m_renderer.UpdateScene();
|
||||
bool const viewChanged = m_renderer.UpdateScene();
|
||||
context->present();
|
||||
|
||||
double availableTime = VSyncInterval - (timer.ElapsedSeconds() /*+ avarageMessageTime*/);
|
||||
|
||||
if (availableTime < 0.0)
|
||||
availableTime = 0.01;
|
||||
|
||||
while (availableTime > 0)
|
||||
if (!viewChanged && m_renderer.IsQueueEmpty())
|
||||
{
|
||||
m_renderer.ProcessSingleMessage(availableTime * 1000.0);
|
||||
availableTime = VSyncInterval - (timer.ElapsedSeconds() /*+ avarageMessageTime*/);
|
||||
//messageCount++;
|
||||
// process a message or wait for a message
|
||||
m_renderer.ProcessSingleMessage();
|
||||
}
|
||||
else
|
||||
{
|
||||
double availableTime = VSyncInterval - (timer.ElapsedSeconds() /*+ avarageMessageTime*/);
|
||||
|
||||
if (availableTime < 0.0)
|
||||
availableTime = 0.01;
|
||||
|
||||
while (availableTime > 0)
|
||||
{
|
||||
m_renderer.ProcessSingleMessage(availableTime * 1000.0);
|
||||
availableTime = VSyncInterval - (timer.ElapsedSeconds() /*+ avarageMessageTime*/);
|
||||
//messageCount++;
|
||||
}
|
||||
|
||||
//processingTime = (timer.ElapsedSeconds() - processingTime) / messageCount;
|
||||
}
|
||||
|
||||
//processingTime = (timer.ElapsedSeconds() - processingTime) / messageCount;
|
||||
|
||||
context->present();
|
||||
timer.Reset();
|
||||
|
||||
m_renderer.CheckRenderingEnabled();
|
||||
|
@ -499,9 +507,14 @@ void FrontendRenderer::SetModelView(ScreenBase const & screen)
|
|||
{
|
||||
lock_guard<mutex> lock(m_modelViewMutex);
|
||||
m_newView = screen;
|
||||
|
||||
// check if view changed and cancel endless message waiting
|
||||
bool const viewChanged = (m_view != m_newView);
|
||||
if (viewChanged && IsInInfinityWaiting())
|
||||
CancelMessageWaiting();
|
||||
}
|
||||
|
||||
void FrontendRenderer::UpdateScene()
|
||||
bool FrontendRenderer::UpdateScene()
|
||||
{
|
||||
lock_guard<mutex> lock(m_modelViewMutex);
|
||||
if (m_view != m_newView)
|
||||
|
@ -516,7 +529,9 @@ void FrontendRenderer::UpdateScene()
|
|||
m_commutator->PostMessage(ThreadsCommutator::ResourceUploadThread,
|
||||
make_unique_dp<UpdateReadManagerMessage>(m_view, move(tiles)),
|
||||
MessagePriority::Normal);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace df
|
||||
|
|
|
@ -89,7 +89,7 @@ private:
|
|||
|
||||
private:
|
||||
// it applies new model-view matrix to the scene (this matrix will be used on next frame)
|
||||
void UpdateScene();
|
||||
bool UpdateScene();
|
||||
|
||||
void AddToRenderGroup(vector<drape_ptr<RenderGroup>> & groups,
|
||||
dp::GLState const & state,
|
||||
|
|
|
@ -5,9 +5,17 @@
|
|||
namespace df
|
||||
{
|
||||
|
||||
MessageAcceptor::MessageAcceptor()
|
||||
: m_infinityWaiting(false)
|
||||
{
|
||||
}
|
||||
|
||||
void MessageAcceptor::ProcessSingleMessage(unsigned maxTimeWait)
|
||||
{
|
||||
m_infinityWaiting = (maxTimeWait == -1);
|
||||
drape_ptr<Message> message = m_messageQueue.PopMessage(maxTimeWait);
|
||||
m_infinityWaiting = false;
|
||||
|
||||
if (message == nullptr)
|
||||
return;
|
||||
|
||||
|
@ -31,4 +39,14 @@ void MessageAcceptor::CancelMessageWaiting()
|
|||
m_messageQueue.CancelWait();
|
||||
}
|
||||
|
||||
bool MessageAcceptor::IsInInfinityWaiting() const
|
||||
{
|
||||
return m_infinityWaiting;
|
||||
}
|
||||
|
||||
bool MessageAcceptor::IsQueueEmpty()
|
||||
{
|
||||
return m_messageQueue.IsEmpty();
|
||||
}
|
||||
|
||||
} // namespace df
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
#include "drape/pointers.hpp"
|
||||
|
||||
#include "std/atomic.hpp"
|
||||
|
||||
namespace df
|
||||
{
|
||||
|
||||
|
@ -12,6 +14,7 @@ class Message;
|
|||
class MessageAcceptor
|
||||
{
|
||||
protected:
|
||||
MessageAcceptor();
|
||||
virtual ~MessageAcceptor(){}
|
||||
|
||||
virtual void AcceptMessage(ref_ptr<Message> message) = 0;
|
||||
|
@ -24,6 +27,9 @@ protected:
|
|||
|
||||
void CloseQueue();
|
||||
|
||||
bool IsInInfinityWaiting() const;
|
||||
bool IsQueueEmpty();
|
||||
|
||||
private:
|
||||
friend class ThreadsCommutator;
|
||||
|
||||
|
@ -31,6 +37,7 @@ private:
|
|||
|
||||
private:
|
||||
MessageQueue m_messageQueue;
|
||||
atomic<bool> m_infinityWaiting;
|
||||
};
|
||||
|
||||
} // namespace df
|
||||
|
|
|
@ -53,6 +53,12 @@ void MessageQueue::PushMessage(drape_ptr<Message> && message, MessagePriority pr
|
|||
guard.Signal();
|
||||
}
|
||||
|
||||
bool MessageQueue::IsEmpty()
|
||||
{
|
||||
threads::ConditionGuard guard(m_condition);
|
||||
return m_messages.empty();
|
||||
}
|
||||
|
||||
void MessageQueue::WaitMessage(unsigned maxTimeWait)
|
||||
{
|
||||
if (m_messages.empty())
|
||||
|
|
|
@ -21,6 +21,7 @@ public:
|
|||
void PushMessage(drape_ptr<Message> && message, MessagePriority priority);
|
||||
void CancelWait();
|
||||
void ClearQuery();
|
||||
bool IsEmpty();
|
||||
|
||||
private:
|
||||
void WaitMessage(unsigned maxTimeWait);
|
||||
|
|
Loading…
Add table
Reference in a new issue