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

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

Issue 2166703003: Implement Main Thread RAF Aligned Input (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master_main_thread_queue
Patch Set: Fix build Created 4 years, 3 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 "base/feature_list.h" 9 #include "base/feature_list.h"
10 #include "content/common/content_export.h" 10 #include "content/common/content_export.h"
(...skipping 12 matching lines...) Expand all
23 class EventWithDispatchType : public ScopedWebInputEventWithLatencyInfo { 23 class EventWithDispatchType : public ScopedWebInputEventWithLatencyInfo {
24 public: 24 public:
25 EventWithDispatchType(ui::ScopedWebInputEvent event, 25 EventWithDispatchType(ui::ScopedWebInputEvent event,
26 const ui::LatencyInfo& latency, 26 const ui::LatencyInfo& latency,
27 InputEventDispatchType dispatch_type); 27 InputEventDispatchType dispatch_type);
28 ~EventWithDispatchType(); 28 ~EventWithDispatchType();
29 bool CanCoalesceWith(const EventWithDispatchType& other) const 29 bool CanCoalesceWith(const EventWithDispatchType& other) const
30 WARN_UNUSED_RESULT; 30 WARN_UNUSED_RESULT;
31 void CoalesceWith(const EventWithDispatchType& other); 31 void CoalesceWith(const EventWithDispatchType& other);
32 32
33 const std::deque<uint32_t>& eventsToAck() const { return eventsToAck_; } 33 const std::deque<uint32_t>& coalescedEventIds() const {
34 return coalesced_event_ids_;
35 }
34 InputEventDispatchType dispatchType() const { return dispatch_type_; } 36 InputEventDispatchType dispatchType() const { return dispatch_type_; }
37 base::TimeTicks creationTimestamp() const { return creation_timestamp_; }
38 base::TimeTicks lastCoalescedTimestamp() const {
39 return last_coalesced_timestamp_;
40 }
35 41
36 private: 42 private:
37 InputEventDispatchType dispatch_type_; 43 InputEventDispatchType dispatch_type_;
38 44
39 // |eventsToAck_| contains the unique touch event id to be acked. If 45 // |coalesced_event_ids_| contains the unique touch event ids to be acked. If
40 // the events are TouchEvents the value will be 0. More importantly for 46 // the events are not TouchEvents the values will be 0. More importantly for
41 // those cases the deque ends up containing how many additional ACKs 47 // those cases the deque ends up containing how many additional ACKs
42 // need to be sent. 48 // need to be sent.
43 std::deque<uint32_t> eventsToAck_; 49 std::deque<uint32_t> coalesced_event_ids_;
50 base::TimeTicks creation_timestamp_;
51 base::TimeTicks last_coalesced_timestamp_;
44 }; 52 };
45 53
46 class CONTENT_EXPORT MainThreadEventQueueClient { 54 class CONTENT_EXPORT MainThreadEventQueueClient {
47 public: 55 public:
48 // Handle an |event| that was previously queued (possibly 56 // Handle an |event| that was previously queued (possibly
49 // coalesced with another event) to the |routing_id|'s 57 // coalesced with another event) to the |routing_id|'s
50 // channel. Implementors must implement this callback. 58 // channel. Implementors must implement this callback.
51 virtual void HandleEventOnMainThread( 59 virtual void HandleEventOnMainThread(
52 int routing_id, 60 int routing_id,
53 const blink::WebInputEvent* event, 61 const blink::WebInputEvent* event,
54 const ui::LatencyInfo& latency, 62 const ui::LatencyInfo& latency,
55 InputEventDispatchType dispatch_type) = 0; 63 InputEventDispatchType dispatch_type) = 0;
56 64
57 virtual void SendInputEventAck(int routing_id, 65 virtual void SendInputEventAck(int routing_id,
58 blink::WebInputEvent::Type type, 66 blink::WebInputEvent::Type type,
59 InputEventAckState ack_result, 67 InputEventAckState ack_result,
60 uint32_t touch_event_id) = 0; 68 uint32_t touch_event_id) = 0;
69 virtual void NeedsMainFrame(int routing_id) = 0;
61 }; 70 };
62 71
63 // MainThreadEventQueue implements a queue for events that need to be 72 // MainThreadEventQueue implements a queue for events that need to be
64 // queued between the compositor and main threads. This queue is managed 73 // queued between the compositor and main threads. This queue is managed
65 // by a lock where events are enqueued by the compositor thread 74 // by a lock where events are enqueued by the compositor thread
66 // and dequeued by the main thread. 75 // and dequeued by the main thread.
67 // 76 //
68 // Below some example flows are how the code behaves. 77 // Below some example flows are how the code behaves.
69 // Legend: B=Browser, C=Compositor, M=Main Thread, NB=Non-blocking 78 // Legend: B=Browser, C=Compositor, M=Main Thread, NB=Non-blocking
70 // BL=Blocking, PT=Post Task, ACK=Acknowledgement 79 // BL=Blocking, PT=Post Task, ACK=Acknowledgement
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 MainThreadEventQueueClient* client, 113 MainThreadEventQueueClient* client,
105 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner, 114 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner,
106 blink::scheduler::RendererScheduler* renderer_scheduler); 115 blink::scheduler::RendererScheduler* renderer_scheduler);
107 116
108 // Called once the compositor has handled |event| and indicated that it is 117 // Called once the compositor has handled |event| and indicated that it is
109 // a non-blocking event to be queued to the main thread. 118 // a non-blocking event to be queued to the main thread.
110 bool HandleEvent(ui::ScopedWebInputEvent event, 119 bool HandleEvent(ui::ScopedWebInputEvent event,
111 const ui::LatencyInfo& latency, 120 const ui::LatencyInfo& latency,
112 InputEventDispatchType dispatch_type, 121 InputEventDispatchType dispatch_type,
113 InputEventAckState ack_result); 122 InputEventAckState ack_result);
123 void DispatchRafAlignedInput();
114 124
115 // Call once the main thread has handled an outstanding |type| event 125 // Call once the main thread has handled an outstanding |type| event
116 // in flight. 126 // in flight.
117 void EventHandled(blink::WebInputEvent::Type type, 127 void EventHandled(blink::WebInputEvent::Type type,
118 InputEventAckState ack_result); 128 InputEventAckState ack_result);
119 129
120 void set_is_flinging(bool is_flinging) { is_flinging_ = is_flinging; } 130 void set_is_flinging(bool is_flinging) { is_flinging_ = is_flinging; }
121 131
122 private: 132 private:
123 friend class base::RefCountedThreadSafe<MainThreadEventQueue>; 133 friend class base::RefCountedThreadSafe<MainThreadEventQueue>;
124 ~MainThreadEventQueue(); 134 ~MainThreadEventQueue();
125 void QueueEvent(std::unique_ptr<EventWithDispatchType> event); 135 void QueueEvent(std::unique_ptr<EventWithDispatchType> event);
126 void SendEventNotificationToMainThread(); 136 void SendEventNotificationToMainThread();
127 void PopEventOnMainThread(); 137 void DispatchSingleEvent();
138 void DispatchInFlightEvent();
139 void PossiblyScheduleMainFrame();
140
128 void SendEventToMainThread(const blink::WebInputEvent* event, 141 void SendEventToMainThread(const blink::WebInputEvent* event,
129 const ui::LatencyInfo& latency, 142 const ui::LatencyInfo& latency,
130 InputEventDispatchType original_dispatch_type); 143 InputEventDispatchType original_dispatch_type);
131 144
132 friend class MainThreadEventQueueTest; 145 friend class MainThreadEventQueueTest;
133 int routing_id_; 146 int routing_id_;
134 MainThreadEventQueueClient* client_; 147 MainThreadEventQueueClient* client_;
135 WebInputEventQueue<EventWithDispatchType> events_;
136 std::unique_ptr<EventWithDispatchType> in_flight_event_; 148 std::unique_ptr<EventWithDispatchType> in_flight_event_;
137 bool is_flinging_; 149 bool is_flinging_;
138 bool last_touch_start_forced_nonblocking_due_to_fling_; 150 bool last_touch_start_forced_nonblocking_due_to_fling_;
139 bool enable_fling_passive_listener_flag_; 151 bool enable_fling_passive_listener_flag_;
152 bool handle_raf_aligned_input_;
140 153
141 base::Lock event_queue_lock_; 154 // Contains data to be shared between main thread and compositor thread.
155 struct SharedState {
156 SharedState();
157 ~SharedState();
158
159 WebInputEventQueue<EventWithDispatchType> events_;
160 bool sent_main_frame_request_;
161 };
162
163 // Lock used to serailize |shared_state_|.
tdresser 2016/08/25 14:38:41 serialize
dtapuska 2016/08/25 15:01:36 Done.
164 base::Lock shared_state_lock_;
165 SharedState shared_state_;
166
142 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; 167 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
143 blink::scheduler::RendererScheduler* renderer_scheduler_; 168 blink::scheduler::RendererScheduler* renderer_scheduler_;
144 169
145 DISALLOW_COPY_AND_ASSIGN(MainThreadEventQueue); 170 DISALLOW_COPY_AND_ASSIGN(MainThreadEventQueue);
146 }; 171 };
147 172
148 } // namespace content 173 } // namespace content
149 174
150 #endif // CONTENT_RENDERER_INPUT_MAIN_THREAD_EVENT_QUEUE_H_ 175 #endif // CONTENT_RENDERER_INPUT_MAIN_THREAD_EVENT_QUEUE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698