OLD | NEW |
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 "base/feature_list.h" | 9 #include "base/feature_list.h" |
10 #include "content/common/content_export.h" | 10 #include "content/common/content_export.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" | |
14 #include "content/public/common/content_features.h" | 13 #include "content/public/common/content_features.h" |
| 14 #include "content/renderer/input/main_thread_event_queue_task_list.h" |
15 #include "content/renderer/input/scoped_web_input_event_with_latency_info.h" | 15 #include "content/renderer/input/scoped_web_input_event_with_latency_info.h" |
16 #include "third_party/WebKit/public/platform/WebInputEvent.h" | 16 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
17 #include "third_party/WebKit/public/platform/scheduler/renderer/renderer_schedul
er.h" | 17 #include "third_party/WebKit/public/platform/scheduler/renderer/renderer_schedul
er.h" |
18 #include "ui/events/blink/web_input_event_traits.h" | 18 #include "ui/events/blink/web_input_event_traits.h" |
19 #include "ui/events/latency_info.h" | 19 #include "ui/events/latency_info.h" |
20 | 20 |
21 namespace content { | 21 namespace content { |
22 | 22 |
23 class EventWithDispatchType : public ScopedWebInputEventWithLatencyInfo { | |
24 public: | |
25 EventWithDispatchType(ui::WebScopedInputEvent event, | |
26 const ui::LatencyInfo& latency, | |
27 InputEventDispatchType dispatch_type, | |
28 bool originally_cancelable); | |
29 ~EventWithDispatchType(); | |
30 void CoalesceWith(const EventWithDispatchType& other); | |
31 | |
32 const std::deque<uint32_t>& blockingCoalescedEventIds() const { | |
33 return blocking_coalesced_event_ids_; | |
34 } | |
35 InputEventDispatchType dispatchType() const { return dispatch_type_; } | |
36 base::TimeTicks creationTimestamp() const { return creation_timestamp_; } | |
37 base::TimeTicks lastCoalescedTimestamp() const { | |
38 return last_coalesced_timestamp_; | |
39 } | |
40 | |
41 size_t coalescedCount() const { | |
42 return non_blocking_coalesced_count_ + blocking_coalesced_event_ids_.size(); | |
43 } | |
44 | |
45 bool originallyCancelable() const { return originally_cancelable_; } | |
46 | |
47 private: | |
48 InputEventDispatchType dispatch_type_; | |
49 | |
50 // Contains the unique touch event ids to be acked. If | |
51 // the events are not TouchEvents the values will be 0. More importantly for | |
52 // those cases the deque ends up containing how many additional ACKs | |
53 // need to be sent. | |
54 std::deque<uint32_t> blocking_coalesced_event_ids_; | |
55 // Contains the number of non-blocking events coalesced. | |
56 size_t non_blocking_coalesced_count_; | |
57 base::TimeTicks creation_timestamp_; | |
58 base::TimeTicks last_coalesced_timestamp_; | |
59 | |
60 // Whether the received event was originally cancelable or not. The compositor | |
61 // input handler can change the event based on presence of event handlers so | |
62 // this is the state at which the renderer received the event from the | |
63 // browser. | |
64 bool originally_cancelable_; | |
65 }; | |
66 | |
67 class CONTENT_EXPORT MainThreadEventQueueClient { | 23 class CONTENT_EXPORT MainThreadEventQueueClient { |
68 public: | 24 public: |
69 // Handle an |event| that was previously queued (possibly | 25 // Handle an |event| that was previously queued (possibly |
70 // coalesced with another event) to the |routing_id|'s | 26 // coalesced with another event) to the |routing_id|'s |
71 // channel. Implementors must implement this callback. | 27 // channel. Implementors must implement this callback. |
72 virtual void HandleEventOnMainThread( | 28 virtual void HandleEventOnMainThread( |
73 int routing_id, | 29 int routing_id, |
74 const blink::WebCoalescedInputEvent* event, | 30 const blink::WebCoalescedInputEvent* event, |
75 const ui::LatencyInfo& latency, | 31 const ui::LatencyInfo& latency, |
76 InputEventDispatchType dispatch_type) = 0; | 32 InputEventDispatchType dispatch_type) = 0; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner, | 83 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner, |
128 blink::scheduler::RendererScheduler* renderer_scheduler); | 84 blink::scheduler::RendererScheduler* renderer_scheduler); |
129 | 85 |
130 // Called once the compositor has handled |event| and indicated that it is | 86 // Called once the compositor has handled |event| and indicated that it is |
131 // a non-blocking event to be queued to the main thread. | 87 // a non-blocking event to be queued to the main thread. |
132 bool HandleEvent(ui::WebScopedInputEvent event, | 88 bool HandleEvent(ui::WebScopedInputEvent event, |
133 const ui::LatencyInfo& latency, | 89 const ui::LatencyInfo& latency, |
134 InputEventDispatchType dispatch_type, | 90 InputEventDispatchType dispatch_type, |
135 InputEventAckState ack_result); | 91 InputEventAckState ack_result); |
136 void DispatchRafAlignedInput(base::TimeTicks frame_time); | 92 void DispatchRafAlignedInput(base::TimeTicks frame_time); |
| 93 void QueueClosure(const base::Closure& closure); |
137 | 94 |
138 // Call once the main thread has handled an outstanding |type| event | 95 // Call once the main thread has handled an outstanding |type| event |
139 // in flight. | 96 // in flight. |
140 void EventHandled(blink::WebInputEvent::Type type, | 97 void EventHandled(blink::WebInputEvent::Type type, |
141 blink::WebInputEventResult result, | 98 blink::WebInputEventResult result, |
142 InputEventAckState ack_result); | 99 InputEventAckState ack_result); |
143 | 100 |
144 private: | 101 private: |
145 friend class base::RefCountedThreadSafe<MainThreadEventQueue>; | 102 friend class base::RefCountedThreadSafe<MainThreadEventQueue>; |
146 ~MainThreadEventQueue(); | 103 ~MainThreadEventQueue(); |
147 void QueueEvent(std::unique_ptr<EventWithDispatchType> event); | 104 void QueueEvent(std::unique_ptr<MainThreadEventQueueTask> event); |
148 void SendEventNotificationToMainThread(); | 105 void PostTaskToMainThread(); |
149 void DispatchSingleEvent(); | 106 void DispatchEvents(); |
150 void DispatchInFlightEvent(); | 107 void DispatchInFlightEvent(); |
151 void PossiblyScheduleMainFrame(); | 108 void PossiblyScheduleMainFrame(); |
152 | 109 |
153 void SendEventToMainThread(const blink::WebInputEvent* event, | 110 void SendEventToMainThread(const blink::WebInputEvent* event, |
154 const ui::LatencyInfo& latency, | 111 const ui::LatencyInfo& latency, |
155 InputEventDispatchType original_dispatch_type); | 112 InputEventDispatchType original_dispatch_type); |
156 | 113 |
157 bool IsRafAlignedInputDisabled(); | 114 bool IsRafAlignedInputDisabled() const; |
158 bool IsRafAlignedEvent(const blink::WebInputEvent& event); | 115 bool IsRafAlignedEvent( |
| 116 const std::unique_ptr<MainThreadEventQueueTask>& item) const; |
159 | 117 |
160 friend class MainThreadEventQueueTest; | 118 friend class MainThreadEventQueueTest; |
161 friend class MainThreadEventQueueInitializationTest; | 119 friend class MainThreadEventQueueInitializationTest; |
162 int routing_id_; | 120 int routing_id_; |
163 MainThreadEventQueueClient* client_; | 121 MainThreadEventQueueClient* client_; |
164 std::unique_ptr<EventWithDispatchType> in_flight_event_; | 122 std::unique_ptr<MainThreadEventQueueTask> in_flight_event_; |
165 bool last_touch_start_forced_nonblocking_due_to_fling_; | 123 bool last_touch_start_forced_nonblocking_due_to_fling_; |
166 bool enable_fling_passive_listener_flag_; | 124 bool enable_fling_passive_listener_flag_; |
167 bool enable_non_blocking_due_to_main_thread_responsiveness_flag_; | 125 bool enable_non_blocking_due_to_main_thread_responsiveness_flag_; |
168 base::TimeDelta main_thread_responsiveness_threshold_; | 126 base::TimeDelta main_thread_responsiveness_threshold_; |
169 bool handle_raf_aligned_touch_input_; | 127 bool handle_raf_aligned_touch_input_; |
170 bool handle_raf_aligned_mouse_input_; | 128 bool handle_raf_aligned_mouse_input_; |
171 | 129 |
172 // Contains data to be shared between main thread and compositor thread. | 130 // Contains data to be shared between main thread and compositor thread. |
173 struct SharedState { | 131 struct SharedState { |
174 SharedState(); | 132 SharedState(); |
175 ~SharedState(); | 133 ~SharedState(); |
176 | 134 |
177 WebInputEventQueue<EventWithDispatchType> events_; | 135 MainThreadEventQueueTaskList events_; |
| 136 // A BeginMainFrame has been requested but not received yet. |
178 bool sent_main_frame_request_; | 137 bool sent_main_frame_request_; |
| 138 // A PostTask to the main thread has been sent but not executed yet. |
| 139 bool sent_post_task_; |
179 base::TimeTicks last_async_touch_move_timestamp_; | 140 base::TimeTicks last_async_touch_move_timestamp_; |
180 }; | 141 }; |
181 | 142 |
182 // Lock used to serialize |shared_state_|. | 143 // Lock used to serialize |shared_state_|. |
183 base::Lock shared_state_lock_; | 144 base::Lock shared_state_lock_; |
184 SharedState shared_state_; | 145 SharedState shared_state_; |
185 | 146 |
186 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 147 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
187 blink::scheduler::RendererScheduler* renderer_scheduler_; | 148 blink::scheduler::RendererScheduler* renderer_scheduler_; |
188 | 149 |
189 DISALLOW_COPY_AND_ASSIGN(MainThreadEventQueue); | 150 DISALLOW_COPY_AND_ASSIGN(MainThreadEventQueue); |
190 }; | 151 }; |
191 | 152 |
192 } // namespace content | 153 } // namespace content |
193 | 154 |
194 #endif // CONTENT_RENDERER_INPUT_MAIN_THREAD_EVENT_QUEUE_H_ | 155 #endif // CONTENT_RENDERER_INPUT_MAIN_THREAD_EVENT_QUEUE_H_ |
OLD | NEW |