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

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

Issue 2170913002: Generalize the main thread event queue into a common event queue. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix nits Created 4 years, 5 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 6581056c741f3c8ca622af3a1f7ba26c09db127c..824bb39a541ad1bc3b4c6491371ed480247e464a 100644
--- a/content/renderer/input/main_thread_event_queue.cc
+++ b/content/renderer/input/main_thread_event_queue.cc
@@ -3,12 +3,44 @@
// found in the LICENSE file.
#include "content/renderer/input/main_thread_event_queue.h"
+#include "content/common/input/event_with_latency_info.h"
+#include "content/common/input_messages.h"
namespace content {
+EventWithDispatchType::EventWithDispatchType(
+ const blink::WebInputEvent& event,
+ const ui::LatencyInfo& latency,
+ InputEventDispatchType dispatch_type)
+ : ScopedWebInputEventWithLatencyInfo(event, latency),
+ dispatch_type_(dispatch_type) {}
+
+EventWithDispatchType::~EventWithDispatchType() {}
+
+bool EventWithDispatchType::CanCoalesceWith(
+ const EventWithDispatchType& other) const {
+ return other.dispatch_type_ == dispatch_type_ &&
+ ScopedWebInputEventWithLatencyInfo::CanCoalesceWith(other);
+}
+
+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) {
+ // 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)
- : routing_id_(routing_id), client_(client), is_flinging_(false) {}
+ : routing_id_(routing_id),
+ client_(client),
+ is_flinging_(false),
+ sent_notification_to_main_(false) {}
MainThreadEventQueue::~MainThreadEventQueue() {}
@@ -29,63 +61,42 @@ bool MainThreadEventQueue::HandleEvent(
non_blocking ? DISPATCH_TYPE_NON_BLOCKING_NOTIFY_MAIN
: DISPATCH_TYPE_BLOCKING_NOTIFY_MAIN;
- if (event->type == blink::WebInputEvent::MouseWheel) {
- PendingMouseWheelEvent modified_dispatch_type_event =
- PendingMouseWheelEvent(
- *static_cast<const blink::WebMouseWheelEvent*>(event), latency,
- dispatch_type);
+ 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));
// Adjust the |dispatchType| on the event since the compositor
// determined all event listeners are passive.
if (non_blocking) {
- modified_dispatch_type_event.event.dispatchType =
- blink::WebInputEvent::ListenersNonBlockingPassive;
- }
-
- if (wheel_events_.state() == WebInputEventQueueState::ITEM_PENDING) {
- wheel_events_.Queue(modified_dispatch_type_event);
- } else {
- if (non_blocking) {
- wheel_events_.set_state(WebInputEventQueueState::ITEM_PENDING);
- client_->SendEventToMainThread(routing_id_,
- &modified_dispatch_type_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_,
- &modified_dispatch_type_event.event,
- latency, original_dispatch_type);
+ 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;
}
}
- } else if (blink::WebInputEvent::isTouchEventType(event->type)) {
- PendingTouchEvent modified_dispatch_type_event =
- PendingTouchEvent(*static_cast<const blink::WebTouchEvent*>(event),
- latency, dispatch_type);
- modified_dispatch_type_event.event.dispatchedDuringFling = is_flinging_;
- // Adjust the |dispatchType| on the event since the compositor
- // determined all event listeners are passive.
- if (non_blocking) {
- modified_dispatch_type_event.event.dispatchType =
- blink::WebInputEvent::ListenersNonBlockingPassive;
+ if (is_touch) {
+ static_cast<blink::WebTouchEvent&>(cloned_event->event())
+ .dispatchedDuringFling = is_flinging_;
}
- if (touch_events_.state() == WebInputEventQueueState::ITEM_PENDING) {
- touch_events_.Queue(modified_dispatch_type_event);
+ if (sent_notification_to_main_) {
+ events_.Queue(std::move(cloned_event));
} else {
if (non_blocking) {
- touch_events_.set_state(WebInputEventQueueState::ITEM_PENDING);
- client_->SendEventToMainThread(routing_id_,
- &modified_dispatch_type_event.event,
+ 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_,
- &modified_dispatch_type_event.event,
+ client_->SendEventToMainThread(routing_id_, &cloned_event->event(),
latency, original_dispatch_type);
}
}
@@ -100,39 +111,20 @@ bool MainThreadEventQueue::HandleEvent(
void MainThreadEventQueue::EventHandled(blink::WebInputEvent::Type type,
InputEventAckState ack_result) {
- if (type == blink::WebInputEvent::MouseWheel) {
- // There should not be two blocking wheel events in flight.
- DCHECK(!in_flight_wheel_event_ ||
- in_flight_wheel_event_->eventsToAck.size() == 0);
-
- if (!wheel_events_.empty()) {
- in_flight_wheel_event_ = wheel_events_.Pop();
- client_->SendEventToMainThread(
- routing_id_, &in_flight_wheel_event_->event,
- in_flight_wheel_event_->latency, in_flight_wheel_event_->type);
- } else {
- in_flight_wheel_event_.reset();
- wheel_events_.set_state(WebInputEventQueueState::ITEM_NOT_PENDING);
- }
- } else if (blink::WebInputEvent::isTouchEventType(type)) {
- if (in_flight_touch_event_) {
- // Send acks for blocking touch events.
- for (const auto id : in_flight_touch_event_->eventsToAck)
- client_->SendInputEventAck(routing_id_, type, ack_result, id);
+ if (in_flight_event_) {
+ // Send acks for blocking touch events.
+ for (const auto id : in_flight_event_->eventsToAck())
+ client_->SendInputEventAck(routing_id_, type, ack_result, id);
}
-
- if (!touch_events_.empty()) {
- in_flight_touch_event_ = touch_events_.Pop();
- client_->SendEventToMainThread(
- routing_id_, &in_flight_touch_event_->event,
- in_flight_touch_event_->latency, in_flight_touch_event_->type);
+ 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_touch_event_.reset();
- touch_events_.set_state(WebInputEventQueueState::ITEM_NOT_PENDING);
+ in_flight_event_.reset();
+ sent_notification_to_main_ = false;
}
- } else {
- NOTREACHED() << "Invalid passive event type";
- }
}
} // 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