Permalink
Browse files

[ios] - learn something from android 1. eat all events with each mess…

…agepump.

2. use a double-buffered queue to avoid excess locking.
  • Loading branch information...
1 parent 9ff141a commit 0ba76a06af6b7fd0b6b89f1dbe8b0d3e958291b0 @Memphiz Memphiz committed Jul 27, 2012
Showing with 14 additions and 18 deletions.
  1. +14 −18 xbmc/windowing/osx/WinEventsIOS.mm
@@ -53,41 +53,37 @@
bool CWinEventsIOS::MessagePump()
{
bool ret = false;
- bool gotEvent = false;
- XBMC_Event pumpEvent;
+ std::vector<XBMC_Event> copy_events;
- 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;
- }
- lock.Leave();
-
- if (gotEvent)
+ { // double-buffered events to avoid constant locking for OnEvent().
+ CSingleLock lock(g_inputCond);
+ copy_events = events;
+ events.clear();
+ }
+
+ for (vector<XBMC_Event>::iterator it = copy_events.begin(); it!=copy_events.end(); ++it)
{
- if (pumpEvent.type == XBMC_USEREVENT)
+ XBMC_Event *pumpEvent = (XBMC_Event *)&*it;
+ if (pumpEvent->type == XBMC_USEREVENT)
{
// On ATV2, we push in events as a XBMC_USEREVENT,
// the jbutton.which will be the keyID to translate using joystick.AppleRemote.xml
// jbutton.holdTime is the time the button is hold in ms (for repeated keypresses)
std::string joystickName = "AppleRemote";
bool isAxis = false;
float fAmount = 1.0;
- unsigned char wKeyID = pumpEvent.jbutton.which;
- unsigned int holdTime = pumpEvent.jbutton.holdTime;
+ unsigned char wKeyID = pumpEvent->jbutton.which;
+ unsigned int holdTime = pumpEvent->jbutton.holdTime;
CLog::Log(LOGDEBUG,"CWinEventsIOS: Button press keyID = %i", wKeyID);
ret |= g_application.ProcessJoystickEvent(joystickName, wKeyID, isAxis, fAmount, holdTime);
}
else
- ret |= g_application.OnEvent(pumpEvent);
+ ret |= g_application.OnEvent(*it);
//on ios touch devices - unfocus controls on finger lift
#if !defined(TARGET_DARWIN_IOS_ATV2)
- if (pumpEvent.type == XBMC_MOUSEBUTTONUP)
+ if (pumpEvent->type == XBMC_MOUSEBUTTONUP)
{
g_windowManager.SendMessage(GUI_MSG_UNFOCUS_ALL, 0, 0, 0, 0);
}

4 comments on commit 0ba76a0

Contributor
ulion commented on 0ba76a0 Feb 1, 2013

Found bug here, on ios, the first run MessagePump is in the process, with mouse 4, 5, 6 three events, then OnEvent(4) called show osd which seems inited a new message loop, then the left 5, 6 event is on the stack of the loop.
new events will be handled in the new message loop, after exit the new message loop, the left 5, 6 event finally got triggered, which cause problem on ios, how to replay:
come to a page with movies, click one, it start play, then touch a place where another movie was there but now covered by the playing movie, the control bar displayed, click stop button, movie stop playing, but now the second tap which opened the osd left 2 mouse events get triggered now, which will call up what ever (such as another movie if the tap positon was on the other movie item over playing movie)

sample test log:

2013-02-01 22:35:53.669 XBMC[917:2003] CWinEventsIOS::MessagePush(4) prelog

2013-02-01 22:35:53.670 XBMC[917:2003] CWinEventsIOS::MessagePush(4), [669, 336]

2013-02-01 22:35:53.672 XBMC[917:2003] CWinEventsIOS::MessagePush(5) prelog

2013-02-01 22:35:53.672 XBMC[917:2003] CWinEventsIOS::MessagePush(5), [669, 336]

2013-02-01 22:35:53.675 XBMC[917:2003] CWinEventsIOS::MessagePush(6) prelog

2013-02-01 22:35:53.676 XBMC[917:2003] CWinEventsIOS::MessagePush(6), [669, 336]

2013-02-01 22:35:53.692 XBMC[917:8303] 22:35:53 T:134189056   DEBUG:  CApplication::OnEvent(4) [669, 336]

2013-02-01 22:35:53.701 XBMC[917:8303] 22:35:53 T:134189056   DEBUG:  ------ Window Init (VideoOSD.xml) ------

2013-02-01 22:35:53.702 XBMC[917:8303] 22:35:53 T:134189056    INFO:  Loading skin file: VideoOSD.xml, load type: KEEP_IN_MEMORY

2013-02-01 22:35:54.073 XBMC[917:8303] 22:35:54 T:134189056   DEBUG:  Load VideoOSD.xml: 370.77ms

2013-02-01 22:35:54.141 XBMC[917:8303] 22:35:54 T:134189056   DEBUG:  Alloc resources: 439.08ms  (372.33 ms skin load)

2013-02-01 22:35:57.408 XBMC[917:2003] CWinEventsIOS::MessagePush(4) prelog

2013-02-01 22:35:57.409 XBMC[917:2003] CWinEventsIOS::MessagePush(4), [487, 641]

2013-02-01 22:35:57.409 XBMC[917:2003] CWinEventsIOS::MessagePush(5) prelog

2013-02-01 22:35:57.410 XBMC[917:2003] CWinEventsIOS::MessagePush(5), [487, 641]

2013-02-01 22:35:57.411 XBMC[917:2003] CWinEventsIOS::MessagePush(6) prelog

2013-02-01 22:35:57.411 XBMC[917:2003] CWinEventsIOS::MessagePush(6), [487, 641]

2013-02-01 22:35:57.451 XBMC[917:8303] 22:35:57 T:134189056   DEBUG:  CApplication::OnEvent(4) [487, 641]

2013-02-01 22:35:57.455 XBMC[917:8303] 22:35:57 T:134189056   DEBUG:  CApplication::OnEvent(5) [487, 641]

2013-02-01 22:35:57.456 XBMC[917:8303] 22:35:57 T:134189056   DEBUG:  CApplication::OnEvent(6) [487, 641]

........2013-02-01 22:35:57.793 XBMC[917:8303] 22:35:57 T:134189056   DEBUG:  CGUIWindowManager::PreviousWindow: Deactivate

2013-02-01 22:35:57.794 XBMC[917:8303] 22:35:57 T:134189056   DEBUG:  ------ Window Deinit (VideoOSD.xml) ------

2013-02-01 22:35:57.795 XBMC[917:8303] 22:35:57 T:134189056   DEBUG:  ExecuteXBMCAction : Translating Skin.Reset(PlayerControlsSubMenuVisible)

2013-02-01 22:35:57.797 XBMC[917:8303] 22:35:57 T:134189056   DEBUG:  ExecuteXBMCAction : To Skin.Reset(PlayerControlsSubMenuVisible)

2013-02-01 22:35:57.886 XBMC[917:8303] 22:35:57 T:134189056   DEBUG:  ------ Window Deinit (VideoFullScreen.xml) ------

2013-02-01 22:35:57.953 XBMC[917:8303] 22:35:57 T:134189056   DEBUG:  CGUIWindowManager::PreviousWindow: Activate new

2013-02-01 22:35:57.982 XBMC[917:8303] 22:35:57 T:134189056   DEBUG:  ------ Window Init (MyVideoNav.xml) ------

2013-02-01 22:35:58.029 XBMC[917:8303] 22:35:58 T:134189056   DEBUG:  Window MyVideoNav.xml was already loaded

2013-02-01 22:35:58.030 XBMC[917:8303] 22:35:58 T:134189056   DEBUG:  Alloc resources: 45.33m

2013-02-01 22:35:58.038 XBMC[917:8303] 22:35:58 T:134189056   DEBUG:  CGUIMediaWindow::GetDirectory (plugin://plugin.video.xunleiark/root_square/)

2013-02-01 22:35:58.039 XBMC[917:8303] 22:35:58 T:134189056   DEBUG:    ParentPath = [plugin://plugin.video.xunleiark/root_square/]

2013-02-01 22:35:58.049 XBMC[917:8303] 22:35:58 T:134189056   DEBUG:  Loading fileitems [plugin://plugin.video.xunleiark/root_square/]

2013-02-01 22:35:58.307 XBMC[917:8303] 22:35:58 T:134189056   DEBUG:    -- items: 69, directory: plugin://plugin.video.xunleiark/root_square/ sort method: 0, ascending: false

2013-02-01 22:35:58.339 XBMC[917:8303] 22:35:58 T:134189056   DEBUG:  RunQuery took 12 ms for 21 items query: SELECT  files.strFilename, files.playCount,  bookmark.timeInSeconds, bookmark.totalTimeInSeconds FROM files  LEFT JOIN bookmark ON    files.idFile = bookmark.idFile AND bookmark.type = 1  WHERE files.idPath=2

2013-02-01 22:35:58.694 XBMC[917:8303] 22:35:58 T:134189056   DEBUG:  Unfocus WindowID: 10025, ControlID: 50

2013-02-01 22:35:59.067 XBMC[917:8303] 22:35:59 T:134189056   DEBUG:  CApplication::OnEvent(5) [669, 336]

2013-02-01 22:35:59.068 XBMC[917:8303] 22:35:59 T:134189056   DEBUG:  CApplication::OnEvent(6) [669, 336]

2013-02-01 22:35:59.069 XBMC[917:8303] 22:35:59 T:134189056   DEBUG:  ProcessMouse: trying mouse action leftclick

Contributor
ulion replied Feb 2, 2013

@Memphiz did you see this?

Owner

Yes i did - but i'm painting my flat Atm and am busy in the Mess ;) - @davilla your handle ;)

Contributor
ulion replied Feb 3, 2013

I can't wait and send a PR for it:#2167
@davilla or you can check whether it is suitable.
seriously, it there is 12.1, this should be included.

Please sign in to comment.