Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1802)

Unified Diff: content/renderer/input/main_thread_event_queue.cc

Issue 2162143002: Don't use PostTask queueing between compositor and main thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address issues with test and fix dchecks in debug mode Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/renderer/input/main_thread_event_queue.cc
diff --git a/content/renderer/input/main_thread_event_queue.cc b/content/renderer/input/main_thread_event_queue.cc
index 824bb39a541ad1bc3b4c6491371ed480247e464a..380eb993e12f718ce4ca0946459225abb1cfcbef 100644
--- a/content/renderer/input/main_thread_event_queue.cc
+++ b/content/renderer/input/main_thread_event_queue.cc
@@ -26,21 +26,23 @@ bool EventWithDispatchType::CanCoalesceWith(
void EventWithDispatchType::CoalesceWith(const EventWithDispatchType& other) {
// If we are blocking and are coalescing touch, make sure to keep
// the touch ids that need to be acked.
- if (dispatch_type_ == DISPATCH_TYPE_BLOCKING_NOTIFY_MAIN) {
+ if (dispatch_type_ == DISPATCH_TYPE_BLOCKING) {
// We should only have blocking touch events that need coalescing.
- DCHECK(blink::WebInputEvent::isTouchEventType(other.event().type));
eventsToAck_.push_back(
WebInputEventTraits::GetUniqueTouchEventId(other.event()));
}
ScopedWebInputEventWithLatencyInfo::CoalesceWith(other);
}
-MainThreadEventQueue::MainThreadEventQueue(int routing_id,
- MainThreadEventQueueClient* client)
+MainThreadEventQueue::MainThreadEventQueue(
+ int routing_id,
+ MainThreadEventQueueClient* client,
+ const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner)
: routing_id_(routing_id),
client_(client),
is_flinging_(false),
- sent_notification_to_main_(false) {}
+ sent_notification_to_main_(false),
+ main_task_runner_(main_task_runner) {}
MainThreadEventQueue::~MainThreadEventQueue() {}
@@ -58,55 +60,69 @@ bool MainThreadEventQueue::HandleEvent(
ack_result == INPUT_EVENT_ACK_STATE_SET_NON_BLOCKING;
InputEventDispatchType dispatch_type =
- non_blocking ? DISPATCH_TYPE_NON_BLOCKING_NOTIFY_MAIN
- : DISPATCH_TYPE_BLOCKING_NOTIFY_MAIN;
+ non_blocking ? DISPATCH_TYPE_NON_BLOCKING : DISPATCH_TYPE_BLOCKING;
bool is_wheel = event->type == blink::WebInputEvent::MouseWheel;
bool is_touch = blink::WebInputEvent::isTouchEventType(event->type);
- if (is_wheel || is_touch) {
- std::unique_ptr<EventWithDispatchType> cloned_event(
- new EventWithDispatchType(*event, latency, dispatch_type));
+ std::unique_ptr<EventWithDispatchType> cloned_event(
+ new EventWithDispatchType(*event, latency, dispatch_type));
+ if (is_touch) {
+ blink::WebTouchEvent& touch_event =
+ static_cast<blink::WebTouchEvent&>(cloned_event->event());
+ touch_event.dispatchedDuringFling = is_flinging_;
// Adjust the |dispatchType| on the event since the compositor
// determined all event listeners are passive.
if (non_blocking) {
- if (is_wheel) {
- static_cast<blink::WebMouseWheelEvent&>(cloned_event->event())
- .dispatchType = blink::WebInputEvent::ListenersNonBlockingPassive;
- } else if (is_touch) {
- static_cast<blink::WebTouchEvent&>(cloned_event->event()).dispatchType =
- blink::WebInputEvent::ListenersNonBlockingPassive;
- }
+ touch_event.dispatchType =
+ blink::WebInputEvent::ListenersNonBlockingPassive;
}
+ }
+ if (is_wheel && non_blocking) {
+ // Adjust the |dispatchType| on the event since the compositor
+ // determined all event listeners are passive.
+ static_cast<blink::WebMouseWheelEvent&>(cloned_event->event())
+ .dispatchType = blink::WebInputEvent::ListenersNonBlockingPassive;
+ }
- if (is_touch) {
- static_cast<blink::WebTouchEvent&>(cloned_event->event())
- .dispatchedDuringFling = is_flinging_;
- }
+ QueueEvent(std::move(cloned_event));
+
+ // send an ack when we are non-blocking.
+ return non_blocking;
+}
+
+void MainThreadEventQueue::PopEventOnMainThread() {
+ {
+ base::AutoLock lock(event_queue_lock_);
+ if (!events_.empty())
+ in_flight_event_ = events_.Pop();
+ }
- if (sent_notification_to_main_) {
- events_.Queue(std::move(cloned_event));
- } else {
- if (non_blocking) {
- sent_notification_to_main_ = true;
- client_->SendEventToMainThread(routing_id_, &cloned_event->event(),
- latency, dispatch_type);
- } else {
- // If there is nothing in the event queue and the event is
- // blocking pass the |original_dispatch_type| to avoid
- // having the main thread call us back as an optimization.
- client_->SendEventToMainThread(routing_id_, &cloned_event->event(),
- latency, original_dispatch_type);
- }
+ if (in_flight_event_) {
+ InputEventDispatchType dispatch_type = in_flight_event_->dispatchType();
+ if (!in_flight_event_->eventsToAck().empty() &&
+ dispatch_type == DISPATCH_TYPE_BLOCKING) {
+ dispatch_type = DISPATCH_TYPE_BLOCKING_NOTIFY_MAIN;
}
- } else {
- client_->SendEventToMainThread(routing_id_, event, latency,
- original_dispatch_type);
+
+ client_->HandleEventOnMainThread(routing_id_, &in_flight_event_->event(),
+ in_flight_event_->latencyInfo(),
+ dispatch_type);
}
- // send an ack when we are non-blocking.
- return non_blocking;
+ in_flight_event_.reset();
+ bool send_notification = false;
+ {
+ base::AutoLock lock(event_queue_lock_);
+ if (!events_.empty())
+ send_notification = true;
+ else
+ sent_notification_to_main_ = false;
+ }
+
+ if (send_notification)
+ SendEventNotificationToMainThread();
}
void MainThreadEventQueue::EventHandled(blink::WebInputEvent::Type type,
@@ -115,16 +131,26 @@ void MainThreadEventQueue::EventHandled(blink::WebInputEvent::Type type,
// Send acks for blocking touch events.
for (const auto id : in_flight_event_->eventsToAck())
client_->SendInputEventAck(routing_id_, type, ack_result, id);
- }
- if (!events_.empty()) {
- in_flight_event_ = events_.Pop();
- client_->SendEventToMainThread(routing_id_, &in_flight_event_->event(),
- in_flight_event_->latencyInfo(),
- in_flight_event_->dispatchType());
- } else {
- in_flight_event_.reset();
- sent_notification_to_main_ = false;
- }
+ }
+}
+
+void MainThreadEventQueue::SendEventNotificationToMainThread() {
+ main_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&MainThreadEventQueue::PopEventOnMainThread,
+ base::Unretained(this)));
+}
+
+void MainThreadEventQueue::QueueEvent(
+ std::unique_ptr<EventWithDispatchType>&& event) {
tdresser 2016/08/08 16:56:05 We aren't allowed to use && here, are we?
dtapuska 2016/08/08 20:11:24 Done.
+ bool send_notification = false;
+ {
+ base::AutoLock lock(event_queue_lock_);
+ send_notification = events_.empty();
+ events_.Queue(std::move(event));
+ sent_notification_to_main_ |= send_notification;
+ }
+ if (send_notification)
+ SendEventNotificationToMainThread();
}
} // namespace content
« no previous file with comments | « content/renderer/input/main_thread_event_queue.h ('k') | content/renderer/input/main_thread_event_queue_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698