Chromium Code Reviews| 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" |
| 11 #include "content/common/input/input_event_ack_state.h" | 11 #include "content/common/input/input_event_ack_state.h" |
| 12 #include "content/common/input/input_event_dispatch_type.h" | 12 #include "content/common/input/input_event_dispatch_type.h" |
| 13 #include "content/common/input/web_input_event_queue.h" | 13 #include "content/common/input/web_input_event_queue.h" |
| 14 #include "ipc/message_filter.h" | |
| 14 #include "third_party/WebKit/public/web/WebInputEvent.h" | 15 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 15 #include "ui/events/latency_info.h" | 16 #include "ui/events/latency_info.h" |
| 16 | 17 |
| 17 namespace content { | 18 namespace content { |
| 18 | 19 |
| 19 template <typename BaseClass, typename BaseType> | 20 template <typename BaseClass, typename BaseType> |
| 20 class EventWithDispatchType : public BaseClass { | 21 class EventWithDispatchType : public BaseClass { |
| 21 public: | 22 public: |
| 22 EventWithDispatchType(const BaseType& e, | 23 EventWithDispatchType(const BaseType& e, |
| 23 const ui::LatencyInfo& l, | 24 const ui::LatencyInfo& l, |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 36 } | 37 } |
| 37 }; | 38 }; |
| 38 | 39 |
| 39 using PendingMouseWheelEvent = | 40 using PendingMouseWheelEvent = |
| 40 EventWithDispatchType<MouseWheelEventWithLatencyInfo, | 41 EventWithDispatchType<MouseWheelEventWithLatencyInfo, |
| 41 blink::WebMouseWheelEvent>; | 42 blink::WebMouseWheelEvent>; |
| 42 | 43 |
| 43 using PendingTouchEvent = | 44 using PendingTouchEvent = |
| 44 EventWithDispatchType<TouchEventWithLatencyInfo, blink::WebTouchEvent>; | 45 EventWithDispatchType<TouchEventWithLatencyInfo, blink::WebTouchEvent>; |
| 45 | 46 |
| 47 using PendingMouseEvent = | |
| 48 EventWithDispatchType<MouseEventWithLatencyInfo, blink::WebMouseEvent>; | |
| 49 | |
| 46 class CONTENT_EXPORT MainThreadEventQueueClient { | 50 class CONTENT_EXPORT MainThreadEventQueueClient { |
| 47 public: | 51 public: |
| 48 // Send an |event| that was previously queued (possibly | 52 // Handle an |event| that was previously queued (possibly |
| 49 // coalesced with another event) to the |routing_id|'s | 53 // coalesced with another event) to the |routing_id|'s |
| 50 // channel. Implementors must implement this callback. | 54 // channel. Implementors must implement this callback. |
| 51 virtual void SendEventToMainThread(int routing_id, | 55 virtual void HandleEventOnMainThread( |
| 52 const blink::WebInputEvent* event, | 56 int routing_id, |
| 53 const ui::LatencyInfo& latency, | 57 const blink::WebInputEvent* event, |
| 54 InputEventDispatchType dispatch_type) = 0; | 58 const ui::LatencyInfo& latency, |
| 59 InputEventDispatchType dispatch_type) = 0; | |
| 55 }; | 60 }; |
| 56 | 61 |
| 57 // MainThreadEventQueue implements a series of queues (one touch | 62 // MainThreadEventQueue implements a series of queues (one touch |
| 58 // and one mouse wheel) for events that need to be queued between | 63 // and one mouse wheel) for events that need to be queued between |
| 59 // the compositor and main threads. When an event is sent | 64 // the compositor and main threads. When an event is sent |
| 60 // from the compositor to main it can either be sent directly if no | 65 // from the compositor to main it can either be sent directly if no |
| 61 // outstanding events of that type are in flight; or it needs to | 66 // outstanding events of that type are in flight; or it needs to |
| 62 // wait in a queue until the main thread has finished processing | 67 // wait in a queue until the main thread has finished processing |
| 63 // the in-flight event. This class tracks the state and queues | 68 // the in-flight event. This class tracks the state and queues |
| 64 // for the event types. Methods on this class should only be called | 69 // for the event types. Methods on this class should only be called |
| 65 // from the compositor thread. | 70 // from the compositor thread. |
|
tdresser
2016/05/30 14:05:32
Don't forget to change this comment.
| |
| 66 // | 71 // |
| 67 // Below some example flows are how the code behaves. | 72 // Below some example flows are how the code behaves. |
| 68 // Legend: B=Browser, C=Compositor, M=Main Thread, NB=Non-blocking | 73 // Legend: B=Browser, C=Compositor, M=Main Thread, NB=Non-blocking |
| 69 // BL=Blocking, PT=Post Task, ACK=Acknowledgement | 74 // BL=Blocking, PT=Post Task, ACK=Acknowledgement |
| 70 // | 75 // |
| 71 // Normal blocking event sent to main thread. | 76 // Normal blocking event sent to main thread. |
| 72 // B C M | 77 // B C M |
| 73 // ---(BL)--> | 78 // ---(BL)--> |
| 74 // ---(PT)--> | 79 // ---(PT)--> |
| 75 // <-------(ACK)------ | 80 // <-------(ACK)------ |
| 76 // | 81 // |
| 77 // Non-blocking event sent to main thread. | 82 // Non-blocking event sent to main thread. |
| 78 // B C M | 83 // B C M |
| 79 // ---(NB)--> | 84 // ---(NB)--> |
| 80 // ---(PT)--> | 85 // ---(PT)--> |
| 81 // <--(PT)--- | 86 // <--(PT)--- |
| 82 // | 87 // |
| 83 // Non-blocking followed by blocking event sent to main thread. | 88 // Non-blocking followed by blocking event sent to main thread. |
| 84 // B C M | 89 // B C M |
| 85 // ---(NB)--> | 90 // ---(NB)--> |
| 86 // ---(PT)--> | 91 // ---(PT)--> |
| 87 // ---(BL)--> | 92 // ---(BL)--> |
| 88 // <--(PT)--- // Notify from NB event. | 93 // <--(PT)--- // Notify from NB event. |
| 89 // ---(PT)--> // Release blocking event. | 94 // ---(PT)--> // Release blocking event. |
| 90 // <--(PT)--- // Notify from BL event. | 95 // <--(PT)--- // Notify from BL event. |
| 91 // <-------(ACK)------ | 96 // <-------(ACK)------ |
| 92 // | 97 // |
| 93 class CONTENT_EXPORT MainThreadEventQueue { | 98 class CONTENT_EXPORT MainThreadEventQueue { |
| 94 public: | 99 public: |
| 95 MainThreadEventQueue(int routing_id, MainThreadEventQueueClient* client); | 100 MainThreadEventQueue( |
| 101 int routing_id, | |
| 102 MainThreadEventQueueClient* client, | |
| 103 const base::Callback<void(const IPC::Message&)>& main_listener, | |
| 104 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner); | |
| 96 ~MainThreadEventQueue(); | 105 ~MainThreadEventQueue(); |
| 97 | 106 |
| 98 // Called once the compositor has handled |event| and indicated that it is | 107 // Called once the compositor has handled |event| and indicated that it is |
| 99 // a non-blocking event to be queued to the main thread. | 108 // a non-blocking event to be queued to the main thread. |
| 100 bool HandleEvent(const blink::WebInputEvent* event, | 109 bool HandleEvent(const blink::WebInputEvent* event, |
| 101 const ui::LatencyInfo& latency, | 110 const ui::LatencyInfo& latency, |
| 102 InputEventDispatchType dispatch_type, | 111 InputEventDispatchType dispatch_type, |
| 103 InputEventAckState ack_result); | 112 InputEventAckState ack_result); |
| 104 | 113 |
| 105 // Call once the main thread has handled an outstanding |type| event | 114 // Call once the main thread has handled an outstanding |type| event |
| 106 // in flight. | 115 // in flight. |
| 107 void EventHandled(blink::WebInputEvent::Type type); | 116 void EventHandled(blink::WebInputEvent::Type type); |
| 108 | 117 |
| 109 void set_is_flinging(bool is_flinging) { is_flinging_ = is_flinging; } | 118 void set_is_flinging(bool is_flinging) { is_flinging_ = is_flinging; } |
| 110 | 119 |
| 111 private: | 120 private: |
| 121 void QueueWheelEvent(const PendingMouseWheelEvent& event); | |
| 122 void QueueTouchEvent(const PendingTouchEvent& event); | |
| 123 void QueueMouseEvent(const PendingMouseEvent& event); | |
| 124 void SendWheelEventNotificationToMainThread(); | |
| 125 void SendTouchEventNotificationToMainThread(); | |
| 126 void SendMouseEventNotificationToMainThread(); | |
| 127 void PopTouchEventOnMainThread(); | |
| 128 void PopWheelEventOnMainThread(); | |
| 129 void PopMouseEventOnMainThread(); | |
| 130 void SendEventToMainThread(const blink::WebInputEvent* event, | |
| 131 const ui::LatencyInfo& latency, | |
| 132 InputEventDispatchType original_dispatch_type); | |
| 133 | |
| 112 friend class MainThreadEventQueueTest; | 134 friend class MainThreadEventQueueTest; |
| 113 int routing_id_; | 135 int routing_id_; |
| 114 MainThreadEventQueueClient* client_; | 136 MainThreadEventQueueClient* client_; |
| 115 WebInputEventQueue<PendingMouseWheelEvent> wheel_events_; | 137 WebInputEventQueue<PendingMouseWheelEvent> wheel_events_; |
| 116 WebInputEventQueue<PendingTouchEvent> touch_events_; | 138 WebInputEventQueue<PendingTouchEvent> touch_events_; |
| 139 WebInputEventQueue<PendingMouseEvent> mouse_events_; | |
| 117 bool is_flinging_; | 140 bool is_flinging_; |
| 141 base::Lock event_queue_mutex_; | |
| 142 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | |
| 143 base::Callback<void(const IPC::Message&)> main_listener_; | |
|
tdresser
2016/05/30 14:05:32
Eventually we'll want a couple ThreadChecker's in
dtapuska
2016/06/01 18:22:54
Acknowledged.
| |
| 118 | 144 |
| 119 DISALLOW_COPY_AND_ASSIGN(MainThreadEventQueue); | 145 DISALLOW_COPY_AND_ASSIGN(MainThreadEventQueue); |
| 120 }; | 146 }; |
| 121 | 147 |
| 122 } // namespace content | 148 } // namespace content |
| 123 | 149 |
| 124 #endif // CONTENT_RENDERER_INPUT_MAIN_THREAD_EVENT_QUEUE_H_ | 150 #endif // CONTENT_RENDERER_INPUT_MAIN_THREAD_EVENT_QUEUE_H_ |
| OLD | NEW |