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

Side by Side Diff: content/renderer/input/main_thread_event_queue.h

Issue 2094323002: Ensure acks are sent for all blocking events. (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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_RENDERER_INPUT_MAIN_THREAD_EVENT_QUEUE_H_ 5 #ifndef CONTENT_RENDERER_INPUT_MAIN_THREAD_EVENT_QUEUE_H_
6 #define CONTENT_RENDERER_INPUT_MAIN_THREAD_EVENT_QUEUE_H_ 6 #define CONTENT_RENDERER_INPUT_MAIN_THREAD_EVENT_QUEUE_H_
7 7
8 #include <deque> 8 #include <deque>
9 #include "content/common/content_export.h" 9 #include "content/common/content_export.h"
10 #include "content/common/input/event_with_latency_info.h" 10 #include "content/common/input/event_with_latency_info.h"
11 #include "content/common/input/input_event_ack_state.h" 11 #include "content/common/input/input_event_ack_state.h"
12 #include "content/common/input/input_event_dispatch_type.h" 12 #include "content/common/input/input_event_dispatch_type.h"
13 #include "content/common/input/web_input_event_queue.h" 13 #include "content/common/input/web_input_event_queue.h"
14 #include "third_party/WebKit/public/web/WebInputEvent.h" 14 #include "third_party/WebKit/public/web/WebInputEvent.h"
15 #include "ui/events/latency_info.h" 15 #include "ui/events/latency_info.h"
16 16
17 namespace content { 17 namespace content {
18 18
19 template <typename BaseClass, typename BaseType> 19 template <typename BaseClass, typename BaseType>
20 class EventWithDispatchType : public BaseClass { 20 class EventWithDispatchType : public BaseClass {
21 public: 21 public:
22 EventWithDispatchType(const BaseType& e, 22 EventWithDispatchType(const BaseType& e,
23 const ui::LatencyInfo& l, 23 const ui::LatencyInfo& l,
24 InputEventDispatchType t) 24 InputEventDispatchType t)
25 : BaseClass(e, l), type(t) {} 25 : BaseClass(e, l), type(t) {}
26 26
27 InputEventDispatchType type; 27 InputEventDispatchType type;
28 std::deque<uint32_t> eventsToAck;
28 29
29 bool CanCoalesceWith(const EventWithDispatchType& other) const 30 bool CanCoalesceWith(const EventWithDispatchType& other) const
30 WARN_UNUSED_RESULT { 31 WARN_UNUSED_RESULT {
31 return other.type == type && BaseClass::CanCoalesceWith(other); 32 return other.type == type && BaseClass::CanCoalesceWith(other);
32 } 33 }
33 34
34 void CoalesceWith(const EventWithDispatchType& other) { 35 void CoalesceWith(const EventWithDispatchType& other) {
36 // If we are blocking and are coalescing touch, make sure to keep
37 // the touch ids that need to be acked.
tdresser 2016/06/28 17:59:24 This comment is a bit confusing, because we'll cal
dtapuska 2016/06/28 19:51:08 Done.
38 if (type == DISPATCH_TYPE_BLOCKING_NOTIFY_MAIN) {
39 eventsToAck.push_back(
40 WebInputEventTraits::GetUniqueTouchEventId(other.event));
41 }
35 BaseClass::CoalesceWith(other); 42 BaseClass::CoalesceWith(other);
36 } 43 }
37 }; 44 };
38 45
39 using PendingMouseWheelEvent = 46 using PendingMouseWheelEvent =
40 EventWithDispatchType<MouseWheelEventWithLatencyInfo, 47 EventWithDispatchType<MouseWheelEventWithLatencyInfo,
41 blink::WebMouseWheelEvent>; 48 blink::WebMouseWheelEvent>;
42 49
43 using PendingTouchEvent = 50 using PendingTouchEvent =
44 EventWithDispatchType<TouchEventWithLatencyInfo, blink::WebTouchEvent>; 51 EventWithDispatchType<TouchEventWithLatencyInfo, blink::WebTouchEvent>;
45 52
46 class CONTENT_EXPORT MainThreadEventQueueClient { 53 class CONTENT_EXPORT MainThreadEventQueueClient {
47 public: 54 public:
48 // Send an |event| that was previously queued (possibly 55 // Send an |event| that was previously queued (possibly
49 // coalesced with another event) to the |routing_id|'s 56 // coalesced with another event) to the |routing_id|'s
50 // channel. Implementors must implement this callback. 57 // channel. Implementors must implement this callback.
51 virtual void SendEventToMainThread(int routing_id, 58 virtual void SendEventToMainThread(int routing_id,
52 const blink::WebInputEvent* event, 59 const blink::WebInputEvent* event,
53 const ui::LatencyInfo& latency, 60 const ui::LatencyInfo& latency,
54 InputEventDispatchType dispatch_type) = 0; 61 InputEventDispatchType dispatch_type) = 0;
62
63 virtual void SendInputEventAck(int routing_id,
64 blink::WebInputEvent::Type type,
65 InputEventAckState ack_result,
66 uint32_t touch_event_id) = 0;
55 }; 67 };
56 68
57 // MainThreadEventQueue implements a series of queues (one touch 69 // MainThreadEventQueue implements a series of queues (one touch
58 // and one mouse wheel) for events that need to be queued between 70 // and one mouse wheel) for events that need to be queued between
59 // the compositor and main threads. When an event is sent 71 // the compositor and main threads. When an event is sent
60 // from the compositor to main it can either be sent directly if no 72 // from the compositor to main it can either be sent directly if no
61 // outstanding events of that type are in flight; or it needs to 73 // outstanding events of that type are in flight; or it needs to
62 // wait in a queue until the main thread has finished processing 74 // wait in a queue until the main thread has finished processing
63 // the in-flight event. This class tracks the state and queues 75 // the in-flight event. This class tracks the state and queues
64 // for the event types. Methods on this class should only be called 76 // for the event types. Methods on this class should only be called
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 109
98 // Called once the compositor has handled |event| and indicated that it is 110 // Called once the compositor has handled |event| and indicated that it is
99 // a non-blocking event to be queued to the main thread. 111 // a non-blocking event to be queued to the main thread.
100 bool HandleEvent(const blink::WebInputEvent* event, 112 bool HandleEvent(const blink::WebInputEvent* event,
101 const ui::LatencyInfo& latency, 113 const ui::LatencyInfo& latency,
102 InputEventDispatchType dispatch_type, 114 InputEventDispatchType dispatch_type,
103 InputEventAckState ack_result); 115 InputEventAckState ack_result);
104 116
105 // Call once the main thread has handled an outstanding |type| event 117 // Call once the main thread has handled an outstanding |type| event
106 // in flight. 118 // in flight.
107 void EventHandled(blink::WebInputEvent::Type type); 119 void EventHandled(blink::WebInputEvent::Type type,
120 InputEventAckState ack_result);
108 121
109 void set_is_flinging(bool is_flinging) { is_flinging_ = is_flinging; } 122 void set_is_flinging(bool is_flinging) { is_flinging_ = is_flinging; }
110 123
111 private: 124 private:
112 friend class MainThreadEventQueueTest; 125 friend class MainThreadEventQueueTest;
113 int routing_id_; 126 int routing_id_;
114 MainThreadEventQueueClient* client_; 127 MainThreadEventQueueClient* client_;
115 WebInputEventQueue<PendingMouseWheelEvent> wheel_events_; 128 WebInputEventQueue<PendingMouseWheelEvent> wheel_events_;
116 WebInputEventQueue<PendingTouchEvent> touch_events_; 129 WebInputEventQueue<PendingTouchEvent> touch_events_;
117 bool is_flinging_; 130 bool is_flinging_;
118 131
132 // TODO(dtapuska): These can be removed when the queues are dequeued
133 // on the main thread. See crbug.com/624021
134 std::unique_ptr<PendingMouseWheelEvent> in_flight_wheel_event_;
135 std::unique_ptr<PendingTouchEvent> in_flight_touch_event_;
136
119 DISALLOW_COPY_AND_ASSIGN(MainThreadEventQueue); 137 DISALLOW_COPY_AND_ASSIGN(MainThreadEventQueue);
120 }; 138 };
121 139
122 } // namespace content 140 } // namespace content
123 141
124 #endif // CONTENT_RENDERER_INPUT_MAIN_THREAD_EVENT_QUEUE_H_ 142 #endif // CONTENT_RENDERER_INPUT_MAIN_THREAD_EVENT_QUEUE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698