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 "content/common/content_export.h" | 9 #include "content/common/content_export.h" |
10 #include "content/common/input/event_with_latency_info.h" | 10 #include "content/common/input/event_with_latency_info.h" |
(...skipping 24 matching lines...) Expand all Loading... | |
35 | 35 |
36 // |eventsToAck_| contains the unique touch event id to be acked. If | 36 // |eventsToAck_| contains the unique touch event id to be acked. If |
37 // the events are TouchEvents the value will be 0. More importantly for | 37 // the events are TouchEvents the value will be 0. More importantly for |
38 // those cases the deque ends up containing how many additional ACKs | 38 // those cases the deque ends up containing how many additional ACKs |
39 // need to be sent. | 39 // need to be sent. |
40 std::deque<uint32_t> eventsToAck_; | 40 std::deque<uint32_t> eventsToAck_; |
41 }; | 41 }; |
42 | 42 |
43 class CONTENT_EXPORT MainThreadEventQueueClient { | 43 class CONTENT_EXPORT MainThreadEventQueueClient { |
44 public: | 44 public: |
45 // Send an |event| that was previously queued (possibly | 45 // Handle an |event| that was previously queued (possibly |
46 // coalesced with another event) to the |routing_id|'s | 46 // coalesced with another event) to the |routing_id|'s |
47 // channel. Implementors must implement this callback. | 47 // channel. Implementors must implement this callback. |
48 virtual void SendEventToMainThread(int routing_id, | 48 virtual void HandleEventOnMainThread( |
49 const blink::WebInputEvent* event, | 49 int routing_id, |
50 const ui::LatencyInfo& latency, | 50 const blink::WebInputEvent* event, |
51 InputEventDispatchType dispatch_type) = 0; | 51 const ui::LatencyInfo& latency, |
52 InputEventDispatchType dispatch_type) = 0; | |
52 | 53 |
53 virtual void SendInputEventAck(int routing_id, | 54 virtual void SendInputEventAck(int routing_id, |
54 blink::WebInputEvent::Type type, | 55 blink::WebInputEvent::Type type, |
55 InputEventAckState ack_result, | 56 InputEventAckState ack_result, |
56 uint32_t touch_event_id) = 0; | 57 uint32_t touch_event_id) = 0; |
57 }; | 58 }; |
58 | 59 |
59 // MainThreadEventQueue implements a series of queues (one touch | 60 // MainThreadEventQueue implements a queue for events that need to be |
60 // and one mouse wheel) for events that need to be queued between | 61 // queued between the compositor and main threads. This queue is managed |
61 // the compositor and main threads. When an event is sent | 62 // by a lock primarily where events are enqued by the compositor thread |
tdresser
2016/08/04 18:02:22
enqued -> enqueued
tdresser
2016/08/04 18:02:22
Is the "primarily" required here? When is this not
dtapuska
2016/08/08 15:34:03
Done.
dtapuska
2016/08/08 15:34:03
Done.
| |
62 // from the compositor to main it can either be sent directly if no | 63 // and dequed by the main thread. |
tdresser
2016/08/04 18:02:22
dequed -> dequeued.
dtapuska
2016/08/08 15:34:03
Done.
| |
63 // outstanding events of that type are in flight; or it needs to | |
64 // wait in a queue until the main thread has finished processing | |
65 // the in-flight event. This class tracks the state and queues | |
66 // for the event types. Methods on this class should only be called | |
67 // from the compositor thread. | |
68 // | 64 // |
69 // Below some example flows are how the code behaves. | 65 // Below some example flows are how the code behaves. |
70 // Legend: B=Browser, C=Compositor, M=Main Thread, NB=Non-blocking | 66 // Legend: B=Browser, C=Compositor, M=Main Thread, NB=Non-blocking |
71 // BL=Blocking, PT=Post Task, ACK=Acknowledgement | 67 // BL=Blocking, PT=Post Task, ACK=Acknowledgement |
72 // | 68 // |
73 // Normal blocking event sent to main thread. | 69 // Normal blocking event sent to main thread. |
74 // B C M | 70 // B C M |
75 // ---(BL)--> | 71 // ---(BL)--> |
72 // (queue) | |
76 // ---(PT)--> | 73 // ---(PT)--> |
74 // (deque) | |
77 // <-------(ACK)------ | 75 // <-------(ACK)------ |
78 // | 76 // |
79 // Non-blocking event sent to main thread. | 77 // Non-blocking event sent to main thread. |
80 // B C M | 78 // B C M |
81 // ---(NB)--> | 79 // ---(NB)--> |
80 // (queue) | |
82 // ---(PT)--> | 81 // ---(PT)--> |
83 // <--(PT)--- | 82 // (deque) |
84 // | 83 // |
85 // Non-blocking followed by blocking event sent to main thread. | 84 // Non-blocking followed by blocking event sent to main thread. |
86 // B C M | 85 // B C M |
87 // ---(NB)--> | 86 // ---(NB)--> |
87 // (queue) | |
88 // ---(PT)--> | 88 // ---(PT)--> |
89 // ---(BL)--> | 89 // ---(BL)--> |
90 // <--(PT)--- // Notify from NB event. | 90 // (queue) |
91 // ---(PT)--> // Release blocking event. | 91 // (deque) |
92 // <--(PT)--- // Notify from BL event. | 92 // (deque) |
93 // <-------(ACK)------ | 93 // <-------(ACK)------ |
tdresser
2016/08/04 18:02:22
Thanks, this looks great.
dtapuska
2016/08/08 15:34:03
Acknowledged.
| |
94 // | 94 // |
95 class CONTENT_EXPORT MainThreadEventQueue { | 95 class CONTENT_EXPORT MainThreadEventQueue |
96 : public base::RefCountedThreadSafe<MainThreadEventQueue> { | |
96 public: | 97 public: |
97 MainThreadEventQueue(int routing_id, MainThreadEventQueueClient* client); | 98 MainThreadEventQueue( |
98 ~MainThreadEventQueue(); | 99 int routing_id, |
100 MainThreadEventQueueClient* client, | |
101 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner); | |
99 | 102 |
100 // Called once the compositor has handled |event| and indicated that it is | 103 // Called once the compositor has handled |event| and indicated that it is |
101 // a non-blocking event to be queued to the main thread. | 104 // a non-blocking event to be queued to the main thread. |
102 bool HandleEvent(const blink::WebInputEvent* event, | 105 bool HandleEvent(const blink::WebInputEvent* event, |
103 const ui::LatencyInfo& latency, | 106 const ui::LatencyInfo& latency, |
104 InputEventDispatchType dispatch_type, | 107 InputEventDispatchType dispatch_type, |
105 InputEventAckState ack_result); | 108 InputEventAckState ack_result); |
106 | 109 |
107 // Call once the main thread has handled an outstanding |type| event | 110 // Call once the main thread has handled an outstanding |type| event |
108 // in flight. | 111 // in flight. |
109 void EventHandled(blink::WebInputEvent::Type type, | 112 void EventHandled(blink::WebInputEvent::Type type, |
110 InputEventAckState ack_result); | 113 InputEventAckState ack_result); |
111 | 114 |
112 void set_is_flinging(bool is_flinging) { is_flinging_ = is_flinging; } | 115 void set_is_flinging(bool is_flinging) { is_flinging_ = is_flinging; } |
113 | 116 |
114 private: | 117 private: |
118 friend class base::RefCountedThreadSafe<MainThreadEventQueue>; | |
119 ~MainThreadEventQueue(); | |
120 void QueueEvent(std::unique_ptr<EventWithDispatchType>&& event); | |
121 void SendEventNotificationToMainThread(); | |
122 void PopEventOnMainThread(); | |
123 void SendEventToMainThread(const blink::WebInputEvent* event, | |
124 const ui::LatencyInfo& latency, | |
125 InputEventDispatchType original_dispatch_type); | |
126 | |
115 friend class MainThreadEventQueueTest; | 127 friend class MainThreadEventQueueTest; |
116 int routing_id_; | 128 int routing_id_; |
117 MainThreadEventQueueClient* client_; | 129 MainThreadEventQueueClient* client_; |
118 WebInputEventQueue<EventWithDispatchType> events_; | 130 WebInputEventQueue<EventWithDispatchType> events_; |
119 std::unique_ptr<EventWithDispatchType> in_flight_event_; | 131 std::unique_ptr<EventWithDispatchType> in_flight_event_; |
120 bool is_flinging_; | 132 bool is_flinging_; |
121 bool sent_notification_to_main_; | 133 bool sent_notification_to_main_; |
122 | 134 |
135 base::Lock event_queue_lock_; | |
136 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | |
137 | |
123 DISALLOW_COPY_AND_ASSIGN(MainThreadEventQueue); | 138 DISALLOW_COPY_AND_ASSIGN(MainThreadEventQueue); |
124 }; | 139 }; |
125 | 140 |
126 } // namespace content | 141 } // namespace content |
127 | 142 |
128 #endif // CONTENT_RENDERER_INPUT_MAIN_THREAD_EVENT_QUEUE_H_ | 143 #endif // CONTENT_RENDERER_INPUT_MAIN_THREAD_EVENT_QUEUE_H_ |
OLD | NEW |