Chromium Code Reviews| 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" | 13 #include "content/common/input/web_input_event_queue.h" |
| 14 #include "content/public/common/content_features.h" | 14 #include "content/public/common/content_features.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 { | 23 class MainThreadEventQueueClient; |
| 24 | |
| 25 class QueuedItem { | |
|
mustaq
2017/03/24 15:31:18
Since this is an exposed class, I would prefer a m
dtapuska
2017/03/24 20:16:34
Done.
| |
| 24 public: | 26 public: |
| 25 EventWithDispatchType(ui::WebScopedInputEvent event, | 27 virtual ~QueuedItem() {} |
| 26 const ui::LatencyInfo& latency, | |
| 27 InputEventDispatchType dispatch_type, | |
| 28 bool originally_cancelable); | |
| 29 ~EventWithDispatchType(); | |
| 30 void CoalesceWith(const EventWithDispatchType& other); | |
| 31 | 28 |
| 32 const std::deque<uint32_t>& blockingCoalescedEventIds() const { | 29 virtual bool CanCoalesceWith(const QueuedItem&) = 0; |
| 33 return blocking_coalesced_event_ids_; | 30 virtual void CoalesceWith(const QueuedItem&) = 0; |
| 34 } | 31 virtual bool IsSameEventClass(const QueuedItem&) const = 0; |
| 35 InputEventDispatchType dispatchType() const { return dispatch_type_; } | 32 virtual bool IsEvent() const = 0; |
| 36 base::TimeTicks creationTimestamp() const { return creation_timestamp_; } | 33 virtual void Dispatch(int routing_id, MainThreadEventQueueClient*) = 0; |
| 37 base::TimeTicks lastCoalescedTimestamp() const { | 34 virtual void EventHandled( |
| 38 return last_coalesced_timestamp_; | 35 int routing_id, |
| 39 } | 36 blink::scheduler::RendererScheduler* renderer_scheduler, |
| 40 | 37 MainThreadEventQueueClient* client, |
| 41 size_t coalescedCount() const { | 38 blink::WebInputEvent::Type type, |
| 42 return non_blocking_coalesced_count_ + blocking_coalesced_event_ids_.size(); | 39 blink::WebInputEventResult result, |
| 43 } | 40 InputEventAckState ack_result) = 0; |
| 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 }; | 41 }; |
| 66 | 42 |
| 67 class CONTENT_EXPORT MainThreadEventQueueClient { | 43 class CONTENT_EXPORT MainThreadEventQueueClient { |
| 68 public: | 44 public: |
| 69 // Handle an |event| that was previously queued (possibly | 45 // Handle an |event| that was previously queued (possibly |
| 70 // coalesced with another event) to the |routing_id|'s | 46 // coalesced with another event) to the |routing_id|'s |
| 71 // channel. Implementors must implement this callback. | 47 // channel. Implementors must implement this callback. |
| 72 virtual void HandleEventOnMainThread( | 48 virtual void HandleEventOnMainThread( |
| 73 int routing_id, | 49 int routing_id, |
| 74 const blink::WebCoalescedInputEvent* event, | 50 const blink::WebCoalescedInputEvent* event, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner, | 103 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner, |
| 128 blink::scheduler::RendererScheduler* renderer_scheduler); | 104 blink::scheduler::RendererScheduler* renderer_scheduler); |
| 129 | 105 |
| 130 // Called once the compositor has handled |event| and indicated that it is | 106 // Called once the compositor has handled |event| and indicated that it is |
| 131 // a non-blocking event to be queued to the main thread. | 107 // a non-blocking event to be queued to the main thread. |
| 132 bool HandleEvent(ui::WebScopedInputEvent event, | 108 bool HandleEvent(ui::WebScopedInputEvent event, |
| 133 const ui::LatencyInfo& latency, | 109 const ui::LatencyInfo& latency, |
| 134 InputEventDispatchType dispatch_type, | 110 InputEventDispatchType dispatch_type, |
| 135 InputEventAckState ack_result); | 111 InputEventAckState ack_result); |
| 136 void DispatchRafAlignedInput(base::TimeTicks frame_time); | 112 void DispatchRafAlignedInput(base::TimeTicks frame_time); |
| 113 void QueueClosure(const base::Closure& closure); | |
| 137 | 114 |
| 138 // Call once the main thread has handled an outstanding |type| event | 115 // Call once the main thread has handled an outstanding |type| event |
| 139 // in flight. | 116 // in flight. |
| 140 void EventHandled(blink::WebInputEvent::Type type, | 117 void EventHandled(blink::WebInputEvent::Type type, |
| 141 blink::WebInputEventResult result, | 118 blink::WebInputEventResult result, |
| 142 InputEventAckState ack_result); | 119 InputEventAckState ack_result); |
| 143 | 120 |
| 144 private: | 121 private: |
| 145 friend class base::RefCountedThreadSafe<MainThreadEventQueue>; | 122 friend class base::RefCountedThreadSafe<MainThreadEventQueue>; |
| 146 ~MainThreadEventQueue(); | 123 ~MainThreadEventQueue(); |
| 147 void QueueEvent(std::unique_ptr<EventWithDispatchType> event); | 124 void QueueEvent(std::unique_ptr<QueuedItem> event); |
| 148 void SendEventNotificationToMainThread(); | 125 void SendEventNotificationToMainThread(); |
| 149 void DispatchSingleEvent(); | 126 void DispatchEvents(); |
| 150 void DispatchInFlightEvent(); | 127 void DispatchInFlightEvent(); |
| 151 void PossiblyScheduleMainFrame(); | 128 void PossiblyScheduleMainFrame(); |
| 152 | 129 |
| 153 void SendEventToMainThread(const blink::WebInputEvent* event, | 130 void SendEventToMainThread(const blink::WebInputEvent* event, |
| 154 const ui::LatencyInfo& latency, | 131 const ui::LatencyInfo& latency, |
| 155 InputEventDispatchType original_dispatch_type); | 132 InputEventDispatchType original_dispatch_type); |
| 156 | 133 |
| 157 bool IsRafAlignedInputDisabled(); | 134 bool IsRafAlignedInputDisabled() const; |
| 158 bool IsRafAlignedEvent(const blink::WebInputEvent& event); | 135 bool IsRafAlignedEvent(const std::unique_ptr<QueuedItem>& item) const; |
|
mustaq
2017/03/24 15:31:18
This seems to belong to the class |QueuedItem| (|M
dtapuska
2017/03/24 20:16:34
I agree. But it needs to check the variables store
| |
| 159 | 136 |
| 160 friend class MainThreadEventQueueTest; | 137 friend class MainThreadEventQueueTest; |
| 161 friend class MainThreadEventQueueInitializationTest; | 138 friend class MainThreadEventQueueInitializationTest; |
| 162 int routing_id_; | 139 int routing_id_; |
| 163 MainThreadEventQueueClient* client_; | 140 MainThreadEventQueueClient* client_; |
| 164 std::unique_ptr<EventWithDispatchType> in_flight_event_; | 141 std::unique_ptr<QueuedItem> in_flight_event_; |
| 165 bool last_touch_start_forced_nonblocking_due_to_fling_; | 142 bool last_touch_start_forced_nonblocking_due_to_fling_; |
| 166 bool enable_fling_passive_listener_flag_; | 143 bool enable_fling_passive_listener_flag_; |
| 167 bool enable_non_blocking_due_to_main_thread_responsiveness_flag_; | 144 bool enable_non_blocking_due_to_main_thread_responsiveness_flag_; |
| 168 base::TimeDelta main_thread_responsiveness_threshold_; | 145 base::TimeDelta main_thread_responsiveness_threshold_; |
| 169 bool handle_raf_aligned_touch_input_; | 146 bool handle_raf_aligned_touch_input_; |
| 170 bool handle_raf_aligned_mouse_input_; | 147 bool handle_raf_aligned_mouse_input_; |
| 171 | 148 |
| 172 // Contains data to be shared between main thread and compositor thread. | 149 // Contains data to be shared between main thread and compositor thread. |
| 173 struct SharedState { | 150 struct SharedState { |
| 174 SharedState(); | 151 SharedState(); |
| 175 ~SharedState(); | 152 ~SharedState(); |
| 176 | 153 |
| 177 WebInputEventQueue<EventWithDispatchType> events_; | 154 WebInputEventQueue<QueuedItem> events_; |
| 178 bool sent_main_frame_request_; | 155 bool sent_main_frame_request_; |
| 156 bool sent_post_task_; | |
|
mustaq
2017/03/24 15:31:18
Could you please clarify what "sent" means here, t
dtapuska
2017/03/24 20:16:34
Done.
| |
| 179 base::TimeTicks last_async_touch_move_timestamp_; | 157 base::TimeTicks last_async_touch_move_timestamp_; |
| 180 }; | 158 }; |
| 181 | 159 |
| 182 // Lock used to serialize |shared_state_|. | 160 // Lock used to serialize |shared_state_|. |
| 183 base::Lock shared_state_lock_; | 161 base::Lock shared_state_lock_; |
| 184 SharedState shared_state_; | 162 SharedState shared_state_; |
| 185 | 163 |
| 186 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 164 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
| 187 blink::scheduler::RendererScheduler* renderer_scheduler_; | 165 blink::scheduler::RendererScheduler* renderer_scheduler_; |
| 188 | 166 |
| 189 DISALLOW_COPY_AND_ASSIGN(MainThreadEventQueue); | 167 DISALLOW_COPY_AND_ASSIGN(MainThreadEventQueue); |
| 190 }; | 168 }; |
| 191 | 169 |
| 192 } // namespace content | 170 } // namespace content |
| 193 | 171 |
| 194 #endif // CONTENT_RENDERER_INPUT_MAIN_THREAD_EVENT_QUEUE_H_ | 172 #endif // CONTENT_RENDERER_INPUT_MAIN_THREAD_EVENT_QUEUE_H_ |
| OLD | NEW |