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

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: Clean prototype up 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 coalescedTimestamp() const { return coalesced_timestamp_; }
35 39
36 private: 40 private:
37 InputEventDispatchType dispatch_type_; 41 InputEventDispatchType dispatch_type_;
38 42
39 // |eventsToAck_| contains the unique touch event id to be acked. If 43 // |coalesced_event_ids_| contains the unique touch event id to be acked. If
tdresser 2016/08/24 13:43:00 event id -> event ids
dtapuska 2016/08/24 17:10:06 done.
40 // the events are TouchEvents the value will be 0. More importantly for 44 // the events are TouchEvents the value will be 0. More importantly for
tdresser 2016/08/24 13:43:00 Is this comment correct? Should it be "If the even
dtapuska 2016/08/24 17:10:06 done.
41 // those cases the deque ends up containing how many additional ACKs 45 // those cases the deque ends up containing how many additional ACKs
42 // need to be sent. 46 // need to be sent.
43 std::deque<uint32_t> eventsToAck_; 47 std::deque<uint32_t> coalesced_event_ids_;
48 base::TimeTicks creation_timestamp_;
49 base::TimeTicks coalesced_timestamp_;
tdresser 2016/08/24 13:43:00 Maybe: last_coalesced_timestamp_ or most_recent_co
dtapuska 2016/08/24 17:10:06 done
44 }; 50 };
45 51
46 class CONTENT_EXPORT MainThreadEventQueueClient { 52 class CONTENT_EXPORT MainThreadEventQueueClient {
47 public: 53 public:
48 // Handle an |event| that was previously queued (possibly 54 // Handle an |event| that was previously queued (possibly
49 // coalesced with another event) to the |routing_id|'s 55 // coalesced with another event) to the |routing_id|'s
50 // channel. Implementors must implement this callback. 56 // channel. Implementors must implement this callback.
51 virtual void HandleEventOnMainThread( 57 virtual void HandleEventOnMainThread(
52 int routing_id, 58 int routing_id,
53 const blink::WebInputEvent* event, 59 const blink::WebInputEvent* event,
54 const ui::LatencyInfo& latency, 60 const ui::LatencyInfo& latency,
55 InputEventDispatchType dispatch_type) = 0; 61 InputEventDispatchType dispatch_type) = 0;
56 62
57 virtual void SendInputEventAck(int routing_id, 63 virtual void SendInputEventAck(int routing_id,
58 blink::WebInputEvent::Type type, 64 blink::WebInputEvent::Type type,
59 InputEventAckState ack_result, 65 InputEventAckState ack_result,
60 uint32_t touch_event_id) = 0; 66 uint32_t touch_event_id) = 0;
67 virtual void NeedsMainFrame(int routing_id) = 0;
61 }; 68 };
62 69
63 // MainThreadEventQueue implements a queue for events that need to be 70 // MainThreadEventQueue implements a queue for events that need to be
64 // queued between the compositor and main threads. This queue is managed 71 // queued between the compositor and main threads. This queue is managed
65 // by a lock where events are enqueued by the compositor thread 72 // by a lock where events are enqueued by the compositor thread
66 // and dequeued by the main thread. 73 // and dequeued by the main thread.
67 // 74 //
68 // Below some example flows are how the code behaves. 75 // Below some example flows are how the code behaves.
69 // Legend: B=Browser, C=Compositor, M=Main Thread, NB=Non-blocking 76 // Legend: B=Browser, C=Compositor, M=Main Thread, NB=Non-blocking
70 // BL=Blocking, PT=Post Task, ACK=Acknowledgement 77 // BL=Blocking, PT=Post Task, ACK=Acknowledgement
(...skipping 25 matching lines...) Expand all
96 // (deque) 103 // (deque)
97 // <-------(ACK)------ 104 // <-------(ACK)------
98 // 105 //
99 class CONTENT_EXPORT MainThreadEventQueue 106 class CONTENT_EXPORT MainThreadEventQueue
100 : public base::RefCountedThreadSafe<MainThreadEventQueue> { 107 : public base::RefCountedThreadSafe<MainThreadEventQueue> {
101 public: 108 public:
102 MainThreadEventQueue( 109 MainThreadEventQueue(
103 int routing_id, 110 int routing_id,
104 MainThreadEventQueueClient* client, 111 MainThreadEventQueueClient* client,
105 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner, 112 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner,
106 blink::scheduler::RendererScheduler* renderer_scheduler); 113 blink::scheduler::RendererScheduler* renderer_scheduler,
114 bool handle_raf_aligned_input);
107 115
108 // Called once the compositor has handled |event| and indicated that it is 116 // Called once the compositor has handled |event| and indicated that it is
109 // a non-blocking event to be queued to the main thread. 117 // a non-blocking event to be queued to the main thread.
110 bool HandleEvent(ui::ScopedWebInputEvent event, 118 bool HandleEvent(ui::ScopedWebInputEvent event,
111 const ui::LatencyInfo& latency, 119 const ui::LatencyInfo& latency,
112 InputEventDispatchType dispatch_type, 120 InputEventDispatchType dispatch_type,
113 InputEventAckState ack_result); 121 InputEventAckState ack_result);
122 void DispatchRafAlignedInput();
114 123
115 // Call once the main thread has handled an outstanding |type| event 124 // Call once the main thread has handled an outstanding |type| event
116 // in flight. 125 // in flight.
117 void EventHandled(blink::WebInputEvent::Type type, 126 void EventHandled(blink::WebInputEvent::Type type,
118 InputEventAckState ack_result); 127 InputEventAckState ack_result);
119 128
120 void set_is_flinging(bool is_flinging) { is_flinging_ = is_flinging; } 129 void set_is_flinging(bool is_flinging) { is_flinging_ = is_flinging; }
121 130
122 private: 131 private:
123 friend class base::RefCountedThreadSafe<MainThreadEventQueue>; 132 friend class base::RefCountedThreadSafe<MainThreadEventQueue>;
124 ~MainThreadEventQueue(); 133 ~MainThreadEventQueue();
125 void QueueEvent(std::unique_ptr<EventWithDispatchType> event); 134 void QueueEvent(std::unique_ptr<EventWithDispatchType> event);
126 void SendEventNotificationToMainThread(); 135 void SendEventNotificationToMainThread();
127 void PopEventOnMainThread(); 136 void DispatchSingleEvent();
137 void DispatchInFlightEvent();
138 void PossiblyScheduleMainFrame();
139
128 void SendEventToMainThread(const blink::WebInputEvent* event, 140 void SendEventToMainThread(const blink::WebInputEvent* event,
129 const ui::LatencyInfo& latency, 141 const ui::LatencyInfo& latency,
130 InputEventDispatchType original_dispatch_type); 142 InputEventDispatchType original_dispatch_type);
131 143
132 friend class MainThreadEventQueueTest; 144 friend class MainThreadEventQueueTest;
133 int routing_id_; 145 int routing_id_;
134 MainThreadEventQueueClient* client_; 146 MainThreadEventQueueClient* client_;
135 WebInputEventQueue<EventWithDispatchType> events_; 147 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_;
153 bool sent_main_frame_request_;
tdresser 2016/08/24 13:42:59 We should indicate which members should only be ac
dtapuska 2016/08/24 17:10:06 done
140 154
141 base::Lock event_queue_lock_; 155 base::Lock event_queue_lock_;
142 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; 156 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
143 blink::scheduler::RendererScheduler* renderer_scheduler_; 157 blink::scheduler::RendererScheduler* renderer_scheduler_;
144 158
145 DISALLOW_COPY_AND_ASSIGN(MainThreadEventQueue); 159 DISALLOW_COPY_AND_ASSIGN(MainThreadEventQueue);
146 }; 160 };
147 161
148 } // namespace content 162 } // namespace content
149 163
150 #endif // CONTENT_RENDERER_INPUT_MAIN_THREAD_EVENT_QUEUE_H_ 164 #endif // CONTENT_RENDERER_INPUT_MAIN_THREAD_EVENT_QUEUE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698