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 series of queues (one touch |
60 // and one mouse wheel) for events that need to be queued between | 61 // and one mouse wheel) for events that need to be queued between |
61 // the compositor and main threads. When an event is sent | 62 // the compositor and main threads. When an event is sent |
(...skipping 21 matching lines...) Expand all Loading... | |
83 // <--(PT)--- | 84 // <--(PT)--- |
84 // | 85 // |
85 // Non-blocking followed by blocking event sent to main thread. | 86 // Non-blocking followed by blocking event sent to main thread. |
86 // B C M | 87 // B C M |
87 // ---(NB)--> | 88 // ---(NB)--> |
88 // ---(PT)--> | 89 // ---(PT)--> |
89 // ---(BL)--> | 90 // ---(BL)--> |
90 // <--(PT)--- // Notify from NB event. | 91 // <--(PT)--- // Notify from NB event. |
91 // ---(PT)--> // Release blocking event. | 92 // ---(PT)--> // Release blocking event. |
92 // <--(PT)--- // Notify from BL event. | 93 // <--(PT)--- // Notify from BL event. |
93 // <-------(ACK)------ | 94 // <-------(ACK)------ |
tdresser
2016/07/27 13:51:51
This comment needs updating, doesn't it?
dtapuska
2016/08/03 20:20:54
Done.
| |
94 // | 95 // |
95 class CONTENT_EXPORT MainThreadEventQueue { | 96 class CONTENT_EXPORT MainThreadEventQueue |
97 : public base::RefCountedThreadSafe<MainThreadEventQueue> { | |
96 public: | 98 public: |
97 MainThreadEventQueue(int routing_id, MainThreadEventQueueClient* client); | 99 MainThreadEventQueue( |
98 ~MainThreadEventQueue(); | 100 int routing_id, |
101 MainThreadEventQueueClient* client, | |
102 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner); | |
99 | 103 |
100 // Called once the compositor has handled |event| and indicated that it is | 104 // Called once the compositor has handled |event| and indicated that it is |
101 // a non-blocking event to be queued to the main thread. | 105 // a non-blocking event to be queued to the main thread. |
102 bool HandleEvent(const blink::WebInputEvent* event, | 106 bool HandleEvent(const blink::WebInputEvent* event, |
103 const ui::LatencyInfo& latency, | 107 const ui::LatencyInfo& latency, |
104 InputEventDispatchType dispatch_type, | 108 InputEventDispatchType dispatch_type, |
105 InputEventAckState ack_result); | 109 InputEventAckState ack_result); |
106 | 110 |
107 // Call once the main thread has handled an outstanding |type| event | 111 // Call once the main thread has handled an outstanding |type| event |
108 // in flight. | 112 // in flight. |
109 void EventHandled(blink::WebInputEvent::Type type, | 113 void EventHandled(blink::WebInputEvent::Type type, |
110 InputEventAckState ack_result); | 114 InputEventAckState ack_result); |
111 | 115 |
112 void set_is_flinging(bool is_flinging) { is_flinging_ = is_flinging; } | 116 void set_is_flinging(bool is_flinging) { is_flinging_ = is_flinging; } |
113 | 117 |
114 private: | 118 private: |
119 friend class base::RefCountedThreadSafe<MainThreadEventQueue>; | |
120 ~MainThreadEventQueue(); | |
121 void QueueEvent(std::unique_ptr<EventWithDispatchType>&& event); | |
122 void SendEventNotificationToMainThread(); | |
123 void PopEventOnMainThread(); | |
124 void SendEventToMainThread(const blink::WebInputEvent* event, | |
125 const ui::LatencyInfo& latency, | |
126 InputEventDispatchType original_dispatch_type); | |
127 | |
115 friend class MainThreadEventQueueTest; | 128 friend class MainThreadEventQueueTest; |
116 int routing_id_; | 129 int routing_id_; |
117 MainThreadEventQueueClient* client_; | 130 MainThreadEventQueueClient* client_; |
118 WebInputEventQueue<EventWithDispatchType> events_; | 131 WebInputEventQueue<EventWithDispatchType> events_; |
119 std::unique_ptr<EventWithDispatchType> in_flight_event_; | 132 std::unique_ptr<EventWithDispatchType> in_flight_event_; |
120 bool is_flinging_; | 133 bool is_flinging_; |
121 bool sent_notification_to_main_; | 134 bool sent_notification_to_main_; |
122 | 135 |
136 base::Lock event_queue_mutex_; | |
tdresser
2016/07/27 13:51:51
Looks like event_queue_lock_ would be better in li
dtapuska
2016/08/03 20:20:54
Done.
| |
137 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | |
138 | |
123 DISALLOW_COPY_AND_ASSIGN(MainThreadEventQueue); | 139 DISALLOW_COPY_AND_ASSIGN(MainThreadEventQueue); |
124 }; | 140 }; |
125 | 141 |
126 } // namespace content | 142 } // namespace content |
127 | 143 |
128 #endif // CONTENT_RENDERER_INPUT_MAIN_THREAD_EVENT_QUEUE_H_ | 144 #endif // CONTENT_RENDERER_INPUT_MAIN_THREAD_EVENT_QUEUE_H_ |
OLD | NEW |