mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-10 16:19:28 +01:00
89 lines
1.6 KiB
C++
89 lines
1.6 KiB
C++
|
#include "VideoCommon/AsyncRequests.h"
|
||
|
#include "VideoCommon/RenderBase.h"
|
||
|
|
||
|
AsyncRequests AsyncRequests::s_singleton;
|
||
|
|
||
|
AsyncRequests::AsyncRequests()
|
||
|
: m_enable(false)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
void AsyncRequests::PullEventsInternal()
|
||
|
{
|
||
|
std::unique_lock<std::mutex> lock(m_mutex);
|
||
|
m_empty.store(true);
|
||
|
|
||
|
while (!m_queue.empty())
|
||
|
{
|
||
|
const Event& e = m_queue.front();
|
||
|
|
||
|
lock.unlock();
|
||
|
HandleEvent(e);
|
||
|
lock.lock();
|
||
|
|
||
|
m_queue.pop();
|
||
|
}
|
||
|
|
||
|
if (m_wake_me_up_again)
|
||
|
{
|
||
|
m_wake_me_up_again = false;
|
||
|
m_cond.notify_all();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void AsyncRequests::PushEvent(const AsyncRequests::Event& event, bool blocking)
|
||
|
{
|
||
|
std::unique_lock<std::mutex> lock(m_mutex);
|
||
|
m_empty.store(false);
|
||
|
m_wake_me_up_again |= blocking;
|
||
|
|
||
|
if (!m_enable)
|
||
|
return;
|
||
|
|
||
|
m_queue.push(event);
|
||
|
|
||
|
if (blocking)
|
||
|
{
|
||
|
m_cond.wait(lock, [this]{return m_queue.empty();});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void AsyncRequests::SetEnable(bool enable)
|
||
|
{
|
||
|
std::unique_lock<std::mutex> lock(m_mutex);
|
||
|
m_enable = enable;
|
||
|
|
||
|
if (!enable)
|
||
|
{
|
||
|
// flush the queue on disabling
|
||
|
while (!m_queue.empty())
|
||
|
m_queue.pop();
|
||
|
if (m_wake_me_up_again)
|
||
|
m_cond.notify_all();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void AsyncRequests::HandleEvent(const AsyncRequests::Event& e)
|
||
|
{
|
||
|
switch (e.type)
|
||
|
{
|
||
|
case Event::EFB_POKE_COLOR:
|
||
|
g_renderer->AccessEFB(POKE_COLOR, e.efb_poke.x, e.efb_poke.y, e.efb_poke.data);
|
||
|
break;
|
||
|
|
||
|
case Event::EFB_POKE_Z:
|
||
|
g_renderer->AccessEFB(POKE_Z, e.efb_poke.x, e.efb_poke.y, e.efb_poke.data);
|
||
|
break;
|
||
|
|
||
|
case Event::EFB_PEEK_COLOR:
|
||
|
*e.efb_peek.data = g_renderer->AccessEFB(PEEK_COLOR, e.efb_peek.x, e.efb_peek.y, 0);
|
||
|
break;
|
||
|
|
||
|
case Event::EFB_PEEK_Z:
|
||
|
*e.efb_peek.data = g_renderer->AccessEFB(PEEK_Z, e.efb_peek.x, e.efb_peek.y, 0);
|
||
|
break;
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|