Skip to content
This repository has been archived by the owner on Sep 30, 2018. It is now read-only.

Commit

Permalink
[droid] cleanup input handling
Browse files Browse the repository at this point in the history
1. eat all events with each messagepump. Fixes lagging mouse.
2. use a double-buffered queue to avoid excess locking.
  • Loading branch information
Cory Fields committed Aug 1, 2012
1 parent 16101a9 commit d26f512
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions xbmc/windowing/android/WinEventsAndroid.cpp
Expand Up @@ -32,7 +32,8 @@ static CCriticalSection g_inputCond;

PHANDLE_EVENT_FUNC CWinEventsBase::m_pEventFunc = NULL;

static std::vector<XBMC_Event> events;
static std::deque<XBMC_Event> events;
static std::deque<XBMC_Event> copy_events;

void CWinEventsAndroid::DeInit()
{
Expand All @@ -45,30 +46,23 @@ void CWinEventsAndroid::Init()
void CWinEventsAndroid::MessagePush(XBMC_Event *newEvent)
{
CSingleLock lock(g_inputCond);

events.push_back(*newEvent);
}

bool CWinEventsAndroid::MessagePump()
{
bool ret = false;
bool gotEvent = false;
XBMC_Event pumpEvent;

CSingleLock lock(g_inputCond);
for (vector<XBMC_Event>::iterator it = events.begin(); it!=events.end(); ++it)
{
memcpy(&pumpEvent, (XBMC_Event *)&*it, sizeof(XBMC_Event));
events.erase (events.begin(),events.begin()+1);
gotEvent = true;
break;
{ // double-buffered queue to avoid constant locking for OnEvent().
CSingleLock lock(g_inputCond);
copy_events = events;
events.clear();
}
lock.Leave();

if (gotEvent)
while (!copy_events.empty())
{
ret = g_application.OnEvent(pumpEvent);
pumpEvent = copy_events.front();
copy_events.pop_front();
ret |= g_application.OnEvent(pumpEvent);
}

return ret;
}

0 comments on commit d26f512

Please sign in to comment.