Bug 1260736 - Let the client to filter out its interested messages to lower the number of times entering the monitor in PeekMessages(). r=dvander

This commit is contained in:
Ting-Yu Chou 2016-04-13 09:51:34 +08:00
parent 7757c74ac0
commit 964d4d12f1
4 changed files with 34 additions and 36 deletions

View File

@ -988,14 +988,13 @@ MessageChannel::OnMessageReceivedFromLink(Message&& aMsg)
}
void
MessageChannel::PeekMessages(msgid_t aMsgId, mozilla::function<bool(const Message& aMsg)> aInvoke)
MessageChannel::PeekMessages(mozilla::function<bool(const Message& aMsg)> aInvoke)
{
MonitorAutoLock lock(*mMonitor);
for (MessageQueue::iterator it = mPending.begin(); it != mPending.end(); it++) {
Message &msg = *it;
if (msg.type() == aMsgId && !aInvoke(msg)) {
if (!aInvoke(msg)) {
break;
}
}

View File

@ -110,10 +110,10 @@ class MessageChannel : HasResultCodes
mAbortOnError = abort;
}
// Call aInvoke for each pending message of type aId until it returns false.
// Call aInvoke for each pending message until it returns false.
// XXX: You must get permission from an IPC peer to use this function
// since it requires custom deserialization and re-orders events.
void PeekMessages(Message::msgid_t aId, mozilla::function<bool(const Message& aMsg)> aInvoke);
void PeekMessages(mozilla::function<bool(const Message& aMsg)> aInvoke);
// Misc. behavioral traits consumers can request for this channel
enum ChannelFlags {

View File

@ -9084,16 +9084,17 @@ nsLayoutUtils::UpdateDisplayPortMarginsFromPendingMessages() {
if (mozilla::dom::ContentChild::GetSingleton() &&
mozilla::dom::ContentChild::GetSingleton()->GetIPCChannel()) {
mozilla::dom::ContentChild::GetSingleton()->GetIPCChannel()->PeekMessages(
mozilla::layers::PAPZ::Msg_UpdateFrame__ID,
[](const IPC::Message& aMsg) -> bool {
void* iter = nullptr;
FrameMetrics frame;
if (!IPC::ReadParam(&aMsg, &iter, &frame)) {
MOZ_ASSERT(false);
return true;
}
if (aMsg.type() == mozilla::layers::PAPZ::Msg_UpdateFrame__ID) {
void* iter = nullptr;
FrameMetrics frame;
if (!IPC::ReadParam(&aMsg, &iter, &frame)) {
MOZ_ASSERT(false);
return true;
}
UpdateDisplayPortMarginsForPendingMetrics(frame);
UpdateDisplayPortMarginsForPendingMetrics(frame);
}
return true;
});
}

View File

@ -1431,33 +1431,31 @@ PuppetWidget::HasPendingInputEvent()
return false;
}
static const IPC::Message::msgid_t kInputEvents[] = {
mozilla::dom::PBrowser::Msg_RealMouseMoveEvent__ID,
mozilla::dom::PBrowser::Msg_SynthMouseMoveEvent__ID,
mozilla::dom::PBrowser::Msg_RealMouseButtonEvent__ID,
mozilla::dom::PBrowser::Msg_RealKeyEvent__ID,
mozilla::dom::PBrowser::Msg_MouseWheelEvent__ID,
mozilla::dom::PBrowser::Msg_RealTouchEvent__ID,
mozilla::dom::PBrowser::Msg_RealTouchMoveEvent__ID,
mozilla::dom::PBrowser::Msg_RealDragEvent__ID,
mozilla::dom::PBrowser::Msg_UpdateDimensions__ID,
mozilla::dom::PBrowser::Msg_MouseEvent__ID,
mozilla::dom::PBrowser::Msg_KeyEvent__ID
};
bool ret = false;
for (IPC::Message::msgid_t e: kInputEvents) {
mTabChild->GetIPCChannel()->PeekMessages(
e,
[&ret](const IPC::Message& aMsg) -> bool {
ret = true;
return false; // Stop peeking.
mTabChild->GetIPCChannel()->PeekMessages(
[&ret](const IPC::Message& aMsg) -> bool {
if ((aMsg.type() & mozilla::dom::PBrowser::PBrowserStart)
== mozilla::dom::PBrowser::PBrowserStart) {
switch (aMsg.type()) {
case mozilla::dom::PBrowser::Msg_RealMouseMoveEvent__ID:
case mozilla::dom::PBrowser::Msg_SynthMouseMoveEvent__ID:
case mozilla::dom::PBrowser::Msg_RealMouseButtonEvent__ID:
case mozilla::dom::PBrowser::Msg_RealKeyEvent__ID:
case mozilla::dom::PBrowser::Msg_MouseWheelEvent__ID:
case mozilla::dom::PBrowser::Msg_RealTouchEvent__ID:
case mozilla::dom::PBrowser::Msg_RealTouchMoveEvent__ID:
case mozilla::dom::PBrowser::Msg_RealDragEvent__ID:
case mozilla::dom::PBrowser::Msg_UpdateDimensions__ID:
case mozilla::dom::PBrowser::Msg_MouseEvent__ID:
case mozilla::dom::PBrowser::Msg_KeyEvent__ID:
ret = true;
return false; // Stop peeking.
}
}
);
if (ret) {
break;
return true;
}
}
);
return ret;
}