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 "base/memory/weak_ptr.h" | |
| 10 #include "content/common/content_export.h" | 11 #include "content/common/content_export.h" |
| 11 #include "content/common/input/input_event_ack_state.h" | 12 #include "content/common/input/input_event_ack_state.h" |
| 12 #include "content/common/input/input_event_dispatch_type.h" | 13 #include "content/common/input/input_event_dispatch_type.h" |
| 13 #include "content/public/common/content_features.h" | 14 #include "content/public/common/content_features.h" |
| 14 #include "content/renderer/input/main_thread_event_queue_task_list.h" | 15 #include "content/renderer/input/main_thread_event_queue_task_list.h" |
| 15 #include "content/renderer/input/scoped_web_input_event_with_latency_info.h" | 16 #include "content/renderer/input/scoped_web_input_event_with_latency_info.h" |
| 16 #include "third_party/WebKit/public/platform/WebInputEvent.h" | 17 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
| 17 #include "third_party/WebKit/public/platform/scheduler/renderer/renderer_schedul er.h" | 18 #include "third_party/WebKit/public/platform/scheduler/renderer/renderer_schedul er.h" |
| 18 #include "ui/events/blink/web_input_event_traits.h" | 19 #include "ui/events/blink/web_input_event_traits.h" |
| 19 #include "ui/latency/latency_info.h" | 20 #include "ui/latency/latency_info.h" |
| 20 | 21 |
| 21 namespace content { | 22 namespace content { |
| 22 | 23 |
| 24 // All interaction with the MainThreadEventQueueClient will occur | |
| 25 // on the main thread. | |
| 23 class CONTENT_EXPORT MainThreadEventQueueClient { | 26 class CONTENT_EXPORT MainThreadEventQueueClient { |
| 24 public: | 27 public: |
| 25 // Handle an |event| that was previously queued (possibly | 28 // Handle an |event| that was previously queued (possibly |
| 26 // coalesced with another event) to the |routing_id|'s | 29 // coalesced with another event). Implementors must implement |
| 27 // channel. Implementors must implement this callback. | 30 // this callback. |
| 28 virtual void HandleEventOnMainThread( | 31 virtual InputEventAckState HandleInputEvent( |
| 29 int routing_id, | 32 const blink::WebCoalescedInputEvent& event, |
| 30 const blink::WebCoalescedInputEvent* event, | 33 const ui::LatencyInfo& latency_info, |
| 31 const ui::LatencyInfo& latency, | |
| 32 InputEventDispatchType dispatch_type) = 0; | 34 InputEventDispatchType dispatch_type) = 0; |
| 33 | 35 |
| 34 virtual void SendInputEventAck(int routing_id, | 36 virtual void SendInputEventAck(blink::WebInputEvent::Type type, |
| 35 blink::WebInputEvent::Type type, | |
| 36 InputEventAckState ack_result, | 37 InputEventAckState ack_result, |
| 37 uint32_t touch_event_id) = 0; | 38 uint32_t touch_event_id) = 0; |
| 38 virtual void NeedsMainFrame(int routing_id) = 0; | 39 virtual void SetNeedsMainFrame() = 0; |
| 39 }; | 40 }; |
| 40 | 41 |
| 41 // MainThreadEventQueue implements a queue for events that need to be | 42 // MainThreadEventQueue implements a queue for events that need to be |
| 42 // queued between the compositor and main threads. This queue is managed | 43 // queued between the compositor and main threads. This queue is managed |
| 43 // by a lock where events are enqueued by the compositor thread | 44 // by a lock where events are enqueued by the compositor thread |
| 44 // and dequeued by the main thread. | 45 // and dequeued by the main thread. |
| 45 // | 46 // |
| 46 // Below some example flows are how the code behaves. | 47 // Below some example flows are how the code behaves. |
| 47 // Legend: B=Browser, C=Compositor, M=Main Thread, NB=Non-blocking | 48 // Legend: B=Browser, C=Compositor, M=Main Thread, NB=Non-blocking |
| 48 // BL=Blocking, PT=Post Task, ACK=Acknowledgement | 49 // BL=Blocking, PT=Post Task, ACK=Acknowledgement |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 71 // (queue) | 72 // (queue) |
| 72 // ---(PT)--> | 73 // ---(PT)--> |
| 73 // (deque) | 74 // (deque) |
| 74 // (deque) | 75 // (deque) |
| 75 // <-------(ACK)------ | 76 // <-------(ACK)------ |
| 76 // | 77 // |
| 77 class CONTENT_EXPORT MainThreadEventQueue | 78 class CONTENT_EXPORT MainThreadEventQueue |
| 78 : public base::RefCountedThreadSafe<MainThreadEventQueue> { | 79 : public base::RefCountedThreadSafe<MainThreadEventQueue> { |
| 79 public: | 80 public: |
| 80 MainThreadEventQueue( | 81 MainThreadEventQueue( |
| 81 int routing_id, | |
| 82 MainThreadEventQueueClient* client, | 82 MainThreadEventQueueClient* client, |
| 83 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner, | 83 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner, |
| 84 blink::scheduler::RendererScheduler* renderer_scheduler); | 84 blink::scheduler::RendererScheduler* renderer_scheduler); |
| 85 | 85 |
| 86 // 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 |
| 87 // a non-blocking event to be queued to the main thread. | 87 // a non-blocking event to be queued to the main thread. |
| 88 bool HandleEvent(ui::WebScopedInputEvent event, | 88 bool HandleEvent(ui::WebScopedInputEvent event, |
| 89 const ui::LatencyInfo& latency, | 89 const ui::LatencyInfo& latency, |
| 90 InputEventDispatchType dispatch_type, | 90 InputEventDispatchType dispatch_type, |
| 91 InputEventAckState ack_result); | 91 InputEventAckState ack_result); |
| 92 void DispatchRafAlignedInput(base::TimeTicks frame_time); | 92 void DispatchRafAlignedInput(base::TimeTicks frame_time); |
| 93 void QueueClosure(const base::Closure& closure); | 93 void QueueClosure(const base::Closure& closure); |
| 94 | 94 |
| 95 // Call once the main thread has handled an outstanding |type| event | 95 void ClearClient(); |
| 96 // in flight. | |
| 97 void EventHandled(blink::WebInputEvent::Type type, | |
| 98 blink::WebInputEventResult result, | |
| 99 InputEventAckState ack_result); | |
| 100 | 96 |
| 101 private: | 97 protected: |
| 102 friend class base::RefCountedThreadSafe<MainThreadEventQueue>; | 98 friend class base::RefCountedThreadSafe<MainThreadEventQueue>; |
| 103 ~MainThreadEventQueue(); | 99 virtual ~MainThreadEventQueue(); |
| 104 void QueueEvent(std::unique_ptr<MainThreadEventQueueTask> event); | 100 void QueueEvent(std::unique_ptr<MainThreadEventQueueTask> event); |
| 105 void PostTaskToMainThread(); | 101 void PostTaskToMainThread(); |
| 106 void DispatchEvents(); | 102 void DispatchEvents(); |
| 107 void DispatchInFlightEvent(); | 103 void DispatchInFlightEvent(); |
| 108 void PossiblyScheduleMainFrame(); | 104 void PossiblyScheduleMainFrame(); |
| 105 void NeedsMainFrame(); | |
|
tdresser
2017/04/13 17:19:59
Should this be called SetNeedsMainFrame, to be con
dtapuska
2017/04/18 12:59:28
Done.
| |
| 106 InputEventAckState HandleEventOnMainThread( | |
| 107 const blink::WebCoalescedInputEvent& event, | |
| 108 const ui::LatencyInfo& latency, | |
| 109 InputEventDispatchType dispatch_type); | |
| 110 void SendInputEventAck(const blink::WebInputEvent& event, | |
| 111 InputEventAckState ack_result, | |
| 112 uint32_t touch_event_id); | |
| 109 | 113 |
| 110 void SendEventToMainThread(const blink::WebInputEvent* event, | 114 void SendEventToMainThread(const blink::WebInputEvent* event, |
| 111 const ui::LatencyInfo& latency, | 115 const ui::LatencyInfo& latency, |
| 112 InputEventDispatchType original_dispatch_type); | 116 InputEventDispatchType original_dispatch_type); |
| 113 | 117 |
| 114 bool IsRafAlignedInputDisabled() const; | 118 bool IsRafAlignedInputDisabled() const; |
| 115 bool IsRafAlignedEvent( | 119 bool IsRafAlignedEvent( |
| 116 const std::unique_ptr<MainThreadEventQueueTask>& item) const; | 120 const std::unique_ptr<MainThreadEventQueueTask>& item) const; |
| 117 | 121 |
| 122 friend class QueuedWebInputEvent; | |
| 118 friend class MainThreadEventQueueTest; | 123 friend class MainThreadEventQueueTest; |
| 119 friend class MainThreadEventQueueInitializationTest; | 124 friend class MainThreadEventQueueInitializationTest; |
| 120 int routing_id_; | |
| 121 MainThreadEventQueueClient* client_; | 125 MainThreadEventQueueClient* client_; |
| 122 std::unique_ptr<MainThreadEventQueueTask> in_flight_event_; | 126 std::unique_ptr<MainThreadEventQueueTask> in_flight_event_; |
| 123 bool last_touch_start_forced_nonblocking_due_to_fling_; | 127 bool last_touch_start_forced_nonblocking_due_to_fling_; |
| 124 bool enable_fling_passive_listener_flag_; | 128 bool enable_fling_passive_listener_flag_; |
| 125 bool enable_non_blocking_due_to_main_thread_responsiveness_flag_; | 129 bool enable_non_blocking_due_to_main_thread_responsiveness_flag_; |
| 126 base::TimeDelta main_thread_responsiveness_threshold_; | 130 base::TimeDelta main_thread_responsiveness_threshold_; |
| 127 bool handle_raf_aligned_touch_input_; | 131 bool handle_raf_aligned_touch_input_; |
| 128 bool handle_raf_aligned_mouse_input_; | 132 bool handle_raf_aligned_mouse_input_; |
| 129 | 133 |
| 130 // Contains data to be shared between main thread and compositor thread. | 134 // Contains data to be shared between main thread and compositor thread. |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 146 | 150 |
| 147 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 151 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
| 148 blink::scheduler::RendererScheduler* renderer_scheduler_; | 152 blink::scheduler::RendererScheduler* renderer_scheduler_; |
| 149 | 153 |
| 150 DISALLOW_COPY_AND_ASSIGN(MainThreadEventQueue); | 154 DISALLOW_COPY_AND_ASSIGN(MainThreadEventQueue); |
| 151 }; | 155 }; |
| 152 | 156 |
| 153 } // namespace content | 157 } // namespace content |
| 154 | 158 |
| 155 #endif // CONTENT_RENDERER_INPUT_MAIN_THREAD_EVENT_QUEUE_H_ | 159 #endif // CONTENT_RENDERER_INPUT_MAIN_THREAD_EVENT_QUEUE_H_ |
| OLD | NEW |