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 |
23 class CONTENT_EXPORT MainThreadEventQueueClient { | 24 class RenderWidget; |
24 public: | |
25 // Handle an |event| that was previously queued (possibly | |
26 // coalesced with another event) to the |routing_id|'s | |
27 // channel. Implementors must implement this callback. | |
28 virtual void HandleEventOnMainThread( | |
29 int routing_id, | |
30 const blink::WebCoalescedInputEvent* event, | |
31 const ui::LatencyInfo& latency, | |
32 InputEventDispatchType dispatch_type) = 0; | |
33 | |
34 virtual void SendInputEventAck(int routing_id, | |
35 blink::WebInputEvent::Type type, | |
36 InputEventAckState ack_result, | |
37 uint32_t touch_event_id) = 0; | |
38 virtual void NeedsMainFrame(int routing_id) = 0; | |
39 }; | |
40 | 25 |
41 // MainThreadEventQueue implements a queue for events that need to be | 26 // MainThreadEventQueue implements a queue for events that need to be |
42 // queued between the compositor and main threads. This queue is managed | 27 // queued between the compositor and main threads. This queue is managed |
43 // by a lock where events are enqueued by the compositor thread | 28 // by a lock where events are enqueued by the compositor thread |
44 // and dequeued by the main thread. | 29 // and dequeued by the main thread. |
45 // | 30 // |
46 // Below some example flows are how the code behaves. | 31 // Below some example flows are how the code behaves. |
47 // Legend: B=Browser, C=Compositor, M=Main Thread, NB=Non-blocking | 32 // Legend: B=Browser, C=Compositor, M=Main Thread, NB=Non-blocking |
48 // BL=Blocking, PT=Post Task, ACK=Acknowledgement | 33 // BL=Blocking, PT=Post Task, ACK=Acknowledgement |
49 // | 34 // |
(...skipping 21 matching lines...) Expand all Loading... | |
71 // (queue) | 56 // (queue) |
72 // ---(PT)--> | 57 // ---(PT)--> |
73 // (deque) | 58 // (deque) |
74 // (deque) | 59 // (deque) |
75 // <-------(ACK)------ | 60 // <-------(ACK)------ |
76 // | 61 // |
77 class CONTENT_EXPORT MainThreadEventQueue | 62 class CONTENT_EXPORT MainThreadEventQueue |
78 : public base::RefCountedThreadSafe<MainThreadEventQueue> { | 63 : public base::RefCountedThreadSafe<MainThreadEventQueue> { |
79 public: | 64 public: |
80 MainThreadEventQueue( | 65 MainThreadEventQueue( |
81 int routing_id, | |
82 MainThreadEventQueueClient* client, | |
83 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner, | 66 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner, |
84 blink::scheduler::RendererScheduler* renderer_scheduler); | 67 blink::scheduler::RendererScheduler* renderer_scheduler); |
85 | 68 |
86 // Called once the compositor has handled |event| and indicated that it is | 69 // Called once the compositor has handled |event| and indicated that it is |
87 // a non-blocking event to be queued to the main thread. | 70 // a non-blocking event to be queued to the main thread. |
88 bool HandleEvent(ui::WebScopedInputEvent event, | 71 bool HandleEvent(ui::WebScopedInputEvent event, |
89 const ui::LatencyInfo& latency, | 72 const ui::LatencyInfo& latency, |
90 InputEventDispatchType dispatch_type, | 73 InputEventDispatchType dispatch_type, |
91 InputEventAckState ack_result); | 74 InputEventAckState ack_result); |
92 void DispatchRafAlignedInput(base::TimeTicks frame_time); | 75 void DispatchRafAlignedInput(base::TimeTicks frame_time); |
93 void QueueClosure(const base::Closure& closure); | 76 void QueueClosure(const base::Closure& closure); |
94 | 77 |
95 // Call once the main thread has handled an outstanding |type| event | 78 void NotifySchedulerOfEventHandled(const blink::WebInputEvent& event, |
96 // in flight. | 79 InputEventAckState ack_result); |
97 void EventHandled(blink::WebInputEvent::Type type, | |
98 blink::WebInputEventResult result, | |
99 InputEventAckState ack_result); | |
100 | 80 |
101 private: | 81 virtual InputEventAckState HandleEventOnMainThread( |
82 const blink::WebCoalescedInputEvent& event, | |
83 const ui::LatencyInfo& latency, | |
84 InputEventDispatchType dispatch_type) = 0; | |
85 | |
86 virtual void SendInputEventAck(blink::WebInputEvent::Type type, | |
87 InputEventAckState ack_result, | |
88 uint32_t touch_event_id) = 0; | |
tdresser
2017/04/10 15:54:17
Why is SendInputEventAck separate from NotifySched
dtapuska
2017/04/10 16:08:05
Mainly for the tests. There is a mock renderer sch
| |
89 virtual void NeedsMainFrame() = 0; | |
90 | |
91 protected: | |
102 friend class base::RefCountedThreadSafe<MainThreadEventQueue>; | 92 friend class base::RefCountedThreadSafe<MainThreadEventQueue>; |
103 ~MainThreadEventQueue(); | 93 virtual ~MainThreadEventQueue(); |
104 void QueueEvent(std::unique_ptr<MainThreadEventQueueTask> event); | 94 void QueueEvent(std::unique_ptr<MainThreadEventQueueTask> event); |
105 void PostTaskToMainThread(); | 95 void PostTaskToMainThread(); |
106 void DispatchEvents(); | 96 void DispatchEvents(); |
107 void DispatchInFlightEvent(); | 97 void DispatchInFlightEvent(); |
108 void PossiblyScheduleMainFrame(); | 98 void PossiblyScheduleMainFrame(); |
109 | 99 |
110 void SendEventToMainThread(const blink::WebInputEvent* event, | 100 void SendEventToMainThread(const blink::WebInputEvent* event, |
111 const ui::LatencyInfo& latency, | 101 const ui::LatencyInfo& latency, |
112 InputEventDispatchType original_dispatch_type); | 102 InputEventDispatchType original_dispatch_type); |
113 | 103 |
114 bool IsRafAlignedInputDisabled() const; | 104 bool IsRafAlignedInputDisabled() const; |
115 bool IsRafAlignedEvent( | 105 bool IsRafAlignedEvent( |
116 const std::unique_ptr<MainThreadEventQueueTask>& item) const; | 106 const std::unique_ptr<MainThreadEventQueueTask>& item) const; |
117 | 107 |
118 friend class MainThreadEventQueueTest; | 108 friend class MainThreadEventQueueTest; |
119 friend class MainThreadEventQueueInitializationTest; | 109 friend class MainThreadEventQueueInitializationTest; |
120 int routing_id_; | |
121 MainThreadEventQueueClient* client_; | |
122 std::unique_ptr<MainThreadEventQueueTask> in_flight_event_; | 110 std::unique_ptr<MainThreadEventQueueTask> in_flight_event_; |
123 bool last_touch_start_forced_nonblocking_due_to_fling_; | 111 bool last_touch_start_forced_nonblocking_due_to_fling_; |
124 bool enable_fling_passive_listener_flag_; | 112 bool enable_fling_passive_listener_flag_; |
125 bool enable_non_blocking_due_to_main_thread_responsiveness_flag_; | 113 bool enable_non_blocking_due_to_main_thread_responsiveness_flag_; |
126 base::TimeDelta main_thread_responsiveness_threshold_; | 114 base::TimeDelta main_thread_responsiveness_threshold_; |
127 bool handle_raf_aligned_touch_input_; | 115 bool handle_raf_aligned_touch_input_; |
128 bool handle_raf_aligned_mouse_input_; | 116 bool handle_raf_aligned_mouse_input_; |
129 | 117 |
130 // Contains data to be shared between main thread and compositor thread. | 118 // Contains data to be shared between main thread and compositor thread. |
131 struct SharedState { | 119 struct SharedState { |
(...skipping 11 matching lines...) Expand all Loading... | |
143 // Lock used to serialize |shared_state_|. | 131 // Lock used to serialize |shared_state_|. |
144 base::Lock shared_state_lock_; | 132 base::Lock shared_state_lock_; |
145 SharedState shared_state_; | 133 SharedState shared_state_; |
146 | 134 |
147 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 135 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
148 blink::scheduler::RendererScheduler* renderer_scheduler_; | 136 blink::scheduler::RendererScheduler* renderer_scheduler_; |
149 | 137 |
150 DISALLOW_COPY_AND_ASSIGN(MainThreadEventQueue); | 138 DISALLOW_COPY_AND_ASSIGN(MainThreadEventQueue); |
151 }; | 139 }; |
152 | 140 |
141 class MainThreadEventQueueWithRenderWidget : public MainThreadEventQueue { | |
tdresser
2017/04/10 15:54:17
Why doesn't the MainThreadEventQueue just have a w
dtapuska
2017/04/10 16:08:05
I could do it that way but the abstraction is for
tdresser
2017/04/10 16:25:01
Could we add a new interface which RenderWidget im
dtapuska
2017/04/13 16:56:24
Done.
| |
142 public: | |
143 MainThreadEventQueueWithRenderWidget( | |
144 const base::WeakPtr<RenderWidget>& widget, | |
145 blink::scheduler::RendererScheduler* renderer_scheduler); | |
146 | |
147 InputEventAckState HandleEventOnMainThread( | |
148 const blink::WebCoalescedInputEvent& event, | |
149 const ui::LatencyInfo& latency, | |
150 InputEventDispatchType dispatch_type) override; | |
151 | |
152 void SendInputEventAck(blink::WebInputEvent::Type type, | |
153 InputEventAckState ack_result, | |
154 uint32_t touch_event_id) override; | |
155 | |
156 void NeedsMainFrame() override; | |
157 | |
158 private: | |
159 ~MainThreadEventQueueWithRenderWidget() override; | |
160 | |
161 base::WeakPtr<RenderWidget> widget_; | |
162 | |
163 DISALLOW_COPY_AND_ASSIGN(MainThreadEventQueueWithRenderWidget); | |
164 }; | |
165 | |
153 } // namespace content | 166 } // namespace content |
154 | 167 |
155 #endif // CONTENT_RENDERER_INPUT_MAIN_THREAD_EVENT_QUEUE_H_ | 168 #endif // CONTENT_RENDERER_INPUT_MAIN_THREAD_EVENT_QUEUE_H_ |
OLD | NEW |