Commit 3e34b190 authored by David Bokan's avatar David Bokan Committed by Commit Bot

Minor cleanups in GestureEventQueue

In https://crrev.com/c/1332769 we removed the vsync aligned feature
flag. This caused the removal of much code in GestureEventQueue. Namely,
it no longer attempts to coalesce and queue events.

This CL cleans up the nomenclature and commentary in the class to better
reflect its current duties.

Bug: 625689
Change-Id: I295fec7923b8d251853b9522c54641edfcac076a
Reviewed-on: https://chromium-review.googlesource.com/c/1334203Reviewed-by: default avatarDave Tapuska <dtapuska@chromium.org>
Commit-Queue: David Bokan <bokan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607998}
parent 6c3fa179
...@@ -42,7 +42,7 @@ GestureEventQueue::GestureEventQueue( ...@@ -42,7 +42,7 @@ GestureEventQueue::GestureEventQueue(
GestureEventQueue::~GestureEventQueue() { } GestureEventQueue::~GestureEventQueue() { }
bool GestureEventQueue::DebounceOrQueueEvent( bool GestureEventQueue::DebounceOrForwardEvent(
const GestureEventWithLatencyInfo& gesture_event) { const GestureEventWithLatencyInfo& gesture_event) {
// GFS and GFC should have been filtered in FlingControllerFilterEvent. // GFS and GFC should have been filtered in FlingControllerFilterEvent.
DCHECK_NE(gesture_event.event.GetType(), WebInputEvent::kGestureFlingStart); DCHECK_NE(gesture_event.event.GetType(), WebInputEvent::kGestureFlingStart);
...@@ -50,7 +50,7 @@ bool GestureEventQueue::DebounceOrQueueEvent( ...@@ -50,7 +50,7 @@ bool GestureEventQueue::DebounceOrQueueEvent(
if (!ShouldForwardForBounceReduction(gesture_event)) if (!ShouldForwardForBounceReduction(gesture_event))
return false; return false;
QueueAndForwardIfNecessary(gesture_event); ForwardGestureEvent(gesture_event);
return true; return true;
} }
...@@ -136,7 +136,6 @@ bool GestureEventQueue::ShouldForwardForBounceReduction( ...@@ -136,7 +136,6 @@ bool GestureEventQueue::ShouldForwardForBounceReduction(
case WebInputEvent::kGesturePinchBegin: case WebInputEvent::kGesturePinchBegin:
case WebInputEvent::kGesturePinchEnd: case WebInputEvent::kGesturePinchEnd:
case WebInputEvent::kGesturePinchUpdate: case WebInputEvent::kGesturePinchUpdate:
// TODO(rjkroege): Debounce pinch (http://crbug.com/147647)
return true; return true;
default: default:
if (scrolling_in_progress_) { if (scrolling_in_progress_) {
...@@ -147,13 +146,13 @@ bool GestureEventQueue::ShouldForwardForBounceReduction( ...@@ -147,13 +146,13 @@ bool GestureEventQueue::ShouldForwardForBounceReduction(
} }
} }
void GestureEventQueue::QueueAndForwardIfNecessary( void GestureEventQueue::ForwardGestureEvent(
const GestureEventWithLatencyInfo& gesture_event) { const GestureEventWithLatencyInfo& gesture_event) {
// GFS and GFC should have been filtered in FlingControllerFilterEvent to // GFS and GFC should have been filtered in FlingControllerFilterEvent to
// get handled by fling controller. // get handled by fling controller.
DCHECK_NE(gesture_event.event.GetType(), WebInputEvent::kGestureFlingStart); DCHECK_NE(gesture_event.event.GetType(), WebInputEvent::kGestureFlingStart);
DCHECK_NE(gesture_event.event.GetType(), WebInputEvent::kGestureFlingCancel); DCHECK_NE(gesture_event.event.GetType(), WebInputEvent::kGestureFlingCancel);
coalesced_gesture_events_.push_back(gesture_event); sent_events_awaiting_ack_.push_back(gesture_event);
if (gesture_event.event.GetType() == WebInputEvent::kGestureScrollBegin) { if (gesture_event.event.GetType() == WebInputEvent::kGestureScrollBegin) {
fling_controller_.RegisterFlingSchedulerObserver(); fling_controller_.RegisterFlingSchedulerObserver();
} else if (gesture_event.event.GetType() == } else if (gesture_event.event.GetType() ==
...@@ -161,7 +160,6 @@ void GestureEventQueue::QueueAndForwardIfNecessary( ...@@ -161,7 +160,6 @@ void GestureEventQueue::QueueAndForwardIfNecessary(
fling_controller_.UnregisterFlingSchedulerObserver(); fling_controller_.UnregisterFlingSchedulerObserver();
} }
client_->SendGestureEventImmediately(gesture_event); client_->SendGestureEventImmediately(gesture_event);
return;
} }
void GestureEventQueue::ProcessGestureAck(InputEventAckSource ack_source, void GestureEventQueue::ProcessGestureAck(InputEventAckSource ack_source,
...@@ -170,14 +168,14 @@ void GestureEventQueue::ProcessGestureAck(InputEventAckSource ack_source, ...@@ -170,14 +168,14 @@ void GestureEventQueue::ProcessGestureAck(InputEventAckSource ack_source,
const ui::LatencyInfo& latency) { const ui::LatencyInfo& latency) {
TRACE_EVENT0("input", "GestureEventQueue::ProcessGestureAck"); TRACE_EVENT0("input", "GestureEventQueue::ProcessGestureAck");
if (coalesced_gesture_events_.empty()) { if (sent_events_awaiting_ack_.empty()) {
DLOG(ERROR) << "Received unexpected ACK for event type " << type; DLOG(ERROR) << "Received unexpected ACK for event type " << type;
return; return;
} }
// ACKs could come back out of order. We want to cache them to restore the // ACKs could come back out of order. We want to cache them to restore the
// original order. // original order.
for (auto& outstanding_event : coalesced_gesture_events_) { for (auto& outstanding_event : sent_events_awaiting_ack_) {
if (outstanding_event.ack_state() != INPUT_EVENT_ACK_STATE_UNKNOWN) if (outstanding_event.ack_state() != INPUT_EVENT_ACK_STATE_UNKNOWN)
continue; continue;
if (outstanding_event.event.GetType() == type) { if (outstanding_event.event.GetType() == type) {
...@@ -196,12 +194,12 @@ void GestureEventQueue::AckCompletedEvents() { ...@@ -196,12 +194,12 @@ void GestureEventQueue::AckCompletedEvents() {
if (processing_acks_) if (processing_acks_)
return; return;
base::AutoReset<bool> process_acks(&processing_acks_, true); base::AutoReset<bool> process_acks(&processing_acks_, true);
while (!coalesced_gesture_events_.empty()) { while (!sent_events_awaiting_ack_.empty()) {
auto iter = coalesced_gesture_events_.begin(); auto iter = sent_events_awaiting_ack_.begin();
if (iter->ack_state() == INPUT_EVENT_ACK_STATE_UNKNOWN) if (iter->ack_state() == INPUT_EVENT_ACK_STATE_UNKNOWN)
break; break;
GestureEventWithLatencyInfoAndAckState event = *iter; GestureEventWithLatencyInfoAndAckState event = *iter;
coalesced_gesture_events_.erase(iter); sent_events_awaiting_ack_.erase(iter);
AckGestureEventToClient(event, event.ack_source(), event.ack_state()); AckGestureEventToClient(event, event.ack_source(), event.ack_state());
} }
} }
...@@ -210,9 +208,6 @@ void GestureEventQueue::AckGestureEventToClient( ...@@ -210,9 +208,6 @@ void GestureEventQueue::AckGestureEventToClient(
const GestureEventWithLatencyInfo& event_with_latency, const GestureEventWithLatencyInfo& event_with_latency,
InputEventAckSource ack_source, InputEventAckSource ack_source,
InputEventAckState ack_result) { InputEventAckState ack_result) {
// Ack'ing an event may enqueue additional gesture events. By ack'ing the
// event before the forwarding of queued events below, such additional events
// can be coalesced with existing queued events prior to dispatch.
client_->OnGestureEventAck(event_with_latency, ack_source, ack_result); client_->OnGestureEventAck(event_with_latency, ack_source, ack_result);
} }
...@@ -221,11 +216,6 @@ TouchpadTapSuppressionController* ...@@ -221,11 +216,6 @@ TouchpadTapSuppressionController*
return fling_controller_.GetTouchpadTapSuppressionController(); return fling_controller_.GetTouchpadTapSuppressionController();
} }
void GestureEventQueue::ForwardGestureEvent(
const GestureEventWithLatencyInfo& gesture_event) {
QueueAndForwardIfNecessary(gesture_event);
}
void GestureEventQueue::SendScrollEndingEventsNow() { void GestureEventQueue::SendScrollEndingEventsNow() {
scrolling_in_progress_ = false; scrolling_in_progress_ = false;
if (debouncing_deferral_queue_.empty()) if (debouncing_deferral_queue_.empty())
...@@ -235,7 +225,7 @@ void GestureEventQueue::SendScrollEndingEventsNow() { ...@@ -235,7 +225,7 @@ void GestureEventQueue::SendScrollEndingEventsNow() {
for (GestureQueue::const_iterator it = debouncing_deferral_queue.begin(); for (GestureQueue::const_iterator it = debouncing_deferral_queue.begin();
it != debouncing_deferral_queue.end(); it++) { it != debouncing_deferral_queue.end(); it++) {
if (!fling_controller_.FilterGestureEvent(*it)) { if (!fling_controller_.FilterGestureEvent(*it)) {
QueueAndForwardIfNecessary(*it); ForwardGestureEvent(*it);
} }
} }
} }
......
...@@ -37,26 +37,28 @@ class CONTENT_EXPORT GestureEventQueueClient { ...@@ -37,26 +37,28 @@ class CONTENT_EXPORT GestureEventQueueClient {
InputEventAckState ack_result) = 0; InputEventAckState ack_result) = 0;
}; };
// Maintains WebGestureEvents in a queue before forwarding them to the renderer // Despite its name, this class isn't so much one queue as it is a collection
// to apply a sequence of filters on them: // of queues and filters. This class applies logic to determine if an event
// should be queued, filtered altogether, or sent immediately; it tracks sent
// events and ACKs them to the clilent in the order they were dispatched. This
// class applies a series of filters and queues for various scenarios:
// 1. The sequence is filtered for bounces. A bounce is when the finger lifts // 1. The sequence is filtered for bounces. A bounce is when the finger lifts
// from the screen briefly during an in-progress scroll. Ifco this happens, // from the screen briefly during an in-progress scroll. If this happens,
// non-GestureScrollUpdate events are queued until the de-bounce interval // non-GestureScrollUpdate events are queued until the de-bounce interval
// passes or another GestureScrollUpdate event occurs. // passes or another GestureScrollUpdate event occurs.
// 2. Unnecessary GestureFlingCancel events are filtered by fling controller. // 2. Unnecessary GestureFlingCancel events are filtered by fling controller.
// These are GestureFlingCancels that have no corresponding GestureFlingStart // These are GestureFlingCancels that have no corresponding GestureFlingStart
// in the queue. // in the queue. GestureFlingStarts are also filtered and translated to
// scroll gestures by the fling controller.
// 3. Taps immediately after a GestureFlingCancel (caused by the same tap) are // 3. Taps immediately after a GestureFlingCancel (caused by the same tap) are
// filtered by fling controller. // filtered by fling controller.
// 4. Whenever possible, events in the queue are coalesced to have as few events // 4. Gesture events are queued while we're waiting to determine the allowed
// as possible and therefore maximize the chance that the event stream can be // touch actions.
// handled entirely by the compositor thread. // Sent events are kept in a queue until a response from the renderer is
// Events in the queue are forwarded to the renderer one by one; i.e., each // received for that event. The client is notified of ACKs in the order the
// event is sent after receiving the ACK for previous one. The only exception is // events were sent, not ACK'd. This means an ACK'd event that was sent after
// that if a GestureScrollUpdate is followed by a GesturePinchUpdate, they are // an event still awaiting an ACK won't notify the client until the earlier
// sent together. // event is ACK'd.
// TODO(rjkroege): Possibly refactor into a filter chain:
// http://crbug.com/148443.
class CONTENT_EXPORT GestureEventQueue { class CONTENT_EXPORT GestureEventQueue {
public: public:
using GestureQueue = base::circular_deque<GestureEventWithLatencyInfo>; using GestureQueue = base::circular_deque<GestureEventWithLatencyInfo>;
...@@ -79,24 +81,23 @@ class CONTENT_EXPORT GestureEventQueue { ...@@ -79,24 +81,23 @@ class CONTENT_EXPORT GestureEventQueue {
~GestureEventQueue(); ~GestureEventQueue();
// Uses fling controller to filter the gesture event. Returns true if the // Uses fling controller to filter the gesture event. Returns true if the
// event wasn't queued and was filtered. // event was filtered by the fling controller and shouldn't be further
// forwarded.
bool FlingControllerFilterEvent(const GestureEventWithLatencyInfo&); bool FlingControllerFilterEvent(const GestureEventWithLatencyInfo&);
// Check for debouncing, or add the gesture event to the queue. Returns false // Filter the event for debouncing or forward it to the renderer. Returns
// if the event wasn't queued. // true if the event was forwarded, false if was filtered for debouncing.
bool DebounceOrQueueEvent(const GestureEventWithLatencyInfo&); bool DebounceOrForwardEvent(const GestureEventWithLatencyInfo&);
// Adds a gesture to the queue of events that needs to be deferred until the // Adds a gesture to the queue of events that needs to be deferred until the
// touch action is known. // touch action is known.
void QueueDeferredEvents(const GestureEventWithLatencyInfo&); void QueueDeferredEvents(const GestureEventWithLatencyInfo&);
// Returns events in the |deferred_gesture_queue_| and empty // Returns events in the |deferred_gesture_queue_| and empty the queue.
// the queue.
GestureQueue TakeDeferredEvents(); GestureQueue TakeDeferredEvents();
// Indicates that the caller has received an acknowledgement from the renderer // Indicates that the caller has received an acknowledgement from the renderer
// with state |ack_result| and event |type|. May send events if the queue is // with state |ack_result| and event |type|.
// not empty.
void ProcessGestureAck(InputEventAckSource ack_source, void ProcessGestureAck(InputEventAckSource ack_source,
InputEventAckState ack_result, InputEventAckState ack_result,
blink::WebInputEvent::Type type, blink::WebInputEvent::Type type,
...@@ -105,10 +106,12 @@ class CONTENT_EXPORT GestureEventQueue { ...@@ -105,10 +106,12 @@ class CONTENT_EXPORT GestureEventQueue {
// Returns the |TouchpadTapSuppressionController| instance. // Returns the |TouchpadTapSuppressionController| instance.
TouchpadTapSuppressionController* GetTouchpadTapSuppressionController(); TouchpadTapSuppressionController* GetTouchpadTapSuppressionController();
// Sends the gesture event to the renderer. Stores the sent event for when
// the renderer replies with an ACK.
void ForwardGestureEvent(const GestureEventWithLatencyInfo& gesture_event); void ForwardGestureEvent(const GestureEventWithLatencyInfo& gesture_event);
bool empty() const { bool empty() const {
return coalesced_gesture_events_.empty() && return sent_events_awaiting_ack_.empty() &&
debouncing_deferral_queue_.empty(); debouncing_deferral_queue_.empty();
} }
...@@ -151,12 +154,6 @@ class CONTENT_EXPORT GestureEventQueue { ...@@ -151,12 +154,6 @@ class CONTENT_EXPORT GestureEventQueue {
bool ShouldForwardForBounceReduction( bool ShouldForwardForBounceReduction(
const GestureEventWithLatencyInfo& gesture_event); const GestureEventWithLatencyInfo& gesture_event);
// Puts the events in a queue to forward them one by one; i.e., forward them
// whenever ACK for previous event is received. This queue also tries to
// coalesce events as much as possible.
void QueueAndForwardIfNecessary(
const GestureEventWithLatencyInfo& gesture_event);
// ACK completed events in order until we have reached an incomplete event. // ACK completed events in order until we have reached an incomplete event.
// Will preserve the FIFO order as events originally arrived. // Will preserve the FIFO order as events originally arrived.
void AckCompletedEvents(); void AckCompletedEvents();
...@@ -178,8 +175,12 @@ class CONTENT_EXPORT GestureEventQueue { ...@@ -178,8 +175,12 @@ class CONTENT_EXPORT GestureEventQueue {
base::circular_deque<GestureEventWithLatencyInfoAndAckState>; base::circular_deque<GestureEventWithLatencyInfoAndAckState>;
// Stores outstanding events that have been sent to the renderer but not yet // Stores outstanding events that have been sent to the renderer but not yet
// been ACKed. // been ACK'd. These are kept in the order they were sent in so that they can
GestureQueueWithAckState coalesced_gesture_events_; // be ACK'd back in order. Note, the renderer can reply to these out-of-order.
// This class makes a note of the ACK state but doesn't actually let the
// client know about the ACK until all events earlier in the queue have been
// ACK'd so that the client sees the ACKs in order.
GestureQueueWithAckState sent_events_awaiting_ack_;
// Timer to release a previously deferred gesture event. // Timer to release a previously deferred gesture event.
base::OneShotTimer debounce_deferring_timer_; base::OneShotTimer debounce_deferring_timer_;
......
...@@ -119,7 +119,7 @@ class GestureEventQueueTest : public testing::Test, ...@@ -119,7 +119,7 @@ class GestureEventQueueTest : public testing::Test,
void SimulateGestureEvent(const WebGestureEvent& gesture) { void SimulateGestureEvent(const WebGestureEvent& gesture) {
GestureEventWithLatencyInfo gesture_event(gesture); GestureEventWithLatencyInfo gesture_event(gesture);
if (!queue()->FlingControllerFilterEvent(gesture_event)) { if (!queue()->FlingControllerFilterEvent(gesture_event)) {
queue()->DebounceOrQueueEvent(gesture_event); queue()->DebounceOrForwardEvent(gesture_event);
} }
} }
...@@ -191,16 +191,17 @@ class GestureEventQueueTest : public testing::Test, ...@@ -191,16 +191,17 @@ class GestureEventQueueTest : public testing::Test,
} }
unsigned GestureEventQueueSize() { unsigned GestureEventQueueSize() {
return queue()->coalesced_gesture_events_.size(); return queue()->sent_events_awaiting_ack_.size();
} }
WebGestureEvent GestureEventSecondFromLastQueueEvent() { WebGestureEvent GestureEventSecondFromLastQueueEvent() {
return queue()->coalesced_gesture_events_.at( return queue()
GestureEventQueueSize() - 2).event; ->sent_events_awaiting_ack_.at(GestureEventQueueSize() - 2)
.event;
} }
WebGestureEvent GestureEventLastQueueEvent() { WebGestureEvent GestureEventLastQueueEvent() {
return queue()->coalesced_gesture_events_.back().event; return queue()->sent_events_awaiting_ack_.back().event;
} }
unsigned GestureEventDebouncingQueueSize() { unsigned GestureEventDebouncingQueueSize() {
...@@ -208,7 +209,7 @@ class GestureEventQueueTest : public testing::Test, ...@@ -208,7 +209,7 @@ class GestureEventQueueTest : public testing::Test,
} }
WebGestureEvent GestureEventQueueEventAt(int i) { WebGestureEvent GestureEventQueueEventAt(int i) {
return queue()->coalesced_gesture_events_.at(i).event; return queue()->sent_events_awaiting_ack_.at(i).event;
} }
bool ScrollingInProgress() { bool ScrollingInProgress() {
......
...@@ -194,7 +194,7 @@ void InputRouterImpl::SendGestureEventWithoutQueueing( ...@@ -194,7 +194,7 @@ void InputRouterImpl::SendGestureEventWithoutQueueing(
return; return;
} }
if (!gesture_event_queue_.DebounceOrQueueEvent(gesture_event)) { if (!gesture_event_queue_.DebounceOrForwardEvent(gesture_event)) {
disposition_handler_->OnGestureEventAck(gesture_event, disposition_handler_->OnGestureEventAck(gesture_event,
InputEventAckSource::BROWSER, InputEventAckSource::BROWSER,
INPUT_EVENT_ACK_STATE_CONSUMED); INPUT_EVENT_ACK_STATE_CONSUMED);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment